3 Copyright (C) Stefan Metzmacher 2012
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #include "../lib/util/samba_util.h"
20 #include "lib/crypto/aes.h"
21 #include "lib/crypto/aes_cmac_128.h"
23 struct torture_context;
24 bool torture_local_crypto_aes_cmac_128(struct torture_context *torture);
27 This uses the test values from rfc 4493
29 bool torture_local_crypto_aes_cmac_128(struct torture_context *torture)
39 TALLOC_CTX *tctx = talloc_new(torture);
40 if (!tctx) { return false; };
42 key = strhex_to_data_blob(tctx, "2b7e151628aed2a6abf7158809cf4f3c");
44 testarray[0].data = data_blob_null;
45 testarray[0].cmac = strhex_to_data_blob(tctx,
46 "bb1d6929e95937287fa37d129b756746");
48 testarray[1].data = strhex_to_data_blob(tctx,
49 "6bc1bee22e409f96e93d7e117393172a");
50 testarray[1].cmac = strhex_to_data_blob(tctx,
51 "070a16b46b4d4144f79bdd9dd04a287c");
53 testarray[2].data = strhex_to_data_blob(tctx,
54 "6bc1bee22e409f96e93d7e117393172a"
55 "ae2d8a571e03ac9c9eb76fac45af8e51"
57 testarray[2].cmac = strhex_to_data_blob(tctx,
58 "dfa66747de9ae63030ca32611497c827");
60 testarray[3].data = strhex_to_data_blob(tctx,
61 "6bc1bee22e409f96e93d7e117393172a"
62 "ae2d8a571e03ac9c9eb76fac45af8e51"
63 "30c81c46a35ce411e5fbc1191a0a52ef"
64 "f69f2445df4f9b17ad2b417be66c3710");
65 testarray[3].cmac = strhex_to_data_blob(tctx,
66 "51f0bebf7e3b9d92fc49741779363cfe");
68 ZERO_STRUCT(testarray[4]);
70 for (i=0; testarray[i].cmac.length != 0; i++) {
71 struct aes_cmac_128_context ctx;
72 uint8_t cmac[AES_BLOCK_SIZE];
75 aes_cmac_128_init(&ctx, key.data);
76 aes_cmac_128_update(&ctx,
77 testarray[i].data.data,
78 testarray[i].data.length);
79 aes_cmac_128_final(&ctx, cmac);
81 e = memcmp(testarray[i].cmac.data, cmac, sizeof(cmac));
83 printf("aes_cmac_128 test[%u]: failed\n", i);
84 dump_data(0, key.data, key.length);
85 dump_data(0, testarray[i].data.data, testarray[i].data.length);
86 dump_data(0, testarray[i].cmac.data, testarray[i].cmac.length);
87 dump_data(0, cmac, sizeof(cmac));
91 for (i=0; testarray[i].cmac.length != 0; i++) {
92 struct aes_cmac_128_context ctx;
93 uint8_t cmac[AES_BLOCK_SIZE];
97 aes_cmac_128_init(&ctx, key.data);
98 for (j=0; j < testarray[i].data.length; j++) {
99 aes_cmac_128_update(&ctx, NULL, 0);
100 aes_cmac_128_update(&ctx,
101 &testarray[i].data.data[j],
103 aes_cmac_128_update(&ctx, NULL, 0);
105 aes_cmac_128_final(&ctx, cmac);
107 e = memcmp(testarray[i].cmac.data, cmac, sizeof(cmac));
109 printf("aes_cmac_128 chunked test[%u]: failed\n", i);
110 dump_data(0, key.data, key.length);
111 dump_data(0, testarray[i].data.data, testarray[i].data.length);
112 dump_data(0, testarray[i].cmac.data, testarray[i].cmac.length);
113 dump_data(0, cmac, sizeof(cmac));