2019-04-11 08:51:21

by Herbert Xu

[permalink] [raw]
Subject: [PATCH 21/24] crypto: stm32 - Forbid 2-key 3DES in FIPS mode

This patch forbids the use of 2-key 3DES (K1 == K3) in FIPS mode.

Signed-off-by: Herbert Xu <[email protected]>
---

drivers/crypto/stm32/stm32-cryp.c | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/drivers/crypto/stm32/stm32-cryp.c b/drivers/crypto/stm32/stm32-cryp.c
index 23b0b7bd64c7..5785f3e235ce 100644
--- a/drivers/crypto/stm32/stm32-cryp.c
+++ b/drivers/crypto/stm32/stm32-cryp.c
@@ -762,10 +762,17 @@ static int stm32_cryp_des_setkey(struct crypto_ablkcipher *tfm, const u8 *key,
static int stm32_cryp_tdes_setkey(struct crypto_ablkcipher *tfm, const u8 *key,
unsigned int keylen)
{
- if (keylen != (3 * DES_KEY_SIZE))
- return -EINVAL;
- else
- return stm32_cryp_setkey(tfm, key, keylen);
+ u32 flags;
+ int err;
+
+ flags = crypto_ablkcipher_get_flags(tfm);
+ err = __des3_verify_key(&flags, key);
+ if (unlikely(err)) {
+ crypto_ablkcipher_set_flags(tfm, flags);
+ return err;
+ }
+
+ return stm32_cryp_setkey(tfm, key, keylen);
}

static int stm32_cryp_aes_aead_setkey(struct crypto_aead *tfm, const u8 *key,


2019-04-12 13:37:00

by Lionel Debieve

[permalink] [raw]
Subject: Re: [PATCH 21/24] crypto: stm32 - Forbid 2-key 3DES in FIPS mode

Hi Herbert,

On 4/11/19 10:51 AM, Herbert Xu wrote:

> This patch forbids the use of 2-key 3DES (K1 == K3) in FIPS mode.
>
> Signed-off-by: Herbert Xu <[email protected]>
> ---
>
> drivers/crypto/stm32/stm32-cryp.c | 15 +++++++++++----
> 1 file changed, 11 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/crypto/stm32/stm32-cryp.c b/drivers/crypto/stm32/stm32-cryp.c
> index 23b0b7bd64c7..5785f3e235ce 100644
> --- a/drivers/crypto/stm32/stm32-cryp.c
> +++ b/drivers/crypto/stm32/stm32-cryp.c
> @@ -762,10 +762,17 @@ static int stm32_cryp_des_setkey(struct crypto_ablkcipher *tfm, const u8 *key,
> static int stm32_cryp_tdes_setkey(struct crypto_ablkcipher *tfm, const u8 *key,
> unsigned int keylen)
> {
> - if (keylen != (3 * DES_KEY_SIZE))
> - return -EINVAL;
> - else
> - return stm32_cryp_setkey(tfm, key, keylen);
> + u32 flags;
> + int err;
> +
> + flags = crypto_ablkcipher_get_flags(tfm);
> + err = __des3_verify_key(&flags, key);
> + if (unlikely(err)) {
> + crypto_ablkcipher_set_flags(tfm, flags);
> + return err;
> + }
> +
> + return stm32_cryp_setkey(tfm, key, keylen);
> }
>
> static int stm32_cryp_aes_aead_setkey(struct crypto_aead *tfm, const u8 *key,
>
I was currently going to send patches around des and tdes key verification. Is there any plan
to do the same factorization on des key check?

Regarding this patch, ok for me.

- Lionel

Acked-by: Lionel Debieve<[email protected]>
Tested-by: Lionel Debieve<[email protected]>


2019-04-13 13:51:04

by Herbert Xu

[permalink] [raw]
Subject: Re: [PATCH 21/24] crypto: stm32 - Forbid 2-key 3DES in FIPS mode

On Fri, Apr 12, 2019 at 01:36:44PM +0000, Lionel DEBIEVE wrote:
>
> I was currently going to send patches around des and tdes key verification. Is there any plan
> to do the same factorization on des key check?

If you have the time please do because I think some single DES
drivers are missing the weak key check. The existing des_ekey
function should be sufficient for the check.

> Acked-by: Lionel Debieve<[email protected]>
> Tested-by: Lionel Debieve<[email protected]>

Thanks,
--
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

2019-04-15 09:45:36

by Lionel Debieve

[permalink] [raw]
Subject: Re: [PATCH 21/24] crypto: stm32 - Forbid 2-key 3DES in FIPS mode

On 4/13/19 3:50 PM, Herbert Xu wrote:

> On Fri, Apr 12, 2019 at 01:36:44PM +0000, Lionel DEBIEVE wrote:
>> I was currently going to send patches around des and tdes key verification. Is there any plan
>> to do the same factorization on des key check?
> If you have the time please do because I think some single DES
> drivers are missing the weak key check. The existing des_ekey
> function should be sufficient for the check.

ok, will try to do it in the same way you've done it for 3des using existing des_ekey function.
Trying to push it this week for all impacted drivers.

- Lionel

>
>> Acked-by: Lionel Debieve<[email protected]>
>> Tested-by: Lionel Debieve<[email protected]>
> Thanks,
>