Commit 7ee27f5a authored by Lionel Debieve's avatar Lionel Debieve Committed by Herbert Xu

crypto: stm32/cryp - add weak key check for DES

Add weak key test for des functions calling the generic
des_ekey.
Signed-off-by: default avatarLionel Debieve <lionel.debieve@st.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 6bbc3936
...@@ -24,6 +24,7 @@ config CRYPTO_DEV_STM32_CRYP ...@@ -24,6 +24,7 @@ config CRYPTO_DEV_STM32_CRYP
depends on ARCH_STM32 depends on ARCH_STM32
select CRYPTO_HASH select CRYPTO_HASH
select CRYPTO_ENGINE select CRYPTO_ENGINE
select CRYPTO_DES
help help
This enables support for the CRYP (AES/DES/TDES) hw accelerator which This enables support for the CRYP (AES/DES/TDES) hw accelerator which
can be found on STMicroelectronics STM32 SOC. can be found on STMicroelectronics STM32 SOC.
...@@ -753,10 +753,19 @@ static int stm32_cryp_aes_setkey(struct crypto_ablkcipher *tfm, const u8 *key, ...@@ -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, static int stm32_cryp_des_setkey(struct crypto_ablkcipher *tfm, const u8 *key,
unsigned int keylen) unsigned int keylen)
{ {
u32 tmp[DES_EXPKEY_WORDS];
if (keylen != DES_KEY_SIZE) if (keylen != DES_KEY_SIZE)
return -EINVAL; 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, static int stm32_cryp_tdes_setkey(struct crypto_ablkcipher *tfm, const u8 *key,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment