aboutsummaryrefslogtreecommitdiffstats
path: root/crypto
diff options
context:
space:
mode:
authorEric Biggers <ebiggers@google.com>2018-02-20 02:47:59 -0500
committerHerbert Xu <herbert@gondor.apana.org.au>2018-03-02 11:03:17 -0500
commitd14f0a1fc488af563ec3b3767383190d2b331b5e (patch)
tree579cdc00c95c78a44cd150ceda38b7a0a300514a /crypto
parentd800e3430e51e3450d8fa25b2eb2a50e5e413f29 (diff)
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>
Diffstat (limited to 'crypto')
-rw-r--r--crypto/simd.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/crypto/simd.c b/crypto/simd.c
index 208226d7f908..ea7240be3001 100644
--- a/crypto/simd.c
+++ b/crypto/simd.c
@@ -221,4 +221,54 @@ void simd_skcipher_free(struct simd_skcipher_alg *salg)
221} 221}
222EXPORT_SYMBOL_GPL(simd_skcipher_free); 222EXPORT_SYMBOL_GPL(simd_skcipher_free);
223 223
224int 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
252err_unregister:
253 simd_unregister_skciphers(algs, count, simd_algs);
254 return err;
255}
256EXPORT_SYMBOL_GPL(simd_register_skciphers_compat);
257
258void 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}
272EXPORT_SYMBOL_GPL(simd_unregister_skciphers);
273
224MODULE_LICENSE("GPL"); 274MODULE_LICENSE("GPL");