]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
crypto: talitos - consolidate common cra_* assignments
authorKim Phillips <kim.phillips@freescale.com>
Thu, 9 Aug 2012 01:33:34 +0000 (20:33 -0500)
committerHerbert Xu <herbert@gondor.apana.org.au>
Mon, 20 Aug 2012 08:40:01 +0000 (16:40 +0800)
the entry points and geniv definitions for all aead,
ablkcipher, and hash algorithms are all common; move them to a
single assignment in talitos_alg_alloc().

This assumes it's ok to assign a setkey() on non-hmac algs.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
drivers/crypto/talitos.c

index b7a69690839ecf7df03ffddb98e4f45a2da64cde..4667a630bdec6354b64158ed51805987468bcc86 100644 (file)
@@ -1915,12 +1915,6 @@ static struct talitos_alg_template driver_algs[] = {
                        .cra_blocksize = AES_BLOCK_SIZE,
                        .cra_flags = CRYPTO_ALG_TYPE_AEAD | CRYPTO_ALG_ASYNC,
                        .cra_aead = {
-                               .setkey = aead_setkey,
-                               .setauthsize = aead_setauthsize,
-                               .encrypt = aead_encrypt,
-                               .decrypt = aead_decrypt,
-                               .givencrypt = aead_givencrypt,
-                               .geniv = "<built-in>",
                                .ivsize = AES_BLOCK_SIZE,
                                .maxauthsize = SHA1_DIGEST_SIZE,
                        }
@@ -1940,12 +1934,6 @@ static struct talitos_alg_template driver_algs[] = {
                        .cra_blocksize = DES3_EDE_BLOCK_SIZE,
                        .cra_flags = CRYPTO_ALG_TYPE_AEAD | CRYPTO_ALG_ASYNC,
                        .cra_aead = {
-                               .setkey = aead_setkey,
-                               .setauthsize = aead_setauthsize,
-                               .encrypt = aead_encrypt,
-                               .decrypt = aead_decrypt,
-                               .givencrypt = aead_givencrypt,
-                               .geniv = "<built-in>",
                                .ivsize = DES3_EDE_BLOCK_SIZE,
                                .maxauthsize = SHA1_DIGEST_SIZE,
                        }
@@ -1966,12 +1954,6 @@ static struct talitos_alg_template driver_algs[] = {
                        .cra_blocksize = AES_BLOCK_SIZE,
                        .cra_flags = CRYPTO_ALG_TYPE_AEAD | CRYPTO_ALG_ASYNC,
                        .cra_aead = {
-                               .setkey = aead_setkey,
-                               .setauthsize = aead_setauthsize,
-                               .encrypt = aead_encrypt,
-                               .decrypt = aead_decrypt,
-                               .givencrypt = aead_givencrypt,
-                               .geniv = "<built-in>",
                                .ivsize = AES_BLOCK_SIZE,
                                .maxauthsize = SHA224_DIGEST_SIZE,
                        }
@@ -1991,12 +1973,6 @@ static struct talitos_alg_template driver_algs[] = {
                        .cra_blocksize = DES3_EDE_BLOCK_SIZE,
                        .cra_flags = CRYPTO_ALG_TYPE_AEAD | CRYPTO_ALG_ASYNC,
                        .cra_aead = {
-                               .setkey = aead_setkey,
-                               .setauthsize = aead_setauthsize,
-                               .encrypt = aead_encrypt,
-                               .decrypt = aead_decrypt,
-                               .givencrypt = aead_givencrypt,
-                               .geniv = "<built-in>",
                                .ivsize = DES3_EDE_BLOCK_SIZE,
                                .maxauthsize = SHA224_DIGEST_SIZE,
                        }
@@ -2017,12 +1993,6 @@ static struct talitos_alg_template driver_algs[] = {
                        .cra_blocksize = AES_BLOCK_SIZE,
                        .cra_flags = CRYPTO_ALG_TYPE_AEAD | CRYPTO_ALG_ASYNC,
                        .cra_aead = {
-                               .setkey = aead_setkey,
-                               .setauthsize = aead_setauthsize,
-                               .encrypt = aead_encrypt,
-                               .decrypt = aead_decrypt,
-                               .givencrypt = aead_givencrypt,
-                               .geniv = "<built-in>",
                                .ivsize = AES_BLOCK_SIZE,
                                .maxauthsize = SHA256_DIGEST_SIZE,
                        }
@@ -2042,12 +2012,6 @@ static struct talitos_alg_template driver_algs[] = {
                        .cra_blocksize = DES3_EDE_BLOCK_SIZE,
                        .cra_flags = CRYPTO_ALG_TYPE_AEAD | CRYPTO_ALG_ASYNC,
                        .cra_aead = {
-                               .setkey = aead_setkey,
-                               .setauthsize = aead_setauthsize,
-                               .encrypt = aead_encrypt,
-                               .decrypt = aead_decrypt,
-                               .givencrypt = aead_givencrypt,
-                               .geniv = "<built-in>",
                                .ivsize = DES3_EDE_BLOCK_SIZE,
                                .maxauthsize = SHA256_DIGEST_SIZE,
                        }
@@ -2068,12 +2032,6 @@ static struct talitos_alg_template driver_algs[] = {
                        .cra_blocksize = AES_BLOCK_SIZE,
                        .cra_flags = CRYPTO_ALG_TYPE_AEAD | CRYPTO_ALG_ASYNC,
                        .cra_aead = {
-                               .setkey = aead_setkey,
-                               .setauthsize = aead_setauthsize,
-                               .encrypt = aead_encrypt,
-                               .decrypt = aead_decrypt,
-                               .givencrypt = aead_givencrypt,
-                               .geniv = "<built-in>",
                                .ivsize = AES_BLOCK_SIZE,
                                .maxauthsize = SHA384_DIGEST_SIZE,
                        }
@@ -2093,12 +2051,6 @@ static struct talitos_alg_template driver_algs[] = {
                        .cra_blocksize = DES3_EDE_BLOCK_SIZE,
                        .cra_flags = CRYPTO_ALG_TYPE_AEAD | CRYPTO_ALG_ASYNC,
                        .cra_aead = {
-                               .setkey = aead_setkey,
-                               .setauthsize = aead_setauthsize,
-                               .encrypt = aead_encrypt,
-                               .decrypt = aead_decrypt,
-                               .givencrypt = aead_givencrypt,
-                               .geniv = "<built-in>",
                                .ivsize = DES3_EDE_BLOCK_SIZE,
                                .maxauthsize = SHA384_DIGEST_SIZE,
                        }
@@ -2119,12 +2071,6 @@ static struct talitos_alg_template driver_algs[] = {
                        .cra_blocksize = AES_BLOCK_SIZE,
                        .cra_flags = CRYPTO_ALG_TYPE_AEAD | CRYPTO_ALG_ASYNC,
                        .cra_aead = {
-                               .setkey = aead_setkey,
-                               .setauthsize = aead_setauthsize,
-                               .encrypt = aead_encrypt,
-                               .decrypt = aead_decrypt,
-                               .givencrypt = aead_givencrypt,
-                               .geniv = "<built-in>",
                                .ivsize = AES_BLOCK_SIZE,
                                .maxauthsize = SHA512_DIGEST_SIZE,
                        }
@@ -2144,12 +2090,6 @@ static struct talitos_alg_template driver_algs[] = {
                        .cra_blocksize = DES3_EDE_BLOCK_SIZE,
                        .cra_flags = CRYPTO_ALG_TYPE_AEAD | CRYPTO_ALG_ASYNC,
                        .cra_aead = {
-                               .setkey = aead_setkey,
-                               .setauthsize = aead_setauthsize,
-                               .encrypt = aead_encrypt,
-                               .decrypt = aead_decrypt,
-                               .givencrypt = aead_givencrypt,
-                               .geniv = "<built-in>",
                                .ivsize = DES3_EDE_BLOCK_SIZE,
                                .maxauthsize = SHA512_DIGEST_SIZE,
                        }
@@ -2170,12 +2110,6 @@ static struct talitos_alg_template driver_algs[] = {
                        .cra_blocksize = AES_BLOCK_SIZE,
                        .cra_flags = CRYPTO_ALG_TYPE_AEAD | CRYPTO_ALG_ASYNC,
                        .cra_aead = {
-                               .setkey = aead_setkey,
-                               .setauthsize = aead_setauthsize,
-                               .encrypt = aead_encrypt,
-                               .decrypt = aead_decrypt,
-                               .givencrypt = aead_givencrypt,
-                               .geniv = "<built-in>",
                                .ivsize = AES_BLOCK_SIZE,
                                .maxauthsize = MD5_DIGEST_SIZE,
                        }
@@ -2195,12 +2129,6 @@ static struct talitos_alg_template driver_algs[] = {
                        .cra_blocksize = DES3_EDE_BLOCK_SIZE,
                        .cra_flags = CRYPTO_ALG_TYPE_AEAD | CRYPTO_ALG_ASYNC,
                        .cra_aead = {
-                               .setkey = aead_setkey,
-                               .setauthsize = aead_setauthsize,
-                               .encrypt = aead_encrypt,
-                               .decrypt = aead_decrypt,
-                               .givencrypt = aead_givencrypt,
-                               .geniv = "<built-in>",
                                .ivsize = DES3_EDE_BLOCK_SIZE,
                                .maxauthsize = MD5_DIGEST_SIZE,
                        }
@@ -2223,10 +2151,6 @@ static struct talitos_alg_template driver_algs[] = {
                        .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER |
                                      CRYPTO_ALG_ASYNC,
                        .cra_ablkcipher = {
-                               .setkey = ablkcipher_setkey,
-                               .encrypt = ablkcipher_encrypt,
-                               .decrypt = ablkcipher_decrypt,
-                               .geniv = "eseqiv",
                                .min_keysize = AES_MIN_KEY_SIZE,
                                .max_keysize = AES_MAX_KEY_SIZE,
                                .ivsize = AES_BLOCK_SIZE,
@@ -2244,10 +2168,6 @@ static struct talitos_alg_template driver_algs[] = {
                        .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER |
                                      CRYPTO_ALG_ASYNC,
                        .cra_ablkcipher = {
-                               .setkey = ablkcipher_setkey,
-                               .encrypt = ablkcipher_encrypt,
-                               .decrypt = ablkcipher_decrypt,
-                               .geniv = "eseqiv",
                                .min_keysize = DES3_EDE_KEY_SIZE,
                                .max_keysize = DES3_EDE_KEY_SIZE,
                                .ivsize = DES3_EDE_BLOCK_SIZE,
@@ -2261,11 +2181,6 @@ static struct talitos_alg_template driver_algs[] = {
        /* AHASH algorithms. */
        {       .type = CRYPTO_ALG_TYPE_AHASH,
                .alg.hash = {
-                       .init = ahash_init,
-                       .update = ahash_update,
-                       .final = ahash_final,
-                       .finup = ahash_finup,
-                       .digest = ahash_digest,
                        .halg.digestsize = MD5_DIGEST_SIZE,
                        .halg.base = {
                                .cra_name = "md5",
@@ -2281,11 +2196,6 @@ static struct talitos_alg_template driver_algs[] = {
        },
        {       .type = CRYPTO_ALG_TYPE_AHASH,
                .alg.hash = {
-                       .init = ahash_init,
-                       .update = ahash_update,
-                       .final = ahash_final,
-                       .finup = ahash_finup,
-                       .digest = ahash_digest,
                        .halg.digestsize = SHA1_DIGEST_SIZE,
                        .halg.base = {
                                .cra_name = "sha1",
@@ -2301,11 +2211,6 @@ static struct talitos_alg_template driver_algs[] = {
        },
        {       .type = CRYPTO_ALG_TYPE_AHASH,
                .alg.hash = {
-                       .init = ahash_init,
-                       .update = ahash_update,
-                       .final = ahash_final,
-                       .finup = ahash_finup,
-                       .digest = ahash_digest,
                        .halg.digestsize = SHA224_DIGEST_SIZE,
                        .halg.base = {
                                .cra_name = "sha224",
@@ -2321,11 +2226,6 @@ static struct talitos_alg_template driver_algs[] = {
        },
        {       .type = CRYPTO_ALG_TYPE_AHASH,
                .alg.hash = {
-                       .init = ahash_init,
-                       .update = ahash_update,
-                       .final = ahash_final,
-                       .finup = ahash_finup,
-                       .digest = ahash_digest,
                        .halg.digestsize = SHA256_DIGEST_SIZE,
                        .halg.base = {
                                .cra_name = "sha256",
@@ -2341,11 +2241,6 @@ static struct talitos_alg_template driver_algs[] = {
        },
        {       .type = CRYPTO_ALG_TYPE_AHASH,
                .alg.hash = {
-                       .init = ahash_init,
-                       .update = ahash_update,
-                       .final = ahash_final,
-                       .finup = ahash_finup,
-                       .digest = ahash_digest,
                        .halg.digestsize = SHA384_DIGEST_SIZE,
                        .halg.base = {
                                .cra_name = "sha384",
@@ -2361,11 +2256,6 @@ static struct talitos_alg_template driver_algs[] = {
        },
        {       .type = CRYPTO_ALG_TYPE_AHASH,
                .alg.hash = {
-                       .init = ahash_init,
-                       .update = ahash_update,
-                       .final = ahash_final,
-                       .finup = ahash_finup,
-                       .digest = ahash_digest,
                        .halg.digestsize = SHA512_DIGEST_SIZE,
                        .halg.base = {
                                .cra_name = "sha512",
@@ -2381,12 +2271,6 @@ static struct talitos_alg_template driver_algs[] = {
        },
        {       .type = CRYPTO_ALG_TYPE_AHASH,
                .alg.hash = {
-                       .init = ahash_init,
-                       .update = ahash_update,
-                       .final = ahash_final,
-                       .finup = ahash_finup,
-                       .digest = ahash_digest,
-                       .setkey = ahash_setkey,
                        .halg.digestsize = MD5_DIGEST_SIZE,
                        .halg.base = {
                                .cra_name = "hmac(md5)",
@@ -2402,12 +2286,6 @@ static struct talitos_alg_template driver_algs[] = {
        },
        {       .type = CRYPTO_ALG_TYPE_AHASH,
                .alg.hash = {
-                       .init = ahash_init,
-                       .update = ahash_update,
-                       .final = ahash_final,
-                       .finup = ahash_finup,
-                       .digest = ahash_digest,
-                       .setkey = ahash_setkey,
                        .halg.digestsize = SHA1_DIGEST_SIZE,
                        .halg.base = {
                                .cra_name = "hmac(sha1)",
@@ -2423,12 +2301,6 @@ static struct talitos_alg_template driver_algs[] = {
        },
        {       .type = CRYPTO_ALG_TYPE_AHASH,
                .alg.hash = {
-                       .init = ahash_init,
-                       .update = ahash_update,
-                       .final = ahash_final,
-                       .finup = ahash_finup,
-                       .digest = ahash_digest,
-                       .setkey = ahash_setkey,
                        .halg.digestsize = SHA224_DIGEST_SIZE,
                        .halg.base = {
                                .cra_name = "hmac(sha224)",
@@ -2444,12 +2316,6 @@ static struct talitos_alg_template driver_algs[] = {
        },
        {       .type = CRYPTO_ALG_TYPE_AHASH,
                .alg.hash = {
-                       .init = ahash_init,
-                       .update = ahash_update,
-                       .final = ahash_final,
-                       .finup = ahash_finup,
-                       .digest = ahash_digest,
-                       .setkey = ahash_setkey,
                        .halg.digestsize = SHA256_DIGEST_SIZE,
                        .halg.base = {
                                .cra_name = "hmac(sha256)",
@@ -2465,12 +2331,6 @@ static struct talitos_alg_template driver_algs[] = {
        },
        {       .type = CRYPTO_ALG_TYPE_AHASH,
                .alg.hash = {
-                       .init = ahash_init,
-                       .update = ahash_update,
-                       .final = ahash_final,
-                       .finup = ahash_finup,
-                       .digest = ahash_digest,
-                       .setkey = ahash_setkey,
                        .halg.digestsize = SHA384_DIGEST_SIZE,
                        .halg.base = {
                                .cra_name = "hmac(sha384)",
@@ -2486,12 +2346,6 @@ static struct talitos_alg_template driver_algs[] = {
        },
        {       .type = CRYPTO_ALG_TYPE_AHASH,
                .alg.hash = {
-                       .init = ahash_init,
-                       .update = ahash_update,
-                       .final = ahash_final,
-                       .finup = ahash_finup,
-                       .digest = ahash_digest,
-                       .setkey = ahash_setkey,
                        .halg.digestsize = SHA512_DIGEST_SIZE,
                        .halg.base = {
                                .cra_name = "hmac(sha512)",
@@ -2657,16 +2511,33 @@ static struct talitos_crypto_alg *talitos_alg_alloc(struct device *dev,
                alg = &t_alg->algt.alg.crypto;
                alg->cra_init = talitos_cra_init;
                alg->cra_type = &crypto_ablkcipher_type;
+               alg->cra_ablkcipher.setkey = ablkcipher_setkey;
+               alg->cra_ablkcipher.encrypt = ablkcipher_encrypt;
+               alg->cra_ablkcipher.decrypt = ablkcipher_decrypt;
+               alg->cra_ablkcipher.geniv = "eseqiv";
                break;
        case CRYPTO_ALG_TYPE_AEAD:
                alg = &t_alg->algt.alg.crypto;
                alg->cra_init = talitos_cra_init_aead;
                alg->cra_type = &crypto_aead_type;
+               alg->cra_aead.setkey = aead_setkey;
+               alg->cra_aead.setauthsize = aead_setauthsize;
+               alg->cra_aead.encrypt = aead_encrypt;
+               alg->cra_aead.decrypt = aead_decrypt;
+               alg->cra_aead.givencrypt = aead_givencrypt;
+               alg->cra_aead.geniv = "<built-in>";
                break;
        case CRYPTO_ALG_TYPE_AHASH:
                alg = &t_alg->algt.alg.hash.halg.base;
                alg->cra_init = talitos_cra_init_ahash;
                alg->cra_type = &crypto_ahash_type;
+               t_alg->algt.alg.hash.init = ahash_init;
+               t_alg->algt.alg.hash.update = ahash_update;
+               t_alg->algt.alg.hash.final = ahash_final;
+               t_alg->algt.alg.hash.finup = ahash_finup;
+               t_alg->algt.alg.hash.digest = ahash_digest;
+               t_alg->algt.alg.hash.setkey = ahash_setkey;
+
                if (!(priv->features & TALITOS_FTR_HMAC_OK) &&
                    !strncmp(alg->cra_name, "hmac", 4)) {
                        kfree(t_alg);