From: Nikola Pajkovsky Date: Fri, 15 Aug 2025 12:02:44 +0000 (+0200) Subject: dh: add FIPS 140-3 PCT on key generation X-Git-Tag: openssl-3.6.0-alpha1~57 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b561837ee9bb9393cd3ada325180130fda2613bc;p=thirdparty%2Fopenssl.git dh: add FIPS 140-3 PCT on key generation According to FIPS 140-3 IG 10.3.A Additonal Comment 1, a PCT shall be performed. Signed-off-by: Nikola Pajkovsky Reviewed-by: Neil Horman Reviewed-by: Tomas Mraz Reviewed-by: Tim Hudson Reviewed-by: Shane Lontis (Merged from https://github.com/openssl/openssl/pull/28280) --- diff --git a/providers/implementations/keymgmt/dh_kmgmt.c b/providers/implementations/keymgmt/dh_kmgmt.c index 5afda2eeaac..09d089c24de 100644 --- a/providers/implementations/keymgmt/dh_kmgmt.c +++ b/providers/implementations/keymgmt/dh_kmgmt.c @@ -810,6 +810,15 @@ static void *dh_gen(void *genctx, OSSL_CALLBACK *osslcb, void *cbarg) gctx->gen_type == DH_PARAMGEN_TYPE_FIPS_186_2); if (DH_generate_key(dh) <= 0) goto end; +#ifdef FIPS_MODULE + if (!ossl_fips_self_testing()) { + ret = ossl_dh_check_pairwise(dh, 0); + if (ret <= 0) { + ossl_set_error_state(OSSL_SELF_TEST_TYPE_PCT); + goto end; + } + } +#endif /* FIPS_MODULE */ } DH_clear_flags(dh, DH_FLAG_TYPE_MASK); DH_set_flags(dh, gctx->dh_type);