crypto: dh - limit key size to 2048 in FIPS mode
authorStephan Müller <smueller@chronox.de>
Sun, 21 Nov 2021 14:51:44 +0000 (15:51 +0100)
committerHerbert Xu <herbert@gondor.apana.org.au>
Fri, 26 Nov 2021 05:25:18 +0000 (16:25 +1100)
FIPS disallows DH with keys < 2048 bits. Thus, the kernel should
consider the enforcement of this limit.

Signed-off-by: Stephan Mueller <smueller@chronox.de>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
crypto/dh.c

index cd4f32092e5ceea89f8a8aea1efc77c62c3b4379..38557e64b4b31597b54e32dc89c9c204b58437e7 100644 (file)
@@ -5,6 +5,7 @@
  * Authors: Salvatore Benedetto <salvatore.benedetto@intel.com>
  */
 
+#include <linux/fips.h>
 #include <linux/module.h>
 #include <crypto/internal/kpp.h>
 #include <crypto/kpp.h>
@@ -47,6 +48,9 @@ static inline struct dh_ctx *dh_get_ctx(struct crypto_kpp *tfm)
 
 static int dh_check_params_length(unsigned int p_len)
 {
+       if (fips_enabled)
+               return (p_len < 2048) ? -EINVAL : 0;
+
        return (p_len < 1536) ? -EINVAL : 0;
 }