Skip to content

Commit d235a00

Browse files
stefanmbrvagg
authored andcommitted
crypto: DSA parameter validation in FIPS mode
FIPS 180-4 requires specific (L,N) values. OpenSSL will crash if an invalid combination is used, so we must check the input sanity first. PR-URL: #3756 Reviewed-By: Fedor Indutny <[email protected]> Reviewed-By: Shigeki Ohtsu <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 8156e14 commit d235a00

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/node_crypto.cc

+23
Original file line numberDiff line numberDiff line change
@@ -3593,6 +3593,29 @@ SignBase::Error Sign::SignFinal(const char* key_pem,
35933593
if (pkey == nullptr || 0 != ERR_peek_error())
35943594
goto exit;
35953595

3596+
#ifdef NODE_FIPS_MODE
3597+
/* Validate DSA2 parameters from FIPS 186-4 */
3598+
if (EVP_PKEY_DSA == pkey->type) {
3599+
size_t L = BN_num_bits(pkey->pkey.dsa->p);
3600+
size_t N = BN_num_bits(pkey->pkey.dsa->q);
3601+
bool result = false;
3602+
3603+
if (L == 1024 && N == 160)
3604+
result = true;
3605+
else if (L == 2048 && N == 224)
3606+
result = true;
3607+
else if (L == 2048 && N == 256)
3608+
result = true;
3609+
else if (L == 3072 && N == 256)
3610+
result = true;
3611+
3612+
if (!result) {
3613+
fatal = true;
3614+
goto exit;
3615+
}
3616+
}
3617+
#endif // NODE_FIPS_MODE
3618+
35963619
if (EVP_SignFinal(&mdctx_, *sig, sig_len, pkey))
35973620
fatal = false;
35983621

0 commit comments

Comments
 (0)