Blame SOURCES/gnutls-3.7.8-fips-pct-dh.patch

7e1ffc
From 51b721b69fd08ef1c4c4989f5e12b643e170ff56 Mon Sep 17 00:00:00 2001
7e1ffc
From: Pedro Monreal <pmgdeb@gmail.com>
7e1ffc
Date: Thu, 16 Feb 2023 17:02:38 +0100
7e1ffc
Subject: [PATCH] pk: extend pair-wise consistency to cover DH key generation
7e1ffc
7e1ffc
Perform SP800 56A (rev 3) 5.6.2.1.4 Owner Assurance of Pair-wise
7e1ffc
Consistency check, even if we only support ephemeral DH, as it is
7e1ffc
required by FIPS 140-3 IG 10.3.A.
7e1ffc
7e1ffc
Signed-off-by: Pedro Monreal <pmgdeb@gmail.com>
7e1ffc
Co-authored-by: Daiki Ueno <ueno@gnu.org>
7e1ffc
---
7e1ffc
 lib/nettle/pk.c | 29 +++++++++++++++++++++++++++++
7e1ffc
 1 file changed, 29 insertions(+)
7e1ffc
7e1ffc
diff --git a/lib/nettle/pk.c b/lib/nettle/pk.c
7e1ffc
index d30bca594f..bd9c1b4c74 100644
7e1ffc
--- a/lib/nettle/pk.c
7e1ffc
+++ b/lib/nettle/pk.c
7e1ffc
@@ -2642,6 +2642,35 @@ static int pct_test(gnutls_pk_algorithm_t algo,
7e1ffc
 		}
7e1ffc
 		break;
7e1ffc
 	case GNUTLS_PK_DH:
7e1ffc
+		{
7e1ffc
+			mpz_t y;
7e1ffc
+
7e1ffc
+			/* Perform SP800 56A (rev 3) 5.6.2.1.4 Owner Assurance
7e1ffc
+			 * of Pair-wise Consistency check, even if we only
7e1ffc
+			 * support ephemeral DH, as it is required by FIPS
7e1ffc
+			 * 140-3 IG 10.3.A.
7e1ffc
+			 *
7e1ffc
+			 * Use the private key, x, along with the generator g
7e1ffc
+			 * and prime modulus p included in the domain
7e1ffc
+			 * parameters associated with the key pair to compute
7e1ffc
+			 * g^x mod p. Compare the result to the public key, y.
7e1ffc
+			 */
7e1ffc
+			mpz_init(y);
7e1ffc
+			mpz_powm(y,
7e1ffc
+				 TOMPZ(params->params[DSA_G]),
7e1ffc
+				 TOMPZ(params->params[DSA_X]),
7e1ffc
+				 TOMPZ(params->params[DSA_P]));
7e1ffc
+			if (unlikely
7e1ffc
+			    (mpz_cmp(y, TOMPZ(params->params[DSA_Y])) != 0)) {
7e1ffc
+				ret =
7e1ffc
+				    gnutls_assert_val
7e1ffc
+				    (GNUTLS_E_PK_GENERATION_ERROR);
7e1ffc
+				mpz_clear(y);
7e1ffc
+				goto cleanup;
7e1ffc
+			}
7e1ffc
+			mpz_clear(y);
7e1ffc
+			break;
7e1ffc
+		}
7e1ffc
 	case GNUTLS_PK_ECDH_X25519:
7e1ffc
 	case GNUTLS_PK_ECDH_X448:
7e1ffc
 		ret = 0;
7e1ffc
-- 
7e1ffc
2.39.2
7e1ffc