Skip to content

Commit 2ef5a91

Browse files
Merged PR 8136159: Fix unit test failure importing DH key to CNG
+ Depending on the environment applications using CNG can either need to opt-in to performing FIPS checks, or opt-out of performing them. + For unit tests to succeed in environment where the application must opt-out of FIPS checks, we must opt-out of these checks when using a DH key which has a private key modulo P.
1 parent 1b588a6 commit 2ef5a91

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

unittest/lib/cng_implementations.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2774,6 +2774,7 @@ DhImp<ImpCng, AlgDh>::setKey( PCDLKEY_TESTBLOB pcKeyBlob )
27742774
BCRYPT_DH_KEY_BLOB * pBlob = (BCRYPT_DH_KEY_BLOB *) blobBuf;
27752775
PBYTE p;
27762776
UINT32 cbP;
2777+
UINT32 flags = 0;
27772778

27782779
if( state.hKey != NULL )
27792780
{
@@ -2802,13 +2803,20 @@ DhImp<ImpCng, AlgDh>::setKey( PCDLKEY_TESTBLOB pcKeyBlob )
28022803
memcpy( p + cbP - pcKeyBlob->cbPrivKey, pcKeyBlob->abPrivKey, pcKeyBlob->cbPrivKey );
28032804
p += cbP;
28042805

2806+
if( pcKeyBlob->fPrivateModP )
2807+
{
2808+
// Having a private key mod P is incompatible with FIPS SP800-56ar3 checks
2809+
// Ensure we have opted out of running these checks in BCrypt
2810+
flags |= BCRYPT_NO_KEY_VALIDATION;
2811+
}
2812+
28052813
ntStatus = BCryptImportKeyPair( BCRYPT_DH_ALG_HANDLE,
28062814
NULL,
28072815
BCRYPT_DH_PRIVATE_BLOB,
28082816
&state.hKey,
28092817
blobBuf,
28102818
(UINT32)(p - blobBuf),
2811-
0 );
2819+
flags );
28122820
CHECK( NT_SUCCESS( ntStatus ), "?" );
28132821

28142822
cleanup:

unittest/lib/testDh.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1026,6 +1026,7 @@ testDhtestGroups( DhImplementation * pDh, INT64 line )
10261026
blob1.cbPrivKey = SymCryptDlkeySizeofPrivateKey( pKey1 );
10271027
blob2.cbPrivKey = SymCryptDlkeySizeofPrivateKey( pKey2 );
10281028

1029+
blob1.fPrivateModP = FALSE;
10291030
blob2.fPrivateModP = TRUE;
10301031

10311032
scError = SymCryptDlkeyGetValue(
@@ -1078,7 +1079,7 @@ testDhtestGroups( DhImplementation * pDh, INT64 line )
10781079
{
10791080
scError = SymCryptDlkeySetPrivateKeyLength( pKey1, SYMCRYPT_MAX(nBitsPrivGenerated+1, pGroup->nMinBitsPriv), 0 );
10801081
CHECK4( scError == SYMCRYPT_NO_ERROR, "Error setting private key length nBitsPrivGenerated+1 %d cbP %d", nBitsPrivGenerated+1, cbP );
1081-
1082+
10821083
scError = SymCryptDlkeySetValue(
10831084
&blob1.abPrivKey[0], blob1.cbPrivKey,
10841085
&blob1.abPubKey[0], cbP,

0 commit comments

Comments
 (0)