21.03.2013 Views

Problem - Kevin Tafuro

Problem - Kevin Tafuro

Problem - Kevin Tafuro

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

4.14 Timing Cryptographic Primitives<br />

<strong>Problem</strong><br />

You want to compare the efficiency of two similar cryptographic primitives and<br />

would like to ensure that you do so in a fair manner.<br />

Solution<br />

Time operations by calculating how many cycles it takes to process each byte, so that<br />

you can compare numbers across processors of different speeds more fairly.<br />

Focus on the expected average case, best case, and worst case.<br />

Discussion<br />

When you’re looking at timing information, you usually have one of two motivations:<br />

either you’re interested in comparing the performance of two algorithms, or<br />

you’d like to get a sense of how much data you’ll actually be able to pump through a<br />

particular machine.<br />

Measuring bytes per second is a useful thing when you’re comparing the performance<br />

of multiple algorithms on a single box, but it gives no real indication of performance<br />

on other machines. Therefore, cryptographers prefer to measure how many<br />

processor clock cycles it takes to process each byte, because doing so allows for comparisons<br />

that are more widely applicable. For example, such comparisons will generally<br />

hold fast on the same line of processors running at different speeds.<br />

If you’re directly comparing the speed of an algorithm on a 2GHz Pentium 4 against<br />

the published speed of the same algorithm run on a 800 MHz Pentium 3, the first<br />

one will always be faster when measured in bytes per second. However, if you convert<br />

the numbers from bytes per second to cycles per byte, you’ll see that, if you run<br />

the same implementation of an algorithm on a P3 and a P4, the P3 will generally be<br />

faster by 25% or so, just because instructions on a P4 take longer to execute on average<br />

than they do on a P3.<br />

If you know the speed of an algorithm in bytes per second, you can calculate the<br />

number of cycles per byte simply by dividing by the clock speed in hertz (giving you<br />

bytes per cycle) and taking the reciprocal (getting cycles per byte). If you know the<br />

speed measured in gigabytes per second, you can divide by the clock speed in gigahertz,<br />

then take the reciprocal. For example, you can process data at 0.2 gigabytes<br />

per second on a 3 GHz CPU as follows:<br />

.2/3 = 0.066666666666666666 (bytes processed per cycle)<br />

1/0.066666666666666666 = 15.0 cycles per byte<br />

150 | 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!