21.03.2013 Views

Problem - Kevin Tafuro

Problem - Kevin Tafuro

Problem - Kevin Tafuro

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

time by subtracting the start from the end. Here’s a function to do both, which<br />

requires you to define a constant with your clock speed in gigahertz:<br />

#define MY_GHZ 1.6666666666666667 /* We're using an Athlon XP 2000 */<br />

spc_uint64_t get_cycle_count(spc_uint64_t start, spc_uint64_t end) {<br />

return (spc_uint64_t)((end - start) / (doublt)MY_GHZ);<br />

}<br />

Timing cryptographic code<br />

When timing cryptographic primitives, you’ll generally want to know how many<br />

cycles it takes to process a byte, on average. That’s easy: just divide the number of<br />

bytes you process by the number of cycles it takes to process. If you wish, you can<br />

remove overhead from the cycle count, such as timing overhead (e.g., a loop).<br />

One important thing to note about timing cryptographic code is that some types of<br />

algorithms have different performance characteristics as they process more data.<br />

That is, they can be dominated by per-message overhead costs for small message<br />

sizes. For example, most hash functions such as SHA1 are significantly slower (per<br />

byte) for small messages than they are for large messages.<br />

You need to figure out whether you care about optimal performance or average-case<br />

performance. Most often, it will be the latter. For example, if you are comparing the<br />

speeds of SHA1 and some other cryptographic hash function such as RIPEMD-160,<br />

you should ask yourself what range of message sizes you expect to see and test for<br />

values sampled throughout that range.<br />

154 | Chapter 4: Symmetric Cryptography Fundamentals<br />

This is the Title of the Book, eMatter Edition<br />

Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!