2008-12-05 15:00:33

by Jarod Wilson

[permalink] [raw]
Subject: Re: [PATCH v2] crypto: des3_ede: permit weak keys unless REQ_WEAK_KEY set

Jarod Wilson wrote:
> While its a slightly insane to bypass the key1 == key2 ||
> key2 == key3 check in triple-des, since it reduces it to the
> same strength as des, some folks do need to do this from time
> to time for backwards compatibility with des.
>
> My own case is FIPS CAVS test vectors. Many triple-des test
> vectors use a single key, replicated 3x. In order to get the
> expected results, des3_ede_setkey() needs to honor the weak
> key flag.
>
> Also adds a warning when a weak key is rejected, otherwise,
> you silently get back a bogus result.
>
> Signed-off-by: Jarod Wilson <[email protected]>

v2: make CRYPTO_TFM_REQ_WEAK_KEY flag usage consistent w/rest of crypto
subsystem, per comments from Herbert in Red Hat bugzilla #474394.

---
crypto/des_generic.c | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/crypto/des_generic.c b/crypto/des_generic.c
index 5d0e458..9002073 100644
--- a/crypto/des_generic.c
+++ b/crypto/des_generic.c
@@ -868,7 +868,8 @@ static int des3_ede_setkey(struct crypto_tfm *tfm,
const u8 *key,
u32 *flags = &tfm->crt_flags;

if (unlikely(!((K[0] ^ K[2]) | (K[1] ^ K[3])) ||
- !((K[2] ^ K[4]) | (K[3] ^ K[5]))))
+ !((K[2] ^ K[4]) | (K[3] ^ K[5]))) &&
+ (*flags & CRYPTO_TFM_REQ_WEAK_KEY))
{
*flags |= CRYPTO_TFM_RES_BAD_KEY_SCHED;
return -EINVAL;


--
Jarod Wilson
[email protected]


2008-12-05 15:24:34

by Herbert Xu

[permalink] [raw]
Subject: Re: [PATCH v2] crypto: des3_ede: permit weak keys unless REQ_WEAK_KEY set

On Fri, Dec 05, 2008 at 10:03:53AM -0500, Jarod Wilson wrote:
>
> if (unlikely(!((K[0] ^ K[2]) | (K[1] ^ K[3])) ||
> - !((K[2] ^ K[4]) | (K[3] ^ K[5]))))
> + !((K[2] ^ K[4]) | (K[3] ^ K[5]))) &&
> + (*flags & CRYPTO_TFM_REQ_WEAK_KEY))
> {
> *flags |= CRYPTO_TFM_RES_BAD_KEY_SCHED;

This should be changed to RES_WEAK_KEY.

Thanks,
--
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

2008-12-06 05:44:48

by Jarod Wilson

[permalink] [raw]
Subject: Re: [PATCH v3] crypto: des3_ede: permit weak keys unless REQ_WEAK_KEY set

Jarod Wilson wrote:
> While its a slightly insane to bypass the key1 == key2 ||
> key2 == key3 check in triple-des, since it reduces it to the
> same strength as des, some folks do need to do this from time
> to time for backwards compatibility with des.
>
> My own case is FIPS CAVS test vectors. Many triple-des test
> vectors use a single key, replicated 3x. In order to get the
> expected results, des3_ede_setkey() needs to honor the weak
> key flag.

v2: make CRYPTO_TFM_REQ_WEAK_KEY flag usage consistent w/rest
of crypto subsystem, per comments from Herbert in Red Hat
bugzilla #474394.

v3: set more appropriate RES flag, also per Herbert.

Signed-off-by: Jarod Wilson <[email protected]>

---
crypto/des_generic.c | 5 +++--
1 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/crypto/des_generic.c b/crypto/des_generic.c
index 5d0e458..5bd3ee3 100644
--- a/crypto/des_generic.c
+++ b/crypto/des_generic.c
@@ -868,9 +868,10 @@ static int des3_ede_setkey(struct crypto_tfm *tfm, const
u8 *key,
u32 *flags = &tfm->crt_flags;

if (unlikely(!((K[0] ^ K[2]) | (K[1] ^ K[3])) ||
- !((K[2] ^ K[4]) | (K[3] ^ K[5]))))
+ !((K[2] ^ K[4]) | (K[3] ^ K[5]))) &&
+ (*flags & CRYPTO_TFM_REQ_WEAK_KEY))
{
- *flags |= CRYPTO_TFM_RES_BAD_KEY_SCHED;
+ *flags |= CRYPTO_TFM_RES_WEAK_KEY;
return -EINVAL;
}


--
Jarod Wilson
[email protected]


2008-12-06 20:19:31

by Neil Horman

[permalink] [raw]
Subject: Re: [PATCH v3] crypto: des3_ede: permit weak keys unless REQ_WEAK_KEY set

On Sat, Dec 06, 2008 at 12:39:38AM -0500, Jarod Wilson wrote:
> Jarod Wilson wrote:
>> While its a slightly insane to bypass the key1 == key2 ||
>> key2 == key3 check in triple-des, since it reduces it to the
>> same strength as des, some folks do need to do this from time
>> to time for backwards compatibility with des.
>>
>> My own case is FIPS CAVS test vectors. Many triple-des test
>> vectors use a single key, replicated 3x. In order to get the
>> expected results, des3_ede_setkey() needs to honor the weak
>> key flag.
>
> v2: make CRYPTO_TFM_REQ_WEAK_KEY flag usage consistent w/rest
> of crypto subsystem, per comments from Herbert in Red Hat
> bugzilla #474394.
>
> v3: set more appropriate RES flag, also per Herbert.
>
> Signed-off-by: Jarod Wilson <[email protected]>
>
> ---
> crypto/des_generic.c | 5 +++--
> 1 files changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/crypto/des_generic.c b/crypto/des_generic.c
> index 5d0e458..5bd3ee3 100644
> --- a/crypto/des_generic.c
> +++ b/crypto/des_generic.c
> @@ -868,9 +868,10 @@ static int des3_ede_setkey(struct crypto_tfm *tfm,
> const u8 *key,
> u32 *flags = &tfm->crt_flags;
>
> if (unlikely(!((K[0] ^ K[2]) | (K[1] ^ K[3])) ||
> - !((K[2] ^ K[4]) | (K[3] ^ K[5]))))
> + !((K[2] ^ K[4]) | (K[3] ^ K[5]))) &&
> + (*flags & CRYPTO_TFM_REQ_WEAK_KEY))
> {
> - *flags |= CRYPTO_TFM_RES_BAD_KEY_SCHED;
> + *flags |= CRYPTO_TFM_RES_WEAK_KEY;
> return -EINVAL;
> }
>
>
Looks good to me. Thanks Jarod!
Acked-by: Neil Horman <[email protected]>

2008-12-07 11:38:34

by Herbert Xu

[permalink] [raw]
Subject: Re: [PATCH v3] crypto: des3_ede: permit weak keys unless REQ_WEAK_KEY set

On Sat, Dec 06, 2008 at 12:39:38AM -0500, Jarod Wilson wrote:
>
> v3: set more appropriate RES flag, also per Herbert.

BTW, please maintain the patch description as you would in the
first submission. This makes it much easier for me to apply the
patch. Feel free to summarise changes elsewhere in the email.

> Signed-off-by: Jarod Wilson <[email protected]>

I tried to apply it but I get

$ git apply ~/p
fatal: corrupt patch at line 29
$ patch -s -p1 < ~/p
patch: **** malformed patch at line 29: u8 *key,

$

Please fix it up and resubmit.

Thanks,
--
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt