[mbedtls] move heap into otInstance. (#1996)

This commit is contained in:
Buke Po
2017-07-14 08:37:12 -07:00
committed by Jonathan Hui
parent 4a1bbc8044
commit d4836a4426
5 changed files with 30 additions and 16 deletions
+14 -10
View File
@@ -63,19 +63,23 @@ void TestHmacSha256(void)
};
otInstance *instance = testInitInstance();
ot::Crypto::HmacSha256 hmac;
uint8_t hash[ot::Crypto::HmacSha256::kHashSize];
VerifyOrQuit(instance != NULL, "Null OpenThread instance");
for (int i = 0; tests[i].key != NULL; i++)
// Make sure hmac is destructed before freeing instance.
{
hmac.Start(reinterpret_cast<const uint8_t *>(tests[i].key), static_cast<uint16_t>(strlen(tests[i].key)));
hmac.Update(reinterpret_cast<const uint8_t *>(tests[i].data), static_cast<uint16_t>(strlen(tests[i].data)));
hmac.Finish(hash);
ot::Crypto::HmacSha256 hmac;
uint8_t hash[ot::Crypto::HmacSha256::kHashSize];
VerifyOrQuit(memcmp(hash, tests[i].hash, sizeof(tests[i].hash)) == 0,
"HMAC-SHA-256 failed\n");
VerifyOrQuit(instance != NULL, "Null OpenThread instance");
for (int i = 0; tests[i].key != NULL; i++)
{
hmac.Start(reinterpret_cast<const uint8_t *>(tests[i].key), static_cast<uint16_t>(strlen(tests[i].key)));
hmac.Update(reinterpret_cast<const uint8_t *>(tests[i].data), static_cast<uint16_t>(strlen(tests[i].data)));
hmac.Finish(hash);
VerifyOrQuit(memcmp(hash, tests[i].hash, sizeof(tests[i].hash)) == 0,
"HMAC-SHA-256 failed\n");
}
}
testFreeInstance(instance);