aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2019-02-10 18:02:54 +0100
committerMattias Andrée <maandree@kth.se>2019-02-10 18:05:41 +0100
commit6a41e6dc9dda34bca8b528fd1a80e82f7ee7e64b (patch)
tree9b84efece50ccc48254650bec42aada372dcf5a8
parent... (diff)
downloadlibsha2-6a41e6dc9dda34bca8b528fd1a80e82f7ee7e64b.tar.gz
libsha2-6a41e6dc9dda34bca8b528fd1a80e82f7ee7e64b.tar.bz2
libsha2-6a41e6dc9dda34bca8b528fd1a80e82f7ee7e64b.tar.xz
Add tests for HMAC
Signed-off-by: Mattias Andrée <maandree@kth.se>
-rw-r--r--test.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/test.c b/test.c
index 87da91f..9eb34a6 100644
--- a/test.c
+++ b/test.c
@@ -77,6 +77,7 @@ main(int argc, char *argv[])
{
char buf[8096], str[2048];
struct libsha2_state s;
+ struct libsha2_hmac_state hs;
int skip_huge, fds[2], status;
size_t i, j, n, len;
ssize_t r;
@@ -323,6 +324,30 @@ main(int argc, char *argv[])
test_bits("2b", 6, LIBSHA2_224, "44b64a6dbd91d49df5af0c9f8e001b1378e1dc29c4b891350e5d7bd9");
test_bits("0c", 7, LIBSHA2_224, "20f25c1fe299cf337ff7ff9cc4b5b5afac076759720174a29ba79db6");
+ test(!libsha2_hmac_init(&hs, LIBSHA2_256, "", 0));
+ test(libsha2_hmac_state_output_size(&hs) == 32);
+ libsha2_hmac_digest(&hs, "", 0, buf);
+ libsha2_behex_lower(str, buf, libsha2_hmac_state_output_size(&hs));
+ test_str(str, "b613679a0814d9ec772f95d778c35fc5ff1697c493715653c6c712144292c5ad");
+
+ test(!libsha2_hmac_init(&hs, LIBSHA2_256, "key", 3 << 3));
+ test(libsha2_hmac_state_output_size(&hs) == 32);
+ libsha2_hmac_digest(&hs, "The quick brown fox jumps over the lazy dog",
+ (sizeof("The quick brown fox jumps over the lazy dog") - 1) << 3, buf);
+ libsha2_behex_lower(str, buf, libsha2_hmac_state_output_size(&hs));
+ test_str(str, "f7bc83f430538424b13298e6aa6fb143ef4d59a14946175997479dbc2d1a3cd8");
+
+ n = sizeof("The quick brown fox jumps over the lazy dog") - 1;
+ for (i = 1; i < n; i++) {
+ test(!libsha2_hmac_init(&hs, LIBSHA2_256, "key", 3 << 3));
+ test(libsha2_hmac_state_output_size(&hs) == 32);
+ for (j = 0; j + i < n; j += i)
+ libsha2_hmac_update(&hs, &"The quick brown fox jumps over the lazy dog"[j], i << 3);
+ libsha2_hmac_digest(&hs, &"The quick brown fox jumps over the lazy dog"[j], (n - j) << 3, buf);
+ libsha2_behex_lower(str, buf, libsha2_hmac_state_output_size(&hs));
+ test_str(str, "f7bc83f430538424b13298e6aa6fb143ef4d59a14946175997479dbc2d1a3cd8");
+ }
+
test(!errno);
return 0;