mirror of
https://github.com/espressif/openthread.git
synced 2026-08-08 19:57:46 +00:00
[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:
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user