X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=bertos%2Fsec%2Fmac%2Fhmac_test.c;h=29b6620ec7be278555d04c62da9fc2f9e5642283;hb=4daa23797d71debc7f85987f76ba2c69ef6cd8a1;hp=8b1609643e9879582981bd041a8043ca94da30d1;hpb=ffcd73346399453a46d47c920545a10885ed42f9;p=bertos.git diff --git a/bertos/sec/mac/hmac_test.c b/bertos/sec/mac/hmac_test.c index 8b160964..29b6620e 100644 --- a/bertos/sec/mac/hmac_test.c +++ b/bertos/sec/mac/hmac_test.c @@ -151,42 +151,24 @@ const struct Test_HMAC tests_hmac_sha1[] = }, }; -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; im, (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) { - 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); - - HMAC_Context hmac; - HMAC_init(&hmac, &sha1.h); - - algo_run_tests(&hmac, tests_hmac_sha1, countof(tests_hmac_sha1)); - } - - return 0; + algo_run_tests(HMAC_stackinit(SHA1_stackinit()), + tests_hmac_sha1, countof(tests_hmac_sha1)); } TEST_MAIN(HMAC);