Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

crypto: simd - allow registering multiple algorithms at once

Add a function to crypto_simd that registers an array of skcipher
algorithms, then allocates and registers the simd wrapper algorithms for
them. It assumes the naming scheme where the names of the underlying
algorithms are prefixed with two underscores.

Also add the corresponding 'unregister' function.

Most of the x86 crypto modules will be able to use these.

Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

Eric Biggers and committed by
Herbert Xu
d14f0a1f d800e343

+57
+50
crypto/simd.c
··· 221 221 } 222 222 EXPORT_SYMBOL_GPL(simd_skcipher_free); 223 223 224 + int simd_register_skciphers_compat(struct skcipher_alg *algs, int count, 225 + struct simd_skcipher_alg **simd_algs) 226 + { 227 + int err; 228 + int i; 229 + const char *algname; 230 + const char *drvname; 231 + const char *basename; 232 + struct simd_skcipher_alg *simd; 233 + 234 + err = crypto_register_skciphers(algs, count); 235 + if (err) 236 + return err; 237 + 238 + for (i = 0; i < count; i++) { 239 + WARN_ON(strncmp(algs[i].base.cra_name, "__", 2)); 240 + WARN_ON(strncmp(algs[i].base.cra_driver_name, "__", 2)); 241 + algname = algs[i].base.cra_name + 2; 242 + drvname = algs[i].base.cra_driver_name + 2; 243 + basename = algs[i].base.cra_driver_name; 244 + simd = simd_skcipher_create_compat(algname, drvname, basename); 245 + err = PTR_ERR(simd); 246 + if (IS_ERR(simd)) 247 + goto err_unregister; 248 + simd_algs[i] = simd; 249 + } 250 + return 0; 251 + 252 + err_unregister: 253 + simd_unregister_skciphers(algs, count, simd_algs); 254 + return err; 255 + } 256 + EXPORT_SYMBOL_GPL(simd_register_skciphers_compat); 257 + 258 + void simd_unregister_skciphers(struct skcipher_alg *algs, int count, 259 + struct simd_skcipher_alg **simd_algs) 260 + { 261 + int i; 262 + 263 + crypto_unregister_skciphers(algs, count); 264 + 265 + for (i = 0; i < count; i++) { 266 + if (simd_algs[i]) { 267 + simd_skcipher_free(simd_algs[i]); 268 + simd_algs[i] = NULL; 269 + } 270 + } 271 + } 272 + EXPORT_SYMBOL_GPL(simd_unregister_skciphers); 273 + 224 274 MODULE_LICENSE("GPL");
+7
include/crypto/internal/simd.h
··· 7 7 #define _CRYPTO_INTERNAL_SIMD_H 8 8 9 9 struct simd_skcipher_alg; 10 + struct skcipher_alg; 10 11 11 12 struct simd_skcipher_alg *simd_skcipher_create_compat(const char *algname, 12 13 const char *drvname, ··· 15 14 struct simd_skcipher_alg *simd_skcipher_create(const char *algname, 16 15 const char *basename); 17 16 void simd_skcipher_free(struct simd_skcipher_alg *alg); 17 + 18 + int simd_register_skciphers_compat(struct skcipher_alg *algs, int count, 19 + struct simd_skcipher_alg **simd_algs); 20 + 21 + void simd_unregister_skciphers(struct skcipher_alg *algs, int count, 22 + struct simd_skcipher_alg **simd_algs); 18 23 19 24 #endif /* _CRYPTO_INTERNAL_SIMD_H */