crypto: x86/aesni - convert to use skcipher SIMD bulk registration
authorEric Biggers <ebiggers@google.com>
Sun, 10 Mar 2019 19:00:51 +0000 (12:00 -0700)
committerHerbert Xu <herbert@gondor.apana.org.au>
Fri, 22 Mar 2019 12:57:26 +0000 (20:57 +0800)
Convert the AES-NI glue code to use simd_register_skciphers_compat() to
create SIMD wrappers for all the internal skcipher algorithms at once,
rather than wrapping each one individually.  This simplifies the code.

Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
arch/x86/crypto/aesni-intel_glue.c

index 1e3d2102033a066c14c01b453744dca288847fbe..451918cc5f739f6524b1c12124cdca56a8aa79b7 100644 (file)
@@ -1253,23 +1253,9 @@ static const struct x86_cpu_id aesni_cpu_id[] = {
 };
 MODULE_DEVICE_TABLE(x86cpu, aesni_cpu_id);
 
-static void aesni_free_simds(void)
-{
-       int i;
-
-       for (i = 0; i < ARRAY_SIZE(aesni_simd_skciphers) &&
-                   aesni_simd_skciphers[i]; i++)
-               simd_skcipher_free(aesni_simd_skciphers[i]);
-}
-
 static int __init aesni_init(void)
 {
-       struct simd_skcipher_alg *simd;
-       const char *basename;
-       const char *algname;
-       const char *drvname;
        int err;
-       int i;
 
        if (!x86_match_cpu(aesni_cpu_id))
                return -ENODEV;
@@ -1304,8 +1290,9 @@ static int __init aesni_init(void)
        if (err)
                return err;
 
-       err = crypto_register_skciphers(aesni_skciphers,
-                                       ARRAY_SIZE(aesni_skciphers));
+       err = simd_register_skciphers_compat(aesni_skciphers,
+                                            ARRAY_SIZE(aesni_skciphers),
+                                            aesni_simd_skciphers);
        if (err)
                goto unregister_algs;
 
@@ -1314,26 +1301,11 @@ static int __init aesni_init(void)
        if (err)
                goto unregister_skciphers;
 
-       for (i = 0; i < ARRAY_SIZE(aesni_skciphers); i++) {
-               algname = aesni_skciphers[i].base.cra_name + 2;
-               drvname = aesni_skciphers[i].base.cra_driver_name + 2;
-               basename = aesni_skciphers[i].base.cra_driver_name;
-               simd = simd_skcipher_create_compat(algname, drvname, basename);
-               err = PTR_ERR(simd);
-               if (IS_ERR(simd))
-                       goto unregister_simds;
-
-               aesni_simd_skciphers[i] = simd;
-       }
-
        return 0;
 
-unregister_simds:
-       aesni_free_simds();
-       crypto_unregister_aeads(aesni_aead_algs, ARRAY_SIZE(aesni_aead_algs));
 unregister_skciphers:
-       crypto_unregister_skciphers(aesni_skciphers,
-                                   ARRAY_SIZE(aesni_skciphers));
+       simd_unregister_skciphers(aesni_skciphers, ARRAY_SIZE(aesni_skciphers),
+                                 aesni_simd_skciphers);
 unregister_algs:
        crypto_unregister_algs(aesni_algs, ARRAY_SIZE(aesni_algs));
        return err;
@@ -1341,10 +1313,9 @@ unregister_algs:
 
 static void __exit aesni_exit(void)
 {
-       aesni_free_simds();
        crypto_unregister_aeads(aesni_aead_algs, ARRAY_SIZE(aesni_aead_algs));
-       crypto_unregister_skciphers(aesni_skciphers,
-                                   ARRAY_SIZE(aesni_skciphers));
+       simd_unregister_skciphers(aesni_skciphers, ARRAY_SIZE(aesni_skciphers),
+                                 aesni_simd_skciphers);
        crypto_unregister_algs(aesni_algs, ARRAY_SIZE(aesni_algs));
 }