]> git.baikalelectronics.ru Git - kernel.git/commitdiff
crypto: inside-secure - Add support for the ofb(sm4) skcipher
authorPascal van Leeuwen <pascalvanl@gmail.com>
Fri, 13 Sep 2019 09:10:38 +0000 (11:10 +0200)
committerHerbert Xu <herbert@gondor.apana.org.au>
Fri, 4 Oct 2019 15:06:04 +0000 (01:06 +1000)
This patch adds support for SM4 in OFB mode, i.e. skcipher ofb(sm4).

changes since v1:
- nothing

Signed-off-by: Pascal van Leeuwen <pvanleeuwen@verimatrix.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_cipher.c

index ac1d5b89cd8d5448d721970365e3a25a90463c1c..e3873f2db7d372fc174547940fef64228ee0e991 100644 (file)
@@ -1180,6 +1180,7 @@ static struct safexcel_alg_template *safexcel_algs[] = {
        &safexcel_alg_hmac_sm3,
        &safexcel_alg_ecb_sm4,
        &safexcel_alg_cbc_sm4,
+       &safexcel_alg_ofb_sm4,
 };
 
 static int safexcel_register_algorithms(struct safexcel_crypto_priv *priv)
index 7c63590f4e5d9c31975aa0fbb6208d49f509c0a1..765f5e8706bda0a05b1e6ec354a97c5974f7e0cb 100644 (file)
@@ -881,5 +881,6 @@ extern struct safexcel_alg_template safexcel_alg_sm3;
 extern struct safexcel_alg_template safexcel_alg_hmac_sm3;
 extern struct safexcel_alg_template safexcel_alg_ecb_sm4;
 extern struct safexcel_alg_template safexcel_alg_cbc_sm4;
+extern struct safexcel_alg_template safexcel_alg_ofb_sm4;
 
 #endif
index f5d39e1a74e75a562451e96241ca4c0b7456c28a..b0e4bfb2e5184bc95405f4cef95831dc90b33ee0 100644 (file)
@@ -2743,3 +2743,39 @@ struct safexcel_alg_template safexcel_alg_cbc_sm4 = {
                },
        },
 };
+
+static int safexcel_skcipher_sm4_ofb_cra_init(struct crypto_tfm *tfm)
+{
+       struct safexcel_cipher_ctx *ctx = crypto_tfm_ctx(tfm);
+
+       safexcel_skcipher_cra_init(tfm);
+       ctx->alg  = SAFEXCEL_SM4;
+       ctx->mode = CONTEXT_CONTROL_CRYPTO_MODE_OFB;
+       return 0;
+}
+
+struct safexcel_alg_template safexcel_alg_ofb_sm4 = {
+       .type = SAFEXCEL_ALG_TYPE_SKCIPHER,
+       .algo_mask = SAFEXCEL_ALG_SM4 | SAFEXCEL_ALG_AES_XFB,
+       .alg.skcipher = {
+               .setkey = safexcel_skcipher_sm4_setkey,
+               .encrypt = safexcel_encrypt,
+               .decrypt = safexcel_decrypt,
+               .min_keysize = SM4_KEY_SIZE,
+               .max_keysize = SM4_KEY_SIZE,
+               .ivsize = SM4_BLOCK_SIZE,
+               .base = {
+                       .cra_name = "ofb(sm4)",
+                       .cra_driver_name = "safexcel-ofb-sm4",
+                       .cra_priority = SAFEXCEL_CRA_PRIORITY,
+                       .cra_flags = CRYPTO_ALG_ASYNC |
+                                    CRYPTO_ALG_KERN_DRIVER_ONLY,
+                       .cra_blocksize = 1,
+                       .cra_ctxsize = sizeof(struct safexcel_cipher_ctx),
+                       .cra_alignmask = 0,
+                       .cra_init = safexcel_skcipher_sm4_ofb_cra_init,
+                       .cra_exit = safexcel_skcipher_cra_exit,
+                       .cra_module = THIS_MODULE,
+               },
+       },
+};