intrbiz / arduino-crypto

A minimal crypto library for ESP8266 Arduino
Other
140 stars 53 forks source link

Consider a reset function #16

Open RezApp opened 6 years ago

RezApp commented 6 years ago

Please consider a reset function for sha256, because if you doUpdate and then doFinal twice or more for the same inputs your hashes are different.

macsnoeren commented 3 years ago

This is indeed an issue. The following code will not give the correct hash for the second doFinal of text1. Only the first doUpdate result in the correct has, in this case for text2. Is it possible to fix that?

hasher.doUpdate(text2.c_str(), text2.length());
hasher.doFinal(hash2);
printHash(hash2);

hasher.doUpdate(text1.c_str(), text1.length());
hasher.doFinal(hash1);
printHash(hash1);

Thanks!

macsnoeren commented 3 years ago

I have created a pull request with the solution to this problem. Hope you like it :).