Remove globals from mbedcrypto.cpp.

This commit is contained in:
Jonathan Hui
2016-09-07 13:30:22 -07:00
parent 28a564548c
commit 9e39426f01
19 changed files with 380 additions and 234 deletions
+10 -6
View File
@@ -31,7 +31,10 @@
#include <common/debug.hpp>
#include <string.h>
#include <crypto/hmac_sha256.h>
#include <crypto/hmac_sha256.hpp>
#include <crypto/mbedtls.hpp>
static Thread::Crypto::MbedTls mbedtls;
extern"C" void otSignalTaskletPending(void)
{
@@ -43,7 +46,7 @@ void TestHmacSha256(void)
{
const char *key;
const char *data;
uint8_t hash[otCryptoSha256Size];
uint8_t hash[Thread::Crypto::HmacSha256::kHashSize];
} tests[] =
{
{
@@ -63,13 +66,14 @@ void TestHmacSha256(void)
},
};
uint8_t hash[otCryptoSha256Size];
Thread::Crypto::HmacSha256 hmac;
uint8_t hash[Thread::Crypto::HmacSha256::kHashSize];
for (int i = 0; tests[i].key != NULL; i++)
{
otCryptoHmacSha256Start(tests[i].key, static_cast<uint16_t>(strlen(tests[i].key)));
otCryptoHmacSha256Update(tests[i].data, static_cast<uint16_t>(strlen(tests[i].data)));
otCryptoHmacSha256Finish(hash);
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");