spaniakos / Cryptosuite

Cryptographic suite for Arduino & RPi (SHA, HMAC-SHA)
http://spaniakos.github.io/Cryptosuite/
GNU Affero General Public License v3.0
23 stars 11 forks source link

Timing Method in Examples gives Large Error - Code is faster than you might think. #6

Open budnail opened 8 years ago

budnail commented 8 years ago

Not a big deal at all, but the method of timing the hash function also includes the time it takes to print the hash values. Typical code from examples below:


ms = micros(); // timing starts here Sha256.initHmac(hmacKey1,20); // initialize and load the key - fair to include Sha256.print("Hi There");// load the data - fair to include printHash(Sha256.resultHmac()); //also includes time to serial print 32 hex characters Serial.print(" Hash took : "); // includes time to print this label Serial.print((micros() - ms)); // time calculated here Serial.println(" micros"); Serial.println();


In one of my test cases, the time to perform the HMAC SHA256 was showing about 950 microseconds. After I reworked my code to not include the serial print, the time dropped to 344 microseconds. This time also included some code I added to convert the binary HMAC to Hex format.

I don't have a really good way to get accurate timing values that is worth sharing, but thought it might be a good idea to point this out for someone who might get discouraged on a slow processor. The code is much faster than the examples might indicate. Which is a good thing. I'm not suggesting that anything be changed unless there is a good place to add a note in the documentation.

spaniakos commented 8 years ago

You are right. I will rework some code in january, as until the 1st of January i wont be able to test changes to the freamework. Also i will try to make a unified hash/encryption library in order to have multiple choices.

Thanks for the remarks, Spaniakos On Dec 17, 2015 1:12 AM, "Bud Nail" notifications@github.com wrote:

Not a big deal at all, but the method of timing the hash function also includes the time it takes to print the hash values. Typical code from

examples below:

ms = micros(); // timing starts here Sha256.initHmac(hmacKey1,20); // initialize and load the key - fair to include Sha256.print("Hi There");// load the data - fair to include printHash(Sha256.resultHmac()); //also includes time to serial print 32 hex characters Serial.print(" Hash took : "); // includes time to print this label Serial.print((micros() - ms)); // time calculated here Serial.println(" micros");

Serial.println();

In one of my test cases, the time to perform the HMAC SHA256 was showing about 950 microseconds. After I reworked my code to not include the serial print, the time dropped to 344 microseconds. This time also included some code I added to convert the binary HMAC to Hex format.

I don't have a really good way to get accurate timing values that is worth sharing, but thought it might be a good idea to point this out for someone who might get discouraged on a slow processor. The code is much faster than the examples might indicate. Which is a good thing. I'm not suggesting that anything be changed unless there is a good place to add a note in the documentation.

— Reply to this email directly or view it on GitHub https://github.com/spaniakos/Cryptosuite/issues/6.