Commit a6608244 authored by Herbert Xu's avatar Herbert Xu

crypto: bcm - Forbid 2-key 3DES in FIPS mode

This patch forbids the use of 2-key 3DES (K1 == K3) in FIPS mode.
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 52ea3cd2
...@@ -1840,13 +1840,14 @@ static int threedes_setkey(struct crypto_ablkcipher *cipher, const u8 *key, ...@@ -1840,13 +1840,14 @@ static int threedes_setkey(struct crypto_ablkcipher *cipher, const u8 *key,
struct iproc_ctx_s *ctx = crypto_ablkcipher_ctx(cipher); struct iproc_ctx_s *ctx = crypto_ablkcipher_ctx(cipher);
if (keylen == (DES_KEY_SIZE * 3)) { if (keylen == (DES_KEY_SIZE * 3)) {
const u32 *K = (const u32 *)key; u32 flags;
u32 flags = CRYPTO_TFM_RES_BAD_KEY_SCHED; int ret;
if (!((K[0] ^ K[2]) | (K[1] ^ K[3])) || flags = crypto_ablkcipher_get_flags(cipher);
!((K[2] ^ K[4]) | (K[3] ^ K[5]))) { ret = __des3_verify_key(&flags, key);
if (unlikely(ret)) {
crypto_ablkcipher_set_flags(cipher, flags); crypto_ablkcipher_set_flags(cipher, flags);
return -EINVAL; return ret;
} }
ctx->cipher_type = CIPHER_TYPE_3DES; ctx->cipher_type = CIPHER_TYPE_3DES;
...@@ -2885,13 +2886,13 @@ static int aead_authenc_setkey(struct crypto_aead *cipher, ...@@ -2885,13 +2886,13 @@ static int aead_authenc_setkey(struct crypto_aead *cipher,
break; break;
case CIPHER_ALG_3DES: case CIPHER_ALG_3DES:
if (ctx->enckeylen == (DES_KEY_SIZE * 3)) { if (ctx->enckeylen == (DES_KEY_SIZE * 3)) {
const u32 *K = (const u32 *)keys.enckey; u32 flags;
u32 flags = CRYPTO_TFM_RES_BAD_KEY_SCHED;
if (!((K[0] ^ K[2]) | (K[1] ^ K[3])) || flags = crypto_aead_get_flags(cipher);
!((K[2] ^ K[4]) | (K[3] ^ K[5]))) { ret = __des3_verify_key(&flags, keys.enckey);
if (unlikely(ret)) {
crypto_aead_set_flags(cipher, flags); crypto_aead_set_flags(cipher, flags);
return -EINVAL; return ret;
} }
ctx->cipher_type = CIPHER_TYPE_3DES; ctx->cipher_type = CIPHER_TYPE_3DES;
......
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