-#include <sec/mac/hmac.h>
+#include "hmac.h"
#include <cfg/test.h>
#include <cfg/debug.h>
#include <sec/hash/sha1.h>
#include <sec/hash/md5.h>
#include <string.h>
-int HMAC_testSetup(void)
+int hmac_testSetup(void)
{
kdbg_init();
return 0;
}
-int HMAC_testTearDown(void)
+int hmac_testTearDown(void)
{
return 0;
}
const struct Test_HMAC tests_hmac_md5[] =
{
- {
+ {
"\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b", 16,
"Hi There", 8,
"\x92\x94\x72\x7a\x36\x38\xbb\x1c\x13\xf4\x8e\xf8\x15\x8b\xfc\x9d",
},
{
- "Jefe", 4,
+ "Jefe", 4,
"what do ya want for nothing?", 28,
"\x75\x0c\x78\x3e\x6a\xb0\xb5\x03\xea\xa8\x6e\x31\x0a\x5d\xb7\x38",
},
"Jefe", 4,
"what do ya want for nothing?", 28,
"\xef\xfc\xdf\x6a\xe5\xeb\x2f\xa2\xd2\x74\x16\xd5\xf1\x84\xdf\x9c\x25\x9a\x7c\x79",
- },
+ },
{
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", 20,
"\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
},
};
-static void algo_run_tests(HMAC_Context *hmac, const struct Test_HMAC *t, int count)
+static void algo_run_tests(Mac *mac, const struct Test_HMAC *t, int count)
{
for (int i=0; i<count; ++i, ++t)
{
- mac_set_key(&hmac->m, (const uint8_t*)t->key, t->key_len);
- mac_begin(&hmac->m);
- mac_update(&hmac->m, (const uint8_t*)t->data, t->data_len);
- ASSERT(memcmp(mac_final(&hmac->m), t->digest, mac_digest_len(&hmac->m)) == 0);
+ mac_set_key(mac, (const uint8_t*)t->key, t->key_len);
+ mac_begin(mac);
+ mac_update(mac, (const uint8_t*)t->data, t->data_len);
+ ASSERT(memcmp(mac_final(mac), t->digest, mac_digest_len(mac)) == 0);
}
}
-int HMAC_testRun(void)
+int hmac_testRun(void)
{
- if (1)
- {
- MD5_Context md5;
- MD5_init(&md5);
-
- HMAC_Context hmac;
- HMAC_init(&hmac, &md5.h);
+ algo_run_tests(hmac_stackinit(MD5_stackinit()),
+ tests_hmac_md5, countof(tests_hmac_md5));
- algo_run_tests(&hmac, tests_hmac_md5, countof(tests_hmac_md5));
- }
-
- if (1)
- {
- SHA1_Context sha1;
- SHA1_init(&sha1);
+ algo_run_tests(hmac_stackinit(SHA1_stackinit()),
+ tests_hmac_sha1, countof(tests_hmac_sha1));
- HMAC_Context hmac;
- HMAC_init(&hmac, &sha1.h);
-
- algo_run_tests(&hmac, tests_hmac_sha1, countof(tests_hmac_sha1));
- }
-
return 0;
}
-TEST_MAIN(HMAC);
+TEST_MAIN(hmac);