crypto: rsa - limit key size to 2048 in FIPS mode
authorStephan Müller <smueller@chronox.de>
Sun, 21 Nov 2021 14:31:27 +0000 (15:31 +0100)
committerHerbert Xu <herbert@gondor.apana.org.au>
Fri, 26 Nov 2021 05:25:18 +0000 (16:25 +1100)
FIPS disallows RSA 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/rsa.c

index 4cdbec9..39e0417 100644 (file)
@@ -5,6 +5,7 @@
  * Authors: Tadeusz Struk <tadeusz.struk@intel.com>
  */
 
+#include <linux/fips.h>
 #include <linux/module.h>
 #include <linux/mpi.h>
 #include <crypto/internal/rsa.h>
@@ -144,6 +145,9 @@ static int rsa_check_key_length(unsigned int len)
        case 512:
        case 1024:
        case 1536:
+               if (fips_enabled)
+                       return -EINVAL;
+               fallthrough;
        case 2048:
        case 3072:
        case 4096: