^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Algorithm testing framework and tests.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (c) 2002 Jean-Francois Dive <jef@linuxbe.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Copyright (c) 2007 Nokia Siemens Networks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Copyright (c) 2008 Herbert Xu <herbert@gondor.apana.org.au>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Copyright (c) 2019 Google LLC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * Updated RFC4106 AES-GCM testing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * Authors: Aidan O'Mahony (aidan.o.mahony@intel.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * Adrian Hoban <adrian.hoban@intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * Gabriele Paoloni <gabriele.paoloni@intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * Tadeusz Struk (tadeusz.struk@intel.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * Copyright (c) 2010, Intel Corporation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <crypto/aead.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <crypto/hash.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <crypto/skcipher.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/fips.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/once.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/random.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/scatterlist.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <linux/uio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include <crypto/rng.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include <crypto/drbg.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include <crypto/akcipher.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #include <crypto/kpp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #include <crypto/acompress.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #include <crypto/internal/cipher.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #include <crypto/internal/simd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #include "internal.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) MODULE_IMPORT_NS(CRYPTO_INTERNAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) static bool notests;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) module_param(notests, bool, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) MODULE_PARM_DESC(notests, "disable crypto self-tests");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) static bool panic_on_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) module_param(panic_on_fail, bool, 0444);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) static bool noextratests;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) module_param(noextratests, bool, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) MODULE_PARM_DESC(noextratests, "disable expensive crypto self-tests");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) static unsigned int fuzz_iterations = 100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) module_param(fuzz_iterations, uint, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) MODULE_PARM_DESC(fuzz_iterations, "number of fuzz test iterations");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) DEFINE_PER_CPU(bool, crypto_simd_disabled_for_test);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) EXPORT_PER_CPU_SYMBOL_GPL(crypto_simd_disabled_for_test);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) #ifdef CONFIG_CRYPTO_MANAGER_DISABLE_TESTS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) /* a perfect nop */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) #include "testmgr.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) * Need slab memory for testing (size in number of pages).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) #define XBUFSIZE 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) * Used by test_cipher()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) #define ENCRYPT 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) #define DECRYPT 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) struct aead_test_suite {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) const struct aead_testvec *vecs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) unsigned int count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) * Set if trying to decrypt an inauthentic ciphertext with this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) * algorithm might result in EINVAL rather than EBADMSG, due to other
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) * validation the algorithm does on the inputs such as length checks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) unsigned int einval_allowed : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) * Set if this algorithm requires that the IV be located at the end of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) * the AAD buffer, in addition to being given in the normal way. The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) * behavior when the two IV copies differ is implementation-defined.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) unsigned int aad_iv : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) struct cipher_test_suite {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) const struct cipher_testvec *vecs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) unsigned int count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) struct comp_test_suite {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) const struct comp_testvec *vecs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) unsigned int count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) } comp, decomp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) struct hash_test_suite {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) const struct hash_testvec *vecs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) unsigned int count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) struct cprng_test_suite {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) const struct cprng_testvec *vecs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) unsigned int count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) struct drbg_test_suite {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) const struct drbg_testvec *vecs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) unsigned int count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) struct akcipher_test_suite {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) const struct akcipher_testvec *vecs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) unsigned int count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) struct kpp_test_suite {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) const struct kpp_testvec *vecs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) unsigned int count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) struct alg_test_desc {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) const char *alg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) const char *generic_driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) int (*test)(const struct alg_test_desc *desc, const char *driver,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) u32 type, u32 mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) int fips_allowed; /* set if alg is allowed in fips mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) struct aead_test_suite aead;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) struct cipher_test_suite cipher;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) struct comp_test_suite comp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) struct hash_test_suite hash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) struct cprng_test_suite cprng;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) struct drbg_test_suite drbg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) struct akcipher_test_suite akcipher;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) struct kpp_test_suite kpp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) } suite;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) static void hexdump(unsigned char *buf, unsigned int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) print_hex_dump(KERN_CONT, "", DUMP_PREFIX_OFFSET,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 16, 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) buf, len, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) static int __testmgr_alloc_buf(char *buf[XBUFSIZE], int order)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) for (i = 0; i < XBUFSIZE; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) buf[i] = (char *)__get_free_pages(GFP_KERNEL, order);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) if (!buf[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) goto err_free_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) err_free_buf:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) while (i-- > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) free_pages((unsigned long)buf[i], order);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) static int testmgr_alloc_buf(char *buf[XBUFSIZE])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) return __testmgr_alloc_buf(buf, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) static void __testmgr_free_buf(char *buf[XBUFSIZE], int order)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) for (i = 0; i < XBUFSIZE; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) free_pages((unsigned long)buf[i], order);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) static void testmgr_free_buf(char *buf[XBUFSIZE])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) __testmgr_free_buf(buf, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) #define TESTMGR_POISON_BYTE 0xfe
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) #define TESTMGR_POISON_LEN 16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) static inline void testmgr_poison(void *addr, size_t len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) memset(addr, TESTMGR_POISON_BYTE, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) /* Is the memory region still fully poisoned? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) static inline bool testmgr_is_poison(const void *addr, size_t len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) return memchr_inv(addr, TESTMGR_POISON_BYTE, len) == NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) /* flush type for hash algorithms */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) enum flush_type {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) /* merge with update of previous buffer(s) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) FLUSH_TYPE_NONE = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) /* update with previous buffer(s) before doing this one */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) FLUSH_TYPE_FLUSH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) /* likewise, but also export and re-import the intermediate state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) FLUSH_TYPE_REIMPORT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) /* finalization function for hash algorithms */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) enum finalization_type {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) FINALIZATION_TYPE_FINAL, /* use final() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) FINALIZATION_TYPE_FINUP, /* use finup() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) FINALIZATION_TYPE_DIGEST, /* use digest() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) #define TEST_SG_TOTAL 10000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) * struct test_sg_division - description of a scatterlist entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) * This struct describes one entry of a scatterlist being constructed to check a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) * crypto test vector.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) * @proportion_of_total: length of this chunk relative to the total length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) * given as a proportion out of TEST_SG_TOTAL so that it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) * scales to fit any test vector
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) * @offset: byte offset into a 2-page buffer at which this chunk will start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) * @offset_relative_to_alignmask: if true, add the algorithm's alignmask to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) * @offset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) * @flush_type: for hashes, whether an update() should be done now vs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) * continuing to accumulate data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) * @nosimd: if doing the pending update(), do it with SIMD disabled?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) struct test_sg_division {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) unsigned int proportion_of_total;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) unsigned int offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) bool offset_relative_to_alignmask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) enum flush_type flush_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) bool nosimd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) * struct testvec_config - configuration for testing a crypto test vector
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) * This struct describes the data layout and other parameters with which each
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) * crypto test vector can be tested.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) * @name: name of this config, logged for debugging purposes if a test fails
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) * @inplace: operate on the data in-place, if applicable for the algorithm type?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) * @req_flags: extra request_flags, e.g. CRYPTO_TFM_REQ_MAY_SLEEP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) * @src_divs: description of how to arrange the source scatterlist
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) * @dst_divs: description of how to arrange the dst scatterlist, if applicable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) * for the algorithm type. Defaults to @src_divs if unset.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) * @iv_offset: misalignment of the IV in the range [0..MAX_ALGAPI_ALIGNMASK+1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) * where 0 is aligned to a 2*(MAX_ALGAPI_ALIGNMASK+1) byte boundary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) * @iv_offset_relative_to_alignmask: if true, add the algorithm's alignmask to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) * the @iv_offset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) * @key_offset: misalignment of the key, where 0 is default alignment
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) * @key_offset_relative_to_alignmask: if true, add the algorithm's alignmask to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) * the @key_offset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) * @finalization_type: what finalization function to use for hashes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) * @nosimd: execute with SIMD disabled? Requires !CRYPTO_TFM_REQ_MAY_SLEEP.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) struct testvec_config {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) bool inplace;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) u32 req_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) struct test_sg_division src_divs[XBUFSIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) struct test_sg_division dst_divs[XBUFSIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) unsigned int iv_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) unsigned int key_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) bool iv_offset_relative_to_alignmask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) bool key_offset_relative_to_alignmask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) enum finalization_type finalization_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) bool nosimd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) #define TESTVEC_CONFIG_NAMELEN 192
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) * The following are the lists of testvec_configs to test for each algorithm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) * type when the basic crypto self-tests are enabled, i.e. when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) * CONFIG_CRYPTO_MANAGER_DISABLE_TESTS is unset. They aim to provide good test
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) * coverage, while keeping the test time much shorter than the full fuzz tests
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) * so that the basic tests can be enabled in a wider range of circumstances.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) /* Configs for skciphers and aeads */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) static const struct testvec_config default_cipher_testvec_configs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) .name = "in-place",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) .inplace = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) .src_divs = { { .proportion_of_total = 10000 } },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) .name = "out-of-place",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) .src_divs = { { .proportion_of_total = 10000 } },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) .name = "unaligned buffer, offset=1",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) .src_divs = { { .proportion_of_total = 10000, .offset = 1 } },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) .iv_offset = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) .key_offset = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) .name = "buffer aligned only to alignmask",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) .src_divs = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) .proportion_of_total = 10000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) .offset = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) .offset_relative_to_alignmask = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) .iv_offset = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) .iv_offset_relative_to_alignmask = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) .key_offset = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) .key_offset_relative_to_alignmask = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) .name = "two even aligned splits",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) .src_divs = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) { .proportion_of_total = 5000 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) { .proportion_of_total = 5000 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) .name = "uneven misaligned splits, may sleep",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) .req_flags = CRYPTO_TFM_REQ_MAY_SLEEP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) .src_divs = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) { .proportion_of_total = 1900, .offset = 33 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) { .proportion_of_total = 3300, .offset = 7 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) { .proportion_of_total = 4800, .offset = 18 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) .iv_offset = 3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) .key_offset = 3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) .name = "misaligned splits crossing pages, inplace",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) .inplace = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) .src_divs = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) .proportion_of_total = 7500,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) .offset = PAGE_SIZE - 32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) .proportion_of_total = 2500,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) .offset = PAGE_SIZE - 7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) static const struct testvec_config default_hash_testvec_configs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) .name = "init+update+final aligned buffer",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) .src_divs = { { .proportion_of_total = 10000 } },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) .finalization_type = FINALIZATION_TYPE_FINAL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) .name = "init+finup aligned buffer",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) .src_divs = { { .proportion_of_total = 10000 } },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) .finalization_type = FINALIZATION_TYPE_FINUP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) .name = "digest aligned buffer",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) .src_divs = { { .proportion_of_total = 10000 } },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) .finalization_type = FINALIZATION_TYPE_DIGEST,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) .name = "init+update+final misaligned buffer",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) .src_divs = { { .proportion_of_total = 10000, .offset = 1 } },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) .finalization_type = FINALIZATION_TYPE_FINAL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) .key_offset = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) .name = "digest buffer aligned only to alignmask",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) .src_divs = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) .proportion_of_total = 10000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) .offset = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) .offset_relative_to_alignmask = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) .finalization_type = FINALIZATION_TYPE_DIGEST,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) .key_offset = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) .key_offset_relative_to_alignmask = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) .name = "init+update+update+final two even splits",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) .src_divs = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) { .proportion_of_total = 5000 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) .proportion_of_total = 5000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) .flush_type = FLUSH_TYPE_FLUSH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) .finalization_type = FINALIZATION_TYPE_FINAL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) .name = "digest uneven misaligned splits, may sleep",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) .req_flags = CRYPTO_TFM_REQ_MAY_SLEEP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) .src_divs = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) { .proportion_of_total = 1900, .offset = 33 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) { .proportion_of_total = 3300, .offset = 7 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) { .proportion_of_total = 4800, .offset = 18 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) .finalization_type = FINALIZATION_TYPE_DIGEST,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) .name = "digest misaligned splits crossing pages",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) .src_divs = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) .proportion_of_total = 7500,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) .offset = PAGE_SIZE - 32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) .proportion_of_total = 2500,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) .offset = PAGE_SIZE - 7,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) .finalization_type = FINALIZATION_TYPE_DIGEST,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) .name = "import/export",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) .src_divs = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) .proportion_of_total = 6500,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) .flush_type = FLUSH_TYPE_REIMPORT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) .proportion_of_total = 3500,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) .flush_type = FLUSH_TYPE_REIMPORT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) .finalization_type = FINALIZATION_TYPE_FINAL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) static unsigned int count_test_sg_divisions(const struct test_sg_division *divs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) unsigned int remaining = TEST_SG_TOTAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) unsigned int ndivs = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) remaining -= divs[ndivs++].proportion_of_total;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) } while (remaining);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) return ndivs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) #define SGDIVS_HAVE_FLUSHES BIT(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) #define SGDIVS_HAVE_NOSIMD BIT(1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) static bool valid_sg_divisions(const struct test_sg_division *divs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) unsigned int count, int *flags_ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) unsigned int total = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) for (i = 0; i < count && total != TEST_SG_TOTAL; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) if (divs[i].proportion_of_total <= 0 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) divs[i].proportion_of_total > TEST_SG_TOTAL - total)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) total += divs[i].proportion_of_total;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) if (divs[i].flush_type != FLUSH_TYPE_NONE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) *flags_ret |= SGDIVS_HAVE_FLUSHES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) if (divs[i].nosimd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) *flags_ret |= SGDIVS_HAVE_NOSIMD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) return total == TEST_SG_TOTAL &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) memchr_inv(&divs[i], 0, (count - i) * sizeof(divs[0])) == NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) * Check whether the given testvec_config is valid. This isn't strictly needed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) * since every testvec_config should be valid, but check anyway so that people
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) * don't unknowingly add broken configs that don't do what they wanted.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) static bool valid_testvec_config(const struct testvec_config *cfg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) int flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) if (cfg->name == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) if (!valid_sg_divisions(cfg->src_divs, ARRAY_SIZE(cfg->src_divs),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) &flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) if (cfg->dst_divs[0].proportion_of_total) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) if (!valid_sg_divisions(cfg->dst_divs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) ARRAY_SIZE(cfg->dst_divs), &flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) if (memchr_inv(cfg->dst_divs, 0, sizeof(cfg->dst_divs)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) /* defaults to dst_divs=src_divs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) if (cfg->iv_offset +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) (cfg->iv_offset_relative_to_alignmask ? MAX_ALGAPI_ALIGNMASK : 0) >
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) MAX_ALGAPI_ALIGNMASK + 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) if ((flags & (SGDIVS_HAVE_FLUSHES | SGDIVS_HAVE_NOSIMD)) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) cfg->finalization_type == FINALIZATION_TYPE_DIGEST)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) if ((cfg->nosimd || (flags & SGDIVS_HAVE_NOSIMD)) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) (cfg->req_flags & CRYPTO_TFM_REQ_MAY_SLEEP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) struct test_sglist {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) char *bufs[XBUFSIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) struct scatterlist sgl[XBUFSIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) struct scatterlist sgl_saved[XBUFSIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) struct scatterlist *sgl_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) unsigned int nents;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) static int init_test_sglist(struct test_sglist *tsgl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) return __testmgr_alloc_buf(tsgl->bufs, 1 /* two pages per buffer */);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) static void destroy_test_sglist(struct test_sglist *tsgl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) return __testmgr_free_buf(tsgl->bufs, 1 /* two pages per buffer */);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) * build_test_sglist() - build a scatterlist for a crypto test
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) * @tsgl: the scatterlist to build. @tsgl->bufs[] contains an array of 2-page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) * buffers which the scatterlist @tsgl->sgl[] will be made to point into.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) * @divs: the layout specification on which the scatterlist will be based
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) * @alignmask: the algorithm's alignmask
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) * @total_len: the total length of the scatterlist to build in bytes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) * @data: if non-NULL, the buffers will be filled with this data until it ends.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) * Otherwise the buffers will be poisoned. In both cases, some bytes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) * past the end of each buffer will be poisoned to help detect overruns.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) * @out_divs: if non-NULL, the test_sg_division to which each scatterlist entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) * corresponds will be returned here. This will match @divs except
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) * that divisions resolving to a length of 0 are omitted as they are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) * not included in the scatterlist.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) * Return: 0 or a -errno value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) static int build_test_sglist(struct test_sglist *tsgl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) const struct test_sg_division *divs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) const unsigned int alignmask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) const unsigned int total_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) struct iov_iter *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) const struct test_sg_division *out_divs[XBUFSIZE])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) const struct test_sg_division *div;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) size_t length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) } partitions[XBUFSIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) const unsigned int ndivs = count_test_sg_divisions(divs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) unsigned int len_remaining = total_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) BUILD_BUG_ON(ARRAY_SIZE(partitions) != ARRAY_SIZE(tsgl->sgl));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) if (WARN_ON(ndivs > ARRAY_SIZE(partitions)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) /* Calculate the (div, length) pairs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) tsgl->nents = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) for (i = 0; i < ndivs; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) unsigned int len_this_sg =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) min(len_remaining,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) (total_len * divs[i].proportion_of_total +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) TEST_SG_TOTAL / 2) / TEST_SG_TOTAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) if (len_this_sg != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) partitions[tsgl->nents].div = &divs[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) partitions[tsgl->nents].length = len_this_sg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) tsgl->nents++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) len_remaining -= len_this_sg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) if (tsgl->nents == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) partitions[tsgl->nents].div = &divs[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) partitions[tsgl->nents].length = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) tsgl->nents++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) partitions[tsgl->nents - 1].length += len_remaining;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) /* Set up the sgl entries and fill the data or poison */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) sg_init_table(tsgl->sgl, tsgl->nents);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) for (i = 0; i < tsgl->nents; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) unsigned int offset = partitions[i].div->offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) void *addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) if (partitions[i].div->offset_relative_to_alignmask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) offset += alignmask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) while (offset + partitions[i].length + TESTMGR_POISON_LEN >
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) 2 * PAGE_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) if (WARN_ON(offset <= 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) offset /= 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) addr = &tsgl->bufs[i][offset];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) sg_set_buf(&tsgl->sgl[i], addr, partitions[i].length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) if (out_divs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) out_divs[i] = partitions[i].div;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) if (data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) size_t copy_len, copied;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) copy_len = min(partitions[i].length, data->count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) copied = copy_from_iter(addr, copy_len, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) if (WARN_ON(copied != copy_len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) testmgr_poison(addr + copy_len, partitions[i].length +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) TESTMGR_POISON_LEN - copy_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) testmgr_poison(addr, partitions[i].length +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) TESTMGR_POISON_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) sg_mark_end(&tsgl->sgl[tsgl->nents - 1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) tsgl->sgl_ptr = tsgl->sgl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) memcpy(tsgl->sgl_saved, tsgl->sgl, tsgl->nents * sizeof(tsgl->sgl[0]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) * Verify that a scatterlist crypto operation produced the correct output.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) * @tsgl: scatterlist containing the actual output
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) * @expected_output: buffer containing the expected output
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) * @len_to_check: length of @expected_output in bytes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) * @unchecked_prefix_len: number of ignored bytes in @tsgl prior to real result
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) * @check_poison: verify that the poison bytes after each chunk are intact?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) * Return: 0 if correct, -EINVAL if incorrect, -EOVERFLOW if buffer overrun.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) static int verify_correct_output(const struct test_sglist *tsgl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) const char *expected_output,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) unsigned int len_to_check,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) unsigned int unchecked_prefix_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) bool check_poison)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) for (i = 0; i < tsgl->nents; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) struct scatterlist *sg = &tsgl->sgl_ptr[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) unsigned int len = sg->length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) unsigned int offset = sg->offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) const char *actual_output;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) if (unchecked_prefix_len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) if (unchecked_prefix_len >= len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) unchecked_prefix_len -= len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) offset += unchecked_prefix_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) len -= unchecked_prefix_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) unchecked_prefix_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) len = min(len, len_to_check);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) actual_output = page_address(sg_page(sg)) + offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) if (memcmp(expected_output, actual_output, len) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) if (check_poison &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) !testmgr_is_poison(actual_output + len, TESTMGR_POISON_LEN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) return -EOVERFLOW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) len_to_check -= len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) expected_output += len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) if (WARN_ON(len_to_check != 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) static bool is_test_sglist_corrupted(const struct test_sglist *tsgl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) for (i = 0; i < tsgl->nents; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) if (tsgl->sgl[i].page_link != tsgl->sgl_saved[i].page_link)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) if (tsgl->sgl[i].offset != tsgl->sgl_saved[i].offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) if (tsgl->sgl[i].length != tsgl->sgl_saved[i].length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) struct cipher_test_sglists {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) struct test_sglist src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) struct test_sglist dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) static struct cipher_test_sglists *alloc_cipher_test_sglists(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) struct cipher_test_sglists *tsgls;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) tsgls = kmalloc(sizeof(*tsgls), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) if (!tsgls)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) if (init_test_sglist(&tsgls->src) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) goto fail_kfree;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) if (init_test_sglist(&tsgls->dst) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) goto fail_destroy_src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) return tsgls;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) fail_destroy_src:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) destroy_test_sglist(&tsgls->src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) fail_kfree:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) kfree(tsgls);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) static void free_cipher_test_sglists(struct cipher_test_sglists *tsgls)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) if (tsgls) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) destroy_test_sglist(&tsgls->src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) destroy_test_sglist(&tsgls->dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) kfree(tsgls);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) /* Build the src and dst scatterlists for an skcipher or AEAD test */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) static int build_cipher_test_sglists(struct cipher_test_sglists *tsgls,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) const struct testvec_config *cfg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) unsigned int alignmask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) unsigned int src_total_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) unsigned int dst_total_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) const struct kvec *inputs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) unsigned int nr_inputs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) struct iov_iter input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) iov_iter_kvec(&input, WRITE, inputs, nr_inputs, src_total_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) err = build_test_sglist(&tsgls->src, cfg->src_divs, alignmask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) cfg->inplace ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) max(dst_total_len, src_total_len) :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) src_total_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) &input, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) if (cfg->inplace) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) tsgls->dst.sgl_ptr = tsgls->src.sgl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) tsgls->dst.nents = tsgls->src.nents;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) return build_test_sglist(&tsgls->dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) cfg->dst_divs[0].proportion_of_total ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) cfg->dst_divs : cfg->src_divs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) alignmask, dst_total_len, NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) * Support for testing passing a misaligned key to setkey():
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) * If cfg->key_offset is set, copy the key into a new buffer at that offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) * optionally adding alignmask. Else, just use the key directly.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) static int prepare_keybuf(const u8 *key, unsigned int ksize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) const struct testvec_config *cfg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) unsigned int alignmask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) const u8 **keybuf_ret, const u8 **keyptr_ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) unsigned int key_offset = cfg->key_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) u8 *keybuf = NULL, *keyptr = (u8 *)key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) if (key_offset != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) if (cfg->key_offset_relative_to_alignmask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) key_offset += alignmask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) keybuf = kmalloc(key_offset + ksize, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) if (!keybuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) keyptr = keybuf + key_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) memcpy(keyptr, key, ksize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) *keybuf_ret = keybuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) *keyptr_ret = keyptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) /* Like setkey_f(tfm, key, ksize), but sometimes misalign the key */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) #define do_setkey(setkey_f, tfm, key, ksize, cfg, alignmask) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) ({ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) const u8 *keybuf, *keyptr; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) int err; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) err = prepare_keybuf((key), (ksize), (cfg), (alignmask), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) &keybuf, &keyptr); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) if (err == 0) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) err = setkey_f((tfm), keyptr, (ksize)); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) kfree(keybuf); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) err; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) #ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) /* Generate a random length in range [0, max_len], but prefer smaller values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) static unsigned int generate_random_length(unsigned int max_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) unsigned int len = prandom_u32() % (max_len + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) switch (prandom_u32() % 4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) return len % 64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) return len % 256;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) return len % 1024;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) /* Flip a random bit in the given nonempty data buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) static void flip_random_bit(u8 *buf, size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) size_t bitpos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) bitpos = prandom_u32() % (size * 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) buf[bitpos / 8] ^= 1 << (bitpos % 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) /* Flip a random byte in the given nonempty data buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) static void flip_random_byte(u8 *buf, size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) buf[prandom_u32() % size] ^= 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) /* Sometimes make some random changes to the given nonempty data buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) static void mutate_buffer(u8 *buf, size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) size_t num_flips;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) size_t i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) /* Sometimes flip some bits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) if (prandom_u32() % 4 == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) num_flips = min_t(size_t, 1 << (prandom_u32() % 8), size * 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) for (i = 0; i < num_flips; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) flip_random_bit(buf, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) /* Sometimes flip some bytes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) if (prandom_u32() % 4 == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) num_flips = min_t(size_t, 1 << (prandom_u32() % 8), size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) for (i = 0; i < num_flips; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) flip_random_byte(buf, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) /* Randomly generate 'count' bytes, but sometimes make them "interesting" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) static void generate_random_bytes(u8 *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) u8 b;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) u8 increment;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) size_t i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) if (count == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) switch (prandom_u32() % 8) { /* Choose a generation strategy */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) /* All the same byte, plus optional mutations */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) switch (prandom_u32() % 4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) b = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) b = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) b = (u8)prandom_u32();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) memset(buf, b, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) mutate_buffer(buf, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) /* Ascending or descending bytes, plus optional mutations */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) increment = (u8)prandom_u32();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) b = (u8)prandom_u32();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) for (i = 0; i < count; i++, b += increment)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) buf[i] = b;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) mutate_buffer(buf, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) /* Fully random bytes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) for (i = 0; i < count; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) buf[i] = (u8)prandom_u32();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) static char *generate_random_sgl_divisions(struct test_sg_division *divs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) size_t max_divs, char *p, char *end,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) bool gen_flushes, u32 req_flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) struct test_sg_division *div = divs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) unsigned int remaining = TEST_SG_TOTAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) unsigned int this_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) const char *flushtype_str;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) if (div == &divs[max_divs - 1] || prandom_u32() % 2 == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) this_len = remaining;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) this_len = 1 + (prandom_u32() % remaining);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) div->proportion_of_total = this_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) if (prandom_u32() % 4 == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) div->offset = (PAGE_SIZE - 128) + (prandom_u32() % 128);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) else if (prandom_u32() % 2 == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) div->offset = prandom_u32() % 32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) div->offset = prandom_u32() % PAGE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) if (prandom_u32() % 8 == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) div->offset_relative_to_alignmask = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) div->flush_type = FLUSH_TYPE_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) if (gen_flushes) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) switch (prandom_u32() % 4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) div->flush_type = FLUSH_TYPE_REIMPORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) div->flush_type = FLUSH_TYPE_FLUSH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) if (div->flush_type != FLUSH_TYPE_NONE &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) !(req_flags & CRYPTO_TFM_REQ_MAY_SLEEP) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) prandom_u32() % 2 == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) div->nosimd = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) switch (div->flush_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) case FLUSH_TYPE_FLUSH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) if (div->nosimd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) flushtype_str = "<flush,nosimd>";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) flushtype_str = "<flush>";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) case FLUSH_TYPE_REIMPORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) if (div->nosimd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) flushtype_str = "<reimport,nosimd>";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) flushtype_str = "<reimport>";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) flushtype_str = "";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) BUILD_BUG_ON(TEST_SG_TOTAL != 10000); /* for "%u.%u%%" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) p += scnprintf(p, end - p, "%s%u.%u%%@%s+%u%s", flushtype_str,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) this_len / 100, this_len % 100,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) div->offset_relative_to_alignmask ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) "alignmask" : "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) div->offset, this_len == remaining ? "" : ", ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) remaining -= this_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) div++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) } while (remaining);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) return p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) /* Generate a random testvec_config for fuzz testing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) static void generate_random_testvec_config(struct testvec_config *cfg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) char *name, size_t max_namelen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) char *p = name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) char * const end = name + max_namelen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) memset(cfg, 0, sizeof(*cfg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) cfg->name = name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) p += scnprintf(p, end - p, "random:");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) if (prandom_u32() % 2 == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) cfg->inplace = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) p += scnprintf(p, end - p, " inplace");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) if (prandom_u32() % 2 == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) cfg->req_flags |= CRYPTO_TFM_REQ_MAY_SLEEP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) p += scnprintf(p, end - p, " may_sleep");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) switch (prandom_u32() % 4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) cfg->finalization_type = FINALIZATION_TYPE_FINAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) p += scnprintf(p, end - p, " use_final");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) cfg->finalization_type = FINALIZATION_TYPE_FINUP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) p += scnprintf(p, end - p, " use_finup");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) cfg->finalization_type = FINALIZATION_TYPE_DIGEST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) p += scnprintf(p, end - p, " use_digest");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) if (!(cfg->req_flags & CRYPTO_TFM_REQ_MAY_SLEEP) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) prandom_u32() % 2 == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) cfg->nosimd = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) p += scnprintf(p, end - p, " nosimd");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) p += scnprintf(p, end - p, " src_divs=[");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) p = generate_random_sgl_divisions(cfg->src_divs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) ARRAY_SIZE(cfg->src_divs), p, end,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) (cfg->finalization_type !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) FINALIZATION_TYPE_DIGEST),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) cfg->req_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) p += scnprintf(p, end - p, "]");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) if (!cfg->inplace && prandom_u32() % 2 == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) p += scnprintf(p, end - p, " dst_divs=[");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) p = generate_random_sgl_divisions(cfg->dst_divs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) ARRAY_SIZE(cfg->dst_divs),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) p, end, false,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) cfg->req_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) p += scnprintf(p, end - p, "]");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) if (prandom_u32() % 2 == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) cfg->iv_offset = 1 + (prandom_u32() % MAX_ALGAPI_ALIGNMASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) p += scnprintf(p, end - p, " iv_offset=%u", cfg->iv_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) if (prandom_u32() % 2 == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) cfg->key_offset = 1 + (prandom_u32() % MAX_ALGAPI_ALIGNMASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) p += scnprintf(p, end - p, " key_offset=%u", cfg->key_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) WARN_ON_ONCE(!valid_testvec_config(cfg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) static void crypto_disable_simd_for_test(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) preempt_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) __this_cpu_write(crypto_simd_disabled_for_test, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) static void crypto_reenable_simd_for_test(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) __this_cpu_write(crypto_simd_disabled_for_test, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) preempt_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) * Given an algorithm name, build the name of the generic implementation of that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) * algorithm, assuming the usual naming convention. Specifically, this appends
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) * "-generic" to every part of the name that is not a template name. Examples:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) * aes => aes-generic
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) * cbc(aes) => cbc(aes-generic)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) * cts(cbc(aes)) => cts(cbc(aes-generic))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) * rfc7539(chacha20,poly1305) => rfc7539(chacha20-generic,poly1305-generic)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) * Return: 0 on success, or -ENAMETOOLONG if the generic name would be too long
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) static int build_generic_driver_name(const char *algname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) char driver_name[CRYPTO_MAX_ALG_NAME])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) const char *in = algname;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) char *out = driver_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) size_t len = strlen(algname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) if (len >= CRYPTO_MAX_ALG_NAME)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) goto too_long;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) const char *in_saved = in;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) while (*in && *in != '(' && *in != ')' && *in != ',')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) *out++ = *in++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) if (*in != '(' && in > in_saved) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) len += 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) if (len >= CRYPTO_MAX_ALG_NAME)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) goto too_long;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) memcpy(out, "-generic", 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) out += 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) } while ((*out++ = *in++) != '\0');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) too_long:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) pr_err("alg: generic driver name for \"%s\" would be too long\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) algname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) return -ENAMETOOLONG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) #else /* !CONFIG_CRYPTO_MANAGER_EXTRA_TESTS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) static void crypto_disable_simd_for_test(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) static void crypto_reenable_simd_for_test(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) #endif /* !CONFIG_CRYPTO_MANAGER_EXTRA_TESTS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) static int build_hash_sglist(struct test_sglist *tsgl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) const struct hash_testvec *vec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) const struct testvec_config *cfg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) unsigned int alignmask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) const struct test_sg_division *divs[XBUFSIZE])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) struct kvec kv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) struct iov_iter input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) kv.iov_base = (void *)vec->plaintext;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) kv.iov_len = vec->psize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) iov_iter_kvec(&input, WRITE, &kv, 1, vec->psize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) return build_test_sglist(tsgl, cfg->src_divs, alignmask, vec->psize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) &input, divs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) static int check_hash_result(const char *type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) const u8 *result, unsigned int digestsize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) const struct hash_testvec *vec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) const char *vec_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) const char *driver,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) const struct testvec_config *cfg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) if (memcmp(result, vec->digest, digestsize) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) pr_err("alg: %s: %s test failed (wrong result) on test vector %s, cfg=\"%s\"\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) type, driver, vec_name, cfg->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) if (!testmgr_is_poison(&result[digestsize], TESTMGR_POISON_LEN)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) pr_err("alg: %s: %s overran result buffer on test vector %s, cfg=\"%s\"\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) type, driver, vec_name, cfg->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) return -EOVERFLOW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) static inline int check_shash_op(const char *op, int err,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) const char *driver, const char *vec_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) const struct testvec_config *cfg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) pr_err("alg: shash: %s %s() failed with err %d on test vector %s, cfg=\"%s\"\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) driver, op, err, vec_name, cfg->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) static inline const void *sg_data(struct scatterlist *sg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) return page_address(sg_page(sg)) + sg->offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) /* Test one hash test vector in one configuration, using the shash API */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) static int test_shash_vec_cfg(const char *driver,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) const struct hash_testvec *vec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) const char *vec_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) const struct testvec_config *cfg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) struct shash_desc *desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) struct test_sglist *tsgl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) u8 *hashstate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) struct crypto_shash *tfm = desc->tfm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) const unsigned int alignmask = crypto_shash_alignmask(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) const unsigned int digestsize = crypto_shash_digestsize(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) const unsigned int statesize = crypto_shash_statesize(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) const struct test_sg_division *divs[XBUFSIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) u8 result[HASH_MAX_DIGESTSIZE + TESTMGR_POISON_LEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) /* Set the key, if specified */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) if (vec->ksize) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) err = do_setkey(crypto_shash_setkey, tfm, vec->key, vec->ksize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) cfg, alignmask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) if (err == vec->setkey_error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) pr_err("alg: shash: %s setkey failed on test vector %s; expected_error=%d, actual_error=%d, flags=%#x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) driver, vec_name, vec->setkey_error, err,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) crypto_shash_get_flags(tfm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) if (vec->setkey_error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) pr_err("alg: shash: %s setkey unexpectedly succeeded on test vector %s; expected_error=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) driver, vec_name, vec->setkey_error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) /* Build the scatterlist for the source data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) err = build_hash_sglist(tsgl, vec, cfg, alignmask, divs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) pr_err("alg: shash: %s: error preparing scatterlist for test vector %s, cfg=\"%s\"\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) driver, vec_name, cfg->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) /* Do the actual hashing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) testmgr_poison(desc->__ctx, crypto_shash_descsize(tfm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) testmgr_poison(result, digestsize + TESTMGR_POISON_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) if (cfg->finalization_type == FINALIZATION_TYPE_DIGEST ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) vec->digest_error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) /* Just using digest() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) if (tsgl->nents != 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) if (cfg->nosimd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) crypto_disable_simd_for_test();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) err = crypto_shash_digest(desc, sg_data(&tsgl->sgl[0]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) tsgl->sgl[0].length, result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) if (cfg->nosimd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) crypto_reenable_simd_for_test();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) if (err == vec->digest_error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) pr_err("alg: shash: %s digest() failed on test vector %s; expected_error=%d, actual_error=%d, cfg=\"%s\"\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) driver, vec_name, vec->digest_error, err,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) cfg->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) if (vec->digest_error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) pr_err("alg: shash: %s digest() unexpectedly succeeded on test vector %s; expected_error=%d, cfg=\"%s\"\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) driver, vec_name, vec->digest_error, cfg->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) goto result_ready;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) /* Using init(), zero or more update(), then final() or finup() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) if (cfg->nosimd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) crypto_disable_simd_for_test();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) err = crypto_shash_init(desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) if (cfg->nosimd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) crypto_reenable_simd_for_test();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) err = check_shash_op("init", err, driver, vec_name, cfg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) for (i = 0; i < tsgl->nents; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) if (i + 1 == tsgl->nents &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) cfg->finalization_type == FINALIZATION_TYPE_FINUP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) if (divs[i]->nosimd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) crypto_disable_simd_for_test();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) err = crypto_shash_finup(desc, sg_data(&tsgl->sgl[i]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) tsgl->sgl[i].length, result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) if (divs[i]->nosimd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) crypto_reenable_simd_for_test();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) err = check_shash_op("finup", err, driver, vec_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) cfg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) goto result_ready;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) if (divs[i]->nosimd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) crypto_disable_simd_for_test();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) err = crypto_shash_update(desc, sg_data(&tsgl->sgl[i]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) tsgl->sgl[i].length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) if (divs[i]->nosimd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) crypto_reenable_simd_for_test();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) err = check_shash_op("update", err, driver, vec_name, cfg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) if (divs[i]->flush_type == FLUSH_TYPE_REIMPORT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) /* Test ->export() and ->import() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) testmgr_poison(hashstate + statesize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) TESTMGR_POISON_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) err = crypto_shash_export(desc, hashstate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) err = check_shash_op("export", err, driver, vec_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) cfg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) if (!testmgr_is_poison(hashstate + statesize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) TESTMGR_POISON_LEN)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) pr_err("alg: shash: %s export() overran state buffer on test vector %s, cfg=\"%s\"\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) driver, vec_name, cfg->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) return -EOVERFLOW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) testmgr_poison(desc->__ctx, crypto_shash_descsize(tfm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) err = crypto_shash_import(desc, hashstate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) err = check_shash_op("import", err, driver, vec_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) cfg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) if (cfg->nosimd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) crypto_disable_simd_for_test();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) err = crypto_shash_final(desc, result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) if (cfg->nosimd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) crypto_reenable_simd_for_test();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) err = check_shash_op("final", err, driver, vec_name, cfg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) result_ready:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) return check_hash_result("shash", result, digestsize, vec, vec_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) driver, cfg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) static int do_ahash_op(int (*op)(struct ahash_request *req),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) struct ahash_request *req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) struct crypto_wait *wait, bool nosimd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) if (nosimd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) crypto_disable_simd_for_test();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) err = op(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) if (nosimd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) crypto_reenable_simd_for_test();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) return crypto_wait_req(err, wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) static int check_nonfinal_ahash_op(const char *op, int err,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) u8 *result, unsigned int digestsize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) const char *driver, const char *vec_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) const struct testvec_config *cfg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) pr_err("alg: ahash: %s %s() failed with err %d on test vector %s, cfg=\"%s\"\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) driver, op, err, vec_name, cfg->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) if (!testmgr_is_poison(result, digestsize)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) pr_err("alg: ahash: %s %s() used result buffer on test vector %s, cfg=\"%s\"\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) driver, op, vec_name, cfg->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) /* Test one hash test vector in one configuration, using the ahash API */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) static int test_ahash_vec_cfg(const char *driver,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) const struct hash_testvec *vec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) const char *vec_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) const struct testvec_config *cfg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) struct ahash_request *req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) struct test_sglist *tsgl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) u8 *hashstate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) const unsigned int alignmask = crypto_ahash_alignmask(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) const unsigned int digestsize = crypto_ahash_digestsize(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) const unsigned int statesize = crypto_ahash_statesize(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) const u32 req_flags = CRYPTO_TFM_REQ_MAY_BACKLOG | cfg->req_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) const struct test_sg_division *divs[XBUFSIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) DECLARE_CRYPTO_WAIT(wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) struct scatterlist *pending_sgl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) unsigned int pending_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) u8 result[HASH_MAX_DIGESTSIZE + TESTMGR_POISON_LEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) /* Set the key, if specified */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) if (vec->ksize) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) err = do_setkey(crypto_ahash_setkey, tfm, vec->key, vec->ksize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) cfg, alignmask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) if (err == vec->setkey_error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) pr_err("alg: ahash: %s setkey failed on test vector %s; expected_error=%d, actual_error=%d, flags=%#x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) driver, vec_name, vec->setkey_error, err,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) crypto_ahash_get_flags(tfm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) if (vec->setkey_error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) pr_err("alg: ahash: %s setkey unexpectedly succeeded on test vector %s; expected_error=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) driver, vec_name, vec->setkey_error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) /* Build the scatterlist for the source data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) err = build_hash_sglist(tsgl, vec, cfg, alignmask, divs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) pr_err("alg: ahash: %s: error preparing scatterlist for test vector %s, cfg=\"%s\"\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) driver, vec_name, cfg->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) /* Do the actual hashing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) testmgr_poison(req->__ctx, crypto_ahash_reqsize(tfm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) testmgr_poison(result, digestsize + TESTMGR_POISON_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) if (cfg->finalization_type == FINALIZATION_TYPE_DIGEST ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) vec->digest_error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) /* Just using digest() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) ahash_request_set_callback(req, req_flags, crypto_req_done,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) &wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) ahash_request_set_crypt(req, tsgl->sgl, result, vec->psize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) err = do_ahash_op(crypto_ahash_digest, req, &wait, cfg->nosimd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) if (err == vec->digest_error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) pr_err("alg: ahash: %s digest() failed on test vector %s; expected_error=%d, actual_error=%d, cfg=\"%s\"\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) driver, vec_name, vec->digest_error, err,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) cfg->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) if (vec->digest_error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) pr_err("alg: ahash: %s digest() unexpectedly succeeded on test vector %s; expected_error=%d, cfg=\"%s\"\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) driver, vec_name, vec->digest_error, cfg->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) goto result_ready;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) /* Using init(), zero or more update(), then final() or finup() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) ahash_request_set_callback(req, req_flags, crypto_req_done, &wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) ahash_request_set_crypt(req, NULL, result, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) err = do_ahash_op(crypto_ahash_init, req, &wait, cfg->nosimd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) err = check_nonfinal_ahash_op("init", err, result, digestsize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) driver, vec_name, cfg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) pending_sgl = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) pending_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) for (i = 0; i < tsgl->nents; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) if (divs[i]->flush_type != FLUSH_TYPE_NONE &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) pending_sgl != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) /* update() with the pending data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) ahash_request_set_callback(req, req_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) crypto_req_done, &wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) ahash_request_set_crypt(req, pending_sgl, result,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) pending_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) err = do_ahash_op(crypto_ahash_update, req, &wait,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) divs[i]->nosimd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) err = check_nonfinal_ahash_op("update", err,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) result, digestsize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) driver, vec_name, cfg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) pending_sgl = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) pending_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) if (divs[i]->flush_type == FLUSH_TYPE_REIMPORT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) /* Test ->export() and ->import() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) testmgr_poison(hashstate + statesize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) TESTMGR_POISON_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) err = crypto_ahash_export(req, hashstate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) err = check_nonfinal_ahash_op("export", err,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) result, digestsize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) driver, vec_name, cfg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) if (!testmgr_is_poison(hashstate + statesize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) TESTMGR_POISON_LEN)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) pr_err("alg: ahash: %s export() overran state buffer on test vector %s, cfg=\"%s\"\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) driver, vec_name, cfg->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) return -EOVERFLOW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) testmgr_poison(req->__ctx, crypto_ahash_reqsize(tfm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) err = crypto_ahash_import(req, hashstate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) err = check_nonfinal_ahash_op("import", err,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) result, digestsize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) driver, vec_name, cfg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) if (pending_sgl == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) pending_sgl = &tsgl->sgl[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) pending_len += tsgl->sgl[i].length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) ahash_request_set_callback(req, req_flags, crypto_req_done, &wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) ahash_request_set_crypt(req, pending_sgl, result, pending_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) if (cfg->finalization_type == FINALIZATION_TYPE_FINAL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) /* finish with update() and final() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) err = do_ahash_op(crypto_ahash_update, req, &wait, cfg->nosimd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) err = check_nonfinal_ahash_op("update", err, result, digestsize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) driver, vec_name, cfg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) err = do_ahash_op(crypto_ahash_final, req, &wait, cfg->nosimd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) pr_err("alg: ahash: %s final() failed with err %d on test vector %s, cfg=\"%s\"\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) driver, err, vec_name, cfg->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) /* finish with finup() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) err = do_ahash_op(crypto_ahash_finup, req, &wait, cfg->nosimd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) pr_err("alg: ahash: %s finup() failed with err %d on test vector %s, cfg=\"%s\"\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) driver, err, vec_name, cfg->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) result_ready:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) return check_hash_result("ahash", result, digestsize, vec, vec_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) driver, cfg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) static int test_hash_vec_cfg(const char *driver,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) const struct hash_testvec *vec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) const char *vec_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) const struct testvec_config *cfg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) struct ahash_request *req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) struct shash_desc *desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) struct test_sglist *tsgl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) u8 *hashstate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) * For algorithms implemented as "shash", most bugs will be detected by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) * both the shash and ahash tests. Test the shash API first so that the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) * failures involve less indirection, so are easier to debug.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) if (desc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) err = test_shash_vec_cfg(driver, vec, vec_name, cfg, desc, tsgl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) hashstate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) return test_ahash_vec_cfg(driver, vec, vec_name, cfg, req, tsgl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) hashstate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) static int test_hash_vec(const char *driver, const struct hash_testvec *vec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) unsigned int vec_num, struct ahash_request *req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) struct shash_desc *desc, struct test_sglist *tsgl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) u8 *hashstate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) char vec_name[16];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) sprintf(vec_name, "%u", vec_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) for (i = 0; i < ARRAY_SIZE(default_hash_testvec_configs); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) err = test_hash_vec_cfg(driver, vec, vec_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) &default_hash_testvec_configs[i],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) req, desc, tsgl, hashstate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) #ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) if (!noextratests) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) struct testvec_config cfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) char cfgname[TESTVEC_CONFIG_NAMELEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) for (i = 0; i < fuzz_iterations; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) generate_random_testvec_config(&cfg, cfgname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) sizeof(cfgname));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) err = test_hash_vec_cfg(driver, vec, vec_name, &cfg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) req, desc, tsgl, hashstate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) cond_resched();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) #ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) * Generate a hash test vector from the given implementation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) * Assumes the buffers in 'vec' were already allocated.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) static void generate_random_hash_testvec(struct shash_desc *desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) struct hash_testvec *vec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) unsigned int maxkeysize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) unsigned int maxdatasize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) char *name, size_t max_namelen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) /* Data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) vec->psize = generate_random_length(maxdatasize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) generate_random_bytes((u8 *)vec->plaintext, vec->psize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) * Key: length in range [1, maxkeysize], but usually choose maxkeysize.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) * If algorithm is unkeyed, then maxkeysize == 0 and set ksize = 0.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) vec->setkey_error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) vec->ksize = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) if (maxkeysize) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) vec->ksize = maxkeysize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) if (prandom_u32() % 4 == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) vec->ksize = 1 + (prandom_u32() % maxkeysize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) generate_random_bytes((u8 *)vec->key, vec->ksize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) vec->setkey_error = crypto_shash_setkey(desc->tfm, vec->key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) vec->ksize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) /* If the key couldn't be set, no need to continue to digest. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) if (vec->setkey_error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) /* Digest */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) vec->digest_error = crypto_shash_digest(desc, vec->plaintext,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) vec->psize, (u8 *)vec->digest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) snprintf(name, max_namelen, "\"random: psize=%u ksize=%u\"",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) vec->psize, vec->ksize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) * Test the hash algorithm represented by @req against the corresponding generic
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) * implementation, if one is available.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) static int test_hash_vs_generic_impl(const char *driver,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) const char *generic_driver,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) unsigned int maxkeysize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) struct ahash_request *req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) struct shash_desc *desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) struct test_sglist *tsgl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) u8 *hashstate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) const unsigned int digestsize = crypto_ahash_digestsize(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) const unsigned int blocksize = crypto_ahash_blocksize(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) const unsigned int maxdatasize = (2 * PAGE_SIZE) - TESTMGR_POISON_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) const char *algname = crypto_hash_alg_common(tfm)->base.cra_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) char _generic_driver[CRYPTO_MAX_ALG_NAME];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) struct crypto_shash *generic_tfm = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) struct shash_desc *generic_desc = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) struct hash_testvec vec = { 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) char vec_name[64];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) struct testvec_config *cfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) char cfgname[TESTVEC_CONFIG_NAMELEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) if (noextratests)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) if (!generic_driver) { /* Use default naming convention? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) err = build_generic_driver_name(algname, _generic_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) generic_driver = _generic_driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) if (strcmp(generic_driver, driver) == 0) /* Already the generic impl? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) generic_tfm = crypto_alloc_shash(generic_driver, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) if (IS_ERR(generic_tfm)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) err = PTR_ERR(generic_tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) if (err == -ENOENT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) pr_warn("alg: hash: skipping comparison tests for %s because %s is unavailable\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) driver, generic_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) pr_err("alg: hash: error allocating %s (generic impl of %s): %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) generic_driver, algname, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) cfg = kzalloc(sizeof(*cfg), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) if (!cfg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) generic_desc = kzalloc(sizeof(*desc) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) crypto_shash_descsize(generic_tfm), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) if (!generic_desc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) generic_desc->tfm = generic_tfm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702) /* Check the algorithm properties for consistency. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) if (digestsize != crypto_shash_digestsize(generic_tfm)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) pr_err("alg: hash: digestsize for %s (%u) doesn't match generic impl (%u)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) driver, digestsize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) crypto_shash_digestsize(generic_tfm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) if (blocksize != crypto_shash_blocksize(generic_tfm)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) pr_err("alg: hash: blocksize for %s (%u) doesn't match generic impl (%u)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) driver, blocksize, crypto_shash_blocksize(generic_tfm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) * Now generate test vectors using the generic implementation, and test
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) * the other implementation against them.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) vec.key = kmalloc(maxkeysize, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) vec.plaintext = kmalloc(maxdatasize, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) vec.digest = kmalloc(digestsize, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) if (!vec.key || !vec.plaintext || !vec.digest) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732) for (i = 0; i < fuzz_iterations * 8; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) generate_random_hash_testvec(generic_desc, &vec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734) maxkeysize, maxdatasize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735) vec_name, sizeof(vec_name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736) generate_random_testvec_config(cfg, cfgname, sizeof(cfgname));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) err = test_hash_vec_cfg(driver, &vec, vec_name, cfg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739) req, desc, tsgl, hashstate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742) cond_resched();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746) kfree(cfg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747) kfree(vec.key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) kfree(vec.plaintext);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749) kfree(vec.digest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750) crypto_free_shash(generic_tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751) kfree_sensitive(generic_desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) #else /* !CONFIG_CRYPTO_MANAGER_EXTRA_TESTS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) static int test_hash_vs_generic_impl(const char *driver,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756) const char *generic_driver,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) unsigned int maxkeysize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) struct ahash_request *req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759) struct shash_desc *desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760) struct test_sglist *tsgl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761) u8 *hashstate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765) #endif /* !CONFIG_CRYPTO_MANAGER_EXTRA_TESTS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) static int alloc_shash(const char *driver, u32 type, u32 mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768) struct crypto_shash **tfm_ret,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769) struct shash_desc **desc_ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771) struct crypto_shash *tfm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) struct shash_desc *desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774) tfm = crypto_alloc_shash(driver, type, mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775) if (IS_ERR(tfm)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776) if (PTR_ERR(tfm) == -ENOENT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778) * This algorithm is only available through the ahash
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) * API, not the shash API, so skip the shash tests.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783) pr_err("alg: hash: failed to allocate shash transform for %s: %ld\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784) driver, PTR_ERR(tfm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785) return PTR_ERR(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788) desc = kmalloc(sizeof(*desc) + crypto_shash_descsize(tfm), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789) if (!desc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790) crypto_free_shash(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793) desc->tfm = tfm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795) *tfm_ret = tfm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796) *desc_ret = desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) static int __alg_test_hash(const struct hash_testvec *vecs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801) unsigned int num_vecs, const char *driver,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802) u32 type, u32 mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803) const char *generic_driver, unsigned int maxkeysize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805) struct crypto_ahash *atfm = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806) struct ahash_request *req = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807) struct crypto_shash *stfm = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808) struct shash_desc *desc = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809) struct test_sglist *tsgl = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810) u8 *hashstate = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811) unsigned int statesize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812) unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816) * Always test the ahash API. This works regardless of whether the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817) * algorithm is implemented as ahash or shash.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820) atfm = crypto_alloc_ahash(driver, type, mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821) if (IS_ERR(atfm)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822) pr_err("alg: hash: failed to allocate transform for %s: %ld\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823) driver, PTR_ERR(atfm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824) return PTR_ERR(atfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827) req = ahash_request_alloc(atfm, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828) if (!req) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829) pr_err("alg: hash: failed to allocate request for %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830) driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) * If available also test the shash API, to cover corner cases that may
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837) * be missed by testing the ahash API only.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839) err = alloc_shash(driver, type, mask, &stfm, &desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843) tsgl = kmalloc(sizeof(*tsgl), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844) if (!tsgl || init_test_sglist(tsgl) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845) pr_err("alg: hash: failed to allocate test buffers for %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846) driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847) kfree(tsgl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848) tsgl = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853) statesize = crypto_ahash_statesize(atfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854) if (stfm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855) statesize = max(statesize, crypto_shash_statesize(stfm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856) hashstate = kmalloc(statesize + TESTMGR_POISON_LEN, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857) if (!hashstate) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858) pr_err("alg: hash: failed to allocate hash state buffer for %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859) driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864) for (i = 0; i < num_vecs; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865) err = test_hash_vec(driver, &vecs[i], i, req, desc, tsgl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866) hashstate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869) cond_resched();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871) err = test_hash_vs_generic_impl(driver, generic_driver, maxkeysize, req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872) desc, tsgl, hashstate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874) kfree(hashstate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875) if (tsgl) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876) destroy_test_sglist(tsgl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877) kfree(tsgl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879) kfree(desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880) crypto_free_shash(stfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881) ahash_request_free(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882) crypto_free_ahash(atfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886) static int alg_test_hash(const struct alg_test_desc *desc, const char *driver,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887) u32 type, u32 mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1889) const struct hash_testvec *template = desc->suite.hash.vecs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1890) unsigned int tcount = desc->suite.hash.count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1891) unsigned int nr_unkeyed, nr_keyed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1892) unsigned int maxkeysize = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1893) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1894)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1895) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1896) * For OPTIONAL_KEY algorithms, we have to do all the unkeyed tests
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1897) * first, before setting a key on the tfm. To make this easier, we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1898) * require that the unkeyed test vectors (if any) are listed first.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1899) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1900)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1901) for (nr_unkeyed = 0; nr_unkeyed < tcount; nr_unkeyed++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1902) if (template[nr_unkeyed].ksize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1903) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1904) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1905) for (nr_keyed = 0; nr_unkeyed + nr_keyed < tcount; nr_keyed++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1906) if (!template[nr_unkeyed + nr_keyed].ksize) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1907) pr_err("alg: hash: test vectors for %s out of order, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1908) "unkeyed ones must come first\n", desc->alg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1909) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1910) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1911) maxkeysize = max_t(unsigned int, maxkeysize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1912) template[nr_unkeyed + nr_keyed].ksize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1913) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1914)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1915) err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1916) if (nr_unkeyed) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1917) err = __alg_test_hash(template, nr_unkeyed, driver, type, mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1918) desc->generic_driver, maxkeysize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1919) template += nr_unkeyed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1920) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1921)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1922) if (!err && nr_keyed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1923) err = __alg_test_hash(template, nr_keyed, driver, type, mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1924) desc->generic_driver, maxkeysize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1925)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1926) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1927) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1928)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1929) static int test_aead_vec_cfg(const char *driver, int enc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1930) const struct aead_testvec *vec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1931) const char *vec_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1932) const struct testvec_config *cfg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1933) struct aead_request *req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1934) struct cipher_test_sglists *tsgls)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1935) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1936) struct crypto_aead *tfm = crypto_aead_reqtfm(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1937) const unsigned int alignmask = crypto_aead_alignmask(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1938) const unsigned int ivsize = crypto_aead_ivsize(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1939) const unsigned int authsize = vec->clen - vec->plen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1940) const u32 req_flags = CRYPTO_TFM_REQ_MAY_BACKLOG | cfg->req_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1941) const char *op = enc ? "encryption" : "decryption";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1942) DECLARE_CRYPTO_WAIT(wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1943) u8 _iv[3 * (MAX_ALGAPI_ALIGNMASK + 1) + MAX_IVLEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1944) u8 *iv = PTR_ALIGN(&_iv[0], 2 * (MAX_ALGAPI_ALIGNMASK + 1)) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1945) cfg->iv_offset +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1946) (cfg->iv_offset_relative_to_alignmask ? alignmask : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1947) struct kvec input[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1948) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1949)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1950) /* Set the key */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1951) if (vec->wk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1952) crypto_aead_set_flags(tfm, CRYPTO_TFM_REQ_FORBID_WEAK_KEYS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1953) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1954) crypto_aead_clear_flags(tfm, CRYPTO_TFM_REQ_FORBID_WEAK_KEYS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1955)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1956) err = do_setkey(crypto_aead_setkey, tfm, vec->key, vec->klen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1957) cfg, alignmask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1958) if (err && err != vec->setkey_error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1959) pr_err("alg: aead: %s setkey failed on test vector %s; expected_error=%d, actual_error=%d, flags=%#x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1960) driver, vec_name, vec->setkey_error, err,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1961) crypto_aead_get_flags(tfm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1962) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1963) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1964) if (!err && vec->setkey_error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1965) pr_err("alg: aead: %s setkey unexpectedly succeeded on test vector %s; expected_error=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1966) driver, vec_name, vec->setkey_error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1967) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1968) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1969)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1970) /* Set the authentication tag size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1971) err = crypto_aead_setauthsize(tfm, authsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1972) if (err && err != vec->setauthsize_error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1973) pr_err("alg: aead: %s setauthsize failed on test vector %s; expected_error=%d, actual_error=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1974) driver, vec_name, vec->setauthsize_error, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1975) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1976) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1977) if (!err && vec->setauthsize_error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1978) pr_err("alg: aead: %s setauthsize unexpectedly succeeded on test vector %s; expected_error=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1979) driver, vec_name, vec->setauthsize_error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1980) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1981) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1982)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1983) if (vec->setkey_error || vec->setauthsize_error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1984) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1985)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1986) /* The IV must be copied to a buffer, as the algorithm may modify it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1987) if (WARN_ON(ivsize > MAX_IVLEN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1988) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1989) if (vec->iv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1990) memcpy(iv, vec->iv, ivsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1991) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1992) memset(iv, 0, ivsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1993)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1994) /* Build the src/dst scatterlists */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1995) input[0].iov_base = (void *)vec->assoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1996) input[0].iov_len = vec->alen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1997) input[1].iov_base = enc ? (void *)vec->ptext : (void *)vec->ctext;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1998) input[1].iov_len = enc ? vec->plen : vec->clen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1999) err = build_cipher_test_sglists(tsgls, cfg, alignmask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2000) vec->alen + (enc ? vec->plen :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2001) vec->clen),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2002) vec->alen + (enc ? vec->clen :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2003) vec->plen),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2004) input, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2005) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2006) pr_err("alg: aead: %s %s: error preparing scatterlists for test vector %s, cfg=\"%s\"\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2007) driver, op, vec_name, cfg->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2008) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2009) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2010)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2011) /* Do the actual encryption or decryption */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2012) testmgr_poison(req->__ctx, crypto_aead_reqsize(tfm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2013) aead_request_set_callback(req, req_flags, crypto_req_done, &wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2014) aead_request_set_crypt(req, tsgls->src.sgl_ptr, tsgls->dst.sgl_ptr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2015) enc ? vec->plen : vec->clen, iv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2016) aead_request_set_ad(req, vec->alen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2017) if (cfg->nosimd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2018) crypto_disable_simd_for_test();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2019) err = enc ? crypto_aead_encrypt(req) : crypto_aead_decrypt(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2020) if (cfg->nosimd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2021) crypto_reenable_simd_for_test();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2022) err = crypto_wait_req(err, &wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2023)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2024) /* Check that the algorithm didn't overwrite things it shouldn't have */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2025) if (req->cryptlen != (enc ? vec->plen : vec->clen) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2026) req->assoclen != vec->alen ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2027) req->iv != iv ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2028) req->src != tsgls->src.sgl_ptr ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2029) req->dst != tsgls->dst.sgl_ptr ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2030) crypto_aead_reqtfm(req) != tfm ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2031) req->base.complete != crypto_req_done ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2032) req->base.flags != req_flags ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2033) req->base.data != &wait) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2034) pr_err("alg: aead: %s %s corrupted request struct on test vector %s, cfg=\"%s\"\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2035) driver, op, vec_name, cfg->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2036) if (req->cryptlen != (enc ? vec->plen : vec->clen))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2037) pr_err("alg: aead: changed 'req->cryptlen'\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2038) if (req->assoclen != vec->alen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2039) pr_err("alg: aead: changed 'req->assoclen'\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2040) if (req->iv != iv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2041) pr_err("alg: aead: changed 'req->iv'\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2042) if (req->src != tsgls->src.sgl_ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2043) pr_err("alg: aead: changed 'req->src'\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2044) if (req->dst != tsgls->dst.sgl_ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2045) pr_err("alg: aead: changed 'req->dst'\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2046) if (crypto_aead_reqtfm(req) != tfm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2047) pr_err("alg: aead: changed 'req->base.tfm'\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2048) if (req->base.complete != crypto_req_done)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2049) pr_err("alg: aead: changed 'req->base.complete'\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2050) if (req->base.flags != req_flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2051) pr_err("alg: aead: changed 'req->base.flags'\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2052) if (req->base.data != &wait)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2053) pr_err("alg: aead: changed 'req->base.data'\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2054) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2055) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2056) if (is_test_sglist_corrupted(&tsgls->src)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2057) pr_err("alg: aead: %s %s corrupted src sgl on test vector %s, cfg=\"%s\"\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2058) driver, op, vec_name, cfg->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2059) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2060) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2061) if (tsgls->dst.sgl_ptr != tsgls->src.sgl &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2062) is_test_sglist_corrupted(&tsgls->dst)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2063) pr_err("alg: aead: %s %s corrupted dst sgl on test vector %s, cfg=\"%s\"\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2064) driver, op, vec_name, cfg->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2065) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2066) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2067)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2068) /* Check for unexpected success or failure, or wrong error code */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2069) if ((err == 0 && vec->novrfy) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2070) (err != vec->crypt_error && !(err == -EBADMSG && vec->novrfy))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2071) char expected_error[32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2072)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2073) if (vec->novrfy &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2074) vec->crypt_error != 0 && vec->crypt_error != -EBADMSG)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2075) sprintf(expected_error, "-EBADMSG or %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2076) vec->crypt_error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2077) else if (vec->novrfy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2078) sprintf(expected_error, "-EBADMSG");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2079) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2080) sprintf(expected_error, "%d", vec->crypt_error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2081) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2082) pr_err("alg: aead: %s %s failed on test vector %s; expected_error=%s, actual_error=%d, cfg=\"%s\"\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2083) driver, op, vec_name, expected_error, err,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2084) cfg->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2085) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2086) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2087) pr_err("alg: aead: %s %s unexpectedly succeeded on test vector %s; expected_error=%s, cfg=\"%s\"\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2088) driver, op, vec_name, expected_error, cfg->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2089) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2090) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2091) if (err) /* Expectedly failed. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2092) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2093)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2094) /* Check for the correct output (ciphertext or plaintext) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2095) err = verify_correct_output(&tsgls->dst, enc ? vec->ctext : vec->ptext,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2096) enc ? vec->clen : vec->plen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2097) vec->alen, enc || !cfg->inplace);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2098) if (err == -EOVERFLOW) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2099) pr_err("alg: aead: %s %s overran dst buffer on test vector %s, cfg=\"%s\"\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2100) driver, op, vec_name, cfg->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2101) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2103) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2104) pr_err("alg: aead: %s %s test failed (wrong result) on test vector %s, cfg=\"%s\"\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2105) driver, op, vec_name, cfg->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2106) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2107) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2109) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2110) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2112) static int test_aead_vec(const char *driver, int enc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2113) const struct aead_testvec *vec, unsigned int vec_num,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2114) struct aead_request *req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2115) struct cipher_test_sglists *tsgls)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2116) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2117) char vec_name[16];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2118) unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2119) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2121) if (enc && vec->novrfy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2122) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2124) sprintf(vec_name, "%u", vec_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2126) for (i = 0; i < ARRAY_SIZE(default_cipher_testvec_configs); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2127) err = test_aead_vec_cfg(driver, enc, vec, vec_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2128) &default_cipher_testvec_configs[i],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2129) req, tsgls);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2130) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2131) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2132) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2134) #ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2135) if (!noextratests) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2136) struct testvec_config cfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2137) char cfgname[TESTVEC_CONFIG_NAMELEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2139) for (i = 0; i < fuzz_iterations; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2140) generate_random_testvec_config(&cfg, cfgname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2141) sizeof(cfgname));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2142) err = test_aead_vec_cfg(driver, enc, vec, vec_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2143) &cfg, req, tsgls);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2144) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2145) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2146) cond_resched();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2148) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2149) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2150) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2151) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2153) #ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2155) struct aead_extra_tests_ctx {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2156) struct aead_request *req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2157) struct crypto_aead *tfm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2158) const char *driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2159) const struct alg_test_desc *test_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2160) struct cipher_test_sglists *tsgls;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2161) unsigned int maxdatasize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2162) unsigned int maxkeysize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2164) struct aead_testvec vec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2165) char vec_name[64];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2166) char cfgname[TESTVEC_CONFIG_NAMELEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2167) struct testvec_config cfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2168) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2170) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2171) * Make at least one random change to a (ciphertext, AAD) pair. "Ciphertext"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2172) * here means the full ciphertext including the authentication tag. The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2173) * authentication tag (and hence also the ciphertext) is assumed to be nonempty.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2174) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2175) static void mutate_aead_message(struct aead_testvec *vec, bool aad_iv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2176) unsigned int ivsize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2177) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2178) const unsigned int aad_tail_size = aad_iv ? ivsize : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2179) const unsigned int authsize = vec->clen - vec->plen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2181) if (prandom_u32() % 2 == 0 && vec->alen > aad_tail_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2182) /* Mutate the AAD */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2183) flip_random_bit((u8 *)vec->assoc, vec->alen - aad_tail_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2184) if (prandom_u32() % 2 == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2185) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2186) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2187) if (prandom_u32() % 2 == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2188) /* Mutate auth tag (assuming it's at the end of ciphertext) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2189) flip_random_bit((u8 *)vec->ctext + vec->plen, authsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2190) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2191) /* Mutate any part of the ciphertext */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2192) flip_random_bit((u8 *)vec->ctext, vec->clen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2193) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2194) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2196) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2197) * Minimum authentication tag size in bytes at which we assume that we can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2198) * reliably generate inauthentic messages, i.e. not generate an authentic
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2199) * message by chance.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2200) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2201) #define MIN_COLLISION_FREE_AUTHSIZE 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2203) static void generate_aead_message(struct aead_request *req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2204) const struct aead_test_suite *suite,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2205) struct aead_testvec *vec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2206) bool prefer_inauthentic)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2207) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2208) struct crypto_aead *tfm = crypto_aead_reqtfm(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2209) const unsigned int ivsize = crypto_aead_ivsize(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2210) const unsigned int authsize = vec->clen - vec->plen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2211) const bool inauthentic = (authsize >= MIN_COLLISION_FREE_AUTHSIZE) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2212) (prefer_inauthentic || prandom_u32() % 4 == 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2214) /* Generate the AAD. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2215) generate_random_bytes((u8 *)vec->assoc, vec->alen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2216) if (suite->aad_iv && vec->alen >= ivsize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2217) /* Avoid implementation-defined behavior. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2218) memcpy((u8 *)vec->assoc + vec->alen - ivsize, vec->iv, ivsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2220) if (inauthentic && prandom_u32() % 2 == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2221) /* Generate a random ciphertext. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2222) generate_random_bytes((u8 *)vec->ctext, vec->clen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2223) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2224) int i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2225) struct scatterlist src[2], dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2226) u8 iv[MAX_IVLEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2227) DECLARE_CRYPTO_WAIT(wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2229) /* Generate a random plaintext and encrypt it. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2230) sg_init_table(src, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2231) if (vec->alen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2232) sg_set_buf(&src[i++], vec->assoc, vec->alen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2233) if (vec->plen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2234) generate_random_bytes((u8 *)vec->ptext, vec->plen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2235) sg_set_buf(&src[i++], vec->ptext, vec->plen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2236) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2237) sg_init_one(&dst, vec->ctext, vec->alen + vec->clen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2238) memcpy(iv, vec->iv, ivsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2239) aead_request_set_callback(req, 0, crypto_req_done, &wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2240) aead_request_set_crypt(req, src, &dst, vec->plen, iv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2241) aead_request_set_ad(req, vec->alen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2242) vec->crypt_error = crypto_wait_req(crypto_aead_encrypt(req),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2243) &wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2244) /* If encryption failed, we're done. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2245) if (vec->crypt_error != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2246) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2247) memmove((u8 *)vec->ctext, vec->ctext + vec->alen, vec->clen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2248) if (!inauthentic)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2249) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2250) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2251) * Mutate the authentic (ciphertext, AAD) pair to get an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2252) * inauthentic one.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2253) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2254) mutate_aead_message(vec, suite->aad_iv, ivsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2255) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2256) vec->novrfy = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2257) if (suite->einval_allowed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2258) vec->crypt_error = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2259) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2261) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2262) * Generate an AEAD test vector 'vec' using the implementation specified by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2263) * 'req'. The buffers in 'vec' must already be allocated.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2264) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2265) * If 'prefer_inauthentic' is true, then this function will generate inauthentic
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2266) * test vectors (i.e. vectors with 'vec->novrfy=1') more often.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2267) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2268) static void generate_random_aead_testvec(struct aead_request *req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2269) struct aead_testvec *vec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2270) const struct aead_test_suite *suite,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2271) unsigned int maxkeysize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2272) unsigned int maxdatasize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2273) char *name, size_t max_namelen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2274) bool prefer_inauthentic)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2275) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2276) struct crypto_aead *tfm = crypto_aead_reqtfm(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2277) const unsigned int ivsize = crypto_aead_ivsize(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2278) const unsigned int maxauthsize = crypto_aead_maxauthsize(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2279) unsigned int authsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2280) unsigned int total_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2282) /* Key: length in [0, maxkeysize], but usually choose maxkeysize */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2283) vec->klen = maxkeysize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2284) if (prandom_u32() % 4 == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2285) vec->klen = prandom_u32() % (maxkeysize + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2286) generate_random_bytes((u8 *)vec->key, vec->klen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2287) vec->setkey_error = crypto_aead_setkey(tfm, vec->key, vec->klen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2288)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2289) /* IV */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2290) generate_random_bytes((u8 *)vec->iv, ivsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2292) /* Tag length: in [0, maxauthsize], but usually choose maxauthsize */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2293) authsize = maxauthsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2294) if (prandom_u32() % 4 == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2295) authsize = prandom_u32() % (maxauthsize + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2296) if (prefer_inauthentic && authsize < MIN_COLLISION_FREE_AUTHSIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2297) authsize = MIN_COLLISION_FREE_AUTHSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2298) if (WARN_ON(authsize > maxdatasize))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2299) authsize = maxdatasize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2300) maxdatasize -= authsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2301) vec->setauthsize_error = crypto_aead_setauthsize(tfm, authsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2303) /* AAD, plaintext, and ciphertext lengths */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2304) total_len = generate_random_length(maxdatasize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2305) if (prandom_u32() % 4 == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2306) vec->alen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2307) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2308) vec->alen = generate_random_length(total_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2309) vec->plen = total_len - vec->alen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2310) vec->clen = vec->plen + authsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2312) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2313) * Generate the AAD, plaintext, and ciphertext. Not applicable if the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2314) * key or the authentication tag size couldn't be set.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2315) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2316) vec->novrfy = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2317) vec->crypt_error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2318) if (vec->setkey_error == 0 && vec->setauthsize_error == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2319) generate_aead_message(req, suite, vec, prefer_inauthentic);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2320) snprintf(name, max_namelen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2321) "\"random: alen=%u plen=%u authsize=%u klen=%u novrfy=%d\"",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2322) vec->alen, vec->plen, authsize, vec->klen, vec->novrfy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2323) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2324)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2325) static void try_to_generate_inauthentic_testvec(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2326) struct aead_extra_tests_ctx *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2327) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2328) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2329)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2330) for (i = 0; i < 10; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2331) generate_random_aead_testvec(ctx->req, &ctx->vec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2332) &ctx->test_desc->suite.aead,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2333) ctx->maxkeysize, ctx->maxdatasize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2334) ctx->vec_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2335) sizeof(ctx->vec_name), true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2336) if (ctx->vec.novrfy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2337) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2338) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2339) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2340)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2341) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2342) * Generate inauthentic test vectors (i.e. ciphertext, AAD pairs that aren't the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2343) * result of an encryption with the key) and verify that decryption fails.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2344) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2345) static int test_aead_inauthentic_inputs(struct aead_extra_tests_ctx *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2346) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2347) unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2348) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2349)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2350) for (i = 0; i < fuzz_iterations * 8; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2351) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2352) * Since this part of the tests isn't comparing the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2353) * implementation to another, there's no point in testing any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2354) * test vectors other than inauthentic ones (vec.novrfy=1) here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2355) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2356) * If we're having trouble generating such a test vector, e.g.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2357) * if the algorithm keeps rejecting the generated keys, don't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2358) * retry forever; just continue on.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2359) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2360) try_to_generate_inauthentic_testvec(ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2361) if (ctx->vec.novrfy) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2362) generate_random_testvec_config(&ctx->cfg, ctx->cfgname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2363) sizeof(ctx->cfgname));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2364) err = test_aead_vec_cfg(ctx->driver, DECRYPT, &ctx->vec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2365) ctx->vec_name, &ctx->cfg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2366) ctx->req, ctx->tsgls);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2367) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2368) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2369) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2370) cond_resched();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2371) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2372) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2373) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2374)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2375) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2376) * Test the AEAD algorithm against the corresponding generic implementation, if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2377) * one is available.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2378) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2379) static int test_aead_vs_generic_impl(struct aead_extra_tests_ctx *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2380) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2381) struct crypto_aead *tfm = ctx->tfm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2382) const char *algname = crypto_aead_alg(tfm)->base.cra_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2383) const char *driver = ctx->driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2384) const char *generic_driver = ctx->test_desc->generic_driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2385) char _generic_driver[CRYPTO_MAX_ALG_NAME];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2386) struct crypto_aead *generic_tfm = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2387) struct aead_request *generic_req = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2388) unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2389) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2390)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2391) if (!generic_driver) { /* Use default naming convention? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2392) err = build_generic_driver_name(algname, _generic_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2393) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2394) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2395) generic_driver = _generic_driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2396) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2397)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2398) if (strcmp(generic_driver, driver) == 0) /* Already the generic impl? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2399) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2400)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2401) generic_tfm = crypto_alloc_aead(generic_driver, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2402) if (IS_ERR(generic_tfm)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2403) err = PTR_ERR(generic_tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2404) if (err == -ENOENT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2405) pr_warn("alg: aead: skipping comparison tests for %s because %s is unavailable\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2406) driver, generic_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2407) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2408) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2409) pr_err("alg: aead: error allocating %s (generic impl of %s): %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2410) generic_driver, algname, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2411) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2412) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2413)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2414) generic_req = aead_request_alloc(generic_tfm, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2415) if (!generic_req) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2416) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2417) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2418) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2419)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2420) /* Check the algorithm properties for consistency. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2421)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2422) if (crypto_aead_maxauthsize(tfm) !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2423) crypto_aead_maxauthsize(generic_tfm)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2424) pr_err("alg: aead: maxauthsize for %s (%u) doesn't match generic impl (%u)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2425) driver, crypto_aead_maxauthsize(tfm),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2426) crypto_aead_maxauthsize(generic_tfm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2427) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2428) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2429) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2430)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2431) if (crypto_aead_ivsize(tfm) != crypto_aead_ivsize(generic_tfm)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2432) pr_err("alg: aead: ivsize for %s (%u) doesn't match generic impl (%u)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2433) driver, crypto_aead_ivsize(tfm),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2434) crypto_aead_ivsize(generic_tfm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2435) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2436) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2437) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2438)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2439) if (crypto_aead_blocksize(tfm) != crypto_aead_blocksize(generic_tfm)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2440) pr_err("alg: aead: blocksize for %s (%u) doesn't match generic impl (%u)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2441) driver, crypto_aead_blocksize(tfm),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2442) crypto_aead_blocksize(generic_tfm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2443) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2444) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2445) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2446)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2447) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2448) * Now generate test vectors using the generic implementation, and test
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2449) * the other implementation against them.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2450) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2451) for (i = 0; i < fuzz_iterations * 8; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2452) generate_random_aead_testvec(generic_req, &ctx->vec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2453) &ctx->test_desc->suite.aead,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2454) ctx->maxkeysize, ctx->maxdatasize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2455) ctx->vec_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2456) sizeof(ctx->vec_name), false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2457) generate_random_testvec_config(&ctx->cfg, ctx->cfgname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2458) sizeof(ctx->cfgname));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2459) if (!ctx->vec.novrfy) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2460) err = test_aead_vec_cfg(driver, ENCRYPT, &ctx->vec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2461) ctx->vec_name, &ctx->cfg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2462) ctx->req, ctx->tsgls);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2463) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2464) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2465) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2466) if (ctx->vec.crypt_error == 0 || ctx->vec.novrfy) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2467) err = test_aead_vec_cfg(driver, DECRYPT, &ctx->vec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2468) ctx->vec_name, &ctx->cfg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2469) ctx->req, ctx->tsgls);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2470) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2471) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2472) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2473) cond_resched();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2474) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2475) err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2476) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2477) crypto_free_aead(generic_tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2478) aead_request_free(generic_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2479) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2480) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2481)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2482) static int test_aead_extra(const char *driver,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2483) const struct alg_test_desc *test_desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2484) struct aead_request *req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2485) struct cipher_test_sglists *tsgls)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2486) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2487) struct aead_extra_tests_ctx *ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2488) unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2489) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2490)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2491) if (noextratests)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2492) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2493)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2494) ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2495) if (!ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2496) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2497) ctx->req = req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2498) ctx->tfm = crypto_aead_reqtfm(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2499) ctx->driver = driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2500) ctx->test_desc = test_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2501) ctx->tsgls = tsgls;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2502) ctx->maxdatasize = (2 * PAGE_SIZE) - TESTMGR_POISON_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2503) ctx->maxkeysize = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2504) for (i = 0; i < test_desc->suite.aead.count; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2505) ctx->maxkeysize = max_t(unsigned int, ctx->maxkeysize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2506) test_desc->suite.aead.vecs[i].klen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2507)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2508) ctx->vec.key = kmalloc(ctx->maxkeysize, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2509) ctx->vec.iv = kmalloc(crypto_aead_ivsize(ctx->tfm), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2510) ctx->vec.assoc = kmalloc(ctx->maxdatasize, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2511) ctx->vec.ptext = kmalloc(ctx->maxdatasize, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2512) ctx->vec.ctext = kmalloc(ctx->maxdatasize, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2513) if (!ctx->vec.key || !ctx->vec.iv || !ctx->vec.assoc ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2514) !ctx->vec.ptext || !ctx->vec.ctext) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2515) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2516) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2517) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2518)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2519) err = test_aead_vs_generic_impl(ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2520) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2521) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2522)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2523) err = test_aead_inauthentic_inputs(ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2524) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2525) kfree(ctx->vec.key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2526) kfree(ctx->vec.iv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2527) kfree(ctx->vec.assoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2528) kfree(ctx->vec.ptext);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2529) kfree(ctx->vec.ctext);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2530) kfree(ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2531) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2532) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2533) #else /* !CONFIG_CRYPTO_MANAGER_EXTRA_TESTS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2534) static int test_aead_extra(const char *driver,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2535) const struct alg_test_desc *test_desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2536) struct aead_request *req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2537) struct cipher_test_sglists *tsgls)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2538) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2539) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2540) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2541) #endif /* !CONFIG_CRYPTO_MANAGER_EXTRA_TESTS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2542)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2543) static int test_aead(const char *driver, int enc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2544) const struct aead_test_suite *suite,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2545) struct aead_request *req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2546) struct cipher_test_sglists *tsgls)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2547) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2548) unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2549) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2550)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2551) for (i = 0; i < suite->count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2552) err = test_aead_vec(driver, enc, &suite->vecs[i], i, req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2553) tsgls);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2554) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2555) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2556) cond_resched();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2557) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2558) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2559) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2560)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2561) static int alg_test_aead(const struct alg_test_desc *desc, const char *driver,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2562) u32 type, u32 mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2563) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2564) const struct aead_test_suite *suite = &desc->suite.aead;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2565) struct crypto_aead *tfm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2566) struct aead_request *req = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2567) struct cipher_test_sglists *tsgls = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2568) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2569)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2570) if (suite->count <= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2571) pr_err("alg: aead: empty test suite for %s\n", driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2572) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2573) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2574)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2575) tfm = crypto_alloc_aead(driver, type, mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2576) if (IS_ERR(tfm)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2577) pr_err("alg: aead: failed to allocate transform for %s: %ld\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2578) driver, PTR_ERR(tfm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2579) return PTR_ERR(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2580) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2581)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2582) req = aead_request_alloc(tfm, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2583) if (!req) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2584) pr_err("alg: aead: failed to allocate request for %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2585) driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2586) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2587) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2588) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2589)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2590) tsgls = alloc_cipher_test_sglists();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2591) if (!tsgls) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2592) pr_err("alg: aead: failed to allocate test buffers for %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2593) driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2594) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2595) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2596) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2597)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2598) err = test_aead(driver, ENCRYPT, suite, req, tsgls);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2599) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2600) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2601)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2602) err = test_aead(driver, DECRYPT, suite, req, tsgls);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2603) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2604) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2605)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2606) err = test_aead_extra(driver, desc, req, tsgls);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2607) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2608) free_cipher_test_sglists(tsgls);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2609) aead_request_free(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2610) crypto_free_aead(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2611) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2612) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2613)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2614) static int test_cipher(struct crypto_cipher *tfm, int enc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2615) const struct cipher_testvec *template,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2616) unsigned int tcount)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2617) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2618) const char *algo = crypto_tfm_alg_driver_name(crypto_cipher_tfm(tfm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2619) unsigned int i, j, k;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2620) char *q;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2621) const char *e;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2622) const char *input, *result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2623) void *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2624) char *xbuf[XBUFSIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2625) int ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2626)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2627) if (testmgr_alloc_buf(xbuf))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2628) goto out_nobuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2629)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2630) if (enc == ENCRYPT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2631) e = "encryption";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2632) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2633) e = "decryption";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2634)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2635) j = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2636) for (i = 0; i < tcount; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2637)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2638) if (fips_enabled && template[i].fips_skip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2639) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2640)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2641) input = enc ? template[i].ptext : template[i].ctext;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2642) result = enc ? template[i].ctext : template[i].ptext;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2643) j++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2644)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2645) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2646) if (WARN_ON(template[i].len > PAGE_SIZE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2647) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2648)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2649) data = xbuf[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2650) memcpy(data, input, template[i].len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2651)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2652) crypto_cipher_clear_flags(tfm, ~0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2653) if (template[i].wk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2654) crypto_cipher_set_flags(tfm, CRYPTO_TFM_REQ_FORBID_WEAK_KEYS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2655)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2656) ret = crypto_cipher_setkey(tfm, template[i].key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2657) template[i].klen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2658) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2659) if (ret == template[i].setkey_error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2660) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2661) pr_err("alg: cipher: %s setkey failed on test vector %u; expected_error=%d, actual_error=%d, flags=%#x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2662) algo, j, template[i].setkey_error, ret,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2663) crypto_cipher_get_flags(tfm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2664) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2665) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2666) if (template[i].setkey_error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2667) pr_err("alg: cipher: %s setkey unexpectedly succeeded on test vector %u; expected_error=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2668) algo, j, template[i].setkey_error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2669) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2670) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2671) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2672)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2673) for (k = 0; k < template[i].len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2674) k += crypto_cipher_blocksize(tfm)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2675) if (enc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2676) crypto_cipher_encrypt_one(tfm, data + k,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2677) data + k);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2678) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2679) crypto_cipher_decrypt_one(tfm, data + k,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2680) data + k);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2681) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2682)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2683) q = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2684) if (memcmp(q, result, template[i].len)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2685) printk(KERN_ERR "alg: cipher: Test %d failed "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2686) "on %s for %s\n", j, e, algo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2687) hexdump(q, template[i].len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2688) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2689) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2690) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2691) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2692)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2693) ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2694)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2695) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2696) testmgr_free_buf(xbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2697) out_nobuf:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2698) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2699) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2700)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2701) static int test_skcipher_vec_cfg(const char *driver, int enc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2702) const struct cipher_testvec *vec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2703) const char *vec_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2704) const struct testvec_config *cfg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2705) struct skcipher_request *req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2706) struct cipher_test_sglists *tsgls)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2707) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2708) struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2709) const unsigned int alignmask = crypto_skcipher_alignmask(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2710) const unsigned int ivsize = crypto_skcipher_ivsize(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2711) const u32 req_flags = CRYPTO_TFM_REQ_MAY_BACKLOG | cfg->req_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2712) const char *op = enc ? "encryption" : "decryption";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2713) DECLARE_CRYPTO_WAIT(wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2714) u8 _iv[3 * (MAX_ALGAPI_ALIGNMASK + 1) + MAX_IVLEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2715) u8 *iv = PTR_ALIGN(&_iv[0], 2 * (MAX_ALGAPI_ALIGNMASK + 1)) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2716) cfg->iv_offset +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2717) (cfg->iv_offset_relative_to_alignmask ? alignmask : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2718) struct kvec input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2719) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2720)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2721) /* Set the key */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2722) if (vec->wk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2723) crypto_skcipher_set_flags(tfm, CRYPTO_TFM_REQ_FORBID_WEAK_KEYS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2724) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2725) crypto_skcipher_clear_flags(tfm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2726) CRYPTO_TFM_REQ_FORBID_WEAK_KEYS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2727) err = do_setkey(crypto_skcipher_setkey, tfm, vec->key, vec->klen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2728) cfg, alignmask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2729) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2730) if (err == vec->setkey_error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2731) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2732) pr_err("alg: skcipher: %s setkey failed on test vector %s; expected_error=%d, actual_error=%d, flags=%#x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2733) driver, vec_name, vec->setkey_error, err,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2734) crypto_skcipher_get_flags(tfm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2735) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2736) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2737) if (vec->setkey_error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2738) pr_err("alg: skcipher: %s setkey unexpectedly succeeded on test vector %s; expected_error=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2739) driver, vec_name, vec->setkey_error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2740) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2741) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2742)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2743) /* The IV must be copied to a buffer, as the algorithm may modify it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2744) if (ivsize) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2745) if (WARN_ON(ivsize > MAX_IVLEN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2746) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2747) if (vec->generates_iv && !enc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2748) memcpy(iv, vec->iv_out, ivsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2749) else if (vec->iv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2750) memcpy(iv, vec->iv, ivsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2751) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2752) memset(iv, 0, ivsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2753) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2754) if (vec->generates_iv) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2755) pr_err("alg: skcipher: %s has ivsize=0 but test vector %s generates IV!\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2756) driver, vec_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2757) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2758) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2759) iv = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2760) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2761)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2762) /* Build the src/dst scatterlists */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2763) input.iov_base = enc ? (void *)vec->ptext : (void *)vec->ctext;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2764) input.iov_len = vec->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2765) err = build_cipher_test_sglists(tsgls, cfg, alignmask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2766) vec->len, vec->len, &input, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2767) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2768) pr_err("alg: skcipher: %s %s: error preparing scatterlists for test vector %s, cfg=\"%s\"\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2769) driver, op, vec_name, cfg->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2770) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2771) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2772)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2773) /* Do the actual encryption or decryption */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2774) testmgr_poison(req->__ctx, crypto_skcipher_reqsize(tfm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2775) skcipher_request_set_callback(req, req_flags, crypto_req_done, &wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2776) skcipher_request_set_crypt(req, tsgls->src.sgl_ptr, tsgls->dst.sgl_ptr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2777) vec->len, iv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2778) if (cfg->nosimd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2779) crypto_disable_simd_for_test();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2780) err = enc ? crypto_skcipher_encrypt(req) : crypto_skcipher_decrypt(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2781) if (cfg->nosimd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2782) crypto_reenable_simd_for_test();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2783) err = crypto_wait_req(err, &wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2784)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2785) /* Check that the algorithm didn't overwrite things it shouldn't have */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2786) if (req->cryptlen != vec->len ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2787) req->iv != iv ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2788) req->src != tsgls->src.sgl_ptr ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2789) req->dst != tsgls->dst.sgl_ptr ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2790) crypto_skcipher_reqtfm(req) != tfm ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2791) req->base.complete != crypto_req_done ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2792) req->base.flags != req_flags ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2793) req->base.data != &wait) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2794) pr_err("alg: skcipher: %s %s corrupted request struct on test vector %s, cfg=\"%s\"\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2795) driver, op, vec_name, cfg->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2796) if (req->cryptlen != vec->len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2797) pr_err("alg: skcipher: changed 'req->cryptlen'\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2798) if (req->iv != iv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2799) pr_err("alg: skcipher: changed 'req->iv'\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2800) if (req->src != tsgls->src.sgl_ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2801) pr_err("alg: skcipher: changed 'req->src'\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2802) if (req->dst != tsgls->dst.sgl_ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2803) pr_err("alg: skcipher: changed 'req->dst'\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2804) if (crypto_skcipher_reqtfm(req) != tfm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2805) pr_err("alg: skcipher: changed 'req->base.tfm'\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2806) if (req->base.complete != crypto_req_done)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2807) pr_err("alg: skcipher: changed 'req->base.complete'\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2808) if (req->base.flags != req_flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2809) pr_err("alg: skcipher: changed 'req->base.flags'\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2810) if (req->base.data != &wait)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2811) pr_err("alg: skcipher: changed 'req->base.data'\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2812) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2813) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2814) if (is_test_sglist_corrupted(&tsgls->src)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2815) pr_err("alg: skcipher: %s %s corrupted src sgl on test vector %s, cfg=\"%s\"\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2816) driver, op, vec_name, cfg->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2817) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2818) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2819) if (tsgls->dst.sgl_ptr != tsgls->src.sgl &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2820) is_test_sglist_corrupted(&tsgls->dst)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2821) pr_err("alg: skcipher: %s %s corrupted dst sgl on test vector %s, cfg=\"%s\"\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2822) driver, op, vec_name, cfg->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2823) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2824) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2825)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2826) /* Check for success or failure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2827) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2828) if (err == vec->crypt_error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2829) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2830) pr_err("alg: skcipher: %s %s failed on test vector %s; expected_error=%d, actual_error=%d, cfg=\"%s\"\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2831) driver, op, vec_name, vec->crypt_error, err, cfg->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2832) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2833) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2834) if (vec->crypt_error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2835) pr_err("alg: skcipher: %s %s unexpectedly succeeded on test vector %s; expected_error=%d, cfg=\"%s\"\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2836) driver, op, vec_name, vec->crypt_error, cfg->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2837) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2838) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2839)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2840) /* Check for the correct output (ciphertext or plaintext) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2841) err = verify_correct_output(&tsgls->dst, enc ? vec->ctext : vec->ptext,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2842) vec->len, 0, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2843) if (err == -EOVERFLOW) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2844) pr_err("alg: skcipher: %s %s overran dst buffer on test vector %s, cfg=\"%s\"\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2845) driver, op, vec_name, cfg->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2846) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2847) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2848) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2849) pr_err("alg: skcipher: %s %s test failed (wrong result) on test vector %s, cfg=\"%s\"\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2850) driver, op, vec_name, cfg->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2851) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2852) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2853)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2854) /* If applicable, check that the algorithm generated the correct IV */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2855) if (vec->iv_out && memcmp(iv, vec->iv_out, ivsize) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2856) pr_err("alg: skcipher: %s %s test failed (wrong output IV) on test vector %s, cfg=\"%s\"\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2857) driver, op, vec_name, cfg->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2858) hexdump(iv, ivsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2859) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2860) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2861)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2862) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2863) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2864)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2865) static int test_skcipher_vec(const char *driver, int enc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2866) const struct cipher_testvec *vec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2867) unsigned int vec_num,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2868) struct skcipher_request *req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2869) struct cipher_test_sglists *tsgls)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2870) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2871) char vec_name[16];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2872) unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2873) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2874)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2875) if (fips_enabled && vec->fips_skip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2876) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2877)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2878) sprintf(vec_name, "%u", vec_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2879)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2880) for (i = 0; i < ARRAY_SIZE(default_cipher_testvec_configs); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2881) err = test_skcipher_vec_cfg(driver, enc, vec, vec_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2882) &default_cipher_testvec_configs[i],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2883) req, tsgls);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2884) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2885) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2886) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2887)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2888) #ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2889) if (!noextratests) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2890) struct testvec_config cfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2891) char cfgname[TESTVEC_CONFIG_NAMELEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2892)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2893) for (i = 0; i < fuzz_iterations; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2894) generate_random_testvec_config(&cfg, cfgname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2895) sizeof(cfgname));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2896) err = test_skcipher_vec_cfg(driver, enc, vec, vec_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2897) &cfg, req, tsgls);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2898) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2899) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2900) cond_resched();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2901) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2902) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2903) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2904) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2905) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2906)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2907) #ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2908) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2909) * Generate a symmetric cipher test vector from the given implementation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2910) * Assumes the buffers in 'vec' were already allocated.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2911) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2912) static void generate_random_cipher_testvec(struct skcipher_request *req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2913) struct cipher_testvec *vec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2914) unsigned int maxdatasize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2915) char *name, size_t max_namelen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2916) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2917) struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2918) const unsigned int maxkeysize = crypto_skcipher_max_keysize(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2919) const unsigned int ivsize = crypto_skcipher_ivsize(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2920) struct scatterlist src, dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2921) u8 iv[MAX_IVLEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2922) DECLARE_CRYPTO_WAIT(wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2923)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2924) /* Key: length in [0, maxkeysize], but usually choose maxkeysize */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2925) vec->klen = maxkeysize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2926) if (prandom_u32() % 4 == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2927) vec->klen = prandom_u32() % (maxkeysize + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2928) generate_random_bytes((u8 *)vec->key, vec->klen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2929) vec->setkey_error = crypto_skcipher_setkey(tfm, vec->key, vec->klen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2930)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2931) /* IV */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2932) generate_random_bytes((u8 *)vec->iv, ivsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2933)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2934) /* Plaintext */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2935) vec->len = generate_random_length(maxdatasize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2936) generate_random_bytes((u8 *)vec->ptext, vec->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2937)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2938) /* If the key couldn't be set, no need to continue to encrypt. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2939) if (vec->setkey_error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2940) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2941)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2942) /* Ciphertext */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2943) sg_init_one(&src, vec->ptext, vec->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2944) sg_init_one(&dst, vec->ctext, vec->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2945) memcpy(iv, vec->iv, ivsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2946) skcipher_request_set_callback(req, 0, crypto_req_done, &wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2947) skcipher_request_set_crypt(req, &src, &dst, vec->len, iv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2948) vec->crypt_error = crypto_wait_req(crypto_skcipher_encrypt(req), &wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2949) if (vec->crypt_error != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2950) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2951) * The only acceptable error here is for an invalid length, so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2952) * skcipher decryption should fail with the same error too.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2953) * We'll test for this. But to keep the API usage well-defined,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2954) * explicitly initialize the ciphertext buffer too.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2955) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2956) memset((u8 *)vec->ctext, 0, vec->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2957) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2958) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2959) snprintf(name, max_namelen, "\"random: len=%u klen=%u\"",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2960) vec->len, vec->klen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2961) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2962)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2963) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2964) * Test the skcipher algorithm represented by @req against the corresponding
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2965) * generic implementation, if one is available.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2966) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2967) static int test_skcipher_vs_generic_impl(const char *driver,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2968) const char *generic_driver,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2969) struct skcipher_request *req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2970) struct cipher_test_sglists *tsgls)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2971) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2972) struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2973) const unsigned int maxkeysize = crypto_skcipher_max_keysize(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2974) const unsigned int ivsize = crypto_skcipher_ivsize(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2975) const unsigned int blocksize = crypto_skcipher_blocksize(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2976) const unsigned int maxdatasize = (2 * PAGE_SIZE) - TESTMGR_POISON_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2977) const char *algname = crypto_skcipher_alg(tfm)->base.cra_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2978) char _generic_driver[CRYPTO_MAX_ALG_NAME];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2979) struct crypto_skcipher *generic_tfm = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2980) struct skcipher_request *generic_req = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2981) unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2982) struct cipher_testvec vec = { 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2983) char vec_name[64];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2984) struct testvec_config *cfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2985) char cfgname[TESTVEC_CONFIG_NAMELEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2986) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2987)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2988) if (noextratests)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2989) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2990)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2991) /* Keywrap isn't supported here yet as it handles its IV differently. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2992) if (strncmp(algname, "kw(", 3) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2993) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2994)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2995) if (!generic_driver) { /* Use default naming convention? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2996) err = build_generic_driver_name(algname, _generic_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2997) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2998) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2999) generic_driver = _generic_driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3000) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3001)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3002) if (strcmp(generic_driver, driver) == 0) /* Already the generic impl? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3003) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3004)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3005) generic_tfm = crypto_alloc_skcipher(generic_driver, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3006) if (IS_ERR(generic_tfm)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3007) err = PTR_ERR(generic_tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3008) if (err == -ENOENT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3009) pr_warn("alg: skcipher: skipping comparison tests for %s because %s is unavailable\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3010) driver, generic_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3011) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3012) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3013) pr_err("alg: skcipher: error allocating %s (generic impl of %s): %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3014) generic_driver, algname, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3015) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3016) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3017)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3018) cfg = kzalloc(sizeof(*cfg), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3019) if (!cfg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3020) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3021) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3022) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3023)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3024) generic_req = skcipher_request_alloc(generic_tfm, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3025) if (!generic_req) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3026) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3027) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3028) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3029)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3030) /* Check the algorithm properties for consistency. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3031)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3032) if (crypto_skcipher_min_keysize(tfm) !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3033) crypto_skcipher_min_keysize(generic_tfm)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3034) pr_err("alg: skcipher: min keysize for %s (%u) doesn't match generic impl (%u)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3035) driver, crypto_skcipher_min_keysize(tfm),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3036) crypto_skcipher_min_keysize(generic_tfm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3037) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3038) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3039) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3040)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3041) if (maxkeysize != crypto_skcipher_max_keysize(generic_tfm)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3042) pr_err("alg: skcipher: max keysize for %s (%u) doesn't match generic impl (%u)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3043) driver, maxkeysize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3044) crypto_skcipher_max_keysize(generic_tfm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3045) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3046) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3047) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3048)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3049) if (ivsize != crypto_skcipher_ivsize(generic_tfm)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3050) pr_err("alg: skcipher: ivsize for %s (%u) doesn't match generic impl (%u)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3051) driver, ivsize, crypto_skcipher_ivsize(generic_tfm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3052) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3053) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3054) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3055)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3056) if (blocksize != crypto_skcipher_blocksize(generic_tfm)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3057) pr_err("alg: skcipher: blocksize for %s (%u) doesn't match generic impl (%u)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3058) driver, blocksize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3059) crypto_skcipher_blocksize(generic_tfm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3060) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3061) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3062) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3063)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3064) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3065) * Now generate test vectors using the generic implementation, and test
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3066) * the other implementation against them.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3067) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3068)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3069) vec.key = kmalloc(maxkeysize, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3070) vec.iv = kmalloc(ivsize, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3071) vec.ptext = kmalloc(maxdatasize, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3072) vec.ctext = kmalloc(maxdatasize, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3073) if (!vec.key || !vec.iv || !vec.ptext || !vec.ctext) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3074) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3075) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3076) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3077)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3078) for (i = 0; i < fuzz_iterations * 8; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3079) generate_random_cipher_testvec(generic_req, &vec, maxdatasize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3080) vec_name, sizeof(vec_name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3081) generate_random_testvec_config(cfg, cfgname, sizeof(cfgname));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3082)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3083) err = test_skcipher_vec_cfg(driver, ENCRYPT, &vec, vec_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3084) cfg, req, tsgls);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3085) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3086) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3087) err = test_skcipher_vec_cfg(driver, DECRYPT, &vec, vec_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3088) cfg, req, tsgls);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3089) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3090) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3091) cond_resched();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3092) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3093) err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3094) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3095) kfree(cfg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3096) kfree(vec.key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3097) kfree(vec.iv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3098) kfree(vec.ptext);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3099) kfree(vec.ctext);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3100) crypto_free_skcipher(generic_tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3101) skcipher_request_free(generic_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3102) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3104) #else /* !CONFIG_CRYPTO_MANAGER_EXTRA_TESTS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3105) static int test_skcipher_vs_generic_impl(const char *driver,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3106) const char *generic_driver,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3107) struct skcipher_request *req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3108) struct cipher_test_sglists *tsgls)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3109) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3110) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3112) #endif /* !CONFIG_CRYPTO_MANAGER_EXTRA_TESTS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3114) static int test_skcipher(const char *driver, int enc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3115) const struct cipher_test_suite *suite,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3116) struct skcipher_request *req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3117) struct cipher_test_sglists *tsgls)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3118) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3119) unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3120) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3122) for (i = 0; i < suite->count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3123) err = test_skcipher_vec(driver, enc, &suite->vecs[i], i, req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3124) tsgls);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3125) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3126) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3127) cond_resched();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3129) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3130) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3132) static int alg_test_skcipher(const struct alg_test_desc *desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3133) const char *driver, u32 type, u32 mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3134) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3135) const struct cipher_test_suite *suite = &desc->suite.cipher;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3136) struct crypto_skcipher *tfm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3137) struct skcipher_request *req = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3138) struct cipher_test_sglists *tsgls = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3139) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3141) if (suite->count <= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3142) pr_err("alg: skcipher: empty test suite for %s\n", driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3143) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3144) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3146) tfm = crypto_alloc_skcipher(driver, type, mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3147) if (IS_ERR(tfm)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3148) pr_err("alg: skcipher: failed to allocate transform for %s: %ld\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3149) driver, PTR_ERR(tfm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3150) return PTR_ERR(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3151) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3153) req = skcipher_request_alloc(tfm, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3154) if (!req) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3155) pr_err("alg: skcipher: failed to allocate request for %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3156) driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3157) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3158) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3161) tsgls = alloc_cipher_test_sglists();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3162) if (!tsgls) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3163) pr_err("alg: skcipher: failed to allocate test buffers for %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3164) driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3165) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3166) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3167) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3169) err = test_skcipher(driver, ENCRYPT, suite, req, tsgls);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3170) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3171) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3173) err = test_skcipher(driver, DECRYPT, suite, req, tsgls);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3174) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3175) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3177) err = test_skcipher_vs_generic_impl(driver, desc->generic_driver, req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3178) tsgls);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3179) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3180) free_cipher_test_sglists(tsgls);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3181) skcipher_request_free(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3182) crypto_free_skcipher(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3183) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3184) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3186) static int test_comp(struct crypto_comp *tfm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3187) const struct comp_testvec *ctemplate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3188) const struct comp_testvec *dtemplate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3189) int ctcount, int dtcount)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3190) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3191) const char *algo = crypto_tfm_alg_driver_name(crypto_comp_tfm(tfm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3192) char *output, *decomp_output;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3193) unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3194) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3196) output = kmalloc(COMP_BUF_SIZE, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3197) if (!output)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3198) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3200) decomp_output = kmalloc(COMP_BUF_SIZE, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3201) if (!decomp_output) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3202) kfree(output);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3203) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3204) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3206) for (i = 0; i < ctcount; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3207) int ilen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3208) unsigned int dlen = COMP_BUF_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3210) memset(output, 0, COMP_BUF_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3211) memset(decomp_output, 0, COMP_BUF_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3213) ilen = ctemplate[i].inlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3214) ret = crypto_comp_compress(tfm, ctemplate[i].input,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3215) ilen, output, &dlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3216) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3217) printk(KERN_ERR "alg: comp: compression failed "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3218) "on test %d for %s: ret=%d\n", i + 1, algo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3219) -ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3220) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3221) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3223) ilen = dlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3224) dlen = COMP_BUF_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3225) ret = crypto_comp_decompress(tfm, output,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3226) ilen, decomp_output, &dlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3227) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3228) pr_err("alg: comp: compression failed: decompress: on test %d for %s failed: ret=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3229) i + 1, algo, -ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3230) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3231) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3233) if (dlen != ctemplate[i].inlen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3234) printk(KERN_ERR "alg: comp: Compression test %d "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3235) "failed for %s: output len = %d\n", i + 1, algo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3236) dlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3237) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3238) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3239) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3241) if (memcmp(decomp_output, ctemplate[i].input,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3242) ctemplate[i].inlen)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3243) pr_err("alg: comp: compression failed: output differs: on test %d for %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3244) i + 1, algo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3245) hexdump(decomp_output, dlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3246) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3247) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3248) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3249) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3251) for (i = 0; i < dtcount; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3252) int ilen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3253) unsigned int dlen = COMP_BUF_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3255) memset(decomp_output, 0, COMP_BUF_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3257) ilen = dtemplate[i].inlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3258) ret = crypto_comp_decompress(tfm, dtemplate[i].input,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3259) ilen, decomp_output, &dlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3260) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3261) printk(KERN_ERR "alg: comp: decompression failed "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3262) "on test %d for %s: ret=%d\n", i + 1, algo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3263) -ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3264) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3265) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3267) if (dlen != dtemplate[i].outlen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3268) printk(KERN_ERR "alg: comp: Decompression test %d "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3269) "failed for %s: output len = %d\n", i + 1, algo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3270) dlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3271) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3272) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3273) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3275) if (memcmp(decomp_output, dtemplate[i].output, dlen)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3276) printk(KERN_ERR "alg: comp: Decompression test %d "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3277) "failed for %s\n", i + 1, algo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3278) hexdump(decomp_output, dlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3279) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3280) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3281) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3282) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3283)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3284) ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3286) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3287) kfree(decomp_output);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3288) kfree(output);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3289) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3290) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3292) static int test_acomp(struct crypto_acomp *tfm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3293) const struct comp_testvec *ctemplate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3294) const struct comp_testvec *dtemplate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3295) int ctcount, int dtcount)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3296) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3297) const char *algo = crypto_tfm_alg_driver_name(crypto_acomp_tfm(tfm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3298) unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3299) char *output, *decomp_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3300) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3301) struct scatterlist src, dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3302) struct acomp_req *req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3303) struct crypto_wait wait;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3305) output = kmalloc(COMP_BUF_SIZE, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3306) if (!output)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3307) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3309) decomp_out = kmalloc(COMP_BUF_SIZE, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3310) if (!decomp_out) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3311) kfree(output);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3312) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3313) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3314)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3315) for (i = 0; i < ctcount; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3316) unsigned int dlen = COMP_BUF_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3317) int ilen = ctemplate[i].inlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3318) void *input_vec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3319)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3320) input_vec = kmemdup(ctemplate[i].input, ilen, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3321) if (!input_vec) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3322) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3323) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3324) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3325)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3326) memset(output, 0, dlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3327) crypto_init_wait(&wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3328) sg_init_one(&src, input_vec, ilen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3329) sg_init_one(&dst, output, dlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3331) req = acomp_request_alloc(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3332) if (!req) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3333) pr_err("alg: acomp: request alloc failed for %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3334) algo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3335) kfree(input_vec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3336) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3337) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3338) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3339)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3340) acomp_request_set_params(req, &src, &dst, ilen, dlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3341) acomp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3342) crypto_req_done, &wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3343)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3344) ret = crypto_wait_req(crypto_acomp_compress(req), &wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3345) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3346) pr_err("alg: acomp: compression failed on test %d for %s: ret=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3347) i + 1, algo, -ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3348) kfree(input_vec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3349) acomp_request_free(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3350) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3351) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3352)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3353) ilen = req->dlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3354) dlen = COMP_BUF_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3355) sg_init_one(&src, output, ilen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3356) sg_init_one(&dst, decomp_out, dlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3357) crypto_init_wait(&wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3358) acomp_request_set_params(req, &src, &dst, ilen, dlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3359)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3360) ret = crypto_wait_req(crypto_acomp_decompress(req), &wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3361) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3362) pr_err("alg: acomp: compression failed on test %d for %s: ret=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3363) i + 1, algo, -ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3364) kfree(input_vec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3365) acomp_request_free(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3366) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3367) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3368)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3369) if (req->dlen != ctemplate[i].inlen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3370) pr_err("alg: acomp: Compression test %d failed for %s: output len = %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3371) i + 1, algo, req->dlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3372) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3373) kfree(input_vec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3374) acomp_request_free(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3375) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3376) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3377)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3378) if (memcmp(input_vec, decomp_out, req->dlen)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3379) pr_err("alg: acomp: Compression test %d failed for %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3380) i + 1, algo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3381) hexdump(output, req->dlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3382) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3383) kfree(input_vec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3384) acomp_request_free(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3385) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3386) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3387)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3388) kfree(input_vec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3389) acomp_request_free(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3390) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3391)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3392) for (i = 0; i < dtcount; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3393) unsigned int dlen = COMP_BUF_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3394) int ilen = dtemplate[i].inlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3395) void *input_vec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3396)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3397) input_vec = kmemdup(dtemplate[i].input, ilen, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3398) if (!input_vec) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3399) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3400) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3401) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3402)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3403) memset(output, 0, dlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3404) crypto_init_wait(&wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3405) sg_init_one(&src, input_vec, ilen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3406) sg_init_one(&dst, output, dlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3407)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3408) req = acomp_request_alloc(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3409) if (!req) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3410) pr_err("alg: acomp: request alloc failed for %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3411) algo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3412) kfree(input_vec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3413) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3414) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3415) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3416)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3417) acomp_request_set_params(req, &src, &dst, ilen, dlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3418) acomp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3419) crypto_req_done, &wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3420)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3421) ret = crypto_wait_req(crypto_acomp_decompress(req), &wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3422) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3423) pr_err("alg: acomp: decompression failed on test %d for %s: ret=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3424) i + 1, algo, -ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3425) kfree(input_vec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3426) acomp_request_free(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3427) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3428) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3429)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3430) if (req->dlen != dtemplate[i].outlen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3431) pr_err("alg: acomp: Decompression test %d failed for %s: output len = %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3432) i + 1, algo, req->dlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3433) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3434) kfree(input_vec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3435) acomp_request_free(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3436) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3437) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3438)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3439) if (memcmp(output, dtemplate[i].output, req->dlen)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3440) pr_err("alg: acomp: Decompression test %d failed for %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3441) i + 1, algo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3442) hexdump(output, req->dlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3443) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3444) kfree(input_vec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3445) acomp_request_free(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3446) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3447) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3448)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3449) kfree(input_vec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3450) acomp_request_free(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3451) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3452)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3453) ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3454)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3455) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3456) kfree(decomp_out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3457) kfree(output);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3458) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3459) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3460)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3461) static int test_cprng(struct crypto_rng *tfm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3462) const struct cprng_testvec *template,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3463) unsigned int tcount)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3464) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3465) const char *algo = crypto_tfm_alg_driver_name(crypto_rng_tfm(tfm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3466) int err = 0, i, j, seedsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3467) u8 *seed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3468) char result[32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3469)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3470) seedsize = crypto_rng_seedsize(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3471)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3472) seed = kmalloc(seedsize, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3473) if (!seed) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3474) printk(KERN_ERR "alg: cprng: Failed to allocate seed space "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3475) "for %s\n", algo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3476) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3477) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3478)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3479) for (i = 0; i < tcount; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3480) memset(result, 0, 32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3481)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3482) memcpy(seed, template[i].v, template[i].vlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3483) memcpy(seed + template[i].vlen, template[i].key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3484) template[i].klen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3485) memcpy(seed + template[i].vlen + template[i].klen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3486) template[i].dt, template[i].dtlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3487)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3488) err = crypto_rng_reset(tfm, seed, seedsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3489) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3490) printk(KERN_ERR "alg: cprng: Failed to reset rng "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3491) "for %s\n", algo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3492) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3493) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3494)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3495) for (j = 0; j < template[i].loops; j++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3496) err = crypto_rng_get_bytes(tfm, result,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3497) template[i].rlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3498) if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3499) printk(KERN_ERR "alg: cprng: Failed to obtain "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3500) "the correct amount of random data for "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3501) "%s (requested %d)\n", algo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3502) template[i].rlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3503) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3504) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3505) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3506)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3507) err = memcmp(result, template[i].result,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3508) template[i].rlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3509) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3510) printk(KERN_ERR "alg: cprng: Test %d failed for %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3511) i, algo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3512) hexdump(result, template[i].rlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3513) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3514) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3515) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3516) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3517)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3518) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3519) kfree(seed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3520) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3521) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3522)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3523) static int alg_test_cipher(const struct alg_test_desc *desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3524) const char *driver, u32 type, u32 mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3525) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3526) const struct cipher_test_suite *suite = &desc->suite.cipher;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3527) struct crypto_cipher *tfm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3528) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3529)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3530) tfm = crypto_alloc_cipher(driver, type, mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3531) if (IS_ERR(tfm)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3532) printk(KERN_ERR "alg: cipher: Failed to load transform for "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3533) "%s: %ld\n", driver, PTR_ERR(tfm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3534) return PTR_ERR(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3535) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3536)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3537) err = test_cipher(tfm, ENCRYPT, suite->vecs, suite->count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3538) if (!err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3539) err = test_cipher(tfm, DECRYPT, suite->vecs, suite->count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3540)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3541) crypto_free_cipher(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3542) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3543) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3544)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3545) static int alg_test_comp(const struct alg_test_desc *desc, const char *driver,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3546) u32 type, u32 mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3547) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3548) struct crypto_comp *comp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3549) struct crypto_acomp *acomp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3550) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3551) u32 algo_type = type & CRYPTO_ALG_TYPE_ACOMPRESS_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3552)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3553) if (algo_type == CRYPTO_ALG_TYPE_ACOMPRESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3554) acomp = crypto_alloc_acomp(driver, type, mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3555) if (IS_ERR(acomp)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3556) pr_err("alg: acomp: Failed to load transform for %s: %ld\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3557) driver, PTR_ERR(acomp));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3558) return PTR_ERR(acomp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3559) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3560) err = test_acomp(acomp, desc->suite.comp.comp.vecs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3561) desc->suite.comp.decomp.vecs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3562) desc->suite.comp.comp.count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3563) desc->suite.comp.decomp.count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3564) crypto_free_acomp(acomp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3565) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3566) comp = crypto_alloc_comp(driver, type, mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3567) if (IS_ERR(comp)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3568) pr_err("alg: comp: Failed to load transform for %s: %ld\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3569) driver, PTR_ERR(comp));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3570) return PTR_ERR(comp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3571) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3572)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3573) err = test_comp(comp, desc->suite.comp.comp.vecs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3574) desc->suite.comp.decomp.vecs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3575) desc->suite.comp.comp.count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3576) desc->suite.comp.decomp.count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3577)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3578) crypto_free_comp(comp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3579) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3580) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3581) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3582)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3583) static int alg_test_crc32c(const struct alg_test_desc *desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3584) const char *driver, u32 type, u32 mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3585) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3586) struct crypto_shash *tfm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3587) __le32 val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3588) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3589)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3590) err = alg_test_hash(desc, driver, type, mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3591) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3592) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3593)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3594) tfm = crypto_alloc_shash(driver, type, mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3595) if (IS_ERR(tfm)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3596) if (PTR_ERR(tfm) == -ENOENT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3597) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3598) * This crc32c implementation is only available through
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3599) * ahash API, not the shash API, so the remaining part
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3600) * of the test is not applicable to it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3601) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3602) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3603) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3604) printk(KERN_ERR "alg: crc32c: Failed to load transform for %s: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3605) "%ld\n", driver, PTR_ERR(tfm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3606) return PTR_ERR(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3607) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3608)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3609) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3610) SHASH_DESC_ON_STACK(shash, tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3611) u32 *ctx = (u32 *)shash_desc_ctx(shash);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3612)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3613) shash->tfm = tfm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3614)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3615) *ctx = 420553207;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3616) err = crypto_shash_final(shash, (u8 *)&val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3617) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3618) printk(KERN_ERR "alg: crc32c: Operation failed for "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3619) "%s: %d\n", driver, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3620) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3621) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3622)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3623) if (val != cpu_to_le32(~420553207)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3624) pr_err("alg: crc32c: Test failed for %s: %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3625) driver, le32_to_cpu(val));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3626) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3627) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3628) } while (0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3629)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3630) crypto_free_shash(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3631)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3632) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3633) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3634)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3635) static int alg_test_cprng(const struct alg_test_desc *desc, const char *driver,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3636) u32 type, u32 mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3637) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3638) struct crypto_rng *rng;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3639) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3640)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3641) rng = crypto_alloc_rng(driver, type, mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3642) if (IS_ERR(rng)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3643) printk(KERN_ERR "alg: cprng: Failed to load transform for %s: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3644) "%ld\n", driver, PTR_ERR(rng));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3645) return PTR_ERR(rng);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3646) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3647)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3648) err = test_cprng(rng, desc->suite.cprng.vecs, desc->suite.cprng.count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3649)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3650) crypto_free_rng(rng);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3651)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3652) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3653) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3654)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3655)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3656) static int drbg_cavs_test(const struct drbg_testvec *test, int pr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3657) const char *driver, u32 type, u32 mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3658) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3659) int ret = -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3660) struct crypto_rng *drng;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3661) struct drbg_test_data test_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3662) struct drbg_string addtl, pers, testentropy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3663) unsigned char *buf = kzalloc(test->expectedlen, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3664)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3665) if (!buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3666) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3667)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3668) drng = crypto_alloc_rng(driver, type, mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3669) if (IS_ERR(drng)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3670) printk(KERN_ERR "alg: drbg: could not allocate DRNG handle for "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3671) "%s\n", driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3672) kfree_sensitive(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3673) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3674) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3675)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3676) test_data.testentropy = &testentropy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3677) drbg_string_fill(&testentropy, test->entropy, test->entropylen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3678) drbg_string_fill(&pers, test->pers, test->perslen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3679) ret = crypto_drbg_reset_test(drng, &pers, &test_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3680) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3681) printk(KERN_ERR "alg: drbg: Failed to reset rng\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3682) goto outbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3683) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3684)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3685) drbg_string_fill(&addtl, test->addtla, test->addtllen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3686) if (pr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3687) drbg_string_fill(&testentropy, test->entpra, test->entprlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3688) ret = crypto_drbg_get_bytes_addtl_test(drng,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3689) buf, test->expectedlen, &addtl, &test_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3690) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3691) ret = crypto_drbg_get_bytes_addtl(drng,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3692) buf, test->expectedlen, &addtl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3693) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3694) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3695) printk(KERN_ERR "alg: drbg: could not obtain random data for "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3696) "driver %s\n", driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3697) goto outbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3698) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3699)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3700) drbg_string_fill(&addtl, test->addtlb, test->addtllen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3701) if (pr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3702) drbg_string_fill(&testentropy, test->entprb, test->entprlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3703) ret = crypto_drbg_get_bytes_addtl_test(drng,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3704) buf, test->expectedlen, &addtl, &test_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3705) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3706) ret = crypto_drbg_get_bytes_addtl(drng,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3707) buf, test->expectedlen, &addtl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3708) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3709) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3710) printk(KERN_ERR "alg: drbg: could not obtain random data for "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3711) "driver %s\n", driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3712) goto outbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3713) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3714)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3715) ret = memcmp(test->expected, buf, test->expectedlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3716)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3717) outbuf:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3718) crypto_free_rng(drng);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3719) kfree_sensitive(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3720) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3721) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3722)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3723)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3724) static int alg_test_drbg(const struct alg_test_desc *desc, const char *driver,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3725) u32 type, u32 mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3726) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3727) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3728) int pr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3729) int i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3730) const struct drbg_testvec *template = desc->suite.drbg.vecs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3731) unsigned int tcount = desc->suite.drbg.count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3732)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3733) if (0 == memcmp(driver, "drbg_pr_", 8))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3734) pr = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3735)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3736) for (i = 0; i < tcount; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3737) err = drbg_cavs_test(&template[i], pr, driver, type, mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3738) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3739) printk(KERN_ERR "alg: drbg: Test %d failed for %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3740) i, driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3741) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3742) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3743) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3744) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3745) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3746)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3747) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3748)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3749) static int do_test_kpp(struct crypto_kpp *tfm, const struct kpp_testvec *vec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3750) const char *alg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3751) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3752) struct kpp_request *req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3753) void *input_buf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3754) void *output_buf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3755) void *a_public = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3756) void *a_ss = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3757) void *shared_secret = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3758) struct crypto_wait wait;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3759) unsigned int out_len_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3760) int err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3761) struct scatterlist src, dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3762)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3763) req = kpp_request_alloc(tfm, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3764) if (!req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3765) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3766)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3767) crypto_init_wait(&wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3768)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3769) err = crypto_kpp_set_secret(tfm, vec->secret, vec->secret_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3770) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3771) goto free_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3772)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3773) out_len_max = crypto_kpp_maxsize(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3774) output_buf = kzalloc(out_len_max, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3775) if (!output_buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3776) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3777) goto free_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3778) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3779)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3780) /* Use appropriate parameter as base */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3781) kpp_request_set_input(req, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3782) sg_init_one(&dst, output_buf, out_len_max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3783) kpp_request_set_output(req, &dst, out_len_max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3784) kpp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3785) crypto_req_done, &wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3786)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3787) /* Compute party A's public key */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3788) err = crypto_wait_req(crypto_kpp_generate_public_key(req), &wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3789) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3790) pr_err("alg: %s: Party A: generate public key test failed. err %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3791) alg, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3792) goto free_output;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3793) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3794)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3795) if (vec->genkey) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3796) /* Save party A's public key */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3797) a_public = kmemdup(sg_virt(req->dst), out_len_max, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3798) if (!a_public) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3799) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3800) goto free_output;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3801) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3802) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3803) /* Verify calculated public key */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3804) if (memcmp(vec->expected_a_public, sg_virt(req->dst),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3805) vec->expected_a_public_size)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3806) pr_err("alg: %s: Party A: generate public key test failed. Invalid output\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3807) alg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3808) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3809) goto free_output;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3810) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3811) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3812)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3813) /* Calculate shared secret key by using counter part (b) public key. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3814) input_buf = kmemdup(vec->b_public, vec->b_public_size, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3815) if (!input_buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3816) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3817) goto free_output;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3818) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3819)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3820) sg_init_one(&src, input_buf, vec->b_public_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3821) sg_init_one(&dst, output_buf, out_len_max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3822) kpp_request_set_input(req, &src, vec->b_public_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3823) kpp_request_set_output(req, &dst, out_len_max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3824) kpp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3825) crypto_req_done, &wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3826) err = crypto_wait_req(crypto_kpp_compute_shared_secret(req), &wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3827) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3828) pr_err("alg: %s: Party A: compute shared secret test failed. err %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3829) alg, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3830) goto free_all;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3831) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3832)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3833) if (vec->genkey) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3834) /* Save the shared secret obtained by party A */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3835) a_ss = kmemdup(sg_virt(req->dst), vec->expected_ss_size, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3836) if (!a_ss) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3837) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3838) goto free_all;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3839) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3840)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3841) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3842) * Calculate party B's shared secret by using party A's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3843) * public key.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3844) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3845) err = crypto_kpp_set_secret(tfm, vec->b_secret,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3846) vec->b_secret_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3847) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3848) goto free_all;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3849)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3850) sg_init_one(&src, a_public, vec->expected_a_public_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3851) sg_init_one(&dst, output_buf, out_len_max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3852) kpp_request_set_input(req, &src, vec->expected_a_public_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3853) kpp_request_set_output(req, &dst, out_len_max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3854) kpp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3855) crypto_req_done, &wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3856) err = crypto_wait_req(crypto_kpp_compute_shared_secret(req),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3857) &wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3858) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3859) pr_err("alg: %s: Party B: compute shared secret failed. err %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3860) alg, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3861) goto free_all;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3862) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3863)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3864) shared_secret = a_ss;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3865) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3866) shared_secret = (void *)vec->expected_ss;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3867) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3868)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3869) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3870) * verify shared secret from which the user will derive
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3871) * secret key by executing whatever hash it has chosen
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3872) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3873) if (memcmp(shared_secret, sg_virt(req->dst),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3874) vec->expected_ss_size)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3875) pr_err("alg: %s: compute shared secret test failed. Invalid output\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3876) alg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3877) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3878) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3879)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3880) free_all:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3881) kfree(a_ss);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3882) kfree(input_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3883) free_output:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3884) kfree(a_public);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3885) kfree(output_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3886) free_req:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3887) kpp_request_free(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3888) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3889) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3890)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3891) static int test_kpp(struct crypto_kpp *tfm, const char *alg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3892) const struct kpp_testvec *vecs, unsigned int tcount)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3893) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3894) int ret, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3895)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3896) for (i = 0; i < tcount; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3897) ret = do_test_kpp(tfm, vecs++, alg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3898) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3899) pr_err("alg: %s: test failed on vector %d, err=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3900) alg, i + 1, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3901) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3902) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3903) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3904) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3905) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3906)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3907) static int alg_test_kpp(const struct alg_test_desc *desc, const char *driver,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3908) u32 type, u32 mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3909) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3910) struct crypto_kpp *tfm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3911) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3912)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3913) tfm = crypto_alloc_kpp(driver, type, mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3914) if (IS_ERR(tfm)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3915) pr_err("alg: kpp: Failed to load tfm for %s: %ld\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3916) driver, PTR_ERR(tfm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3917) return PTR_ERR(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3918) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3919) if (desc->suite.kpp.vecs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3920) err = test_kpp(tfm, desc->alg, desc->suite.kpp.vecs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3921) desc->suite.kpp.count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3922)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3923) crypto_free_kpp(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3924) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3925) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3926)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3927) static u8 *test_pack_u32(u8 *dst, u32 val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3928) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3929) memcpy(dst, &val, sizeof(val));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3930) return dst + sizeof(val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3931) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3932)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3933) static int test_akcipher_one(struct crypto_akcipher *tfm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3934) const struct akcipher_testvec *vecs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3935) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3936) char *xbuf[XBUFSIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3937) struct akcipher_request *req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3938) void *outbuf_enc = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3939) void *outbuf_dec = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3940) struct crypto_wait wait;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3941) unsigned int out_len_max, out_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3942) int err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3943) struct scatterlist src, dst, src_tab[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3944) const char *m, *c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3945) unsigned int m_size, c_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3946) const char *op;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3947) u8 *key, *ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3948)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3949) if (testmgr_alloc_buf(xbuf))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3950) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3951)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3952) req = akcipher_request_alloc(tfm, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3953) if (!req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3954) goto free_xbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3955)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3956) crypto_init_wait(&wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3957)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3958) key = kmalloc(vecs->key_len + sizeof(u32) * 2 + vecs->param_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3959) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3960) if (!key)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3961) goto free_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3962) memcpy(key, vecs->key, vecs->key_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3963) ptr = key + vecs->key_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3964) ptr = test_pack_u32(ptr, vecs->algo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3965) ptr = test_pack_u32(ptr, vecs->param_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3966) memcpy(ptr, vecs->params, vecs->param_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3967)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3968) if (vecs->public_key_vec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3969) err = crypto_akcipher_set_pub_key(tfm, key, vecs->key_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3970) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3971) err = crypto_akcipher_set_priv_key(tfm, key, vecs->key_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3972) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3973) goto free_key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3974)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3975) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3976) * First run test which do not require a private key, such as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3977) * encrypt or verify.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3978) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3979) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3980) out_len_max = crypto_akcipher_maxsize(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3981) outbuf_enc = kzalloc(out_len_max, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3982) if (!outbuf_enc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3983) goto free_key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3984)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3985) if (!vecs->siggen_sigver_test) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3986) m = vecs->m;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3987) m_size = vecs->m_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3988) c = vecs->c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3989) c_size = vecs->c_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3990) op = "encrypt";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3991) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3992) /* Swap args so we could keep plaintext (digest)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3993) * in vecs->m, and cooked signature in vecs->c.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3994) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3995) m = vecs->c; /* signature */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3996) m_size = vecs->c_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3997) c = vecs->m; /* digest */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3998) c_size = vecs->m_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3999) op = "verify";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4000) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4001)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4002) err = -E2BIG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4003) if (WARN_ON(m_size > PAGE_SIZE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4004) goto free_all;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4005) memcpy(xbuf[0], m, m_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4006)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4007) sg_init_table(src_tab, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4008) sg_set_buf(&src_tab[0], xbuf[0], 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4009) sg_set_buf(&src_tab[1], xbuf[0] + 8, m_size - 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4010) if (vecs->siggen_sigver_test) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4011) if (WARN_ON(c_size > PAGE_SIZE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4012) goto free_all;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4013) memcpy(xbuf[1], c, c_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4014) sg_set_buf(&src_tab[2], xbuf[1], c_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4015) akcipher_request_set_crypt(req, src_tab, NULL, m_size, c_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4016) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4017) sg_init_one(&dst, outbuf_enc, out_len_max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4018) akcipher_request_set_crypt(req, src_tab, &dst, m_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4019) out_len_max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4020) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4021) akcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4022) crypto_req_done, &wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4023)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4024) err = crypto_wait_req(vecs->siggen_sigver_test ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4025) /* Run asymmetric signature verification */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4026) crypto_akcipher_verify(req) :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4027) /* Run asymmetric encrypt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4028) crypto_akcipher_encrypt(req), &wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4029) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4030) pr_err("alg: akcipher: %s test failed. err %d\n", op, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4031) goto free_all;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4032) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4033) if (!vecs->siggen_sigver_test && c) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4034) if (req->dst_len != c_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4035) pr_err("alg: akcipher: %s test failed. Invalid output len\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4036) op);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4037) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4038) goto free_all;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4039) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4040) /* verify that encrypted message is equal to expected */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4041) if (memcmp(c, outbuf_enc, c_size) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4042) pr_err("alg: akcipher: %s test failed. Invalid output\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4043) op);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4044) hexdump(outbuf_enc, c_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4045) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4046) goto free_all;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4047) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4048) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4049)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4050) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4051) * Don't invoke (decrypt or sign) test which require a private key
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4052) * for vectors with only a public key.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4053) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4054) if (vecs->public_key_vec) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4055) err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4056) goto free_all;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4057) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4058) outbuf_dec = kzalloc(out_len_max, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4059) if (!outbuf_dec) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4060) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4061) goto free_all;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4062) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4063)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4064) if (!vecs->siggen_sigver_test && !c) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4065) c = outbuf_enc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4066) c_size = req->dst_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4067) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4068)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4069) err = -E2BIG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4070) op = vecs->siggen_sigver_test ? "sign" : "decrypt";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4071) if (WARN_ON(c_size > PAGE_SIZE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4072) goto free_all;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4073) memcpy(xbuf[0], c, c_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4074)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4075) sg_init_one(&src, xbuf[0], c_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4076) sg_init_one(&dst, outbuf_dec, out_len_max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4077) crypto_init_wait(&wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4078) akcipher_request_set_crypt(req, &src, &dst, c_size, out_len_max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4079)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4080) err = crypto_wait_req(vecs->siggen_sigver_test ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4081) /* Run asymmetric signature generation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4082) crypto_akcipher_sign(req) :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4083) /* Run asymmetric decrypt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4084) crypto_akcipher_decrypt(req), &wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4085) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4086) pr_err("alg: akcipher: %s test failed. err %d\n", op, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4087) goto free_all;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4088) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4089) out_len = req->dst_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4090) if (out_len < m_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4091) pr_err("alg: akcipher: %s test failed. Invalid output len %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4092) op, out_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4093) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4094) goto free_all;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4095) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4096) /* verify that decrypted message is equal to the original msg */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4097) if (memchr_inv(outbuf_dec, 0, out_len - m_size) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4098) memcmp(m, outbuf_dec + out_len - m_size, m_size)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4099) pr_err("alg: akcipher: %s test failed. Invalid output\n", op);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4100) hexdump(outbuf_dec, out_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4101) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4103) free_all:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4104) kfree(outbuf_dec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4105) kfree(outbuf_enc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4106) free_key:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4107) kfree(key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4108) free_req:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4109) akcipher_request_free(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4110) free_xbuf:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4111) testmgr_free_buf(xbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4112) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4115) static int test_akcipher(struct crypto_akcipher *tfm, const char *alg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4116) const struct akcipher_testvec *vecs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4117) unsigned int tcount)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4118) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4119) const char *algo =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4120) crypto_tfm_alg_driver_name(crypto_akcipher_tfm(tfm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4121) int ret, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4123) for (i = 0; i < tcount; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4124) ret = test_akcipher_one(tfm, vecs++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4125) if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4126) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4128) pr_err("alg: akcipher: test %d failed for %s, err=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4129) i + 1, algo, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4130) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4131) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4132) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4133) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4135) static int alg_test_akcipher(const struct alg_test_desc *desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4136) const char *driver, u32 type, u32 mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4137) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4138) struct crypto_akcipher *tfm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4139) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4141) tfm = crypto_alloc_akcipher(driver, type, mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4142) if (IS_ERR(tfm)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4143) pr_err("alg: akcipher: Failed to load tfm for %s: %ld\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4144) driver, PTR_ERR(tfm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4145) return PTR_ERR(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4147) if (desc->suite.akcipher.vecs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4148) err = test_akcipher(tfm, desc->alg, desc->suite.akcipher.vecs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4149) desc->suite.akcipher.count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4151) crypto_free_akcipher(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4152) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4153) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4155) static int alg_test_null(const struct alg_test_desc *desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4156) const char *driver, u32 type, u32 mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4157) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4158) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4161) #define ____VECS(tv) .vecs = tv, .count = ARRAY_SIZE(tv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4162) #define __VECS(tv) { ____VECS(tv) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4164) /* Please keep this list sorted by algorithm name. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4165) static const struct alg_test_desc alg_test_descs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4166) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4167) .alg = "adiantum(xchacha12,aes)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4168) .generic_driver = "adiantum(xchacha12-generic,aes-generic,nhpoly1305-generic)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4169) .test = alg_test_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4170) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4171) .cipher = __VECS(adiantum_xchacha12_aes_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4172) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4173) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4174) .alg = "adiantum(xchacha20,aes)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4175) .generic_driver = "adiantum(xchacha20-generic,aes-generic,nhpoly1305-generic)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4176) .test = alg_test_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4177) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4178) .cipher = __VECS(adiantum_xchacha20_aes_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4179) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4180) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4181) .alg = "aegis128",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4182) .test = alg_test_aead,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4183) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4184) .aead = __VECS(aegis128_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4186) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4187) .alg = "ansi_cprng",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4188) .test = alg_test_cprng,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4189) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4190) .cprng = __VECS(ansi_cprng_aes_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4191) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4192) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4193) .alg = "authenc(hmac(md5),ecb(cipher_null))",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4194) .test = alg_test_aead,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4195) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4196) .aead = __VECS(hmac_md5_ecb_cipher_null_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4197) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4198) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4199) .alg = "authenc(hmac(sha1),cbc(aes))",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4200) .test = alg_test_aead,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4201) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4202) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4203) .aead = __VECS(hmac_sha1_aes_cbc_tv_temp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4204) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4205) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4206) .alg = "authenc(hmac(sha1),cbc(des))",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4207) .test = alg_test_aead,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4208) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4209) .aead = __VECS(hmac_sha1_des_cbc_tv_temp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4210) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4211) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4212) .alg = "authenc(hmac(sha1),cbc(des3_ede))",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4213) .test = alg_test_aead,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4214) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4215) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4216) .aead = __VECS(hmac_sha1_des3_ede_cbc_tv_temp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4217) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4218) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4219) .alg = "authenc(hmac(sha1),ctr(aes))",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4220) .test = alg_test_null,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4221) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4222) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4223) .alg = "authenc(hmac(sha1),ecb(cipher_null))",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4224) .test = alg_test_aead,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4225) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4226) .aead = __VECS(hmac_sha1_ecb_cipher_null_tv_temp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4227) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4228) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4229) .alg = "authenc(hmac(sha1),rfc3686(ctr(aes)))",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4230) .test = alg_test_null,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4231) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4232) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4233) .alg = "authenc(hmac(sha224),cbc(des))",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4234) .test = alg_test_aead,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4235) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4236) .aead = __VECS(hmac_sha224_des_cbc_tv_temp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4237) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4238) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4239) .alg = "authenc(hmac(sha224),cbc(des3_ede))",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4240) .test = alg_test_aead,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4241) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4242) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4243) .aead = __VECS(hmac_sha224_des3_ede_cbc_tv_temp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4244) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4245) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4246) .alg = "authenc(hmac(sha256),cbc(aes))",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4247) .test = alg_test_aead,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4248) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4249) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4250) .aead = __VECS(hmac_sha256_aes_cbc_tv_temp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4251) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4252) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4253) .alg = "authenc(hmac(sha256),cbc(des))",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4254) .test = alg_test_aead,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4255) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4256) .aead = __VECS(hmac_sha256_des_cbc_tv_temp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4257) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4258) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4259) .alg = "authenc(hmac(sha256),cbc(des3_ede))",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4260) .test = alg_test_aead,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4261) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4262) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4263) .aead = __VECS(hmac_sha256_des3_ede_cbc_tv_temp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4265) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4266) .alg = "authenc(hmac(sha256),ctr(aes))",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4267) .test = alg_test_null,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4268) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4269) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4270) .alg = "authenc(hmac(sha256),rfc3686(ctr(aes)))",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4271) .test = alg_test_null,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4272) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4273) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4274) .alg = "authenc(hmac(sha384),cbc(des))",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4275) .test = alg_test_aead,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4276) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4277) .aead = __VECS(hmac_sha384_des_cbc_tv_temp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4278) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4279) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4280) .alg = "authenc(hmac(sha384),cbc(des3_ede))",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4281) .test = alg_test_aead,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4282) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4283) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4284) .aead = __VECS(hmac_sha384_des3_ede_cbc_tv_temp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4285) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4286) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4287) .alg = "authenc(hmac(sha384),ctr(aes))",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4288) .test = alg_test_null,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4289) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4290) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4291) .alg = "authenc(hmac(sha384),rfc3686(ctr(aes)))",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4292) .test = alg_test_null,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4293) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4294) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4295) .alg = "authenc(hmac(sha512),cbc(aes))",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4296) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4297) .test = alg_test_aead,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4298) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4299) .aead = __VECS(hmac_sha512_aes_cbc_tv_temp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4300) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4301) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4302) .alg = "authenc(hmac(sha512),cbc(des))",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4303) .test = alg_test_aead,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4304) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4305) .aead = __VECS(hmac_sha512_des_cbc_tv_temp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4306) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4307) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4308) .alg = "authenc(hmac(sha512),cbc(des3_ede))",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4309) .test = alg_test_aead,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4310) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4311) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4312) .aead = __VECS(hmac_sha512_des3_ede_cbc_tv_temp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4313) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4314) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4315) .alg = "authenc(hmac(sha512),ctr(aes))",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4316) .test = alg_test_null,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4317) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4318) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4319) .alg = "authenc(hmac(sha512),rfc3686(ctr(aes)))",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4320) .test = alg_test_null,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4321) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4322) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4323) .alg = "blake2b-160",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4324) .test = alg_test_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4325) .fips_allowed = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4326) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4327) .hash = __VECS(blake2b_160_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4328) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4329) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4330) .alg = "blake2b-256",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4331) .test = alg_test_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4332) .fips_allowed = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4333) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4334) .hash = __VECS(blake2b_256_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4335) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4336) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4337) .alg = "blake2b-384",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4338) .test = alg_test_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4339) .fips_allowed = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4340) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4341) .hash = __VECS(blake2b_384_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4342) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4343) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4344) .alg = "blake2b-512",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4345) .test = alg_test_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4346) .fips_allowed = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4347) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4348) .hash = __VECS(blake2b_512_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4349) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4350) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4351) .alg = "blake2s-128",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4352) .test = alg_test_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4353) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4354) .hash = __VECS(blakes2s_128_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4355) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4356) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4357) .alg = "blake2s-160",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4358) .test = alg_test_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4359) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4360) .hash = __VECS(blakes2s_160_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4361) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4362) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4363) .alg = "blake2s-224",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4364) .test = alg_test_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4365) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4366) .hash = __VECS(blakes2s_224_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4367) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4368) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4369) .alg = "blake2s-256",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4370) .test = alg_test_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4371) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4372) .hash = __VECS(blakes2s_256_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4373) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4374) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4375) .alg = "cbc(aes)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4376) .test = alg_test_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4377) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4378) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4379) .cipher = __VECS(aes_cbc_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4380) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4381) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4382) .alg = "cbc(anubis)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4383) .test = alg_test_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4384) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4385) .cipher = __VECS(anubis_cbc_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4386) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4387) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4388) .alg = "cbc(blowfish)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4389) .test = alg_test_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4390) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4391) .cipher = __VECS(bf_cbc_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4392) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4393) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4394) .alg = "cbc(camellia)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4395) .test = alg_test_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4396) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4397) .cipher = __VECS(camellia_cbc_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4398) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4399) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4400) .alg = "cbc(cast5)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4401) .test = alg_test_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4402) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4403) .cipher = __VECS(cast5_cbc_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4404) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4405) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4406) .alg = "cbc(cast6)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4407) .test = alg_test_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4408) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4409) .cipher = __VECS(cast6_cbc_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4410) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4411) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4412) .alg = "cbc(des)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4413) .test = alg_test_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4414) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4415) .cipher = __VECS(des_cbc_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4416) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4417) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4418) .alg = "cbc(des3_ede)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4419) .test = alg_test_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4420) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4421) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4422) .cipher = __VECS(des3_ede_cbc_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4423) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4424) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4425) /* Same as cbc(aes) except the key is stored in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4426) * hardware secure memory which we reference by index
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4427) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4428) .alg = "cbc(paes)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4429) .test = alg_test_null,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4430) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4431) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4432) /* Same as cbc(sm4) except the key is stored in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4433) * hardware secure memory which we reference by index
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4434) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4435) .alg = "cbc(psm4)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4436) .test = alg_test_null,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4437) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4438) .alg = "cbc(serpent)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4439) .test = alg_test_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4440) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4441) .cipher = __VECS(serpent_cbc_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4442) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4443) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4444) .alg = "cbc(sm4)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4445) .test = alg_test_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4446) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4447) .cipher = __VECS(sm4_cbc_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4448) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4449) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4450) .alg = "cbc(twofish)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4451) .test = alg_test_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4452) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4453) .cipher = __VECS(tf_cbc_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4454) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4455) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4456) #if IS_ENABLED(CONFIG_CRYPTO_PAES_S390)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4457) .alg = "cbc-paes-s390",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4458) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4459) .test = alg_test_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4460) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4461) .cipher = __VECS(aes_cbc_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4462) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4463) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4464) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4465) .alg = "cbcmac(aes)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4466) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4467) .test = alg_test_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4468) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4469) .hash = __VECS(aes_cbcmac_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4470) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4471) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4472) .alg = "ccm(aes)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4473) .generic_driver = "ccm_base(ctr(aes-generic),cbcmac(aes-generic))",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4474) .test = alg_test_aead,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4475) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4476) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4477) .aead = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4478) ____VECS(aes_ccm_tv_template),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4479) .einval_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4480) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4481) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4482) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4483) .alg = "cfb(aes)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4484) .test = alg_test_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4485) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4486) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4487) .cipher = __VECS(aes_cfb_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4488) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4489) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4490) .alg = "cfb(sm4)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4491) .test = alg_test_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4492) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4493) .cipher = __VECS(sm4_cfb_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4494) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4495) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4496) .alg = "chacha20",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4497) .test = alg_test_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4498) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4499) .cipher = __VECS(chacha20_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4500) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4501) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4502) .alg = "cmac(aes)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4503) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4504) .test = alg_test_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4505) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4506) .hash = __VECS(aes_cmac128_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4507) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4508) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4509) .alg = "cmac(des3_ede)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4510) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4511) .test = alg_test_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4512) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4513) .hash = __VECS(des3_ede_cmac64_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4514) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4515) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4516) .alg = "compress_null",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4517) .test = alg_test_null,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4518) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4519) .alg = "crc32",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4520) .test = alg_test_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4521) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4522) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4523) .hash = __VECS(crc32_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4524) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4525) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4526) .alg = "crc32c",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4527) .test = alg_test_crc32c,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4528) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4529) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4530) .hash = __VECS(crc32c_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4531) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4532) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4533) .alg = "crct10dif",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4534) .test = alg_test_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4535) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4536) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4537) .hash = __VECS(crct10dif_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4538) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4539) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4540) .alg = "ctr(aes)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4541) .test = alg_test_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4542) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4543) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4544) .cipher = __VECS(aes_ctr_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4545) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4546) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4547) .alg = "ctr(blowfish)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4548) .test = alg_test_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4549) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4550) .cipher = __VECS(bf_ctr_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4551) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4552) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4553) .alg = "ctr(camellia)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4554) .test = alg_test_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4555) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4556) .cipher = __VECS(camellia_ctr_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4557) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4558) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4559) .alg = "ctr(cast5)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4560) .test = alg_test_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4561) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4562) .cipher = __VECS(cast5_ctr_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4563) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4564) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4565) .alg = "ctr(cast6)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4566) .test = alg_test_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4567) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4568) .cipher = __VECS(cast6_ctr_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4569) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4570) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4571) .alg = "ctr(des)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4572) .test = alg_test_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4573) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4574) .cipher = __VECS(des_ctr_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4575) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4576) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4577) .alg = "ctr(des3_ede)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4578) .test = alg_test_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4579) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4580) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4581) .cipher = __VECS(des3_ede_ctr_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4582) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4583) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4584) /* Same as ctr(aes) except the key is stored in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4585) * hardware secure memory which we reference by index
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4586) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4587) .alg = "ctr(paes)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4588) .test = alg_test_null,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4589) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4590) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4591)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4592) /* Same as ctr(sm4) except the key is stored in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4593) * hardware secure memory which we reference by index
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4594) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4595) .alg = "ctr(psm4)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4596) .test = alg_test_null,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4597) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4598) .alg = "ctr(serpent)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4599) .test = alg_test_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4600) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4601) .cipher = __VECS(serpent_ctr_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4602) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4603) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4604) .alg = "ctr(sm4)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4605) .test = alg_test_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4606) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4607) .cipher = __VECS(sm4_ctr_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4608) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4609) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4610) .alg = "ctr(twofish)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4611) .test = alg_test_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4612) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4613) .cipher = __VECS(tf_ctr_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4614) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4615) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4616) #if IS_ENABLED(CONFIG_CRYPTO_PAES_S390)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4617) .alg = "ctr-paes-s390",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4618) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4619) .test = alg_test_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4620) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4621) .cipher = __VECS(aes_ctr_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4622) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4623) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4624) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4625) .alg = "cts(cbc(aes))",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4626) .test = alg_test_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4627) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4628) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4629) .cipher = __VECS(cts_mode_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4630) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4631) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4632) /* Same as cts(cbc((aes)) except the key is stored in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4633) * hardware secure memory which we reference by index
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4634) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4635) .alg = "cts(cbc(paes))",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4636) .test = alg_test_null,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4637) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4638) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4639) .alg = "curve25519",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4640) .test = alg_test_kpp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4641) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4642) .kpp = __VECS(curve25519_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4643) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4644) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4645) .alg = "deflate",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4646) .test = alg_test_comp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4647) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4648) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4649) .comp = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4650) .comp = __VECS(deflate_comp_tv_template),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4651) .decomp = __VECS(deflate_decomp_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4652) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4653) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4654) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4655) .alg = "dh",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4656) .test = alg_test_kpp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4657) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4658) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4659) .kpp = __VECS(dh_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4660) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4661) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4662) .alg = "digest_null",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4663) .test = alg_test_null,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4664) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4665) .alg = "drbg_nopr_ctr_aes128",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4666) .test = alg_test_drbg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4667) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4668) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4669) .drbg = __VECS(drbg_nopr_ctr_aes128_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4670) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4671) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4672) .alg = "drbg_nopr_ctr_aes192",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4673) .test = alg_test_drbg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4674) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4675) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4676) .drbg = __VECS(drbg_nopr_ctr_aes192_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4677) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4678) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4679) .alg = "drbg_nopr_ctr_aes256",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4680) .test = alg_test_drbg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4681) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4682) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4683) .drbg = __VECS(drbg_nopr_ctr_aes256_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4684) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4685) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4686) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4687) * There is no need to specifically test the DRBG with every
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4688) * backend cipher -- covered by drbg_nopr_hmac_sha256 test
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4689) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4690) .alg = "drbg_nopr_hmac_sha1",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4691) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4692) .test = alg_test_null,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4693) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4694) .alg = "drbg_nopr_hmac_sha256",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4695) .test = alg_test_drbg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4696) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4697) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4698) .drbg = __VECS(drbg_nopr_hmac_sha256_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4699) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4700) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4701) /* covered by drbg_nopr_hmac_sha256 test */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4702) .alg = "drbg_nopr_hmac_sha384",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4703) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4704) .test = alg_test_null,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4705) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4706) .alg = "drbg_nopr_hmac_sha512",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4707) .test = alg_test_null,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4708) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4709) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4710) .alg = "drbg_nopr_sha1",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4711) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4712) .test = alg_test_null,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4713) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4714) .alg = "drbg_nopr_sha256",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4715) .test = alg_test_drbg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4716) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4717) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4718) .drbg = __VECS(drbg_nopr_sha256_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4719) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4720) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4721) /* covered by drbg_nopr_sha256 test */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4722) .alg = "drbg_nopr_sha384",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4723) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4724) .test = alg_test_null,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4725) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4726) .alg = "drbg_nopr_sha512",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4727) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4728) .test = alg_test_null,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4729) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4730) .alg = "drbg_pr_ctr_aes128",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4731) .test = alg_test_drbg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4732) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4733) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4734) .drbg = __VECS(drbg_pr_ctr_aes128_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4735) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4736) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4737) /* covered by drbg_pr_ctr_aes128 test */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4738) .alg = "drbg_pr_ctr_aes192",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4739) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4740) .test = alg_test_null,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4741) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4742) .alg = "drbg_pr_ctr_aes256",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4743) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4744) .test = alg_test_null,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4745) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4746) .alg = "drbg_pr_hmac_sha1",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4747) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4748) .test = alg_test_null,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4749) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4750) .alg = "drbg_pr_hmac_sha256",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4751) .test = alg_test_drbg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4752) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4753) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4754) .drbg = __VECS(drbg_pr_hmac_sha256_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4755) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4756) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4757) /* covered by drbg_pr_hmac_sha256 test */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4758) .alg = "drbg_pr_hmac_sha384",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4759) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4760) .test = alg_test_null,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4761) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4762) .alg = "drbg_pr_hmac_sha512",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4763) .test = alg_test_null,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4764) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4765) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4766) .alg = "drbg_pr_sha1",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4767) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4768) .test = alg_test_null,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4769) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4770) .alg = "drbg_pr_sha256",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4771) .test = alg_test_drbg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4772) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4773) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4774) .drbg = __VECS(drbg_pr_sha256_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4775) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4776) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4777) /* covered by drbg_pr_sha256 test */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4778) .alg = "drbg_pr_sha384",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4779) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4780) .test = alg_test_null,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4781) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4782) .alg = "drbg_pr_sha512",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4783) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4784) .test = alg_test_null,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4785) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4786) .alg = "ecb(aes)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4787) .test = alg_test_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4788) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4789) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4790) .cipher = __VECS(aes_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4791) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4792) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4793) .alg = "ecb(anubis)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4794) .test = alg_test_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4795) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4796) .cipher = __VECS(anubis_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4797) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4798) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4799) .alg = "ecb(arc4)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4800) .generic_driver = "ecb(arc4)-generic",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4801) .test = alg_test_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4802) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4803) .cipher = __VECS(arc4_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4804) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4805) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4806) .alg = "ecb(blowfish)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4807) .test = alg_test_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4808) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4809) .cipher = __VECS(bf_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4810) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4811) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4812) .alg = "ecb(camellia)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4813) .test = alg_test_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4814) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4815) .cipher = __VECS(camellia_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4816) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4817) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4818) .alg = "ecb(cast5)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4819) .test = alg_test_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4820) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4821) .cipher = __VECS(cast5_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4822) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4823) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4824) .alg = "ecb(cast6)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4825) .test = alg_test_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4826) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4827) .cipher = __VECS(cast6_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4828) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4829) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4830) .alg = "ecb(cipher_null)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4831) .test = alg_test_null,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4832) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4833) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4834) .alg = "ecb(des)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4835) .test = alg_test_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4836) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4837) .cipher = __VECS(des_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4838) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4839) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4840) .alg = "ecb(des3_ede)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4841) .test = alg_test_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4842) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4843) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4844) .cipher = __VECS(des3_ede_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4845) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4846) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4847) .alg = "ecb(fcrypt)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4848) .test = alg_test_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4849) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4850) .cipher = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4851) .vecs = fcrypt_pcbc_tv_template,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4852) .count = 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4853) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4854) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4855) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4856) .alg = "ecb(khazad)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4857) .test = alg_test_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4858) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4859) .cipher = __VECS(khazad_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4860) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4861) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4862) /* Same as ecb(aes) except the key is stored in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4863) * hardware secure memory which we reference by index
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4864) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4865) .alg = "ecb(paes)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4866) .test = alg_test_null,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4867) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4868) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4869) .alg = "ecb(seed)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4870) .test = alg_test_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4871) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4872) .cipher = __VECS(seed_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4873) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4874) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4875) .alg = "ecb(serpent)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4876) .test = alg_test_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4877) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4878) .cipher = __VECS(serpent_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4879) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4880) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4881) .alg = "ecb(sm4)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4882) .test = alg_test_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4883) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4884) .cipher = __VECS(sm4_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4885) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4886) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4887) .alg = "ecb(tea)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4888) .test = alg_test_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4889) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4890) .cipher = __VECS(tea_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4891) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4892) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4893) .alg = "ecb(tnepres)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4894) .test = alg_test_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4895) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4896) .cipher = __VECS(tnepres_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4897) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4898) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4899) .alg = "ecb(twofish)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4900) .test = alg_test_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4901) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4902) .cipher = __VECS(tf_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4903) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4904) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4905) .alg = "ecb(xeta)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4906) .test = alg_test_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4907) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4908) .cipher = __VECS(xeta_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4909) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4910) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4911) .alg = "ecb(xtea)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4912) .test = alg_test_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4913) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4914) .cipher = __VECS(xtea_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4915) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4916) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4917) #if IS_ENABLED(CONFIG_CRYPTO_PAES_S390)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4918) .alg = "ecb-paes-s390",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4919) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4920) .test = alg_test_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4921) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4922) .cipher = __VECS(aes_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4923) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4924) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4925) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4926) .alg = "ecdh",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4927) .test = alg_test_kpp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4928) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4929) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4930) .kpp = __VECS(ecdh_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4931) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4932) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4933) .alg = "ecrdsa",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4934) .test = alg_test_akcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4935) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4936) .akcipher = __VECS(ecrdsa_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4937) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4938) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4939) .alg = "essiv(authenc(hmac(sha256),cbc(aes)),sha256)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4940) .test = alg_test_aead,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4941) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4942) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4943) .aead = __VECS(essiv_hmac_sha256_aes_cbc_tv_temp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4944) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4945) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4946) .alg = "essiv(cbc(aes),sha256)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4947) .test = alg_test_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4948) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4949) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4950) .cipher = __VECS(essiv_aes_cbc_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4951) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4952) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4953) .alg = "gcm(aes)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4954) .generic_driver = "gcm_base(ctr(aes-generic),ghash-generic)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4955) .test = alg_test_aead,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4956) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4957) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4958) .aead = __VECS(aes_gcm_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4959) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4960) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4961) .alg = "ghash",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4962) .test = alg_test_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4963) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4964) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4965) .hash = __VECS(ghash_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4966) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4967) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4968) .alg = "hmac(md5)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4969) .test = alg_test_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4970) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4971) .hash = __VECS(hmac_md5_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4972) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4973) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4974) .alg = "hmac(rmd128)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4975) .test = alg_test_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4976) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4977) .hash = __VECS(hmac_rmd128_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4978) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4979) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4980) .alg = "hmac(rmd160)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4981) .test = alg_test_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4982) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4983) .hash = __VECS(hmac_rmd160_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4984) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4985) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4986) .alg = "hmac(sha1)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4987) .test = alg_test_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4988) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4989) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4990) .hash = __VECS(hmac_sha1_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4991) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4992) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4993) .alg = "hmac(sha224)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4994) .test = alg_test_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4995) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4996) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4997) .hash = __VECS(hmac_sha224_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4998) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4999) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5000) .alg = "hmac(sha256)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5001) .test = alg_test_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5002) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5003) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5004) .hash = __VECS(hmac_sha256_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5005) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5006) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5007) .alg = "hmac(sha3-224)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5008) .test = alg_test_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5009) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5010) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5011) .hash = __VECS(hmac_sha3_224_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5012) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5013) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5014) .alg = "hmac(sha3-256)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5015) .test = alg_test_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5016) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5017) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5018) .hash = __VECS(hmac_sha3_256_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5019) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5020) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5021) .alg = "hmac(sha3-384)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5022) .test = alg_test_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5023) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5024) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5025) .hash = __VECS(hmac_sha3_384_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5026) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5027) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5028) .alg = "hmac(sha3-512)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5029) .test = alg_test_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5030) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5031) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5032) .hash = __VECS(hmac_sha3_512_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5033) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5034) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5035) .alg = "hmac(sha384)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5036) .test = alg_test_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5037) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5038) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5039) .hash = __VECS(hmac_sha384_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5040) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5041) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5042) .alg = "hmac(sha512)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5043) .test = alg_test_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5044) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5045) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5046) .hash = __VECS(hmac_sha512_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5047) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5048) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5049) .alg = "hmac(sm3)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5050) .test = alg_test_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5051) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5052) .hash = __VECS(hmac_sm3_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5053) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5054) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5055) .alg = "hmac(streebog256)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5056) .test = alg_test_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5057) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5058) .hash = __VECS(hmac_streebog256_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5059) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5060) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5061) .alg = "hmac(streebog512)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5062) .test = alg_test_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5063) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5064) .hash = __VECS(hmac_streebog512_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5065) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5066) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5067) .alg = "jitterentropy_rng",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5068) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5069) .test = alg_test_null,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5070) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5071) .alg = "kw(aes)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5072) .test = alg_test_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5073) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5074) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5075) .cipher = __VECS(aes_kw_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5076) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5077) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5078) .alg = "lrw(aes)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5079) .generic_driver = "lrw(ecb(aes-generic))",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5080) .test = alg_test_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5081) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5082) .cipher = __VECS(aes_lrw_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5083) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5084) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5085) .alg = "lrw(camellia)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5086) .generic_driver = "lrw(ecb(camellia-generic))",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5087) .test = alg_test_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5088) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5089) .cipher = __VECS(camellia_lrw_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5090) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5091) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5092) .alg = "lrw(cast6)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5093) .generic_driver = "lrw(ecb(cast6-generic))",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5094) .test = alg_test_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5095) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5096) .cipher = __VECS(cast6_lrw_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5097) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5098) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5099) .alg = "lrw(serpent)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5100) .generic_driver = "lrw(ecb(serpent-generic))",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5101) .test = alg_test_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5102) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5103) .cipher = __VECS(serpent_lrw_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5105) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5106) .alg = "lrw(twofish)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5107) .generic_driver = "lrw(ecb(twofish-generic))",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5108) .test = alg_test_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5109) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5110) .cipher = __VECS(tf_lrw_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5112) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5113) .alg = "lz4",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5114) .test = alg_test_comp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5115) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5116) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5117) .comp = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5118) .comp = __VECS(lz4_comp_tv_template),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5119) .decomp = __VECS(lz4_decomp_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5120) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5121) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5122) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5123) .alg = "lz4hc",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5124) .test = alg_test_comp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5125) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5126) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5127) .comp = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5128) .comp = __VECS(lz4hc_comp_tv_template),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5129) .decomp = __VECS(lz4hc_decomp_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5130) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5131) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5132) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5133) .alg = "lzo",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5134) .test = alg_test_comp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5135) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5136) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5137) .comp = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5138) .comp = __VECS(lzo_comp_tv_template),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5139) .decomp = __VECS(lzo_decomp_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5140) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5142) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5143) .alg = "lzo-rle",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5144) .test = alg_test_comp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5145) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5146) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5147) .comp = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5148) .comp = __VECS(lzorle_comp_tv_template),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5149) .decomp = __VECS(lzorle_decomp_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5150) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5151) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5152) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5153) .alg = "md4",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5154) .test = alg_test_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5155) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5156) .hash = __VECS(md4_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5158) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5159) .alg = "md5",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5160) .test = alg_test_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5161) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5162) .hash = __VECS(md5_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5163) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5164) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5165) .alg = "michael_mic",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5166) .test = alg_test_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5167) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5168) .hash = __VECS(michael_mic_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5169) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5170) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5171) .alg = "nhpoly1305",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5172) .test = alg_test_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5173) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5174) .hash = __VECS(nhpoly1305_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5175) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5176) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5177) .alg = "ofb(aes)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5178) .test = alg_test_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5179) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5180) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5181) .cipher = __VECS(aes_ofb_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5182) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5183) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5184) /* Same as ofb(aes) except the key is stored in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5185) * hardware secure memory which we reference by index
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5186) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5187) .alg = "ofb(paes)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5188) .test = alg_test_null,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5189) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5190) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5191) .alg = "ofb(sm4)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5192) .test = alg_test_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5193) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5194) .cipher = __VECS(sm4_ofb_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5195) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5196) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5197) .alg = "pcbc(fcrypt)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5198) .test = alg_test_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5199) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5200) .cipher = __VECS(fcrypt_pcbc_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5201) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5202) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5203) .alg = "pkcs1pad(rsa,sha224)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5204) .test = alg_test_null,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5205) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5206) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5207) .alg = "pkcs1pad(rsa,sha256)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5208) .test = alg_test_akcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5209) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5210) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5211) .akcipher = __VECS(pkcs1pad_rsa_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5212) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5213) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5214) .alg = "pkcs1pad(rsa,sha384)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5215) .test = alg_test_null,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5216) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5217) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5218) .alg = "pkcs1pad(rsa,sha512)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5219) .test = alg_test_null,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5220) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5221) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5222) .alg = "poly1305",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5223) .test = alg_test_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5224) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5225) .hash = __VECS(poly1305_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5226) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5227) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5228) .alg = "rfc3686(ctr(aes))",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5229) .test = alg_test_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5230) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5231) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5232) .cipher = __VECS(aes_ctr_rfc3686_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5233) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5234) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5235) .alg = "rfc3686(ctr(sm4))",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5236) .test = alg_test_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5237) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5238) .cipher = __VECS(sm4_ctr_rfc3686_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5239) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5240) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5241) .alg = "rfc4106(gcm(aes))",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5242) .generic_driver = "rfc4106(gcm_base(ctr(aes-generic),ghash-generic))",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5243) .test = alg_test_aead,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5244) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5245) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5246) .aead = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5247) ____VECS(aes_gcm_rfc4106_tv_template),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5248) .einval_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5249) .aad_iv = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5250) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5251) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5252) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5253) .alg = "rfc4309(ccm(aes))",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5254) .generic_driver = "rfc4309(ccm_base(ctr(aes-generic),cbcmac(aes-generic)))",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5255) .test = alg_test_aead,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5256) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5257) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5258) .aead = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5259) ____VECS(aes_ccm_rfc4309_tv_template),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5260) .einval_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5261) .aad_iv = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5262) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5263) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5264) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5265) .alg = "rfc4543(gcm(aes))",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5266) .generic_driver = "rfc4543(gcm_base(ctr(aes-generic),ghash-generic))",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5267) .test = alg_test_aead,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5268) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5269) .aead = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5270) ____VECS(aes_gcm_rfc4543_tv_template),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5271) .einval_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5272) .aad_iv = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5273) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5274) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5275) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5276) .alg = "rfc7539(chacha20,poly1305)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5277) .test = alg_test_aead,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5278) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5279) .aead = __VECS(rfc7539_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5280) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5281) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5282) .alg = "rfc7539esp(chacha20,poly1305)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5283) .test = alg_test_aead,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5284) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5285) .aead = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5286) ____VECS(rfc7539esp_tv_template),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5287) .einval_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5288) .aad_iv = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5289) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5290) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5291) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5292) .alg = "rmd128",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5293) .test = alg_test_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5294) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5295) .hash = __VECS(rmd128_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5296) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5297) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5298) .alg = "rmd160",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5299) .test = alg_test_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5300) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5301) .hash = __VECS(rmd160_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5302) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5303) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5304) .alg = "rmd256",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5305) .test = alg_test_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5306) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5307) .hash = __VECS(rmd256_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5308) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5309) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5310) .alg = "rmd320",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5311) .test = alg_test_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5312) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5313) .hash = __VECS(rmd320_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5314) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5315) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5316) .alg = "rsa",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5317) .test = alg_test_akcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5318) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5319) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5320) .akcipher = __VECS(rsa_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5321) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5322) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5323) .alg = "salsa20",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5324) .test = alg_test_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5325) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5326) .cipher = __VECS(salsa20_stream_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5327) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5328) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5329) .alg = "sha1",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5330) .test = alg_test_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5331) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5332) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5333) .hash = __VECS(sha1_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5334) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5335) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5336) .alg = "sha224",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5337) .test = alg_test_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5338) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5339) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5340) .hash = __VECS(sha224_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5341) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5342) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5343) .alg = "sha256",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5344) .test = alg_test_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5345) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5346) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5347) .hash = __VECS(sha256_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5348) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5349) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5350) .alg = "sha3-224",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5351) .test = alg_test_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5352) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5353) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5354) .hash = __VECS(sha3_224_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5355) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5356) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5357) .alg = "sha3-256",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5358) .test = alg_test_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5359) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5360) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5361) .hash = __VECS(sha3_256_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5362) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5363) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5364) .alg = "sha3-384",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5365) .test = alg_test_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5366) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5367) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5368) .hash = __VECS(sha3_384_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5369) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5370) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5371) .alg = "sha3-512",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5372) .test = alg_test_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5373) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5374) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5375) .hash = __VECS(sha3_512_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5376) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5377) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5378) .alg = "sha384",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5379) .test = alg_test_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5380) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5381) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5382) .hash = __VECS(sha384_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5383) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5384) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5385) .alg = "sha512",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5386) .test = alg_test_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5387) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5388) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5389) .hash = __VECS(sha512_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5390) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5391) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5392) .alg = "sm2",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5393) .test = alg_test_akcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5394) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5395) .akcipher = __VECS(sm2_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5396) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5397) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5398) .alg = "sm3",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5399) .test = alg_test_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5400) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5401) .hash = __VECS(sm3_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5402) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5403) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5404) .alg = "streebog256",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5405) .test = alg_test_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5406) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5407) .hash = __VECS(streebog256_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5408) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5409) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5410) .alg = "streebog512",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5411) .test = alg_test_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5412) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5413) .hash = __VECS(streebog512_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5414) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5415) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5416) .alg = "tgr128",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5417) .test = alg_test_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5418) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5419) .hash = __VECS(tgr128_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5420) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5421) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5422) .alg = "tgr160",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5423) .test = alg_test_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5424) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5425) .hash = __VECS(tgr160_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5426) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5427) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5428) .alg = "tgr192",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5429) .test = alg_test_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5430) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5431) .hash = __VECS(tgr192_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5432) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5433) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5434) .alg = "vmac64(aes)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5435) .test = alg_test_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5436) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5437) .hash = __VECS(vmac64_aes_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5438) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5439) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5440) .alg = "wp256",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5441) .test = alg_test_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5442) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5443) .hash = __VECS(wp256_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5444) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5445) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5446) .alg = "wp384",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5447) .test = alg_test_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5448) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5449) .hash = __VECS(wp384_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5450) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5451) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5452) .alg = "wp512",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5453) .test = alg_test_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5454) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5455) .hash = __VECS(wp512_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5456) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5457) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5458) .alg = "xcbc(aes)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5459) .test = alg_test_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5460) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5461) .hash = __VECS(aes_xcbc128_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5462) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5463) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5464) .alg = "xchacha12",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5465) .test = alg_test_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5466) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5467) .cipher = __VECS(xchacha12_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5468) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5469) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5470) .alg = "xchacha20",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5471) .test = alg_test_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5472) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5473) .cipher = __VECS(xchacha20_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5474) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5475) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5476) .alg = "xts(aes)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5477) .generic_driver = "xts(ecb(aes-generic))",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5478) .test = alg_test_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5479) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5480) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5481) .cipher = __VECS(aes_xts_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5482) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5483) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5484) .alg = "xts(camellia)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5485) .generic_driver = "xts(ecb(camellia-generic))",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5486) .test = alg_test_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5487) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5488) .cipher = __VECS(camellia_xts_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5489) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5490) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5491) .alg = "xts(cast6)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5492) .generic_driver = "xts(ecb(cast6-generic))",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5493) .test = alg_test_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5494) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5495) .cipher = __VECS(cast6_xts_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5496) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5497) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5498) /* Same as xts(aes) except the key is stored in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5499) * hardware secure memory which we reference by index
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5500) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5501) .alg = "xts(paes)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5502) .test = alg_test_null,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5503) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5504) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5505) .alg = "xts(serpent)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5506) .generic_driver = "xts(ecb(serpent-generic))",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5507) .test = alg_test_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5508) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5509) .cipher = __VECS(serpent_xts_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5510) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5511) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5512) .alg = "xts(twofish)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5513) .generic_driver = "xts(ecb(twofish-generic))",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5514) .test = alg_test_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5515) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5516) .cipher = __VECS(tf_xts_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5517) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5518) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5519) #if IS_ENABLED(CONFIG_CRYPTO_PAES_S390)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5520) .alg = "xts-paes-s390",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5521) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5522) .test = alg_test_skcipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5523) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5524) .cipher = __VECS(aes_xts_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5525) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5526) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5527) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5528) .alg = "xts4096(paes)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5529) .test = alg_test_null,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5530) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5531) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5532) .alg = "xts512(paes)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5533) .test = alg_test_null,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5534) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5535) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5536) .alg = "xxhash64",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5537) .test = alg_test_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5538) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5539) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5540) .hash = __VECS(xxhash64_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5541) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5542) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5543) .alg = "zlib-deflate",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5544) .test = alg_test_comp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5545) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5546) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5547) .comp = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5548) .comp = __VECS(zlib_deflate_comp_tv_template),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5549) .decomp = __VECS(zlib_deflate_decomp_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5550) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5551) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5552) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5553) .alg = "zstd",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5554) .test = alg_test_comp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5555) .fips_allowed = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5556) .suite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5557) .comp = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5558) .comp = __VECS(zstd_comp_tv_template),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5559) .decomp = __VECS(zstd_decomp_tv_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5560) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5561) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5562) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5563) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5564)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5565) static void alg_check_test_descs_order(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5566) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5567) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5568)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5569) for (i = 1; i < ARRAY_SIZE(alg_test_descs); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5570) int diff = strcmp(alg_test_descs[i - 1].alg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5571) alg_test_descs[i].alg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5572)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5573) if (WARN_ON(diff > 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5574) pr_warn("testmgr: alg_test_descs entries in wrong order: '%s' before '%s'\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5575) alg_test_descs[i - 1].alg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5576) alg_test_descs[i].alg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5577) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5578)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5579) if (WARN_ON(diff == 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5580) pr_warn("testmgr: duplicate alg_test_descs entry: '%s'\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5581) alg_test_descs[i].alg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5582) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5583) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5584) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5585)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5586) static void alg_check_testvec_configs(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5587) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5588) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5589)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5590) for (i = 0; i < ARRAY_SIZE(default_cipher_testvec_configs); i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5591) WARN_ON(!valid_testvec_config(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5592) &default_cipher_testvec_configs[i]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5593)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5594) for (i = 0; i < ARRAY_SIZE(default_hash_testvec_configs); i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5595) WARN_ON(!valid_testvec_config(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5596) &default_hash_testvec_configs[i]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5597) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5598)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5599) static void testmgr_onetime_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5600) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5601) alg_check_test_descs_order();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5602) alg_check_testvec_configs();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5603)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5604) #ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5605) pr_warn("alg: extra crypto tests enabled. This is intended for developer use only.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5606) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5607) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5608)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5609) static int alg_find_test(const char *alg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5610) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5611) int start = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5612) int end = ARRAY_SIZE(alg_test_descs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5613)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5614) while (start < end) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5615) int i = (start + end) / 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5616) int diff = strcmp(alg_test_descs[i].alg, alg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5617)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5618) if (diff > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5619) end = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5620) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5621) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5622)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5623) if (diff < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5624) start = i + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5625) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5626) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5627)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5628) return i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5629) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5630)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5631) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5632) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5633)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5634) int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5635) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5636) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5637) int j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5638) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5639)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5640) if (!fips_enabled && notests) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5641) printk_once(KERN_INFO "alg: self-tests disabled\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5642) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5643) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5644)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5645) DO_ONCE(testmgr_onetime_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5646)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5647) if ((type & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_CIPHER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5648) char nalg[CRYPTO_MAX_ALG_NAME];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5649)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5650) if (snprintf(nalg, sizeof(nalg), "ecb(%s)", alg) >=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5651) sizeof(nalg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5652) return -ENAMETOOLONG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5653)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5654) i = alg_find_test(nalg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5655) if (i < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5656) goto notest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5657)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5658) if (fips_enabled && !alg_test_descs[i].fips_allowed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5659) goto non_fips_alg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5660)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5661) rc = alg_test_cipher(alg_test_descs + i, driver, type, mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5662) goto test_done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5663) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5664)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5665) i = alg_find_test(alg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5666) j = alg_find_test(driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5667) if (i < 0 && j < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5668) goto notest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5669)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5670) if (fips_enabled && ((i >= 0 && !alg_test_descs[i].fips_allowed) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5671) (j >= 0 && !alg_test_descs[j].fips_allowed)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5672) goto non_fips_alg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5673)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5674) rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5675) if (i >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5676) rc |= alg_test_descs[i].test(alg_test_descs + i, driver,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5677) type, mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5678) if (j >= 0 && j != i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5679) rc |= alg_test_descs[j].test(alg_test_descs + j, driver,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5680) type, mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5681)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5682) test_done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5683) if (rc && (fips_enabled || panic_on_fail)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5684) fips_fail_notify();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5685) panic("alg: self-tests for %s (%s) failed in %s mode!\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5686) driver, alg, fips_enabled ? "fips" : "panic_on_fail");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5687) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5688)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5689) if (fips_enabled && !rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5690) pr_info("alg: self-tests for %s (%s) passed\n", driver, alg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5691)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5692) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5693)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5694) notest:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5695) printk(KERN_INFO "alg: No test for %s (%s)\n", alg, driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5696) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5697) non_fips_alg:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5698) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5699) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5700)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5701) #endif /* CONFIG_CRYPTO_MANAGER_DISABLE_TESTS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5702)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5703) EXPORT_SYMBOL_GPL(alg_test);