Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp2098711pxf; Sat, 27 Mar 2021 02:36:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwnCfDi7zwX1XiOrM3GAjYmiAlIf/jLDcGBVnniiTJZGsFwjfkGZgyFOK2duoEovESS+zff X-Received: by 2002:a17:906:1494:: with SMTP id x20mr19375724ejc.101.1616837768292; Sat, 27 Mar 2021 02:36:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616837768; cv=none; d=google.com; s=arc-20160816; b=tcGZEVwoCcxBrxmF/gJPKUFia6l36nj7GyiLBppC3wMguPTmRXrKIZvq/YKdp18ZfX bAcnZj7jVYydAmfpdvPoXaoRhz95Uf4r74bbQkzbiikUG8pAg7bpXp6eHnnxlBBPvdCG sj/TD5dDAodoFf654a73S1GiV0n/mBp3P4GzhxKTF4PDQsL8f6tgjIheWF45CYEn++u2 phrGBI9YCCaMPYDxghwqUViC5kJURWfdTuY0wrQSa/RKou0gbBBxUv17JwoVng1Zydue SaQA2L2kJw+kX/dx+03MN7XXQDM+C+vqRHC4Ipec19uSvN4yRJlyGFaxilzRQFwcb/sa kEBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=tEGV93CY3mKM1eAO+kUQDh06Y+NK02FYa7SKjHZARFc=; b=IcXGGpKXvcSHYBFzlswNHUlT9yYyUeB7niOTR5rB7cPzz0n7gP6E5OdkyLSBeq9xW7 iQal0mx+9ugCv99ZyUaLTzoxKNqnoUlkfpsJ1LhBYyjeB/24rIarmB7nlTmHEK1YP5dC a8Sdy1599ClFgUiYzY+Szldr+NinEWPqBdB424rJ7MI2eM9eKjgmYYnUIAN1+NnrrcPs jK/S0wa45/gHd9kdxXln+eppVofw1OuV+oPt5jP3gPka6HxpDQnF8Sh2HIwjnwbK17Dy 7v55qJeSm8Lm1IWGD8BcahNigfqzJzxHN1znmTYJga7RpeUianhPOWKa1J4hkfSWwMDy FNXw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s16si2795952eju.415.2021.03.27.02.35.46; Sat, 27 Mar 2021 02:36:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231329AbhC0JcE (ORCPT + 99 others); Sat, 27 Mar 2021 05:32:04 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:15353 "EHLO szxga07-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230350AbhC0JcB (ORCPT ); Sat, 27 Mar 2021 05:32:01 -0400 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4F6tpn2m5zz8vRN; Sat, 27 Mar 2021 17:29:53 +0800 (CST) Received: from huawei.com (10.67.165.24) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.498.0; Sat, 27 Mar 2021 17:31:45 +0800 From: Longfang Liu To: , CC: , , Subject: [PATCH] crypto: hisilicon/sec - Fixes AES algorithm mode parameter problem Date: Sat, 27 Mar 2021 17:29:18 +0800 Message-ID: <1616837358-15112-2-git-send-email-liulongfang@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1616837358-15112-1-git-send-email-liulongfang@huawei.com> References: <1616837358-15112-1-git-send-email-liulongfang@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.67.165.24] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The input data of the ECB (AES) algorithm needs to be aligned with 16 bytes, and the input data of the XTS (AES) algorithm is at least 16 bytes. Otherwise the SEC hardware will go wrong. Signed-off-by: Longfang Liu --- drivers/crypto/hisilicon/sec2/sec_crypto.c | 37 ++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/drivers/crypto/hisilicon/sec2/sec_crypto.c b/drivers/crypto/hisilicon/sec2/sec_crypto.c index c74082c..71c0125 100644 --- a/drivers/crypto/hisilicon/sec2/sec_crypto.c +++ b/drivers/crypto/hisilicon/sec2/sec_crypto.c @@ -1397,6 +1397,36 @@ static int sec_aead_sha512_ctx_init(struct crypto_aead *tfm) return sec_aead_ctx_init(tfm, "sha512"); } + +static int sec_skcipher_cryptlen_ckeck(struct sec_ctx *ctx, + struct sec_req *sreq) +{ + u32 cryptlen = sreq->c_req.sk_req->cryptlen; + struct device *dev = ctx->dev; + u8 c_mode = ctx->c_ctx.c_mode; + int ret = 0; + + switch (c_mode) { + case SEC_CMODE_XTS: + if (unlikely(cryptlen < AES_BLOCK_SIZE)) { + dev_err(dev, "skcipher XTS mode input length error!\n"); + ret = -EINVAL; + } + break; + case SEC_CMODE_ECB: + case SEC_CMODE_CBC: + if (unlikely(cryptlen & (AES_BLOCK_SIZE - 1))) { + dev_err(dev, "skcipher AES input length error!\n"); + ret = -EINVAL; + } + break; + default: + ret = -EINVAL; + } + + return ret; +} + static int sec_skcipher_param_check(struct sec_ctx *ctx, struct sec_req *sreq) { struct skcipher_request *sk_req = sreq->c_req.sk_req; @@ -1421,12 +1451,9 @@ static int sec_skcipher_param_check(struct sec_ctx *ctx, struct sec_req *sreq) } return 0; } else if (c_alg == SEC_CALG_AES || c_alg == SEC_CALG_SM4) { - if (unlikely(sk_req->cryptlen & (AES_BLOCK_SIZE - 1))) { - dev_err(dev, "skcipher aes input length error!\n"); - return -EINVAL; - } - return 0; + return sec_skcipher_cryptlen_ckeck(ctx, sreq); } + dev_err(dev, "skcipher algorithm error!\n"); return -EINVAL; -- 2.8.1