Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Algorithm testing framework and tests. |
| 3 | * |
| 4 | * Copyright (c) 2002 James Morris <jmorris@intercode.com.au> |
| 5 | * Copyright (c) 2002 Jean-Francois Dive <jef@linuxbe.org> |
| 6 | * Copyright (c) 2007 Nokia Siemens Networks |
| 7 | * Copyright (c) 2008 Herbert Xu <herbert@gondor.apana.org.au> |
| 8 | * |
Adrian Hoban | 69435b9 | 2010-11-04 15:02:04 -0400 | [diff] [blame] | 9 | * Updated RFC4106 AES-GCM testing. |
| 10 | * Authors: Aidan O'Mahony (aidan.o.mahony@intel.com) |
| 11 | * Adrian Hoban <adrian.hoban@intel.com> |
| 12 | * Gabriele Paoloni <gabriele.paoloni@intel.com> |
| 13 | * Tadeusz Struk (tadeusz.struk@intel.com) |
| 14 | * Copyright (c) 2010, Intel Corporation. |
| 15 | * |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 16 | * This program is free software; you can redistribute it and/or modify it |
| 17 | * under the terms of the GNU General Public License as published by the Free |
| 18 | * Software Foundation; either version 2 of the License, or (at your option) |
| 19 | * any later version. |
| 20 | * |
| 21 | */ |
| 22 | |
Herbert Xu | 1ce3311 | 2015-04-22 15:06:31 +0800 | [diff] [blame] | 23 | #include <crypto/aead.h> |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 24 | #include <crypto/hash.h> |
Herbert Xu | 12773d9 | 2015-08-20 15:21:46 +0800 | [diff] [blame] | 25 | #include <crypto/skcipher.h> |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 26 | #include <linux/err.h> |
Herbert Xu | 1c41b88 | 2015-04-22 13:25:58 +0800 | [diff] [blame] | 27 | #include <linux/fips.h> |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 28 | #include <linux/module.h> |
| 29 | #include <linux/scatterlist.h> |
| 30 | #include <linux/slab.h> |
| 31 | #include <linux/string.h> |
Jarod Wilson | 7647d6c | 2009-05-04 19:44:50 +0800 | [diff] [blame] | 32 | #include <crypto/rng.h> |
Stephan Mueller | 64d1cdf | 2014-05-31 17:25:36 +0200 | [diff] [blame] | 33 | #include <crypto/drbg.h> |
Tadeusz Struk | 946cc46 | 2015-06-16 10:31:06 -0700 | [diff] [blame] | 34 | #include <crypto/akcipher.h> |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 35 | |
| 36 | #include "internal.h" |
Alexander Shishkin | 0b767f9 | 2010-06-03 20:53:43 +1000 | [diff] [blame] | 37 | |
Herbert Xu | 326a634 | 2010-08-06 09:40:28 +0800 | [diff] [blame] | 38 | #ifdef CONFIG_CRYPTO_MANAGER_DISABLE_TESTS |
Alexander Shishkin | 0b767f9 | 2010-06-03 20:53:43 +1000 | [diff] [blame] | 39 | |
| 40 | /* a perfect nop */ |
| 41 | int alg_test(const char *driver, const char *alg, u32 type, u32 mask) |
| 42 | { |
| 43 | return 0; |
| 44 | } |
| 45 | |
| 46 | #else |
| 47 | |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 48 | #include "testmgr.h" |
| 49 | |
| 50 | /* |
| 51 | * Need slab memory for testing (size in number of pages). |
| 52 | */ |
| 53 | #define XBUFSIZE 8 |
| 54 | |
| 55 | /* |
| 56 | * Indexes into the xbuf to simulate cross-page access. |
| 57 | */ |
| 58 | #define IDX1 32 |
| 59 | #define IDX2 32400 |
| 60 | #define IDX3 1 |
| 61 | #define IDX4 8193 |
| 62 | #define IDX5 22222 |
| 63 | #define IDX6 17101 |
| 64 | #define IDX7 27333 |
| 65 | #define IDX8 3000 |
| 66 | |
| 67 | /* |
| 68 | * Used by test_cipher() |
| 69 | */ |
| 70 | #define ENCRYPT 1 |
| 71 | #define DECRYPT 0 |
| 72 | |
| 73 | struct tcrypt_result { |
| 74 | struct completion completion; |
| 75 | int err; |
| 76 | }; |
| 77 | |
| 78 | struct aead_test_suite { |
| 79 | struct { |
| 80 | struct aead_testvec *vecs; |
| 81 | unsigned int count; |
| 82 | } enc, dec; |
| 83 | }; |
| 84 | |
| 85 | struct cipher_test_suite { |
| 86 | struct { |
| 87 | struct cipher_testvec *vecs; |
| 88 | unsigned int count; |
| 89 | } enc, dec; |
| 90 | }; |
| 91 | |
| 92 | struct comp_test_suite { |
| 93 | struct { |
| 94 | struct comp_testvec *vecs; |
| 95 | unsigned int count; |
| 96 | } comp, decomp; |
| 97 | }; |
| 98 | |
Geert Uytterhoeven | 8064efb | 2009-03-04 15:08:03 +0800 | [diff] [blame] | 99 | struct pcomp_test_suite { |
| 100 | struct { |
| 101 | struct pcomp_testvec *vecs; |
| 102 | unsigned int count; |
| 103 | } comp, decomp; |
| 104 | }; |
| 105 | |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 106 | struct hash_test_suite { |
| 107 | struct hash_testvec *vecs; |
| 108 | unsigned int count; |
| 109 | }; |
| 110 | |
Jarod Wilson | 7647d6c | 2009-05-04 19:44:50 +0800 | [diff] [blame] | 111 | struct cprng_test_suite { |
| 112 | struct cprng_testvec *vecs; |
| 113 | unsigned int count; |
| 114 | }; |
| 115 | |
Stephan Mueller | 64d1cdf | 2014-05-31 17:25:36 +0200 | [diff] [blame] | 116 | struct drbg_test_suite { |
| 117 | struct drbg_testvec *vecs; |
| 118 | unsigned int count; |
| 119 | }; |
| 120 | |
Tadeusz Struk | 946cc46 | 2015-06-16 10:31:06 -0700 | [diff] [blame] | 121 | struct akcipher_test_suite { |
| 122 | struct akcipher_testvec *vecs; |
| 123 | unsigned int count; |
| 124 | }; |
| 125 | |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 126 | struct alg_test_desc { |
| 127 | const char *alg; |
| 128 | int (*test)(const struct alg_test_desc *desc, const char *driver, |
| 129 | u32 type, u32 mask); |
Jarod Wilson | a1915d5 | 2009-05-15 15:16:03 +1000 | [diff] [blame] | 130 | int fips_allowed; /* set if alg is allowed in fips mode */ |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 131 | |
| 132 | union { |
| 133 | struct aead_test_suite aead; |
| 134 | struct cipher_test_suite cipher; |
| 135 | struct comp_test_suite comp; |
Geert Uytterhoeven | 8064efb | 2009-03-04 15:08:03 +0800 | [diff] [blame] | 136 | struct pcomp_test_suite pcomp; |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 137 | struct hash_test_suite hash; |
Jarod Wilson | 7647d6c | 2009-05-04 19:44:50 +0800 | [diff] [blame] | 138 | struct cprng_test_suite cprng; |
Stephan Mueller | 64d1cdf | 2014-05-31 17:25:36 +0200 | [diff] [blame] | 139 | struct drbg_test_suite drbg; |
Tadeusz Struk | 946cc46 | 2015-06-16 10:31:06 -0700 | [diff] [blame] | 140 | struct akcipher_test_suite akcipher; |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 141 | } suite; |
| 142 | }; |
| 143 | |
| 144 | static unsigned int IDX[8] = { IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 }; |
| 145 | |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 146 | static void hexdump(unsigned char *buf, unsigned int len) |
| 147 | { |
| 148 | print_hex_dump(KERN_CONT, "", DUMP_PREFIX_OFFSET, |
| 149 | 16, 1, |
| 150 | buf, len, false); |
| 151 | } |
| 152 | |
| 153 | static void tcrypt_complete(struct crypto_async_request *req, int err) |
| 154 | { |
| 155 | struct tcrypt_result *res = req->data; |
| 156 | |
| 157 | if (err == -EINPROGRESS) |
| 158 | return; |
| 159 | |
| 160 | res->err = err; |
| 161 | complete(&res->completion); |
| 162 | } |
| 163 | |
Herbert Xu | f8b0d4d | 2009-05-06 14:15:47 +0800 | [diff] [blame] | 164 | static int testmgr_alloc_buf(char *buf[XBUFSIZE]) |
| 165 | { |
| 166 | int i; |
| 167 | |
| 168 | for (i = 0; i < XBUFSIZE; i++) { |
| 169 | buf[i] = (void *)__get_free_page(GFP_KERNEL); |
| 170 | if (!buf[i]) |
| 171 | goto err_free_buf; |
| 172 | } |
| 173 | |
| 174 | return 0; |
| 175 | |
| 176 | err_free_buf: |
| 177 | while (i-- > 0) |
| 178 | free_page((unsigned long)buf[i]); |
| 179 | |
| 180 | return -ENOMEM; |
| 181 | } |
| 182 | |
| 183 | static void testmgr_free_buf(char *buf[XBUFSIZE]) |
| 184 | { |
| 185 | int i; |
| 186 | |
| 187 | for (i = 0; i < XBUFSIZE; i++) |
| 188 | free_page((unsigned long)buf[i]); |
| 189 | } |
| 190 | |
Cristian Stoica | d4c85f9 | 2014-08-08 12:30:04 +0300 | [diff] [blame] | 191 | static int wait_async_op(struct tcrypt_result *tr, int ret) |
David S. Miller | a8f1a05 | 2010-05-19 14:12:03 +1000 | [diff] [blame] | 192 | { |
| 193 | if (ret == -EINPROGRESS || ret == -EBUSY) { |
Rabin Vincent | 8a45ac1 | 2015-01-09 16:25:28 +0100 | [diff] [blame] | 194 | wait_for_completion(&tr->completion); |
Wolfram Sang | 16735d0 | 2013-11-14 14:32:02 -0800 | [diff] [blame] | 195 | reinit_completion(&tr->completion); |
Rabin Vincent | 8a45ac1 | 2015-01-09 16:25:28 +0100 | [diff] [blame] | 196 | ret = tr->err; |
David S. Miller | a8f1a05 | 2010-05-19 14:12:03 +1000 | [diff] [blame] | 197 | } |
| 198 | return ret; |
| 199 | } |
| 200 | |
Jussi Kivilinna | da5ffe1 | 2013-06-13 17:37:55 +0300 | [diff] [blame] | 201 | static int __test_hash(struct crypto_ahash *tfm, struct hash_testvec *template, |
| 202 | unsigned int tcount, bool use_digest, |
| 203 | const int align_offset) |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 204 | { |
| 205 | const char *algo = crypto_tfm_alg_driver_name(crypto_ahash_tfm(tfm)); |
| 206 | unsigned int i, j, k, temp; |
| 207 | struct scatterlist sg[8]; |
Horia Geanta | 29b77e5 | 2014-07-23 11:59:38 +0300 | [diff] [blame] | 208 | char *result; |
| 209 | char *key; |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 210 | struct ahash_request *req; |
| 211 | struct tcrypt_result tresult; |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 212 | void *hash_buff; |
Herbert Xu | f8b0d4d | 2009-05-06 14:15:47 +0800 | [diff] [blame] | 213 | char *xbuf[XBUFSIZE]; |
| 214 | int ret = -ENOMEM; |
| 215 | |
Horia Geanta | 29b77e5 | 2014-07-23 11:59:38 +0300 | [diff] [blame] | 216 | result = kmalloc(MAX_DIGEST_SIZE, GFP_KERNEL); |
| 217 | if (!result) |
| 218 | return ret; |
| 219 | key = kmalloc(MAX_KEYLEN, GFP_KERNEL); |
| 220 | if (!key) |
| 221 | goto out_nobuf; |
Herbert Xu | f8b0d4d | 2009-05-06 14:15:47 +0800 | [diff] [blame] | 222 | if (testmgr_alloc_buf(xbuf)) |
| 223 | goto out_nobuf; |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 224 | |
| 225 | init_completion(&tresult.completion); |
| 226 | |
| 227 | req = ahash_request_alloc(tfm, GFP_KERNEL); |
| 228 | if (!req) { |
| 229 | printk(KERN_ERR "alg: hash: Failed to allocate request for " |
| 230 | "%s\n", algo); |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 231 | goto out_noreq; |
| 232 | } |
| 233 | ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, |
| 234 | tcrypt_complete, &tresult); |
| 235 | |
Herbert Xu | a0cfae5 | 2009-05-29 16:23:12 +1000 | [diff] [blame] | 236 | j = 0; |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 237 | for (i = 0; i < tcount; i++) { |
Herbert Xu | a0cfae5 | 2009-05-29 16:23:12 +1000 | [diff] [blame] | 238 | if (template[i].np) |
| 239 | continue; |
| 240 | |
Jussi Kivilinna | da5ffe1 | 2013-06-13 17:37:55 +0300 | [diff] [blame] | 241 | ret = -EINVAL; |
| 242 | if (WARN_ON(align_offset + template[i].psize > PAGE_SIZE)) |
| 243 | goto out; |
| 244 | |
Herbert Xu | a0cfae5 | 2009-05-29 16:23:12 +1000 | [diff] [blame] | 245 | j++; |
Horia Geanta | 29b77e5 | 2014-07-23 11:59:38 +0300 | [diff] [blame] | 246 | memset(result, 0, MAX_DIGEST_SIZE); |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 247 | |
| 248 | hash_buff = xbuf[0]; |
Jussi Kivilinna | da5ffe1 | 2013-06-13 17:37:55 +0300 | [diff] [blame] | 249 | hash_buff += align_offset; |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 250 | |
| 251 | memcpy(hash_buff, template[i].plaintext, template[i].psize); |
| 252 | sg_init_one(&sg[0], hash_buff, template[i].psize); |
| 253 | |
| 254 | if (template[i].ksize) { |
| 255 | crypto_ahash_clear_flags(tfm, ~0); |
Horia Geanta | 29b77e5 | 2014-07-23 11:59:38 +0300 | [diff] [blame] | 256 | if (template[i].ksize > MAX_KEYLEN) { |
| 257 | pr_err("alg: hash: setkey failed on test %d for %s: key size %d > %d\n", |
| 258 | j, algo, template[i].ksize, MAX_KEYLEN); |
| 259 | ret = -EINVAL; |
| 260 | goto out; |
| 261 | } |
| 262 | memcpy(key, template[i].key, template[i].ksize); |
| 263 | ret = crypto_ahash_setkey(tfm, key, template[i].ksize); |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 264 | if (ret) { |
| 265 | printk(KERN_ERR "alg: hash: setkey failed on " |
Herbert Xu | a0cfae5 | 2009-05-29 16:23:12 +1000 | [diff] [blame] | 266 | "test %d for %s: ret=%d\n", j, algo, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 267 | -ret); |
| 268 | goto out; |
| 269 | } |
| 270 | } |
| 271 | |
| 272 | ahash_request_set_crypt(req, sg, result, template[i].psize); |
David S. Miller | a8f1a05 | 2010-05-19 14:12:03 +1000 | [diff] [blame] | 273 | if (use_digest) { |
Cristian Stoica | d4c85f9 | 2014-08-08 12:30:04 +0300 | [diff] [blame] | 274 | ret = wait_async_op(&tresult, crypto_ahash_digest(req)); |
David S. Miller | a8f1a05 | 2010-05-19 14:12:03 +1000 | [diff] [blame] | 275 | if (ret) { |
| 276 | pr_err("alg: hash: digest failed on test %d " |
| 277 | "for %s: ret=%d\n", j, algo, -ret); |
| 278 | goto out; |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 279 | } |
David S. Miller | a8f1a05 | 2010-05-19 14:12:03 +1000 | [diff] [blame] | 280 | } else { |
Cristian Stoica | d4c85f9 | 2014-08-08 12:30:04 +0300 | [diff] [blame] | 281 | ret = wait_async_op(&tresult, crypto_ahash_init(req)); |
David S. Miller | a8f1a05 | 2010-05-19 14:12:03 +1000 | [diff] [blame] | 282 | if (ret) { |
| 283 | pr_err("alt: hash: init failed on test %d " |
| 284 | "for %s: ret=%d\n", j, algo, -ret); |
| 285 | goto out; |
| 286 | } |
Cristian Stoica | d4c85f9 | 2014-08-08 12:30:04 +0300 | [diff] [blame] | 287 | ret = wait_async_op(&tresult, crypto_ahash_update(req)); |
David S. Miller | a8f1a05 | 2010-05-19 14:12:03 +1000 | [diff] [blame] | 288 | if (ret) { |
| 289 | pr_err("alt: hash: update failed on test %d " |
| 290 | "for %s: ret=%d\n", j, algo, -ret); |
| 291 | goto out; |
| 292 | } |
Cristian Stoica | d4c85f9 | 2014-08-08 12:30:04 +0300 | [diff] [blame] | 293 | ret = wait_async_op(&tresult, crypto_ahash_final(req)); |
David S. Miller | a8f1a05 | 2010-05-19 14:12:03 +1000 | [diff] [blame] | 294 | if (ret) { |
| 295 | pr_err("alt: hash: final failed on test %d " |
| 296 | "for %s: ret=%d\n", j, algo, -ret); |
| 297 | goto out; |
| 298 | } |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | if (memcmp(result, template[i].digest, |
| 302 | crypto_ahash_digestsize(tfm))) { |
| 303 | printk(KERN_ERR "alg: hash: Test %d failed for %s\n", |
Herbert Xu | a0cfae5 | 2009-05-29 16:23:12 +1000 | [diff] [blame] | 304 | j, algo); |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 305 | hexdump(result, crypto_ahash_digestsize(tfm)); |
| 306 | ret = -EINVAL; |
| 307 | goto out; |
| 308 | } |
| 309 | } |
| 310 | |
| 311 | j = 0; |
| 312 | for (i = 0; i < tcount; i++) { |
Jussi Kivilinna | da5ffe1 | 2013-06-13 17:37:55 +0300 | [diff] [blame] | 313 | /* alignment tests are only done with continuous buffers */ |
| 314 | if (align_offset != 0) |
| 315 | break; |
| 316 | |
Cristian Stoica | 5f2b424 | 2014-08-08 14:27:50 +0300 | [diff] [blame] | 317 | if (!template[i].np) |
| 318 | continue; |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 319 | |
Cristian Stoica | 5f2b424 | 2014-08-08 14:27:50 +0300 | [diff] [blame] | 320 | j++; |
| 321 | memset(result, 0, MAX_DIGEST_SIZE); |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 322 | |
Cristian Stoica | 5f2b424 | 2014-08-08 14:27:50 +0300 | [diff] [blame] | 323 | temp = 0; |
| 324 | sg_init_table(sg, template[i].np); |
| 325 | ret = -EINVAL; |
| 326 | for (k = 0; k < template[i].np; k++) { |
| 327 | if (WARN_ON(offset_in_page(IDX[k]) + |
| 328 | template[i].tap[k] > PAGE_SIZE)) |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 329 | goto out; |
Cristian Stoica | 5f2b424 | 2014-08-08 14:27:50 +0300 | [diff] [blame] | 330 | sg_set_buf(&sg[k], |
| 331 | memcpy(xbuf[IDX[k] >> PAGE_SHIFT] + |
| 332 | offset_in_page(IDX[k]), |
| 333 | template[i].plaintext + temp, |
| 334 | template[i].tap[k]), |
| 335 | template[i].tap[k]); |
| 336 | temp += template[i].tap[k]; |
| 337 | } |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 338 | |
Cristian Stoica | 5f2b424 | 2014-08-08 14:27:50 +0300 | [diff] [blame] | 339 | if (template[i].ksize) { |
| 340 | if (template[i].ksize > MAX_KEYLEN) { |
| 341 | pr_err("alg: hash: setkey failed on test %d for %s: key size %d > %d\n", |
| 342 | j, algo, template[i].ksize, MAX_KEYLEN); |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 343 | ret = -EINVAL; |
| 344 | goto out; |
| 345 | } |
Cristian Stoica | 5f2b424 | 2014-08-08 14:27:50 +0300 | [diff] [blame] | 346 | crypto_ahash_clear_flags(tfm, ~0); |
| 347 | memcpy(key, template[i].key, template[i].ksize); |
| 348 | ret = crypto_ahash_setkey(tfm, key, template[i].ksize); |
| 349 | |
| 350 | if (ret) { |
| 351 | printk(KERN_ERR "alg: hash: setkey " |
| 352 | "failed on chunking test %d " |
| 353 | "for %s: ret=%d\n", j, algo, -ret); |
| 354 | goto out; |
| 355 | } |
| 356 | } |
| 357 | |
| 358 | ahash_request_set_crypt(req, sg, result, template[i].psize); |
| 359 | ret = crypto_ahash_digest(req); |
| 360 | switch (ret) { |
| 361 | case 0: |
| 362 | break; |
| 363 | case -EINPROGRESS: |
| 364 | case -EBUSY: |
Rabin Vincent | 8a45ac1 | 2015-01-09 16:25:28 +0100 | [diff] [blame] | 365 | wait_for_completion(&tresult.completion); |
| 366 | reinit_completion(&tresult.completion); |
| 367 | ret = tresult.err; |
| 368 | if (!ret) |
Cristian Stoica | 5f2b424 | 2014-08-08 14:27:50 +0300 | [diff] [blame] | 369 | break; |
Cristian Stoica | 5f2b424 | 2014-08-08 14:27:50 +0300 | [diff] [blame] | 370 | /* fall through */ |
| 371 | default: |
| 372 | printk(KERN_ERR "alg: hash: digest failed " |
| 373 | "on chunking test %d for %s: " |
| 374 | "ret=%d\n", j, algo, -ret); |
| 375 | goto out; |
| 376 | } |
| 377 | |
| 378 | if (memcmp(result, template[i].digest, |
| 379 | crypto_ahash_digestsize(tfm))) { |
| 380 | printk(KERN_ERR "alg: hash: Chunking test %d " |
| 381 | "failed for %s\n", j, algo); |
| 382 | hexdump(result, crypto_ahash_digestsize(tfm)); |
| 383 | ret = -EINVAL; |
| 384 | goto out; |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 385 | } |
| 386 | } |
| 387 | |
| 388 | ret = 0; |
| 389 | |
| 390 | out: |
| 391 | ahash_request_free(req); |
| 392 | out_noreq: |
Herbert Xu | f8b0d4d | 2009-05-06 14:15:47 +0800 | [diff] [blame] | 393 | testmgr_free_buf(xbuf); |
| 394 | out_nobuf: |
Horia Geanta | 29b77e5 | 2014-07-23 11:59:38 +0300 | [diff] [blame] | 395 | kfree(key); |
| 396 | kfree(result); |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 397 | return ret; |
| 398 | } |
| 399 | |
Jussi Kivilinna | da5ffe1 | 2013-06-13 17:37:55 +0300 | [diff] [blame] | 400 | static int test_hash(struct crypto_ahash *tfm, struct hash_testvec *template, |
| 401 | unsigned int tcount, bool use_digest) |
| 402 | { |
| 403 | unsigned int alignmask; |
| 404 | int ret; |
| 405 | |
| 406 | ret = __test_hash(tfm, template, tcount, use_digest, 0); |
| 407 | if (ret) |
| 408 | return ret; |
| 409 | |
| 410 | /* test unaligned buffers, check with one byte offset */ |
| 411 | ret = __test_hash(tfm, template, tcount, use_digest, 1); |
| 412 | if (ret) |
| 413 | return ret; |
| 414 | |
| 415 | alignmask = crypto_tfm_alg_alignmask(&tfm->base); |
| 416 | if (alignmask) { |
| 417 | /* Check if alignment mask for tfm is correctly set. */ |
| 418 | ret = __test_hash(tfm, template, tcount, use_digest, |
| 419 | alignmask + 1); |
| 420 | if (ret) |
| 421 | return ret; |
| 422 | } |
| 423 | |
| 424 | return 0; |
| 425 | } |
| 426 | |
Jussi Kivilinna | d8a32ac | 2012-09-21 10:26:52 +0300 | [diff] [blame] | 427 | static int __test_aead(struct crypto_aead *tfm, int enc, |
| 428 | struct aead_testvec *template, unsigned int tcount, |
Jussi Kivilinna | 58dcf54 | 2013-06-13 17:37:50 +0300 | [diff] [blame] | 429 | const bool diff_dst, const int align_offset) |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 430 | { |
| 431 | const char *algo = crypto_tfm_alg_driver_name(crypto_aead_tfm(tfm)); |
| 432 | unsigned int i, j, k, n, temp; |
Herbert Xu | f8b0d4d | 2009-05-06 14:15:47 +0800 | [diff] [blame] | 433 | int ret = -ENOMEM; |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 434 | char *q; |
| 435 | char *key; |
| 436 | struct aead_request *req; |
Jussi Kivilinna | d8a32ac | 2012-09-21 10:26:52 +0300 | [diff] [blame] | 437 | struct scatterlist *sg; |
Jussi Kivilinna | d8a32ac | 2012-09-21 10:26:52 +0300 | [diff] [blame] | 438 | struct scatterlist *sgout; |
| 439 | const char *e, *d; |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 440 | struct tcrypt_result result; |
Cristian Stoica | 424a5da | 2015-01-28 11:03:05 +0200 | [diff] [blame] | 441 | unsigned int authsize, iv_len; |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 442 | void *input; |
Jussi Kivilinna | d8a32ac | 2012-09-21 10:26:52 +0300 | [diff] [blame] | 443 | void *output; |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 444 | void *assoc; |
Tadeusz Struk | 9bac019 | 2014-05-19 09:51:33 -0700 | [diff] [blame] | 445 | char *iv; |
Herbert Xu | f8b0d4d | 2009-05-06 14:15:47 +0800 | [diff] [blame] | 446 | char *xbuf[XBUFSIZE]; |
Jussi Kivilinna | d8a32ac | 2012-09-21 10:26:52 +0300 | [diff] [blame] | 447 | char *xoutbuf[XBUFSIZE]; |
Herbert Xu | f8b0d4d | 2009-05-06 14:15:47 +0800 | [diff] [blame] | 448 | char *axbuf[XBUFSIZE]; |
| 449 | |
Tadeusz Struk | 9bac019 | 2014-05-19 09:51:33 -0700 | [diff] [blame] | 450 | iv = kzalloc(MAX_IVLEN, GFP_KERNEL); |
| 451 | if (!iv) |
| 452 | return ret; |
Horia Geanta | 29b77e5 | 2014-07-23 11:59:38 +0300 | [diff] [blame] | 453 | key = kmalloc(MAX_KEYLEN, GFP_KERNEL); |
| 454 | if (!key) |
| 455 | goto out_noxbuf; |
Herbert Xu | f8b0d4d | 2009-05-06 14:15:47 +0800 | [diff] [blame] | 456 | if (testmgr_alloc_buf(xbuf)) |
| 457 | goto out_noxbuf; |
| 458 | if (testmgr_alloc_buf(axbuf)) |
| 459 | goto out_noaxbuf; |
Jussi Kivilinna | d8a32ac | 2012-09-21 10:26:52 +0300 | [diff] [blame] | 460 | if (diff_dst && testmgr_alloc_buf(xoutbuf)) |
| 461 | goto out_nooutbuf; |
| 462 | |
| 463 | /* avoid "the frame size is larger than 1024 bytes" compiler warning */ |
Herbert Xu | 8a525fc | 2015-05-27 16:03:43 +0800 | [diff] [blame] | 464 | sg = kmalloc(sizeof(*sg) * 8 * (diff_dst ? 4 : 2), GFP_KERNEL); |
Jussi Kivilinna | d8a32ac | 2012-09-21 10:26:52 +0300 | [diff] [blame] | 465 | if (!sg) |
| 466 | goto out_nosg; |
Herbert Xu | 8a525fc | 2015-05-27 16:03:43 +0800 | [diff] [blame] | 467 | sgout = &sg[16]; |
Jussi Kivilinna | d8a32ac | 2012-09-21 10:26:52 +0300 | [diff] [blame] | 468 | |
| 469 | if (diff_dst) |
| 470 | d = "-ddst"; |
| 471 | else |
| 472 | d = ""; |
| 473 | |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 474 | if (enc == ENCRYPT) |
| 475 | e = "encryption"; |
| 476 | else |
| 477 | e = "decryption"; |
| 478 | |
| 479 | init_completion(&result.completion); |
| 480 | |
| 481 | req = aead_request_alloc(tfm, GFP_KERNEL); |
| 482 | if (!req) { |
Jussi Kivilinna | d8a32ac | 2012-09-21 10:26:52 +0300 | [diff] [blame] | 483 | pr_err("alg: aead%s: Failed to allocate request for %s\n", |
| 484 | d, algo); |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 485 | goto out; |
| 486 | } |
| 487 | |
| 488 | aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, |
| 489 | tcrypt_complete, &result); |
| 490 | |
| 491 | for (i = 0, j = 0; i < tcount; i++) { |
Cristian Stoica | 05b1d33 | 2014-07-28 13:11:23 +0300 | [diff] [blame] | 492 | if (template[i].np) |
| 493 | continue; |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 494 | |
Cristian Stoica | 05b1d33 | 2014-07-28 13:11:23 +0300 | [diff] [blame] | 495 | j++; |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 496 | |
Cristian Stoica | 05b1d33 | 2014-07-28 13:11:23 +0300 | [diff] [blame] | 497 | /* some templates have no input data but they will |
| 498 | * touch input |
| 499 | */ |
| 500 | input = xbuf[0]; |
| 501 | input += align_offset; |
| 502 | assoc = axbuf[0]; |
| 503 | |
| 504 | ret = -EINVAL; |
| 505 | if (WARN_ON(align_offset + template[i].ilen > |
| 506 | PAGE_SIZE || template[i].alen > PAGE_SIZE)) |
| 507 | goto out; |
| 508 | |
| 509 | memcpy(input, template[i].input, template[i].ilen); |
| 510 | memcpy(assoc, template[i].assoc, template[i].alen); |
Cristian Stoica | 424a5da | 2015-01-28 11:03:05 +0200 | [diff] [blame] | 511 | iv_len = crypto_aead_ivsize(tfm); |
Cristian Stoica | 05b1d33 | 2014-07-28 13:11:23 +0300 | [diff] [blame] | 512 | if (template[i].iv) |
Cristian Stoica | 424a5da | 2015-01-28 11:03:05 +0200 | [diff] [blame] | 513 | memcpy(iv, template[i].iv, iv_len); |
Cristian Stoica | 05b1d33 | 2014-07-28 13:11:23 +0300 | [diff] [blame] | 514 | else |
Cristian Stoica | 424a5da | 2015-01-28 11:03:05 +0200 | [diff] [blame] | 515 | memset(iv, 0, iv_len); |
Cristian Stoica | 05b1d33 | 2014-07-28 13:11:23 +0300 | [diff] [blame] | 516 | |
| 517 | crypto_aead_clear_flags(tfm, ~0); |
| 518 | if (template[i].wk) |
| 519 | crypto_aead_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY); |
| 520 | |
| 521 | if (template[i].klen > MAX_KEYLEN) { |
| 522 | pr_err("alg: aead%s: setkey failed on test %d for %s: key size %d > %d\n", |
| 523 | d, j, algo, template[i].klen, |
| 524 | MAX_KEYLEN); |
Herbert Xu | fd57f22 | 2009-05-29 16:05:42 +1000 | [diff] [blame] | 525 | ret = -EINVAL; |
Cristian Stoica | 05b1d33 | 2014-07-28 13:11:23 +0300 | [diff] [blame] | 526 | goto out; |
| 527 | } |
| 528 | memcpy(key, template[i].key, template[i].klen); |
Herbert Xu | fd57f22 | 2009-05-29 16:05:42 +1000 | [diff] [blame] | 529 | |
Cristian Stoica | 05b1d33 | 2014-07-28 13:11:23 +0300 | [diff] [blame] | 530 | ret = crypto_aead_setkey(tfm, key, template[i].klen); |
| 531 | if (!ret == template[i].fail) { |
| 532 | pr_err("alg: aead%s: setkey failed on test %d for %s: flags=%x\n", |
| 533 | d, j, algo, crypto_aead_get_flags(tfm)); |
| 534 | goto out; |
| 535 | } else if (ret) |
| 536 | continue; |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 537 | |
Cristian Stoica | 05b1d33 | 2014-07-28 13:11:23 +0300 | [diff] [blame] | 538 | authsize = abs(template[i].rlen - template[i].ilen); |
| 539 | ret = crypto_aead_setauthsize(tfm, authsize); |
| 540 | if (ret) { |
| 541 | pr_err("alg: aead%s: Failed to set authsize to %u on test %d for %s\n", |
| 542 | d, authsize, j, algo); |
| 543 | goto out; |
| 544 | } |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 545 | |
Herbert Xu | 8a525fc | 2015-05-27 16:03:43 +0800 | [diff] [blame] | 546 | k = !!template[i].alen; |
| 547 | sg_init_table(sg, k + 1); |
| 548 | sg_set_buf(&sg[0], assoc, template[i].alen); |
| 549 | sg_set_buf(&sg[k], input, |
| 550 | template[i].ilen + (enc ? authsize : 0)); |
| 551 | output = input; |
| 552 | |
Cristian Stoica | 05b1d33 | 2014-07-28 13:11:23 +0300 | [diff] [blame] | 553 | if (diff_dst) { |
Herbert Xu | 8a525fc | 2015-05-27 16:03:43 +0800 | [diff] [blame] | 554 | sg_init_table(sgout, k + 1); |
| 555 | sg_set_buf(&sgout[0], assoc, template[i].alen); |
| 556 | |
Cristian Stoica | 05b1d33 | 2014-07-28 13:11:23 +0300 | [diff] [blame] | 557 | output = xoutbuf[0]; |
| 558 | output += align_offset; |
Herbert Xu | 8a525fc | 2015-05-27 16:03:43 +0800 | [diff] [blame] | 559 | sg_set_buf(&sgout[k], output, |
| 560 | template[i].rlen + (enc ? 0 : authsize)); |
Cristian Stoica | 05b1d33 | 2014-07-28 13:11:23 +0300 | [diff] [blame] | 561 | } |
| 562 | |
Cristian Stoica | 05b1d33 | 2014-07-28 13:11:23 +0300 | [diff] [blame] | 563 | aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg, |
| 564 | template[i].ilen, iv); |
| 565 | |
Herbert Xu | 8a525fc | 2015-05-27 16:03:43 +0800 | [diff] [blame] | 566 | aead_request_set_ad(req, template[i].alen); |
Cristian Stoica | 05b1d33 | 2014-07-28 13:11:23 +0300 | [diff] [blame] | 567 | |
| 568 | ret = enc ? crypto_aead_encrypt(req) : crypto_aead_decrypt(req); |
| 569 | |
| 570 | switch (ret) { |
| 571 | case 0: |
| 572 | if (template[i].novrfy) { |
| 573 | /* verification was supposed to fail */ |
| 574 | pr_err("alg: aead%s: %s failed on test %d for %s: ret was 0, expected -EBADMSG\n", |
| 575 | d, e, j, algo); |
| 576 | /* so really, we got a bad message */ |
| 577 | ret = -EBADMSG; |
Horia Geanta | 29b77e5 | 2014-07-23 11:59:38 +0300 | [diff] [blame] | 578 | goto out; |
| 579 | } |
Cristian Stoica | 05b1d33 | 2014-07-28 13:11:23 +0300 | [diff] [blame] | 580 | break; |
| 581 | case -EINPROGRESS: |
| 582 | case -EBUSY: |
Rabin Vincent | 8a45ac1 | 2015-01-09 16:25:28 +0100 | [diff] [blame] | 583 | wait_for_completion(&result.completion); |
| 584 | reinit_completion(&result.completion); |
| 585 | ret = result.err; |
| 586 | if (!ret) |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 587 | break; |
Cristian Stoica | 05b1d33 | 2014-07-28 13:11:23 +0300 | [diff] [blame] | 588 | case -EBADMSG: |
| 589 | if (template[i].novrfy) |
| 590 | /* verification failure was expected */ |
| 591 | continue; |
| 592 | /* fall through */ |
| 593 | default: |
| 594 | pr_err("alg: aead%s: %s failed on test %d for %s: ret=%d\n", |
| 595 | d, e, j, algo, -ret); |
| 596 | goto out; |
| 597 | } |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 598 | |
Cristian Stoica | 05b1d33 | 2014-07-28 13:11:23 +0300 | [diff] [blame] | 599 | q = output; |
| 600 | if (memcmp(q, template[i].result, template[i].rlen)) { |
| 601 | pr_err("alg: aead%s: Test %d failed on %s for %s\n", |
| 602 | d, j, e, algo); |
| 603 | hexdump(q, template[i].rlen); |
| 604 | ret = -EINVAL; |
| 605 | goto out; |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 606 | } |
| 607 | } |
| 608 | |
| 609 | for (i = 0, j = 0; i < tcount; i++) { |
Jussi Kivilinna | 58dcf54 | 2013-06-13 17:37:50 +0300 | [diff] [blame] | 610 | /* alignment tests are only done with continuous buffers */ |
| 611 | if (align_offset != 0) |
| 612 | break; |
| 613 | |
Cristian Stoica | 05b1d33 | 2014-07-28 13:11:23 +0300 | [diff] [blame] | 614 | if (!template[i].np) |
| 615 | continue; |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 616 | |
Cristian Stoica | 05b1d33 | 2014-07-28 13:11:23 +0300 | [diff] [blame] | 617 | j++; |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 618 | |
Cristian Stoica | 05b1d33 | 2014-07-28 13:11:23 +0300 | [diff] [blame] | 619 | if (template[i].iv) |
| 620 | memcpy(iv, template[i].iv, MAX_IVLEN); |
| 621 | else |
| 622 | memset(iv, 0, MAX_IVLEN); |
| 623 | |
| 624 | crypto_aead_clear_flags(tfm, ~0); |
| 625 | if (template[i].wk) |
| 626 | crypto_aead_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY); |
| 627 | if (template[i].klen > MAX_KEYLEN) { |
| 628 | pr_err("alg: aead%s: setkey failed on test %d for %s: key size %d > %d\n", |
| 629 | d, j, algo, template[i].klen, MAX_KEYLEN); |
| 630 | ret = -EINVAL; |
| 631 | goto out; |
| 632 | } |
| 633 | memcpy(key, template[i].key, template[i].klen); |
| 634 | |
| 635 | ret = crypto_aead_setkey(tfm, key, template[i].klen); |
| 636 | if (!ret == template[i].fail) { |
| 637 | pr_err("alg: aead%s: setkey failed on chunk test %d for %s: flags=%x\n", |
| 638 | d, j, algo, crypto_aead_get_flags(tfm)); |
| 639 | goto out; |
| 640 | } else if (ret) |
| 641 | continue; |
| 642 | |
| 643 | authsize = abs(template[i].rlen - template[i].ilen); |
| 644 | |
| 645 | ret = -EINVAL; |
Herbert Xu | 8a525fc | 2015-05-27 16:03:43 +0800 | [diff] [blame] | 646 | sg_init_table(sg, template[i].anp + template[i].np); |
Cristian Stoica | 05b1d33 | 2014-07-28 13:11:23 +0300 | [diff] [blame] | 647 | if (diff_dst) |
Herbert Xu | 8a525fc | 2015-05-27 16:03:43 +0800 | [diff] [blame] | 648 | sg_init_table(sgout, template[i].anp + template[i].np); |
| 649 | |
| 650 | ret = -EINVAL; |
| 651 | for (k = 0, temp = 0; k < template[i].anp; k++) { |
| 652 | if (WARN_ON(offset_in_page(IDX[k]) + |
| 653 | template[i].atap[k] > PAGE_SIZE)) |
| 654 | goto out; |
| 655 | sg_set_buf(&sg[k], |
| 656 | memcpy(axbuf[IDX[k] >> PAGE_SHIFT] + |
| 657 | offset_in_page(IDX[k]), |
| 658 | template[i].assoc + temp, |
| 659 | template[i].atap[k]), |
| 660 | template[i].atap[k]); |
| 661 | if (diff_dst) |
| 662 | sg_set_buf(&sgout[k], |
| 663 | axbuf[IDX[k] >> PAGE_SHIFT] + |
| 664 | offset_in_page(IDX[k]), |
| 665 | template[i].atap[k]); |
| 666 | temp += template[i].atap[k]; |
| 667 | } |
| 668 | |
Cristian Stoica | 05b1d33 | 2014-07-28 13:11:23 +0300 | [diff] [blame] | 669 | for (k = 0, temp = 0; k < template[i].np; k++) { |
| 670 | if (WARN_ON(offset_in_page(IDX[k]) + |
| 671 | template[i].tap[k] > PAGE_SIZE)) |
| 672 | goto out; |
| 673 | |
| 674 | q = xbuf[IDX[k] >> PAGE_SHIFT] + offset_in_page(IDX[k]); |
| 675 | memcpy(q, template[i].input + temp, template[i].tap[k]); |
Herbert Xu | 8a525fc | 2015-05-27 16:03:43 +0800 | [diff] [blame] | 676 | sg_set_buf(&sg[template[i].anp + k], |
| 677 | q, template[i].tap[k]); |
Cristian Stoica | 05b1d33 | 2014-07-28 13:11:23 +0300 | [diff] [blame] | 678 | |
| 679 | if (diff_dst) { |
| 680 | q = xoutbuf[IDX[k] >> PAGE_SHIFT] + |
| 681 | offset_in_page(IDX[k]); |
| 682 | |
| 683 | memset(q, 0, template[i].tap[k]); |
| 684 | |
Herbert Xu | 8a525fc | 2015-05-27 16:03:43 +0800 | [diff] [blame] | 685 | sg_set_buf(&sgout[template[i].anp + k], |
| 686 | q, template[i].tap[k]); |
Cristian Stoica | 05b1d33 | 2014-07-28 13:11:23 +0300 | [diff] [blame] | 687 | } |
| 688 | |
| 689 | n = template[i].tap[k]; |
| 690 | if (k == template[i].np - 1 && enc) |
| 691 | n += authsize; |
| 692 | if (offset_in_page(q) + n < PAGE_SIZE) |
| 693 | q[n] = 0; |
| 694 | |
| 695 | temp += template[i].tap[k]; |
| 696 | } |
| 697 | |
| 698 | ret = crypto_aead_setauthsize(tfm, authsize); |
| 699 | if (ret) { |
| 700 | pr_err("alg: aead%s: Failed to set authsize to %u on chunk test %d for %s\n", |
| 701 | d, authsize, j, algo); |
| 702 | goto out; |
| 703 | } |
| 704 | |
| 705 | if (enc) { |
Herbert Xu | 8a525fc | 2015-05-27 16:03:43 +0800 | [diff] [blame] | 706 | if (WARN_ON(sg[template[i].anp + k - 1].offset + |
| 707 | sg[template[i].anp + k - 1].length + |
| 708 | authsize > PAGE_SIZE)) { |
Horia Geanta | 29b77e5 | 2014-07-23 11:59:38 +0300 | [diff] [blame] | 709 | ret = -EINVAL; |
| 710 | goto out; |
| 711 | } |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 712 | |
Jussi Kivilinna | d8a32ac | 2012-09-21 10:26:52 +0300 | [diff] [blame] | 713 | if (diff_dst) |
Herbert Xu | 8a525fc | 2015-05-27 16:03:43 +0800 | [diff] [blame] | 714 | sgout[template[i].anp + k - 1].length += |
| 715 | authsize; |
| 716 | sg[template[i].anp + k - 1].length += authsize; |
Cristian Stoica | 05b1d33 | 2014-07-28 13:11:23 +0300 | [diff] [blame] | 717 | } |
| 718 | |
| 719 | aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg, |
| 720 | template[i].ilen, |
| 721 | iv); |
| 722 | |
Herbert Xu | 8a525fc | 2015-05-27 16:03:43 +0800 | [diff] [blame] | 723 | aead_request_set_ad(req, template[i].alen); |
Cristian Stoica | 05b1d33 | 2014-07-28 13:11:23 +0300 | [diff] [blame] | 724 | |
| 725 | ret = enc ? crypto_aead_encrypt(req) : crypto_aead_decrypt(req); |
| 726 | |
| 727 | switch (ret) { |
| 728 | case 0: |
| 729 | if (template[i].novrfy) { |
| 730 | /* verification was supposed to fail */ |
| 731 | pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret was 0, expected -EBADMSG\n", |
| 732 | d, e, j, algo); |
| 733 | /* so really, we got a bad message */ |
| 734 | ret = -EBADMSG; |
| 735 | goto out; |
| 736 | } |
| 737 | break; |
| 738 | case -EINPROGRESS: |
| 739 | case -EBUSY: |
Rabin Vincent | 8a45ac1 | 2015-01-09 16:25:28 +0100 | [diff] [blame] | 740 | wait_for_completion(&result.completion); |
| 741 | reinit_completion(&result.completion); |
| 742 | ret = result.err; |
| 743 | if (!ret) |
Cristian Stoica | 05b1d33 | 2014-07-28 13:11:23 +0300 | [diff] [blame] | 744 | break; |
Cristian Stoica | 05b1d33 | 2014-07-28 13:11:23 +0300 | [diff] [blame] | 745 | case -EBADMSG: |
| 746 | if (template[i].novrfy) |
| 747 | /* verification failure was expected */ |
| 748 | continue; |
| 749 | /* fall through */ |
| 750 | default: |
| 751 | pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret=%d\n", |
| 752 | d, e, j, algo, -ret); |
| 753 | goto out; |
| 754 | } |
| 755 | |
| 756 | ret = -EINVAL; |
| 757 | for (k = 0, temp = 0; k < template[i].np; k++) { |
| 758 | if (diff_dst) |
| 759 | q = xoutbuf[IDX[k] >> PAGE_SHIFT] + |
| 760 | offset_in_page(IDX[k]); |
| 761 | else |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 762 | q = xbuf[IDX[k] >> PAGE_SHIFT] + |
| 763 | offset_in_page(IDX[k]); |
| 764 | |
Cristian Stoica | 05b1d33 | 2014-07-28 13:11:23 +0300 | [diff] [blame] | 765 | n = template[i].tap[k]; |
| 766 | if (k == template[i].np - 1) |
| 767 | n += enc ? authsize : -authsize; |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 768 | |
Cristian Stoica | 05b1d33 | 2014-07-28 13:11:23 +0300 | [diff] [blame] | 769 | if (memcmp(q, template[i].result + temp, n)) { |
| 770 | pr_err("alg: aead%s: Chunk test %d failed on %s at page %u for %s\n", |
| 771 | d, j, e, k, algo); |
| 772 | hexdump(q, n); |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 773 | goto out; |
| 774 | } |
| 775 | |
Cristian Stoica | 05b1d33 | 2014-07-28 13:11:23 +0300 | [diff] [blame] | 776 | q += n; |
| 777 | if (k == template[i].np - 1 && !enc) { |
| 778 | if (!diff_dst && |
| 779 | memcmp(q, template[i].input + |
| 780 | temp + n, authsize)) |
| 781 | n = authsize; |
Horia Geanta | 8ec25c5 | 2013-11-28 15:11:18 +0200 | [diff] [blame] | 782 | else |
Cristian Stoica | 05b1d33 | 2014-07-28 13:11:23 +0300 | [diff] [blame] | 783 | n = 0; |
| 784 | } else { |
| 785 | for (n = 0; offset_in_page(q + n) && q[n]; n++) |
| 786 | ; |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 787 | } |
Cristian Stoica | 05b1d33 | 2014-07-28 13:11:23 +0300 | [diff] [blame] | 788 | if (n) { |
| 789 | pr_err("alg: aead%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n", |
| 790 | d, j, e, k, algo, n); |
| 791 | hexdump(q, n); |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 792 | goto out; |
| 793 | } |
| 794 | |
Cristian Stoica | 05b1d33 | 2014-07-28 13:11:23 +0300 | [diff] [blame] | 795 | temp += template[i].tap[k]; |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 796 | } |
| 797 | } |
| 798 | |
| 799 | ret = 0; |
| 800 | |
| 801 | out: |
| 802 | aead_request_free(req); |
Jussi Kivilinna | d8a32ac | 2012-09-21 10:26:52 +0300 | [diff] [blame] | 803 | kfree(sg); |
| 804 | out_nosg: |
| 805 | if (diff_dst) |
| 806 | testmgr_free_buf(xoutbuf); |
| 807 | out_nooutbuf: |
Herbert Xu | f8b0d4d | 2009-05-06 14:15:47 +0800 | [diff] [blame] | 808 | testmgr_free_buf(axbuf); |
| 809 | out_noaxbuf: |
| 810 | testmgr_free_buf(xbuf); |
| 811 | out_noxbuf: |
Horia Geanta | 29b77e5 | 2014-07-23 11:59:38 +0300 | [diff] [blame] | 812 | kfree(key); |
Tadeusz Struk | 9bac019 | 2014-05-19 09:51:33 -0700 | [diff] [blame] | 813 | kfree(iv); |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 814 | return ret; |
| 815 | } |
| 816 | |
Jussi Kivilinna | d8a32ac | 2012-09-21 10:26:52 +0300 | [diff] [blame] | 817 | static int test_aead(struct crypto_aead *tfm, int enc, |
| 818 | struct aead_testvec *template, unsigned int tcount) |
| 819 | { |
Jussi Kivilinna | 58dcf54 | 2013-06-13 17:37:50 +0300 | [diff] [blame] | 820 | unsigned int alignmask; |
Jussi Kivilinna | d8a32ac | 2012-09-21 10:26:52 +0300 | [diff] [blame] | 821 | int ret; |
| 822 | |
| 823 | /* test 'dst == src' case */ |
Jussi Kivilinna | 58dcf54 | 2013-06-13 17:37:50 +0300 | [diff] [blame] | 824 | ret = __test_aead(tfm, enc, template, tcount, false, 0); |
Jussi Kivilinna | d8a32ac | 2012-09-21 10:26:52 +0300 | [diff] [blame] | 825 | if (ret) |
| 826 | return ret; |
| 827 | |
| 828 | /* test 'dst != src' case */ |
Jussi Kivilinna | 58dcf54 | 2013-06-13 17:37:50 +0300 | [diff] [blame] | 829 | ret = __test_aead(tfm, enc, template, tcount, true, 0); |
| 830 | if (ret) |
| 831 | return ret; |
| 832 | |
| 833 | /* test unaligned buffers, check with one byte offset */ |
| 834 | ret = __test_aead(tfm, enc, template, tcount, true, 1); |
| 835 | if (ret) |
| 836 | return ret; |
| 837 | |
| 838 | alignmask = crypto_tfm_alg_alignmask(&tfm->base); |
| 839 | if (alignmask) { |
| 840 | /* Check if alignment mask for tfm is correctly set. */ |
| 841 | ret = __test_aead(tfm, enc, template, tcount, true, |
| 842 | alignmask + 1); |
| 843 | if (ret) |
| 844 | return ret; |
| 845 | } |
| 846 | |
| 847 | return 0; |
Jussi Kivilinna | d8a32ac | 2012-09-21 10:26:52 +0300 | [diff] [blame] | 848 | } |
| 849 | |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 850 | static int test_cipher(struct crypto_cipher *tfm, int enc, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 851 | struct cipher_testvec *template, unsigned int tcount) |
| 852 | { |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 853 | const char *algo = crypto_tfm_alg_driver_name(crypto_cipher_tfm(tfm)); |
| 854 | unsigned int i, j, k; |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 855 | char *q; |
| 856 | const char *e; |
| 857 | void *data; |
Herbert Xu | f8b0d4d | 2009-05-06 14:15:47 +0800 | [diff] [blame] | 858 | char *xbuf[XBUFSIZE]; |
| 859 | int ret = -ENOMEM; |
| 860 | |
| 861 | if (testmgr_alloc_buf(xbuf)) |
| 862 | goto out_nobuf; |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 863 | |
| 864 | if (enc == ENCRYPT) |
| 865 | e = "encryption"; |
| 866 | else |
| 867 | e = "decryption"; |
| 868 | |
| 869 | j = 0; |
| 870 | for (i = 0; i < tcount; i++) { |
| 871 | if (template[i].np) |
| 872 | continue; |
| 873 | |
| 874 | j++; |
| 875 | |
Herbert Xu | fd57f22 | 2009-05-29 16:05:42 +1000 | [diff] [blame] | 876 | ret = -EINVAL; |
| 877 | if (WARN_ON(template[i].ilen > PAGE_SIZE)) |
| 878 | goto out; |
| 879 | |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 880 | data = xbuf[0]; |
| 881 | memcpy(data, template[i].input, template[i].ilen); |
| 882 | |
| 883 | crypto_cipher_clear_flags(tfm, ~0); |
| 884 | if (template[i].wk) |
| 885 | crypto_cipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY); |
| 886 | |
| 887 | ret = crypto_cipher_setkey(tfm, template[i].key, |
| 888 | template[i].klen); |
| 889 | if (!ret == template[i].fail) { |
| 890 | printk(KERN_ERR "alg: cipher: setkey failed " |
| 891 | "on test %d for %s: flags=%x\n", j, |
| 892 | algo, crypto_cipher_get_flags(tfm)); |
| 893 | goto out; |
| 894 | } else if (ret) |
| 895 | continue; |
| 896 | |
| 897 | for (k = 0; k < template[i].ilen; |
| 898 | k += crypto_cipher_blocksize(tfm)) { |
| 899 | if (enc) |
| 900 | crypto_cipher_encrypt_one(tfm, data + k, |
| 901 | data + k); |
| 902 | else |
| 903 | crypto_cipher_decrypt_one(tfm, data + k, |
| 904 | data + k); |
| 905 | } |
| 906 | |
| 907 | q = data; |
| 908 | if (memcmp(q, template[i].result, template[i].rlen)) { |
| 909 | printk(KERN_ERR "alg: cipher: Test %d failed " |
| 910 | "on %s for %s\n", j, e, algo); |
| 911 | hexdump(q, template[i].rlen); |
| 912 | ret = -EINVAL; |
| 913 | goto out; |
| 914 | } |
| 915 | } |
| 916 | |
| 917 | ret = 0; |
| 918 | |
| 919 | out: |
Herbert Xu | f8b0d4d | 2009-05-06 14:15:47 +0800 | [diff] [blame] | 920 | testmgr_free_buf(xbuf); |
| 921 | out_nobuf: |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 922 | return ret; |
| 923 | } |
| 924 | |
Herbert Xu | 12773d9 | 2015-08-20 15:21:46 +0800 | [diff] [blame] | 925 | static int __test_skcipher(struct crypto_skcipher *tfm, int enc, |
Jussi Kivilinna | 08d6af8 | 2012-09-21 10:26:47 +0300 | [diff] [blame] | 926 | struct cipher_testvec *template, unsigned int tcount, |
Jussi Kivilinna | 3a338f2 | 2013-06-13 17:37:45 +0300 | [diff] [blame] | 927 | const bool diff_dst, const int align_offset) |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 928 | { |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 929 | const char *algo = |
Herbert Xu | 12773d9 | 2015-08-20 15:21:46 +0800 | [diff] [blame] | 930 | crypto_tfm_alg_driver_name(crypto_skcipher_tfm(tfm)); |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 931 | unsigned int i, j, k, n, temp; |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 932 | char *q; |
Herbert Xu | 12773d9 | 2015-08-20 15:21:46 +0800 | [diff] [blame] | 933 | struct skcipher_request *req; |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 934 | struct scatterlist sg[8]; |
Jussi Kivilinna | 08d6af8 | 2012-09-21 10:26:47 +0300 | [diff] [blame] | 935 | struct scatterlist sgout[8]; |
| 936 | const char *e, *d; |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 937 | struct tcrypt_result result; |
| 938 | void *data; |
| 939 | char iv[MAX_IVLEN]; |
Herbert Xu | f8b0d4d | 2009-05-06 14:15:47 +0800 | [diff] [blame] | 940 | char *xbuf[XBUFSIZE]; |
Jussi Kivilinna | 08d6af8 | 2012-09-21 10:26:47 +0300 | [diff] [blame] | 941 | char *xoutbuf[XBUFSIZE]; |
Herbert Xu | f8b0d4d | 2009-05-06 14:15:47 +0800 | [diff] [blame] | 942 | int ret = -ENOMEM; |
| 943 | |
| 944 | if (testmgr_alloc_buf(xbuf)) |
| 945 | goto out_nobuf; |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 946 | |
Jussi Kivilinna | 08d6af8 | 2012-09-21 10:26:47 +0300 | [diff] [blame] | 947 | if (diff_dst && testmgr_alloc_buf(xoutbuf)) |
| 948 | goto out_nooutbuf; |
| 949 | |
| 950 | if (diff_dst) |
| 951 | d = "-ddst"; |
| 952 | else |
| 953 | d = ""; |
| 954 | |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 955 | if (enc == ENCRYPT) |
| 956 | e = "encryption"; |
| 957 | else |
| 958 | e = "decryption"; |
| 959 | |
| 960 | init_completion(&result.completion); |
| 961 | |
Herbert Xu | 12773d9 | 2015-08-20 15:21:46 +0800 | [diff] [blame] | 962 | req = skcipher_request_alloc(tfm, GFP_KERNEL); |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 963 | if (!req) { |
Jussi Kivilinna | 08d6af8 | 2012-09-21 10:26:47 +0300 | [diff] [blame] | 964 | pr_err("alg: skcipher%s: Failed to allocate request for %s\n", |
| 965 | d, algo); |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 966 | goto out; |
| 967 | } |
| 968 | |
Herbert Xu | 12773d9 | 2015-08-20 15:21:46 +0800 | [diff] [blame] | 969 | skcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, |
| 970 | tcrypt_complete, &result); |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 971 | |
| 972 | j = 0; |
| 973 | for (i = 0; i < tcount; i++) { |
Cristian Stoica | bbb9a7d | 2014-08-08 14:27:52 +0300 | [diff] [blame] | 974 | if (template[i].np && !template[i].also_non_np) |
| 975 | continue; |
| 976 | |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 977 | if (template[i].iv) |
| 978 | memcpy(iv, template[i].iv, MAX_IVLEN); |
| 979 | else |
| 980 | memset(iv, 0, MAX_IVLEN); |
| 981 | |
Cristian Stoica | a1aa44a | 2014-08-08 14:27:51 +0300 | [diff] [blame] | 982 | j++; |
Cristian Stoica | a1aa44a | 2014-08-08 14:27:51 +0300 | [diff] [blame] | 983 | ret = -EINVAL; |
| 984 | if (WARN_ON(align_offset + template[i].ilen > PAGE_SIZE)) |
| 985 | goto out; |
| 986 | |
| 987 | data = xbuf[0]; |
| 988 | data += align_offset; |
| 989 | memcpy(data, template[i].input, template[i].ilen); |
| 990 | |
Herbert Xu | 12773d9 | 2015-08-20 15:21:46 +0800 | [diff] [blame] | 991 | crypto_skcipher_clear_flags(tfm, ~0); |
Cristian Stoica | a1aa44a | 2014-08-08 14:27:51 +0300 | [diff] [blame] | 992 | if (template[i].wk) |
Herbert Xu | 12773d9 | 2015-08-20 15:21:46 +0800 | [diff] [blame] | 993 | crypto_skcipher_set_flags(tfm, |
| 994 | CRYPTO_TFM_REQ_WEAK_KEY); |
Cristian Stoica | a1aa44a | 2014-08-08 14:27:51 +0300 | [diff] [blame] | 995 | |
Herbert Xu | 12773d9 | 2015-08-20 15:21:46 +0800 | [diff] [blame] | 996 | ret = crypto_skcipher_setkey(tfm, template[i].key, |
| 997 | template[i].klen); |
Cristian Stoica | a1aa44a | 2014-08-08 14:27:51 +0300 | [diff] [blame] | 998 | if (!ret == template[i].fail) { |
| 999 | pr_err("alg: skcipher%s: setkey failed on test %d for %s: flags=%x\n", |
Herbert Xu | 12773d9 | 2015-08-20 15:21:46 +0800 | [diff] [blame] | 1000 | d, j, algo, crypto_skcipher_get_flags(tfm)); |
Cristian Stoica | a1aa44a | 2014-08-08 14:27:51 +0300 | [diff] [blame] | 1001 | goto out; |
| 1002 | } else if (ret) |
| 1003 | continue; |
| 1004 | |
| 1005 | sg_init_one(&sg[0], data, template[i].ilen); |
| 1006 | if (diff_dst) { |
| 1007 | data = xoutbuf[0]; |
Jussi Kivilinna | 3a338f2 | 2013-06-13 17:37:45 +0300 | [diff] [blame] | 1008 | data += align_offset; |
Cristian Stoica | a1aa44a | 2014-08-08 14:27:51 +0300 | [diff] [blame] | 1009 | sg_init_one(&sgout[0], data, template[i].ilen); |
| 1010 | } |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 1011 | |
Herbert Xu | 12773d9 | 2015-08-20 15:21:46 +0800 | [diff] [blame] | 1012 | skcipher_request_set_crypt(req, sg, (diff_dst) ? sgout : sg, |
| 1013 | template[i].ilen, iv); |
| 1014 | ret = enc ? crypto_skcipher_encrypt(req) : |
| 1015 | crypto_skcipher_decrypt(req); |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 1016 | |
Cristian Stoica | a1aa44a | 2014-08-08 14:27:51 +0300 | [diff] [blame] | 1017 | switch (ret) { |
| 1018 | case 0: |
| 1019 | break; |
| 1020 | case -EINPROGRESS: |
| 1021 | case -EBUSY: |
Rabin Vincent | 8a45ac1 | 2015-01-09 16:25:28 +0100 | [diff] [blame] | 1022 | wait_for_completion(&result.completion); |
| 1023 | reinit_completion(&result.completion); |
| 1024 | ret = result.err; |
| 1025 | if (!ret) |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 1026 | break; |
Cristian Stoica | a1aa44a | 2014-08-08 14:27:51 +0300 | [diff] [blame] | 1027 | /* fall through */ |
| 1028 | default: |
| 1029 | pr_err("alg: skcipher%s: %s failed on test %d for %s: ret=%d\n", |
| 1030 | d, e, j, algo, -ret); |
| 1031 | goto out; |
| 1032 | } |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 1033 | |
Cristian Stoica | a1aa44a | 2014-08-08 14:27:51 +0300 | [diff] [blame] | 1034 | q = data; |
| 1035 | if (memcmp(q, template[i].result, template[i].rlen)) { |
| 1036 | pr_err("alg: skcipher%s: Test %d failed on %s for %s\n", |
| 1037 | d, j, e, algo); |
| 1038 | hexdump(q, template[i].rlen); |
| 1039 | ret = -EINVAL; |
| 1040 | goto out; |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 1041 | } |
| 1042 | } |
| 1043 | |
| 1044 | j = 0; |
| 1045 | for (i = 0; i < tcount; i++) { |
Jussi Kivilinna | 3a338f2 | 2013-06-13 17:37:45 +0300 | [diff] [blame] | 1046 | /* alignment tests are only done with continuous buffers */ |
| 1047 | if (align_offset != 0) |
| 1048 | break; |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 1049 | |
Cristian Stoica | bbb9a7d | 2014-08-08 14:27:52 +0300 | [diff] [blame] | 1050 | if (!template[i].np) |
| 1051 | continue; |
| 1052 | |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 1053 | if (template[i].iv) |
| 1054 | memcpy(iv, template[i].iv, MAX_IVLEN); |
| 1055 | else |
| 1056 | memset(iv, 0, MAX_IVLEN); |
| 1057 | |
Cristian Stoica | a1aa44a | 2014-08-08 14:27:51 +0300 | [diff] [blame] | 1058 | j++; |
Herbert Xu | 12773d9 | 2015-08-20 15:21:46 +0800 | [diff] [blame] | 1059 | crypto_skcipher_clear_flags(tfm, ~0); |
Cristian Stoica | a1aa44a | 2014-08-08 14:27:51 +0300 | [diff] [blame] | 1060 | if (template[i].wk) |
Herbert Xu | 12773d9 | 2015-08-20 15:21:46 +0800 | [diff] [blame] | 1061 | crypto_skcipher_set_flags(tfm, |
| 1062 | CRYPTO_TFM_REQ_WEAK_KEY); |
Cristian Stoica | a1aa44a | 2014-08-08 14:27:51 +0300 | [diff] [blame] | 1063 | |
Herbert Xu | 12773d9 | 2015-08-20 15:21:46 +0800 | [diff] [blame] | 1064 | ret = crypto_skcipher_setkey(tfm, template[i].key, |
| 1065 | template[i].klen); |
Cristian Stoica | a1aa44a | 2014-08-08 14:27:51 +0300 | [diff] [blame] | 1066 | if (!ret == template[i].fail) { |
| 1067 | pr_err("alg: skcipher%s: setkey failed on chunk test %d for %s: flags=%x\n", |
Herbert Xu | 12773d9 | 2015-08-20 15:21:46 +0800 | [diff] [blame] | 1068 | d, j, algo, crypto_skcipher_get_flags(tfm)); |
Cristian Stoica | a1aa44a | 2014-08-08 14:27:51 +0300 | [diff] [blame] | 1069 | goto out; |
| 1070 | } else if (ret) |
| 1071 | continue; |
| 1072 | |
| 1073 | temp = 0; |
| 1074 | ret = -EINVAL; |
| 1075 | sg_init_table(sg, template[i].np); |
| 1076 | if (diff_dst) |
| 1077 | sg_init_table(sgout, template[i].np); |
| 1078 | for (k = 0; k < template[i].np; k++) { |
| 1079 | if (WARN_ON(offset_in_page(IDX[k]) + |
| 1080 | template[i].tap[k] > PAGE_SIZE)) |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 1081 | goto out; |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 1082 | |
Cristian Stoica | a1aa44a | 2014-08-08 14:27:51 +0300 | [diff] [blame] | 1083 | q = xbuf[IDX[k] >> PAGE_SHIFT] + offset_in_page(IDX[k]); |
| 1084 | |
| 1085 | memcpy(q, template[i].input + temp, template[i].tap[k]); |
| 1086 | |
| 1087 | if (offset_in_page(q) + template[i].tap[k] < PAGE_SIZE) |
| 1088 | q[template[i].tap[k]] = 0; |
| 1089 | |
| 1090 | sg_set_buf(&sg[k], q, template[i].tap[k]); |
| 1091 | if (diff_dst) { |
| 1092 | q = xoutbuf[IDX[k] >> PAGE_SHIFT] + |
| 1093 | offset_in_page(IDX[k]); |
| 1094 | |
| 1095 | sg_set_buf(&sgout[k], q, template[i].tap[k]); |
| 1096 | |
| 1097 | memset(q, 0, template[i].tap[k]); |
| 1098 | if (offset_in_page(q) + |
| 1099 | template[i].tap[k] < PAGE_SIZE) |
| 1100 | q[template[i].tap[k]] = 0; |
| 1101 | } |
| 1102 | |
| 1103 | temp += template[i].tap[k]; |
| 1104 | } |
| 1105 | |
Herbert Xu | 12773d9 | 2015-08-20 15:21:46 +0800 | [diff] [blame] | 1106 | skcipher_request_set_crypt(req, sg, (diff_dst) ? sgout : sg, |
| 1107 | template[i].ilen, iv); |
Cristian Stoica | a1aa44a | 2014-08-08 14:27:51 +0300 | [diff] [blame] | 1108 | |
Herbert Xu | 12773d9 | 2015-08-20 15:21:46 +0800 | [diff] [blame] | 1109 | ret = enc ? crypto_skcipher_encrypt(req) : |
| 1110 | crypto_skcipher_decrypt(req); |
Cristian Stoica | a1aa44a | 2014-08-08 14:27:51 +0300 | [diff] [blame] | 1111 | |
| 1112 | switch (ret) { |
| 1113 | case 0: |
| 1114 | break; |
| 1115 | case -EINPROGRESS: |
| 1116 | case -EBUSY: |
Rabin Vincent | 8a45ac1 | 2015-01-09 16:25:28 +0100 | [diff] [blame] | 1117 | wait_for_completion(&result.completion); |
| 1118 | reinit_completion(&result.completion); |
| 1119 | ret = result.err; |
| 1120 | if (!ret) |
Cristian Stoica | a1aa44a | 2014-08-08 14:27:51 +0300 | [diff] [blame] | 1121 | break; |
Cristian Stoica | a1aa44a | 2014-08-08 14:27:51 +0300 | [diff] [blame] | 1122 | /* fall through */ |
| 1123 | default: |
| 1124 | pr_err("alg: skcipher%s: %s failed on chunk test %d for %s: ret=%d\n", |
| 1125 | d, e, j, algo, -ret); |
| 1126 | goto out; |
| 1127 | } |
| 1128 | |
| 1129 | temp = 0; |
| 1130 | ret = -EINVAL; |
| 1131 | for (k = 0; k < template[i].np; k++) { |
Jussi Kivilinna | 08d6af8 | 2012-09-21 10:26:47 +0300 | [diff] [blame] | 1132 | if (diff_dst) |
Cristian Stoica | a1aa44a | 2014-08-08 14:27:51 +0300 | [diff] [blame] | 1133 | q = xoutbuf[IDX[k] >> PAGE_SHIFT] + |
| 1134 | offset_in_page(IDX[k]); |
| 1135 | else |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 1136 | q = xbuf[IDX[k] >> PAGE_SHIFT] + |
| 1137 | offset_in_page(IDX[k]); |
| 1138 | |
Cristian Stoica | a1aa44a | 2014-08-08 14:27:51 +0300 | [diff] [blame] | 1139 | if (memcmp(q, template[i].result + temp, |
| 1140 | template[i].tap[k])) { |
| 1141 | pr_err("alg: skcipher%s: Chunk test %d failed on %s at page %u for %s\n", |
| 1142 | d, j, e, k, algo); |
| 1143 | hexdump(q, template[i].tap[k]); |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 1144 | goto out; |
| 1145 | } |
| 1146 | |
Cristian Stoica | a1aa44a | 2014-08-08 14:27:51 +0300 | [diff] [blame] | 1147 | q += template[i].tap[k]; |
| 1148 | for (n = 0; offset_in_page(q + n) && q[n]; n++) |
| 1149 | ; |
| 1150 | if (n) { |
| 1151 | pr_err("alg: skcipher%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n", |
| 1152 | d, j, e, k, algo, n); |
| 1153 | hexdump(q, n); |
| 1154 | goto out; |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 1155 | } |
Cristian Stoica | a1aa44a | 2014-08-08 14:27:51 +0300 | [diff] [blame] | 1156 | temp += template[i].tap[k]; |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 1157 | } |
| 1158 | } |
| 1159 | |
| 1160 | ret = 0; |
| 1161 | |
| 1162 | out: |
Herbert Xu | 12773d9 | 2015-08-20 15:21:46 +0800 | [diff] [blame] | 1163 | skcipher_request_free(req); |
Jussi Kivilinna | 08d6af8 | 2012-09-21 10:26:47 +0300 | [diff] [blame] | 1164 | if (diff_dst) |
| 1165 | testmgr_free_buf(xoutbuf); |
| 1166 | out_nooutbuf: |
Herbert Xu | f8b0d4d | 2009-05-06 14:15:47 +0800 | [diff] [blame] | 1167 | testmgr_free_buf(xbuf); |
| 1168 | out_nobuf: |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 1169 | return ret; |
| 1170 | } |
| 1171 | |
Herbert Xu | 12773d9 | 2015-08-20 15:21:46 +0800 | [diff] [blame] | 1172 | static int test_skcipher(struct crypto_skcipher *tfm, int enc, |
Jussi Kivilinna | 08d6af8 | 2012-09-21 10:26:47 +0300 | [diff] [blame] | 1173 | struct cipher_testvec *template, unsigned int tcount) |
| 1174 | { |
Jussi Kivilinna | 3a338f2 | 2013-06-13 17:37:45 +0300 | [diff] [blame] | 1175 | unsigned int alignmask; |
Jussi Kivilinna | 08d6af8 | 2012-09-21 10:26:47 +0300 | [diff] [blame] | 1176 | int ret; |
| 1177 | |
| 1178 | /* test 'dst == src' case */ |
Jussi Kivilinna | 3a338f2 | 2013-06-13 17:37:45 +0300 | [diff] [blame] | 1179 | ret = __test_skcipher(tfm, enc, template, tcount, false, 0); |
Jussi Kivilinna | 08d6af8 | 2012-09-21 10:26:47 +0300 | [diff] [blame] | 1180 | if (ret) |
| 1181 | return ret; |
| 1182 | |
| 1183 | /* test 'dst != src' case */ |
Jussi Kivilinna | 3a338f2 | 2013-06-13 17:37:45 +0300 | [diff] [blame] | 1184 | ret = __test_skcipher(tfm, enc, template, tcount, true, 0); |
| 1185 | if (ret) |
| 1186 | return ret; |
| 1187 | |
| 1188 | /* test unaligned buffers, check with one byte offset */ |
| 1189 | ret = __test_skcipher(tfm, enc, template, tcount, true, 1); |
| 1190 | if (ret) |
| 1191 | return ret; |
| 1192 | |
| 1193 | alignmask = crypto_tfm_alg_alignmask(&tfm->base); |
| 1194 | if (alignmask) { |
| 1195 | /* Check if alignment mask for tfm is correctly set. */ |
| 1196 | ret = __test_skcipher(tfm, enc, template, tcount, true, |
| 1197 | alignmask + 1); |
| 1198 | if (ret) |
| 1199 | return ret; |
| 1200 | } |
| 1201 | |
| 1202 | return 0; |
Jussi Kivilinna | 08d6af8 | 2012-09-21 10:26:47 +0300 | [diff] [blame] | 1203 | } |
| 1204 | |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 1205 | static int test_comp(struct crypto_comp *tfm, struct comp_testvec *ctemplate, |
| 1206 | struct comp_testvec *dtemplate, int ctcount, int dtcount) |
| 1207 | { |
| 1208 | const char *algo = crypto_tfm_alg_driver_name(crypto_comp_tfm(tfm)); |
| 1209 | unsigned int i; |
| 1210 | char result[COMP_BUF_SIZE]; |
| 1211 | int ret; |
| 1212 | |
| 1213 | for (i = 0; i < ctcount; i++) { |
Geert Uytterhoeven | c79cf91 | 2009-03-29 15:44:19 +0800 | [diff] [blame] | 1214 | int ilen; |
| 1215 | unsigned int dlen = COMP_BUF_SIZE; |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 1216 | |
| 1217 | memset(result, 0, sizeof (result)); |
| 1218 | |
| 1219 | ilen = ctemplate[i].inlen; |
| 1220 | ret = crypto_comp_compress(tfm, ctemplate[i].input, |
| 1221 | ilen, result, &dlen); |
| 1222 | if (ret) { |
| 1223 | printk(KERN_ERR "alg: comp: compression failed " |
| 1224 | "on test %d for %s: ret=%d\n", i + 1, algo, |
| 1225 | -ret); |
| 1226 | goto out; |
| 1227 | } |
| 1228 | |
Geert Uytterhoeven | b812eb0 | 2008-11-28 20:51:28 +0800 | [diff] [blame] | 1229 | if (dlen != ctemplate[i].outlen) { |
| 1230 | printk(KERN_ERR "alg: comp: Compression test %d " |
| 1231 | "failed for %s: output len = %d\n", i + 1, algo, |
| 1232 | dlen); |
| 1233 | ret = -EINVAL; |
| 1234 | goto out; |
| 1235 | } |
| 1236 | |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 1237 | if (memcmp(result, ctemplate[i].output, dlen)) { |
| 1238 | printk(KERN_ERR "alg: comp: Compression test %d " |
| 1239 | "failed for %s\n", i + 1, algo); |
| 1240 | hexdump(result, dlen); |
| 1241 | ret = -EINVAL; |
| 1242 | goto out; |
| 1243 | } |
| 1244 | } |
| 1245 | |
| 1246 | for (i = 0; i < dtcount; i++) { |
Geert Uytterhoeven | c79cf91 | 2009-03-29 15:44:19 +0800 | [diff] [blame] | 1247 | int ilen; |
| 1248 | unsigned int dlen = COMP_BUF_SIZE; |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 1249 | |
| 1250 | memset(result, 0, sizeof (result)); |
| 1251 | |
| 1252 | ilen = dtemplate[i].inlen; |
| 1253 | ret = crypto_comp_decompress(tfm, dtemplate[i].input, |
| 1254 | ilen, result, &dlen); |
| 1255 | if (ret) { |
| 1256 | printk(KERN_ERR "alg: comp: decompression failed " |
| 1257 | "on test %d for %s: ret=%d\n", i + 1, algo, |
| 1258 | -ret); |
| 1259 | goto out; |
| 1260 | } |
| 1261 | |
Geert Uytterhoeven | b812eb0 | 2008-11-28 20:51:28 +0800 | [diff] [blame] | 1262 | if (dlen != dtemplate[i].outlen) { |
| 1263 | printk(KERN_ERR "alg: comp: Decompression test %d " |
| 1264 | "failed for %s: output len = %d\n", i + 1, algo, |
| 1265 | dlen); |
| 1266 | ret = -EINVAL; |
| 1267 | goto out; |
| 1268 | } |
| 1269 | |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 1270 | if (memcmp(result, dtemplate[i].output, dlen)) { |
| 1271 | printk(KERN_ERR "alg: comp: Decompression test %d " |
| 1272 | "failed for %s\n", i + 1, algo); |
| 1273 | hexdump(result, dlen); |
| 1274 | ret = -EINVAL; |
| 1275 | goto out; |
| 1276 | } |
| 1277 | } |
| 1278 | |
| 1279 | ret = 0; |
| 1280 | |
| 1281 | out: |
| 1282 | return ret; |
| 1283 | } |
| 1284 | |
Geert Uytterhoeven | 8064efb | 2009-03-04 15:08:03 +0800 | [diff] [blame] | 1285 | static int test_pcomp(struct crypto_pcomp *tfm, |
| 1286 | struct pcomp_testvec *ctemplate, |
| 1287 | struct pcomp_testvec *dtemplate, int ctcount, |
| 1288 | int dtcount) |
| 1289 | { |
| 1290 | const char *algo = crypto_tfm_alg_driver_name(crypto_pcomp_tfm(tfm)); |
| 1291 | unsigned int i; |
| 1292 | char result[COMP_BUF_SIZE]; |
Geert Uytterhoeven | 3ce858c | 2009-05-27 15:05:02 +1000 | [diff] [blame] | 1293 | int res; |
Geert Uytterhoeven | 8064efb | 2009-03-04 15:08:03 +0800 | [diff] [blame] | 1294 | |
| 1295 | for (i = 0; i < ctcount; i++) { |
| 1296 | struct comp_request req; |
Geert Uytterhoeven | 3ce858c | 2009-05-27 15:05:02 +1000 | [diff] [blame] | 1297 | unsigned int produced = 0; |
Geert Uytterhoeven | 8064efb | 2009-03-04 15:08:03 +0800 | [diff] [blame] | 1298 | |
Geert Uytterhoeven | 3ce858c | 2009-05-27 15:05:02 +1000 | [diff] [blame] | 1299 | res = crypto_compress_setup(tfm, ctemplate[i].params, |
| 1300 | ctemplate[i].paramsize); |
| 1301 | if (res) { |
Geert Uytterhoeven | 8064efb | 2009-03-04 15:08:03 +0800 | [diff] [blame] | 1302 | pr_err("alg: pcomp: compression setup failed on test " |
Geert Uytterhoeven | 3ce858c | 2009-05-27 15:05:02 +1000 | [diff] [blame] | 1303 | "%d for %s: error=%d\n", i + 1, algo, res); |
| 1304 | return res; |
Geert Uytterhoeven | 8064efb | 2009-03-04 15:08:03 +0800 | [diff] [blame] | 1305 | } |
| 1306 | |
Geert Uytterhoeven | 3ce858c | 2009-05-27 15:05:02 +1000 | [diff] [blame] | 1307 | res = crypto_compress_init(tfm); |
| 1308 | if (res) { |
Geert Uytterhoeven | 8064efb | 2009-03-04 15:08:03 +0800 | [diff] [blame] | 1309 | pr_err("alg: pcomp: compression init failed on test " |
Geert Uytterhoeven | 3ce858c | 2009-05-27 15:05:02 +1000 | [diff] [blame] | 1310 | "%d for %s: error=%d\n", i + 1, algo, res); |
| 1311 | return res; |
Geert Uytterhoeven | 8064efb | 2009-03-04 15:08:03 +0800 | [diff] [blame] | 1312 | } |
| 1313 | |
| 1314 | memset(result, 0, sizeof(result)); |
| 1315 | |
| 1316 | req.next_in = ctemplate[i].input; |
| 1317 | req.avail_in = ctemplate[i].inlen / 2; |
| 1318 | req.next_out = result; |
| 1319 | req.avail_out = ctemplate[i].outlen / 2; |
| 1320 | |
Geert Uytterhoeven | 3ce858c | 2009-05-27 15:05:02 +1000 | [diff] [blame] | 1321 | res = crypto_compress_update(tfm, &req); |
| 1322 | if (res < 0 && (res != -EAGAIN || req.avail_in)) { |
Geert Uytterhoeven | 8064efb | 2009-03-04 15:08:03 +0800 | [diff] [blame] | 1323 | pr_err("alg: pcomp: compression update failed on test " |
Geert Uytterhoeven | 3ce858c | 2009-05-27 15:05:02 +1000 | [diff] [blame] | 1324 | "%d for %s: error=%d\n", i + 1, algo, res); |
| 1325 | return res; |
Geert Uytterhoeven | 8064efb | 2009-03-04 15:08:03 +0800 | [diff] [blame] | 1326 | } |
Geert Uytterhoeven | 3ce858c | 2009-05-27 15:05:02 +1000 | [diff] [blame] | 1327 | if (res > 0) |
| 1328 | produced += res; |
Geert Uytterhoeven | 8064efb | 2009-03-04 15:08:03 +0800 | [diff] [blame] | 1329 | |
| 1330 | /* Add remaining input data */ |
| 1331 | req.avail_in += (ctemplate[i].inlen + 1) / 2; |
| 1332 | |
Geert Uytterhoeven | 3ce858c | 2009-05-27 15:05:02 +1000 | [diff] [blame] | 1333 | res = crypto_compress_update(tfm, &req); |
| 1334 | if (res < 0 && (res != -EAGAIN || req.avail_in)) { |
Geert Uytterhoeven | 8064efb | 2009-03-04 15:08:03 +0800 | [diff] [blame] | 1335 | pr_err("alg: pcomp: compression update failed on test " |
Geert Uytterhoeven | 3ce858c | 2009-05-27 15:05:02 +1000 | [diff] [blame] | 1336 | "%d for %s: error=%d\n", i + 1, algo, res); |
| 1337 | return res; |
Geert Uytterhoeven | 8064efb | 2009-03-04 15:08:03 +0800 | [diff] [blame] | 1338 | } |
Geert Uytterhoeven | 3ce858c | 2009-05-27 15:05:02 +1000 | [diff] [blame] | 1339 | if (res > 0) |
| 1340 | produced += res; |
Geert Uytterhoeven | 8064efb | 2009-03-04 15:08:03 +0800 | [diff] [blame] | 1341 | |
| 1342 | /* Provide remaining output space */ |
| 1343 | req.avail_out += COMP_BUF_SIZE - ctemplate[i].outlen / 2; |
| 1344 | |
Geert Uytterhoeven | 3ce858c | 2009-05-27 15:05:02 +1000 | [diff] [blame] | 1345 | res = crypto_compress_final(tfm, &req); |
| 1346 | if (res < 0) { |
Geert Uytterhoeven | 8064efb | 2009-03-04 15:08:03 +0800 | [diff] [blame] | 1347 | pr_err("alg: pcomp: compression final failed on test " |
Geert Uytterhoeven | 3ce858c | 2009-05-27 15:05:02 +1000 | [diff] [blame] | 1348 | "%d for %s: error=%d\n", i + 1, algo, res); |
| 1349 | return res; |
Geert Uytterhoeven | 8064efb | 2009-03-04 15:08:03 +0800 | [diff] [blame] | 1350 | } |
Geert Uytterhoeven | 3ce858c | 2009-05-27 15:05:02 +1000 | [diff] [blame] | 1351 | produced += res; |
Geert Uytterhoeven | 8064efb | 2009-03-04 15:08:03 +0800 | [diff] [blame] | 1352 | |
| 1353 | if (COMP_BUF_SIZE - req.avail_out != ctemplate[i].outlen) { |
| 1354 | pr_err("alg: comp: Compression test %d failed for %s: " |
| 1355 | "output len = %d (expected %d)\n", i + 1, algo, |
| 1356 | COMP_BUF_SIZE - req.avail_out, |
| 1357 | ctemplate[i].outlen); |
| 1358 | return -EINVAL; |
| 1359 | } |
| 1360 | |
Geert Uytterhoeven | 3ce858c | 2009-05-27 15:05:02 +1000 | [diff] [blame] | 1361 | if (produced != ctemplate[i].outlen) { |
| 1362 | pr_err("alg: comp: Compression test %d failed for %s: " |
| 1363 | "returned len = %u (expected %d)\n", i + 1, |
| 1364 | algo, produced, ctemplate[i].outlen); |
| 1365 | return -EINVAL; |
| 1366 | } |
| 1367 | |
Geert Uytterhoeven | 8064efb | 2009-03-04 15:08:03 +0800 | [diff] [blame] | 1368 | if (memcmp(result, ctemplate[i].output, ctemplate[i].outlen)) { |
| 1369 | pr_err("alg: pcomp: Compression test %d failed for " |
| 1370 | "%s\n", i + 1, algo); |
| 1371 | hexdump(result, ctemplate[i].outlen); |
| 1372 | return -EINVAL; |
| 1373 | } |
| 1374 | } |
| 1375 | |
| 1376 | for (i = 0; i < dtcount; i++) { |
| 1377 | struct comp_request req; |
Geert Uytterhoeven | 3ce858c | 2009-05-27 15:05:02 +1000 | [diff] [blame] | 1378 | unsigned int produced = 0; |
Geert Uytterhoeven | 8064efb | 2009-03-04 15:08:03 +0800 | [diff] [blame] | 1379 | |
Geert Uytterhoeven | 3ce858c | 2009-05-27 15:05:02 +1000 | [diff] [blame] | 1380 | res = crypto_decompress_setup(tfm, dtemplate[i].params, |
| 1381 | dtemplate[i].paramsize); |
| 1382 | if (res) { |
Geert Uytterhoeven | 8064efb | 2009-03-04 15:08:03 +0800 | [diff] [blame] | 1383 | pr_err("alg: pcomp: decompression setup failed on " |
Geert Uytterhoeven | 3ce858c | 2009-05-27 15:05:02 +1000 | [diff] [blame] | 1384 | "test %d for %s: error=%d\n", i + 1, algo, res); |
| 1385 | return res; |
Geert Uytterhoeven | 8064efb | 2009-03-04 15:08:03 +0800 | [diff] [blame] | 1386 | } |
| 1387 | |
Geert Uytterhoeven | 3ce858c | 2009-05-27 15:05:02 +1000 | [diff] [blame] | 1388 | res = crypto_decompress_init(tfm); |
| 1389 | if (res) { |
Geert Uytterhoeven | 8064efb | 2009-03-04 15:08:03 +0800 | [diff] [blame] | 1390 | pr_err("alg: pcomp: decompression init failed on test " |
Geert Uytterhoeven | 3ce858c | 2009-05-27 15:05:02 +1000 | [diff] [blame] | 1391 | "%d for %s: error=%d\n", i + 1, algo, res); |
| 1392 | return res; |
Geert Uytterhoeven | 8064efb | 2009-03-04 15:08:03 +0800 | [diff] [blame] | 1393 | } |
| 1394 | |
| 1395 | memset(result, 0, sizeof(result)); |
| 1396 | |
| 1397 | req.next_in = dtemplate[i].input; |
| 1398 | req.avail_in = dtemplate[i].inlen / 2; |
| 1399 | req.next_out = result; |
| 1400 | req.avail_out = dtemplate[i].outlen / 2; |
| 1401 | |
Geert Uytterhoeven | 3ce858c | 2009-05-27 15:05:02 +1000 | [diff] [blame] | 1402 | res = crypto_decompress_update(tfm, &req); |
| 1403 | if (res < 0 && (res != -EAGAIN || req.avail_in)) { |
Geert Uytterhoeven | 8064efb | 2009-03-04 15:08:03 +0800 | [diff] [blame] | 1404 | pr_err("alg: pcomp: decompression update failed on " |
Geert Uytterhoeven | 3ce858c | 2009-05-27 15:05:02 +1000 | [diff] [blame] | 1405 | "test %d for %s: error=%d\n", i + 1, algo, res); |
| 1406 | return res; |
Geert Uytterhoeven | 8064efb | 2009-03-04 15:08:03 +0800 | [diff] [blame] | 1407 | } |
Geert Uytterhoeven | 3ce858c | 2009-05-27 15:05:02 +1000 | [diff] [blame] | 1408 | if (res > 0) |
| 1409 | produced += res; |
Geert Uytterhoeven | 8064efb | 2009-03-04 15:08:03 +0800 | [diff] [blame] | 1410 | |
| 1411 | /* Add remaining input data */ |
| 1412 | req.avail_in += (dtemplate[i].inlen + 1) / 2; |
| 1413 | |
Geert Uytterhoeven | 3ce858c | 2009-05-27 15:05:02 +1000 | [diff] [blame] | 1414 | res = crypto_decompress_update(tfm, &req); |
| 1415 | if (res < 0 && (res != -EAGAIN || req.avail_in)) { |
Geert Uytterhoeven | 8064efb | 2009-03-04 15:08:03 +0800 | [diff] [blame] | 1416 | pr_err("alg: pcomp: decompression update failed on " |
Geert Uytterhoeven | 3ce858c | 2009-05-27 15:05:02 +1000 | [diff] [blame] | 1417 | "test %d for %s: error=%d\n", i + 1, algo, res); |
| 1418 | return res; |
Geert Uytterhoeven | 8064efb | 2009-03-04 15:08:03 +0800 | [diff] [blame] | 1419 | } |
Geert Uytterhoeven | 3ce858c | 2009-05-27 15:05:02 +1000 | [diff] [blame] | 1420 | if (res > 0) |
| 1421 | produced += res; |
Geert Uytterhoeven | 8064efb | 2009-03-04 15:08:03 +0800 | [diff] [blame] | 1422 | |
| 1423 | /* Provide remaining output space */ |
| 1424 | req.avail_out += COMP_BUF_SIZE - dtemplate[i].outlen / 2; |
| 1425 | |
Geert Uytterhoeven | 3ce858c | 2009-05-27 15:05:02 +1000 | [diff] [blame] | 1426 | res = crypto_decompress_final(tfm, &req); |
| 1427 | if (res < 0 && (res != -EAGAIN || req.avail_in)) { |
Geert Uytterhoeven | 8064efb | 2009-03-04 15:08:03 +0800 | [diff] [blame] | 1428 | pr_err("alg: pcomp: decompression final failed on " |
Geert Uytterhoeven | 3ce858c | 2009-05-27 15:05:02 +1000 | [diff] [blame] | 1429 | "test %d for %s: error=%d\n", i + 1, algo, res); |
| 1430 | return res; |
Geert Uytterhoeven | 8064efb | 2009-03-04 15:08:03 +0800 | [diff] [blame] | 1431 | } |
Geert Uytterhoeven | 3ce858c | 2009-05-27 15:05:02 +1000 | [diff] [blame] | 1432 | if (res > 0) |
| 1433 | produced += res; |
Geert Uytterhoeven | 8064efb | 2009-03-04 15:08:03 +0800 | [diff] [blame] | 1434 | |
| 1435 | if (COMP_BUF_SIZE - req.avail_out != dtemplate[i].outlen) { |
| 1436 | pr_err("alg: comp: Decompression test %d failed for " |
| 1437 | "%s: output len = %d (expected %d)\n", i + 1, |
| 1438 | algo, COMP_BUF_SIZE - req.avail_out, |
| 1439 | dtemplate[i].outlen); |
| 1440 | return -EINVAL; |
| 1441 | } |
| 1442 | |
Geert Uytterhoeven | 3ce858c | 2009-05-27 15:05:02 +1000 | [diff] [blame] | 1443 | if (produced != dtemplate[i].outlen) { |
| 1444 | pr_err("alg: comp: Decompression test %d failed for " |
| 1445 | "%s: returned len = %u (expected %d)\n", i + 1, |
| 1446 | algo, produced, dtemplate[i].outlen); |
| 1447 | return -EINVAL; |
| 1448 | } |
| 1449 | |
Geert Uytterhoeven | 8064efb | 2009-03-04 15:08:03 +0800 | [diff] [blame] | 1450 | if (memcmp(result, dtemplate[i].output, dtemplate[i].outlen)) { |
| 1451 | pr_err("alg: pcomp: Decompression test %d failed for " |
| 1452 | "%s\n", i + 1, algo); |
| 1453 | hexdump(result, dtemplate[i].outlen); |
| 1454 | return -EINVAL; |
| 1455 | } |
| 1456 | } |
| 1457 | |
| 1458 | return 0; |
| 1459 | } |
| 1460 | |
Jarod Wilson | 7647d6c | 2009-05-04 19:44:50 +0800 | [diff] [blame] | 1461 | |
| 1462 | static int test_cprng(struct crypto_rng *tfm, struct cprng_testvec *template, |
| 1463 | unsigned int tcount) |
| 1464 | { |
| 1465 | const char *algo = crypto_tfm_alg_driver_name(crypto_rng_tfm(tfm)); |
Felipe Contreras | fa4ef8a | 2009-10-27 19:04:42 +0800 | [diff] [blame] | 1466 | int err = 0, i, j, seedsize; |
Jarod Wilson | 7647d6c | 2009-05-04 19:44:50 +0800 | [diff] [blame] | 1467 | u8 *seed; |
| 1468 | char result[32]; |
| 1469 | |
| 1470 | seedsize = crypto_rng_seedsize(tfm); |
| 1471 | |
| 1472 | seed = kmalloc(seedsize, GFP_KERNEL); |
| 1473 | if (!seed) { |
| 1474 | printk(KERN_ERR "alg: cprng: Failed to allocate seed space " |
| 1475 | "for %s\n", algo); |
| 1476 | return -ENOMEM; |
| 1477 | } |
| 1478 | |
| 1479 | for (i = 0; i < tcount; i++) { |
| 1480 | memset(result, 0, 32); |
| 1481 | |
| 1482 | memcpy(seed, template[i].v, template[i].vlen); |
| 1483 | memcpy(seed + template[i].vlen, template[i].key, |
| 1484 | template[i].klen); |
| 1485 | memcpy(seed + template[i].vlen + template[i].klen, |
| 1486 | template[i].dt, template[i].dtlen); |
| 1487 | |
| 1488 | err = crypto_rng_reset(tfm, seed, seedsize); |
| 1489 | if (err) { |
| 1490 | printk(KERN_ERR "alg: cprng: Failed to reset rng " |
| 1491 | "for %s\n", algo); |
| 1492 | goto out; |
| 1493 | } |
| 1494 | |
| 1495 | for (j = 0; j < template[i].loops; j++) { |
| 1496 | err = crypto_rng_get_bytes(tfm, result, |
| 1497 | template[i].rlen); |
Stephan Mueller | 19e60e1 | 2015-03-10 17:00:36 +0100 | [diff] [blame] | 1498 | if (err < 0) { |
Jarod Wilson | 7647d6c | 2009-05-04 19:44:50 +0800 | [diff] [blame] | 1499 | printk(KERN_ERR "alg: cprng: Failed to obtain " |
| 1500 | "the correct amount of random data for " |
Stephan Mueller | 19e60e1 | 2015-03-10 17:00:36 +0100 | [diff] [blame] | 1501 | "%s (requested %d)\n", algo, |
| 1502 | template[i].rlen); |
Jarod Wilson | 7647d6c | 2009-05-04 19:44:50 +0800 | [diff] [blame] | 1503 | goto out; |
| 1504 | } |
| 1505 | } |
| 1506 | |
| 1507 | err = memcmp(result, template[i].result, |
| 1508 | template[i].rlen); |
| 1509 | if (err) { |
| 1510 | printk(KERN_ERR "alg: cprng: Test %d failed for %s\n", |
| 1511 | i, algo); |
| 1512 | hexdump(result, template[i].rlen); |
| 1513 | err = -EINVAL; |
| 1514 | goto out; |
| 1515 | } |
| 1516 | } |
| 1517 | |
| 1518 | out: |
| 1519 | kfree(seed); |
| 1520 | return err; |
| 1521 | } |
| 1522 | |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 1523 | static int alg_test_aead(const struct alg_test_desc *desc, const char *driver, |
| 1524 | u32 type, u32 mask) |
| 1525 | { |
| 1526 | struct crypto_aead *tfm; |
| 1527 | int err = 0; |
| 1528 | |
Stephan Mueller | 425a882 | 2015-03-30 21:56:31 +0200 | [diff] [blame] | 1529 | tfm = crypto_alloc_aead(driver, type | CRYPTO_ALG_INTERNAL, mask); |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 1530 | if (IS_ERR(tfm)) { |
| 1531 | printk(KERN_ERR "alg: aead: Failed to load transform for %s: " |
| 1532 | "%ld\n", driver, PTR_ERR(tfm)); |
| 1533 | return PTR_ERR(tfm); |
| 1534 | } |
| 1535 | |
| 1536 | if (desc->suite.aead.enc.vecs) { |
| 1537 | err = test_aead(tfm, ENCRYPT, desc->suite.aead.enc.vecs, |
| 1538 | desc->suite.aead.enc.count); |
| 1539 | if (err) |
| 1540 | goto out; |
| 1541 | } |
| 1542 | |
| 1543 | if (!err && desc->suite.aead.dec.vecs) |
| 1544 | err = test_aead(tfm, DECRYPT, desc->suite.aead.dec.vecs, |
| 1545 | desc->suite.aead.dec.count); |
| 1546 | |
| 1547 | out: |
| 1548 | crypto_free_aead(tfm); |
| 1549 | return err; |
| 1550 | } |
| 1551 | |
| 1552 | static int alg_test_cipher(const struct alg_test_desc *desc, |
| 1553 | const char *driver, u32 type, u32 mask) |
| 1554 | { |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 1555 | struct crypto_cipher *tfm; |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 1556 | int err = 0; |
| 1557 | |
Stephan Mueller | 425a882 | 2015-03-30 21:56:31 +0200 | [diff] [blame] | 1558 | tfm = crypto_alloc_cipher(driver, type | CRYPTO_ALG_INTERNAL, mask); |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 1559 | if (IS_ERR(tfm)) { |
| 1560 | printk(KERN_ERR "alg: cipher: Failed to load transform for " |
| 1561 | "%s: %ld\n", driver, PTR_ERR(tfm)); |
| 1562 | return PTR_ERR(tfm); |
| 1563 | } |
| 1564 | |
| 1565 | if (desc->suite.cipher.enc.vecs) { |
| 1566 | err = test_cipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs, |
| 1567 | desc->suite.cipher.enc.count); |
| 1568 | if (err) |
| 1569 | goto out; |
| 1570 | } |
| 1571 | |
| 1572 | if (desc->suite.cipher.dec.vecs) |
| 1573 | err = test_cipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs, |
| 1574 | desc->suite.cipher.dec.count); |
| 1575 | |
| 1576 | out: |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 1577 | crypto_free_cipher(tfm); |
| 1578 | return err; |
| 1579 | } |
| 1580 | |
| 1581 | static int alg_test_skcipher(const struct alg_test_desc *desc, |
| 1582 | const char *driver, u32 type, u32 mask) |
| 1583 | { |
Herbert Xu | 12773d9 | 2015-08-20 15:21:46 +0800 | [diff] [blame] | 1584 | struct crypto_skcipher *tfm; |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 1585 | int err = 0; |
| 1586 | |
Herbert Xu | 12773d9 | 2015-08-20 15:21:46 +0800 | [diff] [blame] | 1587 | tfm = crypto_alloc_skcipher(driver, type | CRYPTO_ALG_INTERNAL, mask); |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 1588 | if (IS_ERR(tfm)) { |
| 1589 | printk(KERN_ERR "alg: skcipher: Failed to load transform for " |
| 1590 | "%s: %ld\n", driver, PTR_ERR(tfm)); |
| 1591 | return PTR_ERR(tfm); |
| 1592 | } |
| 1593 | |
| 1594 | if (desc->suite.cipher.enc.vecs) { |
| 1595 | err = test_skcipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs, |
| 1596 | desc->suite.cipher.enc.count); |
| 1597 | if (err) |
| 1598 | goto out; |
| 1599 | } |
| 1600 | |
| 1601 | if (desc->suite.cipher.dec.vecs) |
| 1602 | err = test_skcipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs, |
| 1603 | desc->suite.cipher.dec.count); |
| 1604 | |
| 1605 | out: |
Herbert Xu | 12773d9 | 2015-08-20 15:21:46 +0800 | [diff] [blame] | 1606 | crypto_free_skcipher(tfm); |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 1607 | return err; |
| 1608 | } |
| 1609 | |
| 1610 | static int alg_test_comp(const struct alg_test_desc *desc, const char *driver, |
| 1611 | u32 type, u32 mask) |
| 1612 | { |
| 1613 | struct crypto_comp *tfm; |
| 1614 | int err; |
| 1615 | |
| 1616 | tfm = crypto_alloc_comp(driver, type, mask); |
| 1617 | if (IS_ERR(tfm)) { |
| 1618 | printk(KERN_ERR "alg: comp: Failed to load transform for %s: " |
| 1619 | "%ld\n", driver, PTR_ERR(tfm)); |
| 1620 | return PTR_ERR(tfm); |
| 1621 | } |
| 1622 | |
| 1623 | err = test_comp(tfm, desc->suite.comp.comp.vecs, |
| 1624 | desc->suite.comp.decomp.vecs, |
| 1625 | desc->suite.comp.comp.count, |
| 1626 | desc->suite.comp.decomp.count); |
| 1627 | |
| 1628 | crypto_free_comp(tfm); |
| 1629 | return err; |
| 1630 | } |
| 1631 | |
Geert Uytterhoeven | 8064efb | 2009-03-04 15:08:03 +0800 | [diff] [blame] | 1632 | static int alg_test_pcomp(const struct alg_test_desc *desc, const char *driver, |
| 1633 | u32 type, u32 mask) |
| 1634 | { |
| 1635 | struct crypto_pcomp *tfm; |
| 1636 | int err; |
| 1637 | |
| 1638 | tfm = crypto_alloc_pcomp(driver, type, mask); |
| 1639 | if (IS_ERR(tfm)) { |
| 1640 | pr_err("alg: pcomp: Failed to load transform for %s: %ld\n", |
| 1641 | driver, PTR_ERR(tfm)); |
| 1642 | return PTR_ERR(tfm); |
| 1643 | } |
| 1644 | |
| 1645 | err = test_pcomp(tfm, desc->suite.pcomp.comp.vecs, |
| 1646 | desc->suite.pcomp.decomp.vecs, |
| 1647 | desc->suite.pcomp.comp.count, |
| 1648 | desc->suite.pcomp.decomp.count); |
| 1649 | |
| 1650 | crypto_free_pcomp(tfm); |
| 1651 | return err; |
| 1652 | } |
| 1653 | |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 1654 | static int alg_test_hash(const struct alg_test_desc *desc, const char *driver, |
| 1655 | u32 type, u32 mask) |
| 1656 | { |
| 1657 | struct crypto_ahash *tfm; |
| 1658 | int err; |
| 1659 | |
Stephan Mueller | 425a882 | 2015-03-30 21:56:31 +0200 | [diff] [blame] | 1660 | tfm = crypto_alloc_ahash(driver, type | CRYPTO_ALG_INTERNAL, mask); |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 1661 | if (IS_ERR(tfm)) { |
| 1662 | printk(KERN_ERR "alg: hash: Failed to load transform for %s: " |
| 1663 | "%ld\n", driver, PTR_ERR(tfm)); |
| 1664 | return PTR_ERR(tfm); |
| 1665 | } |
| 1666 | |
David S. Miller | a8f1a05 | 2010-05-19 14:12:03 +1000 | [diff] [blame] | 1667 | err = test_hash(tfm, desc->suite.hash.vecs, |
| 1668 | desc->suite.hash.count, true); |
| 1669 | if (!err) |
| 1670 | err = test_hash(tfm, desc->suite.hash.vecs, |
| 1671 | desc->suite.hash.count, false); |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 1672 | |
| 1673 | crypto_free_ahash(tfm); |
| 1674 | return err; |
| 1675 | } |
| 1676 | |
Herbert Xu | 8e3ee85 | 2008-11-07 14:58:52 +0800 | [diff] [blame] | 1677 | static int alg_test_crc32c(const struct alg_test_desc *desc, |
| 1678 | const char *driver, u32 type, u32 mask) |
| 1679 | { |
| 1680 | struct crypto_shash *tfm; |
| 1681 | u32 val; |
| 1682 | int err; |
| 1683 | |
| 1684 | err = alg_test_hash(desc, driver, type, mask); |
| 1685 | if (err) |
| 1686 | goto out; |
| 1687 | |
Stephan Mueller | 425a882 | 2015-03-30 21:56:31 +0200 | [diff] [blame] | 1688 | tfm = crypto_alloc_shash(driver, type | CRYPTO_ALG_INTERNAL, mask); |
Herbert Xu | 8e3ee85 | 2008-11-07 14:58:52 +0800 | [diff] [blame] | 1689 | if (IS_ERR(tfm)) { |
| 1690 | printk(KERN_ERR "alg: crc32c: Failed to load transform for %s: " |
| 1691 | "%ld\n", driver, PTR_ERR(tfm)); |
| 1692 | err = PTR_ERR(tfm); |
| 1693 | goto out; |
| 1694 | } |
| 1695 | |
| 1696 | do { |
Jan-Simon Möller | 4c5c302 | 2012-07-02 13:48:30 +0200 | [diff] [blame] | 1697 | SHASH_DESC_ON_STACK(shash, tfm); |
| 1698 | u32 *ctx = (u32 *)shash_desc_ctx(shash); |
Herbert Xu | 8e3ee85 | 2008-11-07 14:58:52 +0800 | [diff] [blame] | 1699 | |
Jan-Simon Möller | 4c5c302 | 2012-07-02 13:48:30 +0200 | [diff] [blame] | 1700 | shash->tfm = tfm; |
| 1701 | shash->flags = 0; |
Herbert Xu | 8e3ee85 | 2008-11-07 14:58:52 +0800 | [diff] [blame] | 1702 | |
Jan-Simon Möller | 4c5c302 | 2012-07-02 13:48:30 +0200 | [diff] [blame] | 1703 | *ctx = le32_to_cpu(420553207); |
| 1704 | err = crypto_shash_final(shash, (u8 *)&val); |
Herbert Xu | 8e3ee85 | 2008-11-07 14:58:52 +0800 | [diff] [blame] | 1705 | if (err) { |
| 1706 | printk(KERN_ERR "alg: crc32c: Operation failed for " |
| 1707 | "%s: %d\n", driver, err); |
| 1708 | break; |
| 1709 | } |
| 1710 | |
| 1711 | if (val != ~420553207) { |
| 1712 | printk(KERN_ERR "alg: crc32c: Test failed for %s: " |
| 1713 | "%d\n", driver, val); |
| 1714 | err = -EINVAL; |
| 1715 | } |
| 1716 | } while (0); |
| 1717 | |
| 1718 | crypto_free_shash(tfm); |
| 1719 | |
| 1720 | out: |
| 1721 | return err; |
| 1722 | } |
| 1723 | |
Jarod Wilson | 7647d6c | 2009-05-04 19:44:50 +0800 | [diff] [blame] | 1724 | static int alg_test_cprng(const struct alg_test_desc *desc, const char *driver, |
| 1725 | u32 type, u32 mask) |
| 1726 | { |
| 1727 | struct crypto_rng *rng; |
| 1728 | int err; |
| 1729 | |
Stephan Mueller | 425a882 | 2015-03-30 21:56:31 +0200 | [diff] [blame] | 1730 | rng = crypto_alloc_rng(driver, type | CRYPTO_ALG_INTERNAL, mask); |
Jarod Wilson | 7647d6c | 2009-05-04 19:44:50 +0800 | [diff] [blame] | 1731 | if (IS_ERR(rng)) { |
| 1732 | printk(KERN_ERR "alg: cprng: Failed to load transform for %s: " |
| 1733 | "%ld\n", driver, PTR_ERR(rng)); |
| 1734 | return PTR_ERR(rng); |
| 1735 | } |
| 1736 | |
| 1737 | err = test_cprng(rng, desc->suite.cprng.vecs, desc->suite.cprng.count); |
| 1738 | |
| 1739 | crypto_free_rng(rng); |
| 1740 | |
| 1741 | return err; |
| 1742 | } |
| 1743 | |
Stephan Mueller | 64d1cdf | 2014-05-31 17:25:36 +0200 | [diff] [blame] | 1744 | |
| 1745 | static int drbg_cavs_test(struct drbg_testvec *test, int pr, |
| 1746 | const char *driver, u32 type, u32 mask) |
| 1747 | { |
| 1748 | int ret = -EAGAIN; |
| 1749 | struct crypto_rng *drng; |
| 1750 | struct drbg_test_data test_data; |
| 1751 | struct drbg_string addtl, pers, testentropy; |
| 1752 | unsigned char *buf = kzalloc(test->expectedlen, GFP_KERNEL); |
| 1753 | |
| 1754 | if (!buf) |
| 1755 | return -ENOMEM; |
| 1756 | |
Stephan Mueller | 425a882 | 2015-03-30 21:56:31 +0200 | [diff] [blame] | 1757 | drng = crypto_alloc_rng(driver, type | CRYPTO_ALG_INTERNAL, mask); |
Stephan Mueller | 64d1cdf | 2014-05-31 17:25:36 +0200 | [diff] [blame] | 1758 | if (IS_ERR(drng)) { |
Jarod Wilson | 2fc0d25 | 2014-07-29 15:47:56 -0400 | [diff] [blame] | 1759 | printk(KERN_ERR "alg: drbg: could not allocate DRNG handle for " |
Stephan Mueller | 64d1cdf | 2014-05-31 17:25:36 +0200 | [diff] [blame] | 1760 | "%s\n", driver); |
| 1761 | kzfree(buf); |
| 1762 | return -ENOMEM; |
| 1763 | } |
| 1764 | |
| 1765 | test_data.testentropy = &testentropy; |
| 1766 | drbg_string_fill(&testentropy, test->entropy, test->entropylen); |
| 1767 | drbg_string_fill(&pers, test->pers, test->perslen); |
| 1768 | ret = crypto_drbg_reset_test(drng, &pers, &test_data); |
| 1769 | if (ret) { |
| 1770 | printk(KERN_ERR "alg: drbg: Failed to reset rng\n"); |
| 1771 | goto outbuf; |
| 1772 | } |
| 1773 | |
| 1774 | drbg_string_fill(&addtl, test->addtla, test->addtllen); |
| 1775 | if (pr) { |
| 1776 | drbg_string_fill(&testentropy, test->entpra, test->entprlen); |
| 1777 | ret = crypto_drbg_get_bytes_addtl_test(drng, |
| 1778 | buf, test->expectedlen, &addtl, &test_data); |
| 1779 | } else { |
| 1780 | ret = crypto_drbg_get_bytes_addtl(drng, |
| 1781 | buf, test->expectedlen, &addtl); |
| 1782 | } |
Stephan Mueller | 19e60e1 | 2015-03-10 17:00:36 +0100 | [diff] [blame] | 1783 | if (ret < 0) { |
Jarod Wilson | 2fc0d25 | 2014-07-29 15:47:56 -0400 | [diff] [blame] | 1784 | printk(KERN_ERR "alg: drbg: could not obtain random data for " |
Stephan Mueller | 64d1cdf | 2014-05-31 17:25:36 +0200 | [diff] [blame] | 1785 | "driver %s\n", driver); |
| 1786 | goto outbuf; |
| 1787 | } |
| 1788 | |
| 1789 | drbg_string_fill(&addtl, test->addtlb, test->addtllen); |
| 1790 | if (pr) { |
| 1791 | drbg_string_fill(&testentropy, test->entprb, test->entprlen); |
| 1792 | ret = crypto_drbg_get_bytes_addtl_test(drng, |
| 1793 | buf, test->expectedlen, &addtl, &test_data); |
| 1794 | } else { |
| 1795 | ret = crypto_drbg_get_bytes_addtl(drng, |
| 1796 | buf, test->expectedlen, &addtl); |
| 1797 | } |
Stephan Mueller | 19e60e1 | 2015-03-10 17:00:36 +0100 | [diff] [blame] | 1798 | if (ret < 0) { |
Jarod Wilson | 2fc0d25 | 2014-07-29 15:47:56 -0400 | [diff] [blame] | 1799 | printk(KERN_ERR "alg: drbg: could not obtain random data for " |
Stephan Mueller | 64d1cdf | 2014-05-31 17:25:36 +0200 | [diff] [blame] | 1800 | "driver %s\n", driver); |
| 1801 | goto outbuf; |
| 1802 | } |
| 1803 | |
| 1804 | ret = memcmp(test->expected, buf, test->expectedlen); |
| 1805 | |
| 1806 | outbuf: |
| 1807 | crypto_free_rng(drng); |
| 1808 | kzfree(buf); |
| 1809 | return ret; |
| 1810 | } |
| 1811 | |
| 1812 | |
| 1813 | static int alg_test_drbg(const struct alg_test_desc *desc, const char *driver, |
| 1814 | u32 type, u32 mask) |
| 1815 | { |
| 1816 | int err = 0; |
| 1817 | int pr = 0; |
| 1818 | int i = 0; |
| 1819 | struct drbg_testvec *template = desc->suite.drbg.vecs; |
| 1820 | unsigned int tcount = desc->suite.drbg.count; |
| 1821 | |
| 1822 | if (0 == memcmp(driver, "drbg_pr_", 8)) |
| 1823 | pr = 1; |
| 1824 | |
| 1825 | for (i = 0; i < tcount; i++) { |
| 1826 | err = drbg_cavs_test(&template[i], pr, driver, type, mask); |
| 1827 | if (err) { |
| 1828 | printk(KERN_ERR "alg: drbg: Test %d failed for %s\n", |
| 1829 | i, driver); |
| 1830 | err = -EINVAL; |
| 1831 | break; |
| 1832 | } |
| 1833 | } |
| 1834 | return err; |
| 1835 | |
| 1836 | } |
| 1837 | |
Tadeusz Struk | 946cc46 | 2015-06-16 10:31:06 -0700 | [diff] [blame] | 1838 | static int do_test_rsa(struct crypto_akcipher *tfm, |
| 1839 | struct akcipher_testvec *vecs) |
| 1840 | { |
| 1841 | struct akcipher_request *req; |
| 1842 | void *outbuf_enc = NULL; |
| 1843 | void *outbuf_dec = NULL; |
| 1844 | struct tcrypt_result result; |
| 1845 | unsigned int out_len_max, out_len = 0; |
| 1846 | int err = -ENOMEM; |
| 1847 | |
| 1848 | req = akcipher_request_alloc(tfm, GFP_KERNEL); |
| 1849 | if (!req) |
| 1850 | return err; |
| 1851 | |
| 1852 | init_completion(&result.completion); |
| 1853 | err = crypto_akcipher_setkey(tfm, vecs->key, vecs->key_len); |
| 1854 | if (err) |
| 1855 | goto free_req; |
| 1856 | |
| 1857 | akcipher_request_set_crypt(req, vecs->m, outbuf_enc, vecs->m_size, |
| 1858 | out_len); |
| 1859 | /* expect this to fail, and update the required buf len */ |
| 1860 | crypto_akcipher_encrypt(req); |
| 1861 | out_len = req->dst_len; |
| 1862 | if (!out_len) { |
| 1863 | err = -EINVAL; |
| 1864 | goto free_req; |
| 1865 | } |
| 1866 | |
| 1867 | out_len_max = out_len; |
| 1868 | err = -ENOMEM; |
| 1869 | outbuf_enc = kzalloc(out_len_max, GFP_KERNEL); |
| 1870 | if (!outbuf_enc) |
| 1871 | goto free_req; |
| 1872 | |
| 1873 | akcipher_request_set_crypt(req, vecs->m, outbuf_enc, vecs->m_size, |
| 1874 | out_len); |
| 1875 | akcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, |
| 1876 | tcrypt_complete, &result); |
| 1877 | |
| 1878 | /* Run RSA encrypt - c = m^e mod n;*/ |
| 1879 | err = wait_async_op(&result, crypto_akcipher_encrypt(req)); |
| 1880 | if (err) { |
| 1881 | pr_err("alg: rsa: encrypt test failed. err %d\n", err); |
| 1882 | goto free_all; |
| 1883 | } |
| 1884 | if (out_len != vecs->c_size) { |
| 1885 | pr_err("alg: rsa: encrypt test failed. Invalid output len\n"); |
| 1886 | err = -EINVAL; |
| 1887 | goto free_all; |
| 1888 | } |
| 1889 | /* verify that encrypted message is equal to expected */ |
| 1890 | if (memcmp(vecs->c, outbuf_enc, vecs->c_size)) { |
| 1891 | pr_err("alg: rsa: encrypt test failed. Invalid output\n"); |
| 1892 | err = -EINVAL; |
| 1893 | goto free_all; |
| 1894 | } |
| 1895 | /* Don't invoke decrypt for vectors with public key */ |
| 1896 | if (vecs->public_key_vec) { |
| 1897 | err = 0; |
| 1898 | goto free_all; |
| 1899 | } |
| 1900 | outbuf_dec = kzalloc(out_len_max, GFP_KERNEL); |
| 1901 | if (!outbuf_dec) { |
| 1902 | err = -ENOMEM; |
| 1903 | goto free_all; |
| 1904 | } |
| 1905 | init_completion(&result.completion); |
| 1906 | akcipher_request_set_crypt(req, outbuf_enc, outbuf_dec, vecs->c_size, |
| 1907 | out_len); |
| 1908 | |
| 1909 | /* Run RSA decrypt - m = c^d mod n;*/ |
| 1910 | err = wait_async_op(&result, crypto_akcipher_decrypt(req)); |
| 1911 | if (err) { |
| 1912 | pr_err("alg: rsa: decrypt test failed. err %d\n", err); |
| 1913 | goto free_all; |
| 1914 | } |
| 1915 | out_len = req->dst_len; |
| 1916 | if (out_len != vecs->m_size) { |
| 1917 | pr_err("alg: rsa: decrypt test failed. Invalid output len\n"); |
| 1918 | err = -EINVAL; |
| 1919 | goto free_all; |
| 1920 | } |
| 1921 | /* verify that decrypted message is equal to the original msg */ |
| 1922 | if (memcmp(vecs->m, outbuf_dec, vecs->m_size)) { |
| 1923 | pr_err("alg: rsa: decrypt test failed. Invalid output\n"); |
| 1924 | err = -EINVAL; |
| 1925 | } |
| 1926 | free_all: |
| 1927 | kfree(outbuf_dec); |
| 1928 | kfree(outbuf_enc); |
| 1929 | free_req: |
| 1930 | akcipher_request_free(req); |
| 1931 | return err; |
| 1932 | } |
| 1933 | |
| 1934 | static int test_rsa(struct crypto_akcipher *tfm, struct akcipher_testvec *vecs, |
| 1935 | unsigned int tcount) |
| 1936 | { |
| 1937 | int ret, i; |
| 1938 | |
| 1939 | for (i = 0; i < tcount; i++) { |
| 1940 | ret = do_test_rsa(tfm, vecs++); |
| 1941 | if (ret) { |
| 1942 | pr_err("alg: rsa: test failed on vector %d, err=%d\n", |
| 1943 | i + 1, ret); |
| 1944 | return ret; |
| 1945 | } |
| 1946 | } |
| 1947 | return 0; |
| 1948 | } |
| 1949 | |
| 1950 | static int test_akcipher(struct crypto_akcipher *tfm, const char *alg, |
| 1951 | struct akcipher_testvec *vecs, unsigned int tcount) |
| 1952 | { |
| 1953 | if (strncmp(alg, "rsa", 3) == 0) |
| 1954 | return test_rsa(tfm, vecs, tcount); |
| 1955 | |
| 1956 | return 0; |
| 1957 | } |
| 1958 | |
| 1959 | static int alg_test_akcipher(const struct alg_test_desc *desc, |
| 1960 | const char *driver, u32 type, u32 mask) |
| 1961 | { |
| 1962 | struct crypto_akcipher *tfm; |
| 1963 | int err = 0; |
| 1964 | |
| 1965 | tfm = crypto_alloc_akcipher(driver, type | CRYPTO_ALG_INTERNAL, mask); |
| 1966 | if (IS_ERR(tfm)) { |
| 1967 | pr_err("alg: akcipher: Failed to load tfm for %s: %ld\n", |
| 1968 | driver, PTR_ERR(tfm)); |
| 1969 | return PTR_ERR(tfm); |
| 1970 | } |
| 1971 | if (desc->suite.akcipher.vecs) |
| 1972 | err = test_akcipher(tfm, desc->alg, desc->suite.akcipher.vecs, |
| 1973 | desc->suite.akcipher.count); |
| 1974 | |
| 1975 | crypto_free_akcipher(tfm); |
| 1976 | return err; |
| 1977 | } |
| 1978 | |
Youquan, Song | 863b557 | 2009-12-23 19:45:20 +0800 | [diff] [blame] | 1979 | static int alg_test_null(const struct alg_test_desc *desc, |
| 1980 | const char *driver, u32 type, u32 mask) |
| 1981 | { |
| 1982 | return 0; |
| 1983 | } |
| 1984 | |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 1985 | /* Please keep this list sorted by algorithm name. */ |
| 1986 | static const struct alg_test_desc alg_test_descs[] = { |
| 1987 | { |
Johannes Goetzfried | 4d6d6a2 | 2012-07-11 19:37:37 +0200 | [diff] [blame] | 1988 | .alg = "__cbc-cast5-avx", |
| 1989 | .test = alg_test_null, |
Johannes Goetzfried | 4d6d6a2 | 2012-07-11 19:37:37 +0200 | [diff] [blame] | 1990 | }, { |
Johannes Goetzfried | 4ea1277 | 2012-07-11 19:38:57 +0200 | [diff] [blame] | 1991 | .alg = "__cbc-cast6-avx", |
| 1992 | .test = alg_test_null, |
Johannes Goetzfried | 4ea1277 | 2012-07-11 19:38:57 +0200 | [diff] [blame] | 1993 | }, { |
Johannes Goetzfried | 7efe407 | 2012-06-12 16:47:43 +0800 | [diff] [blame] | 1994 | .alg = "__cbc-serpent-avx", |
| 1995 | .test = alg_test_null, |
Johannes Goetzfried | 7efe407 | 2012-06-12 16:47:43 +0800 | [diff] [blame] | 1996 | }, { |
Jussi Kivilinna | 56d76c9 | 2013-04-13 13:46:55 +0300 | [diff] [blame] | 1997 | .alg = "__cbc-serpent-avx2", |
| 1998 | .test = alg_test_null, |
| 1999 | }, { |
Jussi Kivilinna | 937c30d | 2011-11-09 16:26:25 +0200 | [diff] [blame] | 2000 | .alg = "__cbc-serpent-sse2", |
| 2001 | .test = alg_test_null, |
Jussi Kivilinna | 937c30d | 2011-11-09 16:26:25 +0200 | [diff] [blame] | 2002 | }, { |
Johannes Goetzfried | 107778b | 2012-05-28 15:54:24 +0200 | [diff] [blame] | 2003 | .alg = "__cbc-twofish-avx", |
| 2004 | .test = alg_test_null, |
Johannes Goetzfried | 107778b | 2012-05-28 15:54:24 +0200 | [diff] [blame] | 2005 | }, { |
Youquan, Song | 863b557 | 2009-12-23 19:45:20 +0800 | [diff] [blame] | 2006 | .alg = "__driver-cbc-aes-aesni", |
| 2007 | .test = alg_test_null, |
Milan Broz | 6c79294 | 2012-06-29 22:08:09 +0200 | [diff] [blame] | 2008 | .fips_allowed = 1, |
Youquan, Song | 863b557 | 2009-12-23 19:45:20 +0800 | [diff] [blame] | 2009 | }, { |
Jussi Kivilinna | d9b1d2e | 2012-10-26 14:49:01 +0300 | [diff] [blame] | 2010 | .alg = "__driver-cbc-camellia-aesni", |
| 2011 | .test = alg_test_null, |
Jussi Kivilinna | d9b1d2e | 2012-10-26 14:49:01 +0300 | [diff] [blame] | 2012 | }, { |
Jussi Kivilinna | f3f935a | 2013-04-13 13:47:00 +0300 | [diff] [blame] | 2013 | .alg = "__driver-cbc-camellia-aesni-avx2", |
| 2014 | .test = alg_test_null, |
| 2015 | }, { |
Johannes Goetzfried | 4d6d6a2 | 2012-07-11 19:37:37 +0200 | [diff] [blame] | 2016 | .alg = "__driver-cbc-cast5-avx", |
| 2017 | .test = alg_test_null, |
Johannes Goetzfried | 4d6d6a2 | 2012-07-11 19:37:37 +0200 | [diff] [blame] | 2018 | }, { |
Johannes Goetzfried | 4ea1277 | 2012-07-11 19:38:57 +0200 | [diff] [blame] | 2019 | .alg = "__driver-cbc-cast6-avx", |
| 2020 | .test = alg_test_null, |
Johannes Goetzfried | 4ea1277 | 2012-07-11 19:38:57 +0200 | [diff] [blame] | 2021 | }, { |
Johannes Goetzfried | 7efe407 | 2012-06-12 16:47:43 +0800 | [diff] [blame] | 2022 | .alg = "__driver-cbc-serpent-avx", |
| 2023 | .test = alg_test_null, |
Johannes Goetzfried | 7efe407 | 2012-06-12 16:47:43 +0800 | [diff] [blame] | 2024 | }, { |
Jussi Kivilinna | 56d76c9 | 2013-04-13 13:46:55 +0300 | [diff] [blame] | 2025 | .alg = "__driver-cbc-serpent-avx2", |
| 2026 | .test = alg_test_null, |
| 2027 | }, { |
Jussi Kivilinna | 937c30d | 2011-11-09 16:26:25 +0200 | [diff] [blame] | 2028 | .alg = "__driver-cbc-serpent-sse2", |
| 2029 | .test = alg_test_null, |
Jussi Kivilinna | 937c30d | 2011-11-09 16:26:25 +0200 | [diff] [blame] | 2030 | }, { |
Johannes Goetzfried | 107778b | 2012-05-28 15:54:24 +0200 | [diff] [blame] | 2031 | .alg = "__driver-cbc-twofish-avx", |
| 2032 | .test = alg_test_null, |
Johannes Goetzfried | 107778b | 2012-05-28 15:54:24 +0200 | [diff] [blame] | 2033 | }, { |
Youquan, Song | 863b557 | 2009-12-23 19:45:20 +0800 | [diff] [blame] | 2034 | .alg = "__driver-ecb-aes-aesni", |
| 2035 | .test = alg_test_null, |
Milan Broz | 6c79294 | 2012-06-29 22:08:09 +0200 | [diff] [blame] | 2036 | .fips_allowed = 1, |
Youquan, Song | 863b557 | 2009-12-23 19:45:20 +0800 | [diff] [blame] | 2037 | }, { |
Jussi Kivilinna | d9b1d2e | 2012-10-26 14:49:01 +0300 | [diff] [blame] | 2038 | .alg = "__driver-ecb-camellia-aesni", |
| 2039 | .test = alg_test_null, |
Jussi Kivilinna | d9b1d2e | 2012-10-26 14:49:01 +0300 | [diff] [blame] | 2040 | }, { |
Jussi Kivilinna | f3f935a | 2013-04-13 13:47:00 +0300 | [diff] [blame] | 2041 | .alg = "__driver-ecb-camellia-aesni-avx2", |
| 2042 | .test = alg_test_null, |
| 2043 | }, { |
Johannes Goetzfried | 4d6d6a2 | 2012-07-11 19:37:37 +0200 | [diff] [blame] | 2044 | .alg = "__driver-ecb-cast5-avx", |
| 2045 | .test = alg_test_null, |
Johannes Goetzfried | 4d6d6a2 | 2012-07-11 19:37:37 +0200 | [diff] [blame] | 2046 | }, { |
Johannes Goetzfried | 4ea1277 | 2012-07-11 19:38:57 +0200 | [diff] [blame] | 2047 | .alg = "__driver-ecb-cast6-avx", |
| 2048 | .test = alg_test_null, |
Johannes Goetzfried | 4ea1277 | 2012-07-11 19:38:57 +0200 | [diff] [blame] | 2049 | }, { |
Johannes Goetzfried | 7efe407 | 2012-06-12 16:47:43 +0800 | [diff] [blame] | 2050 | .alg = "__driver-ecb-serpent-avx", |
| 2051 | .test = alg_test_null, |
Johannes Goetzfried | 7efe407 | 2012-06-12 16:47:43 +0800 | [diff] [blame] | 2052 | }, { |
Jussi Kivilinna | 56d76c9 | 2013-04-13 13:46:55 +0300 | [diff] [blame] | 2053 | .alg = "__driver-ecb-serpent-avx2", |
| 2054 | .test = alg_test_null, |
| 2055 | }, { |
Jussi Kivilinna | 937c30d | 2011-11-09 16:26:25 +0200 | [diff] [blame] | 2056 | .alg = "__driver-ecb-serpent-sse2", |
| 2057 | .test = alg_test_null, |
Jussi Kivilinna | 937c30d | 2011-11-09 16:26:25 +0200 | [diff] [blame] | 2058 | }, { |
Johannes Goetzfried | 107778b | 2012-05-28 15:54:24 +0200 | [diff] [blame] | 2059 | .alg = "__driver-ecb-twofish-avx", |
| 2060 | .test = alg_test_null, |
Johannes Goetzfried | 107778b | 2012-05-28 15:54:24 +0200 | [diff] [blame] | 2061 | }, { |
Tadeusz Struk | 9d77b6c | 2015-06-24 09:01:30 -0700 | [diff] [blame] | 2062 | .alg = "__driver-gcm-aes-aesni", |
| 2063 | .test = alg_test_null, |
| 2064 | .fips_allowed = 1, |
| 2065 | }, { |
Youquan, Song | 863b557 | 2009-12-23 19:45:20 +0800 | [diff] [blame] | 2066 | .alg = "__ghash-pclmulqdqni", |
| 2067 | .test = alg_test_null, |
Milan Broz | 6c79294 | 2012-06-29 22:08:09 +0200 | [diff] [blame] | 2068 | .fips_allowed = 1, |
Youquan, Song | 863b557 | 2009-12-23 19:45:20 +0800 | [diff] [blame] | 2069 | }, { |
Jarod Wilson | e08ca2d | 2009-05-04 19:46:29 +0800 | [diff] [blame] | 2070 | .alg = "ansi_cprng", |
| 2071 | .test = alg_test_cprng, |
Jarod Wilson | a1915d5 | 2009-05-15 15:16:03 +1000 | [diff] [blame] | 2072 | .fips_allowed = 1, |
Jarod Wilson | e08ca2d | 2009-05-04 19:46:29 +0800 | [diff] [blame] | 2073 | .suite = { |
| 2074 | .cprng = { |
| 2075 | .vecs = ansi_cprng_aes_tv_template, |
| 2076 | .count = ANSI_CPRNG_AES_TEST_VECTORS |
| 2077 | } |
| 2078 | } |
| 2079 | }, { |
Horia Geanta | bca4feb | 2014-03-14 17:46:51 +0200 | [diff] [blame] | 2080 | .alg = "authenc(hmac(md5),ecb(cipher_null))", |
| 2081 | .test = alg_test_aead, |
| 2082 | .fips_allowed = 1, |
| 2083 | .suite = { |
| 2084 | .aead = { |
| 2085 | .enc = { |
| 2086 | .vecs = hmac_md5_ecb_cipher_null_enc_tv_template, |
| 2087 | .count = HMAC_MD5_ECB_CIPHER_NULL_ENC_TEST_VECTORS |
| 2088 | }, |
| 2089 | .dec = { |
| 2090 | .vecs = hmac_md5_ecb_cipher_null_dec_tv_template, |
| 2091 | .count = HMAC_MD5_ECB_CIPHER_NULL_DEC_TEST_VECTORS |
| 2092 | } |
| 2093 | } |
| 2094 | } |
| 2095 | }, { |
Herbert Xu | a4198fd | 2015-07-30 17:53:23 +0800 | [diff] [blame] | 2096 | .alg = "authenc(hmac(sha1),cbc(aes))", |
Horia Geanta | e46e9a4 | 2012-07-03 19:16:54 +0300 | [diff] [blame] | 2097 | .test = alg_test_aead, |
| 2098 | .fips_allowed = 1, |
| 2099 | .suite = { |
| 2100 | .aead = { |
| 2101 | .enc = { |
Nitesh Lal | 5208ed2 | 2014-05-21 17:09:08 +0530 | [diff] [blame] | 2102 | .vecs = |
| 2103 | hmac_sha1_aes_cbc_enc_tv_temp, |
| 2104 | .count = |
| 2105 | HMAC_SHA1_AES_CBC_ENC_TEST_VEC |
| 2106 | } |
| 2107 | } |
| 2108 | } |
| 2109 | }, { |
Herbert Xu | a4198fd | 2015-07-30 17:53:23 +0800 | [diff] [blame] | 2110 | .alg = "authenc(hmac(sha1),cbc(des))", |
Nitesh Lal | 5208ed2 | 2014-05-21 17:09:08 +0530 | [diff] [blame] | 2111 | .test = alg_test_aead, |
| 2112 | .fips_allowed = 1, |
| 2113 | .suite = { |
| 2114 | .aead = { |
| 2115 | .enc = { |
| 2116 | .vecs = |
| 2117 | hmac_sha1_des_cbc_enc_tv_temp, |
| 2118 | .count = |
| 2119 | HMAC_SHA1_DES_CBC_ENC_TEST_VEC |
| 2120 | } |
| 2121 | } |
| 2122 | } |
| 2123 | }, { |
Herbert Xu | a4198fd | 2015-07-30 17:53:23 +0800 | [diff] [blame] | 2124 | .alg = "authenc(hmac(sha1),cbc(des3_ede))", |
Nitesh Lal | 5208ed2 | 2014-05-21 17:09:08 +0530 | [diff] [blame] | 2125 | .test = alg_test_aead, |
| 2126 | .fips_allowed = 1, |
| 2127 | .suite = { |
| 2128 | .aead = { |
| 2129 | .enc = { |
| 2130 | .vecs = |
| 2131 | hmac_sha1_des3_ede_cbc_enc_tv_temp, |
| 2132 | .count = |
| 2133 | HMAC_SHA1_DES3_EDE_CBC_ENC_TEST_VEC |
Horia Geanta | e46e9a4 | 2012-07-03 19:16:54 +0300 | [diff] [blame] | 2134 | } |
| 2135 | } |
| 2136 | } |
| 2137 | }, { |
Horia Geanta | bca4feb | 2014-03-14 17:46:51 +0200 | [diff] [blame] | 2138 | .alg = "authenc(hmac(sha1),ecb(cipher_null))", |
| 2139 | .test = alg_test_aead, |
| 2140 | .fips_allowed = 1, |
| 2141 | .suite = { |
| 2142 | .aead = { |
| 2143 | .enc = { |
Nitesh Lal | 5208ed2 | 2014-05-21 17:09:08 +0530 | [diff] [blame] | 2144 | .vecs = |
| 2145 | hmac_sha1_ecb_cipher_null_enc_tv_temp, |
| 2146 | .count = |
| 2147 | HMAC_SHA1_ECB_CIPHER_NULL_ENC_TEST_VEC |
Horia Geanta | bca4feb | 2014-03-14 17:46:51 +0200 | [diff] [blame] | 2148 | }, |
| 2149 | .dec = { |
Nitesh Lal | 5208ed2 | 2014-05-21 17:09:08 +0530 | [diff] [blame] | 2150 | .vecs = |
| 2151 | hmac_sha1_ecb_cipher_null_dec_tv_temp, |
| 2152 | .count = |
| 2153 | HMAC_SHA1_ECB_CIPHER_NULL_DEC_TEST_VEC |
| 2154 | } |
| 2155 | } |
| 2156 | } |
| 2157 | }, { |
Herbert Xu | a4198fd | 2015-07-30 17:53:23 +0800 | [diff] [blame] | 2158 | .alg = "authenc(hmac(sha224),cbc(des))", |
Nitesh Lal | 5208ed2 | 2014-05-21 17:09:08 +0530 | [diff] [blame] | 2159 | .test = alg_test_aead, |
| 2160 | .fips_allowed = 1, |
| 2161 | .suite = { |
| 2162 | .aead = { |
| 2163 | .enc = { |
| 2164 | .vecs = |
| 2165 | hmac_sha224_des_cbc_enc_tv_temp, |
| 2166 | .count = |
| 2167 | HMAC_SHA224_DES_CBC_ENC_TEST_VEC |
| 2168 | } |
| 2169 | } |
| 2170 | } |
| 2171 | }, { |
Herbert Xu | a4198fd | 2015-07-30 17:53:23 +0800 | [diff] [blame] | 2172 | .alg = "authenc(hmac(sha224),cbc(des3_ede))", |
Nitesh Lal | 5208ed2 | 2014-05-21 17:09:08 +0530 | [diff] [blame] | 2173 | .test = alg_test_aead, |
| 2174 | .fips_allowed = 1, |
| 2175 | .suite = { |
| 2176 | .aead = { |
| 2177 | .enc = { |
| 2178 | .vecs = |
| 2179 | hmac_sha224_des3_ede_cbc_enc_tv_temp, |
| 2180 | .count = |
| 2181 | HMAC_SHA224_DES3_EDE_CBC_ENC_TEST_VEC |
Horia Geanta | bca4feb | 2014-03-14 17:46:51 +0200 | [diff] [blame] | 2182 | } |
| 2183 | } |
| 2184 | } |
| 2185 | }, { |
Herbert Xu | a4198fd | 2015-07-30 17:53:23 +0800 | [diff] [blame] | 2186 | .alg = "authenc(hmac(sha256),cbc(aes))", |
Horia Geanta | e46e9a4 | 2012-07-03 19:16:54 +0300 | [diff] [blame] | 2187 | .test = alg_test_aead, |
| 2188 | .fips_allowed = 1, |
| 2189 | .suite = { |
| 2190 | .aead = { |
| 2191 | .enc = { |
Nitesh Lal | 5208ed2 | 2014-05-21 17:09:08 +0530 | [diff] [blame] | 2192 | .vecs = |
| 2193 | hmac_sha256_aes_cbc_enc_tv_temp, |
| 2194 | .count = |
| 2195 | HMAC_SHA256_AES_CBC_ENC_TEST_VEC |
| 2196 | } |
| 2197 | } |
| 2198 | } |
| 2199 | }, { |
Herbert Xu | a4198fd | 2015-07-30 17:53:23 +0800 | [diff] [blame] | 2200 | .alg = "authenc(hmac(sha256),cbc(des))", |
Nitesh Lal | 5208ed2 | 2014-05-21 17:09:08 +0530 | [diff] [blame] | 2201 | .test = alg_test_aead, |
| 2202 | .fips_allowed = 1, |
| 2203 | .suite = { |
| 2204 | .aead = { |
| 2205 | .enc = { |
| 2206 | .vecs = |
| 2207 | hmac_sha256_des_cbc_enc_tv_temp, |
| 2208 | .count = |
| 2209 | HMAC_SHA256_DES_CBC_ENC_TEST_VEC |
| 2210 | } |
| 2211 | } |
| 2212 | } |
| 2213 | }, { |
Herbert Xu | a4198fd | 2015-07-30 17:53:23 +0800 | [diff] [blame] | 2214 | .alg = "authenc(hmac(sha256),cbc(des3_ede))", |
Nitesh Lal | 5208ed2 | 2014-05-21 17:09:08 +0530 | [diff] [blame] | 2215 | .test = alg_test_aead, |
| 2216 | .fips_allowed = 1, |
| 2217 | .suite = { |
| 2218 | .aead = { |
| 2219 | .enc = { |
| 2220 | .vecs = |
| 2221 | hmac_sha256_des3_ede_cbc_enc_tv_temp, |
| 2222 | .count = |
| 2223 | HMAC_SHA256_DES3_EDE_CBC_ENC_TEST_VEC |
| 2224 | } |
| 2225 | } |
| 2226 | } |
| 2227 | }, { |
Herbert Xu | a4198fd | 2015-07-30 17:53:23 +0800 | [diff] [blame] | 2228 | .alg = "authenc(hmac(sha384),cbc(des))", |
Nitesh Lal | 5208ed2 | 2014-05-21 17:09:08 +0530 | [diff] [blame] | 2229 | .test = alg_test_aead, |
| 2230 | .fips_allowed = 1, |
| 2231 | .suite = { |
| 2232 | .aead = { |
| 2233 | .enc = { |
| 2234 | .vecs = |
| 2235 | hmac_sha384_des_cbc_enc_tv_temp, |
| 2236 | .count = |
| 2237 | HMAC_SHA384_DES_CBC_ENC_TEST_VEC |
| 2238 | } |
| 2239 | } |
| 2240 | } |
| 2241 | }, { |
Herbert Xu | a4198fd | 2015-07-30 17:53:23 +0800 | [diff] [blame] | 2242 | .alg = "authenc(hmac(sha384),cbc(des3_ede))", |
Nitesh Lal | 5208ed2 | 2014-05-21 17:09:08 +0530 | [diff] [blame] | 2243 | .test = alg_test_aead, |
| 2244 | .fips_allowed = 1, |
| 2245 | .suite = { |
| 2246 | .aead = { |
| 2247 | .enc = { |
| 2248 | .vecs = |
| 2249 | hmac_sha384_des3_ede_cbc_enc_tv_temp, |
| 2250 | .count = |
| 2251 | HMAC_SHA384_DES3_EDE_CBC_ENC_TEST_VEC |
Horia Geanta | e46e9a4 | 2012-07-03 19:16:54 +0300 | [diff] [blame] | 2252 | } |
| 2253 | } |
| 2254 | } |
| 2255 | }, { |
Herbert Xu | a4198fd | 2015-07-30 17:53:23 +0800 | [diff] [blame] | 2256 | .alg = "authenc(hmac(sha512),cbc(aes))", |
Horia Geanta | e46e9a4 | 2012-07-03 19:16:54 +0300 | [diff] [blame] | 2257 | .test = alg_test_aead, |
| 2258 | .fips_allowed = 1, |
| 2259 | .suite = { |
| 2260 | .aead = { |
| 2261 | .enc = { |
Nitesh Lal | 5208ed2 | 2014-05-21 17:09:08 +0530 | [diff] [blame] | 2262 | .vecs = |
| 2263 | hmac_sha512_aes_cbc_enc_tv_temp, |
| 2264 | .count = |
| 2265 | HMAC_SHA512_AES_CBC_ENC_TEST_VEC |
| 2266 | } |
| 2267 | } |
| 2268 | } |
| 2269 | }, { |
Herbert Xu | a4198fd | 2015-07-30 17:53:23 +0800 | [diff] [blame] | 2270 | .alg = "authenc(hmac(sha512),cbc(des))", |
Nitesh Lal | 5208ed2 | 2014-05-21 17:09:08 +0530 | [diff] [blame] | 2271 | .test = alg_test_aead, |
| 2272 | .fips_allowed = 1, |
| 2273 | .suite = { |
| 2274 | .aead = { |
| 2275 | .enc = { |
| 2276 | .vecs = |
| 2277 | hmac_sha512_des_cbc_enc_tv_temp, |
| 2278 | .count = |
| 2279 | HMAC_SHA512_DES_CBC_ENC_TEST_VEC |
| 2280 | } |
| 2281 | } |
| 2282 | } |
| 2283 | }, { |
Herbert Xu | a4198fd | 2015-07-30 17:53:23 +0800 | [diff] [blame] | 2284 | .alg = "authenc(hmac(sha512),cbc(des3_ede))", |
Nitesh Lal | 5208ed2 | 2014-05-21 17:09:08 +0530 | [diff] [blame] | 2285 | .test = alg_test_aead, |
| 2286 | .fips_allowed = 1, |
| 2287 | .suite = { |
| 2288 | .aead = { |
| 2289 | .enc = { |
| 2290 | .vecs = |
| 2291 | hmac_sha512_des3_ede_cbc_enc_tv_temp, |
| 2292 | .count = |
| 2293 | HMAC_SHA512_DES3_EDE_CBC_ENC_TEST_VEC |
Horia Geanta | e46e9a4 | 2012-07-03 19:16:54 +0300 | [diff] [blame] | 2294 | } |
| 2295 | } |
| 2296 | } |
| 2297 | }, { |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 2298 | .alg = "cbc(aes)", |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 2299 | .test = alg_test_skcipher, |
Jarod Wilson | a1915d5 | 2009-05-15 15:16:03 +1000 | [diff] [blame] | 2300 | .fips_allowed = 1, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 2301 | .suite = { |
| 2302 | .cipher = { |
| 2303 | .enc = { |
| 2304 | .vecs = aes_cbc_enc_tv_template, |
| 2305 | .count = AES_CBC_ENC_TEST_VECTORS |
| 2306 | }, |
| 2307 | .dec = { |
| 2308 | .vecs = aes_cbc_dec_tv_template, |
| 2309 | .count = AES_CBC_DEC_TEST_VECTORS |
| 2310 | } |
| 2311 | } |
| 2312 | } |
| 2313 | }, { |
| 2314 | .alg = "cbc(anubis)", |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 2315 | .test = alg_test_skcipher, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 2316 | .suite = { |
| 2317 | .cipher = { |
| 2318 | .enc = { |
| 2319 | .vecs = anubis_cbc_enc_tv_template, |
| 2320 | .count = ANUBIS_CBC_ENC_TEST_VECTORS |
| 2321 | }, |
| 2322 | .dec = { |
| 2323 | .vecs = anubis_cbc_dec_tv_template, |
| 2324 | .count = ANUBIS_CBC_DEC_TEST_VECTORS |
| 2325 | } |
| 2326 | } |
| 2327 | } |
| 2328 | }, { |
| 2329 | .alg = "cbc(blowfish)", |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 2330 | .test = alg_test_skcipher, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 2331 | .suite = { |
| 2332 | .cipher = { |
| 2333 | .enc = { |
| 2334 | .vecs = bf_cbc_enc_tv_template, |
| 2335 | .count = BF_CBC_ENC_TEST_VECTORS |
| 2336 | }, |
| 2337 | .dec = { |
| 2338 | .vecs = bf_cbc_dec_tv_template, |
| 2339 | .count = BF_CBC_DEC_TEST_VECTORS |
| 2340 | } |
| 2341 | } |
| 2342 | } |
| 2343 | }, { |
| 2344 | .alg = "cbc(camellia)", |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 2345 | .test = alg_test_skcipher, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 2346 | .suite = { |
| 2347 | .cipher = { |
| 2348 | .enc = { |
| 2349 | .vecs = camellia_cbc_enc_tv_template, |
| 2350 | .count = CAMELLIA_CBC_ENC_TEST_VECTORS |
| 2351 | }, |
| 2352 | .dec = { |
| 2353 | .vecs = camellia_cbc_dec_tv_template, |
| 2354 | .count = CAMELLIA_CBC_DEC_TEST_VECTORS |
| 2355 | } |
| 2356 | } |
| 2357 | } |
| 2358 | }, { |
Johannes Goetzfried | a2c5826 | 2012-07-11 19:37:21 +0200 | [diff] [blame] | 2359 | .alg = "cbc(cast5)", |
| 2360 | .test = alg_test_skcipher, |
| 2361 | .suite = { |
| 2362 | .cipher = { |
| 2363 | .enc = { |
| 2364 | .vecs = cast5_cbc_enc_tv_template, |
| 2365 | .count = CAST5_CBC_ENC_TEST_VECTORS |
| 2366 | }, |
| 2367 | .dec = { |
| 2368 | .vecs = cast5_cbc_dec_tv_template, |
| 2369 | .count = CAST5_CBC_DEC_TEST_VECTORS |
| 2370 | } |
| 2371 | } |
| 2372 | } |
| 2373 | }, { |
Johannes Goetzfried | 9b8b040 | 2012-07-11 19:38:29 +0200 | [diff] [blame] | 2374 | .alg = "cbc(cast6)", |
| 2375 | .test = alg_test_skcipher, |
| 2376 | .suite = { |
| 2377 | .cipher = { |
| 2378 | .enc = { |
| 2379 | .vecs = cast6_cbc_enc_tv_template, |
| 2380 | .count = CAST6_CBC_ENC_TEST_VECTORS |
| 2381 | }, |
| 2382 | .dec = { |
| 2383 | .vecs = cast6_cbc_dec_tv_template, |
| 2384 | .count = CAST6_CBC_DEC_TEST_VECTORS |
| 2385 | } |
| 2386 | } |
| 2387 | } |
| 2388 | }, { |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 2389 | .alg = "cbc(des)", |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 2390 | .test = alg_test_skcipher, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 2391 | .suite = { |
| 2392 | .cipher = { |
| 2393 | .enc = { |
| 2394 | .vecs = des_cbc_enc_tv_template, |
| 2395 | .count = DES_CBC_ENC_TEST_VECTORS |
| 2396 | }, |
| 2397 | .dec = { |
| 2398 | .vecs = des_cbc_dec_tv_template, |
| 2399 | .count = DES_CBC_DEC_TEST_VECTORS |
| 2400 | } |
| 2401 | } |
| 2402 | } |
| 2403 | }, { |
| 2404 | .alg = "cbc(des3_ede)", |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 2405 | .test = alg_test_skcipher, |
Jarod Wilson | a1915d5 | 2009-05-15 15:16:03 +1000 | [diff] [blame] | 2406 | .fips_allowed = 1, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 2407 | .suite = { |
| 2408 | .cipher = { |
| 2409 | .enc = { |
| 2410 | .vecs = des3_ede_cbc_enc_tv_template, |
| 2411 | .count = DES3_EDE_CBC_ENC_TEST_VECTORS |
| 2412 | }, |
| 2413 | .dec = { |
| 2414 | .vecs = des3_ede_cbc_dec_tv_template, |
| 2415 | .count = DES3_EDE_CBC_DEC_TEST_VECTORS |
| 2416 | } |
| 2417 | } |
| 2418 | } |
| 2419 | }, { |
Jussi Kivilinna | 9d25917 | 2011-10-18 00:02:53 +0300 | [diff] [blame] | 2420 | .alg = "cbc(serpent)", |
| 2421 | .test = alg_test_skcipher, |
| 2422 | .suite = { |
| 2423 | .cipher = { |
| 2424 | .enc = { |
| 2425 | .vecs = serpent_cbc_enc_tv_template, |
| 2426 | .count = SERPENT_CBC_ENC_TEST_VECTORS |
| 2427 | }, |
| 2428 | .dec = { |
| 2429 | .vecs = serpent_cbc_dec_tv_template, |
| 2430 | .count = SERPENT_CBC_DEC_TEST_VECTORS |
| 2431 | } |
| 2432 | } |
| 2433 | } |
| 2434 | }, { |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 2435 | .alg = "cbc(twofish)", |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 2436 | .test = alg_test_skcipher, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 2437 | .suite = { |
| 2438 | .cipher = { |
| 2439 | .enc = { |
| 2440 | .vecs = tf_cbc_enc_tv_template, |
| 2441 | .count = TF_CBC_ENC_TEST_VECTORS |
| 2442 | }, |
| 2443 | .dec = { |
| 2444 | .vecs = tf_cbc_dec_tv_template, |
| 2445 | .count = TF_CBC_DEC_TEST_VECTORS |
| 2446 | } |
| 2447 | } |
| 2448 | } |
| 2449 | }, { |
| 2450 | .alg = "ccm(aes)", |
| 2451 | .test = alg_test_aead, |
Jarod Wilson | a1915d5 | 2009-05-15 15:16:03 +1000 | [diff] [blame] | 2452 | .fips_allowed = 1, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 2453 | .suite = { |
| 2454 | .aead = { |
| 2455 | .enc = { |
| 2456 | .vecs = aes_ccm_enc_tv_template, |
| 2457 | .count = AES_CCM_ENC_TEST_VECTORS |
| 2458 | }, |
| 2459 | .dec = { |
| 2460 | .vecs = aes_ccm_dec_tv_template, |
| 2461 | .count = AES_CCM_DEC_TEST_VECTORS |
| 2462 | } |
| 2463 | } |
| 2464 | } |
| 2465 | }, { |
Martin Willi | 3590ebf | 2015-06-01 13:43:57 +0200 | [diff] [blame] | 2466 | .alg = "chacha20", |
| 2467 | .test = alg_test_skcipher, |
| 2468 | .suite = { |
| 2469 | .cipher = { |
| 2470 | .enc = { |
| 2471 | .vecs = chacha20_enc_tv_template, |
| 2472 | .count = CHACHA20_ENC_TEST_VECTORS |
| 2473 | }, |
| 2474 | .dec = { |
| 2475 | .vecs = chacha20_enc_tv_template, |
| 2476 | .count = CHACHA20_ENC_TEST_VECTORS |
| 2477 | }, |
| 2478 | } |
| 2479 | } |
| 2480 | }, { |
Jussi Kivilinna | 93b5e86 | 2013-04-08 10:48:44 +0300 | [diff] [blame] | 2481 | .alg = "cmac(aes)", |
Stephan Mueller | 8f18375 | 2015-08-19 08:42:07 +0200 | [diff] [blame] | 2482 | .fips_allowed = 1, |
Jussi Kivilinna | 93b5e86 | 2013-04-08 10:48:44 +0300 | [diff] [blame] | 2483 | .test = alg_test_hash, |
| 2484 | .suite = { |
| 2485 | .hash = { |
| 2486 | .vecs = aes_cmac128_tv_template, |
| 2487 | .count = CMAC_AES_TEST_VECTORS |
| 2488 | } |
| 2489 | } |
| 2490 | }, { |
| 2491 | .alg = "cmac(des3_ede)", |
Stephan Mueller | 8f18375 | 2015-08-19 08:42:07 +0200 | [diff] [blame] | 2492 | .fips_allowed = 1, |
Jussi Kivilinna | 93b5e86 | 2013-04-08 10:48:44 +0300 | [diff] [blame] | 2493 | .test = alg_test_hash, |
| 2494 | .suite = { |
| 2495 | .hash = { |
| 2496 | .vecs = des3_ede_cmac64_tv_template, |
| 2497 | .count = CMAC_DES3_EDE_TEST_VECTORS |
| 2498 | } |
| 2499 | } |
| 2500 | }, { |
Jussi Kivilinna | e448370 | 2013-04-07 16:43:56 +0300 | [diff] [blame] | 2501 | .alg = "compress_null", |
| 2502 | .test = alg_test_null, |
| 2503 | }, { |
Ard Biesheuvel | ebb3472 | 2015-05-04 11:00:17 +0200 | [diff] [blame] | 2504 | .alg = "crc32", |
| 2505 | .test = alg_test_hash, |
| 2506 | .suite = { |
| 2507 | .hash = { |
| 2508 | .vecs = crc32_tv_template, |
| 2509 | .count = CRC32_TEST_VECTORS |
| 2510 | } |
| 2511 | } |
| 2512 | }, { |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 2513 | .alg = "crc32c", |
Herbert Xu | 8e3ee85 | 2008-11-07 14:58:52 +0800 | [diff] [blame] | 2514 | .test = alg_test_crc32c, |
Jarod Wilson | a1915d5 | 2009-05-15 15:16:03 +1000 | [diff] [blame] | 2515 | .fips_allowed = 1, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 2516 | .suite = { |
| 2517 | .hash = { |
| 2518 | .vecs = crc32c_tv_template, |
| 2519 | .count = CRC32C_TEST_VECTORS |
| 2520 | } |
| 2521 | } |
| 2522 | }, { |
Herbert Xu | 68411521 | 2013-09-07 12:56:26 +1000 | [diff] [blame] | 2523 | .alg = "crct10dif", |
| 2524 | .test = alg_test_hash, |
| 2525 | .fips_allowed = 1, |
| 2526 | .suite = { |
| 2527 | .hash = { |
| 2528 | .vecs = crct10dif_tv_template, |
| 2529 | .count = CRCT10DIF_TEST_VECTORS |
| 2530 | } |
| 2531 | } |
| 2532 | }, { |
Milan Broz | 6c79294 | 2012-06-29 22:08:09 +0200 | [diff] [blame] | 2533 | .alg = "cryptd(__driver-cbc-aes-aesni)", |
| 2534 | .test = alg_test_null, |
| 2535 | .fips_allowed = 1, |
Milan Broz | 6c79294 | 2012-06-29 22:08:09 +0200 | [diff] [blame] | 2536 | }, { |
Jussi Kivilinna | d9b1d2e | 2012-10-26 14:49:01 +0300 | [diff] [blame] | 2537 | .alg = "cryptd(__driver-cbc-camellia-aesni)", |
| 2538 | .test = alg_test_null, |
Jussi Kivilinna | d9b1d2e | 2012-10-26 14:49:01 +0300 | [diff] [blame] | 2539 | }, { |
Jussi Kivilinna | f3f935a | 2013-04-13 13:47:00 +0300 | [diff] [blame] | 2540 | .alg = "cryptd(__driver-cbc-camellia-aesni-avx2)", |
| 2541 | .test = alg_test_null, |
| 2542 | }, { |
Jussi Kivilinna | 56d76c9 | 2013-04-13 13:46:55 +0300 | [diff] [blame] | 2543 | .alg = "cryptd(__driver-cbc-serpent-avx2)", |
| 2544 | .test = alg_test_null, |
| 2545 | }, { |
Youquan, Song | 863b557 | 2009-12-23 19:45:20 +0800 | [diff] [blame] | 2546 | .alg = "cryptd(__driver-ecb-aes-aesni)", |
| 2547 | .test = alg_test_null, |
Milan Broz | 6c79294 | 2012-06-29 22:08:09 +0200 | [diff] [blame] | 2548 | .fips_allowed = 1, |
Youquan, Song | 863b557 | 2009-12-23 19:45:20 +0800 | [diff] [blame] | 2549 | }, { |
Jussi Kivilinna | d9b1d2e | 2012-10-26 14:49:01 +0300 | [diff] [blame] | 2550 | .alg = "cryptd(__driver-ecb-camellia-aesni)", |
| 2551 | .test = alg_test_null, |
Jussi Kivilinna | d9b1d2e | 2012-10-26 14:49:01 +0300 | [diff] [blame] | 2552 | }, { |
Jussi Kivilinna | f3f935a | 2013-04-13 13:47:00 +0300 | [diff] [blame] | 2553 | .alg = "cryptd(__driver-ecb-camellia-aesni-avx2)", |
| 2554 | .test = alg_test_null, |
| 2555 | }, { |
Johannes Goetzfried | 4d6d6a2 | 2012-07-11 19:37:37 +0200 | [diff] [blame] | 2556 | .alg = "cryptd(__driver-ecb-cast5-avx)", |
| 2557 | .test = alg_test_null, |
Johannes Goetzfried | 4d6d6a2 | 2012-07-11 19:37:37 +0200 | [diff] [blame] | 2558 | }, { |
Johannes Goetzfried | 4ea1277 | 2012-07-11 19:38:57 +0200 | [diff] [blame] | 2559 | .alg = "cryptd(__driver-ecb-cast6-avx)", |
| 2560 | .test = alg_test_null, |
Johannes Goetzfried | 4ea1277 | 2012-07-11 19:38:57 +0200 | [diff] [blame] | 2561 | }, { |
Johannes Goetzfried | 7efe407 | 2012-06-12 16:47:43 +0800 | [diff] [blame] | 2562 | .alg = "cryptd(__driver-ecb-serpent-avx)", |
| 2563 | .test = alg_test_null, |
Johannes Goetzfried | 7efe407 | 2012-06-12 16:47:43 +0800 | [diff] [blame] | 2564 | }, { |
Jussi Kivilinna | 56d76c9 | 2013-04-13 13:46:55 +0300 | [diff] [blame] | 2565 | .alg = "cryptd(__driver-ecb-serpent-avx2)", |
| 2566 | .test = alg_test_null, |
| 2567 | }, { |
Jussi Kivilinna | 937c30d | 2011-11-09 16:26:25 +0200 | [diff] [blame] | 2568 | .alg = "cryptd(__driver-ecb-serpent-sse2)", |
| 2569 | .test = alg_test_null, |
Jussi Kivilinna | 937c30d | 2011-11-09 16:26:25 +0200 | [diff] [blame] | 2570 | }, { |
Johannes Goetzfried | 107778b | 2012-05-28 15:54:24 +0200 | [diff] [blame] | 2571 | .alg = "cryptd(__driver-ecb-twofish-avx)", |
| 2572 | .test = alg_test_null, |
Johannes Goetzfried | 107778b | 2012-05-28 15:54:24 +0200 | [diff] [blame] | 2573 | }, { |
Milan Broz | 6c79294 | 2012-06-29 22:08:09 +0200 | [diff] [blame] | 2574 | .alg = "cryptd(__driver-gcm-aes-aesni)", |
| 2575 | .test = alg_test_null, |
| 2576 | .fips_allowed = 1, |
Milan Broz | 6c79294 | 2012-06-29 22:08:09 +0200 | [diff] [blame] | 2577 | }, { |
Youquan, Song | 863b557 | 2009-12-23 19:45:20 +0800 | [diff] [blame] | 2578 | .alg = "cryptd(__ghash-pclmulqdqni)", |
| 2579 | .test = alg_test_null, |
Milan Broz | 6c79294 | 2012-06-29 22:08:09 +0200 | [diff] [blame] | 2580 | .fips_allowed = 1, |
Youquan, Song | 863b557 | 2009-12-23 19:45:20 +0800 | [diff] [blame] | 2581 | }, { |
Jarod Wilson | f7cb80f | 2009-05-06 17:29:17 +0800 | [diff] [blame] | 2582 | .alg = "ctr(aes)", |
| 2583 | .test = alg_test_skcipher, |
Jarod Wilson | a1915d5 | 2009-05-15 15:16:03 +1000 | [diff] [blame] | 2584 | .fips_allowed = 1, |
Jarod Wilson | f7cb80f | 2009-05-06 17:29:17 +0800 | [diff] [blame] | 2585 | .suite = { |
| 2586 | .cipher = { |
| 2587 | .enc = { |
| 2588 | .vecs = aes_ctr_enc_tv_template, |
| 2589 | .count = AES_CTR_ENC_TEST_VECTORS |
| 2590 | }, |
| 2591 | .dec = { |
| 2592 | .vecs = aes_ctr_dec_tv_template, |
| 2593 | .count = AES_CTR_DEC_TEST_VECTORS |
| 2594 | } |
| 2595 | } |
| 2596 | } |
| 2597 | }, { |
Jussi Kivilinna | 85b63e3 | 2011-10-10 23:03:03 +0300 | [diff] [blame] | 2598 | .alg = "ctr(blowfish)", |
| 2599 | .test = alg_test_skcipher, |
| 2600 | .suite = { |
| 2601 | .cipher = { |
| 2602 | .enc = { |
| 2603 | .vecs = bf_ctr_enc_tv_template, |
| 2604 | .count = BF_CTR_ENC_TEST_VECTORS |
| 2605 | }, |
| 2606 | .dec = { |
| 2607 | .vecs = bf_ctr_dec_tv_template, |
| 2608 | .count = BF_CTR_DEC_TEST_VECTORS |
| 2609 | } |
| 2610 | } |
| 2611 | } |
| 2612 | }, { |
Jussi Kivilinna | 0840605 | 2012-03-05 20:26:21 +0200 | [diff] [blame] | 2613 | .alg = "ctr(camellia)", |
| 2614 | .test = alg_test_skcipher, |
| 2615 | .suite = { |
| 2616 | .cipher = { |
| 2617 | .enc = { |
| 2618 | .vecs = camellia_ctr_enc_tv_template, |
| 2619 | .count = CAMELLIA_CTR_ENC_TEST_VECTORS |
| 2620 | }, |
| 2621 | .dec = { |
| 2622 | .vecs = camellia_ctr_dec_tv_template, |
| 2623 | .count = CAMELLIA_CTR_DEC_TEST_VECTORS |
| 2624 | } |
| 2625 | } |
| 2626 | } |
| 2627 | }, { |
Johannes Goetzfried | a2c5826 | 2012-07-11 19:37:21 +0200 | [diff] [blame] | 2628 | .alg = "ctr(cast5)", |
| 2629 | .test = alg_test_skcipher, |
| 2630 | .suite = { |
| 2631 | .cipher = { |
| 2632 | .enc = { |
| 2633 | .vecs = cast5_ctr_enc_tv_template, |
| 2634 | .count = CAST5_CTR_ENC_TEST_VECTORS |
| 2635 | }, |
| 2636 | .dec = { |
| 2637 | .vecs = cast5_ctr_dec_tv_template, |
| 2638 | .count = CAST5_CTR_DEC_TEST_VECTORS |
| 2639 | } |
| 2640 | } |
| 2641 | } |
| 2642 | }, { |
Johannes Goetzfried | 9b8b040 | 2012-07-11 19:38:29 +0200 | [diff] [blame] | 2643 | .alg = "ctr(cast6)", |
| 2644 | .test = alg_test_skcipher, |
| 2645 | .suite = { |
| 2646 | .cipher = { |
| 2647 | .enc = { |
| 2648 | .vecs = cast6_ctr_enc_tv_template, |
| 2649 | .count = CAST6_CTR_ENC_TEST_VECTORS |
| 2650 | }, |
| 2651 | .dec = { |
| 2652 | .vecs = cast6_ctr_dec_tv_template, |
| 2653 | .count = CAST6_CTR_DEC_TEST_VECTORS |
| 2654 | } |
| 2655 | } |
| 2656 | } |
| 2657 | }, { |
Jussi Kivilinna | 8163fc3 | 2012-10-20 14:53:07 +0300 | [diff] [blame] | 2658 | .alg = "ctr(des)", |
| 2659 | .test = alg_test_skcipher, |
| 2660 | .suite = { |
| 2661 | .cipher = { |
| 2662 | .enc = { |
| 2663 | .vecs = des_ctr_enc_tv_template, |
| 2664 | .count = DES_CTR_ENC_TEST_VECTORS |
| 2665 | }, |
| 2666 | .dec = { |
| 2667 | .vecs = des_ctr_dec_tv_template, |
| 2668 | .count = DES_CTR_DEC_TEST_VECTORS |
| 2669 | } |
| 2670 | } |
| 2671 | } |
| 2672 | }, { |
Jussi Kivilinna | e080b17 | 2012-10-20 14:53:12 +0300 | [diff] [blame] | 2673 | .alg = "ctr(des3_ede)", |
| 2674 | .test = alg_test_skcipher, |
| 2675 | .suite = { |
| 2676 | .cipher = { |
| 2677 | .enc = { |
| 2678 | .vecs = des3_ede_ctr_enc_tv_template, |
| 2679 | .count = DES3_EDE_CTR_ENC_TEST_VECTORS |
| 2680 | }, |
| 2681 | .dec = { |
| 2682 | .vecs = des3_ede_ctr_dec_tv_template, |
| 2683 | .count = DES3_EDE_CTR_DEC_TEST_VECTORS |
| 2684 | } |
| 2685 | } |
| 2686 | } |
| 2687 | }, { |
Jussi Kivilinna | 9d25917 | 2011-10-18 00:02:53 +0300 | [diff] [blame] | 2688 | .alg = "ctr(serpent)", |
| 2689 | .test = alg_test_skcipher, |
| 2690 | .suite = { |
| 2691 | .cipher = { |
| 2692 | .enc = { |
| 2693 | .vecs = serpent_ctr_enc_tv_template, |
| 2694 | .count = SERPENT_CTR_ENC_TEST_VECTORS |
| 2695 | }, |
| 2696 | .dec = { |
| 2697 | .vecs = serpent_ctr_dec_tv_template, |
| 2698 | .count = SERPENT_CTR_DEC_TEST_VECTORS |
| 2699 | } |
| 2700 | } |
| 2701 | } |
| 2702 | }, { |
Jussi Kivilinna | 573da62 | 2011-10-10 23:03:12 +0300 | [diff] [blame] | 2703 | .alg = "ctr(twofish)", |
| 2704 | .test = alg_test_skcipher, |
| 2705 | .suite = { |
| 2706 | .cipher = { |
| 2707 | .enc = { |
| 2708 | .vecs = tf_ctr_enc_tv_template, |
| 2709 | .count = TF_CTR_ENC_TEST_VECTORS |
| 2710 | }, |
| 2711 | .dec = { |
| 2712 | .vecs = tf_ctr_dec_tv_template, |
| 2713 | .count = TF_CTR_DEC_TEST_VECTORS |
| 2714 | } |
| 2715 | } |
| 2716 | } |
| 2717 | }, { |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 2718 | .alg = "cts(cbc(aes))", |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 2719 | .test = alg_test_skcipher, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 2720 | .suite = { |
| 2721 | .cipher = { |
| 2722 | .enc = { |
| 2723 | .vecs = cts_mode_enc_tv_template, |
| 2724 | .count = CTS_MODE_ENC_TEST_VECTORS |
| 2725 | }, |
| 2726 | .dec = { |
| 2727 | .vecs = cts_mode_dec_tv_template, |
| 2728 | .count = CTS_MODE_DEC_TEST_VECTORS |
| 2729 | } |
| 2730 | } |
| 2731 | } |
| 2732 | }, { |
| 2733 | .alg = "deflate", |
| 2734 | .test = alg_test_comp, |
Milan Broz | 0818904 | 2012-12-06 17:16:28 +0800 | [diff] [blame] | 2735 | .fips_allowed = 1, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 2736 | .suite = { |
| 2737 | .comp = { |
| 2738 | .comp = { |
| 2739 | .vecs = deflate_comp_tv_template, |
| 2740 | .count = DEFLATE_COMP_TEST_VECTORS |
| 2741 | }, |
| 2742 | .decomp = { |
| 2743 | .vecs = deflate_decomp_tv_template, |
| 2744 | .count = DEFLATE_DECOMP_TEST_VECTORS |
| 2745 | } |
| 2746 | } |
| 2747 | } |
| 2748 | }, { |
Jussi Kivilinna | e448370 | 2013-04-07 16:43:56 +0300 | [diff] [blame] | 2749 | .alg = "digest_null", |
| 2750 | .test = alg_test_null, |
| 2751 | }, { |
Stephan Mueller | 64d1cdf | 2014-05-31 17:25:36 +0200 | [diff] [blame] | 2752 | .alg = "drbg_nopr_ctr_aes128", |
| 2753 | .test = alg_test_drbg, |
| 2754 | .fips_allowed = 1, |
| 2755 | .suite = { |
| 2756 | .drbg = { |
| 2757 | .vecs = drbg_nopr_ctr_aes128_tv_template, |
| 2758 | .count = ARRAY_SIZE(drbg_nopr_ctr_aes128_tv_template) |
| 2759 | } |
| 2760 | } |
| 2761 | }, { |
| 2762 | .alg = "drbg_nopr_ctr_aes192", |
| 2763 | .test = alg_test_drbg, |
| 2764 | .fips_allowed = 1, |
| 2765 | .suite = { |
| 2766 | .drbg = { |
| 2767 | .vecs = drbg_nopr_ctr_aes192_tv_template, |
| 2768 | .count = ARRAY_SIZE(drbg_nopr_ctr_aes192_tv_template) |
| 2769 | } |
| 2770 | } |
| 2771 | }, { |
| 2772 | .alg = "drbg_nopr_ctr_aes256", |
| 2773 | .test = alg_test_drbg, |
| 2774 | .fips_allowed = 1, |
| 2775 | .suite = { |
| 2776 | .drbg = { |
| 2777 | .vecs = drbg_nopr_ctr_aes256_tv_template, |
| 2778 | .count = ARRAY_SIZE(drbg_nopr_ctr_aes256_tv_template) |
| 2779 | } |
| 2780 | } |
| 2781 | }, { |
| 2782 | /* |
| 2783 | * There is no need to specifically test the DRBG with every |
| 2784 | * backend cipher -- covered by drbg_nopr_hmac_sha256 test |
| 2785 | */ |
| 2786 | .alg = "drbg_nopr_hmac_sha1", |
| 2787 | .fips_allowed = 1, |
| 2788 | .test = alg_test_null, |
| 2789 | }, { |
| 2790 | .alg = "drbg_nopr_hmac_sha256", |
| 2791 | .test = alg_test_drbg, |
| 2792 | .fips_allowed = 1, |
| 2793 | .suite = { |
| 2794 | .drbg = { |
| 2795 | .vecs = drbg_nopr_hmac_sha256_tv_template, |
| 2796 | .count = |
| 2797 | ARRAY_SIZE(drbg_nopr_hmac_sha256_tv_template) |
| 2798 | } |
| 2799 | } |
| 2800 | }, { |
| 2801 | /* covered by drbg_nopr_hmac_sha256 test */ |
| 2802 | .alg = "drbg_nopr_hmac_sha384", |
| 2803 | .fips_allowed = 1, |
| 2804 | .test = alg_test_null, |
| 2805 | }, { |
| 2806 | .alg = "drbg_nopr_hmac_sha512", |
| 2807 | .test = alg_test_null, |
| 2808 | .fips_allowed = 1, |
| 2809 | }, { |
| 2810 | .alg = "drbg_nopr_sha1", |
| 2811 | .fips_allowed = 1, |
| 2812 | .test = alg_test_null, |
| 2813 | }, { |
| 2814 | .alg = "drbg_nopr_sha256", |
| 2815 | .test = alg_test_drbg, |
| 2816 | .fips_allowed = 1, |
| 2817 | .suite = { |
| 2818 | .drbg = { |
| 2819 | .vecs = drbg_nopr_sha256_tv_template, |
| 2820 | .count = ARRAY_SIZE(drbg_nopr_sha256_tv_template) |
| 2821 | } |
| 2822 | } |
| 2823 | }, { |
| 2824 | /* covered by drbg_nopr_sha256 test */ |
| 2825 | .alg = "drbg_nopr_sha384", |
| 2826 | .fips_allowed = 1, |
| 2827 | .test = alg_test_null, |
| 2828 | }, { |
| 2829 | .alg = "drbg_nopr_sha512", |
| 2830 | .fips_allowed = 1, |
| 2831 | .test = alg_test_null, |
| 2832 | }, { |
| 2833 | .alg = "drbg_pr_ctr_aes128", |
| 2834 | .test = alg_test_drbg, |
| 2835 | .fips_allowed = 1, |
| 2836 | .suite = { |
| 2837 | .drbg = { |
| 2838 | .vecs = drbg_pr_ctr_aes128_tv_template, |
| 2839 | .count = ARRAY_SIZE(drbg_pr_ctr_aes128_tv_template) |
| 2840 | } |
| 2841 | } |
| 2842 | }, { |
| 2843 | /* covered by drbg_pr_ctr_aes128 test */ |
| 2844 | .alg = "drbg_pr_ctr_aes192", |
| 2845 | .fips_allowed = 1, |
| 2846 | .test = alg_test_null, |
| 2847 | }, { |
| 2848 | .alg = "drbg_pr_ctr_aes256", |
| 2849 | .fips_allowed = 1, |
| 2850 | .test = alg_test_null, |
| 2851 | }, { |
| 2852 | .alg = "drbg_pr_hmac_sha1", |
| 2853 | .fips_allowed = 1, |
| 2854 | .test = alg_test_null, |
| 2855 | }, { |
| 2856 | .alg = "drbg_pr_hmac_sha256", |
| 2857 | .test = alg_test_drbg, |
| 2858 | .fips_allowed = 1, |
| 2859 | .suite = { |
| 2860 | .drbg = { |
| 2861 | .vecs = drbg_pr_hmac_sha256_tv_template, |
| 2862 | .count = ARRAY_SIZE(drbg_pr_hmac_sha256_tv_template) |
| 2863 | } |
| 2864 | } |
| 2865 | }, { |
| 2866 | /* covered by drbg_pr_hmac_sha256 test */ |
| 2867 | .alg = "drbg_pr_hmac_sha384", |
| 2868 | .fips_allowed = 1, |
| 2869 | .test = alg_test_null, |
| 2870 | }, { |
| 2871 | .alg = "drbg_pr_hmac_sha512", |
| 2872 | .test = alg_test_null, |
| 2873 | .fips_allowed = 1, |
| 2874 | }, { |
| 2875 | .alg = "drbg_pr_sha1", |
| 2876 | .fips_allowed = 1, |
| 2877 | .test = alg_test_null, |
| 2878 | }, { |
| 2879 | .alg = "drbg_pr_sha256", |
| 2880 | .test = alg_test_drbg, |
| 2881 | .fips_allowed = 1, |
| 2882 | .suite = { |
| 2883 | .drbg = { |
| 2884 | .vecs = drbg_pr_sha256_tv_template, |
| 2885 | .count = ARRAY_SIZE(drbg_pr_sha256_tv_template) |
| 2886 | } |
| 2887 | } |
| 2888 | }, { |
| 2889 | /* covered by drbg_pr_sha256 test */ |
| 2890 | .alg = "drbg_pr_sha384", |
| 2891 | .fips_allowed = 1, |
| 2892 | .test = alg_test_null, |
| 2893 | }, { |
| 2894 | .alg = "drbg_pr_sha512", |
| 2895 | .fips_allowed = 1, |
| 2896 | .test = alg_test_null, |
| 2897 | }, { |
Youquan, Song | 863b557 | 2009-12-23 19:45:20 +0800 | [diff] [blame] | 2898 | .alg = "ecb(__aes-aesni)", |
| 2899 | .test = alg_test_null, |
Milan Broz | 6c79294 | 2012-06-29 22:08:09 +0200 | [diff] [blame] | 2900 | .fips_allowed = 1, |
Youquan, Song | 863b557 | 2009-12-23 19:45:20 +0800 | [diff] [blame] | 2901 | }, { |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 2902 | .alg = "ecb(aes)", |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 2903 | .test = alg_test_skcipher, |
Jarod Wilson | a1915d5 | 2009-05-15 15:16:03 +1000 | [diff] [blame] | 2904 | .fips_allowed = 1, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 2905 | .suite = { |
| 2906 | .cipher = { |
| 2907 | .enc = { |
| 2908 | .vecs = aes_enc_tv_template, |
| 2909 | .count = AES_ENC_TEST_VECTORS |
| 2910 | }, |
| 2911 | .dec = { |
| 2912 | .vecs = aes_dec_tv_template, |
| 2913 | .count = AES_DEC_TEST_VECTORS |
| 2914 | } |
| 2915 | } |
| 2916 | } |
| 2917 | }, { |
| 2918 | .alg = "ecb(anubis)", |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 2919 | .test = alg_test_skcipher, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 2920 | .suite = { |
| 2921 | .cipher = { |
| 2922 | .enc = { |
| 2923 | .vecs = anubis_enc_tv_template, |
| 2924 | .count = ANUBIS_ENC_TEST_VECTORS |
| 2925 | }, |
| 2926 | .dec = { |
| 2927 | .vecs = anubis_dec_tv_template, |
| 2928 | .count = ANUBIS_DEC_TEST_VECTORS |
| 2929 | } |
| 2930 | } |
| 2931 | } |
| 2932 | }, { |
| 2933 | .alg = "ecb(arc4)", |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 2934 | .test = alg_test_skcipher, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 2935 | .suite = { |
| 2936 | .cipher = { |
| 2937 | .enc = { |
| 2938 | .vecs = arc4_enc_tv_template, |
| 2939 | .count = ARC4_ENC_TEST_VECTORS |
| 2940 | }, |
| 2941 | .dec = { |
| 2942 | .vecs = arc4_dec_tv_template, |
| 2943 | .count = ARC4_DEC_TEST_VECTORS |
| 2944 | } |
| 2945 | } |
| 2946 | } |
| 2947 | }, { |
| 2948 | .alg = "ecb(blowfish)", |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 2949 | .test = alg_test_skcipher, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 2950 | .suite = { |
| 2951 | .cipher = { |
| 2952 | .enc = { |
| 2953 | .vecs = bf_enc_tv_template, |
| 2954 | .count = BF_ENC_TEST_VECTORS |
| 2955 | }, |
| 2956 | .dec = { |
| 2957 | .vecs = bf_dec_tv_template, |
| 2958 | .count = BF_DEC_TEST_VECTORS |
| 2959 | } |
| 2960 | } |
| 2961 | } |
| 2962 | }, { |
| 2963 | .alg = "ecb(camellia)", |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 2964 | .test = alg_test_skcipher, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 2965 | .suite = { |
| 2966 | .cipher = { |
| 2967 | .enc = { |
| 2968 | .vecs = camellia_enc_tv_template, |
| 2969 | .count = CAMELLIA_ENC_TEST_VECTORS |
| 2970 | }, |
| 2971 | .dec = { |
| 2972 | .vecs = camellia_dec_tv_template, |
| 2973 | .count = CAMELLIA_DEC_TEST_VECTORS |
| 2974 | } |
| 2975 | } |
| 2976 | } |
| 2977 | }, { |
| 2978 | .alg = "ecb(cast5)", |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 2979 | .test = alg_test_skcipher, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 2980 | .suite = { |
| 2981 | .cipher = { |
| 2982 | .enc = { |
| 2983 | .vecs = cast5_enc_tv_template, |
| 2984 | .count = CAST5_ENC_TEST_VECTORS |
| 2985 | }, |
| 2986 | .dec = { |
| 2987 | .vecs = cast5_dec_tv_template, |
| 2988 | .count = CAST5_DEC_TEST_VECTORS |
| 2989 | } |
| 2990 | } |
| 2991 | } |
| 2992 | }, { |
| 2993 | .alg = "ecb(cast6)", |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 2994 | .test = alg_test_skcipher, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 2995 | .suite = { |
| 2996 | .cipher = { |
| 2997 | .enc = { |
| 2998 | .vecs = cast6_enc_tv_template, |
| 2999 | .count = CAST6_ENC_TEST_VECTORS |
| 3000 | }, |
| 3001 | .dec = { |
| 3002 | .vecs = cast6_dec_tv_template, |
| 3003 | .count = CAST6_DEC_TEST_VECTORS |
| 3004 | } |
| 3005 | } |
| 3006 | } |
| 3007 | }, { |
Jussi Kivilinna | e448370 | 2013-04-07 16:43:56 +0300 | [diff] [blame] | 3008 | .alg = "ecb(cipher_null)", |
| 3009 | .test = alg_test_null, |
| 3010 | }, { |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 3011 | .alg = "ecb(des)", |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 3012 | .test = alg_test_skcipher, |
Jarod Wilson | a1915d5 | 2009-05-15 15:16:03 +1000 | [diff] [blame] | 3013 | .fips_allowed = 1, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 3014 | .suite = { |
| 3015 | .cipher = { |
| 3016 | .enc = { |
| 3017 | .vecs = des_enc_tv_template, |
| 3018 | .count = DES_ENC_TEST_VECTORS |
| 3019 | }, |
| 3020 | .dec = { |
| 3021 | .vecs = des_dec_tv_template, |
| 3022 | .count = DES_DEC_TEST_VECTORS |
| 3023 | } |
| 3024 | } |
| 3025 | } |
| 3026 | }, { |
| 3027 | .alg = "ecb(des3_ede)", |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 3028 | .test = alg_test_skcipher, |
Jarod Wilson | a1915d5 | 2009-05-15 15:16:03 +1000 | [diff] [blame] | 3029 | .fips_allowed = 1, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 3030 | .suite = { |
| 3031 | .cipher = { |
| 3032 | .enc = { |
| 3033 | .vecs = des3_ede_enc_tv_template, |
| 3034 | .count = DES3_EDE_ENC_TEST_VECTORS |
| 3035 | }, |
| 3036 | .dec = { |
| 3037 | .vecs = des3_ede_dec_tv_template, |
| 3038 | .count = DES3_EDE_DEC_TEST_VECTORS |
| 3039 | } |
| 3040 | } |
| 3041 | } |
| 3042 | }, { |
Jussi Kivilinna | 66e5bd0 | 2013-01-19 13:31:36 +0200 | [diff] [blame] | 3043 | .alg = "ecb(fcrypt)", |
| 3044 | .test = alg_test_skcipher, |
| 3045 | .suite = { |
| 3046 | .cipher = { |
| 3047 | .enc = { |
| 3048 | .vecs = fcrypt_pcbc_enc_tv_template, |
| 3049 | .count = 1 |
| 3050 | }, |
| 3051 | .dec = { |
| 3052 | .vecs = fcrypt_pcbc_dec_tv_template, |
| 3053 | .count = 1 |
| 3054 | } |
| 3055 | } |
| 3056 | } |
| 3057 | }, { |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 3058 | .alg = "ecb(khazad)", |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 3059 | .test = alg_test_skcipher, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 3060 | .suite = { |
| 3061 | .cipher = { |
| 3062 | .enc = { |
| 3063 | .vecs = khazad_enc_tv_template, |
| 3064 | .count = KHAZAD_ENC_TEST_VECTORS |
| 3065 | }, |
| 3066 | .dec = { |
| 3067 | .vecs = khazad_dec_tv_template, |
| 3068 | .count = KHAZAD_DEC_TEST_VECTORS |
| 3069 | } |
| 3070 | } |
| 3071 | } |
| 3072 | }, { |
| 3073 | .alg = "ecb(seed)", |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 3074 | .test = alg_test_skcipher, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 3075 | .suite = { |
| 3076 | .cipher = { |
| 3077 | .enc = { |
| 3078 | .vecs = seed_enc_tv_template, |
| 3079 | .count = SEED_ENC_TEST_VECTORS |
| 3080 | }, |
| 3081 | .dec = { |
| 3082 | .vecs = seed_dec_tv_template, |
| 3083 | .count = SEED_DEC_TEST_VECTORS |
| 3084 | } |
| 3085 | } |
| 3086 | } |
| 3087 | }, { |
| 3088 | .alg = "ecb(serpent)", |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 3089 | .test = alg_test_skcipher, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 3090 | .suite = { |
| 3091 | .cipher = { |
| 3092 | .enc = { |
| 3093 | .vecs = serpent_enc_tv_template, |
| 3094 | .count = SERPENT_ENC_TEST_VECTORS |
| 3095 | }, |
| 3096 | .dec = { |
| 3097 | .vecs = serpent_dec_tv_template, |
| 3098 | .count = SERPENT_DEC_TEST_VECTORS |
| 3099 | } |
| 3100 | } |
| 3101 | } |
| 3102 | }, { |
| 3103 | .alg = "ecb(tea)", |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 3104 | .test = alg_test_skcipher, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 3105 | .suite = { |
| 3106 | .cipher = { |
| 3107 | .enc = { |
| 3108 | .vecs = tea_enc_tv_template, |
| 3109 | .count = TEA_ENC_TEST_VECTORS |
| 3110 | }, |
| 3111 | .dec = { |
| 3112 | .vecs = tea_dec_tv_template, |
| 3113 | .count = TEA_DEC_TEST_VECTORS |
| 3114 | } |
| 3115 | } |
| 3116 | } |
| 3117 | }, { |
| 3118 | .alg = "ecb(tnepres)", |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 3119 | .test = alg_test_skcipher, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 3120 | .suite = { |
| 3121 | .cipher = { |
| 3122 | .enc = { |
| 3123 | .vecs = tnepres_enc_tv_template, |
| 3124 | .count = TNEPRES_ENC_TEST_VECTORS |
| 3125 | }, |
| 3126 | .dec = { |
| 3127 | .vecs = tnepres_dec_tv_template, |
| 3128 | .count = TNEPRES_DEC_TEST_VECTORS |
| 3129 | } |
| 3130 | } |
| 3131 | } |
| 3132 | }, { |
| 3133 | .alg = "ecb(twofish)", |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 3134 | .test = alg_test_skcipher, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 3135 | .suite = { |
| 3136 | .cipher = { |
| 3137 | .enc = { |
| 3138 | .vecs = tf_enc_tv_template, |
| 3139 | .count = TF_ENC_TEST_VECTORS |
| 3140 | }, |
| 3141 | .dec = { |
| 3142 | .vecs = tf_dec_tv_template, |
| 3143 | .count = TF_DEC_TEST_VECTORS |
| 3144 | } |
| 3145 | } |
| 3146 | } |
| 3147 | }, { |
| 3148 | .alg = "ecb(xeta)", |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 3149 | .test = alg_test_skcipher, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 3150 | .suite = { |
| 3151 | .cipher = { |
| 3152 | .enc = { |
| 3153 | .vecs = xeta_enc_tv_template, |
| 3154 | .count = XETA_ENC_TEST_VECTORS |
| 3155 | }, |
| 3156 | .dec = { |
| 3157 | .vecs = xeta_dec_tv_template, |
| 3158 | .count = XETA_DEC_TEST_VECTORS |
| 3159 | } |
| 3160 | } |
| 3161 | } |
| 3162 | }, { |
| 3163 | .alg = "ecb(xtea)", |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 3164 | .test = alg_test_skcipher, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 3165 | .suite = { |
| 3166 | .cipher = { |
| 3167 | .enc = { |
| 3168 | .vecs = xtea_enc_tv_template, |
| 3169 | .count = XTEA_ENC_TEST_VECTORS |
| 3170 | }, |
| 3171 | .dec = { |
| 3172 | .vecs = xtea_dec_tv_template, |
| 3173 | .count = XTEA_DEC_TEST_VECTORS |
| 3174 | } |
| 3175 | } |
| 3176 | } |
| 3177 | }, { |
| 3178 | .alg = "gcm(aes)", |
| 3179 | .test = alg_test_aead, |
Jarod Wilson | a1915d5 | 2009-05-15 15:16:03 +1000 | [diff] [blame] | 3180 | .fips_allowed = 1, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 3181 | .suite = { |
| 3182 | .aead = { |
| 3183 | .enc = { |
| 3184 | .vecs = aes_gcm_enc_tv_template, |
| 3185 | .count = AES_GCM_ENC_TEST_VECTORS |
| 3186 | }, |
| 3187 | .dec = { |
| 3188 | .vecs = aes_gcm_dec_tv_template, |
| 3189 | .count = AES_GCM_DEC_TEST_VECTORS |
| 3190 | } |
| 3191 | } |
| 3192 | } |
| 3193 | }, { |
Youquan, Song | 507069c | 2009-11-23 20:23:04 +0800 | [diff] [blame] | 3194 | .alg = "ghash", |
| 3195 | .test = alg_test_hash, |
Jarod Wilson | 18c0ebd | 2011-01-29 15:14:35 +1100 | [diff] [blame] | 3196 | .fips_allowed = 1, |
Youquan, Song | 507069c | 2009-11-23 20:23:04 +0800 | [diff] [blame] | 3197 | .suite = { |
| 3198 | .hash = { |
| 3199 | .vecs = ghash_tv_template, |
| 3200 | .count = GHASH_TEST_VECTORS |
| 3201 | } |
| 3202 | } |
| 3203 | }, { |
Sonic Zhang | a482b08 | 2012-05-25 17:54:13 +0800 | [diff] [blame] | 3204 | .alg = "hmac(crc32)", |
| 3205 | .test = alg_test_hash, |
| 3206 | .suite = { |
| 3207 | .hash = { |
| 3208 | .vecs = bfin_crc_tv_template, |
| 3209 | .count = BFIN_CRC_TEST_VECTORS |
| 3210 | } |
| 3211 | } |
| 3212 | }, { |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 3213 | .alg = "hmac(md5)", |
| 3214 | .test = alg_test_hash, |
| 3215 | .suite = { |
| 3216 | .hash = { |
| 3217 | .vecs = hmac_md5_tv_template, |
| 3218 | .count = HMAC_MD5_TEST_VECTORS |
| 3219 | } |
| 3220 | } |
| 3221 | }, { |
| 3222 | .alg = "hmac(rmd128)", |
| 3223 | .test = alg_test_hash, |
| 3224 | .suite = { |
| 3225 | .hash = { |
| 3226 | .vecs = hmac_rmd128_tv_template, |
| 3227 | .count = HMAC_RMD128_TEST_VECTORS |
| 3228 | } |
| 3229 | } |
| 3230 | }, { |
| 3231 | .alg = "hmac(rmd160)", |
| 3232 | .test = alg_test_hash, |
| 3233 | .suite = { |
| 3234 | .hash = { |
| 3235 | .vecs = hmac_rmd160_tv_template, |
| 3236 | .count = HMAC_RMD160_TEST_VECTORS |
| 3237 | } |
| 3238 | } |
| 3239 | }, { |
| 3240 | .alg = "hmac(sha1)", |
| 3241 | .test = alg_test_hash, |
Jarod Wilson | a1915d5 | 2009-05-15 15:16:03 +1000 | [diff] [blame] | 3242 | .fips_allowed = 1, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 3243 | .suite = { |
| 3244 | .hash = { |
| 3245 | .vecs = hmac_sha1_tv_template, |
| 3246 | .count = HMAC_SHA1_TEST_VECTORS |
| 3247 | } |
| 3248 | } |
| 3249 | }, { |
| 3250 | .alg = "hmac(sha224)", |
| 3251 | .test = alg_test_hash, |
Jarod Wilson | a1915d5 | 2009-05-15 15:16:03 +1000 | [diff] [blame] | 3252 | .fips_allowed = 1, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 3253 | .suite = { |
| 3254 | .hash = { |
| 3255 | .vecs = hmac_sha224_tv_template, |
| 3256 | .count = HMAC_SHA224_TEST_VECTORS |
| 3257 | } |
| 3258 | } |
| 3259 | }, { |
| 3260 | .alg = "hmac(sha256)", |
| 3261 | .test = alg_test_hash, |
Jarod Wilson | a1915d5 | 2009-05-15 15:16:03 +1000 | [diff] [blame] | 3262 | .fips_allowed = 1, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 3263 | .suite = { |
| 3264 | .hash = { |
| 3265 | .vecs = hmac_sha256_tv_template, |
| 3266 | .count = HMAC_SHA256_TEST_VECTORS |
| 3267 | } |
| 3268 | } |
| 3269 | }, { |
| 3270 | .alg = "hmac(sha384)", |
| 3271 | .test = alg_test_hash, |
Jarod Wilson | a1915d5 | 2009-05-15 15:16:03 +1000 | [diff] [blame] | 3272 | .fips_allowed = 1, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 3273 | .suite = { |
| 3274 | .hash = { |
| 3275 | .vecs = hmac_sha384_tv_template, |
| 3276 | .count = HMAC_SHA384_TEST_VECTORS |
| 3277 | } |
| 3278 | } |
| 3279 | }, { |
| 3280 | .alg = "hmac(sha512)", |
| 3281 | .test = alg_test_hash, |
Jarod Wilson | a1915d5 | 2009-05-15 15:16:03 +1000 | [diff] [blame] | 3282 | .fips_allowed = 1, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 3283 | .suite = { |
| 3284 | .hash = { |
| 3285 | .vecs = hmac_sha512_tv_template, |
| 3286 | .count = HMAC_SHA512_TEST_VECTORS |
| 3287 | } |
| 3288 | } |
| 3289 | }, { |
Stephan Mueller | bb5530e | 2015-05-25 15:10:20 +0200 | [diff] [blame] | 3290 | .alg = "jitterentropy_rng", |
| 3291 | .fips_allowed = 1, |
| 3292 | .test = alg_test_null, |
| 3293 | }, { |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 3294 | .alg = "lrw(aes)", |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 3295 | .test = alg_test_skcipher, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 3296 | .suite = { |
| 3297 | .cipher = { |
| 3298 | .enc = { |
| 3299 | .vecs = aes_lrw_enc_tv_template, |
| 3300 | .count = AES_LRW_ENC_TEST_VECTORS |
| 3301 | }, |
| 3302 | .dec = { |
| 3303 | .vecs = aes_lrw_dec_tv_template, |
| 3304 | .count = AES_LRW_DEC_TEST_VECTORS |
| 3305 | } |
| 3306 | } |
| 3307 | } |
| 3308 | }, { |
Jussi Kivilinna | 0840605 | 2012-03-05 20:26:21 +0200 | [diff] [blame] | 3309 | .alg = "lrw(camellia)", |
| 3310 | .test = alg_test_skcipher, |
| 3311 | .suite = { |
| 3312 | .cipher = { |
| 3313 | .enc = { |
| 3314 | .vecs = camellia_lrw_enc_tv_template, |
| 3315 | .count = CAMELLIA_LRW_ENC_TEST_VECTORS |
| 3316 | }, |
| 3317 | .dec = { |
| 3318 | .vecs = camellia_lrw_dec_tv_template, |
| 3319 | .count = CAMELLIA_LRW_DEC_TEST_VECTORS |
| 3320 | } |
| 3321 | } |
| 3322 | } |
| 3323 | }, { |
Johannes Goetzfried | 9b8b040 | 2012-07-11 19:38:29 +0200 | [diff] [blame] | 3324 | .alg = "lrw(cast6)", |
| 3325 | .test = alg_test_skcipher, |
| 3326 | .suite = { |
| 3327 | .cipher = { |
| 3328 | .enc = { |
| 3329 | .vecs = cast6_lrw_enc_tv_template, |
| 3330 | .count = CAST6_LRW_ENC_TEST_VECTORS |
| 3331 | }, |
| 3332 | .dec = { |
| 3333 | .vecs = cast6_lrw_dec_tv_template, |
| 3334 | .count = CAST6_LRW_DEC_TEST_VECTORS |
| 3335 | } |
| 3336 | } |
| 3337 | } |
| 3338 | }, { |
Jussi Kivilinna | d7bfc0f | 2011-10-18 13:32:34 +0300 | [diff] [blame] | 3339 | .alg = "lrw(serpent)", |
| 3340 | .test = alg_test_skcipher, |
| 3341 | .suite = { |
| 3342 | .cipher = { |
| 3343 | .enc = { |
| 3344 | .vecs = serpent_lrw_enc_tv_template, |
| 3345 | .count = SERPENT_LRW_ENC_TEST_VECTORS |
| 3346 | }, |
| 3347 | .dec = { |
| 3348 | .vecs = serpent_lrw_dec_tv_template, |
| 3349 | .count = SERPENT_LRW_DEC_TEST_VECTORS |
| 3350 | } |
| 3351 | } |
| 3352 | } |
| 3353 | }, { |
Jussi Kivilinna | 0b2a155 | 2011-10-18 13:32:50 +0300 | [diff] [blame] | 3354 | .alg = "lrw(twofish)", |
| 3355 | .test = alg_test_skcipher, |
| 3356 | .suite = { |
| 3357 | .cipher = { |
| 3358 | .enc = { |
| 3359 | .vecs = tf_lrw_enc_tv_template, |
| 3360 | .count = TF_LRW_ENC_TEST_VECTORS |
| 3361 | }, |
| 3362 | .dec = { |
| 3363 | .vecs = tf_lrw_dec_tv_template, |
| 3364 | .count = TF_LRW_DEC_TEST_VECTORS |
| 3365 | } |
| 3366 | } |
| 3367 | } |
| 3368 | }, { |
KOVACS Krisztian | 1443cc9 | 2014-08-22 10:44:36 +0200 | [diff] [blame] | 3369 | .alg = "lz4", |
| 3370 | .test = alg_test_comp, |
| 3371 | .fips_allowed = 1, |
| 3372 | .suite = { |
| 3373 | .comp = { |
| 3374 | .comp = { |
| 3375 | .vecs = lz4_comp_tv_template, |
| 3376 | .count = LZ4_COMP_TEST_VECTORS |
| 3377 | }, |
| 3378 | .decomp = { |
| 3379 | .vecs = lz4_decomp_tv_template, |
| 3380 | .count = LZ4_DECOMP_TEST_VECTORS |
| 3381 | } |
| 3382 | } |
| 3383 | } |
| 3384 | }, { |
| 3385 | .alg = "lz4hc", |
| 3386 | .test = alg_test_comp, |
| 3387 | .fips_allowed = 1, |
| 3388 | .suite = { |
| 3389 | .comp = { |
| 3390 | .comp = { |
| 3391 | .vecs = lz4hc_comp_tv_template, |
| 3392 | .count = LZ4HC_COMP_TEST_VECTORS |
| 3393 | }, |
| 3394 | .decomp = { |
| 3395 | .vecs = lz4hc_decomp_tv_template, |
| 3396 | .count = LZ4HC_DECOMP_TEST_VECTORS |
| 3397 | } |
| 3398 | } |
| 3399 | } |
| 3400 | }, { |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 3401 | .alg = "lzo", |
| 3402 | .test = alg_test_comp, |
Milan Broz | 0818904 | 2012-12-06 17:16:28 +0800 | [diff] [blame] | 3403 | .fips_allowed = 1, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 3404 | .suite = { |
| 3405 | .comp = { |
| 3406 | .comp = { |
| 3407 | .vecs = lzo_comp_tv_template, |
| 3408 | .count = LZO_COMP_TEST_VECTORS |
| 3409 | }, |
| 3410 | .decomp = { |
| 3411 | .vecs = lzo_decomp_tv_template, |
| 3412 | .count = LZO_DECOMP_TEST_VECTORS |
| 3413 | } |
| 3414 | } |
| 3415 | } |
| 3416 | }, { |
| 3417 | .alg = "md4", |
| 3418 | .test = alg_test_hash, |
| 3419 | .suite = { |
| 3420 | .hash = { |
| 3421 | .vecs = md4_tv_template, |
| 3422 | .count = MD4_TEST_VECTORS |
| 3423 | } |
| 3424 | } |
| 3425 | }, { |
| 3426 | .alg = "md5", |
| 3427 | .test = alg_test_hash, |
| 3428 | .suite = { |
| 3429 | .hash = { |
| 3430 | .vecs = md5_tv_template, |
| 3431 | .count = MD5_TEST_VECTORS |
| 3432 | } |
| 3433 | } |
| 3434 | }, { |
| 3435 | .alg = "michael_mic", |
| 3436 | .test = alg_test_hash, |
| 3437 | .suite = { |
| 3438 | .hash = { |
| 3439 | .vecs = michael_mic_tv_template, |
| 3440 | .count = MICHAEL_MIC_TEST_VECTORS |
| 3441 | } |
| 3442 | } |
| 3443 | }, { |
Puneet Saxena | ba0e14a | 2011-05-04 15:04:10 +1000 | [diff] [blame] | 3444 | .alg = "ofb(aes)", |
| 3445 | .test = alg_test_skcipher, |
| 3446 | .fips_allowed = 1, |
| 3447 | .suite = { |
| 3448 | .cipher = { |
| 3449 | .enc = { |
| 3450 | .vecs = aes_ofb_enc_tv_template, |
| 3451 | .count = AES_OFB_ENC_TEST_VECTORS |
| 3452 | }, |
| 3453 | .dec = { |
| 3454 | .vecs = aes_ofb_dec_tv_template, |
| 3455 | .count = AES_OFB_DEC_TEST_VECTORS |
| 3456 | } |
| 3457 | } |
| 3458 | } |
| 3459 | }, { |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 3460 | .alg = "pcbc(fcrypt)", |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 3461 | .test = alg_test_skcipher, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 3462 | .suite = { |
| 3463 | .cipher = { |
| 3464 | .enc = { |
| 3465 | .vecs = fcrypt_pcbc_enc_tv_template, |
| 3466 | .count = FCRYPT_ENC_TEST_VECTORS |
| 3467 | }, |
| 3468 | .dec = { |
| 3469 | .vecs = fcrypt_pcbc_dec_tv_template, |
| 3470 | .count = FCRYPT_DEC_TEST_VECTORS |
| 3471 | } |
| 3472 | } |
| 3473 | } |
| 3474 | }, { |
Martin Willi | eee9dc6 | 2015-06-01 13:43:59 +0200 | [diff] [blame] | 3475 | .alg = "poly1305", |
| 3476 | .test = alg_test_hash, |
| 3477 | .suite = { |
| 3478 | .hash = { |
| 3479 | .vecs = poly1305_tv_template, |
| 3480 | .count = POLY1305_TEST_VECTORS |
| 3481 | } |
| 3482 | } |
| 3483 | }, { |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 3484 | .alg = "rfc3686(ctr(aes))", |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 3485 | .test = alg_test_skcipher, |
Jarod Wilson | a1915d5 | 2009-05-15 15:16:03 +1000 | [diff] [blame] | 3486 | .fips_allowed = 1, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 3487 | .suite = { |
| 3488 | .cipher = { |
| 3489 | .enc = { |
Jarod Wilson | f7cb80f | 2009-05-06 17:29:17 +0800 | [diff] [blame] | 3490 | .vecs = aes_ctr_rfc3686_enc_tv_template, |
| 3491 | .count = AES_CTR_3686_ENC_TEST_VECTORS |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 3492 | }, |
| 3493 | .dec = { |
Jarod Wilson | f7cb80f | 2009-05-06 17:29:17 +0800 | [diff] [blame] | 3494 | .vecs = aes_ctr_rfc3686_dec_tv_template, |
| 3495 | .count = AES_CTR_3686_DEC_TEST_VECTORS |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 3496 | } |
| 3497 | } |
| 3498 | } |
| 3499 | }, { |
Herbert Xu | 3f31a74 | 2015-07-09 07:17:34 +0800 | [diff] [blame] | 3500 | .alg = "rfc4106(gcm(aes))", |
Adrian Hoban | 69435b9 | 2010-11-04 15:02:04 -0400 | [diff] [blame] | 3501 | .test = alg_test_aead, |
Jarod Wilson | db71f29 | 2015-01-23 12:42:15 -0500 | [diff] [blame] | 3502 | .fips_allowed = 1, |
Adrian Hoban | 69435b9 | 2010-11-04 15:02:04 -0400 | [diff] [blame] | 3503 | .suite = { |
| 3504 | .aead = { |
| 3505 | .enc = { |
| 3506 | .vecs = aes_gcm_rfc4106_enc_tv_template, |
| 3507 | .count = AES_GCM_4106_ENC_TEST_VECTORS |
| 3508 | }, |
| 3509 | .dec = { |
| 3510 | .vecs = aes_gcm_rfc4106_dec_tv_template, |
| 3511 | .count = AES_GCM_4106_DEC_TEST_VECTORS |
| 3512 | } |
| 3513 | } |
| 3514 | } |
| 3515 | }, { |
Herbert Xu | 544c436 | 2015-07-14 16:53:22 +0800 | [diff] [blame] | 3516 | .alg = "rfc4309(ccm(aes))", |
Jarod Wilson | 5d66732 | 2009-05-04 19:23:40 +0800 | [diff] [blame] | 3517 | .test = alg_test_aead, |
Jarod Wilson | a1915d5 | 2009-05-15 15:16:03 +1000 | [diff] [blame] | 3518 | .fips_allowed = 1, |
Jarod Wilson | 5d66732 | 2009-05-04 19:23:40 +0800 | [diff] [blame] | 3519 | .suite = { |
| 3520 | .aead = { |
| 3521 | .enc = { |
| 3522 | .vecs = aes_ccm_rfc4309_enc_tv_template, |
| 3523 | .count = AES_CCM_4309_ENC_TEST_VECTORS |
| 3524 | }, |
| 3525 | .dec = { |
| 3526 | .vecs = aes_ccm_rfc4309_dec_tv_template, |
| 3527 | .count = AES_CCM_4309_DEC_TEST_VECTORS |
| 3528 | } |
| 3529 | } |
| 3530 | } |
| 3531 | }, { |
Herbert Xu | bb68745 | 2015-06-16 13:54:24 +0800 | [diff] [blame] | 3532 | .alg = "rfc4543(gcm(aes))", |
Jussi Kivilinna | e9b7441 | 2013-04-07 16:43:51 +0300 | [diff] [blame] | 3533 | .test = alg_test_aead, |
| 3534 | .suite = { |
| 3535 | .aead = { |
| 3536 | .enc = { |
| 3537 | .vecs = aes_gcm_rfc4543_enc_tv_template, |
| 3538 | .count = AES_GCM_4543_ENC_TEST_VECTORS |
| 3539 | }, |
| 3540 | .dec = { |
| 3541 | .vecs = aes_gcm_rfc4543_dec_tv_template, |
| 3542 | .count = AES_GCM_4543_DEC_TEST_VECTORS |
| 3543 | }, |
| 3544 | } |
| 3545 | } |
| 3546 | }, { |
Martin Willi | af2b76b | 2015-06-01 13:44:01 +0200 | [diff] [blame] | 3547 | .alg = "rfc7539(chacha20,poly1305)", |
| 3548 | .test = alg_test_aead, |
| 3549 | .suite = { |
| 3550 | .aead = { |
| 3551 | .enc = { |
| 3552 | .vecs = rfc7539_enc_tv_template, |
| 3553 | .count = RFC7539_ENC_TEST_VECTORS |
| 3554 | }, |
| 3555 | .dec = { |
| 3556 | .vecs = rfc7539_dec_tv_template, |
| 3557 | .count = RFC7539_DEC_TEST_VECTORS |
| 3558 | }, |
| 3559 | } |
| 3560 | } |
| 3561 | }, { |
Martin Willi | 5900758 | 2015-06-01 13:44:03 +0200 | [diff] [blame] | 3562 | .alg = "rfc7539esp(chacha20,poly1305)", |
| 3563 | .test = alg_test_aead, |
| 3564 | .suite = { |
| 3565 | .aead = { |
| 3566 | .enc = { |
| 3567 | .vecs = rfc7539esp_enc_tv_template, |
| 3568 | .count = RFC7539ESP_ENC_TEST_VECTORS |
| 3569 | }, |
| 3570 | .dec = { |
| 3571 | .vecs = rfc7539esp_dec_tv_template, |
| 3572 | .count = RFC7539ESP_DEC_TEST_VECTORS |
| 3573 | }, |
| 3574 | } |
| 3575 | } |
| 3576 | }, { |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 3577 | .alg = "rmd128", |
| 3578 | .test = alg_test_hash, |
| 3579 | .suite = { |
| 3580 | .hash = { |
| 3581 | .vecs = rmd128_tv_template, |
| 3582 | .count = RMD128_TEST_VECTORS |
| 3583 | } |
| 3584 | } |
| 3585 | }, { |
| 3586 | .alg = "rmd160", |
| 3587 | .test = alg_test_hash, |
| 3588 | .suite = { |
| 3589 | .hash = { |
| 3590 | .vecs = rmd160_tv_template, |
| 3591 | .count = RMD160_TEST_VECTORS |
| 3592 | } |
| 3593 | } |
| 3594 | }, { |
| 3595 | .alg = "rmd256", |
| 3596 | .test = alg_test_hash, |
| 3597 | .suite = { |
| 3598 | .hash = { |
| 3599 | .vecs = rmd256_tv_template, |
| 3600 | .count = RMD256_TEST_VECTORS |
| 3601 | } |
| 3602 | } |
| 3603 | }, { |
| 3604 | .alg = "rmd320", |
| 3605 | .test = alg_test_hash, |
| 3606 | .suite = { |
| 3607 | .hash = { |
| 3608 | .vecs = rmd320_tv_template, |
| 3609 | .count = RMD320_TEST_VECTORS |
| 3610 | } |
| 3611 | } |
| 3612 | }, { |
Tadeusz Struk | 946cc46 | 2015-06-16 10:31:06 -0700 | [diff] [blame] | 3613 | .alg = "rsa", |
| 3614 | .test = alg_test_akcipher, |
| 3615 | .fips_allowed = 1, |
| 3616 | .suite = { |
| 3617 | .akcipher = { |
| 3618 | .vecs = rsa_tv_template, |
| 3619 | .count = RSA_TEST_VECTORS |
| 3620 | } |
| 3621 | } |
| 3622 | }, { |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 3623 | .alg = "salsa20", |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 3624 | .test = alg_test_skcipher, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 3625 | .suite = { |
| 3626 | .cipher = { |
| 3627 | .enc = { |
| 3628 | .vecs = salsa20_stream_enc_tv_template, |
| 3629 | .count = SALSA20_STREAM_ENC_TEST_VECTORS |
| 3630 | } |
| 3631 | } |
| 3632 | } |
| 3633 | }, { |
| 3634 | .alg = "sha1", |
| 3635 | .test = alg_test_hash, |
Jarod Wilson | a1915d5 | 2009-05-15 15:16:03 +1000 | [diff] [blame] | 3636 | .fips_allowed = 1, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 3637 | .suite = { |
| 3638 | .hash = { |
| 3639 | .vecs = sha1_tv_template, |
| 3640 | .count = SHA1_TEST_VECTORS |
| 3641 | } |
| 3642 | } |
| 3643 | }, { |
| 3644 | .alg = "sha224", |
| 3645 | .test = alg_test_hash, |
Jarod Wilson | a1915d5 | 2009-05-15 15:16:03 +1000 | [diff] [blame] | 3646 | .fips_allowed = 1, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 3647 | .suite = { |
| 3648 | .hash = { |
| 3649 | .vecs = sha224_tv_template, |
| 3650 | .count = SHA224_TEST_VECTORS |
| 3651 | } |
| 3652 | } |
| 3653 | }, { |
| 3654 | .alg = "sha256", |
| 3655 | .test = alg_test_hash, |
Jarod Wilson | a1915d5 | 2009-05-15 15:16:03 +1000 | [diff] [blame] | 3656 | .fips_allowed = 1, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 3657 | .suite = { |
| 3658 | .hash = { |
| 3659 | .vecs = sha256_tv_template, |
| 3660 | .count = SHA256_TEST_VECTORS |
| 3661 | } |
| 3662 | } |
| 3663 | }, { |
| 3664 | .alg = "sha384", |
| 3665 | .test = alg_test_hash, |
Jarod Wilson | a1915d5 | 2009-05-15 15:16:03 +1000 | [diff] [blame] | 3666 | .fips_allowed = 1, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 3667 | .suite = { |
| 3668 | .hash = { |
| 3669 | .vecs = sha384_tv_template, |
| 3670 | .count = SHA384_TEST_VECTORS |
| 3671 | } |
| 3672 | } |
| 3673 | }, { |
| 3674 | .alg = "sha512", |
| 3675 | .test = alg_test_hash, |
Jarod Wilson | a1915d5 | 2009-05-15 15:16:03 +1000 | [diff] [blame] | 3676 | .fips_allowed = 1, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 3677 | .suite = { |
| 3678 | .hash = { |
| 3679 | .vecs = sha512_tv_template, |
| 3680 | .count = SHA512_TEST_VECTORS |
| 3681 | } |
| 3682 | } |
| 3683 | }, { |
| 3684 | .alg = "tgr128", |
| 3685 | .test = alg_test_hash, |
| 3686 | .suite = { |
| 3687 | .hash = { |
| 3688 | .vecs = tgr128_tv_template, |
| 3689 | .count = TGR128_TEST_VECTORS |
| 3690 | } |
| 3691 | } |
| 3692 | }, { |
| 3693 | .alg = "tgr160", |
| 3694 | .test = alg_test_hash, |
| 3695 | .suite = { |
| 3696 | .hash = { |
| 3697 | .vecs = tgr160_tv_template, |
| 3698 | .count = TGR160_TEST_VECTORS |
| 3699 | } |
| 3700 | } |
| 3701 | }, { |
| 3702 | .alg = "tgr192", |
| 3703 | .test = alg_test_hash, |
| 3704 | .suite = { |
| 3705 | .hash = { |
| 3706 | .vecs = tgr192_tv_template, |
| 3707 | .count = TGR192_TEST_VECTORS |
| 3708 | } |
| 3709 | } |
| 3710 | }, { |
Shane Wang | f1939f7 | 2009-09-02 20:05:22 +1000 | [diff] [blame] | 3711 | .alg = "vmac(aes)", |
| 3712 | .test = alg_test_hash, |
| 3713 | .suite = { |
| 3714 | .hash = { |
| 3715 | .vecs = aes_vmac128_tv_template, |
| 3716 | .count = VMAC_AES_TEST_VECTORS |
| 3717 | } |
| 3718 | } |
| 3719 | }, { |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 3720 | .alg = "wp256", |
| 3721 | .test = alg_test_hash, |
| 3722 | .suite = { |
| 3723 | .hash = { |
| 3724 | .vecs = wp256_tv_template, |
| 3725 | .count = WP256_TEST_VECTORS |
| 3726 | } |
| 3727 | } |
| 3728 | }, { |
| 3729 | .alg = "wp384", |
| 3730 | .test = alg_test_hash, |
| 3731 | .suite = { |
| 3732 | .hash = { |
| 3733 | .vecs = wp384_tv_template, |
| 3734 | .count = WP384_TEST_VECTORS |
| 3735 | } |
| 3736 | } |
| 3737 | }, { |
| 3738 | .alg = "wp512", |
| 3739 | .test = alg_test_hash, |
| 3740 | .suite = { |
| 3741 | .hash = { |
| 3742 | .vecs = wp512_tv_template, |
| 3743 | .count = WP512_TEST_VECTORS |
| 3744 | } |
| 3745 | } |
| 3746 | }, { |
| 3747 | .alg = "xcbc(aes)", |
| 3748 | .test = alg_test_hash, |
| 3749 | .suite = { |
| 3750 | .hash = { |
| 3751 | .vecs = aes_xcbc128_tv_template, |
| 3752 | .count = XCBC_AES_TEST_VECTORS |
| 3753 | } |
| 3754 | } |
| 3755 | }, { |
| 3756 | .alg = "xts(aes)", |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 3757 | .test = alg_test_skcipher, |
Jarod Wilson | 2918aa8 | 2011-01-29 15:14:01 +1100 | [diff] [blame] | 3758 | .fips_allowed = 1, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 3759 | .suite = { |
| 3760 | .cipher = { |
| 3761 | .enc = { |
| 3762 | .vecs = aes_xts_enc_tv_template, |
| 3763 | .count = AES_XTS_ENC_TEST_VECTORS |
| 3764 | }, |
| 3765 | .dec = { |
| 3766 | .vecs = aes_xts_dec_tv_template, |
| 3767 | .count = AES_XTS_DEC_TEST_VECTORS |
| 3768 | } |
| 3769 | } |
| 3770 | } |
Geert Uytterhoeven | 0c01aed | 2009-03-04 15:42:15 +0800 | [diff] [blame] | 3771 | }, { |
Jussi Kivilinna | 0840605 | 2012-03-05 20:26:21 +0200 | [diff] [blame] | 3772 | .alg = "xts(camellia)", |
| 3773 | .test = alg_test_skcipher, |
| 3774 | .suite = { |
| 3775 | .cipher = { |
| 3776 | .enc = { |
| 3777 | .vecs = camellia_xts_enc_tv_template, |
| 3778 | .count = CAMELLIA_XTS_ENC_TEST_VECTORS |
| 3779 | }, |
| 3780 | .dec = { |
| 3781 | .vecs = camellia_xts_dec_tv_template, |
| 3782 | .count = CAMELLIA_XTS_DEC_TEST_VECTORS |
| 3783 | } |
| 3784 | } |
| 3785 | } |
| 3786 | }, { |
Johannes Goetzfried | 9b8b040 | 2012-07-11 19:38:29 +0200 | [diff] [blame] | 3787 | .alg = "xts(cast6)", |
| 3788 | .test = alg_test_skcipher, |
| 3789 | .suite = { |
| 3790 | .cipher = { |
| 3791 | .enc = { |
| 3792 | .vecs = cast6_xts_enc_tv_template, |
| 3793 | .count = CAST6_XTS_ENC_TEST_VECTORS |
| 3794 | }, |
| 3795 | .dec = { |
| 3796 | .vecs = cast6_xts_dec_tv_template, |
| 3797 | .count = CAST6_XTS_DEC_TEST_VECTORS |
| 3798 | } |
| 3799 | } |
| 3800 | } |
| 3801 | }, { |
Jussi Kivilinna | 18be20b9 | 2011-10-18 13:33:17 +0300 | [diff] [blame] | 3802 | .alg = "xts(serpent)", |
| 3803 | .test = alg_test_skcipher, |
| 3804 | .suite = { |
| 3805 | .cipher = { |
| 3806 | .enc = { |
| 3807 | .vecs = serpent_xts_enc_tv_template, |
| 3808 | .count = SERPENT_XTS_ENC_TEST_VECTORS |
| 3809 | }, |
| 3810 | .dec = { |
| 3811 | .vecs = serpent_xts_dec_tv_template, |
| 3812 | .count = SERPENT_XTS_DEC_TEST_VECTORS |
| 3813 | } |
| 3814 | } |
| 3815 | } |
| 3816 | }, { |
Jussi Kivilinna | aed265b | 2011-10-18 13:33:33 +0300 | [diff] [blame] | 3817 | .alg = "xts(twofish)", |
| 3818 | .test = alg_test_skcipher, |
| 3819 | .suite = { |
| 3820 | .cipher = { |
| 3821 | .enc = { |
| 3822 | .vecs = tf_xts_enc_tv_template, |
| 3823 | .count = TF_XTS_ENC_TEST_VECTORS |
| 3824 | }, |
| 3825 | .dec = { |
| 3826 | .vecs = tf_xts_dec_tv_template, |
| 3827 | .count = TF_XTS_DEC_TEST_VECTORS |
| 3828 | } |
| 3829 | } |
| 3830 | } |
| 3831 | }, { |
Geert Uytterhoeven | 0c01aed | 2009-03-04 15:42:15 +0800 | [diff] [blame] | 3832 | .alg = "zlib", |
| 3833 | .test = alg_test_pcomp, |
Milan Broz | 0818904 | 2012-12-06 17:16:28 +0800 | [diff] [blame] | 3834 | .fips_allowed = 1, |
Geert Uytterhoeven | 0c01aed | 2009-03-04 15:42:15 +0800 | [diff] [blame] | 3835 | .suite = { |
| 3836 | .pcomp = { |
| 3837 | .comp = { |
| 3838 | .vecs = zlib_comp_tv_template, |
| 3839 | .count = ZLIB_COMP_TEST_VECTORS |
| 3840 | }, |
| 3841 | .decomp = { |
| 3842 | .vecs = zlib_decomp_tv_template, |
| 3843 | .count = ZLIB_DECOMP_TEST_VECTORS |
| 3844 | } |
| 3845 | } |
| 3846 | } |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 3847 | } |
| 3848 | }; |
| 3849 | |
Jussi Kivilinna | 5714758 | 2013-06-13 17:37:40 +0300 | [diff] [blame] | 3850 | static bool alg_test_descs_checked; |
| 3851 | |
| 3852 | static void alg_test_descs_check_order(void) |
| 3853 | { |
| 3854 | int i; |
| 3855 | |
| 3856 | /* only check once */ |
| 3857 | if (alg_test_descs_checked) |
| 3858 | return; |
| 3859 | |
| 3860 | alg_test_descs_checked = true; |
| 3861 | |
| 3862 | for (i = 1; i < ARRAY_SIZE(alg_test_descs); i++) { |
| 3863 | int diff = strcmp(alg_test_descs[i - 1].alg, |
| 3864 | alg_test_descs[i].alg); |
| 3865 | |
| 3866 | if (WARN_ON(diff > 0)) { |
| 3867 | pr_warn("testmgr: alg_test_descs entries in wrong order: '%s' before '%s'\n", |
| 3868 | alg_test_descs[i - 1].alg, |
| 3869 | alg_test_descs[i].alg); |
| 3870 | } |
| 3871 | |
| 3872 | if (WARN_ON(diff == 0)) { |
| 3873 | pr_warn("testmgr: duplicate alg_test_descs entry: '%s'\n", |
| 3874 | alg_test_descs[i].alg); |
| 3875 | } |
| 3876 | } |
| 3877 | } |
| 3878 | |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 3879 | static int alg_find_test(const char *alg) |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 3880 | { |
| 3881 | int start = 0; |
| 3882 | int end = ARRAY_SIZE(alg_test_descs); |
| 3883 | |
| 3884 | while (start < end) { |
| 3885 | int i = (start + end) / 2; |
| 3886 | int diff = strcmp(alg_test_descs[i].alg, alg); |
| 3887 | |
| 3888 | if (diff > 0) { |
| 3889 | end = i; |
| 3890 | continue; |
| 3891 | } |
| 3892 | |
| 3893 | if (diff < 0) { |
| 3894 | start = i + 1; |
| 3895 | continue; |
| 3896 | } |
| 3897 | |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 3898 | return i; |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 3899 | } |
| 3900 | |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 3901 | return -1; |
| 3902 | } |
| 3903 | |
| 3904 | int alg_test(const char *driver, const char *alg, u32 type, u32 mask) |
| 3905 | { |
| 3906 | int i; |
Herbert Xu | a68f661 | 2009-07-02 16:32:12 +0800 | [diff] [blame] | 3907 | int j; |
Neil Horman | d12d6b6 | 2008-10-12 20:36:51 +0800 | [diff] [blame] | 3908 | int rc; |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 3909 | |
Jussi Kivilinna | 5714758 | 2013-06-13 17:37:40 +0300 | [diff] [blame] | 3910 | alg_test_descs_check_order(); |
| 3911 | |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 3912 | if ((type & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_CIPHER) { |
| 3913 | char nalg[CRYPTO_MAX_ALG_NAME]; |
| 3914 | |
| 3915 | if (snprintf(nalg, sizeof(nalg), "ecb(%s)", alg) >= |
| 3916 | sizeof(nalg)) |
| 3917 | return -ENAMETOOLONG; |
| 3918 | |
| 3919 | i = alg_find_test(nalg); |
| 3920 | if (i < 0) |
| 3921 | goto notest; |
| 3922 | |
Jarod Wilson | a3bef3a | 2009-05-15 15:17:05 +1000 | [diff] [blame] | 3923 | if (fips_enabled && !alg_test_descs[i].fips_allowed) |
| 3924 | goto non_fips_alg; |
| 3925 | |
Jarod Wilson | 941fb32 | 2009-05-04 19:49:23 +0800 | [diff] [blame] | 3926 | rc = alg_test_cipher(alg_test_descs + i, driver, type, mask); |
| 3927 | goto test_done; |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 3928 | } |
| 3929 | |
| 3930 | i = alg_find_test(alg); |
Herbert Xu | a68f661 | 2009-07-02 16:32:12 +0800 | [diff] [blame] | 3931 | j = alg_find_test(driver); |
| 3932 | if (i < 0 && j < 0) |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 3933 | goto notest; |
| 3934 | |
Herbert Xu | a68f661 | 2009-07-02 16:32:12 +0800 | [diff] [blame] | 3935 | if (fips_enabled && ((i >= 0 && !alg_test_descs[i].fips_allowed) || |
| 3936 | (j >= 0 && !alg_test_descs[j].fips_allowed))) |
Jarod Wilson | a3bef3a | 2009-05-15 15:17:05 +1000 | [diff] [blame] | 3937 | goto non_fips_alg; |
| 3938 | |
Herbert Xu | a68f661 | 2009-07-02 16:32:12 +0800 | [diff] [blame] | 3939 | rc = 0; |
| 3940 | if (i >= 0) |
| 3941 | rc |= alg_test_descs[i].test(alg_test_descs + i, driver, |
| 3942 | type, mask); |
Cristian Stoica | 032c8ca | 2013-07-18 18:57:07 +0300 | [diff] [blame] | 3943 | if (j >= 0 && j != i) |
Herbert Xu | a68f661 | 2009-07-02 16:32:12 +0800 | [diff] [blame] | 3944 | rc |= alg_test_descs[j].test(alg_test_descs + j, driver, |
| 3945 | type, mask); |
| 3946 | |
Jarod Wilson | 941fb32 | 2009-05-04 19:49:23 +0800 | [diff] [blame] | 3947 | test_done: |
Neil Horman | d12d6b6 | 2008-10-12 20:36:51 +0800 | [diff] [blame] | 3948 | if (fips_enabled && rc) |
| 3949 | panic("%s: %s alg self test failed in fips mode!\n", driver, alg); |
| 3950 | |
Jarod Wilson | 29ecd4a | 2009-05-04 19:51:17 +0800 | [diff] [blame] | 3951 | if (fips_enabled && !rc) |
Masanari Iida | 3e8cffd | 2014-10-07 00:37:54 +0900 | [diff] [blame] | 3952 | pr_info("alg: self-tests for %s (%s) passed\n", driver, alg); |
Jarod Wilson | 29ecd4a | 2009-05-04 19:51:17 +0800 | [diff] [blame] | 3953 | |
Neil Horman | d12d6b6 | 2008-10-12 20:36:51 +0800 | [diff] [blame] | 3954 | return rc; |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 3955 | |
| 3956 | notest: |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 3957 | printk(KERN_INFO "alg: No test for %s (%s)\n", alg, driver); |
| 3958 | return 0; |
Jarod Wilson | a3bef3a | 2009-05-15 15:17:05 +1000 | [diff] [blame] | 3959 | non_fips_alg: |
| 3960 | return -EINVAL; |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 3961 | } |
Alexander Shishkin | 0b767f9 | 2010-06-03 20:53:43 +1000 | [diff] [blame] | 3962 | |
Herbert Xu | 326a634 | 2010-08-06 09:40:28 +0800 | [diff] [blame] | 3963 | #endif /* CONFIG_CRYPTO_MANAGER_DISABLE_TESTS */ |
Alexander Shishkin | 0b767f9 | 2010-06-03 20:53:43 +1000 | [diff] [blame] | 3964 | |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 3965 | EXPORT_SYMBOL_GPL(alg_test); |