|
|
cabbaa |
From 9f5a60c1fe576f82bcd5c7998b2ca2b0d60e8e4f Mon Sep 17 00:00:00 2001
|
|
|
cabbaa |
From: Daiki Ueno <ueno@gnu.org>
|
|
|
cabbaa |
Date: Thu, 27 Jan 2022 18:17:43 +0100
|
|
|
cabbaa |
Subject: [PATCH 1/2] rsa_generate_fips186_4_keypair: accept a few more modulus
|
|
|
cabbaa |
sizes
|
|
|
cabbaa |
|
|
|
cabbaa |
While _rsa_generate_fips186_4_keypair was modified to accept modulus
|
|
|
cabbaa |
sizes other than 2048 and 3076, rsa_generate_fips186_4_keypair, which
|
|
|
cabbaa |
calls that function, was not updated to accept such modulus sizes.
|
|
|
cabbaa |
|
|
|
cabbaa |
Spotted by Alexander Sosedkin.
|
|
|
cabbaa |
|
|
|
cabbaa |
Signed-off-by: Daiki Ueno <ueno@gnu.org>
|
|
|
cabbaa |
---
|
|
|
cabbaa |
lib/nettle/int/rsa-keygen-fips186.c | 67 ++++++++++++++++-------------
|
|
|
cabbaa |
1 file changed, 36 insertions(+), 31 deletions(-)
|
|
|
cabbaa |
|
|
|
cabbaa |
diff --git a/lib/nettle/int/rsa-keygen-fips186.c b/lib/nettle/int/rsa-keygen-fips186.c
|
|
|
cabbaa |
index 5b221a030a..c6f7e675af 100644
|
|
|
cabbaa |
--- a/lib/nettle/int/rsa-keygen-fips186.c
|
|
|
cabbaa |
+++ b/lib/nettle/int/rsa-keygen-fips186.c
|
|
|
cabbaa |
@@ -27,6 +27,7 @@
|
|
|
cabbaa |
#include "config.h"
|
|
|
cabbaa |
#endif
|
|
|
cabbaa |
|
|
|
cabbaa |
+#include <assert.h>
|
|
|
cabbaa |
#include <stdlib.h>
|
|
|
cabbaa |
#include <stdio.h>
|
|
|
cabbaa |
#include <string.h>
|
|
|
cabbaa |
@@ -248,6 +249,33 @@ cleanup:
|
|
|
cabbaa |
return ret;
|
|
|
cabbaa |
}
|
|
|
cabbaa |
|
|
|
cabbaa |
+/* Return the pre-defined seed length for modulus size, or 0 when the
|
|
|
cabbaa |
+ * modulus size is unsupported.
|
|
|
cabbaa |
+ */
|
|
|
cabbaa |
+static inline unsigned
|
|
|
cabbaa |
+seed_length_for_modulus_size(unsigned modulus_size)
|
|
|
cabbaa |
+{
|
|
|
cabbaa |
+ switch (modulus_size) {
|
|
|
cabbaa |
+ case 2048: /* SP 800-56B rev 2 Appendix D and FIPS 140-2 IG 7.5 */
|
|
|
cabbaa |
+ return 14 * 2;
|
|
|
cabbaa |
+ case 3072: /* SP 800-56B rev 2 Appendix D and FIPS 140-2 IG 7.5 */
|
|
|
cabbaa |
+ return 16 * 2;
|
|
|
cabbaa |
+ case 4096: /* SP 800-56B rev 2 Appendix D */
|
|
|
cabbaa |
+ return 19 * 2;
|
|
|
cabbaa |
+ case 6144: /* SP 800-56B rev 2 Appendix D */
|
|
|
cabbaa |
+ return 22 * 2;
|
|
|
cabbaa |
+ case 7680: /* FIPS 140-2 IG 7.5 */
|
|
|
cabbaa |
+ return 24 * 2;
|
|
|
cabbaa |
+ case 8192: /* SP 800-56B rev 2 Appendix D */
|
|
|
cabbaa |
+ return 25 * 2;
|
|
|
cabbaa |
+ case 15360: /* FIPS 140-2 IG 7.5 */
|
|
|
cabbaa |
+ return 32 * 2;
|
|
|
cabbaa |
+ default:
|
|
|
cabbaa |
+ return 0;
|
|
|
cabbaa |
+ }
|
|
|
cabbaa |
+
|
|
|
cabbaa |
+}
|
|
|
cabbaa |
+
|
|
|
cabbaa |
/* This generates p,q params using the B.3.2.2 algorithm in FIPS 186-4.
|
|
|
cabbaa |
*
|
|
|
cabbaa |
* The hash function used is SHA384.
|
|
|
cabbaa |
@@ -266,33 +294,15 @@ _rsa_generate_fips186_4_keypair(struct rsa_public_key *pub,
|
|
|
cabbaa |
int ret;
|
|
|
cabbaa |
struct dss_params_validation_seeds cert;
|
|
|
cabbaa |
unsigned l = n_size / 2;
|
|
|
cabbaa |
+ unsigned s = seed_length_for_modulus_size(n_size);
|
|
|
cabbaa |
|
|
|
cabbaa |
- switch (n_size) {
|
|
|
cabbaa |
- case 2048: /* SP 800-56B rev 2 Appendix D and FIPS 140-2 IG 7.5 */
|
|
|
cabbaa |
- FIPS_RULE(seed_length != 14 * 2, 0, "seed length other than 28 bytes\n");
|
|
|
cabbaa |
- break;
|
|
|
cabbaa |
- case 3072: /* SP 800-56B rev 2 Appendix D and FIPS 140-2 IG 7.5 */
|
|
|
cabbaa |
- FIPS_RULE(seed_length != 16 * 2, 0, "seed length other than 32 bytes\n");
|
|
|
cabbaa |
- break;
|
|
|
cabbaa |
- case 4096: /* SP 800-56B rev 2 Appendix D */
|
|
|
cabbaa |
- FIPS_RULE(seed_length != 19 * 2, 0, "seed length other than 38 bytes\n");
|
|
|
cabbaa |
- break;
|
|
|
cabbaa |
- case 6144: /* SP 800-56B rev 2 Appendix D */
|
|
|
cabbaa |
- FIPS_RULE(seed_length != 22 * 2, 0, "seed length other than 44 bytes\n");
|
|
|
cabbaa |
- break;
|
|
|
cabbaa |
- case 7680: /* FIPS 140-2 IG 7.5 */
|
|
|
cabbaa |
- FIPS_RULE(seed_length != 24 * 2, 0, "seed length other than 48 bytes\n");
|
|
|
cabbaa |
- break;
|
|
|
cabbaa |
- case 8192: /* SP 800-56B rev 2 Appendix D */
|
|
|
cabbaa |
- FIPS_RULE(seed_length != 25 * 2, 0, "seed length other than 50 bytes\n");
|
|
|
cabbaa |
- break;
|
|
|
cabbaa |
- case 15360: /* FIPS 140-2 IG 7.5 */
|
|
|
cabbaa |
- FIPS_RULE(seed_length != 32 * 2, 0, "seed length other than 64 bytes\n");
|
|
|
cabbaa |
- break;
|
|
|
cabbaa |
- default:
|
|
|
cabbaa |
+ if (!s) {
|
|
|
cabbaa |
FIPS_RULE(false, 0, "unsupported modulus size\n");
|
|
|
cabbaa |
}
|
|
|
cabbaa |
|
|
|
cabbaa |
+ FIPS_RULE(seed_length != s, 0,
|
|
|
cabbaa |
+ "seed length other than %u bytes\n", s);
|
|
|
cabbaa |
+
|
|
|
cabbaa |
if (!mpz_tstbit(pub->e, 0)) {
|
|
|
cabbaa |
_gnutls_debug_log("Unacceptable e (it is even)\n");
|
|
|
cabbaa |
return 0;
|
|
|
cabbaa |
@@ -405,10 +415,6 @@ _rsa_generate_fips186_4_keypair(struct rsa_public_key *pub,
|
|
|
cabbaa |
return ret;
|
|
|
cabbaa |
}
|
|
|
cabbaa |
|
|
|
cabbaa |
-/* Not entirely accurate but a good precision
|
|
|
cabbaa |
- */
|
|
|
cabbaa |
-#define SEED_LENGTH(bits) (_gnutls_pk_bits_to_subgroup_bits(bits)/8)
|
|
|
cabbaa |
-
|
|
|
cabbaa |
/* This generates p,q params using the B.3.2.2 algorithm in FIPS 186-4.
|
|
|
cabbaa |
*
|
|
|
cabbaa |
* The hash function used is SHA384.
|
|
|
cabbaa |
@@ -429,11 +435,10 @@ rsa_generate_fips186_4_keypair(struct rsa_public_key *pub,
|
|
|
cabbaa |
unsigned seed_length;
|
|
|
cabbaa |
int ret;
|
|
|
cabbaa |
|
|
|
cabbaa |
- FIPS_RULE(n_size != 2048 && n_size != 3072, 0, "size of prime of other than 2048 or 3072\n");
|
|
|
cabbaa |
+ seed_length = seed_length_for_modulus_size(n_size);
|
|
|
cabbaa |
+ FIPS_RULE(!seed_length, 0, "unsupported modulus size\n");
|
|
|
cabbaa |
|
|
|
cabbaa |
- seed_length = SEED_LENGTH(n_size);
|
|
|
cabbaa |
- if (seed_length > sizeof(seed))
|
|
|
cabbaa |
- return 0;
|
|
|
cabbaa |
+ assert(seed_length <= sizeof(seed));
|
|
|
cabbaa |
|
|
|
cabbaa |
random(random_ctx, seed_length, seed);
|
|
|
cabbaa |
|
|
|
cabbaa |
--
|
|
|
cabbaa |
2.34.1
|
|
|
cabbaa |
|
|
|
cabbaa |
|
|
|
cabbaa |
From 46ae6160489151034bca19aa6c40ba0df6b53bcc Mon Sep 17 00:00:00 2001
|
|
|
cabbaa |
From: Daiki Ueno <ueno@gnu.org>
|
|
|
cabbaa |
Date: Tue, 1 Feb 2022 15:19:52 +0100
|
|
|
cabbaa |
Subject: [PATCH 2/2] certtool --generate-privkey: update warnings on RSA key
|
|
|
cabbaa |
sizes
|
|
|
cabbaa |
|
|
|
cabbaa |
Signed-off-by: Daiki Ueno <ueno@gnu.org>
|
|
|
cabbaa |
---
|
|
|
cabbaa |
src/certtool.c | 18 +++++++++++++++---
|
|
|
cabbaa |
1 file changed, 15 insertions(+), 3 deletions(-)
|
|
|
cabbaa |
|
|
|
cabbaa |
diff --git a/src/certtool.c b/src/certtool.c
|
|
|
cabbaa |
index c128500614..71d4aff13e 100644
|
|
|
cabbaa |
--- a/src/certtool.c
|
|
|
cabbaa |
+++ b/src/certtool.c
|
|
|
cabbaa |
@@ -206,8 +206,12 @@ generate_private_key_int(common_info_st * cinfo)
|
|
|
cabbaa |
"Note that DSA keys with size over 1024 may cause incompatibility problems when used with earlier than TLS 1.2 versions.\n\n");
|
|
|
cabbaa |
|
|
|
cabbaa |
if ((HAVE_OPT(SEED) || provable) && GNUTLS_PK_IS_RSA(key_type)) {
|
|
|
cabbaa |
- if (bits != 2048 && bits != 3072) {
|
|
|
cabbaa |
- fprintf(stderr, "Note that the FIPS 186-4 key generation restricts keys to 2048 and 3072 bits\n");
|
|
|
cabbaa |
+ /* Keep in sync with seed_length_for_modulus_size in
|
|
|
cabbaa |
+ * lib/nettle/int/rsa-keygen-fips186.c. */
|
|
|
cabbaa |
+ if (bits != 2048 && bits != 3072 && bits != 4096 &&
|
|
|
cabbaa |
+ bits != 6144 && bits != 7680 && bits != 8192 &&
|
|
|
cabbaa |
+ bits != 15360) {
|
|
|
cabbaa |
+ fprintf(stderr, "Note that the FIPS 186-4 key generation restricts keys to be of known lengths (2048, 3072, etc)\n");
|
|
|
cabbaa |
}
|
|
|
cabbaa |
}
|
|
|
cabbaa |
|
|
|
cabbaa |
@@ -225,7 +229,15 @@ generate_private_key_int(common_info_st * cinfo)
|
|
|
cabbaa |
kdata[kdata_size++].size = cinfo->seed_size;
|
|
|
cabbaa |
|
|
|
cabbaa |
if (GNUTLS_PK_IS_RSA(key_type)) {
|
|
|
cabbaa |
- if ((bits == 3072 && cinfo->seed_size != 32) || (bits == 2048 && cinfo->seed_size != 28)) {
|
|
|
cabbaa |
+ /* Keep in sync with seed_length_for_modulus_size in
|
|
|
cabbaa |
+ * lib/nettle/int/rsa-keygen-fips186.c. */
|
|
|
cabbaa |
+ if ((bits == 2048 && cinfo->seed_size != 28) ||
|
|
|
cabbaa |
+ (bits == 3072 && cinfo->seed_size != 32) ||
|
|
|
cabbaa |
+ (bits == 4096 && cinfo->seed_size != 38) ||
|
|
|
cabbaa |
+ (bits == 6144 && cinfo->seed_size != 44) ||
|
|
|
cabbaa |
+ (bits == 7680 && cinfo->seed_size != 48) ||
|
|
|
cabbaa |
+ (bits == 8192 && cinfo->seed_size != 50) ||
|
|
|
cabbaa |
+ (bits == 15360 && cinfo->seed_size != 64)) {
|
|
|
cabbaa |
fprintf(stderr, "The seed size (%d) doesn't match the size of the request security level; use -d 2 for more information.\n", (int)cinfo->seed_size);
|
|
|
cabbaa |
}
|
|
|
cabbaa |
} else if (key_type == GNUTLS_PK_DSA) {
|
|
|
cabbaa |
--
|
|
|
cabbaa |
2.34.1
|
|
|
cabbaa |
|