4

I am trying to measure the cycles per byte for $\mathop{SHA-3}$ reference implementation. I am using recommendations from Microsoft querying the performance counter. As you can see in the first snippet, cycles are measured before converting into microseconds. My code looks like the following:

QueryPerformanceCounter(&StartingTime);
SHA3_256(K_OUT, K_IN, length);
QueryPerformanceCounter(&EndingTime);

ElapsedMicroseconds.QuadPart = EndingTime.QuadPart - StartingTime.QuadPart;
printf("Elapsed ticks: %.20f \n", ElapsedMicroseconds.QuadPart / (float)(length));

But the results are definitively wrong. It is mostly something smaller than $0.9$. I would guess a value around $30$ Cycles per Byte. What am I doing wrong?

Biv
  • 10,088
  • 2
  • 42
  • 68
chris000r
  • 519
  • 3
  • 15

1 Answers1

10

To perform a good check, please use a large number of iterations (i.e. a for loop) of calls to the cryptographic primitive with your specific data size. Then average these out.

To avoid compiler optimizations, be sure to print out the result after the clock has been stopped. For instance, you could XOR all the outputs together and print that out. Otherwise the compiler may determine that your call has no side effects and simply remove the entire call to SHA-3.

Note that internal operations are usually performed on 64-bit or larger registers, i.e. 8 bytes at a time. It is perfectly possible to have sub-one scores - although I admit that for SHA-3 the value of 0.9 cycle/byte does not seem likely.

Maarten Bodewes
  • 96,351
  • 14
  • 169
  • 323