Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp969362pxf; Thu, 1 Apr 2021 19:51:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwfaLTxkY8CcmAchCuefH28UL/n+diE/PKAMAKzIF0jfnJxJCqnbqIu3Z/7hQJ5sSYlkc3y X-Received: by 2002:a05:6402:35c9:: with SMTP id z9mr13213425edc.94.1617331886149; Thu, 01 Apr 2021 19:51:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617331886; cv=none; d=google.com; s=arc-20160816; b=uwGBfdHLhO+jS5VTBoYUtyl1uTPQ5IhB365nXCnTop3LwFnSuKyqrGTIq5WBvbjI1Q k3YEuNKlmY3eI7pcMJThwysfCKO4+z8iKkERuxAmaVR+AHQwriKsy0P0pHk2y2/xOWQ+ ImzjJO77b/nJV4v5f+1R8IKcxx2DadiuS9dM/BzGqgF2V2bGaLQtyuGI/YCt6swjlOJ/ 5HaG7Ehqm1E0/7tXR/e2MbNoU5hevD8Ct4CUBX1ZHfho4GNc67vGfK3YtSX5ZyJkkN+H MAzQfGwSfhqWOgZtZ1oyuRaUI2ibcYXGOSaXU+qtLhMXjhfG2xDIf6zniOexD67wOrK1 +qPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=YInlV+VyxlonE740cmDNZrQme3tBkUYAS4mmWvlWpXc=; b=q8nc52ZqHz/09FNutv9wP5JzJq74wI/nkZkm0+d3ZUoBlZYVcor7y4j4J11ixIO1vR pz96crp830U5s/PR5e7eclxqvfxQyCMSuyBVnk3yq7sFCJGl/6PKQI6WfOQaX3UO7Mb/ CWEoTDMeNU5SwkqA6BtnzQb9zwaLvXIJ/eIcZcDbiJomQ/1Xp8lHQNlpB7xmM9Uh22s2 LwtX/2jJ0TdshoPYEwcJi4H7nha4/UtBwqExjfopLErLtbpwTw2LSLn7TdgsaP2YLd3v fcZjV8sEBiQtWk1l3lC49/svFbG3wsC+qEie+pLo5YaGfGO5aOgraDfdBDlUdFAQEqGO ofaw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-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 o9si5935791ejr.588.2021.04.01.19.50.47; Thu, 01 Apr 2021 19:51:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-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-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-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 S233841AbhDBCug (ORCPT + 99 others); Thu, 1 Apr 2021 22:50:36 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:15525 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233665AbhDBCug (ORCPT ); Thu, 1 Apr 2021 22:50:36 -0400 Received: from DGGEMS405-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4FBPc95LznzNs6m; Fri, 2 Apr 2021 10:47:53 +0800 (CST) Received: from huawei.com (10.67.165.24) by DGGEMS405-HUB.china.huawei.com (10.3.19.205) with Microsoft SMTP Server id 14.3.498.0; Fri, 2 Apr 2021 10:50:26 +0800 From: Kai Ye To: CC: , , , Subject: [PATCH] crypto:hisilicon/sec - fixup checking the 3DES weak key Date: Fri, 2 Apr 2021 10:47:57 +0800 Message-ID: <1617331677-49794-1-git-send-email-yekai13@huawei.com> X-Mailer: git-send-email 2.8.1 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-crypto@vger.kernel.org skcipher: Add a verifying to check whether the triple DES key is weak. Signed-off-by: Kai Ye --- drivers/crypto/hisilicon/sec2/sec_crypto.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/crypto/hisilicon/sec2/sec_crypto.c b/drivers/crypto/hisilicon/sec2/sec_crypto.c index 2eaa516..ee18c88 100644 --- a/drivers/crypto/hisilicon/sec2/sec_crypto.c +++ b/drivers/crypto/hisilicon/sec2/sec_crypto.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -573,10 +574,18 @@ static void sec_skcipher_uninit(struct crypto_skcipher *tfm) sec_ctx_base_uninit(ctx); } -static int sec_skcipher_3des_setkey(struct sec_cipher_ctx *c_ctx, +static int sec_skcipher_3des_setkey(struct crypto_skcipher *tfm, const u8 *key, const u32 keylen, const enum sec_cmode c_mode) { + struct sec_ctx *ctx = crypto_skcipher_ctx(tfm); + struct sec_cipher_ctx *c_ctx = &ctx->c_ctx; + int ret; + + ret = verify_skcipher_des3_key(tfm, key); + if (ret) + return ret; + switch (keylen) { case SEC_DES3_2KEY_SIZE: c_ctx->c_key_len = SEC_CKEY_3DES_2KEY; @@ -648,7 +657,7 @@ static int sec_skcipher_setkey(struct crypto_skcipher *tfm, const u8 *key, switch (c_alg) { case SEC_CALG_3DES: - ret = sec_skcipher_3des_setkey(c_ctx, keylen, c_mode); + ret = sec_skcipher_3des_setkey(tfm, key, keylen, c_mode); break; case SEC_CALG_AES: case SEC_CALG_SM4: -- 2.8.1