diff options
author | Jussi Kivilinna <jussi.kivilinna@iki.fi> | 2013-04-08 03:48:44 -0400 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2013-04-25 09:01:47 -0400 |
commit | 93b5e86a6d13c5dec18c6611933fb38d7d80f0d2 (patch) | |
tree | d30e88d098a44877a8701320f2a17073da37ff71 /crypto | |
parent | e448370d7377f064c2fef55f72e9b45184bf0926 (diff) |
crypto: add CMAC support to CryptoAPI
Patch adds support for NIST recommended block cipher mode CMAC to CryptoAPI.
This work is based on Tom St Denis' earlier patch,
http://marc.info/?l=linux-crypto-vger&m=135877306305466&w=2
Cc: Tom St Denis <tstdenis@elliptictech.com>
Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
Acked-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/Kconfig | 11 | ||||
-rw-r--r-- | crypto/Makefile | 1 | ||||
-rw-r--r-- | crypto/cmac.c | 315 | ||||
-rw-r--r-- | crypto/tcrypt.c | 11 | ||||
-rw-r--r-- | crypto/testmgr.c | 18 | ||||
-rw-r--r-- | crypto/testmgr.h | 125 |
6 files changed, 480 insertions, 1 deletions
diff --git a/crypto/Kconfig b/crypto/Kconfig index 6cc27f111551..c1142f31a00c 100644 --- a/crypto/Kconfig +++ b/crypto/Kconfig | |||
@@ -283,6 +283,17 @@ config CRYPTO_XTS | |||
283 | 283 | ||
284 | comment "Hash modes" | 284 | comment "Hash modes" |
285 | 285 | ||
286 | config CRYPTO_CMAC | ||
287 | tristate "CMAC support" | ||
288 | select CRYPTO_HASH | ||
289 | select CRYPTO_MANAGER | ||
290 | help | ||
291 | Cipher-based Message Authentication Code (CMAC) specified by | ||
292 | The National Institute of Standards and Technology (NIST). | ||
293 | |||
294 | https://tools.ietf.org/html/rfc4493 | ||
295 | http://csrc.nist.gov/publications/nistpubs/800-38B/SP_800-38B.pdf | ||
296 | |||
286 | config CRYPTO_HMAC | 297 | config CRYPTO_HMAC |
287 | tristate "HMAC support" | 298 | tristate "HMAC support" |
288 | select CRYPTO_HASH | 299 | select CRYPTO_HASH |
diff --git a/crypto/Makefile b/crypto/Makefile index be1a1bebbb86..a8e9b0fefbe9 100644 --- a/crypto/Makefile +++ b/crypto/Makefile | |||
@@ -32,6 +32,7 @@ cryptomgr-y := algboss.o testmgr.o | |||
32 | 32 | ||
33 | obj-$(CONFIG_CRYPTO_MANAGER2) += cryptomgr.o | 33 | obj-$(CONFIG_CRYPTO_MANAGER2) += cryptomgr.o |
34 | obj-$(CONFIG_CRYPTO_USER) += crypto_user.o | 34 | obj-$(CONFIG_CRYPTO_USER) += crypto_user.o |
35 | obj-$(CONFIG_CRYPTO_CMAC) += cmac.o | ||
35 | obj-$(CONFIG_CRYPTO_HMAC) += hmac.o | 36 | obj-$(CONFIG_CRYPTO_HMAC) += hmac.o |
36 | obj-$(CONFIG_CRYPTO_VMAC) += vmac.o | 37 | obj-$(CONFIG_CRYPTO_VMAC) += vmac.o |
37 | obj-$(CONFIG_CRYPTO_XCBC) += xcbc.o | 38 | obj-$(CONFIG_CRYPTO_XCBC) += xcbc.o |
diff --git a/crypto/cmac.c b/crypto/cmac.c new file mode 100644 index 000000000000..50880cf17fad --- /dev/null +++ b/crypto/cmac.c | |||
@@ -0,0 +1,315 @@ | |||
1 | /* | ||
2 | * CMAC: Cipher Block Mode for Authentication | ||
3 | * | ||
4 | * Copyright © 2013 Jussi Kivilinna <jussi.kivilinna@iki.fi> | ||
5 | * | ||
6 | * Based on work by: | ||
7 | * Copyright © 2013 Tom St Denis <tstdenis@elliptictech.com> | ||
8 | * Based on crypto/xcbc.c: | ||
9 | * Copyright © 2006 USAGI/WIDE Project, | ||
10 | * Author: Kazunori Miyazawa <miyazawa@linux-ipv6.org> | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or modify | ||
13 | * it under the terms of the GNU General Public License as published by | ||
14 | * the Free Software Foundation; either version 2 of the License, or | ||
15 | * (at your option) any later version. | ||
16 | * | ||
17 | */ | ||
18 | |||
19 | #include <crypto/internal/hash.h> | ||
20 | #include <linux/err.h> | ||
21 | #include <linux/kernel.h> | ||
22 | #include <linux/module.h> | ||
23 | |||
24 | /* | ||
25 | * +------------------------ | ||
26 | * | <parent tfm> | ||
27 | * +------------------------ | ||
28 | * | cmac_tfm_ctx | ||
29 | * +------------------------ | ||
30 | * | consts (block size * 2) | ||
31 | * +------------------------ | ||
32 | */ | ||
33 | struct cmac_tfm_ctx { | ||
34 | struct crypto_cipher *child; | ||
35 | u8 ctx[]; | ||
36 | }; | ||
37 | |||
38 | /* | ||
39 | * +------------------------ | ||
40 | * | <shash desc> | ||
41 | * +------------------------ | ||
42 | * | cmac_desc_ctx | ||
43 | * +------------------------ | ||
44 | * | odds (block size) | ||
45 | * +------------------------ | ||
46 | * | prev (block size) | ||
47 | * +------------------------ | ||
48 | */ | ||
49 | struct cmac_desc_ctx { | ||
50 | unsigned int len; | ||
51 | u8 ctx[]; | ||
52 | }; | ||
53 | |||
54 | static int crypto_cmac_digest_setkey(struct crypto_shash *parent, | ||
55 | const u8 *inkey, unsigned int keylen) | ||
56 | { | ||
57 | unsigned long alignmask = crypto_shash_alignmask(parent); | ||
58 | struct cmac_tfm_ctx *ctx = crypto_shash_ctx(parent); | ||
59 | unsigned int bs = crypto_shash_blocksize(parent); | ||
60 | __be64 *consts = PTR_ALIGN((void *)ctx->ctx, alignmask + 1); | ||
61 | u64 _const[2]; | ||
62 | int i, err = 0; | ||
63 | u8 msb_mask, gfmask; | ||
64 | |||
65 | err = crypto_cipher_setkey(ctx->child, inkey, keylen); | ||
66 | if (err) | ||
67 | return err; | ||
68 | |||
69 | /* encrypt the zero block */ | ||
70 | memset(consts, 0, bs); | ||
71 | crypto_cipher_encrypt_one(ctx->child, (u8 *)consts, (u8 *)consts); | ||
72 | |||
73 | switch (bs) { | ||
74 | case 16: | ||
75 | gfmask = 0x87; | ||
76 | _const[0] = be64_to_cpu(consts[1]); | ||
77 | _const[1] = be64_to_cpu(consts[0]); | ||
78 | |||
79 | /* gf(2^128) multiply zero-ciphertext with u and u^2 */ | ||
80 | for (i = 0; i < 4; i += 2) { | ||
81 | msb_mask = ((s64)_const[1] >> 63) & gfmask; | ||
82 | _const[1] = (_const[1] << 1) | (_const[0] >> 63); | ||
83 | _const[0] = (_const[0] << 1) ^ msb_mask; | ||
84 | |||
85 | consts[i + 0] = cpu_to_be64(_const[1]); | ||
86 | consts[i + 1] = cpu_to_be64(_const[0]); | ||
87 | } | ||
88 | |||
89 | break; | ||
90 | case 8: | ||
91 | gfmask = 0x1B; | ||
92 | _const[0] = be64_to_cpu(consts[0]); | ||
93 | |||
94 | /* gf(2^64) multiply zero-ciphertext with u and u^2 */ | ||
95 | for (i = 0; i < 2; i++) { | ||
96 | msb_mask = ((s64)_const[0] >> 63) & gfmask; | ||
97 | _const[0] = (_const[0] << 1) ^ msb_mask; | ||
98 | |||
99 | consts[i] = cpu_to_be64(_const[0]); | ||
100 | } | ||
101 | |||
102 | break; | ||
103 | } | ||
104 | |||
105 | return 0; | ||
106 | } | ||
107 | |||
108 | static int crypto_cmac_digest_init(struct shash_desc *pdesc) | ||
109 | { | ||
110 | unsigned long alignmask = crypto_shash_alignmask(pdesc->tfm); | ||
111 | struct cmac_desc_ctx *ctx = shash_desc_ctx(pdesc); | ||
112 | int bs = crypto_shash_blocksize(pdesc->tfm); | ||
113 | u8 *prev = PTR_ALIGN((void *)ctx->ctx, alignmask + 1) + bs; | ||
114 | |||
115 | ctx->len = 0; | ||
116 | memset(prev, 0, bs); | ||
117 | |||
118 | return 0; | ||
119 | } | ||
120 | |||
121 | static int crypto_cmac_digest_update(struct shash_desc *pdesc, const u8 *p, | ||
122 | unsigned int len) | ||
123 | { | ||
124 | struct crypto_shash *parent = pdesc->tfm; | ||
125 | unsigned long alignmask = crypto_shash_alignmask(parent); | ||
126 | struct cmac_tfm_ctx *tctx = crypto_shash_ctx(parent); | ||
127 | struct cmac_desc_ctx *ctx = shash_desc_ctx(pdesc); | ||
128 | struct crypto_cipher *tfm = tctx->child; | ||
129 | int bs = crypto_shash_blocksize(parent); | ||
130 | u8 *odds = PTR_ALIGN((void *)ctx->ctx, alignmask + 1); | ||
131 | u8 *prev = odds + bs; | ||
132 | |||
133 | /* checking the data can fill the block */ | ||
134 | if ((ctx->len + len) <= bs) { | ||
135 | memcpy(odds + ctx->len, p, len); | ||
136 | ctx->len += len; | ||
137 | return 0; | ||
138 | } | ||
139 | |||
140 | /* filling odds with new data and encrypting it */ | ||
141 | memcpy(odds + ctx->len, p, bs - ctx->len); | ||
142 | len -= bs - ctx->len; | ||
143 | p += bs - ctx->len; | ||
144 | |||
145 | crypto_xor(prev, odds, bs); | ||
146 | crypto_cipher_encrypt_one(tfm, prev, prev); | ||
147 | |||
148 | /* clearing the length */ | ||
149 | ctx->len = 0; | ||
150 | |||
151 | /* encrypting the rest of data */ | ||
152 | while (len > bs) { | ||
153 | crypto_xor(prev, p, bs); | ||
154 | crypto_cipher_encrypt_one(tfm, prev, prev); | ||
155 | p += bs; | ||
156 | len -= bs; | ||
157 | } | ||
158 | |||
159 | /* keeping the surplus of blocksize */ | ||
160 | if (len) { | ||
161 | memcpy(odds, p, len); | ||
162 | ctx->len = len; | ||
163 | } | ||
164 | |||
165 | return 0; | ||
166 | } | ||
167 | |||
168 | static int crypto_cmac_digest_final(struct shash_desc *pdesc, u8 *out) | ||
169 | { | ||
170 | struct crypto_shash *parent = pdesc->tfm; | ||
171 | unsigned long alignmask = crypto_shash_alignmask(parent); | ||
172 | struct cmac_tfm_ctx *tctx = crypto_shash_ctx(parent); | ||
173 | struct cmac_desc_ctx *ctx = shash_desc_ctx(pdesc); | ||
174 | struct crypto_cipher *tfm = tctx->child; | ||
175 | int bs = crypto_shash_blocksize(parent); | ||
176 | u8 *consts = PTR_ALIGN((void *)tctx->ctx, alignmask + 1); | ||
177 | u8 *odds = PTR_ALIGN((void *)ctx->ctx, alignmask + 1); | ||
178 | u8 *prev = odds + bs; | ||
179 | unsigned int offset = 0; | ||
180 | |||
181 | if (ctx->len != bs) { | ||
182 | unsigned int rlen; | ||
183 | u8 *p = odds + ctx->len; | ||
184 | |||
185 | *p = 0x80; | ||
186 | p++; | ||
187 | |||
188 | rlen = bs - ctx->len - 1; | ||
189 | if (rlen) | ||
190 | memset(p, 0, rlen); | ||
191 | |||
192 | offset += bs; | ||
193 | } | ||
194 | |||
195 | crypto_xor(prev, odds, bs); | ||
196 | crypto_xor(prev, consts + offset, bs); | ||
197 | |||
198 | crypto_cipher_encrypt_one(tfm, out, prev); | ||
199 | |||
200 | return 0; | ||
201 | } | ||
202 | |||
203 | static int cmac_init_tfm(struct crypto_tfm *tfm) | ||
204 | { | ||
205 | struct crypto_cipher *cipher; | ||
206 | struct crypto_instance *inst = (void *)tfm->__crt_alg; | ||
207 | struct crypto_spawn *spawn = crypto_instance_ctx(inst); | ||
208 | struct cmac_tfm_ctx *ctx = crypto_tfm_ctx(tfm); | ||
209 | |||
210 | cipher = crypto_spawn_cipher(spawn); | ||
211 | if (IS_ERR(cipher)) | ||
212 | return PTR_ERR(cipher); | ||
213 | |||
214 | ctx->child = cipher; | ||
215 | |||
216 | return 0; | ||
217 | }; | ||
218 | |||
219 | static void cmac_exit_tfm(struct crypto_tfm *tfm) | ||
220 | { | ||
221 | struct cmac_tfm_ctx *ctx = crypto_tfm_ctx(tfm); | ||
222 | crypto_free_cipher(ctx->child); | ||
223 | } | ||
224 | |||
225 | static int cmac_create(struct crypto_template *tmpl, struct rtattr **tb) | ||
226 | { | ||
227 | struct shash_instance *inst; | ||
228 | struct crypto_alg *alg; | ||
229 | unsigned long alignmask; | ||
230 | int err; | ||
231 | |||
232 | err = crypto_check_attr_type(tb, CRYPTO_ALG_TYPE_SHASH); | ||
233 | if (err) | ||
234 | return err; | ||
235 | |||
236 | alg = crypto_get_attr_alg(tb, CRYPTO_ALG_TYPE_CIPHER, | ||
237 | CRYPTO_ALG_TYPE_MASK); | ||
238 | if (IS_ERR(alg)) | ||
239 | return PTR_ERR(alg); | ||
240 | |||
241 | switch (alg->cra_blocksize) { | ||
242 | case 16: | ||
243 | case 8: | ||
244 | break; | ||
245 | default: | ||
246 | goto out_put_alg; | ||
247 | } | ||
248 | |||
249 | inst = shash_alloc_instance("cmac", alg); | ||
250 | err = PTR_ERR(inst); | ||
251 | if (IS_ERR(inst)) | ||
252 | goto out_put_alg; | ||
253 | |||
254 | err = crypto_init_spawn(shash_instance_ctx(inst), alg, | ||
255 | shash_crypto_instance(inst), | ||
256 | CRYPTO_ALG_TYPE_MASK); | ||
257 | if (err) | ||
258 | goto out_free_inst; | ||
259 | |||
260 | alignmask = alg->cra_alignmask | (sizeof(long) - 1); | ||
261 | inst->alg.base.cra_alignmask = alignmask; | ||
262 | inst->alg.base.cra_priority = alg->cra_priority; | ||
263 | inst->alg.base.cra_blocksize = alg->cra_blocksize; | ||
264 | |||
265 | inst->alg.digestsize = alg->cra_blocksize; | ||
266 | inst->alg.descsize = | ||
267 | ALIGN(sizeof(struct cmac_desc_ctx), crypto_tfm_ctx_alignment()) | ||
268 | + (alignmask & ~(crypto_tfm_ctx_alignment() - 1)) | ||
269 | + alg->cra_blocksize * 2; | ||
270 | |||
271 | inst->alg.base.cra_ctxsize = | ||
272 | ALIGN(sizeof(struct cmac_tfm_ctx), alignmask + 1) | ||
273 | + alg->cra_blocksize * 2; | ||
274 | |||
275 | inst->alg.base.cra_init = cmac_init_tfm; | ||
276 | inst->alg.base.cra_exit = cmac_exit_tfm; | ||
277 | |||
278 | inst->alg.init = crypto_cmac_digest_init; | ||
279 | inst->alg.update = crypto_cmac_digest_update; | ||
280 | inst->alg.final = crypto_cmac_digest_final; | ||
281 | inst->alg.setkey = crypto_cmac_digest_setkey; | ||
282 | |||
283 | err = shash_register_instance(tmpl, inst); | ||
284 | if (err) { | ||
285 | out_free_inst: | ||
286 | shash_free_instance(shash_crypto_instance(inst)); | ||
287 | } | ||
288 | |||
289 | out_put_alg: | ||
290 | crypto_mod_put(alg); | ||
291 | return err; | ||
292 | } | ||
293 | |||
294 | static struct crypto_template crypto_cmac_tmpl = { | ||
295 | .name = "cmac", | ||
296 | .create = cmac_create, | ||
297 | .free = shash_free_instance, | ||
298 | .module = THIS_MODULE, | ||
299 | }; | ||
300 | |||
301 | static int __init crypto_cmac_module_init(void) | ||
302 | { | ||
303 | return crypto_register_template(&crypto_cmac_tmpl); | ||
304 | } | ||
305 | |||
306 | static void __exit crypto_cmac_module_exit(void) | ||
307 | { | ||
308 | crypto_unregister_template(&crypto_cmac_tmpl); | ||
309 | } | ||
310 | |||
311 | module_init(crypto_cmac_module_init); | ||
312 | module_exit(crypto_cmac_module_exit); | ||
313 | |||
314 | MODULE_LICENSE("GPL"); | ||
315 | MODULE_DESCRIPTION("CMAC keyed hash algorithm"); | ||
diff --git a/crypto/tcrypt.c b/crypto/tcrypt.c index 6b911ef8df8b..24ea7dffd21e 100644 --- a/crypto/tcrypt.c +++ b/crypto/tcrypt.c | |||
@@ -1095,7 +1095,6 @@ static int do_test(int m) | |||
1095 | break; | 1095 | break; |
1096 | 1096 | ||
1097 | case 28: | 1097 | case 28: |
1098 | |||
1099 | ret += tcrypt_test("tgr160"); | 1098 | ret += tcrypt_test("tgr160"); |
1100 | break; | 1099 | break; |
1101 | 1100 | ||
@@ -1118,6 +1117,7 @@ static int do_test(int m) | |||
1118 | ret += tcrypt_test("lrw(camellia)"); | 1117 | ret += tcrypt_test("lrw(camellia)"); |
1119 | ret += tcrypt_test("xts(camellia)"); | 1118 | ret += tcrypt_test("xts(camellia)"); |
1120 | break; | 1119 | break; |
1120 | |||
1121 | case 33: | 1121 | case 33: |
1122 | ret += tcrypt_test("sha224"); | 1122 | ret += tcrypt_test("sha224"); |
1123 | break; | 1123 | break; |
@@ -1213,6 +1213,7 @@ static int do_test(int m) | |||
1213 | case 109: | 1213 | case 109: |
1214 | ret += tcrypt_test("vmac(aes)"); | 1214 | ret += tcrypt_test("vmac(aes)"); |
1215 | break; | 1215 | break; |
1216 | |||
1216 | case 110: | 1217 | case 110: |
1217 | ret += tcrypt_test("hmac(crc32)"); | 1218 | ret += tcrypt_test("hmac(crc32)"); |
1218 | break; | 1219 | break; |
@@ -1229,6 +1230,14 @@ static int do_test(int m) | |||
1229 | ret += tcrypt_test("rfc4543(gcm(aes))"); | 1230 | ret += tcrypt_test("rfc4543(gcm(aes))"); |
1230 | break; | 1231 | break; |
1231 | 1232 | ||
1233 | case 153: | ||
1234 | ret += tcrypt_test("cmac(aes)"); | ||
1235 | break; | ||
1236 | |||
1237 | case 154: | ||
1238 | ret += tcrypt_test("cmac(des3_ede)"); | ||
1239 | break; | ||
1240 | |||
1232 | case 200: | 1241 | case 200: |
1233 | test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0, | 1242 | test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0, |
1234 | speed_template_16_24_32); | 1243 | speed_template_16_24_32); |
diff --git a/crypto/testmgr.c b/crypto/testmgr.c index f37e544dddf0..380708477b35 100644 --- a/crypto/testmgr.c +++ b/crypto/testmgr.c | |||
@@ -1913,6 +1913,24 @@ static const struct alg_test_desc alg_test_descs[] = { | |||
1913 | } | 1913 | } |
1914 | } | 1914 | } |
1915 | }, { | 1915 | }, { |
1916 | .alg = "cmac(aes)", | ||
1917 | .test = alg_test_hash, | ||
1918 | .suite = { | ||
1919 | .hash = { | ||
1920 | .vecs = aes_cmac128_tv_template, | ||
1921 | .count = CMAC_AES_TEST_VECTORS | ||
1922 | } | ||
1923 | } | ||
1924 | }, { | ||
1925 | .alg = "cmac(des3_ede)", | ||
1926 | .test = alg_test_hash, | ||
1927 | .suite = { | ||
1928 | .hash = { | ||
1929 | .vecs = des3_ede_cmac64_tv_template, | ||
1930 | .count = CMAC_DES3_EDE_TEST_VECTORS | ||
1931 | } | ||
1932 | } | ||
1933 | }, { | ||
1916 | .alg = "compress_null", | 1934 | .alg = "compress_null", |
1917 | .test = alg_test_null, | 1935 | .test = alg_test_null, |
1918 | }, { | 1936 | }, { |
diff --git a/crypto/testmgr.h b/crypto/testmgr.h index 92db37dda757..d50366092b1a 100644 --- a/crypto/testmgr.h +++ b/crypto/testmgr.h | |||
@@ -1639,6 +1639,131 @@ static struct hash_testvec hmac_sha256_tv_template[] = { | |||
1639 | }, | 1639 | }, |
1640 | }; | 1640 | }; |
1641 | 1641 | ||
1642 | #define CMAC_AES_TEST_VECTORS 6 | ||
1643 | |||
1644 | static struct hash_testvec aes_cmac128_tv_template[] = { | ||
1645 | { /* From NIST Special Publication 800-38B, AES-128 */ | ||
1646 | .key = "\x2b\x7e\x15\x16\x28\xae\xd2\xa6" | ||
1647 | "\xab\xf7\x15\x88\x09\xcf\x4f\x3c", | ||
1648 | .plaintext = zeroed_string, | ||
1649 | .digest = "\xbb\x1d\x69\x29\xe9\x59\x37\x28" | ||
1650 | "\x7f\xa3\x7d\x12\x9b\x75\x67\x46", | ||
1651 | .psize = 0, | ||
1652 | .ksize = 16, | ||
1653 | }, { | ||
1654 | .key = "\x2b\x7e\x15\x16\x28\xae\xd2\xa6" | ||
1655 | "\xab\xf7\x15\x88\x09\xcf\x4f\x3c", | ||
1656 | .plaintext = "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96" | ||
1657 | "\xe9\x3d\x7e\x11\x73\x93\x17\x2a", | ||
1658 | .digest = "\x07\x0a\x16\xb4\x6b\x4d\x41\x44" | ||
1659 | "\xf7\x9b\xdd\x9d\xd0\x4a\x28\x7c", | ||
1660 | .psize = 16, | ||
1661 | .ksize = 16, | ||
1662 | }, { | ||
1663 | .key = "\x2b\x7e\x15\x16\x28\xae\xd2\xa6" | ||
1664 | "\xab\xf7\x15\x88\x09\xcf\x4f\x3c", | ||
1665 | .plaintext = "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96" | ||
1666 | "\xe9\x3d\x7e\x11\x73\x93\x17\x2a" | ||
1667 | "\xae\x2d\x8a\x57\x1e\x03\xac\x9c" | ||
1668 | "\x9e\xb7\x6f\xac\x45\xaf\x8e\x51" | ||
1669 | "\x30\xc8\x1c\x46\xa3\x5c\xe4\x11", | ||
1670 | .digest = "\xdf\xa6\x67\x47\xde\x9a\xe6\x30" | ||
1671 | "\x30\xca\x32\x61\x14\x97\xc8\x27", | ||
1672 | .psize = 40, | ||
1673 | .ksize = 16, | ||
1674 | }, { | ||
1675 | .key = "\x2b\x7e\x15\x16\x28\xae\xd2\xa6" | ||
1676 | "\xab\xf7\x15\x88\x09\xcf\x4f\x3c", | ||
1677 | .plaintext = "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96" | ||
1678 | "\xe9\x3d\x7e\x11\x73\x93\x17\x2a" | ||
1679 | "\xae\x2d\x8a\x57\x1e\x03\xac\x9c" | ||
1680 | "\x9e\xb7\x6f\xac\x45\xaf\x8e\x51" | ||
1681 | "\x30\xc8\x1c\x46\xa3\x5c\xe4\x11" | ||
1682 | "\xe5\xfb\xc1\x19\x1a\x0a\x52\xef" | ||
1683 | "\xf6\x9f\x24\x45\xdf\x4f\x9b\x17" | ||
1684 | "\xad\x2b\x41\x7b\xe6\x6c\x37\x10", | ||
1685 | .digest = "\x51\xf0\xbe\xbf\x7e\x3b\x9d\x92" | ||
1686 | "\xfc\x49\x74\x17\x79\x36\x3c\xfe", | ||
1687 | .psize = 64, | ||
1688 | .ksize = 16, | ||
1689 | }, { /* From NIST Special Publication 800-38B, AES-256 */ | ||
1690 | .key = "\x60\x3d\xeb\x10\x15\xca\x71\xbe" | ||
1691 | "\x2b\x73\xae\xf0\x85\x7d\x77\x81" | ||
1692 | "\x1f\x35\x2c\x07\x3b\x61\x08\xd7" | ||
1693 | "\x2d\x98\x10\xa3\x09\x14\xdf\xf4", | ||
1694 | .plaintext = zeroed_string, | ||
1695 | .digest = "\x02\x89\x62\xf6\x1b\x7b\xf8\x9e" | ||
1696 | "\xfc\x6b\x55\x1f\x46\x67\xd9\x83", | ||
1697 | .psize = 0, | ||
1698 | .ksize = 32, | ||
1699 | }, { | ||
1700 | .key = "\x60\x3d\xeb\x10\x15\xca\x71\xbe" | ||
1701 | "\x2b\x73\xae\xf0\x85\x7d\x77\x81" | ||
1702 | "\x1f\x35\x2c\x07\x3b\x61\x08\xd7" | ||
1703 | "\x2d\x98\x10\xa3\x09\x14\xdf\xf4", | ||
1704 | .plaintext = "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96" | ||
1705 | "\xe9\x3d\x7e\x11\x73\x93\x17\x2a" | ||
1706 | "\xae\x2d\x8a\x57\x1e\x03\xac\x9c" | ||
1707 | "\x9e\xb7\x6f\xac\x45\xaf\x8e\x51" | ||
1708 | "\x30\xc8\x1c\x46\xa3\x5c\xe4\x11" | ||
1709 | "\xe5\xfb\xc1\x19\x1a\x0a\x52\xef" | ||
1710 | "\xf6\x9f\x24\x45\xdf\x4f\x9b\x17" | ||
1711 | "\xad\x2b\x41\x7b\xe6\x6c\x37\x10", | ||
1712 | .digest = "\xe1\x99\x21\x90\x54\x9f\x6e\xd5" | ||
1713 | "\x69\x6a\x2c\x05\x6c\x31\x54\x10", | ||
1714 | .psize = 64, | ||
1715 | .ksize = 32, | ||
1716 | } | ||
1717 | }; | ||
1718 | |||
1719 | #define CMAC_DES3_EDE_TEST_VECTORS 4 | ||
1720 | |||
1721 | static struct hash_testvec des3_ede_cmac64_tv_template[] = { | ||
1722 | /* | ||
1723 | * From NIST Special Publication 800-38B, Three Key TDEA | ||
1724 | * Corrected test vectors from: | ||
1725 | * http://csrc.nist.gov/publications/nistpubs/800-38B/Updated_CMAC_Examples.pdf | ||
1726 | */ | ||
1727 | { | ||
1728 | .key = "\x8a\xa8\x3b\xf8\xcb\xda\x10\x62" | ||
1729 | "\x0b\xc1\xbf\x19\xfb\xb6\xcd\x58" | ||
1730 | "\xbc\x31\x3d\x4a\x37\x1c\xa8\xb5", | ||
1731 | .plaintext = zeroed_string, | ||
1732 | .digest = "\xb7\xa6\x88\xe1\x22\xff\xaf\x95", | ||
1733 | .psize = 0, | ||
1734 | .ksize = 24, | ||
1735 | }, { | ||
1736 | .key = "\x8a\xa8\x3b\xf8\xcb\xda\x10\x62" | ||
1737 | "\x0b\xc1\xbf\x19\xfb\xb6\xcd\x58" | ||
1738 | "\xbc\x31\x3d\x4a\x37\x1c\xa8\xb5", | ||
1739 | .plaintext = "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96", | ||
1740 | .digest = "\x8e\x8f\x29\x31\x36\x28\x37\x97", | ||
1741 | .psize = 8, | ||
1742 | .ksize = 24, | ||
1743 | }, { | ||
1744 | .key = "\x8a\xa8\x3b\xf8\xcb\xda\x10\x62" | ||
1745 | "\x0b\xc1\xbf\x19\xfb\xb6\xcd\x58" | ||
1746 | "\xbc\x31\x3d\x4a\x37\x1c\xa8\xb5", | ||
1747 | .plaintext = "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96" | ||
1748 | "\xe9\x3d\x7e\x11\x73\x93\x17\x2a" | ||
1749 | "\xae\x2d\x8a\x57", | ||
1750 | .digest = "\x74\x3d\xdb\xe0\xce\x2d\xc2\xed", | ||
1751 | .psize = 20, | ||
1752 | .ksize = 24, | ||
1753 | }, { | ||
1754 | .key = "\x8a\xa8\x3b\xf8\xcb\xda\x10\x62" | ||
1755 | "\x0b\xc1\xbf\x19\xfb\xb6\xcd\x58" | ||
1756 | "\xbc\x31\x3d\x4a\x37\x1c\xa8\xb5", | ||
1757 | .plaintext = "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96" | ||
1758 | "\xe9\x3d\x7e\x11\x73\x93\x17\x2a" | ||
1759 | "\xae\x2d\x8a\x57\x1e\x03\xac\x9c" | ||
1760 | "\x9e\xb7\x6f\xac\x45\xaf\x8e\x51", | ||
1761 | .digest = "\x33\xe6\xb1\x09\x24\x00\xea\xe5", | ||
1762 | .psize = 32, | ||
1763 | .ksize = 24, | ||
1764 | } | ||
1765 | }; | ||
1766 | |||
1642 | #define XCBC_AES_TEST_VECTORS 6 | 1767 | #define XCBC_AES_TEST_VECTORS 6 |
1643 | 1768 | ||
1644 | static struct hash_testvec aes_xcbc128_tv_template[] = { | 1769 | static struct hash_testvec aes_xcbc128_tv_template[] = { |