OSDN Git Service

crypto: hisilicon - Forbid 2-key 3DES in FIPS mode
authorHerbert Xu <herbert@gondor.apana.org.au>
Thu, 11 Apr 2019 08:51:08 +0000 (16:51 +0800)
committerHerbert Xu <herbert@gondor.apana.org.au>
Thu, 18 Apr 2019 14:15:00 +0000 (22:15 +0800)
This patch forbids the use of 2-key 3DES (K1 == K3) in FIPS mode.

It also removes a couple of unnecessary key length checks that
are already performed by the crypto API.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
drivers/crypto/hisilicon/sec/sec_algs.c

index adc0cd8..02768af 100644 (file)
@@ -365,20 +365,16 @@ static int sec_alg_skcipher_setkey_des_cbc(struct crypto_skcipher *tfm,
 static int sec_alg_skcipher_setkey_3des_ecb(struct crypto_skcipher *tfm,
                                            const u8 *key, unsigned int keylen)
 {
-       if (keylen != DES_KEY_SIZE * 3)
-               return -EINVAL;
-
-       return sec_alg_skcipher_setkey(tfm, key, keylen,
+       return unlikely(des3_verify_key(tfm, key)) ?:
+              sec_alg_skcipher_setkey(tfm, key, keylen,
                                       SEC_C_3DES_ECB_192_3KEY);
 }
 
 static int sec_alg_skcipher_setkey_3des_cbc(struct crypto_skcipher *tfm,
                                            const u8 *key, unsigned int keylen)
 {
-       if (keylen != DES3_EDE_KEY_SIZE)
-               return -EINVAL;
-
-       return sec_alg_skcipher_setkey(tfm, key, keylen,
+       return unlikely(des3_verify_key(tfm, key)) ?:
+              sec_alg_skcipher_setkey(tfm, key, keylen,
                                       SEC_C_3DES_CBC_192_3KEY);
 }