1da7f033dSHerbert Xu /* 2da7f033dSHerbert Xu * Algorithm testing framework and tests. 3da7f033dSHerbert Xu * 4da7f033dSHerbert Xu * Copyright (c) 2002 James Morris <jmorris@intercode.com.au> 5da7f033dSHerbert Xu * Copyright (c) 2002 Jean-Francois Dive <jef@linuxbe.org> 6da7f033dSHerbert Xu * Copyright (c) 2007 Nokia Siemens Networks 7da7f033dSHerbert Xu * Copyright (c) 2008 Herbert Xu <herbert@gondor.apana.org.au> 8da7f033dSHerbert Xu * 969435b94SAdrian Hoban * Updated RFC4106 AES-GCM testing. 1069435b94SAdrian Hoban * Authors: Aidan O'Mahony (aidan.o.mahony@intel.com) 1169435b94SAdrian Hoban * Adrian Hoban <adrian.hoban@intel.com> 1269435b94SAdrian Hoban * Gabriele Paoloni <gabriele.paoloni@intel.com> 1369435b94SAdrian Hoban * Tadeusz Struk (tadeusz.struk@intel.com) 1469435b94SAdrian Hoban * Copyright (c) 2010, Intel Corporation. 1569435b94SAdrian Hoban * 16da7f033dSHerbert Xu * This program is free software; you can redistribute it and/or modify it 17da7f033dSHerbert Xu * under the terms of the GNU General Public License as published by the Free 18da7f033dSHerbert Xu * Software Foundation; either version 2 of the License, or (at your option) 19da7f033dSHerbert Xu * any later version. 20da7f033dSHerbert Xu * 21da7f033dSHerbert Xu */ 22da7f033dSHerbert Xu 231ce33115SHerbert Xu #include <crypto/aead.h> 24da7f033dSHerbert Xu #include <crypto/hash.h> 2512773d93SHerbert Xu #include <crypto/skcipher.h> 26da7f033dSHerbert Xu #include <linux/err.h> 271c41b882SHerbert Xu #include <linux/fips.h> 28da7f033dSHerbert Xu #include <linux/module.h> 29da7f033dSHerbert Xu #include <linux/scatterlist.h> 30da7f033dSHerbert Xu #include <linux/slab.h> 31da7f033dSHerbert Xu #include <linux/string.h> 327647d6ceSJarod Wilson #include <crypto/rng.h> 3364d1cdfbSStephan Mueller #include <crypto/drbg.h> 34946cc463STadeusz Struk #include <crypto/akcipher.h> 35802c7f1cSSalvatore Benedetto #include <crypto/kpp.h> 36d7db7a88SGiovanni Cabiddu #include <crypto/acompress.h> 37da7f033dSHerbert Xu 38da7f033dSHerbert Xu #include "internal.h" 390b767f96SAlexander Shishkin 409e5c9fe4SRichard W.M. Jones static bool notests; 419e5c9fe4SRichard W.M. Jones module_param(notests, bool, 0644); 429e5c9fe4SRichard W.M. Jones MODULE_PARM_DESC(notests, "disable crypto self-tests"); 439e5c9fe4SRichard W.M. Jones 44326a6346SHerbert Xu #ifdef CONFIG_CRYPTO_MANAGER_DISABLE_TESTS 450b767f96SAlexander Shishkin 460b767f96SAlexander Shishkin /* a perfect nop */ 470b767f96SAlexander Shishkin int alg_test(const char *driver, const char *alg, u32 type, u32 mask) 480b767f96SAlexander Shishkin { 490b767f96SAlexander Shishkin return 0; 500b767f96SAlexander Shishkin } 510b767f96SAlexander Shishkin 520b767f96SAlexander Shishkin #else 530b767f96SAlexander Shishkin 54da7f033dSHerbert Xu #include "testmgr.h" 55da7f033dSHerbert Xu 56da7f033dSHerbert Xu /* 57da7f033dSHerbert Xu * Need slab memory for testing (size in number of pages). 58da7f033dSHerbert Xu */ 59da7f033dSHerbert Xu #define XBUFSIZE 8 60da7f033dSHerbert Xu 61da7f033dSHerbert Xu /* 62da7f033dSHerbert Xu * Indexes into the xbuf to simulate cross-page access. 63da7f033dSHerbert Xu */ 64da7f033dSHerbert Xu #define IDX1 32 65da7f033dSHerbert Xu #define IDX2 32400 6604b46fbdSArd Biesheuvel #define IDX3 1511 67da7f033dSHerbert Xu #define IDX4 8193 68da7f033dSHerbert Xu #define IDX5 22222 69da7f033dSHerbert Xu #define IDX6 17101 70da7f033dSHerbert Xu #define IDX7 27333 71da7f033dSHerbert Xu #define IDX8 3000 72da7f033dSHerbert Xu 73da7f033dSHerbert Xu /* 74da7f033dSHerbert Xu * Used by test_cipher() 75da7f033dSHerbert Xu */ 76da7f033dSHerbert Xu #define ENCRYPT 1 77da7f033dSHerbert Xu #define DECRYPT 0 78da7f033dSHerbert Xu 79da7f033dSHerbert Xu struct aead_test_suite { 80da7f033dSHerbert Xu struct { 81b13b1e0cSEric Biggers const struct aead_testvec *vecs; 82da7f033dSHerbert Xu unsigned int count; 83da7f033dSHerbert Xu } enc, dec; 84da7f033dSHerbert Xu }; 85da7f033dSHerbert Xu 86da7f033dSHerbert Xu struct cipher_test_suite { 87da7f033dSHerbert Xu struct { 88b13b1e0cSEric Biggers const struct cipher_testvec *vecs; 89da7f033dSHerbert Xu unsigned int count; 90da7f033dSHerbert Xu } enc, dec; 91da7f033dSHerbert Xu }; 92da7f033dSHerbert Xu 93da7f033dSHerbert Xu struct comp_test_suite { 94da7f033dSHerbert Xu struct { 95b13b1e0cSEric Biggers const struct comp_testvec *vecs; 96da7f033dSHerbert Xu unsigned int count; 97da7f033dSHerbert Xu } comp, decomp; 98da7f033dSHerbert Xu }; 99da7f033dSHerbert Xu 100da7f033dSHerbert Xu struct hash_test_suite { 101b13b1e0cSEric Biggers const struct hash_testvec *vecs; 102da7f033dSHerbert Xu unsigned int count; 103da7f033dSHerbert Xu }; 104da7f033dSHerbert Xu 1057647d6ceSJarod Wilson struct cprng_test_suite { 106b13b1e0cSEric Biggers const struct cprng_testvec *vecs; 1077647d6ceSJarod Wilson unsigned int count; 1087647d6ceSJarod Wilson }; 1097647d6ceSJarod Wilson 11064d1cdfbSStephan Mueller struct drbg_test_suite { 111b13b1e0cSEric Biggers const struct drbg_testvec *vecs; 11264d1cdfbSStephan Mueller unsigned int count; 11364d1cdfbSStephan Mueller }; 11464d1cdfbSStephan Mueller 115946cc463STadeusz Struk struct akcipher_test_suite { 116b13b1e0cSEric Biggers const struct akcipher_testvec *vecs; 117946cc463STadeusz Struk unsigned int count; 118946cc463STadeusz Struk }; 119946cc463STadeusz Struk 120802c7f1cSSalvatore Benedetto struct kpp_test_suite { 121b13b1e0cSEric Biggers const struct kpp_testvec *vecs; 122802c7f1cSSalvatore Benedetto unsigned int count; 123802c7f1cSSalvatore Benedetto }; 124802c7f1cSSalvatore Benedetto 125da7f033dSHerbert Xu struct alg_test_desc { 126da7f033dSHerbert Xu const char *alg; 127da7f033dSHerbert Xu int (*test)(const struct alg_test_desc *desc, const char *driver, 128da7f033dSHerbert Xu u32 type, u32 mask); 129a1915d51SJarod Wilson int fips_allowed; /* set if alg is allowed in fips mode */ 130da7f033dSHerbert Xu 131da7f033dSHerbert Xu union { 132da7f033dSHerbert Xu struct aead_test_suite aead; 133da7f033dSHerbert Xu struct cipher_test_suite cipher; 134da7f033dSHerbert Xu struct comp_test_suite comp; 135da7f033dSHerbert Xu struct hash_test_suite hash; 1367647d6ceSJarod Wilson struct cprng_test_suite cprng; 13764d1cdfbSStephan Mueller struct drbg_test_suite drbg; 138946cc463STadeusz Struk struct akcipher_test_suite akcipher; 139802c7f1cSSalvatore Benedetto struct kpp_test_suite kpp; 140da7f033dSHerbert Xu } suite; 141da7f033dSHerbert Xu }; 142da7f033dSHerbert Xu 143b13b1e0cSEric Biggers static const unsigned int IDX[8] = { 144b13b1e0cSEric Biggers IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 }; 145da7f033dSHerbert Xu 146da7f033dSHerbert Xu static void hexdump(unsigned char *buf, unsigned int len) 147da7f033dSHerbert Xu { 148da7f033dSHerbert Xu print_hex_dump(KERN_CONT, "", DUMP_PREFIX_OFFSET, 149da7f033dSHerbert Xu 16, 1, 150da7f033dSHerbert Xu buf, len, false); 151da7f033dSHerbert Xu } 152da7f033dSHerbert Xu 153f8b0d4d0SHerbert Xu static int testmgr_alloc_buf(char *buf[XBUFSIZE]) 154f8b0d4d0SHerbert Xu { 155f8b0d4d0SHerbert Xu int i; 156f8b0d4d0SHerbert Xu 157f8b0d4d0SHerbert Xu for (i = 0; i < XBUFSIZE; i++) { 158f8b0d4d0SHerbert Xu buf[i] = (void *)__get_free_page(GFP_KERNEL); 159f8b0d4d0SHerbert Xu if (!buf[i]) 160f8b0d4d0SHerbert Xu goto err_free_buf; 161f8b0d4d0SHerbert Xu } 162f8b0d4d0SHerbert Xu 163f8b0d4d0SHerbert Xu return 0; 164f8b0d4d0SHerbert Xu 165f8b0d4d0SHerbert Xu err_free_buf: 166f8b0d4d0SHerbert Xu while (i-- > 0) 167f8b0d4d0SHerbert Xu free_page((unsigned long)buf[i]); 168f8b0d4d0SHerbert Xu 169f8b0d4d0SHerbert Xu return -ENOMEM; 170f8b0d4d0SHerbert Xu } 171f8b0d4d0SHerbert Xu 172f8b0d4d0SHerbert Xu static void testmgr_free_buf(char *buf[XBUFSIZE]) 173f8b0d4d0SHerbert Xu { 174f8b0d4d0SHerbert Xu int i; 175f8b0d4d0SHerbert Xu 176f8b0d4d0SHerbert Xu for (i = 0; i < XBUFSIZE; i++) 177f8b0d4d0SHerbert Xu free_page((unsigned long)buf[i]); 178f8b0d4d0SHerbert Xu } 179f8b0d4d0SHerbert Xu 180466d7b9fSKamil Konieczny static int ahash_guard_result(char *result, char c, int size) 181466d7b9fSKamil Konieczny { 182466d7b9fSKamil Konieczny int i; 183466d7b9fSKamil Konieczny 184466d7b9fSKamil Konieczny for (i = 0; i < size; i++) { 185466d7b9fSKamil Konieczny if (result[i] != c) 186466d7b9fSKamil Konieczny return -EINVAL; 187466d7b9fSKamil Konieczny } 188466d7b9fSKamil Konieczny 189466d7b9fSKamil Konieczny return 0; 190466d7b9fSKamil Konieczny } 191466d7b9fSKamil Konieczny 192018ba95cSWang, Rui Y static int ahash_partial_update(struct ahash_request **preq, 193b13b1e0cSEric Biggers struct crypto_ahash *tfm, const struct hash_testvec *template, 194018ba95cSWang, Rui Y void *hash_buff, int k, int temp, struct scatterlist *sg, 1957f397136SGilad Ben-Yossef const char *algo, char *result, struct crypto_wait *wait) 196018ba95cSWang, Rui Y { 197018ba95cSWang, Rui Y char *state; 198018ba95cSWang, Rui Y struct ahash_request *req; 199018ba95cSWang, Rui Y int statesize, ret = -EINVAL; 200da1729ceSJoey Pabalinas static const unsigned char guard[] = { 0x00, 0xba, 0xad, 0x00 }; 201466d7b9fSKamil Konieczny int digestsize = crypto_ahash_digestsize(tfm); 202018ba95cSWang, Rui Y 203018ba95cSWang, Rui Y req = *preq; 204018ba95cSWang, Rui Y statesize = crypto_ahash_statesize( 205018ba95cSWang, Rui Y crypto_ahash_reqtfm(req)); 2067bcb87bcSJan Stancek state = kmalloc(statesize + sizeof(guard), GFP_KERNEL); 207018ba95cSWang, Rui Y if (!state) { 208cf3f9609SGilad Ben-Yossef pr_err("alg: hash: Failed to alloc state for %s\n", algo); 209018ba95cSWang, Rui Y goto out_nostate; 210018ba95cSWang, Rui Y } 2117bcb87bcSJan Stancek memcpy(state + statesize, guard, sizeof(guard)); 212466d7b9fSKamil Konieczny memset(result, 1, digestsize); 213018ba95cSWang, Rui Y ret = crypto_ahash_export(req, state); 2147bcb87bcSJan Stancek WARN_ON(memcmp(state + statesize, guard, sizeof(guard))); 215018ba95cSWang, Rui Y if (ret) { 216cf3f9609SGilad Ben-Yossef pr_err("alg: hash: Failed to export() for %s\n", algo); 217018ba95cSWang, Rui Y goto out; 218018ba95cSWang, Rui Y } 219466d7b9fSKamil Konieczny ret = ahash_guard_result(result, 1, digestsize); 220466d7b9fSKamil Konieczny if (ret) { 221466d7b9fSKamil Konieczny pr_err("alg: hash: Failed, export used req->result for %s\n", 222466d7b9fSKamil Konieczny algo); 223466d7b9fSKamil Konieczny goto out; 224466d7b9fSKamil Konieczny } 225018ba95cSWang, Rui Y ahash_request_free(req); 226018ba95cSWang, Rui Y req = ahash_request_alloc(tfm, GFP_KERNEL); 227018ba95cSWang, Rui Y if (!req) { 228018ba95cSWang, Rui Y pr_err("alg: hash: Failed to alloc request for %s\n", algo); 229018ba95cSWang, Rui Y goto out_noreq; 230018ba95cSWang, Rui Y } 231018ba95cSWang, Rui Y ahash_request_set_callback(req, 232018ba95cSWang, Rui Y CRYPTO_TFM_REQ_MAY_BACKLOG, 2337f397136SGilad Ben-Yossef crypto_req_done, wait); 234018ba95cSWang, Rui Y 235018ba95cSWang, Rui Y memcpy(hash_buff, template->plaintext + temp, 236018ba95cSWang, Rui Y template->tap[k]); 237018ba95cSWang, Rui Y sg_init_one(&sg[0], hash_buff, template->tap[k]); 238018ba95cSWang, Rui Y ahash_request_set_crypt(req, sg, result, template->tap[k]); 239018ba95cSWang, Rui Y ret = crypto_ahash_import(req, state); 240018ba95cSWang, Rui Y if (ret) { 241018ba95cSWang, Rui Y pr_err("alg: hash: Failed to import() for %s\n", algo); 242018ba95cSWang, Rui Y goto out; 243018ba95cSWang, Rui Y } 244466d7b9fSKamil Konieczny ret = ahash_guard_result(result, 1, digestsize); 245466d7b9fSKamil Konieczny if (ret) { 246466d7b9fSKamil Konieczny pr_err("alg: hash: Failed, import used req->result for %s\n", 247466d7b9fSKamil Konieczny algo); 248466d7b9fSKamil Konieczny goto out; 249466d7b9fSKamil Konieczny } 2507f397136SGilad Ben-Yossef ret = crypto_wait_req(crypto_ahash_update(req), wait); 251018ba95cSWang, Rui Y if (ret) 252018ba95cSWang, Rui Y goto out; 253018ba95cSWang, Rui Y *preq = req; 254018ba95cSWang, Rui Y ret = 0; 255018ba95cSWang, Rui Y goto out_noreq; 256018ba95cSWang, Rui Y out: 257018ba95cSWang, Rui Y ahash_request_free(req); 258018ba95cSWang, Rui Y out_noreq: 259018ba95cSWang, Rui Y kfree(state); 260018ba95cSWang, Rui Y out_nostate: 261018ba95cSWang, Rui Y return ret; 262018ba95cSWang, Rui Y } 263018ba95cSWang, Rui Y 264b13b1e0cSEric Biggers static int __test_hash(struct crypto_ahash *tfm, 265b13b1e0cSEric Biggers const struct hash_testvec *template, unsigned int tcount, 266b13b1e0cSEric Biggers bool use_digest, const int align_offset) 267da7f033dSHerbert Xu { 268da7f033dSHerbert Xu const char *algo = crypto_tfm_alg_driver_name(crypto_ahash_tfm(tfm)); 269e93acd6fSAndrew Lutomirski size_t digest_size = crypto_ahash_digestsize(tfm); 270da7f033dSHerbert Xu unsigned int i, j, k, temp; 271da7f033dSHerbert Xu struct scatterlist sg[8]; 27229b77e5dSHoria Geanta char *result; 27329b77e5dSHoria Geanta char *key; 274da7f033dSHerbert Xu struct ahash_request *req; 2757f397136SGilad Ben-Yossef struct crypto_wait wait; 276da7f033dSHerbert Xu void *hash_buff; 277f8b0d4d0SHerbert Xu char *xbuf[XBUFSIZE]; 278f8b0d4d0SHerbert Xu int ret = -ENOMEM; 279f8b0d4d0SHerbert Xu 280e93acd6fSAndrew Lutomirski result = kmalloc(digest_size, GFP_KERNEL); 28129b77e5dSHoria Geanta if (!result) 28229b77e5dSHoria Geanta return ret; 28329b77e5dSHoria Geanta key = kmalloc(MAX_KEYLEN, GFP_KERNEL); 28429b77e5dSHoria Geanta if (!key) 28529b77e5dSHoria Geanta goto out_nobuf; 286f8b0d4d0SHerbert Xu if (testmgr_alloc_buf(xbuf)) 287f8b0d4d0SHerbert Xu goto out_nobuf; 288da7f033dSHerbert Xu 2897f397136SGilad Ben-Yossef crypto_init_wait(&wait); 290da7f033dSHerbert Xu 291da7f033dSHerbert Xu req = ahash_request_alloc(tfm, GFP_KERNEL); 292da7f033dSHerbert Xu if (!req) { 293da7f033dSHerbert Xu printk(KERN_ERR "alg: hash: Failed to allocate request for " 294da7f033dSHerbert Xu "%s\n", algo); 295da7f033dSHerbert Xu goto out_noreq; 296da7f033dSHerbert Xu } 297da7f033dSHerbert Xu ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, 2987f397136SGilad Ben-Yossef crypto_req_done, &wait); 299da7f033dSHerbert Xu 300a0cfae59SHerbert Xu j = 0; 301da7f033dSHerbert Xu for (i = 0; i < tcount; i++) { 302a0cfae59SHerbert Xu if (template[i].np) 303a0cfae59SHerbert Xu continue; 304a0cfae59SHerbert Xu 305da5ffe11SJussi Kivilinna ret = -EINVAL; 306da5ffe11SJussi Kivilinna if (WARN_ON(align_offset + template[i].psize > PAGE_SIZE)) 307da5ffe11SJussi Kivilinna goto out; 308da5ffe11SJussi Kivilinna 309a0cfae59SHerbert Xu j++; 310e93acd6fSAndrew Lutomirski memset(result, 0, digest_size); 311da7f033dSHerbert Xu 312da7f033dSHerbert Xu hash_buff = xbuf[0]; 313da5ffe11SJussi Kivilinna hash_buff += align_offset; 314da7f033dSHerbert Xu 315da7f033dSHerbert Xu memcpy(hash_buff, template[i].plaintext, template[i].psize); 316da7f033dSHerbert Xu sg_init_one(&sg[0], hash_buff, template[i].psize); 317da7f033dSHerbert Xu 318da7f033dSHerbert Xu if (template[i].ksize) { 319da7f033dSHerbert Xu crypto_ahash_clear_flags(tfm, ~0); 32029b77e5dSHoria Geanta if (template[i].ksize > MAX_KEYLEN) { 32129b77e5dSHoria Geanta pr_err("alg: hash: setkey failed on test %d for %s: key size %d > %d\n", 32229b77e5dSHoria Geanta j, algo, template[i].ksize, MAX_KEYLEN); 32329b77e5dSHoria Geanta ret = -EINVAL; 32429b77e5dSHoria Geanta goto out; 32529b77e5dSHoria Geanta } 32629b77e5dSHoria Geanta memcpy(key, template[i].key, template[i].ksize); 32729b77e5dSHoria Geanta ret = crypto_ahash_setkey(tfm, key, template[i].ksize); 328da7f033dSHerbert Xu if (ret) { 329da7f033dSHerbert Xu printk(KERN_ERR "alg: hash: setkey failed on " 330a0cfae59SHerbert Xu "test %d for %s: ret=%d\n", j, algo, 331da7f033dSHerbert Xu -ret); 332da7f033dSHerbert Xu goto out; 333da7f033dSHerbert Xu } 334da7f033dSHerbert Xu } 335da7f033dSHerbert Xu 336da7f033dSHerbert Xu ahash_request_set_crypt(req, sg, result, template[i].psize); 337a8f1a052SDavid S. Miller if (use_digest) { 3387f397136SGilad Ben-Yossef ret = crypto_wait_req(crypto_ahash_digest(req), &wait); 339a8f1a052SDavid S. Miller if (ret) { 340a8f1a052SDavid S. Miller pr_err("alg: hash: digest failed on test %d " 341a0cfae59SHerbert Xu "for %s: ret=%d\n", j, algo, -ret); 342da7f033dSHerbert Xu goto out; 343da7f033dSHerbert Xu } 344a8f1a052SDavid S. Miller } else { 345466d7b9fSKamil Konieczny memset(result, 1, digest_size); 3467f397136SGilad Ben-Yossef ret = crypto_wait_req(crypto_ahash_init(req), &wait); 347a8f1a052SDavid S. Miller if (ret) { 348cf3f9609SGilad Ben-Yossef pr_err("alg: hash: init failed on test %d " 349a8f1a052SDavid S. Miller "for %s: ret=%d\n", j, algo, -ret); 350a8f1a052SDavid S. Miller goto out; 351a8f1a052SDavid S. Miller } 352466d7b9fSKamil Konieczny ret = ahash_guard_result(result, 1, digest_size); 353466d7b9fSKamil Konieczny if (ret) { 354466d7b9fSKamil Konieczny pr_err("alg: hash: init failed on test %d " 355466d7b9fSKamil Konieczny "for %s: used req->result\n", j, algo); 356466d7b9fSKamil Konieczny goto out; 357466d7b9fSKamil Konieczny } 3587f397136SGilad Ben-Yossef ret = crypto_wait_req(crypto_ahash_update(req), &wait); 359a8f1a052SDavid S. Miller if (ret) { 360cf3f9609SGilad Ben-Yossef pr_err("alg: hash: update failed on test %d " 361a8f1a052SDavid S. Miller "for %s: ret=%d\n", j, algo, -ret); 362a8f1a052SDavid S. Miller goto out; 363a8f1a052SDavid S. Miller } 364466d7b9fSKamil Konieczny ret = ahash_guard_result(result, 1, digest_size); 365466d7b9fSKamil Konieczny if (ret) { 366466d7b9fSKamil Konieczny pr_err("alg: hash: update failed on test %d " 367466d7b9fSKamil Konieczny "for %s: used req->result\n", j, algo); 368466d7b9fSKamil Konieczny goto out; 369466d7b9fSKamil Konieczny } 3707f397136SGilad Ben-Yossef ret = crypto_wait_req(crypto_ahash_final(req), &wait); 371a8f1a052SDavid S. Miller if (ret) { 372cf3f9609SGilad Ben-Yossef pr_err("alg: hash: final failed on test %d " 373a8f1a052SDavid S. Miller "for %s: ret=%d\n", j, algo, -ret); 374a8f1a052SDavid S. Miller goto out; 375a8f1a052SDavid S. Miller } 376a8f1a052SDavid S. Miller } 377da7f033dSHerbert Xu 378da7f033dSHerbert Xu if (memcmp(result, template[i].digest, 379da7f033dSHerbert Xu crypto_ahash_digestsize(tfm))) { 380da7f033dSHerbert Xu printk(KERN_ERR "alg: hash: Test %d failed for %s\n", 381a0cfae59SHerbert Xu j, algo); 382da7f033dSHerbert Xu hexdump(result, crypto_ahash_digestsize(tfm)); 383da7f033dSHerbert Xu ret = -EINVAL; 384da7f033dSHerbert Xu goto out; 385da7f033dSHerbert Xu } 386da7f033dSHerbert Xu } 387da7f033dSHerbert Xu 388da7f033dSHerbert Xu j = 0; 389da7f033dSHerbert Xu for (i = 0; i < tcount; i++) { 390da5ffe11SJussi Kivilinna /* alignment tests are only done with continuous buffers */ 391da5ffe11SJussi Kivilinna if (align_offset != 0) 392da5ffe11SJussi Kivilinna break; 393da5ffe11SJussi Kivilinna 3945f2b424eSCristian Stoica if (!template[i].np) 3955f2b424eSCristian Stoica continue; 3965f2b424eSCristian Stoica 397da7f033dSHerbert Xu j++; 398e93acd6fSAndrew Lutomirski memset(result, 0, digest_size); 399da7f033dSHerbert Xu 400da7f033dSHerbert Xu temp = 0; 401da7f033dSHerbert Xu sg_init_table(sg, template[i].np); 402fd57f22aSHerbert Xu ret = -EINVAL; 403da7f033dSHerbert Xu for (k = 0; k < template[i].np; k++) { 404fd57f22aSHerbert Xu if (WARN_ON(offset_in_page(IDX[k]) + 405fd57f22aSHerbert Xu template[i].tap[k] > PAGE_SIZE)) 406fd57f22aSHerbert Xu goto out; 407da7f033dSHerbert Xu sg_set_buf(&sg[k], 408da7f033dSHerbert Xu memcpy(xbuf[IDX[k] >> PAGE_SHIFT] + 409da7f033dSHerbert Xu offset_in_page(IDX[k]), 410da7f033dSHerbert Xu template[i].plaintext + temp, 411da7f033dSHerbert Xu template[i].tap[k]), 412da7f033dSHerbert Xu template[i].tap[k]); 413da7f033dSHerbert Xu temp += template[i].tap[k]; 414da7f033dSHerbert Xu } 415da7f033dSHerbert Xu 416da7f033dSHerbert Xu if (template[i].ksize) { 41729b77e5dSHoria Geanta if (template[i].ksize > MAX_KEYLEN) { 41829b77e5dSHoria Geanta pr_err("alg: hash: setkey failed on test %d for %s: key size %d > %d\n", 4195f2b424eSCristian Stoica j, algo, template[i].ksize, MAX_KEYLEN); 42029b77e5dSHoria Geanta ret = -EINVAL; 42129b77e5dSHoria Geanta goto out; 42229b77e5dSHoria Geanta } 423da7f033dSHerbert Xu crypto_ahash_clear_flags(tfm, ~0); 42429b77e5dSHoria Geanta memcpy(key, template[i].key, template[i].ksize); 4255f2b424eSCristian Stoica ret = crypto_ahash_setkey(tfm, key, template[i].ksize); 426da7f033dSHerbert Xu 427da7f033dSHerbert Xu if (ret) { 428da7f033dSHerbert Xu printk(KERN_ERR "alg: hash: setkey " 429da7f033dSHerbert Xu "failed on chunking test %d " 4305f2b424eSCristian Stoica "for %s: ret=%d\n", j, algo, -ret); 431da7f033dSHerbert Xu goto out; 432da7f033dSHerbert Xu } 433da7f033dSHerbert Xu } 434da7f033dSHerbert Xu 4355f2b424eSCristian Stoica ahash_request_set_crypt(req, sg, result, template[i].psize); 4367f397136SGilad Ben-Yossef ret = crypto_wait_req(crypto_ahash_digest(req), &wait); 4377f397136SGilad Ben-Yossef if (ret) { 4387f397136SGilad Ben-Yossef pr_err("alg: hash: digest failed on chunking test %d for %s: ret=%d\n", 4397f397136SGilad Ben-Yossef j, algo, -ret); 440da7f033dSHerbert Xu goto out; 441da7f033dSHerbert Xu } 442da7f033dSHerbert Xu 443da7f033dSHerbert Xu if (memcmp(result, template[i].digest, 444da7f033dSHerbert Xu crypto_ahash_digestsize(tfm))) { 445da7f033dSHerbert Xu printk(KERN_ERR "alg: hash: Chunking test %d " 446da7f033dSHerbert Xu "failed for %s\n", j, algo); 447da7f033dSHerbert Xu hexdump(result, crypto_ahash_digestsize(tfm)); 448da7f033dSHerbert Xu ret = -EINVAL; 449da7f033dSHerbert Xu goto out; 450da7f033dSHerbert Xu } 451da7f033dSHerbert Xu } 452da7f033dSHerbert Xu 453018ba95cSWang, Rui Y /* partial update exercise */ 454018ba95cSWang, Rui Y j = 0; 455018ba95cSWang, Rui Y for (i = 0; i < tcount; i++) { 456018ba95cSWang, Rui Y /* alignment tests are only done with continuous buffers */ 457018ba95cSWang, Rui Y if (align_offset != 0) 458018ba95cSWang, Rui Y break; 459018ba95cSWang, Rui Y 460018ba95cSWang, Rui Y if (template[i].np < 2) 461018ba95cSWang, Rui Y continue; 462018ba95cSWang, Rui Y 463018ba95cSWang, Rui Y j++; 464e93acd6fSAndrew Lutomirski memset(result, 0, digest_size); 465018ba95cSWang, Rui Y 466018ba95cSWang, Rui Y ret = -EINVAL; 467018ba95cSWang, Rui Y hash_buff = xbuf[0]; 468018ba95cSWang, Rui Y memcpy(hash_buff, template[i].plaintext, 469018ba95cSWang, Rui Y template[i].tap[0]); 470018ba95cSWang, Rui Y sg_init_one(&sg[0], hash_buff, template[i].tap[0]); 471018ba95cSWang, Rui Y 472018ba95cSWang, Rui Y if (template[i].ksize) { 473018ba95cSWang, Rui Y crypto_ahash_clear_flags(tfm, ~0); 474018ba95cSWang, Rui Y if (template[i].ksize > MAX_KEYLEN) { 475018ba95cSWang, Rui Y pr_err("alg: hash: setkey failed on test %d for %s: key size %d > %d\n", 476018ba95cSWang, Rui Y j, algo, template[i].ksize, MAX_KEYLEN); 477018ba95cSWang, Rui Y ret = -EINVAL; 478018ba95cSWang, Rui Y goto out; 479018ba95cSWang, Rui Y } 480018ba95cSWang, Rui Y memcpy(key, template[i].key, template[i].ksize); 481018ba95cSWang, Rui Y ret = crypto_ahash_setkey(tfm, key, template[i].ksize); 482018ba95cSWang, Rui Y if (ret) { 483018ba95cSWang, Rui Y pr_err("alg: hash: setkey failed on test %d for %s: ret=%d\n", 484018ba95cSWang, Rui Y j, algo, -ret); 485018ba95cSWang, Rui Y goto out; 486018ba95cSWang, Rui Y } 487018ba95cSWang, Rui Y } 488018ba95cSWang, Rui Y 489018ba95cSWang, Rui Y ahash_request_set_crypt(req, sg, result, template[i].tap[0]); 4907f397136SGilad Ben-Yossef ret = crypto_wait_req(crypto_ahash_init(req), &wait); 491018ba95cSWang, Rui Y if (ret) { 492cf3f9609SGilad Ben-Yossef pr_err("alg: hash: init failed on test %d for %s: ret=%d\n", 493018ba95cSWang, Rui Y j, algo, -ret); 494018ba95cSWang, Rui Y goto out; 495018ba95cSWang, Rui Y } 4967f397136SGilad Ben-Yossef ret = crypto_wait_req(crypto_ahash_update(req), &wait); 497018ba95cSWang, Rui Y if (ret) { 498cf3f9609SGilad Ben-Yossef pr_err("alg: hash: update failed on test %d for %s: ret=%d\n", 499018ba95cSWang, Rui Y j, algo, -ret); 500018ba95cSWang, Rui Y goto out; 501018ba95cSWang, Rui Y } 502018ba95cSWang, Rui Y 503018ba95cSWang, Rui Y temp = template[i].tap[0]; 504018ba95cSWang, Rui Y for (k = 1; k < template[i].np; k++) { 505018ba95cSWang, Rui Y ret = ahash_partial_update(&req, tfm, &template[i], 506018ba95cSWang, Rui Y hash_buff, k, temp, &sg[0], algo, result, 5077f397136SGilad Ben-Yossef &wait); 508018ba95cSWang, Rui Y if (ret) { 509cf3f9609SGilad Ben-Yossef pr_err("alg: hash: partial update failed on test %d for %s: ret=%d\n", 510018ba95cSWang, Rui Y j, algo, -ret); 511018ba95cSWang, Rui Y goto out_noreq; 512018ba95cSWang, Rui Y } 513018ba95cSWang, Rui Y temp += template[i].tap[k]; 514018ba95cSWang, Rui Y } 5157f397136SGilad Ben-Yossef ret = crypto_wait_req(crypto_ahash_final(req), &wait); 516018ba95cSWang, Rui Y if (ret) { 517cf3f9609SGilad Ben-Yossef pr_err("alg: hash: final failed on test %d for %s: ret=%d\n", 518018ba95cSWang, Rui Y j, algo, -ret); 519018ba95cSWang, Rui Y goto out; 520018ba95cSWang, Rui Y } 521018ba95cSWang, Rui Y if (memcmp(result, template[i].digest, 522018ba95cSWang, Rui Y crypto_ahash_digestsize(tfm))) { 523018ba95cSWang, Rui Y pr_err("alg: hash: Partial Test %d failed for %s\n", 524018ba95cSWang, Rui Y j, algo); 525018ba95cSWang, Rui Y hexdump(result, crypto_ahash_digestsize(tfm)); 526018ba95cSWang, Rui Y ret = -EINVAL; 527018ba95cSWang, Rui Y goto out; 528018ba95cSWang, Rui Y } 529018ba95cSWang, Rui Y } 530018ba95cSWang, Rui Y 531da7f033dSHerbert Xu ret = 0; 532da7f033dSHerbert Xu 533da7f033dSHerbert Xu out: 534da7f033dSHerbert Xu ahash_request_free(req); 535da7f033dSHerbert Xu out_noreq: 536f8b0d4d0SHerbert Xu testmgr_free_buf(xbuf); 537f8b0d4d0SHerbert Xu out_nobuf: 53829b77e5dSHoria Geanta kfree(key); 53929b77e5dSHoria Geanta kfree(result); 540da7f033dSHerbert Xu return ret; 541da7f033dSHerbert Xu } 542da7f033dSHerbert Xu 543b13b1e0cSEric Biggers static int test_hash(struct crypto_ahash *tfm, 544b13b1e0cSEric Biggers const struct hash_testvec *template, 545da5ffe11SJussi Kivilinna unsigned int tcount, bool use_digest) 546da5ffe11SJussi Kivilinna { 547da5ffe11SJussi Kivilinna unsigned int alignmask; 548da5ffe11SJussi Kivilinna int ret; 549da5ffe11SJussi Kivilinna 550da5ffe11SJussi Kivilinna ret = __test_hash(tfm, template, tcount, use_digest, 0); 551da5ffe11SJussi Kivilinna if (ret) 552da5ffe11SJussi Kivilinna return ret; 553da5ffe11SJussi Kivilinna 554da5ffe11SJussi Kivilinna /* test unaligned buffers, check with one byte offset */ 555da5ffe11SJussi Kivilinna ret = __test_hash(tfm, template, tcount, use_digest, 1); 556da5ffe11SJussi Kivilinna if (ret) 557da5ffe11SJussi Kivilinna return ret; 558da5ffe11SJussi Kivilinna 559da5ffe11SJussi Kivilinna alignmask = crypto_tfm_alg_alignmask(&tfm->base); 560da5ffe11SJussi Kivilinna if (alignmask) { 561da5ffe11SJussi Kivilinna /* Check if alignment mask for tfm is correctly set. */ 562da5ffe11SJussi Kivilinna ret = __test_hash(tfm, template, tcount, use_digest, 563da5ffe11SJussi Kivilinna alignmask + 1); 564da5ffe11SJussi Kivilinna if (ret) 565da5ffe11SJussi Kivilinna return ret; 566da5ffe11SJussi Kivilinna } 567da5ffe11SJussi Kivilinna 568da5ffe11SJussi Kivilinna return 0; 569da5ffe11SJussi Kivilinna } 570da5ffe11SJussi Kivilinna 571d8a32ac2SJussi Kivilinna static int __test_aead(struct crypto_aead *tfm, int enc, 572b13b1e0cSEric Biggers const struct aead_testvec *template, unsigned int tcount, 57358dcf548SJussi Kivilinna const bool diff_dst, const int align_offset) 574da7f033dSHerbert Xu { 575da7f033dSHerbert Xu const char *algo = crypto_tfm_alg_driver_name(crypto_aead_tfm(tfm)); 576da7f033dSHerbert Xu unsigned int i, j, k, n, temp; 577f8b0d4d0SHerbert Xu int ret = -ENOMEM; 578da7f033dSHerbert Xu char *q; 579da7f033dSHerbert Xu char *key; 580da7f033dSHerbert Xu struct aead_request *req; 581d8a32ac2SJussi Kivilinna struct scatterlist *sg; 582d8a32ac2SJussi Kivilinna struct scatterlist *sgout; 583d8a32ac2SJussi Kivilinna const char *e, *d; 5847f397136SGilad Ben-Yossef struct crypto_wait wait; 585424a5da6SCristian Stoica unsigned int authsize, iv_len; 586da7f033dSHerbert Xu void *input; 587d8a32ac2SJussi Kivilinna void *output; 588da7f033dSHerbert Xu void *assoc; 5899bac019dSTadeusz Struk char *iv; 590f8b0d4d0SHerbert Xu char *xbuf[XBUFSIZE]; 591d8a32ac2SJussi Kivilinna char *xoutbuf[XBUFSIZE]; 592f8b0d4d0SHerbert Xu char *axbuf[XBUFSIZE]; 593f8b0d4d0SHerbert Xu 5949bac019dSTadeusz Struk iv = kzalloc(MAX_IVLEN, GFP_KERNEL); 5959bac019dSTadeusz Struk if (!iv) 5969bac019dSTadeusz Struk return ret; 59729b77e5dSHoria Geanta key = kmalloc(MAX_KEYLEN, GFP_KERNEL); 59829b77e5dSHoria Geanta if (!key) 59929b77e5dSHoria Geanta goto out_noxbuf; 600f8b0d4d0SHerbert Xu if (testmgr_alloc_buf(xbuf)) 601f8b0d4d0SHerbert Xu goto out_noxbuf; 602f8b0d4d0SHerbert Xu if (testmgr_alloc_buf(axbuf)) 603f8b0d4d0SHerbert Xu goto out_noaxbuf; 604d8a32ac2SJussi Kivilinna if (diff_dst && testmgr_alloc_buf(xoutbuf)) 605d8a32ac2SJussi Kivilinna goto out_nooutbuf; 606d8a32ac2SJussi Kivilinna 607d8a32ac2SJussi Kivilinna /* avoid "the frame size is larger than 1024 bytes" compiler warning */ 6088a525fcdSHerbert Xu sg = kmalloc(sizeof(*sg) * 8 * (diff_dst ? 4 : 2), GFP_KERNEL); 609d8a32ac2SJussi Kivilinna if (!sg) 610d8a32ac2SJussi Kivilinna goto out_nosg; 6118a525fcdSHerbert Xu sgout = &sg[16]; 612d8a32ac2SJussi Kivilinna 613d8a32ac2SJussi Kivilinna if (diff_dst) 614d8a32ac2SJussi Kivilinna d = "-ddst"; 615d8a32ac2SJussi Kivilinna else 616d8a32ac2SJussi Kivilinna d = ""; 617d8a32ac2SJussi Kivilinna 618da7f033dSHerbert Xu if (enc == ENCRYPT) 619da7f033dSHerbert Xu e = "encryption"; 620da7f033dSHerbert Xu else 621da7f033dSHerbert Xu e = "decryption"; 622da7f033dSHerbert Xu 6237f397136SGilad Ben-Yossef crypto_init_wait(&wait); 624da7f033dSHerbert Xu 625da7f033dSHerbert Xu req = aead_request_alloc(tfm, GFP_KERNEL); 626da7f033dSHerbert Xu if (!req) { 627d8a32ac2SJussi Kivilinna pr_err("alg: aead%s: Failed to allocate request for %s\n", 628d8a32ac2SJussi Kivilinna d, algo); 629da7f033dSHerbert Xu goto out; 630da7f033dSHerbert Xu } 631da7f033dSHerbert Xu 632da7f033dSHerbert Xu aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, 6337f397136SGilad Ben-Yossef crypto_req_done, &wait); 634da7f033dSHerbert Xu 635abfa7f43SJerome Marchand iv_len = crypto_aead_ivsize(tfm); 636abfa7f43SJerome Marchand 637da7f033dSHerbert Xu for (i = 0, j = 0; i < tcount; i++) { 63805b1d338SCristian Stoica if (template[i].np) 63905b1d338SCristian Stoica continue; 64005b1d338SCristian Stoica 641da7f033dSHerbert Xu j++; 642da7f033dSHerbert Xu 64358dcf548SJussi Kivilinna /* some templates have no input data but they will 644da7f033dSHerbert Xu * touch input 645da7f033dSHerbert Xu */ 646da7f033dSHerbert Xu input = xbuf[0]; 64758dcf548SJussi Kivilinna input += align_offset; 648da7f033dSHerbert Xu assoc = axbuf[0]; 649da7f033dSHerbert Xu 650fd57f22aSHerbert Xu ret = -EINVAL; 65158dcf548SJussi Kivilinna if (WARN_ON(align_offset + template[i].ilen > 65258dcf548SJussi Kivilinna PAGE_SIZE || template[i].alen > PAGE_SIZE)) 653fd57f22aSHerbert Xu goto out; 654fd57f22aSHerbert Xu 655da7f033dSHerbert Xu memcpy(input, template[i].input, template[i].ilen); 656da7f033dSHerbert Xu memcpy(assoc, template[i].assoc, template[i].alen); 657da7f033dSHerbert Xu if (template[i].iv) 658424a5da6SCristian Stoica memcpy(iv, template[i].iv, iv_len); 659da7f033dSHerbert Xu else 660424a5da6SCristian Stoica memset(iv, 0, iv_len); 661da7f033dSHerbert Xu 662da7f033dSHerbert Xu crypto_aead_clear_flags(tfm, ~0); 663da7f033dSHerbert Xu if (template[i].wk) 66405b1d338SCristian Stoica crypto_aead_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY); 665da7f033dSHerbert Xu 66629b77e5dSHoria Geanta if (template[i].klen > MAX_KEYLEN) { 66729b77e5dSHoria Geanta pr_err("alg: aead%s: setkey failed on test %d for %s: key size %d > %d\n", 66829b77e5dSHoria Geanta d, j, algo, template[i].klen, 66929b77e5dSHoria Geanta MAX_KEYLEN); 67029b77e5dSHoria Geanta ret = -EINVAL; 67129b77e5dSHoria Geanta goto out; 67229b77e5dSHoria Geanta } 67329b77e5dSHoria Geanta memcpy(key, template[i].key, template[i].klen); 674da7f033dSHerbert Xu 67505b1d338SCristian Stoica ret = crypto_aead_setkey(tfm, key, template[i].klen); 6760fae0c1eSYanjiang Jin if (template[i].fail == !ret) { 677d8a32ac2SJussi Kivilinna pr_err("alg: aead%s: setkey failed on test %d for %s: flags=%x\n", 678d8a32ac2SJussi Kivilinna d, j, algo, crypto_aead_get_flags(tfm)); 679da7f033dSHerbert Xu goto out; 680da7f033dSHerbert Xu } else if (ret) 681da7f033dSHerbert Xu continue; 682da7f033dSHerbert Xu 683da7f033dSHerbert Xu authsize = abs(template[i].rlen - template[i].ilen); 684da7f033dSHerbert Xu ret = crypto_aead_setauthsize(tfm, authsize); 685da7f033dSHerbert Xu if (ret) { 686d8a32ac2SJussi Kivilinna pr_err("alg: aead%s: Failed to set authsize to %u on test %d for %s\n", 687d8a32ac2SJussi Kivilinna d, authsize, j, algo); 688da7f033dSHerbert Xu goto out; 689da7f033dSHerbert Xu } 690da7f033dSHerbert Xu 6918a525fcdSHerbert Xu k = !!template[i].alen; 6928a525fcdSHerbert Xu sg_init_table(sg, k + 1); 6938a525fcdSHerbert Xu sg_set_buf(&sg[0], assoc, template[i].alen); 6948a525fcdSHerbert Xu sg_set_buf(&sg[k], input, 69505b1d338SCristian Stoica template[i].ilen + (enc ? authsize : 0)); 696d8a32ac2SJussi Kivilinna output = input; 697d8a32ac2SJussi Kivilinna 6988a525fcdSHerbert Xu if (diff_dst) { 6998a525fcdSHerbert Xu sg_init_table(sgout, k + 1); 7008a525fcdSHerbert Xu sg_set_buf(&sgout[0], assoc, template[i].alen); 7018a525fcdSHerbert Xu 7028a525fcdSHerbert Xu output = xoutbuf[0]; 7038a525fcdSHerbert Xu output += align_offset; 7048a525fcdSHerbert Xu sg_set_buf(&sgout[k], output, 7058a525fcdSHerbert Xu template[i].rlen + (enc ? 0 : authsize)); 7068a525fcdSHerbert Xu } 707da7f033dSHerbert Xu 708d8a32ac2SJussi Kivilinna aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg, 709da7f033dSHerbert Xu template[i].ilen, iv); 710da7f033dSHerbert Xu 7118a525fcdSHerbert Xu aead_request_set_ad(req, template[i].alen); 712da7f033dSHerbert Xu 7137f397136SGilad Ben-Yossef ret = crypto_wait_req(enc ? crypto_aead_encrypt(req) 7147f397136SGilad Ben-Yossef : crypto_aead_decrypt(req), &wait); 715da7f033dSHerbert Xu 716da7f033dSHerbert Xu switch (ret) { 717da7f033dSHerbert Xu case 0: 718e44a1b44SJarod Wilson if (template[i].novrfy) { 719e44a1b44SJarod Wilson /* verification was supposed to fail */ 720d8a32ac2SJussi Kivilinna pr_err("alg: aead%s: %s failed on test %d for %s: ret was 0, expected -EBADMSG\n", 721d8a32ac2SJussi Kivilinna d, e, j, algo); 722e44a1b44SJarod Wilson /* so really, we got a bad message */ 723e44a1b44SJarod Wilson ret = -EBADMSG; 724e44a1b44SJarod Wilson goto out; 725e44a1b44SJarod Wilson } 726da7f033dSHerbert Xu break; 727e44a1b44SJarod Wilson case -EBADMSG: 728e44a1b44SJarod Wilson if (template[i].novrfy) 729e44a1b44SJarod Wilson /* verification failure was expected */ 730e44a1b44SJarod Wilson continue; 731da7f033dSHerbert Xu /* fall through */ 732da7f033dSHerbert Xu default: 733d8a32ac2SJussi Kivilinna pr_err("alg: aead%s: %s failed on test %d for %s: ret=%d\n", 734d8a32ac2SJussi Kivilinna d, e, j, algo, -ret); 735da7f033dSHerbert Xu goto out; 736da7f033dSHerbert Xu } 737da7f033dSHerbert Xu 738d8a32ac2SJussi Kivilinna q = output; 739da7f033dSHerbert Xu if (memcmp(q, template[i].result, template[i].rlen)) { 740d8a32ac2SJussi Kivilinna pr_err("alg: aead%s: Test %d failed on %s for %s\n", 741d8a32ac2SJussi Kivilinna d, j, e, algo); 742da7f033dSHerbert Xu hexdump(q, template[i].rlen); 743da7f033dSHerbert Xu ret = -EINVAL; 744da7f033dSHerbert Xu goto out; 745da7f033dSHerbert Xu } 746da7f033dSHerbert Xu } 747da7f033dSHerbert Xu 748da7f033dSHerbert Xu for (i = 0, j = 0; i < tcount; i++) { 74958dcf548SJussi Kivilinna /* alignment tests are only done with continuous buffers */ 75058dcf548SJussi Kivilinna if (align_offset != 0) 75158dcf548SJussi Kivilinna break; 75258dcf548SJussi Kivilinna 75305b1d338SCristian Stoica if (!template[i].np) 75405b1d338SCristian Stoica continue; 75505b1d338SCristian Stoica 756da7f033dSHerbert Xu j++; 757da7f033dSHerbert Xu 758da7f033dSHerbert Xu if (template[i].iv) 759abfa7f43SJerome Marchand memcpy(iv, template[i].iv, iv_len); 760da7f033dSHerbert Xu else 761da7f033dSHerbert Xu memset(iv, 0, MAX_IVLEN); 762da7f033dSHerbert Xu 763da7f033dSHerbert Xu crypto_aead_clear_flags(tfm, ~0); 764da7f033dSHerbert Xu if (template[i].wk) 76505b1d338SCristian Stoica crypto_aead_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY); 76629b77e5dSHoria Geanta if (template[i].klen > MAX_KEYLEN) { 76729b77e5dSHoria Geanta pr_err("alg: aead%s: setkey failed on test %d for %s: key size %d > %d\n", 76805b1d338SCristian Stoica d, j, algo, template[i].klen, MAX_KEYLEN); 76929b77e5dSHoria Geanta ret = -EINVAL; 77029b77e5dSHoria Geanta goto out; 77129b77e5dSHoria Geanta } 77229b77e5dSHoria Geanta memcpy(key, template[i].key, template[i].klen); 773da7f033dSHerbert Xu 774da7f033dSHerbert Xu ret = crypto_aead_setkey(tfm, key, template[i].klen); 7750fae0c1eSYanjiang Jin if (template[i].fail == !ret) { 776d8a32ac2SJussi Kivilinna pr_err("alg: aead%s: setkey failed on chunk test %d for %s: flags=%x\n", 777d8a32ac2SJussi Kivilinna d, j, algo, crypto_aead_get_flags(tfm)); 778da7f033dSHerbert Xu goto out; 779da7f033dSHerbert Xu } else if (ret) 780da7f033dSHerbert Xu continue; 781da7f033dSHerbert Xu 782da7f033dSHerbert Xu authsize = abs(template[i].rlen - template[i].ilen); 783da7f033dSHerbert Xu 784da7f033dSHerbert Xu ret = -EINVAL; 7858a525fcdSHerbert Xu sg_init_table(sg, template[i].anp + template[i].np); 786d8a32ac2SJussi Kivilinna if (diff_dst) 7878a525fcdSHerbert Xu sg_init_table(sgout, template[i].anp + template[i].np); 7888a525fcdSHerbert Xu 7898a525fcdSHerbert Xu ret = -EINVAL; 7908a525fcdSHerbert Xu for (k = 0, temp = 0; k < template[i].anp; k++) { 7918a525fcdSHerbert Xu if (WARN_ON(offset_in_page(IDX[k]) + 7928a525fcdSHerbert Xu template[i].atap[k] > PAGE_SIZE)) 7938a525fcdSHerbert Xu goto out; 7948a525fcdSHerbert Xu sg_set_buf(&sg[k], 7958a525fcdSHerbert Xu memcpy(axbuf[IDX[k] >> PAGE_SHIFT] + 7968a525fcdSHerbert Xu offset_in_page(IDX[k]), 7978a525fcdSHerbert Xu template[i].assoc + temp, 7988a525fcdSHerbert Xu template[i].atap[k]), 7998a525fcdSHerbert Xu template[i].atap[k]); 8008a525fcdSHerbert Xu if (diff_dst) 8018a525fcdSHerbert Xu sg_set_buf(&sgout[k], 8028a525fcdSHerbert Xu axbuf[IDX[k] >> PAGE_SHIFT] + 8038a525fcdSHerbert Xu offset_in_page(IDX[k]), 8048a525fcdSHerbert Xu template[i].atap[k]); 8058a525fcdSHerbert Xu temp += template[i].atap[k]; 8068a525fcdSHerbert Xu } 8078a525fcdSHerbert Xu 808da7f033dSHerbert Xu for (k = 0, temp = 0; k < template[i].np; k++) { 809da7f033dSHerbert Xu if (WARN_ON(offset_in_page(IDX[k]) + 810da7f033dSHerbert Xu template[i].tap[k] > PAGE_SIZE)) 811da7f033dSHerbert Xu goto out; 812da7f033dSHerbert Xu 81305b1d338SCristian Stoica q = xbuf[IDX[k] >> PAGE_SHIFT] + offset_in_page(IDX[k]); 81405b1d338SCristian Stoica memcpy(q, template[i].input + temp, template[i].tap[k]); 8158a525fcdSHerbert Xu sg_set_buf(&sg[template[i].anp + k], 8168a525fcdSHerbert Xu q, template[i].tap[k]); 817d8a32ac2SJussi Kivilinna 818d8a32ac2SJussi Kivilinna if (diff_dst) { 819d8a32ac2SJussi Kivilinna q = xoutbuf[IDX[k] >> PAGE_SHIFT] + 820d8a32ac2SJussi Kivilinna offset_in_page(IDX[k]); 821d8a32ac2SJussi Kivilinna 822d8a32ac2SJussi Kivilinna memset(q, 0, template[i].tap[k]); 823d8a32ac2SJussi Kivilinna 8248a525fcdSHerbert Xu sg_set_buf(&sgout[template[i].anp + k], 8258a525fcdSHerbert Xu q, template[i].tap[k]); 826d8a32ac2SJussi Kivilinna } 827d8a32ac2SJussi Kivilinna 8288ec25c51SHoria Geanta n = template[i].tap[k]; 8298ec25c51SHoria Geanta if (k == template[i].np - 1 && enc) 8308ec25c51SHoria Geanta n += authsize; 8318ec25c51SHoria Geanta if (offset_in_page(q) + n < PAGE_SIZE) 8328ec25c51SHoria Geanta q[n] = 0; 8338ec25c51SHoria Geanta 834da7f033dSHerbert Xu temp += template[i].tap[k]; 835da7f033dSHerbert Xu } 836da7f033dSHerbert Xu 837da7f033dSHerbert Xu ret = crypto_aead_setauthsize(tfm, authsize); 838da7f033dSHerbert Xu if (ret) { 839d8a32ac2SJussi Kivilinna pr_err("alg: aead%s: Failed to set authsize to %u on chunk test %d for %s\n", 840d8a32ac2SJussi Kivilinna d, authsize, j, algo); 841da7f033dSHerbert Xu goto out; 842da7f033dSHerbert Xu } 843da7f033dSHerbert Xu 844da7f033dSHerbert Xu if (enc) { 8458a525fcdSHerbert Xu if (WARN_ON(sg[template[i].anp + k - 1].offset + 8468a525fcdSHerbert Xu sg[template[i].anp + k - 1].length + 8478a525fcdSHerbert Xu authsize > PAGE_SIZE)) { 848da7f033dSHerbert Xu ret = -EINVAL; 849da7f033dSHerbert Xu goto out; 850da7f033dSHerbert Xu } 851da7f033dSHerbert Xu 852d8a32ac2SJussi Kivilinna if (diff_dst) 8538a525fcdSHerbert Xu sgout[template[i].anp + k - 1].length += 8548a525fcdSHerbert Xu authsize; 8558a525fcdSHerbert Xu sg[template[i].anp + k - 1].length += authsize; 856da7f033dSHerbert Xu } 857da7f033dSHerbert Xu 858d8a32ac2SJussi Kivilinna aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg, 859da7f033dSHerbert Xu template[i].ilen, 860da7f033dSHerbert Xu iv); 861da7f033dSHerbert Xu 8628a525fcdSHerbert Xu aead_request_set_ad(req, template[i].alen); 863da7f033dSHerbert Xu 8647f397136SGilad Ben-Yossef ret = crypto_wait_req(enc ? crypto_aead_encrypt(req) 8657f397136SGilad Ben-Yossef : crypto_aead_decrypt(req), &wait); 866da7f033dSHerbert Xu 867da7f033dSHerbert Xu switch (ret) { 868da7f033dSHerbert Xu case 0: 869e44a1b44SJarod Wilson if (template[i].novrfy) { 870e44a1b44SJarod Wilson /* verification was supposed to fail */ 871d8a32ac2SJussi Kivilinna pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret was 0, expected -EBADMSG\n", 872d8a32ac2SJussi Kivilinna d, e, j, algo); 873e44a1b44SJarod Wilson /* so really, we got a bad message */ 874e44a1b44SJarod Wilson ret = -EBADMSG; 875e44a1b44SJarod Wilson goto out; 876e44a1b44SJarod Wilson } 877da7f033dSHerbert Xu break; 878e44a1b44SJarod Wilson case -EBADMSG: 879e44a1b44SJarod Wilson if (template[i].novrfy) 880e44a1b44SJarod Wilson /* verification failure was expected */ 881e44a1b44SJarod Wilson continue; 882da7f033dSHerbert Xu /* fall through */ 883da7f033dSHerbert Xu default: 884d8a32ac2SJussi Kivilinna pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret=%d\n", 885d8a32ac2SJussi Kivilinna d, e, j, algo, -ret); 886da7f033dSHerbert Xu goto out; 887da7f033dSHerbert Xu } 888da7f033dSHerbert Xu 889da7f033dSHerbert Xu ret = -EINVAL; 890da7f033dSHerbert Xu for (k = 0, temp = 0; k < template[i].np; k++) { 891d8a32ac2SJussi Kivilinna if (diff_dst) 892d8a32ac2SJussi Kivilinna q = xoutbuf[IDX[k] >> PAGE_SHIFT] + 893d8a32ac2SJussi Kivilinna offset_in_page(IDX[k]); 894d8a32ac2SJussi Kivilinna else 895da7f033dSHerbert Xu q = xbuf[IDX[k] >> PAGE_SHIFT] + 896da7f033dSHerbert Xu offset_in_page(IDX[k]); 897da7f033dSHerbert Xu 898da7f033dSHerbert Xu n = template[i].tap[k]; 899da7f033dSHerbert Xu if (k == template[i].np - 1) 900da7f033dSHerbert Xu n += enc ? authsize : -authsize; 901da7f033dSHerbert Xu 902da7f033dSHerbert Xu if (memcmp(q, template[i].result + temp, n)) { 903d8a32ac2SJussi Kivilinna pr_err("alg: aead%s: Chunk test %d failed on %s at page %u for %s\n", 904d8a32ac2SJussi Kivilinna d, j, e, k, algo); 905da7f033dSHerbert Xu hexdump(q, n); 906da7f033dSHerbert Xu goto out; 907da7f033dSHerbert Xu } 908da7f033dSHerbert Xu 909da7f033dSHerbert Xu q += n; 910da7f033dSHerbert Xu if (k == template[i].np - 1 && !enc) { 911d8a32ac2SJussi Kivilinna if (!diff_dst && 912d8a32ac2SJussi Kivilinna memcmp(q, template[i].input + 913da7f033dSHerbert Xu temp + n, authsize)) 914da7f033dSHerbert Xu n = authsize; 915da7f033dSHerbert Xu else 916da7f033dSHerbert Xu n = 0; 917da7f033dSHerbert Xu } else { 91805b1d338SCristian Stoica for (n = 0; offset_in_page(q + n) && q[n]; n++) 919da7f033dSHerbert Xu ; 920da7f033dSHerbert Xu } 921da7f033dSHerbert Xu if (n) { 922d8a32ac2SJussi Kivilinna pr_err("alg: aead%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n", 923d8a32ac2SJussi Kivilinna d, j, e, k, algo, n); 924da7f033dSHerbert Xu hexdump(q, n); 925da7f033dSHerbert Xu goto out; 926da7f033dSHerbert Xu } 927da7f033dSHerbert Xu 928da7f033dSHerbert Xu temp += template[i].tap[k]; 929da7f033dSHerbert Xu } 930da7f033dSHerbert Xu } 931da7f033dSHerbert Xu 932da7f033dSHerbert Xu ret = 0; 933da7f033dSHerbert Xu 934da7f033dSHerbert Xu out: 935da7f033dSHerbert Xu aead_request_free(req); 936d8a32ac2SJussi Kivilinna kfree(sg); 937d8a32ac2SJussi Kivilinna out_nosg: 938d8a32ac2SJussi Kivilinna if (diff_dst) 939d8a32ac2SJussi Kivilinna testmgr_free_buf(xoutbuf); 940d8a32ac2SJussi Kivilinna out_nooutbuf: 941f8b0d4d0SHerbert Xu testmgr_free_buf(axbuf); 942f8b0d4d0SHerbert Xu out_noaxbuf: 943f8b0d4d0SHerbert Xu testmgr_free_buf(xbuf); 944f8b0d4d0SHerbert Xu out_noxbuf: 94529b77e5dSHoria Geanta kfree(key); 9469bac019dSTadeusz Struk kfree(iv); 947da7f033dSHerbert Xu return ret; 948da7f033dSHerbert Xu } 949da7f033dSHerbert Xu 950d8a32ac2SJussi Kivilinna static int test_aead(struct crypto_aead *tfm, int enc, 951b13b1e0cSEric Biggers const struct aead_testvec *template, unsigned int tcount) 952d8a32ac2SJussi Kivilinna { 95358dcf548SJussi Kivilinna unsigned int alignmask; 954d8a32ac2SJussi Kivilinna int ret; 955d8a32ac2SJussi Kivilinna 956d8a32ac2SJussi Kivilinna /* test 'dst == src' case */ 95758dcf548SJussi Kivilinna ret = __test_aead(tfm, enc, template, tcount, false, 0); 958d8a32ac2SJussi Kivilinna if (ret) 959d8a32ac2SJussi Kivilinna return ret; 960d8a32ac2SJussi Kivilinna 961d8a32ac2SJussi Kivilinna /* test 'dst != src' case */ 96258dcf548SJussi Kivilinna ret = __test_aead(tfm, enc, template, tcount, true, 0); 96358dcf548SJussi Kivilinna if (ret) 96458dcf548SJussi Kivilinna return ret; 96558dcf548SJussi Kivilinna 96658dcf548SJussi Kivilinna /* test unaligned buffers, check with one byte offset */ 96758dcf548SJussi Kivilinna ret = __test_aead(tfm, enc, template, tcount, true, 1); 96858dcf548SJussi Kivilinna if (ret) 96958dcf548SJussi Kivilinna return ret; 97058dcf548SJussi Kivilinna 97158dcf548SJussi Kivilinna alignmask = crypto_tfm_alg_alignmask(&tfm->base); 97258dcf548SJussi Kivilinna if (alignmask) { 97358dcf548SJussi Kivilinna /* Check if alignment mask for tfm is correctly set. */ 97458dcf548SJussi Kivilinna ret = __test_aead(tfm, enc, template, tcount, true, 97558dcf548SJussi Kivilinna alignmask + 1); 97658dcf548SJussi Kivilinna if (ret) 97758dcf548SJussi Kivilinna return ret; 97858dcf548SJussi Kivilinna } 97958dcf548SJussi Kivilinna 98058dcf548SJussi Kivilinna return 0; 981d8a32ac2SJussi Kivilinna } 982d8a32ac2SJussi Kivilinna 9831aa4ecd9SHerbert Xu static int test_cipher(struct crypto_cipher *tfm, int enc, 984b13b1e0cSEric Biggers const struct cipher_testvec *template, 985b13b1e0cSEric Biggers unsigned int tcount) 9861aa4ecd9SHerbert Xu { 9871aa4ecd9SHerbert Xu const char *algo = crypto_tfm_alg_driver_name(crypto_cipher_tfm(tfm)); 9881aa4ecd9SHerbert Xu unsigned int i, j, k; 9891aa4ecd9SHerbert Xu char *q; 9901aa4ecd9SHerbert Xu const char *e; 9911aa4ecd9SHerbert Xu void *data; 992f8b0d4d0SHerbert Xu char *xbuf[XBUFSIZE]; 993f8b0d4d0SHerbert Xu int ret = -ENOMEM; 994f8b0d4d0SHerbert Xu 995f8b0d4d0SHerbert Xu if (testmgr_alloc_buf(xbuf)) 996f8b0d4d0SHerbert Xu goto out_nobuf; 9971aa4ecd9SHerbert Xu 9981aa4ecd9SHerbert Xu if (enc == ENCRYPT) 9991aa4ecd9SHerbert Xu e = "encryption"; 10001aa4ecd9SHerbert Xu else 10011aa4ecd9SHerbert Xu e = "decryption"; 10021aa4ecd9SHerbert Xu 10031aa4ecd9SHerbert Xu j = 0; 10041aa4ecd9SHerbert Xu for (i = 0; i < tcount; i++) { 10051aa4ecd9SHerbert Xu if (template[i].np) 10061aa4ecd9SHerbert Xu continue; 10071aa4ecd9SHerbert Xu 100810faa8c0SStephan Mueller if (fips_enabled && template[i].fips_skip) 100910faa8c0SStephan Mueller continue; 101010faa8c0SStephan Mueller 10111aa4ecd9SHerbert Xu j++; 10121aa4ecd9SHerbert Xu 1013fd57f22aSHerbert Xu ret = -EINVAL; 1014fd57f22aSHerbert Xu if (WARN_ON(template[i].ilen > PAGE_SIZE)) 1015fd57f22aSHerbert Xu goto out; 1016fd57f22aSHerbert Xu 10171aa4ecd9SHerbert Xu data = xbuf[0]; 10181aa4ecd9SHerbert Xu memcpy(data, template[i].input, template[i].ilen); 10191aa4ecd9SHerbert Xu 10201aa4ecd9SHerbert Xu crypto_cipher_clear_flags(tfm, ~0); 10211aa4ecd9SHerbert Xu if (template[i].wk) 10221aa4ecd9SHerbert Xu crypto_cipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY); 10231aa4ecd9SHerbert Xu 10241aa4ecd9SHerbert Xu ret = crypto_cipher_setkey(tfm, template[i].key, 10251aa4ecd9SHerbert Xu template[i].klen); 10260fae0c1eSYanjiang Jin if (template[i].fail == !ret) { 10271aa4ecd9SHerbert Xu printk(KERN_ERR "alg: cipher: setkey failed " 10281aa4ecd9SHerbert Xu "on test %d for %s: flags=%x\n", j, 10291aa4ecd9SHerbert Xu algo, crypto_cipher_get_flags(tfm)); 10301aa4ecd9SHerbert Xu goto out; 10311aa4ecd9SHerbert Xu } else if (ret) 10321aa4ecd9SHerbert Xu continue; 10331aa4ecd9SHerbert Xu 10341aa4ecd9SHerbert Xu for (k = 0; k < template[i].ilen; 10351aa4ecd9SHerbert Xu k += crypto_cipher_blocksize(tfm)) { 10361aa4ecd9SHerbert Xu if (enc) 10371aa4ecd9SHerbert Xu crypto_cipher_encrypt_one(tfm, data + k, 10381aa4ecd9SHerbert Xu data + k); 10391aa4ecd9SHerbert Xu else 10401aa4ecd9SHerbert Xu crypto_cipher_decrypt_one(tfm, data + k, 10411aa4ecd9SHerbert Xu data + k); 10421aa4ecd9SHerbert Xu } 10431aa4ecd9SHerbert Xu 10441aa4ecd9SHerbert Xu q = data; 10451aa4ecd9SHerbert Xu if (memcmp(q, template[i].result, template[i].rlen)) { 10461aa4ecd9SHerbert Xu printk(KERN_ERR "alg: cipher: Test %d failed " 10471aa4ecd9SHerbert Xu "on %s for %s\n", j, e, algo); 10481aa4ecd9SHerbert Xu hexdump(q, template[i].rlen); 10491aa4ecd9SHerbert Xu ret = -EINVAL; 10501aa4ecd9SHerbert Xu goto out; 10511aa4ecd9SHerbert Xu } 10521aa4ecd9SHerbert Xu } 10531aa4ecd9SHerbert Xu 10541aa4ecd9SHerbert Xu ret = 0; 10551aa4ecd9SHerbert Xu 10561aa4ecd9SHerbert Xu out: 1057f8b0d4d0SHerbert Xu testmgr_free_buf(xbuf); 1058f8b0d4d0SHerbert Xu out_nobuf: 10591aa4ecd9SHerbert Xu return ret; 10601aa4ecd9SHerbert Xu } 10611aa4ecd9SHerbert Xu 106212773d93SHerbert Xu static int __test_skcipher(struct crypto_skcipher *tfm, int enc, 1063b13b1e0cSEric Biggers const struct cipher_testvec *template, 1064b13b1e0cSEric Biggers unsigned int tcount, 10653a338f20SJussi Kivilinna const bool diff_dst, const int align_offset) 1066da7f033dSHerbert Xu { 1067da7f033dSHerbert Xu const char *algo = 106812773d93SHerbert Xu crypto_tfm_alg_driver_name(crypto_skcipher_tfm(tfm)); 1069da7f033dSHerbert Xu unsigned int i, j, k, n, temp; 1070da7f033dSHerbert Xu char *q; 107112773d93SHerbert Xu struct skcipher_request *req; 1072da7f033dSHerbert Xu struct scatterlist sg[8]; 107308d6af8cSJussi Kivilinna struct scatterlist sgout[8]; 107408d6af8cSJussi Kivilinna const char *e, *d; 10757f397136SGilad Ben-Yossef struct crypto_wait wait; 1076da7f033dSHerbert Xu void *data; 1077da7f033dSHerbert Xu char iv[MAX_IVLEN]; 1078f8b0d4d0SHerbert Xu char *xbuf[XBUFSIZE]; 107908d6af8cSJussi Kivilinna char *xoutbuf[XBUFSIZE]; 1080f8b0d4d0SHerbert Xu int ret = -ENOMEM; 108184cba178SAndrey Ryabinin unsigned int ivsize = crypto_skcipher_ivsize(tfm); 1082f8b0d4d0SHerbert Xu 1083f8b0d4d0SHerbert Xu if (testmgr_alloc_buf(xbuf)) 1084f8b0d4d0SHerbert Xu goto out_nobuf; 1085da7f033dSHerbert Xu 108608d6af8cSJussi Kivilinna if (diff_dst && testmgr_alloc_buf(xoutbuf)) 108708d6af8cSJussi Kivilinna goto out_nooutbuf; 108808d6af8cSJussi Kivilinna 108908d6af8cSJussi Kivilinna if (diff_dst) 109008d6af8cSJussi Kivilinna d = "-ddst"; 109108d6af8cSJussi Kivilinna else 109208d6af8cSJussi Kivilinna d = ""; 109308d6af8cSJussi Kivilinna 1094da7f033dSHerbert Xu if (enc == ENCRYPT) 1095da7f033dSHerbert Xu e = "encryption"; 1096da7f033dSHerbert Xu else 1097da7f033dSHerbert Xu e = "decryption"; 1098da7f033dSHerbert Xu 10997f397136SGilad Ben-Yossef crypto_init_wait(&wait); 1100da7f033dSHerbert Xu 110112773d93SHerbert Xu req = skcipher_request_alloc(tfm, GFP_KERNEL); 1102da7f033dSHerbert Xu if (!req) { 110308d6af8cSJussi Kivilinna pr_err("alg: skcipher%s: Failed to allocate request for %s\n", 110408d6af8cSJussi Kivilinna d, algo); 1105da7f033dSHerbert Xu goto out; 1106da7f033dSHerbert Xu } 1107da7f033dSHerbert Xu 110812773d93SHerbert Xu skcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, 11097f397136SGilad Ben-Yossef crypto_req_done, &wait); 1110da7f033dSHerbert Xu 1111da7f033dSHerbert Xu j = 0; 1112da7f033dSHerbert Xu for (i = 0; i < tcount; i++) { 1113bbb9a7ddSCristian Stoica if (template[i].np && !template[i].also_non_np) 1114bbb9a7ddSCristian Stoica continue; 1115bbb9a7ddSCristian Stoica 111610faa8c0SStephan Mueller if (fips_enabled && template[i].fips_skip) 111710faa8c0SStephan Mueller continue; 111810faa8c0SStephan Mueller 1119da7f033dSHerbert Xu if (template[i].iv) 112084cba178SAndrey Ryabinin memcpy(iv, template[i].iv, ivsize); 1121da7f033dSHerbert Xu else 1122da7f033dSHerbert Xu memset(iv, 0, MAX_IVLEN); 1123da7f033dSHerbert Xu 1124da7f033dSHerbert Xu j++; 1125fd57f22aSHerbert Xu ret = -EINVAL; 1126a1aa44a2SCristian Stoica if (WARN_ON(align_offset + template[i].ilen > PAGE_SIZE)) 1127fd57f22aSHerbert Xu goto out; 1128fd57f22aSHerbert Xu 1129da7f033dSHerbert Xu data = xbuf[0]; 11303a338f20SJussi Kivilinna data += align_offset; 1131da7f033dSHerbert Xu memcpy(data, template[i].input, template[i].ilen); 1132da7f033dSHerbert Xu 113312773d93SHerbert Xu crypto_skcipher_clear_flags(tfm, ~0); 1134da7f033dSHerbert Xu if (template[i].wk) 113512773d93SHerbert Xu crypto_skcipher_set_flags(tfm, 113612773d93SHerbert Xu CRYPTO_TFM_REQ_WEAK_KEY); 1137da7f033dSHerbert Xu 113812773d93SHerbert Xu ret = crypto_skcipher_setkey(tfm, template[i].key, 1139da7f033dSHerbert Xu template[i].klen); 11400fae0c1eSYanjiang Jin if (template[i].fail == !ret) { 114108d6af8cSJussi Kivilinna pr_err("alg: skcipher%s: setkey failed on test %d for %s: flags=%x\n", 114212773d93SHerbert Xu d, j, algo, crypto_skcipher_get_flags(tfm)); 1143da7f033dSHerbert Xu goto out; 1144da7f033dSHerbert Xu } else if (ret) 1145da7f033dSHerbert Xu continue; 1146da7f033dSHerbert Xu 1147da7f033dSHerbert Xu sg_init_one(&sg[0], data, template[i].ilen); 114808d6af8cSJussi Kivilinna if (diff_dst) { 114908d6af8cSJussi Kivilinna data = xoutbuf[0]; 11503a338f20SJussi Kivilinna data += align_offset; 115108d6af8cSJussi Kivilinna sg_init_one(&sgout[0], data, template[i].ilen); 115208d6af8cSJussi Kivilinna } 1153da7f033dSHerbert Xu 115412773d93SHerbert Xu skcipher_request_set_crypt(req, sg, (diff_dst) ? sgout : sg, 1155da7f033dSHerbert Xu template[i].ilen, iv); 11567f397136SGilad Ben-Yossef ret = crypto_wait_req(enc ? crypto_skcipher_encrypt(req) : 11577f397136SGilad Ben-Yossef crypto_skcipher_decrypt(req), &wait); 1158da7f033dSHerbert Xu 11597f397136SGilad Ben-Yossef if (ret) { 116008d6af8cSJussi Kivilinna pr_err("alg: skcipher%s: %s failed on test %d for %s: ret=%d\n", 116108d6af8cSJussi Kivilinna d, e, j, algo, -ret); 1162da7f033dSHerbert Xu goto out; 1163da7f033dSHerbert Xu } 1164da7f033dSHerbert Xu 1165da7f033dSHerbert Xu q = data; 1166da7f033dSHerbert Xu if (memcmp(q, template[i].result, template[i].rlen)) { 11678a826a34SBoris BREZILLON pr_err("alg: skcipher%s: Test %d failed (invalid result) on %s for %s\n", 116808d6af8cSJussi Kivilinna d, j, e, algo); 1169da7f033dSHerbert Xu hexdump(q, template[i].rlen); 1170da7f033dSHerbert Xu ret = -EINVAL; 1171da7f033dSHerbert Xu goto out; 1172da7f033dSHerbert Xu } 11738a826a34SBoris BREZILLON 11748a826a34SBoris BREZILLON if (template[i].iv_out && 11758a826a34SBoris BREZILLON memcmp(iv, template[i].iv_out, 11768a826a34SBoris BREZILLON crypto_skcipher_ivsize(tfm))) { 11778a826a34SBoris BREZILLON pr_err("alg: skcipher%s: Test %d failed (invalid output IV) on %s for %s\n", 11788a826a34SBoris BREZILLON d, j, e, algo); 11798a826a34SBoris BREZILLON hexdump(iv, crypto_skcipher_ivsize(tfm)); 11808a826a34SBoris BREZILLON ret = -EINVAL; 11818a826a34SBoris BREZILLON goto out; 11828a826a34SBoris BREZILLON } 1183da7f033dSHerbert Xu } 1184da7f033dSHerbert Xu 1185da7f033dSHerbert Xu j = 0; 1186da7f033dSHerbert Xu for (i = 0; i < tcount; i++) { 11873a338f20SJussi Kivilinna /* alignment tests are only done with continuous buffers */ 11883a338f20SJussi Kivilinna if (align_offset != 0) 11893a338f20SJussi Kivilinna break; 1190da7f033dSHerbert Xu 1191bbb9a7ddSCristian Stoica if (!template[i].np) 1192bbb9a7ddSCristian Stoica continue; 1193bbb9a7ddSCristian Stoica 119410faa8c0SStephan Mueller if (fips_enabled && template[i].fips_skip) 119510faa8c0SStephan Mueller continue; 119610faa8c0SStephan Mueller 1197da7f033dSHerbert Xu if (template[i].iv) 119884cba178SAndrey Ryabinin memcpy(iv, template[i].iv, ivsize); 1199da7f033dSHerbert Xu else 1200da7f033dSHerbert Xu memset(iv, 0, MAX_IVLEN); 1201da7f033dSHerbert Xu 1202da7f033dSHerbert Xu j++; 120312773d93SHerbert Xu crypto_skcipher_clear_flags(tfm, ~0); 1204da7f033dSHerbert Xu if (template[i].wk) 120512773d93SHerbert Xu crypto_skcipher_set_flags(tfm, 120612773d93SHerbert Xu CRYPTO_TFM_REQ_WEAK_KEY); 1207da7f033dSHerbert Xu 120812773d93SHerbert Xu ret = crypto_skcipher_setkey(tfm, template[i].key, 1209da7f033dSHerbert Xu template[i].klen); 12100fae0c1eSYanjiang Jin if (template[i].fail == !ret) { 121108d6af8cSJussi Kivilinna pr_err("alg: skcipher%s: setkey failed on chunk test %d for %s: flags=%x\n", 121212773d93SHerbert Xu d, j, algo, crypto_skcipher_get_flags(tfm)); 1213da7f033dSHerbert Xu goto out; 1214da7f033dSHerbert Xu } else if (ret) 1215da7f033dSHerbert Xu continue; 1216da7f033dSHerbert Xu 1217da7f033dSHerbert Xu temp = 0; 1218da7f033dSHerbert Xu ret = -EINVAL; 1219da7f033dSHerbert Xu sg_init_table(sg, template[i].np); 122008d6af8cSJussi Kivilinna if (diff_dst) 122108d6af8cSJussi Kivilinna sg_init_table(sgout, template[i].np); 1222da7f033dSHerbert Xu for (k = 0; k < template[i].np; k++) { 1223da7f033dSHerbert Xu if (WARN_ON(offset_in_page(IDX[k]) + 1224da7f033dSHerbert Xu template[i].tap[k] > PAGE_SIZE)) 1225da7f033dSHerbert Xu goto out; 1226da7f033dSHerbert Xu 1227a1aa44a2SCristian Stoica q = xbuf[IDX[k] >> PAGE_SHIFT] + offset_in_page(IDX[k]); 1228da7f033dSHerbert Xu 1229a1aa44a2SCristian Stoica memcpy(q, template[i].input + temp, template[i].tap[k]); 1230da7f033dSHerbert Xu 1231a1aa44a2SCristian Stoica if (offset_in_page(q) + template[i].tap[k] < PAGE_SIZE) 1232da7f033dSHerbert Xu q[template[i].tap[k]] = 0; 1233da7f033dSHerbert Xu 1234da7f033dSHerbert Xu sg_set_buf(&sg[k], q, template[i].tap[k]); 123508d6af8cSJussi Kivilinna if (diff_dst) { 123608d6af8cSJussi Kivilinna q = xoutbuf[IDX[k] >> PAGE_SHIFT] + 123708d6af8cSJussi Kivilinna offset_in_page(IDX[k]); 123808d6af8cSJussi Kivilinna 1239a1aa44a2SCristian Stoica sg_set_buf(&sgout[k], q, template[i].tap[k]); 124008d6af8cSJussi Kivilinna 124108d6af8cSJussi Kivilinna memset(q, 0, template[i].tap[k]); 124208d6af8cSJussi Kivilinna if (offset_in_page(q) + 124308d6af8cSJussi Kivilinna template[i].tap[k] < PAGE_SIZE) 124408d6af8cSJussi Kivilinna q[template[i].tap[k]] = 0; 124508d6af8cSJussi Kivilinna } 1246da7f033dSHerbert Xu 1247da7f033dSHerbert Xu temp += template[i].tap[k]; 1248da7f033dSHerbert Xu } 1249da7f033dSHerbert Xu 125012773d93SHerbert Xu skcipher_request_set_crypt(req, sg, (diff_dst) ? sgout : sg, 1251da7f033dSHerbert Xu template[i].ilen, iv); 1252da7f033dSHerbert Xu 12537f397136SGilad Ben-Yossef ret = crypto_wait_req(enc ? crypto_skcipher_encrypt(req) : 12547f397136SGilad Ben-Yossef crypto_skcipher_decrypt(req), &wait); 1255da7f033dSHerbert Xu 12567f397136SGilad Ben-Yossef if (ret) { 125708d6af8cSJussi Kivilinna pr_err("alg: skcipher%s: %s failed on chunk test %d for %s: ret=%d\n", 125808d6af8cSJussi Kivilinna d, e, j, algo, -ret); 1259da7f033dSHerbert Xu goto out; 1260da7f033dSHerbert Xu } 1261da7f033dSHerbert Xu 1262da7f033dSHerbert Xu temp = 0; 1263da7f033dSHerbert Xu ret = -EINVAL; 1264da7f033dSHerbert Xu for (k = 0; k < template[i].np; k++) { 126508d6af8cSJussi Kivilinna if (diff_dst) 126608d6af8cSJussi Kivilinna q = xoutbuf[IDX[k] >> PAGE_SHIFT] + 126708d6af8cSJussi Kivilinna offset_in_page(IDX[k]); 126808d6af8cSJussi Kivilinna else 1269da7f033dSHerbert Xu q = xbuf[IDX[k] >> PAGE_SHIFT] + 1270da7f033dSHerbert Xu offset_in_page(IDX[k]); 1271da7f033dSHerbert Xu 1272da7f033dSHerbert Xu if (memcmp(q, template[i].result + temp, 1273da7f033dSHerbert Xu template[i].tap[k])) { 127408d6af8cSJussi Kivilinna pr_err("alg: skcipher%s: Chunk test %d failed on %s at page %u for %s\n", 127508d6af8cSJussi Kivilinna d, j, e, k, algo); 1276da7f033dSHerbert Xu hexdump(q, template[i].tap[k]); 1277da7f033dSHerbert Xu goto out; 1278da7f033dSHerbert Xu } 1279da7f033dSHerbert Xu 1280da7f033dSHerbert Xu q += template[i].tap[k]; 1281da7f033dSHerbert Xu for (n = 0; offset_in_page(q + n) && q[n]; n++) 1282da7f033dSHerbert Xu ; 1283da7f033dSHerbert Xu if (n) { 128408d6af8cSJussi Kivilinna pr_err("alg: skcipher%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n", 128508d6af8cSJussi Kivilinna d, j, e, k, algo, n); 1286da7f033dSHerbert Xu hexdump(q, n); 1287da7f033dSHerbert Xu goto out; 1288da7f033dSHerbert Xu } 1289da7f033dSHerbert Xu temp += template[i].tap[k]; 1290da7f033dSHerbert Xu } 1291da7f033dSHerbert Xu } 1292da7f033dSHerbert Xu 1293da7f033dSHerbert Xu ret = 0; 1294da7f033dSHerbert Xu 1295da7f033dSHerbert Xu out: 129612773d93SHerbert Xu skcipher_request_free(req); 129708d6af8cSJussi Kivilinna if (diff_dst) 129808d6af8cSJussi Kivilinna testmgr_free_buf(xoutbuf); 129908d6af8cSJussi Kivilinna out_nooutbuf: 1300f8b0d4d0SHerbert Xu testmgr_free_buf(xbuf); 1301f8b0d4d0SHerbert Xu out_nobuf: 1302da7f033dSHerbert Xu return ret; 1303da7f033dSHerbert Xu } 1304da7f033dSHerbert Xu 130512773d93SHerbert Xu static int test_skcipher(struct crypto_skcipher *tfm, int enc, 1306b13b1e0cSEric Biggers const struct cipher_testvec *template, 1307b13b1e0cSEric Biggers unsigned int tcount) 130808d6af8cSJussi Kivilinna { 13093a338f20SJussi Kivilinna unsigned int alignmask; 131008d6af8cSJussi Kivilinna int ret; 131108d6af8cSJussi Kivilinna 131208d6af8cSJussi Kivilinna /* test 'dst == src' case */ 13133a338f20SJussi Kivilinna ret = __test_skcipher(tfm, enc, template, tcount, false, 0); 131408d6af8cSJussi Kivilinna if (ret) 131508d6af8cSJussi Kivilinna return ret; 131608d6af8cSJussi Kivilinna 131708d6af8cSJussi Kivilinna /* test 'dst != src' case */ 13183a338f20SJussi Kivilinna ret = __test_skcipher(tfm, enc, template, tcount, true, 0); 13193a338f20SJussi Kivilinna if (ret) 13203a338f20SJussi Kivilinna return ret; 13213a338f20SJussi Kivilinna 13223a338f20SJussi Kivilinna /* test unaligned buffers, check with one byte offset */ 13233a338f20SJussi Kivilinna ret = __test_skcipher(tfm, enc, template, tcount, true, 1); 13243a338f20SJussi Kivilinna if (ret) 13253a338f20SJussi Kivilinna return ret; 13263a338f20SJussi Kivilinna 13273a338f20SJussi Kivilinna alignmask = crypto_tfm_alg_alignmask(&tfm->base); 13283a338f20SJussi Kivilinna if (alignmask) { 13293a338f20SJussi Kivilinna /* Check if alignment mask for tfm is correctly set. */ 13303a338f20SJussi Kivilinna ret = __test_skcipher(tfm, enc, template, tcount, true, 13313a338f20SJussi Kivilinna alignmask + 1); 13323a338f20SJussi Kivilinna if (ret) 13333a338f20SJussi Kivilinna return ret; 13343a338f20SJussi Kivilinna } 13353a338f20SJussi Kivilinna 13363a338f20SJussi Kivilinna return 0; 133708d6af8cSJussi Kivilinna } 133808d6af8cSJussi Kivilinna 1339b13b1e0cSEric Biggers static int test_comp(struct crypto_comp *tfm, 1340b13b1e0cSEric Biggers const struct comp_testvec *ctemplate, 1341b13b1e0cSEric Biggers const struct comp_testvec *dtemplate, 1342b13b1e0cSEric Biggers int ctcount, int dtcount) 1343da7f033dSHerbert Xu { 1344da7f033dSHerbert Xu const char *algo = crypto_tfm_alg_driver_name(crypto_comp_tfm(tfm)); 1345da7f033dSHerbert Xu unsigned int i; 1346da7f033dSHerbert Xu char result[COMP_BUF_SIZE]; 1347da7f033dSHerbert Xu int ret; 1348da7f033dSHerbert Xu 1349da7f033dSHerbert Xu for (i = 0; i < ctcount; i++) { 1350c79cf910SGeert Uytterhoeven int ilen; 1351c79cf910SGeert Uytterhoeven unsigned int dlen = COMP_BUF_SIZE; 1352da7f033dSHerbert Xu 1353da7f033dSHerbert Xu memset(result, 0, sizeof (result)); 1354da7f033dSHerbert Xu 1355da7f033dSHerbert Xu ilen = ctemplate[i].inlen; 1356da7f033dSHerbert Xu ret = crypto_comp_compress(tfm, ctemplate[i].input, 1357da7f033dSHerbert Xu ilen, result, &dlen); 1358da7f033dSHerbert Xu if (ret) { 1359da7f033dSHerbert Xu printk(KERN_ERR "alg: comp: compression failed " 1360da7f033dSHerbert Xu "on test %d for %s: ret=%d\n", i + 1, algo, 1361da7f033dSHerbert Xu -ret); 1362da7f033dSHerbert Xu goto out; 1363da7f033dSHerbert Xu } 1364da7f033dSHerbert Xu 1365b812eb00SGeert Uytterhoeven if (dlen != ctemplate[i].outlen) { 1366b812eb00SGeert Uytterhoeven printk(KERN_ERR "alg: comp: Compression test %d " 1367b812eb00SGeert Uytterhoeven "failed for %s: output len = %d\n", i + 1, algo, 1368b812eb00SGeert Uytterhoeven dlen); 1369b812eb00SGeert Uytterhoeven ret = -EINVAL; 1370b812eb00SGeert Uytterhoeven goto out; 1371b812eb00SGeert Uytterhoeven } 1372b812eb00SGeert Uytterhoeven 1373da7f033dSHerbert Xu if (memcmp(result, ctemplate[i].output, dlen)) { 1374da7f033dSHerbert Xu printk(KERN_ERR "alg: comp: Compression test %d " 1375da7f033dSHerbert Xu "failed for %s\n", i + 1, algo); 1376da7f033dSHerbert Xu hexdump(result, dlen); 1377da7f033dSHerbert Xu ret = -EINVAL; 1378da7f033dSHerbert Xu goto out; 1379da7f033dSHerbert Xu } 1380da7f033dSHerbert Xu } 1381da7f033dSHerbert Xu 1382da7f033dSHerbert Xu for (i = 0; i < dtcount; i++) { 1383c79cf910SGeert Uytterhoeven int ilen; 1384c79cf910SGeert Uytterhoeven unsigned int dlen = COMP_BUF_SIZE; 1385da7f033dSHerbert Xu 1386da7f033dSHerbert Xu memset(result, 0, sizeof (result)); 1387da7f033dSHerbert Xu 1388da7f033dSHerbert Xu ilen = dtemplate[i].inlen; 1389da7f033dSHerbert Xu ret = crypto_comp_decompress(tfm, dtemplate[i].input, 1390da7f033dSHerbert Xu ilen, result, &dlen); 1391da7f033dSHerbert Xu if (ret) { 1392da7f033dSHerbert Xu printk(KERN_ERR "alg: comp: decompression failed " 1393da7f033dSHerbert Xu "on test %d for %s: ret=%d\n", i + 1, algo, 1394da7f033dSHerbert Xu -ret); 1395da7f033dSHerbert Xu goto out; 1396da7f033dSHerbert Xu } 1397da7f033dSHerbert Xu 1398b812eb00SGeert Uytterhoeven if (dlen != dtemplate[i].outlen) { 1399b812eb00SGeert Uytterhoeven printk(KERN_ERR "alg: comp: Decompression test %d " 1400b812eb00SGeert Uytterhoeven "failed for %s: output len = %d\n", i + 1, algo, 1401b812eb00SGeert Uytterhoeven dlen); 1402b812eb00SGeert Uytterhoeven ret = -EINVAL; 1403b812eb00SGeert Uytterhoeven goto out; 1404b812eb00SGeert Uytterhoeven } 1405b812eb00SGeert Uytterhoeven 1406da7f033dSHerbert Xu if (memcmp(result, dtemplate[i].output, dlen)) { 1407da7f033dSHerbert Xu printk(KERN_ERR "alg: comp: Decompression test %d " 1408da7f033dSHerbert Xu "failed for %s\n", i + 1, algo); 1409da7f033dSHerbert Xu hexdump(result, dlen); 1410da7f033dSHerbert Xu ret = -EINVAL; 1411da7f033dSHerbert Xu goto out; 1412da7f033dSHerbert Xu } 1413da7f033dSHerbert Xu } 1414da7f033dSHerbert Xu 1415da7f033dSHerbert Xu ret = 0; 1416da7f033dSHerbert Xu 1417da7f033dSHerbert Xu out: 1418da7f033dSHerbert Xu return ret; 1419da7f033dSHerbert Xu } 1420da7f033dSHerbert Xu 1421b13b1e0cSEric Biggers static int test_acomp(struct crypto_acomp *tfm, 1422b13b1e0cSEric Biggers const struct comp_testvec *ctemplate, 1423b13b1e0cSEric Biggers const struct comp_testvec *dtemplate, 1424b13b1e0cSEric Biggers int ctcount, int dtcount) 1425d7db7a88SGiovanni Cabiddu { 1426d7db7a88SGiovanni Cabiddu const char *algo = crypto_tfm_alg_driver_name(crypto_acomp_tfm(tfm)); 1427d7db7a88SGiovanni Cabiddu unsigned int i; 1428a9943a0aSGiovanni Cabiddu char *output, *decomp_out; 1429d7db7a88SGiovanni Cabiddu int ret; 1430d7db7a88SGiovanni Cabiddu struct scatterlist src, dst; 1431d7db7a88SGiovanni Cabiddu struct acomp_req *req; 14327f397136SGilad Ben-Yossef struct crypto_wait wait; 1433d7db7a88SGiovanni Cabiddu 1434eb095593SEric Biggers output = kmalloc(COMP_BUF_SIZE, GFP_KERNEL); 1435eb095593SEric Biggers if (!output) 1436eb095593SEric Biggers return -ENOMEM; 1437eb095593SEric Biggers 1438a9943a0aSGiovanni Cabiddu decomp_out = kmalloc(COMP_BUF_SIZE, GFP_KERNEL); 1439a9943a0aSGiovanni Cabiddu if (!decomp_out) { 1440a9943a0aSGiovanni Cabiddu kfree(output); 1441a9943a0aSGiovanni Cabiddu return -ENOMEM; 1442a9943a0aSGiovanni Cabiddu } 1443a9943a0aSGiovanni Cabiddu 1444d7db7a88SGiovanni Cabiddu for (i = 0; i < ctcount; i++) { 1445d7db7a88SGiovanni Cabiddu unsigned int dlen = COMP_BUF_SIZE; 1446d7db7a88SGiovanni Cabiddu int ilen = ctemplate[i].inlen; 144702608e02SLaura Abbott void *input_vec; 1448d7db7a88SGiovanni Cabiddu 1449d2110224SEric Biggers input_vec = kmemdup(ctemplate[i].input, ilen, GFP_KERNEL); 145002608e02SLaura Abbott if (!input_vec) { 145102608e02SLaura Abbott ret = -ENOMEM; 145202608e02SLaura Abbott goto out; 145302608e02SLaura Abbott } 145402608e02SLaura Abbott 1455eb095593SEric Biggers memset(output, 0, dlen); 14567f397136SGilad Ben-Yossef crypto_init_wait(&wait); 145702608e02SLaura Abbott sg_init_one(&src, input_vec, ilen); 1458d7db7a88SGiovanni Cabiddu sg_init_one(&dst, output, dlen); 1459d7db7a88SGiovanni Cabiddu 1460d7db7a88SGiovanni Cabiddu req = acomp_request_alloc(tfm); 1461d7db7a88SGiovanni Cabiddu if (!req) { 1462d7db7a88SGiovanni Cabiddu pr_err("alg: acomp: request alloc failed for %s\n", 1463d7db7a88SGiovanni Cabiddu algo); 146402608e02SLaura Abbott kfree(input_vec); 1465d7db7a88SGiovanni Cabiddu ret = -ENOMEM; 1466d7db7a88SGiovanni Cabiddu goto out; 1467d7db7a88SGiovanni Cabiddu } 1468d7db7a88SGiovanni Cabiddu 1469d7db7a88SGiovanni Cabiddu acomp_request_set_params(req, &src, &dst, ilen, dlen); 1470d7db7a88SGiovanni Cabiddu acomp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, 14717f397136SGilad Ben-Yossef crypto_req_done, &wait); 1472d7db7a88SGiovanni Cabiddu 14737f397136SGilad Ben-Yossef ret = crypto_wait_req(crypto_acomp_compress(req), &wait); 1474d7db7a88SGiovanni Cabiddu if (ret) { 1475d7db7a88SGiovanni Cabiddu pr_err("alg: acomp: compression failed on test %d for %s: ret=%d\n", 1476d7db7a88SGiovanni Cabiddu i + 1, algo, -ret); 147702608e02SLaura Abbott kfree(input_vec); 1478d7db7a88SGiovanni Cabiddu acomp_request_free(req); 1479d7db7a88SGiovanni Cabiddu goto out; 1480d7db7a88SGiovanni Cabiddu } 1481d7db7a88SGiovanni Cabiddu 1482a9943a0aSGiovanni Cabiddu ilen = req->dlen; 1483a9943a0aSGiovanni Cabiddu dlen = COMP_BUF_SIZE; 1484a9943a0aSGiovanni Cabiddu sg_init_one(&src, output, ilen); 1485a9943a0aSGiovanni Cabiddu sg_init_one(&dst, decomp_out, dlen); 14867f397136SGilad Ben-Yossef crypto_init_wait(&wait); 1487a9943a0aSGiovanni Cabiddu acomp_request_set_params(req, &src, &dst, ilen, dlen); 1488a9943a0aSGiovanni Cabiddu 14897f397136SGilad Ben-Yossef ret = crypto_wait_req(crypto_acomp_decompress(req), &wait); 1490a9943a0aSGiovanni Cabiddu if (ret) { 1491a9943a0aSGiovanni Cabiddu pr_err("alg: acomp: compression failed on test %d for %s: ret=%d\n", 1492a9943a0aSGiovanni Cabiddu i + 1, algo, -ret); 1493a9943a0aSGiovanni Cabiddu kfree(input_vec); 1494a9943a0aSGiovanni Cabiddu acomp_request_free(req); 1495a9943a0aSGiovanni Cabiddu goto out; 1496a9943a0aSGiovanni Cabiddu } 1497a9943a0aSGiovanni Cabiddu 1498a9943a0aSGiovanni Cabiddu if (req->dlen != ctemplate[i].inlen) { 1499d7db7a88SGiovanni Cabiddu pr_err("alg: acomp: Compression test %d failed for %s: output len = %d\n", 1500d7db7a88SGiovanni Cabiddu i + 1, algo, req->dlen); 1501d7db7a88SGiovanni Cabiddu ret = -EINVAL; 150202608e02SLaura Abbott kfree(input_vec); 1503d7db7a88SGiovanni Cabiddu acomp_request_free(req); 1504d7db7a88SGiovanni Cabiddu goto out; 1505d7db7a88SGiovanni Cabiddu } 1506d7db7a88SGiovanni Cabiddu 1507a9943a0aSGiovanni Cabiddu if (memcmp(input_vec, decomp_out, req->dlen)) { 1508d7db7a88SGiovanni Cabiddu pr_err("alg: acomp: Compression test %d failed for %s\n", 1509d7db7a88SGiovanni Cabiddu i + 1, algo); 1510d7db7a88SGiovanni Cabiddu hexdump(output, req->dlen); 1511d7db7a88SGiovanni Cabiddu ret = -EINVAL; 151202608e02SLaura Abbott kfree(input_vec); 1513d7db7a88SGiovanni Cabiddu acomp_request_free(req); 1514d7db7a88SGiovanni Cabiddu goto out; 1515d7db7a88SGiovanni Cabiddu } 1516d7db7a88SGiovanni Cabiddu 151702608e02SLaura Abbott kfree(input_vec); 1518d7db7a88SGiovanni Cabiddu acomp_request_free(req); 1519d7db7a88SGiovanni Cabiddu } 1520d7db7a88SGiovanni Cabiddu 1521d7db7a88SGiovanni Cabiddu for (i = 0; i < dtcount; i++) { 1522d7db7a88SGiovanni Cabiddu unsigned int dlen = COMP_BUF_SIZE; 1523d7db7a88SGiovanni Cabiddu int ilen = dtemplate[i].inlen; 152402608e02SLaura Abbott void *input_vec; 1525d7db7a88SGiovanni Cabiddu 1526d2110224SEric Biggers input_vec = kmemdup(dtemplate[i].input, ilen, GFP_KERNEL); 152702608e02SLaura Abbott if (!input_vec) { 152802608e02SLaura Abbott ret = -ENOMEM; 152902608e02SLaura Abbott goto out; 153002608e02SLaura Abbott } 153102608e02SLaura Abbott 1532eb095593SEric Biggers memset(output, 0, dlen); 15337f397136SGilad Ben-Yossef crypto_init_wait(&wait); 153402608e02SLaura Abbott sg_init_one(&src, input_vec, ilen); 1535d7db7a88SGiovanni Cabiddu sg_init_one(&dst, output, dlen); 1536d7db7a88SGiovanni Cabiddu 1537d7db7a88SGiovanni Cabiddu req = acomp_request_alloc(tfm); 1538d7db7a88SGiovanni Cabiddu if (!req) { 1539d7db7a88SGiovanni Cabiddu pr_err("alg: acomp: request alloc failed for %s\n", 1540d7db7a88SGiovanni Cabiddu algo); 154102608e02SLaura Abbott kfree(input_vec); 1542d7db7a88SGiovanni Cabiddu ret = -ENOMEM; 1543d7db7a88SGiovanni Cabiddu goto out; 1544d7db7a88SGiovanni Cabiddu } 1545d7db7a88SGiovanni Cabiddu 1546d7db7a88SGiovanni Cabiddu acomp_request_set_params(req, &src, &dst, ilen, dlen); 1547d7db7a88SGiovanni Cabiddu acomp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, 15487f397136SGilad Ben-Yossef crypto_req_done, &wait); 1549d7db7a88SGiovanni Cabiddu 15507f397136SGilad Ben-Yossef ret = crypto_wait_req(crypto_acomp_decompress(req), &wait); 1551d7db7a88SGiovanni Cabiddu if (ret) { 1552d7db7a88SGiovanni Cabiddu pr_err("alg: acomp: decompression failed on test %d for %s: ret=%d\n", 1553d7db7a88SGiovanni Cabiddu i + 1, algo, -ret); 155402608e02SLaura Abbott kfree(input_vec); 1555d7db7a88SGiovanni Cabiddu acomp_request_free(req); 1556d7db7a88SGiovanni Cabiddu goto out; 1557d7db7a88SGiovanni Cabiddu } 1558d7db7a88SGiovanni Cabiddu 1559d7db7a88SGiovanni Cabiddu if (req->dlen != dtemplate[i].outlen) { 1560d7db7a88SGiovanni Cabiddu pr_err("alg: acomp: Decompression test %d failed for %s: output len = %d\n", 1561d7db7a88SGiovanni Cabiddu i + 1, algo, req->dlen); 1562d7db7a88SGiovanni Cabiddu ret = -EINVAL; 156302608e02SLaura Abbott kfree(input_vec); 1564d7db7a88SGiovanni Cabiddu acomp_request_free(req); 1565d7db7a88SGiovanni Cabiddu goto out; 1566d7db7a88SGiovanni Cabiddu } 1567d7db7a88SGiovanni Cabiddu 1568d7db7a88SGiovanni Cabiddu if (memcmp(output, dtemplate[i].output, req->dlen)) { 1569d7db7a88SGiovanni Cabiddu pr_err("alg: acomp: Decompression test %d failed for %s\n", 1570d7db7a88SGiovanni Cabiddu i + 1, algo); 1571d7db7a88SGiovanni Cabiddu hexdump(output, req->dlen); 1572d7db7a88SGiovanni Cabiddu ret = -EINVAL; 157302608e02SLaura Abbott kfree(input_vec); 1574d7db7a88SGiovanni Cabiddu acomp_request_free(req); 1575d7db7a88SGiovanni Cabiddu goto out; 1576d7db7a88SGiovanni Cabiddu } 1577d7db7a88SGiovanni Cabiddu 157802608e02SLaura Abbott kfree(input_vec); 1579d7db7a88SGiovanni Cabiddu acomp_request_free(req); 1580d7db7a88SGiovanni Cabiddu } 1581d7db7a88SGiovanni Cabiddu 1582d7db7a88SGiovanni Cabiddu ret = 0; 1583d7db7a88SGiovanni Cabiddu 1584d7db7a88SGiovanni Cabiddu out: 1585a9943a0aSGiovanni Cabiddu kfree(decomp_out); 1586eb095593SEric Biggers kfree(output); 1587d7db7a88SGiovanni Cabiddu return ret; 1588d7db7a88SGiovanni Cabiddu } 1589d7db7a88SGiovanni Cabiddu 1590b13b1e0cSEric Biggers static int test_cprng(struct crypto_rng *tfm, 1591b13b1e0cSEric Biggers const struct cprng_testvec *template, 15927647d6ceSJarod Wilson unsigned int tcount) 15937647d6ceSJarod Wilson { 15947647d6ceSJarod Wilson const char *algo = crypto_tfm_alg_driver_name(crypto_rng_tfm(tfm)); 1595fa4ef8a6SFelipe Contreras int err = 0, i, j, seedsize; 15967647d6ceSJarod Wilson u8 *seed; 15977647d6ceSJarod Wilson char result[32]; 15987647d6ceSJarod Wilson 15997647d6ceSJarod Wilson seedsize = crypto_rng_seedsize(tfm); 16007647d6ceSJarod Wilson 16017647d6ceSJarod Wilson seed = kmalloc(seedsize, GFP_KERNEL); 16027647d6ceSJarod Wilson if (!seed) { 16037647d6ceSJarod Wilson printk(KERN_ERR "alg: cprng: Failed to allocate seed space " 16047647d6ceSJarod Wilson "for %s\n", algo); 16057647d6ceSJarod Wilson return -ENOMEM; 16067647d6ceSJarod Wilson } 16077647d6ceSJarod Wilson 16087647d6ceSJarod Wilson for (i = 0; i < tcount; i++) { 16097647d6ceSJarod Wilson memset(result, 0, 32); 16107647d6ceSJarod Wilson 16117647d6ceSJarod Wilson memcpy(seed, template[i].v, template[i].vlen); 16127647d6ceSJarod Wilson memcpy(seed + template[i].vlen, template[i].key, 16137647d6ceSJarod Wilson template[i].klen); 16147647d6ceSJarod Wilson memcpy(seed + template[i].vlen + template[i].klen, 16157647d6ceSJarod Wilson template[i].dt, template[i].dtlen); 16167647d6ceSJarod Wilson 16177647d6ceSJarod Wilson err = crypto_rng_reset(tfm, seed, seedsize); 16187647d6ceSJarod Wilson if (err) { 16197647d6ceSJarod Wilson printk(KERN_ERR "alg: cprng: Failed to reset rng " 16207647d6ceSJarod Wilson "for %s\n", algo); 16217647d6ceSJarod Wilson goto out; 16227647d6ceSJarod Wilson } 16237647d6ceSJarod Wilson 16247647d6ceSJarod Wilson for (j = 0; j < template[i].loops; j++) { 16257647d6ceSJarod Wilson err = crypto_rng_get_bytes(tfm, result, 16267647d6ceSJarod Wilson template[i].rlen); 162719e60e13SStephan Mueller if (err < 0) { 16287647d6ceSJarod Wilson printk(KERN_ERR "alg: cprng: Failed to obtain " 16297647d6ceSJarod Wilson "the correct amount of random data for " 163019e60e13SStephan Mueller "%s (requested %d)\n", algo, 163119e60e13SStephan Mueller template[i].rlen); 16327647d6ceSJarod Wilson goto out; 16337647d6ceSJarod Wilson } 16347647d6ceSJarod Wilson } 16357647d6ceSJarod Wilson 16367647d6ceSJarod Wilson err = memcmp(result, template[i].result, 16377647d6ceSJarod Wilson template[i].rlen); 16387647d6ceSJarod Wilson if (err) { 16397647d6ceSJarod Wilson printk(KERN_ERR "alg: cprng: Test %d failed for %s\n", 16407647d6ceSJarod Wilson i, algo); 16417647d6ceSJarod Wilson hexdump(result, template[i].rlen); 16427647d6ceSJarod Wilson err = -EINVAL; 16437647d6ceSJarod Wilson goto out; 16447647d6ceSJarod Wilson } 16457647d6ceSJarod Wilson } 16467647d6ceSJarod Wilson 16477647d6ceSJarod Wilson out: 16487647d6ceSJarod Wilson kfree(seed); 16497647d6ceSJarod Wilson return err; 16507647d6ceSJarod Wilson } 16517647d6ceSJarod Wilson 1652da7f033dSHerbert Xu static int alg_test_aead(const struct alg_test_desc *desc, const char *driver, 1653da7f033dSHerbert Xu u32 type, u32 mask) 1654da7f033dSHerbert Xu { 1655da7f033dSHerbert Xu struct crypto_aead *tfm; 1656da7f033dSHerbert Xu int err = 0; 1657da7f033dSHerbert Xu 1658eed93e0cSHerbert Xu tfm = crypto_alloc_aead(driver, type, mask); 1659da7f033dSHerbert Xu if (IS_ERR(tfm)) { 1660da7f033dSHerbert Xu printk(KERN_ERR "alg: aead: Failed to load transform for %s: " 1661da7f033dSHerbert Xu "%ld\n", driver, PTR_ERR(tfm)); 1662da7f033dSHerbert Xu return PTR_ERR(tfm); 1663da7f033dSHerbert Xu } 1664da7f033dSHerbert Xu 1665da7f033dSHerbert Xu if (desc->suite.aead.enc.vecs) { 1666da7f033dSHerbert Xu err = test_aead(tfm, ENCRYPT, desc->suite.aead.enc.vecs, 1667da7f033dSHerbert Xu desc->suite.aead.enc.count); 1668da7f033dSHerbert Xu if (err) 1669da7f033dSHerbert Xu goto out; 1670da7f033dSHerbert Xu } 1671da7f033dSHerbert Xu 1672da7f033dSHerbert Xu if (!err && desc->suite.aead.dec.vecs) 1673da7f033dSHerbert Xu err = test_aead(tfm, DECRYPT, desc->suite.aead.dec.vecs, 1674da7f033dSHerbert Xu desc->suite.aead.dec.count); 1675da7f033dSHerbert Xu 1676da7f033dSHerbert Xu out: 1677da7f033dSHerbert Xu crypto_free_aead(tfm); 1678da7f033dSHerbert Xu return err; 1679da7f033dSHerbert Xu } 1680da7f033dSHerbert Xu 1681da7f033dSHerbert Xu static int alg_test_cipher(const struct alg_test_desc *desc, 1682da7f033dSHerbert Xu const char *driver, u32 type, u32 mask) 1683da7f033dSHerbert Xu { 16841aa4ecd9SHerbert Xu struct crypto_cipher *tfm; 1685da7f033dSHerbert Xu int err = 0; 1686da7f033dSHerbert Xu 1687eed93e0cSHerbert Xu tfm = crypto_alloc_cipher(driver, type, mask); 1688da7f033dSHerbert Xu if (IS_ERR(tfm)) { 1689da7f033dSHerbert Xu printk(KERN_ERR "alg: cipher: Failed to load transform for " 1690da7f033dSHerbert Xu "%s: %ld\n", driver, PTR_ERR(tfm)); 1691da7f033dSHerbert Xu return PTR_ERR(tfm); 1692da7f033dSHerbert Xu } 1693da7f033dSHerbert Xu 1694da7f033dSHerbert Xu if (desc->suite.cipher.enc.vecs) { 1695da7f033dSHerbert Xu err = test_cipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs, 1696da7f033dSHerbert Xu desc->suite.cipher.enc.count); 1697da7f033dSHerbert Xu if (err) 1698da7f033dSHerbert Xu goto out; 1699da7f033dSHerbert Xu } 1700da7f033dSHerbert Xu 1701da7f033dSHerbert Xu if (desc->suite.cipher.dec.vecs) 1702da7f033dSHerbert Xu err = test_cipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs, 1703da7f033dSHerbert Xu desc->suite.cipher.dec.count); 1704da7f033dSHerbert Xu 1705da7f033dSHerbert Xu out: 17061aa4ecd9SHerbert Xu crypto_free_cipher(tfm); 17071aa4ecd9SHerbert Xu return err; 17081aa4ecd9SHerbert Xu } 17091aa4ecd9SHerbert Xu 17101aa4ecd9SHerbert Xu static int alg_test_skcipher(const struct alg_test_desc *desc, 17111aa4ecd9SHerbert Xu const char *driver, u32 type, u32 mask) 17121aa4ecd9SHerbert Xu { 171312773d93SHerbert Xu struct crypto_skcipher *tfm; 17141aa4ecd9SHerbert Xu int err = 0; 17151aa4ecd9SHerbert Xu 1716eed93e0cSHerbert Xu tfm = crypto_alloc_skcipher(driver, type, mask); 17171aa4ecd9SHerbert Xu if (IS_ERR(tfm)) { 17181aa4ecd9SHerbert Xu printk(KERN_ERR "alg: skcipher: Failed to load transform for " 17191aa4ecd9SHerbert Xu "%s: %ld\n", driver, PTR_ERR(tfm)); 17201aa4ecd9SHerbert Xu return PTR_ERR(tfm); 17211aa4ecd9SHerbert Xu } 17221aa4ecd9SHerbert Xu 17231aa4ecd9SHerbert Xu if (desc->suite.cipher.enc.vecs) { 17241aa4ecd9SHerbert Xu err = test_skcipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs, 17251aa4ecd9SHerbert Xu desc->suite.cipher.enc.count); 17261aa4ecd9SHerbert Xu if (err) 17271aa4ecd9SHerbert Xu goto out; 17281aa4ecd9SHerbert Xu } 17291aa4ecd9SHerbert Xu 17301aa4ecd9SHerbert Xu if (desc->suite.cipher.dec.vecs) 17311aa4ecd9SHerbert Xu err = test_skcipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs, 17321aa4ecd9SHerbert Xu desc->suite.cipher.dec.count); 17331aa4ecd9SHerbert Xu 17341aa4ecd9SHerbert Xu out: 173512773d93SHerbert Xu crypto_free_skcipher(tfm); 1736da7f033dSHerbert Xu return err; 1737da7f033dSHerbert Xu } 1738da7f033dSHerbert Xu 1739da7f033dSHerbert Xu static int alg_test_comp(const struct alg_test_desc *desc, const char *driver, 1740da7f033dSHerbert Xu u32 type, u32 mask) 1741da7f033dSHerbert Xu { 1742d7db7a88SGiovanni Cabiddu struct crypto_comp *comp; 1743d7db7a88SGiovanni Cabiddu struct crypto_acomp *acomp; 1744da7f033dSHerbert Xu int err; 1745d7db7a88SGiovanni Cabiddu u32 algo_type = type & CRYPTO_ALG_TYPE_ACOMPRESS_MASK; 1746da7f033dSHerbert Xu 1747d7db7a88SGiovanni Cabiddu if (algo_type == CRYPTO_ALG_TYPE_ACOMPRESS) { 1748d7db7a88SGiovanni Cabiddu acomp = crypto_alloc_acomp(driver, type, mask); 1749d7db7a88SGiovanni Cabiddu if (IS_ERR(acomp)) { 1750d7db7a88SGiovanni Cabiddu pr_err("alg: acomp: Failed to load transform for %s: %ld\n", 1751d7db7a88SGiovanni Cabiddu driver, PTR_ERR(acomp)); 1752d7db7a88SGiovanni Cabiddu return PTR_ERR(acomp); 1753d7db7a88SGiovanni Cabiddu } 1754d7db7a88SGiovanni Cabiddu err = test_acomp(acomp, desc->suite.comp.comp.vecs, 1755d7db7a88SGiovanni Cabiddu desc->suite.comp.decomp.vecs, 1756d7db7a88SGiovanni Cabiddu desc->suite.comp.comp.count, 1757d7db7a88SGiovanni Cabiddu desc->suite.comp.decomp.count); 1758d7db7a88SGiovanni Cabiddu crypto_free_acomp(acomp); 1759d7db7a88SGiovanni Cabiddu } else { 1760d7db7a88SGiovanni Cabiddu comp = crypto_alloc_comp(driver, type, mask); 1761d7db7a88SGiovanni Cabiddu if (IS_ERR(comp)) { 1762d7db7a88SGiovanni Cabiddu pr_err("alg: comp: Failed to load transform for %s: %ld\n", 1763d7db7a88SGiovanni Cabiddu driver, PTR_ERR(comp)); 1764d7db7a88SGiovanni Cabiddu return PTR_ERR(comp); 1765da7f033dSHerbert Xu } 1766da7f033dSHerbert Xu 1767d7db7a88SGiovanni Cabiddu err = test_comp(comp, desc->suite.comp.comp.vecs, 1768da7f033dSHerbert Xu desc->suite.comp.decomp.vecs, 1769da7f033dSHerbert Xu desc->suite.comp.comp.count, 1770da7f033dSHerbert Xu desc->suite.comp.decomp.count); 1771da7f033dSHerbert Xu 1772d7db7a88SGiovanni Cabiddu crypto_free_comp(comp); 1773d7db7a88SGiovanni Cabiddu } 1774da7f033dSHerbert Xu return err; 1775da7f033dSHerbert Xu } 1776da7f033dSHerbert Xu 1777da7f033dSHerbert Xu static int alg_test_hash(const struct alg_test_desc *desc, const char *driver, 1778da7f033dSHerbert Xu u32 type, u32 mask) 1779da7f033dSHerbert Xu { 1780da7f033dSHerbert Xu struct crypto_ahash *tfm; 1781da7f033dSHerbert Xu int err; 1782da7f033dSHerbert Xu 1783eed93e0cSHerbert Xu tfm = crypto_alloc_ahash(driver, type, mask); 1784da7f033dSHerbert Xu if (IS_ERR(tfm)) { 1785da7f033dSHerbert Xu printk(KERN_ERR "alg: hash: Failed to load transform for %s: " 1786da7f033dSHerbert Xu "%ld\n", driver, PTR_ERR(tfm)); 1787da7f033dSHerbert Xu return PTR_ERR(tfm); 1788da7f033dSHerbert Xu } 1789da7f033dSHerbert Xu 1790a8f1a052SDavid S. Miller err = test_hash(tfm, desc->suite.hash.vecs, 1791a8f1a052SDavid S. Miller desc->suite.hash.count, true); 1792a8f1a052SDavid S. Miller if (!err) 1793a8f1a052SDavid S. Miller err = test_hash(tfm, desc->suite.hash.vecs, 1794a8f1a052SDavid S. Miller desc->suite.hash.count, false); 1795da7f033dSHerbert Xu 1796da7f033dSHerbert Xu crypto_free_ahash(tfm); 1797da7f033dSHerbert Xu return err; 1798da7f033dSHerbert Xu } 1799da7f033dSHerbert Xu 18008e3ee85eSHerbert Xu static int alg_test_crc32c(const struct alg_test_desc *desc, 18018e3ee85eSHerbert Xu const char *driver, u32 type, u32 mask) 18028e3ee85eSHerbert Xu { 18038e3ee85eSHerbert Xu struct crypto_shash *tfm; 18048e3ee85eSHerbert Xu u32 val; 18058e3ee85eSHerbert Xu int err; 18068e3ee85eSHerbert Xu 18078e3ee85eSHerbert Xu err = alg_test_hash(desc, driver, type, mask); 18088e3ee85eSHerbert Xu if (err) 18098e3ee85eSHerbert Xu goto out; 18108e3ee85eSHerbert Xu 1811eed93e0cSHerbert Xu tfm = crypto_alloc_shash(driver, type, mask); 18128e3ee85eSHerbert Xu if (IS_ERR(tfm)) { 18138e3ee85eSHerbert Xu printk(KERN_ERR "alg: crc32c: Failed to load transform for %s: " 18148e3ee85eSHerbert Xu "%ld\n", driver, PTR_ERR(tfm)); 18158e3ee85eSHerbert Xu err = PTR_ERR(tfm); 18168e3ee85eSHerbert Xu goto out; 18178e3ee85eSHerbert Xu } 18188e3ee85eSHerbert Xu 18198e3ee85eSHerbert Xu do { 18204c5c3024SJan-Simon Möller SHASH_DESC_ON_STACK(shash, tfm); 18214c5c3024SJan-Simon Möller u32 *ctx = (u32 *)shash_desc_ctx(shash); 18228e3ee85eSHerbert Xu 18234c5c3024SJan-Simon Möller shash->tfm = tfm; 18244c5c3024SJan-Simon Möller shash->flags = 0; 18258e3ee85eSHerbert Xu 18264c5c3024SJan-Simon Möller *ctx = le32_to_cpu(420553207); 18274c5c3024SJan-Simon Möller err = crypto_shash_final(shash, (u8 *)&val); 18288e3ee85eSHerbert Xu if (err) { 18298e3ee85eSHerbert Xu printk(KERN_ERR "alg: crc32c: Operation failed for " 18308e3ee85eSHerbert Xu "%s: %d\n", driver, err); 18318e3ee85eSHerbert Xu break; 18328e3ee85eSHerbert Xu } 18338e3ee85eSHerbert Xu 18348e3ee85eSHerbert Xu if (val != ~420553207) { 18358e3ee85eSHerbert Xu printk(KERN_ERR "alg: crc32c: Test failed for %s: " 18368e3ee85eSHerbert Xu "%d\n", driver, val); 18378e3ee85eSHerbert Xu err = -EINVAL; 18388e3ee85eSHerbert Xu } 18398e3ee85eSHerbert Xu } while (0); 18408e3ee85eSHerbert Xu 18418e3ee85eSHerbert Xu crypto_free_shash(tfm); 18428e3ee85eSHerbert Xu 18438e3ee85eSHerbert Xu out: 18448e3ee85eSHerbert Xu return err; 18458e3ee85eSHerbert Xu } 18468e3ee85eSHerbert Xu 18477647d6ceSJarod Wilson static int alg_test_cprng(const struct alg_test_desc *desc, const char *driver, 18487647d6ceSJarod Wilson u32 type, u32 mask) 18497647d6ceSJarod Wilson { 18507647d6ceSJarod Wilson struct crypto_rng *rng; 18517647d6ceSJarod Wilson int err; 18527647d6ceSJarod Wilson 1853eed93e0cSHerbert Xu rng = crypto_alloc_rng(driver, type, mask); 18547647d6ceSJarod Wilson if (IS_ERR(rng)) { 18557647d6ceSJarod Wilson printk(KERN_ERR "alg: cprng: Failed to load transform for %s: " 18567647d6ceSJarod Wilson "%ld\n", driver, PTR_ERR(rng)); 18577647d6ceSJarod Wilson return PTR_ERR(rng); 18587647d6ceSJarod Wilson } 18597647d6ceSJarod Wilson 18607647d6ceSJarod Wilson err = test_cprng(rng, desc->suite.cprng.vecs, desc->suite.cprng.count); 18617647d6ceSJarod Wilson 18627647d6ceSJarod Wilson crypto_free_rng(rng); 18637647d6ceSJarod Wilson 18647647d6ceSJarod Wilson return err; 18657647d6ceSJarod Wilson } 18667647d6ceSJarod Wilson 186764d1cdfbSStephan Mueller 1868b13b1e0cSEric Biggers static int drbg_cavs_test(const struct drbg_testvec *test, int pr, 186964d1cdfbSStephan Mueller const char *driver, u32 type, u32 mask) 187064d1cdfbSStephan Mueller { 187164d1cdfbSStephan Mueller int ret = -EAGAIN; 187264d1cdfbSStephan Mueller struct crypto_rng *drng; 187364d1cdfbSStephan Mueller struct drbg_test_data test_data; 187464d1cdfbSStephan Mueller struct drbg_string addtl, pers, testentropy; 187564d1cdfbSStephan Mueller unsigned char *buf = kzalloc(test->expectedlen, GFP_KERNEL); 187664d1cdfbSStephan Mueller 187764d1cdfbSStephan Mueller if (!buf) 187864d1cdfbSStephan Mueller return -ENOMEM; 187964d1cdfbSStephan Mueller 1880eed93e0cSHerbert Xu drng = crypto_alloc_rng(driver, type, mask); 188164d1cdfbSStephan Mueller if (IS_ERR(drng)) { 188264d1cdfbSStephan Mueller printk(KERN_ERR "alg: drbg: could not allocate DRNG handle for " 188364d1cdfbSStephan Mueller "%s\n", driver); 188464d1cdfbSStephan Mueller kzfree(buf); 188564d1cdfbSStephan Mueller return -ENOMEM; 188664d1cdfbSStephan Mueller } 188764d1cdfbSStephan Mueller 188864d1cdfbSStephan Mueller test_data.testentropy = &testentropy; 188964d1cdfbSStephan Mueller drbg_string_fill(&testentropy, test->entropy, test->entropylen); 189064d1cdfbSStephan Mueller drbg_string_fill(&pers, test->pers, test->perslen); 189164d1cdfbSStephan Mueller ret = crypto_drbg_reset_test(drng, &pers, &test_data); 189264d1cdfbSStephan Mueller if (ret) { 189364d1cdfbSStephan Mueller printk(KERN_ERR "alg: drbg: Failed to reset rng\n"); 189464d1cdfbSStephan Mueller goto outbuf; 189564d1cdfbSStephan Mueller } 189664d1cdfbSStephan Mueller 189764d1cdfbSStephan Mueller drbg_string_fill(&addtl, test->addtla, test->addtllen); 189864d1cdfbSStephan Mueller if (pr) { 189964d1cdfbSStephan Mueller drbg_string_fill(&testentropy, test->entpra, test->entprlen); 190064d1cdfbSStephan Mueller ret = crypto_drbg_get_bytes_addtl_test(drng, 190164d1cdfbSStephan Mueller buf, test->expectedlen, &addtl, &test_data); 190264d1cdfbSStephan Mueller } else { 190364d1cdfbSStephan Mueller ret = crypto_drbg_get_bytes_addtl(drng, 190464d1cdfbSStephan Mueller buf, test->expectedlen, &addtl); 190564d1cdfbSStephan Mueller } 190619e60e13SStephan Mueller if (ret < 0) { 190764d1cdfbSStephan Mueller printk(KERN_ERR "alg: drbg: could not obtain random data for " 190864d1cdfbSStephan Mueller "driver %s\n", driver); 190964d1cdfbSStephan Mueller goto outbuf; 191064d1cdfbSStephan Mueller } 191164d1cdfbSStephan Mueller 191264d1cdfbSStephan Mueller drbg_string_fill(&addtl, test->addtlb, test->addtllen); 191364d1cdfbSStephan Mueller if (pr) { 191464d1cdfbSStephan Mueller drbg_string_fill(&testentropy, test->entprb, test->entprlen); 191564d1cdfbSStephan Mueller ret = crypto_drbg_get_bytes_addtl_test(drng, 191664d1cdfbSStephan Mueller buf, test->expectedlen, &addtl, &test_data); 191764d1cdfbSStephan Mueller } else { 191864d1cdfbSStephan Mueller ret = crypto_drbg_get_bytes_addtl(drng, 191964d1cdfbSStephan Mueller buf, test->expectedlen, &addtl); 192064d1cdfbSStephan Mueller } 192119e60e13SStephan Mueller if (ret < 0) { 192264d1cdfbSStephan Mueller printk(KERN_ERR "alg: drbg: could not obtain random data for " 192364d1cdfbSStephan Mueller "driver %s\n", driver); 192464d1cdfbSStephan Mueller goto outbuf; 192564d1cdfbSStephan Mueller } 192664d1cdfbSStephan Mueller 192764d1cdfbSStephan Mueller ret = memcmp(test->expected, buf, test->expectedlen); 192864d1cdfbSStephan Mueller 192964d1cdfbSStephan Mueller outbuf: 193064d1cdfbSStephan Mueller crypto_free_rng(drng); 193164d1cdfbSStephan Mueller kzfree(buf); 193264d1cdfbSStephan Mueller return ret; 193364d1cdfbSStephan Mueller } 193464d1cdfbSStephan Mueller 193564d1cdfbSStephan Mueller 193664d1cdfbSStephan Mueller static int alg_test_drbg(const struct alg_test_desc *desc, const char *driver, 193764d1cdfbSStephan Mueller u32 type, u32 mask) 193864d1cdfbSStephan Mueller { 193964d1cdfbSStephan Mueller int err = 0; 194064d1cdfbSStephan Mueller int pr = 0; 194164d1cdfbSStephan Mueller int i = 0; 1942b13b1e0cSEric Biggers const struct drbg_testvec *template = desc->suite.drbg.vecs; 194364d1cdfbSStephan Mueller unsigned int tcount = desc->suite.drbg.count; 194464d1cdfbSStephan Mueller 194564d1cdfbSStephan Mueller if (0 == memcmp(driver, "drbg_pr_", 8)) 194664d1cdfbSStephan Mueller pr = 1; 194764d1cdfbSStephan Mueller 194864d1cdfbSStephan Mueller for (i = 0; i < tcount; i++) { 194964d1cdfbSStephan Mueller err = drbg_cavs_test(&template[i], pr, driver, type, mask); 195064d1cdfbSStephan Mueller if (err) { 195164d1cdfbSStephan Mueller printk(KERN_ERR "alg: drbg: Test %d failed for %s\n", 195264d1cdfbSStephan Mueller i, driver); 195364d1cdfbSStephan Mueller err = -EINVAL; 195464d1cdfbSStephan Mueller break; 195564d1cdfbSStephan Mueller } 195664d1cdfbSStephan Mueller } 195764d1cdfbSStephan Mueller return err; 195864d1cdfbSStephan Mueller 195964d1cdfbSStephan Mueller } 196064d1cdfbSStephan Mueller 1961b13b1e0cSEric Biggers static int do_test_kpp(struct crypto_kpp *tfm, const struct kpp_testvec *vec, 1962802c7f1cSSalvatore Benedetto const char *alg) 1963802c7f1cSSalvatore Benedetto { 1964802c7f1cSSalvatore Benedetto struct kpp_request *req; 1965802c7f1cSSalvatore Benedetto void *input_buf = NULL; 1966802c7f1cSSalvatore Benedetto void *output_buf = NULL; 196747d3fd39STudor-Dan Ambarus void *a_public = NULL; 196847d3fd39STudor-Dan Ambarus void *a_ss = NULL; 196947d3fd39STudor-Dan Ambarus void *shared_secret = NULL; 19707f397136SGilad Ben-Yossef struct crypto_wait wait; 1971802c7f1cSSalvatore Benedetto unsigned int out_len_max; 1972802c7f1cSSalvatore Benedetto int err = -ENOMEM; 1973802c7f1cSSalvatore Benedetto struct scatterlist src, dst; 1974802c7f1cSSalvatore Benedetto 1975802c7f1cSSalvatore Benedetto req = kpp_request_alloc(tfm, GFP_KERNEL); 1976802c7f1cSSalvatore Benedetto if (!req) 1977802c7f1cSSalvatore Benedetto return err; 1978802c7f1cSSalvatore Benedetto 19797f397136SGilad Ben-Yossef crypto_init_wait(&wait); 1980802c7f1cSSalvatore Benedetto 1981802c7f1cSSalvatore Benedetto err = crypto_kpp_set_secret(tfm, vec->secret, vec->secret_size); 1982802c7f1cSSalvatore Benedetto if (err < 0) 1983802c7f1cSSalvatore Benedetto goto free_req; 1984802c7f1cSSalvatore Benedetto 1985802c7f1cSSalvatore Benedetto out_len_max = crypto_kpp_maxsize(tfm); 1986802c7f1cSSalvatore Benedetto output_buf = kzalloc(out_len_max, GFP_KERNEL); 1987802c7f1cSSalvatore Benedetto if (!output_buf) { 1988802c7f1cSSalvatore Benedetto err = -ENOMEM; 1989802c7f1cSSalvatore Benedetto goto free_req; 1990802c7f1cSSalvatore Benedetto } 1991802c7f1cSSalvatore Benedetto 1992802c7f1cSSalvatore Benedetto /* Use appropriate parameter as base */ 1993802c7f1cSSalvatore Benedetto kpp_request_set_input(req, NULL, 0); 1994802c7f1cSSalvatore Benedetto sg_init_one(&dst, output_buf, out_len_max); 1995802c7f1cSSalvatore Benedetto kpp_request_set_output(req, &dst, out_len_max); 1996802c7f1cSSalvatore Benedetto kpp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, 19977f397136SGilad Ben-Yossef crypto_req_done, &wait); 1998802c7f1cSSalvatore Benedetto 199947d3fd39STudor-Dan Ambarus /* Compute party A's public key */ 20007f397136SGilad Ben-Yossef err = crypto_wait_req(crypto_kpp_generate_public_key(req), &wait); 2001802c7f1cSSalvatore Benedetto if (err) { 200247d3fd39STudor-Dan Ambarus pr_err("alg: %s: Party A: generate public key test failed. err %d\n", 2003802c7f1cSSalvatore Benedetto alg, err); 2004802c7f1cSSalvatore Benedetto goto free_output; 2005802c7f1cSSalvatore Benedetto } 200647d3fd39STudor-Dan Ambarus 200747d3fd39STudor-Dan Ambarus if (vec->genkey) { 200847d3fd39STudor-Dan Ambarus /* Save party A's public key */ 200947d3fd39STudor-Dan Ambarus a_public = kzalloc(out_len_max, GFP_KERNEL); 201047d3fd39STudor-Dan Ambarus if (!a_public) { 201147d3fd39STudor-Dan Ambarus err = -ENOMEM; 201247d3fd39STudor-Dan Ambarus goto free_output; 201347d3fd39STudor-Dan Ambarus } 201447d3fd39STudor-Dan Ambarus memcpy(a_public, sg_virt(req->dst), out_len_max); 201547d3fd39STudor-Dan Ambarus } else { 2016802c7f1cSSalvatore Benedetto /* Verify calculated public key */ 2017802c7f1cSSalvatore Benedetto if (memcmp(vec->expected_a_public, sg_virt(req->dst), 2018802c7f1cSSalvatore Benedetto vec->expected_a_public_size)) { 201947d3fd39STudor-Dan Ambarus pr_err("alg: %s: Party A: generate public key test failed. Invalid output\n", 2020802c7f1cSSalvatore Benedetto alg); 2021802c7f1cSSalvatore Benedetto err = -EINVAL; 2022802c7f1cSSalvatore Benedetto goto free_output; 2023802c7f1cSSalvatore Benedetto } 202447d3fd39STudor-Dan Ambarus } 2025802c7f1cSSalvatore Benedetto 2026802c7f1cSSalvatore Benedetto /* Calculate shared secret key by using counter part (b) public key. */ 2027802c7f1cSSalvatore Benedetto input_buf = kzalloc(vec->b_public_size, GFP_KERNEL); 2028802c7f1cSSalvatore Benedetto if (!input_buf) { 2029802c7f1cSSalvatore Benedetto err = -ENOMEM; 2030802c7f1cSSalvatore Benedetto goto free_output; 2031802c7f1cSSalvatore Benedetto } 2032802c7f1cSSalvatore Benedetto 2033802c7f1cSSalvatore Benedetto memcpy(input_buf, vec->b_public, vec->b_public_size); 2034802c7f1cSSalvatore Benedetto sg_init_one(&src, input_buf, vec->b_public_size); 2035802c7f1cSSalvatore Benedetto sg_init_one(&dst, output_buf, out_len_max); 2036802c7f1cSSalvatore Benedetto kpp_request_set_input(req, &src, vec->b_public_size); 2037802c7f1cSSalvatore Benedetto kpp_request_set_output(req, &dst, out_len_max); 2038802c7f1cSSalvatore Benedetto kpp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, 20397f397136SGilad Ben-Yossef crypto_req_done, &wait); 20407f397136SGilad Ben-Yossef err = crypto_wait_req(crypto_kpp_compute_shared_secret(req), &wait); 2041802c7f1cSSalvatore Benedetto if (err) { 204247d3fd39STudor-Dan Ambarus pr_err("alg: %s: Party A: compute shared secret test failed. err %d\n", 2043802c7f1cSSalvatore Benedetto alg, err); 2044802c7f1cSSalvatore Benedetto goto free_all; 2045802c7f1cSSalvatore Benedetto } 204647d3fd39STudor-Dan Ambarus 204747d3fd39STudor-Dan Ambarus if (vec->genkey) { 204847d3fd39STudor-Dan Ambarus /* Save the shared secret obtained by party A */ 204947d3fd39STudor-Dan Ambarus a_ss = kzalloc(vec->expected_ss_size, GFP_KERNEL); 205047d3fd39STudor-Dan Ambarus if (!a_ss) { 205147d3fd39STudor-Dan Ambarus err = -ENOMEM; 205247d3fd39STudor-Dan Ambarus goto free_all; 205347d3fd39STudor-Dan Ambarus } 205447d3fd39STudor-Dan Ambarus memcpy(a_ss, sg_virt(req->dst), vec->expected_ss_size); 205547d3fd39STudor-Dan Ambarus 205647d3fd39STudor-Dan Ambarus /* 205747d3fd39STudor-Dan Ambarus * Calculate party B's shared secret by using party A's 205847d3fd39STudor-Dan Ambarus * public key. 205947d3fd39STudor-Dan Ambarus */ 206047d3fd39STudor-Dan Ambarus err = crypto_kpp_set_secret(tfm, vec->b_secret, 206147d3fd39STudor-Dan Ambarus vec->b_secret_size); 206247d3fd39STudor-Dan Ambarus if (err < 0) 206347d3fd39STudor-Dan Ambarus goto free_all; 206447d3fd39STudor-Dan Ambarus 206547d3fd39STudor-Dan Ambarus sg_init_one(&src, a_public, vec->expected_a_public_size); 206647d3fd39STudor-Dan Ambarus sg_init_one(&dst, output_buf, out_len_max); 206747d3fd39STudor-Dan Ambarus kpp_request_set_input(req, &src, vec->expected_a_public_size); 206847d3fd39STudor-Dan Ambarus kpp_request_set_output(req, &dst, out_len_max); 206947d3fd39STudor-Dan Ambarus kpp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, 20707f397136SGilad Ben-Yossef crypto_req_done, &wait); 20717f397136SGilad Ben-Yossef err = crypto_wait_req(crypto_kpp_compute_shared_secret(req), 20727f397136SGilad Ben-Yossef &wait); 207347d3fd39STudor-Dan Ambarus if (err) { 207447d3fd39STudor-Dan Ambarus pr_err("alg: %s: Party B: compute shared secret failed. err %d\n", 207547d3fd39STudor-Dan Ambarus alg, err); 207647d3fd39STudor-Dan Ambarus goto free_all; 207747d3fd39STudor-Dan Ambarus } 207847d3fd39STudor-Dan Ambarus 207947d3fd39STudor-Dan Ambarus shared_secret = a_ss; 208047d3fd39STudor-Dan Ambarus } else { 208147d3fd39STudor-Dan Ambarus shared_secret = (void *)vec->expected_ss; 208247d3fd39STudor-Dan Ambarus } 208347d3fd39STudor-Dan Ambarus 2084802c7f1cSSalvatore Benedetto /* 2085802c7f1cSSalvatore Benedetto * verify shared secret from which the user will derive 2086802c7f1cSSalvatore Benedetto * secret key by executing whatever hash it has chosen 2087802c7f1cSSalvatore Benedetto */ 208847d3fd39STudor-Dan Ambarus if (memcmp(shared_secret, sg_virt(req->dst), 2089802c7f1cSSalvatore Benedetto vec->expected_ss_size)) { 2090802c7f1cSSalvatore Benedetto pr_err("alg: %s: compute shared secret test failed. Invalid output\n", 2091802c7f1cSSalvatore Benedetto alg); 2092802c7f1cSSalvatore Benedetto err = -EINVAL; 2093802c7f1cSSalvatore Benedetto } 2094802c7f1cSSalvatore Benedetto 2095802c7f1cSSalvatore Benedetto free_all: 209647d3fd39STudor-Dan Ambarus kfree(a_ss); 2097802c7f1cSSalvatore Benedetto kfree(input_buf); 2098802c7f1cSSalvatore Benedetto free_output: 209947d3fd39STudor-Dan Ambarus kfree(a_public); 2100802c7f1cSSalvatore Benedetto kfree(output_buf); 2101802c7f1cSSalvatore Benedetto free_req: 2102802c7f1cSSalvatore Benedetto kpp_request_free(req); 2103802c7f1cSSalvatore Benedetto return err; 2104802c7f1cSSalvatore Benedetto } 2105802c7f1cSSalvatore Benedetto 2106802c7f1cSSalvatore Benedetto static int test_kpp(struct crypto_kpp *tfm, const char *alg, 2107b13b1e0cSEric Biggers const struct kpp_testvec *vecs, unsigned int tcount) 2108802c7f1cSSalvatore Benedetto { 2109802c7f1cSSalvatore Benedetto int ret, i; 2110802c7f1cSSalvatore Benedetto 2111802c7f1cSSalvatore Benedetto for (i = 0; i < tcount; i++) { 2112802c7f1cSSalvatore Benedetto ret = do_test_kpp(tfm, vecs++, alg); 2113802c7f1cSSalvatore Benedetto if (ret) { 2114802c7f1cSSalvatore Benedetto pr_err("alg: %s: test failed on vector %d, err=%d\n", 2115802c7f1cSSalvatore Benedetto alg, i + 1, ret); 2116802c7f1cSSalvatore Benedetto return ret; 2117802c7f1cSSalvatore Benedetto } 2118802c7f1cSSalvatore Benedetto } 2119802c7f1cSSalvatore Benedetto return 0; 2120802c7f1cSSalvatore Benedetto } 2121802c7f1cSSalvatore Benedetto 2122802c7f1cSSalvatore Benedetto static int alg_test_kpp(const struct alg_test_desc *desc, const char *driver, 2123802c7f1cSSalvatore Benedetto u32 type, u32 mask) 2124802c7f1cSSalvatore Benedetto { 2125802c7f1cSSalvatore Benedetto struct crypto_kpp *tfm; 2126802c7f1cSSalvatore Benedetto int err = 0; 2127802c7f1cSSalvatore Benedetto 2128eed93e0cSHerbert Xu tfm = crypto_alloc_kpp(driver, type, mask); 2129802c7f1cSSalvatore Benedetto if (IS_ERR(tfm)) { 2130802c7f1cSSalvatore Benedetto pr_err("alg: kpp: Failed to load tfm for %s: %ld\n", 2131802c7f1cSSalvatore Benedetto driver, PTR_ERR(tfm)); 2132802c7f1cSSalvatore Benedetto return PTR_ERR(tfm); 2133802c7f1cSSalvatore Benedetto } 2134802c7f1cSSalvatore Benedetto if (desc->suite.kpp.vecs) 2135802c7f1cSSalvatore Benedetto err = test_kpp(tfm, desc->alg, desc->suite.kpp.vecs, 2136802c7f1cSSalvatore Benedetto desc->suite.kpp.count); 2137802c7f1cSSalvatore Benedetto 2138802c7f1cSSalvatore Benedetto crypto_free_kpp(tfm); 2139802c7f1cSSalvatore Benedetto return err; 2140802c7f1cSSalvatore Benedetto } 2141802c7f1cSSalvatore Benedetto 214250d2b643SHerbert Xu static int test_akcipher_one(struct crypto_akcipher *tfm, 2143b13b1e0cSEric Biggers const struct akcipher_testvec *vecs) 2144946cc463STadeusz Struk { 2145df27b26fSHerbert Xu char *xbuf[XBUFSIZE]; 2146946cc463STadeusz Struk struct akcipher_request *req; 2147946cc463STadeusz Struk void *outbuf_enc = NULL; 2148946cc463STadeusz Struk void *outbuf_dec = NULL; 21497f397136SGilad Ben-Yossef struct crypto_wait wait; 2150946cc463STadeusz Struk unsigned int out_len_max, out_len = 0; 2151946cc463STadeusz Struk int err = -ENOMEM; 215222287b0bSTadeusz Struk struct scatterlist src, dst, src_tab[2]; 2153946cc463STadeusz Struk 2154df27b26fSHerbert Xu if (testmgr_alloc_buf(xbuf)) 2155df27b26fSHerbert Xu return err; 2156df27b26fSHerbert Xu 2157946cc463STadeusz Struk req = akcipher_request_alloc(tfm, GFP_KERNEL); 2158946cc463STadeusz Struk if (!req) 2159df27b26fSHerbert Xu goto free_xbuf; 2160946cc463STadeusz Struk 21617f397136SGilad Ben-Yossef crypto_init_wait(&wait); 216222287b0bSTadeusz Struk 216322287b0bSTadeusz Struk if (vecs->public_key_vec) 216422287b0bSTadeusz Struk err = crypto_akcipher_set_pub_key(tfm, vecs->key, 216522287b0bSTadeusz Struk vecs->key_len); 216622287b0bSTadeusz Struk else 216722287b0bSTadeusz Struk err = crypto_akcipher_set_priv_key(tfm, vecs->key, 216822287b0bSTadeusz Struk vecs->key_len); 2169946cc463STadeusz Struk if (err) 2170946cc463STadeusz Struk goto free_req; 2171946cc463STadeusz Struk 217257763f5eSSalvatore Benedetto err = -ENOMEM; 217322287b0bSTadeusz Struk out_len_max = crypto_akcipher_maxsize(tfm); 2174946cc463STadeusz Struk outbuf_enc = kzalloc(out_len_max, GFP_KERNEL); 2175946cc463STadeusz Struk if (!outbuf_enc) 2176946cc463STadeusz Struk goto free_req; 2177946cc463STadeusz Struk 2178df27b26fSHerbert Xu if (WARN_ON(vecs->m_size > PAGE_SIZE)) 2179df27b26fSHerbert Xu goto free_all; 2180df27b26fSHerbert Xu 2181df27b26fSHerbert Xu memcpy(xbuf[0], vecs->m, vecs->m_size); 2182df27b26fSHerbert Xu 218322287b0bSTadeusz Struk sg_init_table(src_tab, 2); 2184df27b26fSHerbert Xu sg_set_buf(&src_tab[0], xbuf[0], 8); 2185df27b26fSHerbert Xu sg_set_buf(&src_tab[1], xbuf[0] + 8, vecs->m_size - 8); 218622287b0bSTadeusz Struk sg_init_one(&dst, outbuf_enc, out_len_max); 218722287b0bSTadeusz Struk akcipher_request_set_crypt(req, src_tab, &dst, vecs->m_size, 218822287b0bSTadeusz Struk out_len_max); 2189946cc463STadeusz Struk akcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, 21907f397136SGilad Ben-Yossef crypto_req_done, &wait); 2191946cc463STadeusz Struk 21927f397136SGilad Ben-Yossef err = crypto_wait_req(vecs->siggen_sigver_test ? 21931207107cSStephan Mueller /* Run asymmetric signature generation */ 21941207107cSStephan Mueller crypto_akcipher_sign(req) : 21951207107cSStephan Mueller /* Run asymmetric encrypt */ 21967f397136SGilad Ben-Yossef crypto_akcipher_encrypt(req), &wait); 2197946cc463STadeusz Struk if (err) { 219850d2b643SHerbert Xu pr_err("alg: akcipher: encrypt test failed. err %d\n", err); 2199946cc463STadeusz Struk goto free_all; 2200946cc463STadeusz Struk } 220122287b0bSTadeusz Struk if (req->dst_len != vecs->c_size) { 220250d2b643SHerbert Xu pr_err("alg: akcipher: encrypt test failed. Invalid output len\n"); 2203946cc463STadeusz Struk err = -EINVAL; 2204946cc463STadeusz Struk goto free_all; 2205946cc463STadeusz Struk } 2206946cc463STadeusz Struk /* verify that encrypted message is equal to expected */ 2207df27b26fSHerbert Xu if (memcmp(vecs->c, outbuf_enc, vecs->c_size)) { 220850d2b643SHerbert Xu pr_err("alg: akcipher: encrypt test failed. Invalid output\n"); 220950d2b643SHerbert Xu hexdump(outbuf_enc, vecs->c_size); 2210946cc463STadeusz Struk err = -EINVAL; 2211946cc463STadeusz Struk goto free_all; 2212946cc463STadeusz Struk } 2213946cc463STadeusz Struk /* Don't invoke decrypt for vectors with public key */ 2214946cc463STadeusz Struk if (vecs->public_key_vec) { 2215946cc463STadeusz Struk err = 0; 2216946cc463STadeusz Struk goto free_all; 2217946cc463STadeusz Struk } 2218946cc463STadeusz Struk outbuf_dec = kzalloc(out_len_max, GFP_KERNEL); 2219946cc463STadeusz Struk if (!outbuf_dec) { 2220946cc463STadeusz Struk err = -ENOMEM; 2221946cc463STadeusz Struk goto free_all; 2222946cc463STadeusz Struk } 2223df27b26fSHerbert Xu 2224df27b26fSHerbert Xu if (WARN_ON(vecs->c_size > PAGE_SIZE)) 2225df27b26fSHerbert Xu goto free_all; 2226df27b26fSHerbert Xu 2227df27b26fSHerbert Xu memcpy(xbuf[0], vecs->c, vecs->c_size); 2228df27b26fSHerbert Xu 2229df27b26fSHerbert Xu sg_init_one(&src, xbuf[0], vecs->c_size); 223022287b0bSTadeusz Struk sg_init_one(&dst, outbuf_dec, out_len_max); 22317f397136SGilad Ben-Yossef crypto_init_wait(&wait); 223222287b0bSTadeusz Struk akcipher_request_set_crypt(req, &src, &dst, vecs->c_size, out_len_max); 2233946cc463STadeusz Struk 22347f397136SGilad Ben-Yossef err = crypto_wait_req(vecs->siggen_sigver_test ? 22351207107cSStephan Mueller /* Run asymmetric signature verification */ 22361207107cSStephan Mueller crypto_akcipher_verify(req) : 22371207107cSStephan Mueller /* Run asymmetric decrypt */ 22387f397136SGilad Ben-Yossef crypto_akcipher_decrypt(req), &wait); 2239946cc463STadeusz Struk if (err) { 224050d2b643SHerbert Xu pr_err("alg: akcipher: decrypt test failed. err %d\n", err); 2241946cc463STadeusz Struk goto free_all; 2242946cc463STadeusz Struk } 2243946cc463STadeusz Struk out_len = req->dst_len; 224450d2b643SHerbert Xu if (out_len < vecs->m_size) { 224550d2b643SHerbert Xu pr_err("alg: akcipher: decrypt test failed. " 224650d2b643SHerbert Xu "Invalid output len %u\n", out_len); 2247946cc463STadeusz Struk err = -EINVAL; 2248946cc463STadeusz Struk goto free_all; 2249946cc463STadeusz Struk } 2250946cc463STadeusz Struk /* verify that decrypted message is equal to the original msg */ 225150d2b643SHerbert Xu if (memchr_inv(outbuf_dec, 0, out_len - vecs->m_size) || 225250d2b643SHerbert Xu memcmp(vecs->m, outbuf_dec + out_len - vecs->m_size, 225350d2b643SHerbert Xu vecs->m_size)) { 225450d2b643SHerbert Xu pr_err("alg: akcipher: decrypt test failed. Invalid output\n"); 225550d2b643SHerbert Xu hexdump(outbuf_dec, out_len); 2256946cc463STadeusz Struk err = -EINVAL; 2257946cc463STadeusz Struk } 2258946cc463STadeusz Struk free_all: 2259946cc463STadeusz Struk kfree(outbuf_dec); 2260946cc463STadeusz Struk kfree(outbuf_enc); 2261946cc463STadeusz Struk free_req: 2262946cc463STadeusz Struk akcipher_request_free(req); 2263df27b26fSHerbert Xu free_xbuf: 2264df27b26fSHerbert Xu testmgr_free_buf(xbuf); 2265946cc463STadeusz Struk return err; 2266946cc463STadeusz Struk } 2267946cc463STadeusz Struk 226850d2b643SHerbert Xu static int test_akcipher(struct crypto_akcipher *tfm, const char *alg, 2269b13b1e0cSEric Biggers const struct akcipher_testvec *vecs, 2270b13b1e0cSEric Biggers unsigned int tcount) 2271946cc463STadeusz Struk { 227215226e48SHerbert Xu const char *algo = 227315226e48SHerbert Xu crypto_tfm_alg_driver_name(crypto_akcipher_tfm(tfm)); 2274946cc463STadeusz Struk int ret, i; 2275946cc463STadeusz Struk 2276946cc463STadeusz Struk for (i = 0; i < tcount; i++) { 227750d2b643SHerbert Xu ret = test_akcipher_one(tfm, vecs++); 227850d2b643SHerbert Xu if (!ret) 227950d2b643SHerbert Xu continue; 228050d2b643SHerbert Xu 228115226e48SHerbert Xu pr_err("alg: akcipher: test %d failed for %s, err=%d\n", 228215226e48SHerbert Xu i + 1, algo, ret); 2283946cc463STadeusz Struk return ret; 2284946cc463STadeusz Struk } 2285946cc463STadeusz Struk return 0; 2286946cc463STadeusz Struk } 2287946cc463STadeusz Struk 2288946cc463STadeusz Struk static int alg_test_akcipher(const struct alg_test_desc *desc, 2289946cc463STadeusz Struk const char *driver, u32 type, u32 mask) 2290946cc463STadeusz Struk { 2291946cc463STadeusz Struk struct crypto_akcipher *tfm; 2292946cc463STadeusz Struk int err = 0; 2293946cc463STadeusz Struk 2294eed93e0cSHerbert Xu tfm = crypto_alloc_akcipher(driver, type, mask); 2295946cc463STadeusz Struk if (IS_ERR(tfm)) { 2296946cc463STadeusz Struk pr_err("alg: akcipher: Failed to load tfm for %s: %ld\n", 2297946cc463STadeusz Struk driver, PTR_ERR(tfm)); 2298946cc463STadeusz Struk return PTR_ERR(tfm); 2299946cc463STadeusz Struk } 2300946cc463STadeusz Struk if (desc->suite.akcipher.vecs) 2301946cc463STadeusz Struk err = test_akcipher(tfm, desc->alg, desc->suite.akcipher.vecs, 2302946cc463STadeusz Struk desc->suite.akcipher.count); 2303946cc463STadeusz Struk 2304946cc463STadeusz Struk crypto_free_akcipher(tfm); 2305946cc463STadeusz Struk return err; 2306946cc463STadeusz Struk } 2307946cc463STadeusz Struk 2308863b557aSYouquan, Song static int alg_test_null(const struct alg_test_desc *desc, 2309863b557aSYouquan, Song const char *driver, u32 type, u32 mask) 2310863b557aSYouquan, Song { 2311863b557aSYouquan, Song return 0; 2312863b557aSYouquan, Song } 2313863b557aSYouquan, Song 231421c8e720SArd Biesheuvel #define __VECS(tv) { .vecs = tv, .count = ARRAY_SIZE(tv) } 231521c8e720SArd Biesheuvel 2316da7f033dSHerbert Xu /* Please keep this list sorted by algorithm name. */ 2317da7f033dSHerbert Xu static const struct alg_test_desc alg_test_descs[] = { 2318da7f033dSHerbert Xu { 2319e08ca2daSJarod Wilson .alg = "ansi_cprng", 2320e08ca2daSJarod Wilson .test = alg_test_cprng, 2321e08ca2daSJarod Wilson .suite = { 232221c8e720SArd Biesheuvel .cprng = __VECS(ansi_cprng_aes_tv_template) 2323e08ca2daSJarod Wilson } 2324e08ca2daSJarod Wilson }, { 2325bca4feb0SHoria Geanta .alg = "authenc(hmac(md5),ecb(cipher_null))", 2326bca4feb0SHoria Geanta .test = alg_test_aead, 2327bca4feb0SHoria Geanta .suite = { 2328bca4feb0SHoria Geanta .aead = { 232921c8e720SArd Biesheuvel .enc = __VECS(hmac_md5_ecb_cipher_null_enc_tv_template), 233021c8e720SArd Biesheuvel .dec = __VECS(hmac_md5_ecb_cipher_null_dec_tv_template) 2331bca4feb0SHoria Geanta } 2332bca4feb0SHoria Geanta } 2333bca4feb0SHoria Geanta }, { 2334a4198fd4SHerbert Xu .alg = "authenc(hmac(sha1),cbc(aes))", 2335e46e9a46SHoria Geanta .test = alg_test_aead, 2336bcf741cbSHerbert Xu .fips_allowed = 1, 2337e46e9a46SHoria Geanta .suite = { 2338e46e9a46SHoria Geanta .aead = { 233921c8e720SArd Biesheuvel .enc = __VECS(hmac_sha1_aes_cbc_enc_tv_temp) 23405208ed2cSNitesh Lal } 23415208ed2cSNitesh Lal } 23425208ed2cSNitesh Lal }, { 2343a4198fd4SHerbert Xu .alg = "authenc(hmac(sha1),cbc(des))", 23445208ed2cSNitesh Lal .test = alg_test_aead, 23455208ed2cSNitesh Lal .suite = { 23465208ed2cSNitesh Lal .aead = { 234721c8e720SArd Biesheuvel .enc = __VECS(hmac_sha1_des_cbc_enc_tv_temp) 23485208ed2cSNitesh Lal } 23495208ed2cSNitesh Lal } 23505208ed2cSNitesh Lal }, { 2351a4198fd4SHerbert Xu .alg = "authenc(hmac(sha1),cbc(des3_ede))", 23525208ed2cSNitesh Lal .test = alg_test_aead, 2353ed1afac9SMarcus Meissner .fips_allowed = 1, 23545208ed2cSNitesh Lal .suite = { 23555208ed2cSNitesh Lal .aead = { 235621c8e720SArd Biesheuvel .enc = __VECS(hmac_sha1_des3_ede_cbc_enc_tv_temp) 2357e46e9a46SHoria Geanta } 2358e46e9a46SHoria Geanta } 2359e46e9a46SHoria Geanta }, { 2360fb16abc2SMarcus Meissner .alg = "authenc(hmac(sha1),ctr(aes))", 2361fb16abc2SMarcus Meissner .test = alg_test_null, 2362fb16abc2SMarcus Meissner .fips_allowed = 1, 2363fb16abc2SMarcus Meissner }, { 2364bca4feb0SHoria Geanta .alg = "authenc(hmac(sha1),ecb(cipher_null))", 2365bca4feb0SHoria Geanta .test = alg_test_aead, 2366bca4feb0SHoria Geanta .suite = { 2367bca4feb0SHoria Geanta .aead = { 236821c8e720SArd Biesheuvel .enc = __VECS(hmac_sha1_ecb_cipher_null_enc_tv_temp), 236921c8e720SArd Biesheuvel .dec = __VECS(hmac_sha1_ecb_cipher_null_dec_tv_temp) 23705208ed2cSNitesh Lal } 23715208ed2cSNitesh Lal } 23725208ed2cSNitesh Lal }, { 23738888690eSMarcus Meissner .alg = "authenc(hmac(sha1),rfc3686(ctr(aes)))", 23748888690eSMarcus Meissner .test = alg_test_null, 23758888690eSMarcus Meissner .fips_allowed = 1, 23768888690eSMarcus Meissner }, { 2377a4198fd4SHerbert Xu .alg = "authenc(hmac(sha224),cbc(des))", 23785208ed2cSNitesh Lal .test = alg_test_aead, 23795208ed2cSNitesh Lal .suite = { 23805208ed2cSNitesh Lal .aead = { 238121c8e720SArd Biesheuvel .enc = __VECS(hmac_sha224_des_cbc_enc_tv_temp) 23825208ed2cSNitesh Lal } 23835208ed2cSNitesh Lal } 23845208ed2cSNitesh Lal }, { 2385a4198fd4SHerbert Xu .alg = "authenc(hmac(sha224),cbc(des3_ede))", 23865208ed2cSNitesh Lal .test = alg_test_aead, 2387ed1afac9SMarcus Meissner .fips_allowed = 1, 23885208ed2cSNitesh Lal .suite = { 23895208ed2cSNitesh Lal .aead = { 239021c8e720SArd Biesheuvel .enc = __VECS(hmac_sha224_des3_ede_cbc_enc_tv_temp) 2391bca4feb0SHoria Geanta } 2392bca4feb0SHoria Geanta } 2393bca4feb0SHoria Geanta }, { 2394a4198fd4SHerbert Xu .alg = "authenc(hmac(sha256),cbc(aes))", 2395e46e9a46SHoria Geanta .test = alg_test_aead, 2396ed1afac9SMarcus Meissner .fips_allowed = 1, 2397e46e9a46SHoria Geanta .suite = { 2398e46e9a46SHoria Geanta .aead = { 239921c8e720SArd Biesheuvel .enc = __VECS(hmac_sha256_aes_cbc_enc_tv_temp) 24005208ed2cSNitesh Lal } 24015208ed2cSNitesh Lal } 24025208ed2cSNitesh Lal }, { 2403a4198fd4SHerbert Xu .alg = "authenc(hmac(sha256),cbc(des))", 24045208ed2cSNitesh Lal .test = alg_test_aead, 24055208ed2cSNitesh Lal .suite = { 24065208ed2cSNitesh Lal .aead = { 240721c8e720SArd Biesheuvel .enc = __VECS(hmac_sha256_des_cbc_enc_tv_temp) 24085208ed2cSNitesh Lal } 24095208ed2cSNitesh Lal } 24105208ed2cSNitesh Lal }, { 2411a4198fd4SHerbert Xu .alg = "authenc(hmac(sha256),cbc(des3_ede))", 24125208ed2cSNitesh Lal .test = alg_test_aead, 2413ed1afac9SMarcus Meissner .fips_allowed = 1, 24145208ed2cSNitesh Lal .suite = { 24155208ed2cSNitesh Lal .aead = { 241621c8e720SArd Biesheuvel .enc = __VECS(hmac_sha256_des3_ede_cbc_enc_tv_temp) 24175208ed2cSNitesh Lal } 24185208ed2cSNitesh Lal } 24195208ed2cSNitesh Lal }, { 2420fb16abc2SMarcus Meissner .alg = "authenc(hmac(sha256),ctr(aes))", 2421fb16abc2SMarcus Meissner .test = alg_test_null, 2422fb16abc2SMarcus Meissner .fips_allowed = 1, 2423fb16abc2SMarcus Meissner }, { 24248888690eSMarcus Meissner .alg = "authenc(hmac(sha256),rfc3686(ctr(aes)))", 24258888690eSMarcus Meissner .test = alg_test_null, 24268888690eSMarcus Meissner .fips_allowed = 1, 24278888690eSMarcus Meissner }, { 2428a4198fd4SHerbert Xu .alg = "authenc(hmac(sha384),cbc(des))", 24295208ed2cSNitesh Lal .test = alg_test_aead, 24305208ed2cSNitesh Lal .suite = { 24315208ed2cSNitesh Lal .aead = { 243221c8e720SArd Biesheuvel .enc = __VECS(hmac_sha384_des_cbc_enc_tv_temp) 24335208ed2cSNitesh Lal } 24345208ed2cSNitesh Lal } 24355208ed2cSNitesh Lal }, { 2436a4198fd4SHerbert Xu .alg = "authenc(hmac(sha384),cbc(des3_ede))", 24375208ed2cSNitesh Lal .test = alg_test_aead, 2438ed1afac9SMarcus Meissner .fips_allowed = 1, 24395208ed2cSNitesh Lal .suite = { 24405208ed2cSNitesh Lal .aead = { 244121c8e720SArd Biesheuvel .enc = __VECS(hmac_sha384_des3_ede_cbc_enc_tv_temp) 2442e46e9a46SHoria Geanta } 2443e46e9a46SHoria Geanta } 2444e46e9a46SHoria Geanta }, { 2445fb16abc2SMarcus Meissner .alg = "authenc(hmac(sha384),ctr(aes))", 2446fb16abc2SMarcus Meissner .test = alg_test_null, 2447fb16abc2SMarcus Meissner .fips_allowed = 1, 2448fb16abc2SMarcus Meissner }, { 24498888690eSMarcus Meissner .alg = "authenc(hmac(sha384),rfc3686(ctr(aes)))", 24508888690eSMarcus Meissner .test = alg_test_null, 24518888690eSMarcus Meissner .fips_allowed = 1, 24528888690eSMarcus Meissner }, { 2453a4198fd4SHerbert Xu .alg = "authenc(hmac(sha512),cbc(aes))", 2454ed1afac9SMarcus Meissner .fips_allowed = 1, 2455e46e9a46SHoria Geanta .test = alg_test_aead, 2456e46e9a46SHoria Geanta .suite = { 2457e46e9a46SHoria Geanta .aead = { 245821c8e720SArd Biesheuvel .enc = __VECS(hmac_sha512_aes_cbc_enc_tv_temp) 24595208ed2cSNitesh Lal } 24605208ed2cSNitesh Lal } 24615208ed2cSNitesh Lal }, { 2462a4198fd4SHerbert Xu .alg = "authenc(hmac(sha512),cbc(des))", 24635208ed2cSNitesh Lal .test = alg_test_aead, 24645208ed2cSNitesh Lal .suite = { 24655208ed2cSNitesh Lal .aead = { 246621c8e720SArd Biesheuvel .enc = __VECS(hmac_sha512_des_cbc_enc_tv_temp) 24675208ed2cSNitesh Lal } 24685208ed2cSNitesh Lal } 24695208ed2cSNitesh Lal }, { 2470a4198fd4SHerbert Xu .alg = "authenc(hmac(sha512),cbc(des3_ede))", 24715208ed2cSNitesh Lal .test = alg_test_aead, 2472ed1afac9SMarcus Meissner .fips_allowed = 1, 24735208ed2cSNitesh Lal .suite = { 24745208ed2cSNitesh Lal .aead = { 247521c8e720SArd Biesheuvel .enc = __VECS(hmac_sha512_des3_ede_cbc_enc_tv_temp) 2476e46e9a46SHoria Geanta } 2477e46e9a46SHoria Geanta } 2478e46e9a46SHoria Geanta }, { 2479fb16abc2SMarcus Meissner .alg = "authenc(hmac(sha512),ctr(aes))", 2480fb16abc2SMarcus Meissner .test = alg_test_null, 2481fb16abc2SMarcus Meissner .fips_allowed = 1, 2482fb16abc2SMarcus Meissner }, { 24838888690eSMarcus Meissner .alg = "authenc(hmac(sha512),rfc3686(ctr(aes)))", 24848888690eSMarcus Meissner .test = alg_test_null, 24858888690eSMarcus Meissner .fips_allowed = 1, 24868888690eSMarcus Meissner }, { 2487da7f033dSHerbert Xu .alg = "cbc(aes)", 24881aa4ecd9SHerbert Xu .test = alg_test_skcipher, 2489a1915d51SJarod Wilson .fips_allowed = 1, 2490da7f033dSHerbert Xu .suite = { 2491da7f033dSHerbert Xu .cipher = { 249221c8e720SArd Biesheuvel .enc = __VECS(aes_cbc_enc_tv_template), 249321c8e720SArd Biesheuvel .dec = __VECS(aes_cbc_dec_tv_template) 2494da7f033dSHerbert Xu } 2495da7f033dSHerbert Xu } 2496da7f033dSHerbert Xu }, { 2497da7f033dSHerbert Xu .alg = "cbc(anubis)", 24981aa4ecd9SHerbert Xu .test = alg_test_skcipher, 2499da7f033dSHerbert Xu .suite = { 2500da7f033dSHerbert Xu .cipher = { 250121c8e720SArd Biesheuvel .enc = __VECS(anubis_cbc_enc_tv_template), 250221c8e720SArd Biesheuvel .dec = __VECS(anubis_cbc_dec_tv_template) 2503da7f033dSHerbert Xu } 2504da7f033dSHerbert Xu } 2505da7f033dSHerbert Xu }, { 2506da7f033dSHerbert Xu .alg = "cbc(blowfish)", 25071aa4ecd9SHerbert Xu .test = alg_test_skcipher, 2508da7f033dSHerbert Xu .suite = { 2509da7f033dSHerbert Xu .cipher = { 251021c8e720SArd Biesheuvel .enc = __VECS(bf_cbc_enc_tv_template), 251121c8e720SArd Biesheuvel .dec = __VECS(bf_cbc_dec_tv_template) 2512da7f033dSHerbert Xu } 2513da7f033dSHerbert Xu } 2514da7f033dSHerbert Xu }, { 2515da7f033dSHerbert Xu .alg = "cbc(camellia)", 25161aa4ecd9SHerbert Xu .test = alg_test_skcipher, 2517da7f033dSHerbert Xu .suite = { 2518da7f033dSHerbert Xu .cipher = { 251921c8e720SArd Biesheuvel .enc = __VECS(camellia_cbc_enc_tv_template), 252021c8e720SArd Biesheuvel .dec = __VECS(camellia_cbc_dec_tv_template) 2521da7f033dSHerbert Xu } 2522da7f033dSHerbert Xu } 2523da7f033dSHerbert Xu }, { 2524a2c58260SJohannes Goetzfried .alg = "cbc(cast5)", 2525a2c58260SJohannes Goetzfried .test = alg_test_skcipher, 2526a2c58260SJohannes Goetzfried .suite = { 2527a2c58260SJohannes Goetzfried .cipher = { 252821c8e720SArd Biesheuvel .enc = __VECS(cast5_cbc_enc_tv_template), 252921c8e720SArd Biesheuvel .dec = __VECS(cast5_cbc_dec_tv_template) 2530a2c58260SJohannes Goetzfried } 2531a2c58260SJohannes Goetzfried } 2532a2c58260SJohannes Goetzfried }, { 25339b8b0405SJohannes Goetzfried .alg = "cbc(cast6)", 25349b8b0405SJohannes Goetzfried .test = alg_test_skcipher, 25359b8b0405SJohannes Goetzfried .suite = { 25369b8b0405SJohannes Goetzfried .cipher = { 253721c8e720SArd Biesheuvel .enc = __VECS(cast6_cbc_enc_tv_template), 253821c8e720SArd Biesheuvel .dec = __VECS(cast6_cbc_dec_tv_template) 25399b8b0405SJohannes Goetzfried } 25409b8b0405SJohannes Goetzfried } 25419b8b0405SJohannes Goetzfried }, { 2542da7f033dSHerbert Xu .alg = "cbc(des)", 25431aa4ecd9SHerbert Xu .test = alg_test_skcipher, 2544da7f033dSHerbert Xu .suite = { 2545da7f033dSHerbert Xu .cipher = { 254621c8e720SArd Biesheuvel .enc = __VECS(des_cbc_enc_tv_template), 254721c8e720SArd Biesheuvel .dec = __VECS(des_cbc_dec_tv_template) 2548da7f033dSHerbert Xu } 2549da7f033dSHerbert Xu } 2550da7f033dSHerbert Xu }, { 2551da7f033dSHerbert Xu .alg = "cbc(des3_ede)", 25521aa4ecd9SHerbert Xu .test = alg_test_skcipher, 2553a1915d51SJarod Wilson .fips_allowed = 1, 2554da7f033dSHerbert Xu .suite = { 2555da7f033dSHerbert Xu .cipher = { 255621c8e720SArd Biesheuvel .enc = __VECS(des3_ede_cbc_enc_tv_template), 255721c8e720SArd Biesheuvel .dec = __VECS(des3_ede_cbc_dec_tv_template) 2558da7f033dSHerbert Xu } 2559da7f033dSHerbert Xu } 2560da7f033dSHerbert Xu }, { 25619d25917dSJussi Kivilinna .alg = "cbc(serpent)", 25629d25917dSJussi Kivilinna .test = alg_test_skcipher, 25639d25917dSJussi Kivilinna .suite = { 25649d25917dSJussi Kivilinna .cipher = { 256521c8e720SArd Biesheuvel .enc = __VECS(serpent_cbc_enc_tv_template), 256621c8e720SArd Biesheuvel .dec = __VECS(serpent_cbc_dec_tv_template) 25679d25917dSJussi Kivilinna } 25689d25917dSJussi Kivilinna } 25699d25917dSJussi Kivilinna }, { 2570da7f033dSHerbert Xu .alg = "cbc(twofish)", 25711aa4ecd9SHerbert Xu .test = alg_test_skcipher, 2572da7f033dSHerbert Xu .suite = { 2573da7f033dSHerbert Xu .cipher = { 257421c8e720SArd Biesheuvel .enc = __VECS(tf_cbc_enc_tv_template), 257521c8e720SArd Biesheuvel .dec = __VECS(tf_cbc_dec_tv_template) 2576da7f033dSHerbert Xu } 2577da7f033dSHerbert Xu } 2578da7f033dSHerbert Xu }, { 2579092acf06SArd Biesheuvel .alg = "cbcmac(aes)", 2580092acf06SArd Biesheuvel .fips_allowed = 1, 2581092acf06SArd Biesheuvel .test = alg_test_hash, 2582092acf06SArd Biesheuvel .suite = { 2583092acf06SArd Biesheuvel .hash = __VECS(aes_cbcmac_tv_template) 2584092acf06SArd Biesheuvel } 2585092acf06SArd Biesheuvel }, { 2586da7f033dSHerbert Xu .alg = "ccm(aes)", 2587da7f033dSHerbert Xu .test = alg_test_aead, 2588a1915d51SJarod Wilson .fips_allowed = 1, 2589da7f033dSHerbert Xu .suite = { 2590da7f033dSHerbert Xu .aead = { 259121c8e720SArd Biesheuvel .enc = __VECS(aes_ccm_enc_tv_template), 259221c8e720SArd Biesheuvel .dec = __VECS(aes_ccm_dec_tv_template) 2593da7f033dSHerbert Xu } 2594da7f033dSHerbert Xu } 2595da7f033dSHerbert Xu }, { 25963590ebf2SMartin Willi .alg = "chacha20", 25973590ebf2SMartin Willi .test = alg_test_skcipher, 25983590ebf2SMartin Willi .suite = { 25993590ebf2SMartin Willi .cipher = { 260021c8e720SArd Biesheuvel .enc = __VECS(chacha20_enc_tv_template), 260121c8e720SArd Biesheuvel .dec = __VECS(chacha20_enc_tv_template), 26023590ebf2SMartin Willi } 26033590ebf2SMartin Willi } 26043590ebf2SMartin Willi }, { 260593b5e86aSJussi Kivilinna .alg = "cmac(aes)", 26068f183751SStephan Mueller .fips_allowed = 1, 260793b5e86aSJussi Kivilinna .test = alg_test_hash, 260893b5e86aSJussi Kivilinna .suite = { 260921c8e720SArd Biesheuvel .hash = __VECS(aes_cmac128_tv_template) 261093b5e86aSJussi Kivilinna } 261193b5e86aSJussi Kivilinna }, { 261293b5e86aSJussi Kivilinna .alg = "cmac(des3_ede)", 26138f183751SStephan Mueller .fips_allowed = 1, 261493b5e86aSJussi Kivilinna .test = alg_test_hash, 261593b5e86aSJussi Kivilinna .suite = { 261621c8e720SArd Biesheuvel .hash = __VECS(des3_ede_cmac64_tv_template) 261793b5e86aSJussi Kivilinna } 261893b5e86aSJussi Kivilinna }, { 2619e448370dSJussi Kivilinna .alg = "compress_null", 2620e448370dSJussi Kivilinna .test = alg_test_null, 2621e448370dSJussi Kivilinna }, { 2622ebb3472fSArd Biesheuvel .alg = "crc32", 2623ebb3472fSArd Biesheuvel .test = alg_test_hash, 2624ebb3472fSArd Biesheuvel .suite = { 262521c8e720SArd Biesheuvel .hash = __VECS(crc32_tv_template) 2626ebb3472fSArd Biesheuvel } 2627ebb3472fSArd Biesheuvel }, { 2628da7f033dSHerbert Xu .alg = "crc32c", 26298e3ee85eSHerbert Xu .test = alg_test_crc32c, 2630a1915d51SJarod Wilson .fips_allowed = 1, 2631da7f033dSHerbert Xu .suite = { 263221c8e720SArd Biesheuvel .hash = __VECS(crc32c_tv_template) 2633da7f033dSHerbert Xu } 2634da7f033dSHerbert Xu }, { 263568411521SHerbert Xu .alg = "crct10dif", 263668411521SHerbert Xu .test = alg_test_hash, 263768411521SHerbert Xu .fips_allowed = 1, 263868411521SHerbert Xu .suite = { 263921c8e720SArd Biesheuvel .hash = __VECS(crct10dif_tv_template) 264068411521SHerbert Xu } 264168411521SHerbert Xu }, { 2642f7cb80f2SJarod Wilson .alg = "ctr(aes)", 2643f7cb80f2SJarod Wilson .test = alg_test_skcipher, 2644a1915d51SJarod Wilson .fips_allowed = 1, 2645f7cb80f2SJarod Wilson .suite = { 2646f7cb80f2SJarod Wilson .cipher = { 264721c8e720SArd Biesheuvel .enc = __VECS(aes_ctr_enc_tv_template), 264821c8e720SArd Biesheuvel .dec = __VECS(aes_ctr_dec_tv_template) 2649f7cb80f2SJarod Wilson } 2650f7cb80f2SJarod Wilson } 2651f7cb80f2SJarod Wilson }, { 265285b63e34SJussi Kivilinna .alg = "ctr(blowfish)", 265385b63e34SJussi Kivilinna .test = alg_test_skcipher, 265485b63e34SJussi Kivilinna .suite = { 265585b63e34SJussi Kivilinna .cipher = { 265621c8e720SArd Biesheuvel .enc = __VECS(bf_ctr_enc_tv_template), 265721c8e720SArd Biesheuvel .dec = __VECS(bf_ctr_dec_tv_template) 265885b63e34SJussi Kivilinna } 265985b63e34SJussi Kivilinna } 266085b63e34SJussi Kivilinna }, { 26610840605eSJussi Kivilinna .alg = "ctr(camellia)", 26620840605eSJussi Kivilinna .test = alg_test_skcipher, 26630840605eSJussi Kivilinna .suite = { 26640840605eSJussi Kivilinna .cipher = { 266521c8e720SArd Biesheuvel .enc = __VECS(camellia_ctr_enc_tv_template), 266621c8e720SArd Biesheuvel .dec = __VECS(camellia_ctr_dec_tv_template) 26670840605eSJussi Kivilinna } 26680840605eSJussi Kivilinna } 26690840605eSJussi Kivilinna }, { 2670a2c58260SJohannes Goetzfried .alg = "ctr(cast5)", 2671a2c58260SJohannes Goetzfried .test = alg_test_skcipher, 2672a2c58260SJohannes Goetzfried .suite = { 2673a2c58260SJohannes Goetzfried .cipher = { 267421c8e720SArd Biesheuvel .enc = __VECS(cast5_ctr_enc_tv_template), 267521c8e720SArd Biesheuvel .dec = __VECS(cast5_ctr_dec_tv_template) 2676a2c58260SJohannes Goetzfried } 2677a2c58260SJohannes Goetzfried } 2678a2c58260SJohannes Goetzfried }, { 26799b8b0405SJohannes Goetzfried .alg = "ctr(cast6)", 26809b8b0405SJohannes Goetzfried .test = alg_test_skcipher, 26819b8b0405SJohannes Goetzfried .suite = { 26829b8b0405SJohannes Goetzfried .cipher = { 268321c8e720SArd Biesheuvel .enc = __VECS(cast6_ctr_enc_tv_template), 268421c8e720SArd Biesheuvel .dec = __VECS(cast6_ctr_dec_tv_template) 26859b8b0405SJohannes Goetzfried } 26869b8b0405SJohannes Goetzfried } 26879b8b0405SJohannes Goetzfried }, { 26888163fc30SJussi Kivilinna .alg = "ctr(des)", 26898163fc30SJussi Kivilinna .test = alg_test_skcipher, 26908163fc30SJussi Kivilinna .suite = { 26918163fc30SJussi Kivilinna .cipher = { 269221c8e720SArd Biesheuvel .enc = __VECS(des_ctr_enc_tv_template), 269321c8e720SArd Biesheuvel .dec = __VECS(des_ctr_dec_tv_template) 26948163fc30SJussi Kivilinna } 26958163fc30SJussi Kivilinna } 26968163fc30SJussi Kivilinna }, { 2697e080b17aSJussi Kivilinna .alg = "ctr(des3_ede)", 2698e080b17aSJussi Kivilinna .test = alg_test_skcipher, 26990d8da104SMarcelo Cerri .fips_allowed = 1, 2700e080b17aSJussi Kivilinna .suite = { 2701e080b17aSJussi Kivilinna .cipher = { 270221c8e720SArd Biesheuvel .enc = __VECS(des3_ede_ctr_enc_tv_template), 270321c8e720SArd Biesheuvel .dec = __VECS(des3_ede_ctr_dec_tv_template) 2704e080b17aSJussi Kivilinna } 2705e080b17aSJussi Kivilinna } 2706e080b17aSJussi Kivilinna }, { 27079d25917dSJussi Kivilinna .alg = "ctr(serpent)", 27089d25917dSJussi Kivilinna .test = alg_test_skcipher, 27099d25917dSJussi Kivilinna .suite = { 27109d25917dSJussi Kivilinna .cipher = { 271121c8e720SArd Biesheuvel .enc = __VECS(serpent_ctr_enc_tv_template), 271221c8e720SArd Biesheuvel .dec = __VECS(serpent_ctr_dec_tv_template) 27139d25917dSJussi Kivilinna } 27149d25917dSJussi Kivilinna } 27159d25917dSJussi Kivilinna }, { 2716573da620SJussi Kivilinna .alg = "ctr(twofish)", 2717573da620SJussi Kivilinna .test = alg_test_skcipher, 2718573da620SJussi Kivilinna .suite = { 2719573da620SJussi Kivilinna .cipher = { 272021c8e720SArd Biesheuvel .enc = __VECS(tf_ctr_enc_tv_template), 272121c8e720SArd Biesheuvel .dec = __VECS(tf_ctr_dec_tv_template) 2722573da620SJussi Kivilinna } 2723573da620SJussi Kivilinna } 2724573da620SJussi Kivilinna }, { 2725da7f033dSHerbert Xu .alg = "cts(cbc(aes))", 27261aa4ecd9SHerbert Xu .test = alg_test_skcipher, 2727da7f033dSHerbert Xu .suite = { 2728da7f033dSHerbert Xu .cipher = { 272921c8e720SArd Biesheuvel .enc = __VECS(cts_mode_enc_tv_template), 273021c8e720SArd Biesheuvel .dec = __VECS(cts_mode_dec_tv_template) 2731da7f033dSHerbert Xu } 2732da7f033dSHerbert Xu } 2733da7f033dSHerbert Xu }, { 2734da7f033dSHerbert Xu .alg = "deflate", 2735da7f033dSHerbert Xu .test = alg_test_comp, 27360818904dSMilan Broz .fips_allowed = 1, 2737da7f033dSHerbert Xu .suite = { 2738da7f033dSHerbert Xu .comp = { 273921c8e720SArd Biesheuvel .comp = __VECS(deflate_comp_tv_template), 274021c8e720SArd Biesheuvel .decomp = __VECS(deflate_decomp_tv_template) 2741da7f033dSHerbert Xu } 2742da7f033dSHerbert Xu } 2743da7f033dSHerbert Xu }, { 2744802c7f1cSSalvatore Benedetto .alg = "dh", 2745802c7f1cSSalvatore Benedetto .test = alg_test_kpp, 2746802c7f1cSSalvatore Benedetto .fips_allowed = 1, 2747802c7f1cSSalvatore Benedetto .suite = { 274821c8e720SArd Biesheuvel .kpp = __VECS(dh_tv_template) 2749802c7f1cSSalvatore Benedetto } 2750802c7f1cSSalvatore Benedetto }, { 2751e448370dSJussi Kivilinna .alg = "digest_null", 2752e448370dSJussi Kivilinna .test = alg_test_null, 2753e448370dSJussi Kivilinna }, { 275464d1cdfbSStephan Mueller .alg = "drbg_nopr_ctr_aes128", 275564d1cdfbSStephan Mueller .test = alg_test_drbg, 275664d1cdfbSStephan Mueller .fips_allowed = 1, 275764d1cdfbSStephan Mueller .suite = { 275821c8e720SArd Biesheuvel .drbg = __VECS(drbg_nopr_ctr_aes128_tv_template) 275964d1cdfbSStephan Mueller } 276064d1cdfbSStephan Mueller }, { 276164d1cdfbSStephan Mueller .alg = "drbg_nopr_ctr_aes192", 276264d1cdfbSStephan Mueller .test = alg_test_drbg, 276364d1cdfbSStephan Mueller .fips_allowed = 1, 276464d1cdfbSStephan Mueller .suite = { 276521c8e720SArd Biesheuvel .drbg = __VECS(drbg_nopr_ctr_aes192_tv_template) 276664d1cdfbSStephan Mueller } 276764d1cdfbSStephan Mueller }, { 276864d1cdfbSStephan Mueller .alg = "drbg_nopr_ctr_aes256", 276964d1cdfbSStephan Mueller .test = alg_test_drbg, 277064d1cdfbSStephan Mueller .fips_allowed = 1, 277164d1cdfbSStephan Mueller .suite = { 277221c8e720SArd Biesheuvel .drbg = __VECS(drbg_nopr_ctr_aes256_tv_template) 277364d1cdfbSStephan Mueller } 277464d1cdfbSStephan Mueller }, { 277564d1cdfbSStephan Mueller /* 277664d1cdfbSStephan Mueller * There is no need to specifically test the DRBG with every 277764d1cdfbSStephan Mueller * backend cipher -- covered by drbg_nopr_hmac_sha256 test 277864d1cdfbSStephan Mueller */ 277964d1cdfbSStephan Mueller .alg = "drbg_nopr_hmac_sha1", 278064d1cdfbSStephan Mueller .fips_allowed = 1, 278164d1cdfbSStephan Mueller .test = alg_test_null, 278264d1cdfbSStephan Mueller }, { 278364d1cdfbSStephan Mueller .alg = "drbg_nopr_hmac_sha256", 278464d1cdfbSStephan Mueller .test = alg_test_drbg, 278564d1cdfbSStephan Mueller .fips_allowed = 1, 278664d1cdfbSStephan Mueller .suite = { 278721c8e720SArd Biesheuvel .drbg = __VECS(drbg_nopr_hmac_sha256_tv_template) 278864d1cdfbSStephan Mueller } 278964d1cdfbSStephan Mueller }, { 279064d1cdfbSStephan Mueller /* covered by drbg_nopr_hmac_sha256 test */ 279164d1cdfbSStephan Mueller .alg = "drbg_nopr_hmac_sha384", 279264d1cdfbSStephan Mueller .fips_allowed = 1, 279364d1cdfbSStephan Mueller .test = alg_test_null, 279464d1cdfbSStephan Mueller }, { 279564d1cdfbSStephan Mueller .alg = "drbg_nopr_hmac_sha512", 279664d1cdfbSStephan Mueller .test = alg_test_null, 279764d1cdfbSStephan Mueller .fips_allowed = 1, 279864d1cdfbSStephan Mueller }, { 279964d1cdfbSStephan Mueller .alg = "drbg_nopr_sha1", 280064d1cdfbSStephan Mueller .fips_allowed = 1, 280164d1cdfbSStephan Mueller .test = alg_test_null, 280264d1cdfbSStephan Mueller }, { 280364d1cdfbSStephan Mueller .alg = "drbg_nopr_sha256", 280464d1cdfbSStephan Mueller .test = alg_test_drbg, 280564d1cdfbSStephan Mueller .fips_allowed = 1, 280664d1cdfbSStephan Mueller .suite = { 280721c8e720SArd Biesheuvel .drbg = __VECS(drbg_nopr_sha256_tv_template) 280864d1cdfbSStephan Mueller } 280964d1cdfbSStephan Mueller }, { 281064d1cdfbSStephan Mueller /* covered by drbg_nopr_sha256 test */ 281164d1cdfbSStephan Mueller .alg = "drbg_nopr_sha384", 281264d1cdfbSStephan Mueller .fips_allowed = 1, 281364d1cdfbSStephan Mueller .test = alg_test_null, 281464d1cdfbSStephan Mueller }, { 281564d1cdfbSStephan Mueller .alg = "drbg_nopr_sha512", 281664d1cdfbSStephan Mueller .fips_allowed = 1, 281764d1cdfbSStephan Mueller .test = alg_test_null, 281864d1cdfbSStephan Mueller }, { 281964d1cdfbSStephan Mueller .alg = "drbg_pr_ctr_aes128", 282064d1cdfbSStephan Mueller .test = alg_test_drbg, 282164d1cdfbSStephan Mueller .fips_allowed = 1, 282264d1cdfbSStephan Mueller .suite = { 282321c8e720SArd Biesheuvel .drbg = __VECS(drbg_pr_ctr_aes128_tv_template) 282464d1cdfbSStephan Mueller } 282564d1cdfbSStephan Mueller }, { 282664d1cdfbSStephan Mueller /* covered by drbg_pr_ctr_aes128 test */ 282764d1cdfbSStephan Mueller .alg = "drbg_pr_ctr_aes192", 282864d1cdfbSStephan Mueller .fips_allowed = 1, 282964d1cdfbSStephan Mueller .test = alg_test_null, 283064d1cdfbSStephan Mueller }, { 283164d1cdfbSStephan Mueller .alg = "drbg_pr_ctr_aes256", 283264d1cdfbSStephan Mueller .fips_allowed = 1, 283364d1cdfbSStephan Mueller .test = alg_test_null, 283464d1cdfbSStephan Mueller }, { 283564d1cdfbSStephan Mueller .alg = "drbg_pr_hmac_sha1", 283664d1cdfbSStephan Mueller .fips_allowed = 1, 283764d1cdfbSStephan Mueller .test = alg_test_null, 283864d1cdfbSStephan Mueller }, { 283964d1cdfbSStephan Mueller .alg = "drbg_pr_hmac_sha256", 284064d1cdfbSStephan Mueller .test = alg_test_drbg, 284164d1cdfbSStephan Mueller .fips_allowed = 1, 284264d1cdfbSStephan Mueller .suite = { 284321c8e720SArd Biesheuvel .drbg = __VECS(drbg_pr_hmac_sha256_tv_template) 284464d1cdfbSStephan Mueller } 284564d1cdfbSStephan Mueller }, { 284664d1cdfbSStephan Mueller /* covered by drbg_pr_hmac_sha256 test */ 284764d1cdfbSStephan Mueller .alg = "drbg_pr_hmac_sha384", 284864d1cdfbSStephan Mueller .fips_allowed = 1, 284964d1cdfbSStephan Mueller .test = alg_test_null, 285064d1cdfbSStephan Mueller }, { 285164d1cdfbSStephan Mueller .alg = "drbg_pr_hmac_sha512", 285264d1cdfbSStephan Mueller .test = alg_test_null, 285364d1cdfbSStephan Mueller .fips_allowed = 1, 285464d1cdfbSStephan Mueller }, { 285564d1cdfbSStephan Mueller .alg = "drbg_pr_sha1", 285664d1cdfbSStephan Mueller .fips_allowed = 1, 285764d1cdfbSStephan Mueller .test = alg_test_null, 285864d1cdfbSStephan Mueller }, { 285964d1cdfbSStephan Mueller .alg = "drbg_pr_sha256", 286064d1cdfbSStephan Mueller .test = alg_test_drbg, 286164d1cdfbSStephan Mueller .fips_allowed = 1, 286264d1cdfbSStephan Mueller .suite = { 286321c8e720SArd Biesheuvel .drbg = __VECS(drbg_pr_sha256_tv_template) 286464d1cdfbSStephan Mueller } 286564d1cdfbSStephan Mueller }, { 286664d1cdfbSStephan Mueller /* covered by drbg_pr_sha256 test */ 286764d1cdfbSStephan Mueller .alg = "drbg_pr_sha384", 286864d1cdfbSStephan Mueller .fips_allowed = 1, 286964d1cdfbSStephan Mueller .test = alg_test_null, 287064d1cdfbSStephan Mueller }, { 287164d1cdfbSStephan Mueller .alg = "drbg_pr_sha512", 287264d1cdfbSStephan Mueller .fips_allowed = 1, 287364d1cdfbSStephan Mueller .test = alg_test_null, 287464d1cdfbSStephan Mueller }, { 2875da7f033dSHerbert Xu .alg = "ecb(aes)", 28761aa4ecd9SHerbert Xu .test = alg_test_skcipher, 2877a1915d51SJarod Wilson .fips_allowed = 1, 2878da7f033dSHerbert Xu .suite = { 2879da7f033dSHerbert Xu .cipher = { 288021c8e720SArd Biesheuvel .enc = __VECS(aes_enc_tv_template), 288121c8e720SArd Biesheuvel .dec = __VECS(aes_dec_tv_template) 2882da7f033dSHerbert Xu } 2883da7f033dSHerbert Xu } 2884da7f033dSHerbert Xu }, { 2885da7f033dSHerbert Xu .alg = "ecb(anubis)", 28861aa4ecd9SHerbert Xu .test = alg_test_skcipher, 2887da7f033dSHerbert Xu .suite = { 2888da7f033dSHerbert Xu .cipher = { 288921c8e720SArd Biesheuvel .enc = __VECS(anubis_enc_tv_template), 289021c8e720SArd Biesheuvel .dec = __VECS(anubis_dec_tv_template) 2891da7f033dSHerbert Xu } 2892da7f033dSHerbert Xu } 2893da7f033dSHerbert Xu }, { 2894da7f033dSHerbert Xu .alg = "ecb(arc4)", 28951aa4ecd9SHerbert Xu .test = alg_test_skcipher, 2896da7f033dSHerbert Xu .suite = { 2897da7f033dSHerbert Xu .cipher = { 289821c8e720SArd Biesheuvel .enc = __VECS(arc4_enc_tv_template), 289921c8e720SArd Biesheuvel .dec = __VECS(arc4_dec_tv_template) 2900da7f033dSHerbert Xu } 2901da7f033dSHerbert Xu } 2902da7f033dSHerbert Xu }, { 2903da7f033dSHerbert Xu .alg = "ecb(blowfish)", 29041aa4ecd9SHerbert Xu .test = alg_test_skcipher, 2905da7f033dSHerbert Xu .suite = { 2906da7f033dSHerbert Xu .cipher = { 290721c8e720SArd Biesheuvel .enc = __VECS(bf_enc_tv_template), 290821c8e720SArd Biesheuvel .dec = __VECS(bf_dec_tv_template) 2909da7f033dSHerbert Xu } 2910da7f033dSHerbert Xu } 2911da7f033dSHerbert Xu }, { 2912da7f033dSHerbert Xu .alg = "ecb(camellia)", 29131aa4ecd9SHerbert Xu .test = alg_test_skcipher, 2914da7f033dSHerbert Xu .suite = { 2915da7f033dSHerbert Xu .cipher = { 291621c8e720SArd Biesheuvel .enc = __VECS(camellia_enc_tv_template), 291721c8e720SArd Biesheuvel .dec = __VECS(camellia_dec_tv_template) 2918da7f033dSHerbert Xu } 2919da7f033dSHerbert Xu } 2920da7f033dSHerbert Xu }, { 2921da7f033dSHerbert Xu .alg = "ecb(cast5)", 29221aa4ecd9SHerbert Xu .test = alg_test_skcipher, 2923da7f033dSHerbert Xu .suite = { 2924da7f033dSHerbert Xu .cipher = { 292521c8e720SArd Biesheuvel .enc = __VECS(cast5_enc_tv_template), 292621c8e720SArd Biesheuvel .dec = __VECS(cast5_dec_tv_template) 2927da7f033dSHerbert Xu } 2928da7f033dSHerbert Xu } 2929da7f033dSHerbert Xu }, { 2930da7f033dSHerbert Xu .alg = "ecb(cast6)", 29311aa4ecd9SHerbert Xu .test = alg_test_skcipher, 2932da7f033dSHerbert Xu .suite = { 2933da7f033dSHerbert Xu .cipher = { 293421c8e720SArd Biesheuvel .enc = __VECS(cast6_enc_tv_template), 293521c8e720SArd Biesheuvel .dec = __VECS(cast6_dec_tv_template) 2936da7f033dSHerbert Xu } 2937da7f033dSHerbert Xu } 2938da7f033dSHerbert Xu }, { 2939e448370dSJussi Kivilinna .alg = "ecb(cipher_null)", 2940e448370dSJussi Kivilinna .test = alg_test_null, 29416175ca2bSMilan Broz .fips_allowed = 1, 2942e448370dSJussi Kivilinna }, { 2943da7f033dSHerbert Xu .alg = "ecb(des)", 29441aa4ecd9SHerbert Xu .test = alg_test_skcipher, 2945da7f033dSHerbert Xu .suite = { 2946da7f033dSHerbert Xu .cipher = { 294721c8e720SArd Biesheuvel .enc = __VECS(des_enc_tv_template), 294821c8e720SArd Biesheuvel .dec = __VECS(des_dec_tv_template) 2949da7f033dSHerbert Xu } 2950da7f033dSHerbert Xu } 2951da7f033dSHerbert Xu }, { 2952da7f033dSHerbert Xu .alg = "ecb(des3_ede)", 29531aa4ecd9SHerbert Xu .test = alg_test_skcipher, 2954a1915d51SJarod Wilson .fips_allowed = 1, 2955da7f033dSHerbert Xu .suite = { 2956da7f033dSHerbert Xu .cipher = { 295721c8e720SArd Biesheuvel .enc = __VECS(des3_ede_enc_tv_template), 295821c8e720SArd Biesheuvel .dec = __VECS(des3_ede_dec_tv_template) 2959da7f033dSHerbert Xu } 2960da7f033dSHerbert Xu } 2961da7f033dSHerbert Xu }, { 296266e5bd00SJussi Kivilinna .alg = "ecb(fcrypt)", 296366e5bd00SJussi Kivilinna .test = alg_test_skcipher, 296466e5bd00SJussi Kivilinna .suite = { 296566e5bd00SJussi Kivilinna .cipher = { 296666e5bd00SJussi Kivilinna .enc = { 296766e5bd00SJussi Kivilinna .vecs = fcrypt_pcbc_enc_tv_template, 296866e5bd00SJussi Kivilinna .count = 1 296966e5bd00SJussi Kivilinna }, 297066e5bd00SJussi Kivilinna .dec = { 297166e5bd00SJussi Kivilinna .vecs = fcrypt_pcbc_dec_tv_template, 297266e5bd00SJussi Kivilinna .count = 1 297366e5bd00SJussi Kivilinna } 297466e5bd00SJussi Kivilinna } 297566e5bd00SJussi Kivilinna } 297666e5bd00SJussi Kivilinna }, { 2977da7f033dSHerbert Xu .alg = "ecb(khazad)", 29781aa4ecd9SHerbert Xu .test = alg_test_skcipher, 2979da7f033dSHerbert Xu .suite = { 2980da7f033dSHerbert Xu .cipher = { 298121c8e720SArd Biesheuvel .enc = __VECS(khazad_enc_tv_template), 298221c8e720SArd Biesheuvel .dec = __VECS(khazad_dec_tv_template) 2983da7f033dSHerbert Xu } 2984da7f033dSHerbert Xu } 2985da7f033dSHerbert Xu }, { 2986da7f033dSHerbert Xu .alg = "ecb(seed)", 29871aa4ecd9SHerbert Xu .test = alg_test_skcipher, 2988da7f033dSHerbert Xu .suite = { 2989da7f033dSHerbert Xu .cipher = { 299021c8e720SArd Biesheuvel .enc = __VECS(seed_enc_tv_template), 299121c8e720SArd Biesheuvel .dec = __VECS(seed_dec_tv_template) 2992da7f033dSHerbert Xu } 2993da7f033dSHerbert Xu } 2994da7f033dSHerbert Xu }, { 2995da7f033dSHerbert Xu .alg = "ecb(serpent)", 29961aa4ecd9SHerbert Xu .test = alg_test_skcipher, 2997da7f033dSHerbert Xu .suite = { 2998da7f033dSHerbert Xu .cipher = { 299921c8e720SArd Biesheuvel .enc = __VECS(serpent_enc_tv_template), 300021c8e720SArd Biesheuvel .dec = __VECS(serpent_dec_tv_template) 3001da7f033dSHerbert Xu } 3002da7f033dSHerbert Xu } 3003da7f033dSHerbert Xu }, { 3004da7a0ab5SEric Biggers .alg = "ecb(speck128)", 3005da7a0ab5SEric Biggers .test = alg_test_skcipher, 3006da7a0ab5SEric Biggers .suite = { 3007da7a0ab5SEric Biggers .cipher = { 3008da7a0ab5SEric Biggers .enc = __VECS(speck128_enc_tv_template), 3009da7a0ab5SEric Biggers .dec = __VECS(speck128_dec_tv_template) 3010da7a0ab5SEric Biggers } 3011da7a0ab5SEric Biggers } 3012da7a0ab5SEric Biggers }, { 3013da7a0ab5SEric Biggers .alg = "ecb(speck64)", 3014da7a0ab5SEric Biggers .test = alg_test_skcipher, 3015da7a0ab5SEric Biggers .suite = { 3016da7a0ab5SEric Biggers .cipher = { 3017da7a0ab5SEric Biggers .enc = __VECS(speck64_enc_tv_template), 3018da7a0ab5SEric Biggers .dec = __VECS(speck64_dec_tv_template) 3019da7a0ab5SEric Biggers } 3020da7a0ab5SEric Biggers } 3021da7a0ab5SEric Biggers }, { 3022da7f033dSHerbert Xu .alg = "ecb(tea)", 30231aa4ecd9SHerbert Xu .test = alg_test_skcipher, 3024da7f033dSHerbert Xu .suite = { 3025da7f033dSHerbert Xu .cipher = { 302621c8e720SArd Biesheuvel .enc = __VECS(tea_enc_tv_template), 302721c8e720SArd Biesheuvel .dec = __VECS(tea_dec_tv_template) 3028da7f033dSHerbert Xu } 3029da7f033dSHerbert Xu } 3030da7f033dSHerbert Xu }, { 3031da7f033dSHerbert Xu .alg = "ecb(tnepres)", 30321aa4ecd9SHerbert Xu .test = alg_test_skcipher, 3033da7f033dSHerbert Xu .suite = { 3034da7f033dSHerbert Xu .cipher = { 303521c8e720SArd Biesheuvel .enc = __VECS(tnepres_enc_tv_template), 303621c8e720SArd Biesheuvel .dec = __VECS(tnepres_dec_tv_template) 3037da7f033dSHerbert Xu } 3038da7f033dSHerbert Xu } 3039da7f033dSHerbert Xu }, { 3040da7f033dSHerbert Xu .alg = "ecb(twofish)", 30411aa4ecd9SHerbert Xu .test = alg_test_skcipher, 3042da7f033dSHerbert Xu .suite = { 3043da7f033dSHerbert Xu .cipher = { 304421c8e720SArd Biesheuvel .enc = __VECS(tf_enc_tv_template), 304521c8e720SArd Biesheuvel .dec = __VECS(tf_dec_tv_template) 3046da7f033dSHerbert Xu } 3047da7f033dSHerbert Xu } 3048da7f033dSHerbert Xu }, { 3049da7f033dSHerbert Xu .alg = "ecb(xeta)", 30501aa4ecd9SHerbert Xu .test = alg_test_skcipher, 3051da7f033dSHerbert Xu .suite = { 3052da7f033dSHerbert Xu .cipher = { 305321c8e720SArd Biesheuvel .enc = __VECS(xeta_enc_tv_template), 305421c8e720SArd Biesheuvel .dec = __VECS(xeta_dec_tv_template) 3055da7f033dSHerbert Xu } 3056da7f033dSHerbert Xu } 3057da7f033dSHerbert Xu }, { 3058da7f033dSHerbert Xu .alg = "ecb(xtea)", 30591aa4ecd9SHerbert Xu .test = alg_test_skcipher, 3060da7f033dSHerbert Xu .suite = { 3061da7f033dSHerbert Xu .cipher = { 306221c8e720SArd Biesheuvel .enc = __VECS(xtea_enc_tv_template), 306321c8e720SArd Biesheuvel .dec = __VECS(xtea_dec_tv_template) 3064da7f033dSHerbert Xu } 3065da7f033dSHerbert Xu } 3066da7f033dSHerbert Xu }, { 30673c4b2390SSalvatore Benedetto .alg = "ecdh", 30683c4b2390SSalvatore Benedetto .test = alg_test_kpp, 30693c4b2390SSalvatore Benedetto .fips_allowed = 1, 30703c4b2390SSalvatore Benedetto .suite = { 307121c8e720SArd Biesheuvel .kpp = __VECS(ecdh_tv_template) 30723c4b2390SSalvatore Benedetto } 30733c4b2390SSalvatore Benedetto }, { 3074da7f033dSHerbert Xu .alg = "gcm(aes)", 3075da7f033dSHerbert Xu .test = alg_test_aead, 3076a1915d51SJarod Wilson .fips_allowed = 1, 3077da7f033dSHerbert Xu .suite = { 3078da7f033dSHerbert Xu .aead = { 307921c8e720SArd Biesheuvel .enc = __VECS(aes_gcm_enc_tv_template), 308021c8e720SArd Biesheuvel .dec = __VECS(aes_gcm_dec_tv_template) 3081da7f033dSHerbert Xu } 3082da7f033dSHerbert Xu } 3083da7f033dSHerbert Xu }, { 3084507069c9SYouquan, Song .alg = "ghash", 3085507069c9SYouquan, Song .test = alg_test_hash, 308618c0ebd2SJarod Wilson .fips_allowed = 1, 3087507069c9SYouquan, Song .suite = { 308821c8e720SArd Biesheuvel .hash = __VECS(ghash_tv_template) 3089507069c9SYouquan, Song } 3090507069c9SYouquan, Song }, { 3091a482b081SSonic Zhang .alg = "hmac(crc32)", 3092a482b081SSonic Zhang .test = alg_test_hash, 3093a482b081SSonic Zhang .suite = { 309421c8e720SArd Biesheuvel .hash = __VECS(bfin_crc_tv_template) 3095a482b081SSonic Zhang } 3096a482b081SSonic Zhang }, { 3097da7f033dSHerbert Xu .alg = "hmac(md5)", 3098da7f033dSHerbert Xu .test = alg_test_hash, 3099da7f033dSHerbert Xu .suite = { 310021c8e720SArd Biesheuvel .hash = __VECS(hmac_md5_tv_template) 3101da7f033dSHerbert Xu } 3102da7f033dSHerbert Xu }, { 3103da7f033dSHerbert Xu .alg = "hmac(rmd128)", 3104da7f033dSHerbert Xu .test = alg_test_hash, 3105da7f033dSHerbert Xu .suite = { 310621c8e720SArd Biesheuvel .hash = __VECS(hmac_rmd128_tv_template) 3107da7f033dSHerbert Xu } 3108da7f033dSHerbert Xu }, { 3109da7f033dSHerbert Xu .alg = "hmac(rmd160)", 3110da7f033dSHerbert Xu .test = alg_test_hash, 3111da7f033dSHerbert Xu .suite = { 311221c8e720SArd Biesheuvel .hash = __VECS(hmac_rmd160_tv_template) 3113da7f033dSHerbert Xu } 3114da7f033dSHerbert Xu }, { 3115da7f033dSHerbert Xu .alg = "hmac(sha1)", 3116da7f033dSHerbert Xu .test = alg_test_hash, 3117a1915d51SJarod Wilson .fips_allowed = 1, 3118da7f033dSHerbert Xu .suite = { 311921c8e720SArd Biesheuvel .hash = __VECS(hmac_sha1_tv_template) 3120da7f033dSHerbert Xu } 3121da7f033dSHerbert Xu }, { 3122da7f033dSHerbert Xu .alg = "hmac(sha224)", 3123da7f033dSHerbert Xu .test = alg_test_hash, 3124a1915d51SJarod Wilson .fips_allowed = 1, 3125da7f033dSHerbert Xu .suite = { 312621c8e720SArd Biesheuvel .hash = __VECS(hmac_sha224_tv_template) 3127da7f033dSHerbert Xu } 3128da7f033dSHerbert Xu }, { 3129da7f033dSHerbert Xu .alg = "hmac(sha256)", 3130da7f033dSHerbert Xu .test = alg_test_hash, 3131a1915d51SJarod Wilson .fips_allowed = 1, 3132da7f033dSHerbert Xu .suite = { 313321c8e720SArd Biesheuvel .hash = __VECS(hmac_sha256_tv_template) 3134da7f033dSHerbert Xu } 3135da7f033dSHerbert Xu }, { 313698eca72fSraveendra padasalagi .alg = "hmac(sha3-224)", 313798eca72fSraveendra padasalagi .test = alg_test_hash, 313898eca72fSraveendra padasalagi .fips_allowed = 1, 313998eca72fSraveendra padasalagi .suite = { 314021c8e720SArd Biesheuvel .hash = __VECS(hmac_sha3_224_tv_template) 314198eca72fSraveendra padasalagi } 314298eca72fSraveendra padasalagi }, { 314398eca72fSraveendra padasalagi .alg = "hmac(sha3-256)", 314498eca72fSraveendra padasalagi .test = alg_test_hash, 314598eca72fSraveendra padasalagi .fips_allowed = 1, 314698eca72fSraveendra padasalagi .suite = { 314721c8e720SArd Biesheuvel .hash = __VECS(hmac_sha3_256_tv_template) 314898eca72fSraveendra padasalagi } 314998eca72fSraveendra padasalagi }, { 315098eca72fSraveendra padasalagi .alg = "hmac(sha3-384)", 315198eca72fSraveendra padasalagi .test = alg_test_hash, 315298eca72fSraveendra padasalagi .fips_allowed = 1, 315398eca72fSraveendra padasalagi .suite = { 315421c8e720SArd Biesheuvel .hash = __VECS(hmac_sha3_384_tv_template) 315598eca72fSraveendra padasalagi } 315698eca72fSraveendra padasalagi }, { 315798eca72fSraveendra padasalagi .alg = "hmac(sha3-512)", 315898eca72fSraveendra padasalagi .test = alg_test_hash, 315998eca72fSraveendra padasalagi .fips_allowed = 1, 316098eca72fSraveendra padasalagi .suite = { 316121c8e720SArd Biesheuvel .hash = __VECS(hmac_sha3_512_tv_template) 316298eca72fSraveendra padasalagi } 316398eca72fSraveendra padasalagi }, { 3164da7f033dSHerbert Xu .alg = "hmac(sha384)", 3165da7f033dSHerbert Xu .test = alg_test_hash, 3166a1915d51SJarod Wilson .fips_allowed = 1, 3167da7f033dSHerbert Xu .suite = { 316821c8e720SArd Biesheuvel .hash = __VECS(hmac_sha384_tv_template) 3169da7f033dSHerbert Xu } 3170da7f033dSHerbert Xu }, { 3171da7f033dSHerbert Xu .alg = "hmac(sha512)", 3172da7f033dSHerbert Xu .test = alg_test_hash, 3173a1915d51SJarod Wilson .fips_allowed = 1, 3174da7f033dSHerbert Xu .suite = { 317521c8e720SArd Biesheuvel .hash = __VECS(hmac_sha512_tv_template) 3176da7f033dSHerbert Xu } 3177da7f033dSHerbert Xu }, { 3178bb5530e4SStephan Mueller .alg = "jitterentropy_rng", 3179bb5530e4SStephan Mueller .fips_allowed = 1, 3180bb5530e4SStephan Mueller .test = alg_test_null, 3181bb5530e4SStephan Mueller }, { 318235351988SStephan Mueller .alg = "kw(aes)", 318335351988SStephan Mueller .test = alg_test_skcipher, 318435351988SStephan Mueller .fips_allowed = 1, 318535351988SStephan Mueller .suite = { 318635351988SStephan Mueller .cipher = { 318721c8e720SArd Biesheuvel .enc = __VECS(aes_kw_enc_tv_template), 318821c8e720SArd Biesheuvel .dec = __VECS(aes_kw_dec_tv_template) 318935351988SStephan Mueller } 319035351988SStephan Mueller } 319135351988SStephan Mueller }, { 3192da7f033dSHerbert Xu .alg = "lrw(aes)", 31931aa4ecd9SHerbert Xu .test = alg_test_skcipher, 3194da7f033dSHerbert Xu .suite = { 3195da7f033dSHerbert Xu .cipher = { 319621c8e720SArd Biesheuvel .enc = __VECS(aes_lrw_enc_tv_template), 319721c8e720SArd Biesheuvel .dec = __VECS(aes_lrw_dec_tv_template) 3198da7f033dSHerbert Xu } 3199da7f033dSHerbert Xu } 3200da7f033dSHerbert Xu }, { 32010840605eSJussi Kivilinna .alg = "lrw(camellia)", 32020840605eSJussi Kivilinna .test = alg_test_skcipher, 32030840605eSJussi Kivilinna .suite = { 32040840605eSJussi Kivilinna .cipher = { 320521c8e720SArd Biesheuvel .enc = __VECS(camellia_lrw_enc_tv_template), 320621c8e720SArd Biesheuvel .dec = __VECS(camellia_lrw_dec_tv_template) 32070840605eSJussi Kivilinna } 32080840605eSJussi Kivilinna } 32090840605eSJussi Kivilinna }, { 32109b8b0405SJohannes Goetzfried .alg = "lrw(cast6)", 32119b8b0405SJohannes Goetzfried .test = alg_test_skcipher, 32129b8b0405SJohannes Goetzfried .suite = { 32139b8b0405SJohannes Goetzfried .cipher = { 321421c8e720SArd Biesheuvel .enc = __VECS(cast6_lrw_enc_tv_template), 321521c8e720SArd Biesheuvel .dec = __VECS(cast6_lrw_dec_tv_template) 32169b8b0405SJohannes Goetzfried } 32179b8b0405SJohannes Goetzfried } 32189b8b0405SJohannes Goetzfried }, { 3219d7bfc0faSJussi Kivilinna .alg = "lrw(serpent)", 3220d7bfc0faSJussi Kivilinna .test = alg_test_skcipher, 3221d7bfc0faSJussi Kivilinna .suite = { 3222d7bfc0faSJussi Kivilinna .cipher = { 322321c8e720SArd Biesheuvel .enc = __VECS(serpent_lrw_enc_tv_template), 322421c8e720SArd Biesheuvel .dec = __VECS(serpent_lrw_dec_tv_template) 3225d7bfc0faSJussi Kivilinna } 3226d7bfc0faSJussi Kivilinna } 3227d7bfc0faSJussi Kivilinna }, { 32280b2a1551SJussi Kivilinna .alg = "lrw(twofish)", 32290b2a1551SJussi Kivilinna .test = alg_test_skcipher, 32300b2a1551SJussi Kivilinna .suite = { 32310b2a1551SJussi Kivilinna .cipher = { 323221c8e720SArd Biesheuvel .enc = __VECS(tf_lrw_enc_tv_template), 323321c8e720SArd Biesheuvel .dec = __VECS(tf_lrw_dec_tv_template) 32340b2a1551SJussi Kivilinna } 32350b2a1551SJussi Kivilinna } 32360b2a1551SJussi Kivilinna }, { 32371443cc9bSKOVACS Krisztian .alg = "lz4", 32381443cc9bSKOVACS Krisztian .test = alg_test_comp, 32391443cc9bSKOVACS Krisztian .fips_allowed = 1, 32401443cc9bSKOVACS Krisztian .suite = { 32411443cc9bSKOVACS Krisztian .comp = { 324221c8e720SArd Biesheuvel .comp = __VECS(lz4_comp_tv_template), 324321c8e720SArd Biesheuvel .decomp = __VECS(lz4_decomp_tv_template) 32441443cc9bSKOVACS Krisztian } 32451443cc9bSKOVACS Krisztian } 32461443cc9bSKOVACS Krisztian }, { 32471443cc9bSKOVACS Krisztian .alg = "lz4hc", 32481443cc9bSKOVACS Krisztian .test = alg_test_comp, 32491443cc9bSKOVACS Krisztian .fips_allowed = 1, 32501443cc9bSKOVACS Krisztian .suite = { 32511443cc9bSKOVACS Krisztian .comp = { 325221c8e720SArd Biesheuvel .comp = __VECS(lz4hc_comp_tv_template), 325321c8e720SArd Biesheuvel .decomp = __VECS(lz4hc_decomp_tv_template) 32541443cc9bSKOVACS Krisztian } 32551443cc9bSKOVACS Krisztian } 32561443cc9bSKOVACS Krisztian }, { 3257da7f033dSHerbert Xu .alg = "lzo", 3258da7f033dSHerbert Xu .test = alg_test_comp, 32590818904dSMilan Broz .fips_allowed = 1, 3260da7f033dSHerbert Xu .suite = { 3261da7f033dSHerbert Xu .comp = { 326221c8e720SArd Biesheuvel .comp = __VECS(lzo_comp_tv_template), 326321c8e720SArd Biesheuvel .decomp = __VECS(lzo_decomp_tv_template) 3264da7f033dSHerbert Xu } 3265da7f033dSHerbert Xu } 3266da7f033dSHerbert Xu }, { 3267da7f033dSHerbert Xu .alg = "md4", 3268da7f033dSHerbert Xu .test = alg_test_hash, 3269da7f033dSHerbert Xu .suite = { 327021c8e720SArd Biesheuvel .hash = __VECS(md4_tv_template) 3271da7f033dSHerbert Xu } 3272da7f033dSHerbert Xu }, { 3273da7f033dSHerbert Xu .alg = "md5", 3274da7f033dSHerbert Xu .test = alg_test_hash, 3275da7f033dSHerbert Xu .suite = { 327621c8e720SArd Biesheuvel .hash = __VECS(md5_tv_template) 3277da7f033dSHerbert Xu } 3278da7f033dSHerbert Xu }, { 3279da7f033dSHerbert Xu .alg = "michael_mic", 3280da7f033dSHerbert Xu .test = alg_test_hash, 3281da7f033dSHerbert Xu .suite = { 328221c8e720SArd Biesheuvel .hash = __VECS(michael_mic_tv_template) 3283da7f033dSHerbert Xu } 3284da7f033dSHerbert Xu }, { 3285ba0e14acSPuneet Saxena .alg = "ofb(aes)", 3286ba0e14acSPuneet Saxena .test = alg_test_skcipher, 3287ba0e14acSPuneet Saxena .fips_allowed = 1, 3288ba0e14acSPuneet Saxena .suite = { 3289ba0e14acSPuneet Saxena .cipher = { 329021c8e720SArd Biesheuvel .enc = __VECS(aes_ofb_enc_tv_template), 329121c8e720SArd Biesheuvel .dec = __VECS(aes_ofb_dec_tv_template) 3292ba0e14acSPuneet Saxena } 3293ba0e14acSPuneet Saxena } 3294ba0e14acSPuneet Saxena }, { 3295da7f033dSHerbert Xu .alg = "pcbc(fcrypt)", 32961aa4ecd9SHerbert Xu .test = alg_test_skcipher, 3297da7f033dSHerbert Xu .suite = { 3298da7f033dSHerbert Xu .cipher = { 329921c8e720SArd Biesheuvel .enc = __VECS(fcrypt_pcbc_enc_tv_template), 330021c8e720SArd Biesheuvel .dec = __VECS(fcrypt_pcbc_dec_tv_template) 3301da7f033dSHerbert Xu } 3302da7f033dSHerbert Xu } 3303da7f033dSHerbert Xu }, { 33041207107cSStephan Mueller .alg = "pkcs1pad(rsa,sha224)", 33051207107cSStephan Mueller .test = alg_test_null, 33061207107cSStephan Mueller .fips_allowed = 1, 33071207107cSStephan Mueller }, { 33081207107cSStephan Mueller .alg = "pkcs1pad(rsa,sha256)", 33091207107cSStephan Mueller .test = alg_test_akcipher, 33101207107cSStephan Mueller .fips_allowed = 1, 33111207107cSStephan Mueller .suite = { 33121207107cSStephan Mueller .akcipher = __VECS(pkcs1pad_rsa_tv_template) 33131207107cSStephan Mueller } 33141207107cSStephan Mueller }, { 33151207107cSStephan Mueller .alg = "pkcs1pad(rsa,sha384)", 33161207107cSStephan Mueller .test = alg_test_null, 33171207107cSStephan Mueller .fips_allowed = 1, 33181207107cSStephan Mueller }, { 33191207107cSStephan Mueller .alg = "pkcs1pad(rsa,sha512)", 33201207107cSStephan Mueller .test = alg_test_null, 33211207107cSStephan Mueller .fips_allowed = 1, 33221207107cSStephan Mueller }, { 3323eee9dc61SMartin Willi .alg = "poly1305", 3324eee9dc61SMartin Willi .test = alg_test_hash, 3325eee9dc61SMartin Willi .suite = { 332621c8e720SArd Biesheuvel .hash = __VECS(poly1305_tv_template) 3327eee9dc61SMartin Willi } 3328eee9dc61SMartin Willi }, { 3329da7f033dSHerbert Xu .alg = "rfc3686(ctr(aes))", 33301aa4ecd9SHerbert Xu .test = alg_test_skcipher, 3331a1915d51SJarod Wilson .fips_allowed = 1, 3332da7f033dSHerbert Xu .suite = { 3333da7f033dSHerbert Xu .cipher = { 333421c8e720SArd Biesheuvel .enc = __VECS(aes_ctr_rfc3686_enc_tv_template), 333521c8e720SArd Biesheuvel .dec = __VECS(aes_ctr_rfc3686_dec_tv_template) 3336da7f033dSHerbert Xu } 3337da7f033dSHerbert Xu } 3338da7f033dSHerbert Xu }, { 33393f31a740SHerbert Xu .alg = "rfc4106(gcm(aes))", 334069435b94SAdrian Hoban .test = alg_test_aead, 3341db71f29aSJarod Wilson .fips_allowed = 1, 334269435b94SAdrian Hoban .suite = { 334369435b94SAdrian Hoban .aead = { 334421c8e720SArd Biesheuvel .enc = __VECS(aes_gcm_rfc4106_enc_tv_template), 334521c8e720SArd Biesheuvel .dec = __VECS(aes_gcm_rfc4106_dec_tv_template) 334669435b94SAdrian Hoban } 334769435b94SAdrian Hoban } 334869435b94SAdrian Hoban }, { 3349544c436aSHerbert Xu .alg = "rfc4309(ccm(aes))", 33505d667322SJarod Wilson .test = alg_test_aead, 3351a1915d51SJarod Wilson .fips_allowed = 1, 33525d667322SJarod Wilson .suite = { 33535d667322SJarod Wilson .aead = { 335421c8e720SArd Biesheuvel .enc = __VECS(aes_ccm_rfc4309_enc_tv_template), 335521c8e720SArd Biesheuvel .dec = __VECS(aes_ccm_rfc4309_dec_tv_template) 33565d667322SJarod Wilson } 33575d667322SJarod Wilson } 33585d667322SJarod Wilson }, { 3359bb68745eSHerbert Xu .alg = "rfc4543(gcm(aes))", 3360e9b7441aSJussi Kivilinna .test = alg_test_aead, 3361e9b7441aSJussi Kivilinna .suite = { 3362e9b7441aSJussi Kivilinna .aead = { 336321c8e720SArd Biesheuvel .enc = __VECS(aes_gcm_rfc4543_enc_tv_template), 336421c8e720SArd Biesheuvel .dec = __VECS(aes_gcm_rfc4543_dec_tv_template), 3365e9b7441aSJussi Kivilinna } 3366e9b7441aSJussi Kivilinna } 3367e9b7441aSJussi Kivilinna }, { 3368af2b76b5SMartin Willi .alg = "rfc7539(chacha20,poly1305)", 3369af2b76b5SMartin Willi .test = alg_test_aead, 3370af2b76b5SMartin Willi .suite = { 3371af2b76b5SMartin Willi .aead = { 337221c8e720SArd Biesheuvel .enc = __VECS(rfc7539_enc_tv_template), 337321c8e720SArd Biesheuvel .dec = __VECS(rfc7539_dec_tv_template), 3374af2b76b5SMartin Willi } 3375af2b76b5SMartin Willi } 3376af2b76b5SMartin Willi }, { 33775900758dSMartin Willi .alg = "rfc7539esp(chacha20,poly1305)", 33785900758dSMartin Willi .test = alg_test_aead, 33795900758dSMartin Willi .suite = { 33805900758dSMartin Willi .aead = { 338121c8e720SArd Biesheuvel .enc = __VECS(rfc7539esp_enc_tv_template), 338221c8e720SArd Biesheuvel .dec = __VECS(rfc7539esp_dec_tv_template), 33835900758dSMartin Willi } 33845900758dSMartin Willi } 33855900758dSMartin Willi }, { 3386da7f033dSHerbert Xu .alg = "rmd128", 3387da7f033dSHerbert Xu .test = alg_test_hash, 3388da7f033dSHerbert Xu .suite = { 338921c8e720SArd Biesheuvel .hash = __VECS(rmd128_tv_template) 3390da7f033dSHerbert Xu } 3391da7f033dSHerbert Xu }, { 3392da7f033dSHerbert Xu .alg = "rmd160", 3393da7f033dSHerbert Xu .test = alg_test_hash, 3394da7f033dSHerbert Xu .suite = { 339521c8e720SArd Biesheuvel .hash = __VECS(rmd160_tv_template) 3396da7f033dSHerbert Xu } 3397da7f033dSHerbert Xu }, { 3398da7f033dSHerbert Xu .alg = "rmd256", 3399da7f033dSHerbert Xu .test = alg_test_hash, 3400da7f033dSHerbert Xu .suite = { 340121c8e720SArd Biesheuvel .hash = __VECS(rmd256_tv_template) 3402da7f033dSHerbert Xu } 3403da7f033dSHerbert Xu }, { 3404da7f033dSHerbert Xu .alg = "rmd320", 3405da7f033dSHerbert Xu .test = alg_test_hash, 3406da7f033dSHerbert Xu .suite = { 340721c8e720SArd Biesheuvel .hash = __VECS(rmd320_tv_template) 3408da7f033dSHerbert Xu } 3409da7f033dSHerbert Xu }, { 3410946cc463STadeusz Struk .alg = "rsa", 3411946cc463STadeusz Struk .test = alg_test_akcipher, 3412946cc463STadeusz Struk .fips_allowed = 1, 3413946cc463STadeusz Struk .suite = { 341421c8e720SArd Biesheuvel .akcipher = __VECS(rsa_tv_template) 3415946cc463STadeusz Struk } 3416946cc463STadeusz Struk }, { 3417da7f033dSHerbert Xu .alg = "salsa20", 34181aa4ecd9SHerbert Xu .test = alg_test_skcipher, 3419da7f033dSHerbert Xu .suite = { 3420da7f033dSHerbert Xu .cipher = { 342121c8e720SArd Biesheuvel .enc = __VECS(salsa20_stream_enc_tv_template) 3422da7f033dSHerbert Xu } 3423da7f033dSHerbert Xu } 3424da7f033dSHerbert Xu }, { 3425da7f033dSHerbert Xu .alg = "sha1", 3426da7f033dSHerbert Xu .test = alg_test_hash, 3427a1915d51SJarod Wilson .fips_allowed = 1, 3428da7f033dSHerbert Xu .suite = { 342921c8e720SArd Biesheuvel .hash = __VECS(sha1_tv_template) 3430da7f033dSHerbert Xu } 3431da7f033dSHerbert Xu }, { 3432da7f033dSHerbert Xu .alg = "sha224", 3433da7f033dSHerbert Xu .test = alg_test_hash, 3434a1915d51SJarod Wilson .fips_allowed = 1, 3435da7f033dSHerbert Xu .suite = { 343621c8e720SArd Biesheuvel .hash = __VECS(sha224_tv_template) 3437da7f033dSHerbert Xu } 3438da7f033dSHerbert Xu }, { 3439da7f033dSHerbert Xu .alg = "sha256", 3440da7f033dSHerbert Xu .test = alg_test_hash, 3441a1915d51SJarod Wilson .fips_allowed = 1, 3442da7f033dSHerbert Xu .suite = { 344321c8e720SArd Biesheuvel .hash = __VECS(sha256_tv_template) 3444da7f033dSHerbert Xu } 3445da7f033dSHerbert Xu }, { 344679cc6ab8Sraveendra padasalagi .alg = "sha3-224", 344779cc6ab8Sraveendra padasalagi .test = alg_test_hash, 344879cc6ab8Sraveendra padasalagi .fips_allowed = 1, 344979cc6ab8Sraveendra padasalagi .suite = { 345021c8e720SArd Biesheuvel .hash = __VECS(sha3_224_tv_template) 345179cc6ab8Sraveendra padasalagi } 345279cc6ab8Sraveendra padasalagi }, { 345379cc6ab8Sraveendra padasalagi .alg = "sha3-256", 345479cc6ab8Sraveendra padasalagi .test = alg_test_hash, 345579cc6ab8Sraveendra padasalagi .fips_allowed = 1, 345679cc6ab8Sraveendra padasalagi .suite = { 345721c8e720SArd Biesheuvel .hash = __VECS(sha3_256_tv_template) 345879cc6ab8Sraveendra padasalagi } 345979cc6ab8Sraveendra padasalagi }, { 346079cc6ab8Sraveendra padasalagi .alg = "sha3-384", 346179cc6ab8Sraveendra padasalagi .test = alg_test_hash, 346279cc6ab8Sraveendra padasalagi .fips_allowed = 1, 346379cc6ab8Sraveendra padasalagi .suite = { 346421c8e720SArd Biesheuvel .hash = __VECS(sha3_384_tv_template) 346579cc6ab8Sraveendra padasalagi } 346679cc6ab8Sraveendra padasalagi }, { 346779cc6ab8Sraveendra padasalagi .alg = "sha3-512", 346879cc6ab8Sraveendra padasalagi .test = alg_test_hash, 346979cc6ab8Sraveendra padasalagi .fips_allowed = 1, 347079cc6ab8Sraveendra padasalagi .suite = { 347121c8e720SArd Biesheuvel .hash = __VECS(sha3_512_tv_template) 347279cc6ab8Sraveendra padasalagi } 347379cc6ab8Sraveendra padasalagi }, { 3474da7f033dSHerbert Xu .alg = "sha384", 3475da7f033dSHerbert Xu .test = alg_test_hash, 3476a1915d51SJarod Wilson .fips_allowed = 1, 3477da7f033dSHerbert Xu .suite = { 347821c8e720SArd Biesheuvel .hash = __VECS(sha384_tv_template) 3479da7f033dSHerbert Xu } 3480da7f033dSHerbert Xu }, { 3481da7f033dSHerbert Xu .alg = "sha512", 3482da7f033dSHerbert Xu .test = alg_test_hash, 3483a1915d51SJarod Wilson .fips_allowed = 1, 3484da7f033dSHerbert Xu .suite = { 348521c8e720SArd Biesheuvel .hash = __VECS(sha512_tv_template) 3486da7f033dSHerbert Xu } 3487da7f033dSHerbert Xu }, { 3488b7e27530SGilad Ben-Yossef .alg = "sm3", 3489b7e27530SGilad Ben-Yossef .test = alg_test_hash, 3490b7e27530SGilad Ben-Yossef .suite = { 3491b7e27530SGilad Ben-Yossef .hash = __VECS(sm3_tv_template) 3492b7e27530SGilad Ben-Yossef } 3493b7e27530SGilad Ben-Yossef }, { 3494da7f033dSHerbert Xu .alg = "tgr128", 3495da7f033dSHerbert Xu .test = alg_test_hash, 3496da7f033dSHerbert Xu .suite = { 349721c8e720SArd Biesheuvel .hash = __VECS(tgr128_tv_template) 3498da7f033dSHerbert Xu } 3499da7f033dSHerbert Xu }, { 3500da7f033dSHerbert Xu .alg = "tgr160", 3501da7f033dSHerbert Xu .test = alg_test_hash, 3502da7f033dSHerbert Xu .suite = { 350321c8e720SArd Biesheuvel .hash = __VECS(tgr160_tv_template) 3504da7f033dSHerbert Xu } 3505da7f033dSHerbert Xu }, { 3506da7f033dSHerbert Xu .alg = "tgr192", 3507da7f033dSHerbert Xu .test = alg_test_hash, 3508da7f033dSHerbert Xu .suite = { 350921c8e720SArd Biesheuvel .hash = __VECS(tgr192_tv_template) 3510da7f033dSHerbert Xu } 3511da7f033dSHerbert Xu }, { 3512f1939f7cSShane Wang .alg = "vmac(aes)", 3513f1939f7cSShane Wang .test = alg_test_hash, 3514f1939f7cSShane Wang .suite = { 351521c8e720SArd Biesheuvel .hash = __VECS(aes_vmac128_tv_template) 3516f1939f7cSShane Wang } 3517f1939f7cSShane Wang }, { 3518da7f033dSHerbert Xu .alg = "wp256", 3519da7f033dSHerbert Xu .test = alg_test_hash, 3520da7f033dSHerbert Xu .suite = { 352121c8e720SArd Biesheuvel .hash = __VECS(wp256_tv_template) 3522da7f033dSHerbert Xu } 3523da7f033dSHerbert Xu }, { 3524da7f033dSHerbert Xu .alg = "wp384", 3525da7f033dSHerbert Xu .test = alg_test_hash, 3526da7f033dSHerbert Xu .suite = { 352721c8e720SArd Biesheuvel .hash = __VECS(wp384_tv_template) 3528da7f033dSHerbert Xu } 3529da7f033dSHerbert Xu }, { 3530da7f033dSHerbert Xu .alg = "wp512", 3531da7f033dSHerbert Xu .test = alg_test_hash, 3532da7f033dSHerbert Xu .suite = { 353321c8e720SArd Biesheuvel .hash = __VECS(wp512_tv_template) 3534da7f033dSHerbert Xu } 3535da7f033dSHerbert Xu }, { 3536da7f033dSHerbert Xu .alg = "xcbc(aes)", 3537da7f033dSHerbert Xu .test = alg_test_hash, 3538da7f033dSHerbert Xu .suite = { 353921c8e720SArd Biesheuvel .hash = __VECS(aes_xcbc128_tv_template) 3540da7f033dSHerbert Xu } 3541da7f033dSHerbert Xu }, { 3542da7f033dSHerbert Xu .alg = "xts(aes)", 35431aa4ecd9SHerbert Xu .test = alg_test_skcipher, 35442918aa8dSJarod Wilson .fips_allowed = 1, 3545da7f033dSHerbert Xu .suite = { 3546da7f033dSHerbert Xu .cipher = { 354721c8e720SArd Biesheuvel .enc = __VECS(aes_xts_enc_tv_template), 354821c8e720SArd Biesheuvel .dec = __VECS(aes_xts_dec_tv_template) 3549da7f033dSHerbert Xu } 3550da7f033dSHerbert Xu } 35510c01aed5SGeert Uytterhoeven }, { 35520840605eSJussi Kivilinna .alg = "xts(camellia)", 35530840605eSJussi Kivilinna .test = alg_test_skcipher, 35540840605eSJussi Kivilinna .suite = { 35550840605eSJussi Kivilinna .cipher = { 355621c8e720SArd Biesheuvel .enc = __VECS(camellia_xts_enc_tv_template), 355721c8e720SArd Biesheuvel .dec = __VECS(camellia_xts_dec_tv_template) 35580840605eSJussi Kivilinna } 35590840605eSJussi Kivilinna } 35600840605eSJussi Kivilinna }, { 35619b8b0405SJohannes Goetzfried .alg = "xts(cast6)", 35629b8b0405SJohannes Goetzfried .test = alg_test_skcipher, 35639b8b0405SJohannes Goetzfried .suite = { 35649b8b0405SJohannes Goetzfried .cipher = { 356521c8e720SArd Biesheuvel .enc = __VECS(cast6_xts_enc_tv_template), 356621c8e720SArd Biesheuvel .dec = __VECS(cast6_xts_dec_tv_template) 35679b8b0405SJohannes Goetzfried } 35689b8b0405SJohannes Goetzfried } 35699b8b0405SJohannes Goetzfried }, { 357018be20b9SJussi Kivilinna .alg = "xts(serpent)", 357118be20b9SJussi Kivilinna .test = alg_test_skcipher, 357218be20b9SJussi Kivilinna .suite = { 357318be20b9SJussi Kivilinna .cipher = { 357421c8e720SArd Biesheuvel .enc = __VECS(serpent_xts_enc_tv_template), 357521c8e720SArd Biesheuvel .dec = __VECS(serpent_xts_dec_tv_template) 357618be20b9SJussi Kivilinna } 357718be20b9SJussi Kivilinna } 357818be20b9SJussi Kivilinna }, { 3579c3bb521bSEric Biggers .alg = "xts(speck128)", 3580c3bb521bSEric Biggers .test = alg_test_skcipher, 3581c3bb521bSEric Biggers .suite = { 3582c3bb521bSEric Biggers .cipher = { 3583c3bb521bSEric Biggers .enc = __VECS(speck128_xts_enc_tv_template), 3584c3bb521bSEric Biggers .dec = __VECS(speck128_xts_dec_tv_template) 3585c3bb521bSEric Biggers } 3586c3bb521bSEric Biggers } 3587c3bb521bSEric Biggers }, { 3588aed265b9SJussi Kivilinna .alg = "xts(twofish)", 3589aed265b9SJussi Kivilinna .test = alg_test_skcipher, 3590aed265b9SJussi Kivilinna .suite = { 3591aed265b9SJussi Kivilinna .cipher = { 359221c8e720SArd Biesheuvel .enc = __VECS(tf_xts_enc_tv_template), 359321c8e720SArd Biesheuvel .dec = __VECS(tf_xts_dec_tv_template) 3594aed265b9SJussi Kivilinna } 3595aed265b9SJussi Kivilinna } 3596a368f43dSGiovanni Cabiddu }, { 3597a368f43dSGiovanni Cabiddu .alg = "zlib-deflate", 3598a368f43dSGiovanni Cabiddu .test = alg_test_comp, 3599a368f43dSGiovanni Cabiddu .fips_allowed = 1, 3600a368f43dSGiovanni Cabiddu .suite = { 3601a368f43dSGiovanni Cabiddu .comp = { 3602a368f43dSGiovanni Cabiddu .comp = __VECS(zlib_deflate_comp_tv_template), 3603a368f43dSGiovanni Cabiddu .decomp = __VECS(zlib_deflate_decomp_tv_template) 3604a368f43dSGiovanni Cabiddu } 3605a368f43dSGiovanni Cabiddu } 3606da7f033dSHerbert Xu } 3607da7f033dSHerbert Xu }; 3608da7f033dSHerbert Xu 36095714758bSJussi Kivilinna static bool alg_test_descs_checked; 36105714758bSJussi Kivilinna 36115714758bSJussi Kivilinna static void alg_test_descs_check_order(void) 36125714758bSJussi Kivilinna { 36135714758bSJussi Kivilinna int i; 36145714758bSJussi Kivilinna 36155714758bSJussi Kivilinna /* only check once */ 36165714758bSJussi Kivilinna if (alg_test_descs_checked) 36175714758bSJussi Kivilinna return; 36185714758bSJussi Kivilinna 36195714758bSJussi Kivilinna alg_test_descs_checked = true; 36205714758bSJussi Kivilinna 36215714758bSJussi Kivilinna for (i = 1; i < ARRAY_SIZE(alg_test_descs); i++) { 36225714758bSJussi Kivilinna int diff = strcmp(alg_test_descs[i - 1].alg, 36235714758bSJussi Kivilinna alg_test_descs[i].alg); 36245714758bSJussi Kivilinna 36255714758bSJussi Kivilinna if (WARN_ON(diff > 0)) { 36265714758bSJussi Kivilinna pr_warn("testmgr: alg_test_descs entries in wrong order: '%s' before '%s'\n", 36275714758bSJussi Kivilinna alg_test_descs[i - 1].alg, 36285714758bSJussi Kivilinna alg_test_descs[i].alg); 36295714758bSJussi Kivilinna } 36305714758bSJussi Kivilinna 36315714758bSJussi Kivilinna if (WARN_ON(diff == 0)) { 36325714758bSJussi Kivilinna pr_warn("testmgr: duplicate alg_test_descs entry: '%s'\n", 36335714758bSJussi Kivilinna alg_test_descs[i].alg); 36345714758bSJussi Kivilinna } 36355714758bSJussi Kivilinna } 36365714758bSJussi Kivilinna } 36375714758bSJussi Kivilinna 36381aa4ecd9SHerbert Xu static int alg_find_test(const char *alg) 3639da7f033dSHerbert Xu { 3640da7f033dSHerbert Xu int start = 0; 3641da7f033dSHerbert Xu int end = ARRAY_SIZE(alg_test_descs); 3642da7f033dSHerbert Xu 3643da7f033dSHerbert Xu while (start < end) { 3644da7f033dSHerbert Xu int i = (start + end) / 2; 3645da7f033dSHerbert Xu int diff = strcmp(alg_test_descs[i].alg, alg); 3646da7f033dSHerbert Xu 3647da7f033dSHerbert Xu if (diff > 0) { 3648da7f033dSHerbert Xu end = i; 3649da7f033dSHerbert Xu continue; 3650da7f033dSHerbert Xu } 3651da7f033dSHerbert Xu 3652da7f033dSHerbert Xu if (diff < 0) { 3653da7f033dSHerbert Xu start = i + 1; 3654da7f033dSHerbert Xu continue; 3655da7f033dSHerbert Xu } 3656da7f033dSHerbert Xu 36571aa4ecd9SHerbert Xu return i; 3658da7f033dSHerbert Xu } 3659da7f033dSHerbert Xu 36601aa4ecd9SHerbert Xu return -1; 36611aa4ecd9SHerbert Xu } 36621aa4ecd9SHerbert Xu 36631aa4ecd9SHerbert Xu int alg_test(const char *driver, const char *alg, u32 type, u32 mask) 36641aa4ecd9SHerbert Xu { 36651aa4ecd9SHerbert Xu int i; 3666a68f6610SHerbert Xu int j; 3667d12d6b6dSNeil Horman int rc; 36681aa4ecd9SHerbert Xu 36699e5c9fe4SRichard W.M. Jones if (!fips_enabled && notests) { 36709e5c9fe4SRichard W.M. Jones printk_once(KERN_INFO "alg: self-tests disabled\n"); 36719e5c9fe4SRichard W.M. Jones return 0; 36729e5c9fe4SRichard W.M. Jones } 36739e5c9fe4SRichard W.M. Jones 36745714758bSJussi Kivilinna alg_test_descs_check_order(); 36755714758bSJussi Kivilinna 36761aa4ecd9SHerbert Xu if ((type & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_CIPHER) { 36771aa4ecd9SHerbert Xu char nalg[CRYPTO_MAX_ALG_NAME]; 36781aa4ecd9SHerbert Xu 36791aa4ecd9SHerbert Xu if (snprintf(nalg, sizeof(nalg), "ecb(%s)", alg) >= 36801aa4ecd9SHerbert Xu sizeof(nalg)) 36811aa4ecd9SHerbert Xu return -ENAMETOOLONG; 36821aa4ecd9SHerbert Xu 36831aa4ecd9SHerbert Xu i = alg_find_test(nalg); 36841aa4ecd9SHerbert Xu if (i < 0) 36851aa4ecd9SHerbert Xu goto notest; 36861aa4ecd9SHerbert Xu 3687a3bef3a3SJarod Wilson if (fips_enabled && !alg_test_descs[i].fips_allowed) 3688a3bef3a3SJarod Wilson goto non_fips_alg; 3689a3bef3a3SJarod Wilson 3690941fb328SJarod Wilson rc = alg_test_cipher(alg_test_descs + i, driver, type, mask); 3691941fb328SJarod Wilson goto test_done; 36921aa4ecd9SHerbert Xu } 36931aa4ecd9SHerbert Xu 36941aa4ecd9SHerbert Xu i = alg_find_test(alg); 3695a68f6610SHerbert Xu j = alg_find_test(driver); 3696a68f6610SHerbert Xu if (i < 0 && j < 0) 36971aa4ecd9SHerbert Xu goto notest; 36981aa4ecd9SHerbert Xu 3699a68f6610SHerbert Xu if (fips_enabled && ((i >= 0 && !alg_test_descs[i].fips_allowed) || 3700a68f6610SHerbert Xu (j >= 0 && !alg_test_descs[j].fips_allowed))) 3701a3bef3a3SJarod Wilson goto non_fips_alg; 3702a3bef3a3SJarod Wilson 3703a68f6610SHerbert Xu rc = 0; 3704a68f6610SHerbert Xu if (i >= 0) 3705a68f6610SHerbert Xu rc |= alg_test_descs[i].test(alg_test_descs + i, driver, 37061aa4ecd9SHerbert Xu type, mask); 3707032c8cacSCristian Stoica if (j >= 0 && j != i) 3708a68f6610SHerbert Xu rc |= alg_test_descs[j].test(alg_test_descs + j, driver, 3709a68f6610SHerbert Xu type, mask); 3710a68f6610SHerbert Xu 3711941fb328SJarod Wilson test_done: 3712d12d6b6dSNeil Horman if (fips_enabled && rc) 3713d12d6b6dSNeil Horman panic("%s: %s alg self test failed in fips mode!\n", driver, alg); 3714d12d6b6dSNeil Horman 371529ecd4abSJarod Wilson if (fips_enabled && !rc) 37163e8cffd4SMasanari Iida pr_info("alg: self-tests for %s (%s) passed\n", driver, alg); 371729ecd4abSJarod Wilson 3718d12d6b6dSNeil Horman return rc; 37191aa4ecd9SHerbert Xu 37201aa4ecd9SHerbert Xu notest: 3721da7f033dSHerbert Xu printk(KERN_INFO "alg: No test for %s (%s)\n", alg, driver); 3722da7f033dSHerbert Xu return 0; 3723a3bef3a3SJarod Wilson non_fips_alg: 3724a3bef3a3SJarod Wilson return -EINVAL; 3725da7f033dSHerbert Xu } 37260b767f96SAlexander Shishkin 3727326a6346SHerbert Xu #endif /* CONFIG_CRYPTO_MANAGER_DISABLE_TESTS */ 37280b767f96SAlexander Shishkin 3729da7f033dSHerbert Xu EXPORT_SYMBOL_GPL(alg_test); 3730