crypto: inside-secure - hmac(sha384) support
authorAntoine Tenart <antoine.tenart@bootlin.com>
Tue, 29 May 2018 12:13:51 +0000 (14:13 +0200)
committerHerbert Xu <herbert@gondor.apana.org.au>
Fri, 22 Jun 2018 15:03:05 +0000 (23:03 +0800)
This patch adds the hmac(sha384) algorithm support to the Inside Secure
SafeXcel driver.

Signed-off-by: Antoine Tenart <antoine.tenart@bootlin.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
drivers/crypto/inside-secure/safexcel.c
drivers/crypto/inside-secure/safexcel.h
drivers/crypto/inside-secure/safexcel_hash.c

index b02451e0bbb6839fe12073040669c1a28af6df49..5ef8ba7ae29caceb295c552dc6c6c4678e303d8a 100644 (file)
@@ -795,6 +795,7 @@ static struct safexcel_alg_template *safexcel_algs[] = {
        &safexcel_alg_hmac_sha1,
        &safexcel_alg_hmac_sha224,
        &safexcel_alg_hmac_sha256,
+       &safexcel_alg_hmac_sha384,
        &safexcel_alg_hmac_sha512,
        &safexcel_alg_authenc_hmac_sha1_cbc_aes,
        &safexcel_alg_authenc_hmac_sha224_cbc_aes,
index 57abf75e8b6638ef78558f3b225092ee5aaf6144..e002f963ff5a8c3ca75355ea7e850f3921eec925 100644 (file)
@@ -677,6 +677,7 @@ extern struct safexcel_alg_template safexcel_alg_sha512;
 extern struct safexcel_alg_template safexcel_alg_hmac_sha1;
 extern struct safexcel_alg_template safexcel_alg_hmac_sha224;
 extern struct safexcel_alg_template safexcel_alg_hmac_sha256;
+extern struct safexcel_alg_template safexcel_alg_hmac_sha384;
 extern struct safexcel_alg_template safexcel_alg_hmac_sha512;
 extern struct safexcel_alg_template safexcel_alg_authenc_hmac_sha1_cbc_aes;
 extern struct safexcel_alg_template safexcel_alg_authenc_hmac_sha224_cbc_aes;
index 585667a1c259228d422b10581fac71fdd20feaf2..188ba0734337acda8da9732f283395f51015d844 100644 (file)
@@ -1488,3 +1488,59 @@ struct safexcel_alg_template safexcel_alg_hmac_sha512 = {
                },
        },
 };
+
+static int safexcel_hmac_sha384_setkey(struct crypto_ahash *tfm, const u8 *key,
+                                      unsigned int keylen)
+{
+       return safexcel_hmac_alg_setkey(tfm, key, keylen, "safexcel-sha384",
+                                       SHA512_DIGEST_SIZE);
+}
+
+static int safexcel_hmac_sha384_init(struct ahash_request *areq)
+{
+       struct safexcel_ahash_req *req = ahash_request_ctx(areq);
+
+       safexcel_sha384_init(areq);
+       req->digest = CONTEXT_CONTROL_DIGEST_HMAC;
+       return 0;
+}
+
+static int safexcel_hmac_sha384_digest(struct ahash_request *areq)
+{
+       int ret = safexcel_hmac_sha384_init(areq);
+
+       if (ret)
+               return ret;
+
+       return safexcel_ahash_finup(areq);
+}
+
+struct safexcel_alg_template safexcel_alg_hmac_sha384 = {
+       .type = SAFEXCEL_ALG_TYPE_AHASH,
+       .alg.ahash = {
+               .init = safexcel_hmac_sha384_init,
+               .update = safexcel_ahash_update,
+               .final = safexcel_ahash_final,
+               .finup = safexcel_ahash_finup,
+               .digest = safexcel_hmac_sha384_digest,
+               .setkey = safexcel_hmac_sha384_setkey,
+               .export = safexcel_ahash_export,
+               .import = safexcel_ahash_import,
+               .halg = {
+                       .digestsize = SHA384_DIGEST_SIZE,
+                       .statesize = sizeof(struct safexcel_ahash_export_state),
+                       .base = {
+                               .cra_name = "hmac(sha384)",
+                               .cra_driver_name = "safexcel-hmac-sha384",
+                               .cra_priority = 300,
+                               .cra_flags = CRYPTO_ALG_ASYNC |
+                                            CRYPTO_ALG_KERN_DRIVER_ONLY,
+                               .cra_blocksize = SHA384_BLOCK_SIZE,
+                               .cra_ctxsize = sizeof(struct safexcel_ahash_ctx),
+                               .cra_init = safexcel_ahash_cra_init,
+                               .cra_exit = safexcel_ahash_cra_exit,
+                               .cra_module = THIS_MODULE,
+                       },
+               },
+       },
+};