Skip to content

Commit 907622c

Browse files
committed
Merged PR 11456063: Fix RSA export/import test: ensure key is large enough for salt/hash
!11444004 added a new unit test for RSA export/import to catch regressions in this functionality, particularly those relating to FIPS PCTs which are currently in a state of flux. However, the test would sometimes choose a key that was too small for the combination of the hash and salt it used, which would cause it to fail. Since test keys are chosen randomly, this failure also happened at random. Tested: ran export/import test hundreds of times in a loop to ensure it no longer fails intermittently
1 parent 7267807 commit 907622c

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

unittest/lib/testRsaSign.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,17 +1056,18 @@ testRsaExportImport()
10561056

10571057
iprint( " RsaExportImport" );
10581058

1059+
const SIZE_T cbSalt = 32;
1060+
10591061
RSAKEY_TESTBLOB blob;
10601062
PSYMCRYPT_RSAKEY pKeyPair;
10611063
PSYMCRYPT_RSAKEY pPubKey;
10621064
BYTE hash[32];
1063-
BYTE salt[32];
10641065
BYTE sig[ RSAKEY_MAXKEYSIZE ];
10651066
SIZE_T cbSig;
10661067
SYMCRYPT_ERROR scError;
10671068
SYMCRYPT_RSA_PARAMS params;
10681069

1069-
pKeyPair = rsaTestKeyRandom();
1070+
pKeyPair = rsaTestKeyForSize( 2048 ); // Ensure the key is large enough for the salt + hash
10701071
GENRANDOM( hash, sizeof( hash ) );
10711072

10721073
params.version = 1;
@@ -1098,7 +1099,7 @@ testRsaExportImport()
10981099
scError = ScDispatchSymCryptRsaPssSign(
10991100
pKeyPair,
11001101
hash, sizeof( hash ),
1101-
ScDispatchSymCryptSha256Algorithm, sizeof( salt ),
1102+
ScDispatchSymCryptSha256Algorithm, cbSalt,
11021103
0,
11031104
SYMCRYPT_NUMBER_FORMAT_MSB_FIRST,
11041105
sig, ScDispatchSymCryptRsakeySizeofModulus( pKeyPair ),
@@ -1111,7 +1112,7 @@ testRsaExportImport()
11111112
sig, cbSig,
11121113
SYMCRYPT_NUMBER_FORMAT_MSB_FIRST,
11131114
ScDispatchSymCryptSha256Algorithm,
1114-
sizeof( salt ),
1115+
cbSalt,
11151116
0 );
11161117
CHECK( scError == SYMCRYPT_NO_ERROR, "?" );
11171118

0 commit comments

Comments
 (0)