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