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