lib/crypto: add aes_cmac_128 chunked tests
authorStefan Metzmacher <metze@samba.org>
Tue, 11 Aug 2015 14:31:25 +0000 (16:31 +0200)
committerJeremy Allison <jra@samba.org>
Thu, 27 Aug 2015 18:23:20 +0000 (20:23 +0200)
BUG: https://bugzilla.samba.org/show_bug.cgi?id=11451

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
lib/crypto/aes_cmac_128_test.c

index 173087f06424ad927f4dc5d828b210c6e4a66041..86a2fd73d0a55106baec6446c9cc811412390cfe 100644 (file)
@@ -87,6 +87,32 @@ bool torture_local_crypto_aes_cmac_128(struct torture_context *torture)
                        ret = false;
                }
        }
+       for (i=0; testarray[i].cmac.length != 0; i++) {
+               struct aes_cmac_128_context ctx;
+               uint8_t cmac[AES_BLOCK_SIZE];
+               int e;
+               size_t j;
+
+               aes_cmac_128_init(&ctx, key.data);
+               for (j=0; j < testarray[i].data.length; j++) {
+                       aes_cmac_128_update(&ctx, NULL, 0);
+                       aes_cmac_128_update(&ctx,
+                                           &testarray[i].data.data[j],
+                                           1);
+                       aes_cmac_128_update(&ctx, NULL, 0);
+               }
+               aes_cmac_128_final(&ctx, cmac);
+
+               e = memcmp(testarray[i].cmac.data, cmac, sizeof(cmac));
+               if (e != 0) {
+                       printf("aes_cmac_128 chunked test[%u]: failed\n", i);
+                       dump_data(0, key.data, key.length);
+                       dump_data(0, testarray[i].data.data, testarray[i].data.length);
+                       dump_data(0, testarray[i].cmac.data, testarray[i].cmac.length);
+                       dump_data(0, cmac, sizeof(cmac));
+                       ret = false;
+               }
+       }
        talloc_free(tctx);
        return ret;
 }