From patchwork Wed Apr 24 13:34:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lionel Debieve X-Patchwork-Id: 162783 Delivered-To: patch@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp672102jan; Wed, 24 Apr 2019 06:37:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqzpcZQpF160k7vQIroKHA5XK3ENR6DzYNbZIp2w7qvaOocxQfea0MItkbHxMgNEXqja8+NK X-Received: by 2002:a65:648f:: with SMTP id e15mr30931109pgv.414.1556113043008; Wed, 24 Apr 2019 06:37:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556113043; cv=none; d=google.com; s=arc-20160816; b=S/Fvw9JYl6JRzCrBC4SYHRK3ZLy/c/znMMvriPEbdiy5nBUfXBEZWfgawYTifrvpwn mit1FnWj6pMPJqEh8X2UUJUIEPEv3kD8QC11UfCjYBVbrZSUeRiRdvCGLIR0MyVUXlWu qf5NoVsbFYo4FZQ/dgx15w7VImBN3nHxAEGu/sHdR+8/P4e+Y41xbGGMNsY2N15nEMYN OROtSEtf/xLlYKSGh13aVdMbYnbNNpmKp5s9zaKNdgOpDmCy+zEeA4Coo75Luk/ZkaAQ UCGjPtJehm64H1hYtR7zs3brk+i8tCe75pQUXQOfUohrJ2gvqtFIgl+fZkO48VHUPOfF fgKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from:dkim-signature; bh=9d9FjDMPYFvQCTzlRmg0uybrmhlVz6nU0nj2RYqkkTk=; b=rgi1cZlkwrvfIimQI7hr+dlo5VKcwJU8xO7YS4M4aTCcqHfbTnxWS5SPKx4RlgoEdS DmicuqKCL4QsdDk+4dEjkQv/bYhUwz3tk+aPWCnBQjgRdKAL+ZgI2cwo1WINlfzWmeaw Tsq5cDr1qTYXipfgdXaKEVqHmXB44hdLETl2k/bz5odET2G/QsrOWp0vtKUYA6Nq3Zat 4IR2MseSnT70zIYqsx8igCdHZ+pr0eruwchE8iHyaCOWFOci5q+cFoVjT9HG6vGtvgeQ kzBezRLZR44q7m3rfIDIlLiFFHboxgYaVgVk/2CZcqqFtf9eavzMAt57E2Tq9VpteghN Xrew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@st.com header.s=STMicroelectronics header.b=ddRU2uuG; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 g31si19414000plg.154.2019.04.24.06.37.22; Wed, 24 Apr 2019 06:37:22 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@st.com header.s=STMicroelectronics header.b=ddRU2uuG; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729539AbfDXNhV (ORCPT + 30 others); Wed, 24 Apr 2019 09:37:21 -0400 Received: from mx08-00178001.pphosted.com ([91.207.212.93]:38238 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727369AbfDXNhU (ORCPT ); Wed, 24 Apr 2019 09:37:20 -0400 Received: from pps.filterd (m0046661.ppops.net [127.0.0.1]) by mx08-00178001.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x3ODU5mq019752; Wed, 24 Apr 2019 15:35:04 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=st.com; h=from : to : cc : subject : date : message-id : mime-version : content-type; s=STMicroelectronics; bh=9d9FjDMPYFvQCTzlRmg0uybrmhlVz6nU0nj2RYqkkTk=; b=ddRU2uuG1Fx61Uj34/n7dogCSdRIewzJpk4y29NdpaLf0DsEsTPH5B0xasUzy/yfFlPw 6+yzE2LF3qonph7YsjmK/fqs/FnQjH0xfgLJ0hzCL3xvUkV1dt496M8gzKrYL4LWdJD/ eUQ6D8zXOyq9FGo4+Xqz4mzfs4nXTP6Kha/0WsHHzfLuGgKvlwgt2VUN6/1hW29w8eRc ZwxSSlc/YdWLGFUlk2FI9mElUnIHFnCosy3rkfW4R10wltqJxTpp94S9VM9jiRCmppFA pvwo6ePiIHQfSDaHvob0c3YE9F/MpRM7m0Pqhkybbyjyoroe7/TUlOYlwGUjSPXqn93D eA== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx08-00178001.pphosted.com with ESMTP id 2rytad6ttg-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Wed, 24 Apr 2019 15:35:04 +0200 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 27EB741; Wed, 24 Apr 2019 13:35:02 +0000 (GMT) Received: from Webmail-eu.st.com (Safex1hubcas24.st.com [10.75.90.94]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id C504526A4; Wed, 24 Apr 2019 13:35:02 +0000 (GMT) Received: from SAFEX1HUBCAS22.st.com (10.75.90.93) by Safex1hubcas24.st.com (10.75.90.94) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 24 Apr 2019 15:35:02 +0200 Received: from localhost (10.201.23.65) by Webmail-ga.st.com (10.75.90.48) with Microsoft SMTP Server (TLS) id 14.3.361.1; Wed, 24 Apr 2019 15:35:02 +0200 From: Lionel Debieve To: Herbert Xu , "David S . Miller" , Maxime Coquelin , "Alexandre Torgue" , , , CC: Benjamin Gaignard , Fabien Dessenne , Subject: [PATCH 1/3] crypto: stm32/cryp - add weak key check for DES Date: Wed, 24 Apr 2019 15:34:51 +0200 Message-ID: <1556112893-13116-1-git-send-email-lionel.debieve@st.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 X-Originating-IP: [10.201.23.65] X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2019-04-24_09:, , signatures=0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add weak key test for des functions calling the generic des_ekey. Signed-off-by: Lionel Debieve --- drivers/crypto/stm32/Kconfig | 1 + drivers/crypto/stm32/stm32-cryp.c | 13 +++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) -- 2.7.4 diff --git a/drivers/crypto/stm32/Kconfig b/drivers/crypto/stm32/Kconfig index 63aa78c..4491e21 100644 --- a/drivers/crypto/stm32/Kconfig +++ b/drivers/crypto/stm32/Kconfig @@ -24,6 +24,7 @@ config CRYPTO_DEV_STM32_CRYP depends on ARCH_STM32 select CRYPTO_HASH select CRYPTO_ENGINE + select CRYPTO_DES help This enables support for the CRYP (AES/DES/TDES) hw accelerator which can be found on STMicroelectronics STM32 SOC. diff --git a/drivers/crypto/stm32/stm32-cryp.c b/drivers/crypto/stm32/stm32-cryp.c index 5785f3e..cfcb640 100644 --- a/drivers/crypto/stm32/stm32-cryp.c +++ b/drivers/crypto/stm32/stm32-cryp.c @@ -753,10 +753,19 @@ static int stm32_cryp_aes_setkey(struct crypto_ablkcipher *tfm, const u8 *key, static int stm32_cryp_des_setkey(struct crypto_ablkcipher *tfm, const u8 *key, unsigned int keylen) { + u32 tmp[DES_EXPKEY_WORDS]; + if (keylen != DES_KEY_SIZE) return -EINVAL; - else - return stm32_cryp_setkey(tfm, key, keylen); + + if ((crypto_ablkcipher_get_flags(tfm) & + CRYPTO_TFM_REQ_FORBID_WEAK_KEYS) && + unlikely(!des_ekey(tmp, key))) { + crypto_ablkcipher_set_flags(tfm, CRYPTO_TFM_RES_WEAK_KEY); + return -EINVAL; + } + + return stm32_cryp_setkey(tfm, key, keylen); } static int stm32_cryp_tdes_setkey(struct crypto_ablkcipher *tfm, const u8 *key,