Skip to content

Commit a660824

Browse files
committed
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: Herbert Xu <[email protected]>
1 parent 52ea3cd commit a660824

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

drivers/crypto/bcm/cipher.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1840,13 +1840,14 @@ static int threedes_setkey(struct crypto_ablkcipher *cipher, const u8 *key,
18401840
struct iproc_ctx_s *ctx = crypto_ablkcipher_ctx(cipher);
18411841

18421842
if (keylen == (DES_KEY_SIZE * 3)) {
1843-
const u32 *K = (const u32 *)key;
1844-
u32 flags = CRYPTO_TFM_RES_BAD_KEY_SCHED;
1843+
u32 flags;
1844+
int ret;
18451845

1846-
if (!((K[0] ^ K[2]) | (K[1] ^ K[3])) ||
1847-
!((K[2] ^ K[4]) | (K[3] ^ K[5]))) {
1846+
flags = crypto_ablkcipher_get_flags(cipher);
1847+
ret = __des3_verify_key(&flags, key);
1848+
if (unlikely(ret)) {
18481849
crypto_ablkcipher_set_flags(cipher, flags);
1849-
return -EINVAL;
1850+
return ret;
18501851
}
18511852

18521853
ctx->cipher_type = CIPHER_TYPE_3DES;
@@ -2885,13 +2886,13 @@ static int aead_authenc_setkey(struct crypto_aead *cipher,
28852886
break;
28862887
case CIPHER_ALG_3DES:
28872888
if (ctx->enckeylen == (DES_KEY_SIZE * 3)) {
2888-
const u32 *K = (const u32 *)keys.enckey;
2889-
u32 flags = CRYPTO_TFM_RES_BAD_KEY_SCHED;
2889+
u32 flags;
28902890

2891-
if (!((K[0] ^ K[2]) | (K[1] ^ K[3])) ||
2892-
!((K[2] ^ K[4]) | (K[3] ^ K[5]))) {
2891+
flags = crypto_aead_get_flags(cipher);
2892+
ret = __des3_verify_key(&flags, keys.enckey);
2893+
if (unlikely(ret)) {
28932894
crypto_aead_set_flags(cipher, flags);
2894-
return -EINVAL;
2895+
return ret;
28952896
}
28962897

28972898
ctx->cipher_type = CIPHER_TYPE_3DES;

0 commit comments

Comments
 (0)