diff options
author | Niels Möller <nisse@lysator.liu.se> | 2022-01-24 18:58:54 +0100 |
---|---|---|
committer | Niels Möller <nisse@lysator.liu.se> | 2022-01-24 18:58:54 +0100 |
commit | 4adcb4af1c3873b4bdf0f5c81306917ceb44e3f5 (patch) | |
tree | 906db58048fc48e8635fc9fe3f51cefa19745a9e | |
parent | b48217c8058676c8cd2fd12cdeba457755ace309 (diff) | |
download | nettle-4adcb4af1c3873b4bdf0f5c81306917ceb44e3f5.tar.gz |
Simplify poly1305-test, more use of tstring length.
-rw-r--r-- | testsuite/poly1305-test.c | 45 |
1 files changed, 17 insertions, 28 deletions
diff --git a/testsuite/poly1305-test.c b/testsuite/poly1305-test.c index a1242ab8..8bca9dd6 100644 --- a/testsuite/poly1305-test.c +++ b/testsuite/poly1305-test.c @@ -4,29 +4,20 @@ #include "knuth-lfib.h" static void -update (void *ctx, nettle_hash_update_func *f, - const struct tstring *msg, - unsigned length) -{ - for (; length > msg->length; length -= msg->length) - f(ctx, msg->length, msg->data); - f(ctx, length, msg->data); -} - -static void check_digest (const char *name, void *ctx, nettle_hash_digest_func *f, - const struct tstring *msg, unsigned length, - unsigned tag_length, const uint8_t *ref) + const struct tstring *msg, + const struct tstring *ref) { uint8_t tag[16]; - f(ctx, tag_length, tag); - if (memcmp (tag, ref, tag_length) != 0) + ASSERT (ref->length <= 16); + f(ctx, ref->length, tag); + if (!MEMEQ(ref->length, ref->data, tag)) { printf ("%s failed\n", name); printf ("msg: "); print_hex (msg->length, msg->data); - printf ("length: %u\n", length); - printf ("tag: "); print_hex (tag_length, tag); - printf ("ref: "); print_hex (tag_length, ref); + printf ("length: %u\n", (unsigned) msg->length); + printf ("tag: "); print_hex (ref->length, tag); + printf ("ref: "); print_hex (ref->length, ref->data); abort (); } @@ -34,10 +25,9 @@ check_digest (const char *name, void *ctx, nettle_hash_digest_func *f, static void test_poly1305 (const struct tstring *key, - const struct tstring *nonce, - const struct tstring *msg, - unsigned length, - const struct tstring *ref) + const struct tstring *nonce, + const struct tstring *msg, + const struct tstring *ref) { struct poly1305_aes_ctx ctx; @@ -46,11 +36,10 @@ test_poly1305 (const struct tstring *key, poly1305_aes_set_key (&ctx, key->data); poly1305_aes_set_nonce (&ctx, nonce->data); - - update(&ctx, (nettle_hash_update_func *) poly1305_aes_update, msg, length); + poly1305_aes_update(&ctx, msg->length, msg->data); check_digest ("poly1305-aes", &ctx, (nettle_hash_digest_func *) poly1305_aes_digest, - msg, length, 16, ref->data); + msg, ref); } static void @@ -187,13 +176,13 @@ test_main(void) test_poly1305 (SHEX("75deaa25c09f208e1dc4ce6b5cad3fbfa0f3080000f46400d0c7e9076c834403"), SHEX("61ee09218d29b0aaed7e154a2c5509cc"), - SHEX(""), 0, + SHEX(""), SHEX("dd3fab2251f11ac759f0887129cc2ee7")); test_poly1305 (SHEX("ec074c835580741701425b623235add6851fc40c3467ac0be05cc20404f3f700"), SHEX("fb447350c4e868c52ac3275cf9d4327e"), - SHEX("f3f6"), 2, + SHEX("f3f6"), SHEX("f4c633c3044fc145f84f335cb81953de")); test_poly1305 @@ -201,7 +190,7 @@ test_main(void) "48443d0bb0d21109c89a100b5ce2c208"), SHEX("ae212a55399729595dea458bc621ff0e"), SHEX("663cea190ffb83d89593f3f476b6bc24" - "d7e679107ea26adb8caf6652d0656136"), 32, + "d7e679107ea26adb8caf6652d0656136"), SHEX("0ee1c16bb73f0f4fd19881753c01cdbe")); test_poly1305 @@ -209,7 +198,7 @@ test_main(void) SHEX("9ae831e743978d3a23527c7128149e3a"), SHEX("ab0812724a7f1e342742cbed374d94d136c6b8795d45b3819830f2c04491" "faf0990c62e48b8018b2c3e4a0fa3134cb67fa83e158c994d961c4cb2109" - "5c1bf9"), 63, + "5c1bf9"), SHEX("5154ad0d2cb26e01274fc51148491f1b")); test_random(); |