[crypto] add new flavors of 'Update()' for SHA-256 and HMAC computation (#6002)

This commit updates `Sha256` and `HmacSha256` classes adding new
flavors of `Update()` method which inputs bytes from a given buffer,
or from an object, or read from a `Message` for hash calculation.

This commit also updates unit test to add more test-cases (from RFC
4231) for HMAC and adds new set of test-cases for SHA-256. The test
also covers calculating hash over data read directly from a `Message`.
This commit is contained in:
Abtin Keshavarzian
2020-12-23 14:56:33 -08:00
committed by GitHub
parent 01d169ad87
commit 65eac03ad9
11 changed files with 355 additions and 55 deletions
+3 -3
View File
@@ -101,7 +101,7 @@ void TestEcdsaVector(void)
printf("\nHash the message ----------------------------------------------------------\n");
sha256.Start();
sha256.Update(kMessage, sizeof(kMessage));
sha256.Update(kMessage);
sha256.Finish(hash);
DumpBuffer("Hash", hash.GetBytes(), sizeof(hash));
@@ -153,7 +153,7 @@ void TestEdsaKeyGenerationSignAndVerify(void)
printf("\nHash the message ----------------------------------------------------------\n");
sha256.Start();
sha256.Update(reinterpret_cast<const uint8_t *>(kMessage), sizeof(kMessage) - 1);
sha256.Update(kMessage, sizeof(kMessage) - 1);
sha256.Finish(hash);
DumpBuffer("Hash", hash.GetBytes(), sizeof(hash));
@@ -167,7 +167,7 @@ void TestEdsaKeyGenerationSignAndVerify(void)
printf("\nSignature was verified successfully.");
sha256.Start();
sha256.Update(reinterpret_cast<const uint8_t *>(kMessage), sizeof(kMessage)); // include null char
sha256.Update(kMessage, sizeof(kMessage)); // include null char
sha256.Finish(hash);
VerifyOrQuit(publicKey.Verify(hash, signature) != OT_ERROR_NONE,
"PublicKey::Verify() passed for invalid signature");