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

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
arch/s390/crypto/des_s390.c

index 0d15383d0ff1bdb9d500c279341467f928d2d5fc..1f9ab24dc04831bac18504d6849c358c9843c571 100644 (file)
@@ -224,24 +224,11 @@ static int des3_setkey(struct crypto_tfm *tfm, const u8 *key,
                       unsigned int key_len)
 {
        struct s390_des_ctx *ctx = crypto_tfm_ctx(tfm);
+       int err;
 
-       if (!(crypto_memneq(key, &key[DES_KEY_SIZE], DES_KEY_SIZE) &&
-           crypto_memneq(&key[DES_KEY_SIZE], &key[DES_KEY_SIZE * 2],
-                         DES_KEY_SIZE)) &&
-           (tfm->crt_flags & CRYPTO_TFM_REQ_FORBID_WEAK_KEYS)) {
-               tfm->crt_flags |= CRYPTO_TFM_RES_WEAK_KEY;
-               return -EINVAL;
-       }
-
-       /* in fips mode, ensure k1 != k2 and k2 != k3 and k1 != k3 */
-       if (fips_enabled &&
-           !(crypto_memneq(key, &key[DES_KEY_SIZE], DES_KEY_SIZE) &&
-             crypto_memneq(&key[DES_KEY_SIZE], &key[DES_KEY_SIZE * 2],
-                           DES_KEY_SIZE) &&
-             crypto_memneq(key, &key[DES_KEY_SIZE * 2], DES_KEY_SIZE))) {
-               tfm->crt_flags |= CRYPTO_TFM_RES_WEAK_KEY;
-               return -EINVAL;
-       }
+       err = __des3_verify_key(&tfm->crt_flags, key);
+       if (unlikely(err))
+               return err;
 
        memcpy(ctx->key, key, key_len);
        return 0;