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