From patchwork Mon Oct 29 09:50:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gilad Ben-Yossef X-Patchwork-Id: 149652 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp3912000ljp; Mon, 29 Oct 2018 02:50:37 -0700 (PDT) X-Google-Smtp-Source: AJdET5c98+u0e7yAVhXsO+hXfs5YaiN/YsynZEoOCUTxHwOA31cryehgnizpWhAm5UTM9urteijl X-Received: by 2002:a17:902:82ca:: with SMTP id u10-v6mr13139602plz.146.1540806637102; Mon, 29 Oct 2018 02:50:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540806637; cv=none; d=google.com; s=arc-20160816; b=PqEgFOIiHSBxuspgedpsRyoYfDhGm+xlDghP17UXbRgWODVvFACxKnBDnRBk9rRGHQ BzBQ1qE+XHSlrCuHYCNKNlpYKTz+TMgQA/FuZmryywteOYcAqvXltZ1S5LEvgGGVNCCb MmUmij63jZNaR2ZA4MDf+uzDXQtOeOYA3IYhhUCcSgbGkL41rf3F85zyW5q0XY2FwrUT bqkihLe6RGwpJ2LWAvwVA2KQHk9o6PtP7OWyy2qsRBdc0ko5gnHkRM3DsTXIm68OTWqj FDuR31AFn8dwdw3+xV4glSiXov/kqmdbdSqCy9qrdfBd80bNuk3pycI7MtnK3BD4QW+i NjRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=CVo4zGzbS+FDP/kTfbj0XmggXSQQO2PYjzJdQI6XMqI=; b=QpUDmaqkiq0oWPslg8RKy9RUMGw0x51K4iJOyzVvsOUAvLhSJBCCudj3oZ0rB5EWkq beO1c04YjT/TIuIpWLCegHjDDwh3sLVWiQtph2D2bMTqsIFk6LFUOWzTIWQNUzQs00Cj 7MDPZUwUhAm1iWAb5WE8keJCKLg1aqtmSvSVurargPxCg0Mz0/oe9xtKdXmjoxZClpUB HmEwWFO7tBUhjx0z1qiSrBTz0NAdXxSBbYujlI0ftnNrev8bkppfmbgFfbOrZUGErNRw eWprZL7SmrT5VirW5iIMUNQrQiexpKkCKfY1i/dyZhXwhm+Adphx9QUOVWr48kxBfM6A uJ0Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f32-v6si19289120pgf.203.2018.10.29.02.50.36; Mon, 29 Oct 2018 02:50:37 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729789AbeJ2Sia (ORCPT + 2 others); Mon, 29 Oct 2018 14:38:30 -0400 Received: from foss.arm.com ([217.140.101.70]:37796 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729509AbeJ2Sia (ORCPT ); Mon, 29 Oct 2018 14:38:30 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id C870E1596; Mon, 29 Oct 2018 02:50:34 -0700 (PDT) Received: from sugar.kfn.arm.com (E110176.Arm.com [10.50.4.178]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 8EF1F3F557; Mon, 29 Oct 2018 02:50:32 -0700 (PDT) From: Gilad Ben-Yossef To: Herbert Xu , "David S. Miller" , Rob Herring , Mark Rutland Cc: Ofir Drang , Yael Chemla , linux-crypto@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 3/3] crypto: ccree: add SM4 support Date: Mon, 29 Oct 2018 09:50:14 +0000 Message-Id: <1540806616-5483-4-git-send-email-gilad@benyossef.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1540806616-5483-1-git-send-email-gilad@benyossef.com> References: <1540806616-5483-1-git-send-email-gilad@benyossef.com> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Add support for SM4 cipher in CryptoCell 713. Signed-off-by: Gilad Ben-Yossef --- drivers/crypto/Kconfig | 1 + drivers/crypto/ccree/cc_cipher.c | 66 +++++++++++++++++++++++++++++++++ drivers/crypto/ccree/cc_hw_queue_defs.h | 3 ++ 3 files changed, 70 insertions(+) -- 2.7.4 diff --git a/drivers/crypto/Kconfig b/drivers/crypto/Kconfig index bea4de6..c7e6f5d 100644 --- a/drivers/crypto/Kconfig +++ b/drivers/crypto/Kconfig @@ -751,6 +751,7 @@ config CRYPTO_DEV_CCREE select CRYPTO_ECB select CRYPTO_CTR select CRYPTO_XTS + select CRYPTO_SM4 help Say 'Y' to enable a driver for the REE interface of the Arm TrustZone CryptoCell family of processors. Currently the diff --git a/drivers/crypto/ccree/cc_cipher.c b/drivers/crypto/ccree/cc_cipher.c index 7623b299..989e70f 100644 --- a/drivers/crypto/ccree/cc_cipher.c +++ b/drivers/crypto/ccree/cc_cipher.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include "cc_driver.h" @@ -83,6 +84,9 @@ static int validate_keys_sizes(struct cc_cipher_ctx *ctx_p, u32 size) if (size == DES3_EDE_KEY_SIZE || size == DES_KEY_SIZE) return 0; break; + case S_DIN_to_SM4: + if (size == SM4_KEY_SIZE) + return 0; default: break; } @@ -122,6 +126,17 @@ static int validate_data_size(struct cc_cipher_ctx *ctx_p, if (IS_ALIGNED(size, DES_BLOCK_SIZE)) return 0; break; + case S_DIN_to_SM4: + switch (ctx_p->cipher_mode) { + case DRV_CIPHER_CTR: + return 0; + case DRV_CIPHER_ECB: + case DRV_CIPHER_CBC: + if (IS_ALIGNED(size, SM4_BLOCK_SIZE)) + return 0; + default: + break; + } default: break; } @@ -522,6 +537,9 @@ static void cc_setup_cipher_data(struct crypto_tfm *tfm, case S_DIN_to_DES: flow_mode = DIN_DES_DOUT; break; + case S_DIN_to_SM4: + flow_mode = DIN_SM4_DOUT; + break; default: dev_err(dev, "invalid flow mode, flow_mode = %d\n", flow_mode); return; @@ -1324,6 +1342,54 @@ static const struct cc_alg_template skcipher_algs[] = { .flow_mode = S_DIN_to_DES, .min_hw_rev = CC_HW_REV_630, }, + { + .name = "cbc(sm4)", + .driver_name = "cbc-sm4-ccree", + .blocksize = SM4_BLOCK_SIZE, + .template_skcipher = { + .setkey = cc_cipher_setkey, + .encrypt = cc_cipher_encrypt, + .decrypt = cc_cipher_decrypt, + .min_keysize = SM4_KEY_SIZE, + .max_keysize = SM4_KEY_SIZE, + .ivsize = SM4_BLOCK_SIZE, + }, + .cipher_mode = DRV_CIPHER_CBC, + .flow_mode = S_DIN_to_SM4, + .min_hw_rev = CC_HW_REV_713, + }, + { + .name = "ecb(sm4)", + .driver_name = "ecb-sm4-ccree", + .blocksize = SM4_BLOCK_SIZE, + .template_skcipher = { + .setkey = cc_cipher_setkey, + .encrypt = cc_cipher_encrypt, + .decrypt = cc_cipher_decrypt, + .min_keysize = SM4_KEY_SIZE, + .max_keysize = SM4_KEY_SIZE, + .ivsize = 0, + }, + .cipher_mode = DRV_CIPHER_ECB, + .flow_mode = S_DIN_to_SM4, + .min_hw_rev = CC_HW_REV_713, + }, + { + .name = "ctr(sm4)", + .driver_name = "ctr-sm4-ccree", + .blocksize = SM4_BLOCK_SIZE, + .template_skcipher = { + .setkey = cc_cipher_setkey, + .encrypt = cc_cipher_encrypt, + .decrypt = cc_cipher_decrypt, + .min_keysize = SM4_KEY_SIZE, + .max_keysize = SM4_KEY_SIZE, + .ivsize = SM4_BLOCK_SIZE, + }, + .cipher_mode = DRV_CIPHER_CTR, + .flow_mode = S_DIN_to_SM4, + .min_hw_rev = CC_HW_REV_713, + }, }; static struct cc_crypto_alg *cc_create_alg(const struct cc_alg_template *tmpl, diff --git a/drivers/crypto/ccree/cc_hw_queue_defs.h b/drivers/crypto/ccree/cc_hw_queue_defs.h index 45985b9..f719ff9c 100644 --- a/drivers/crypto/ccree/cc_hw_queue_defs.h +++ b/drivers/crypto/ccree/cc_hw_queue_defs.h @@ -107,6 +107,7 @@ enum cc_flow_mode { AES_to_AES_to_HASH_and_DOUT = 13, AES_to_AES_to_HASH = 14, AES_to_HASH_and_AES = 15, + DIN_SM4_DOUT = 16, DIN_AES_AESMAC = 17, HASH_to_DOUT = 18, /* setup flows */ @@ -114,9 +115,11 @@ enum cc_flow_mode { S_DIN_to_AES2 = 33, S_DIN_to_DES = 34, S_DIN_to_RC4 = 35, + S_DIN_to_SM4 = 36, S_DIN_to_HASH = 37, S_AES_to_DOUT = 38, S_AES2_to_DOUT = 39, + S_SM4_to_DOUT = 40, S_RC4_to_DOUT = 41, S_DES_to_DOUT = 42, S_HASH_to_DOUT = 43,