Skip to content

Commit 7a290ab

Browse files
stefanmbFishrock123
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 fd0253b commit 7a290ab

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
@@ -3781,6 +3781,29 @@ SignBase::Error Sign::SignFinal(const char* key_pem,
37813781
if (pkey == nullptr || 0 != ERR_peek_error())
37823782
goto exit;
37833783

3784+
#ifdef NODE_FIPS_MODE
3785+
/* Validate DSA2 parameters from FIPS 186-4 */
3786+
if (EVP_PKEY_DSA == pkey->type) {
3787+
size_t L = BN_num_bits(pkey->pkey.dsa->p);
3788+
size_t N = BN_num_bits(pkey->pkey.dsa->q);
3789+
bool result = false;
3790+
3791+
if (L == 1024 && N == 160)
3792+
result = true;
3793+
else if (L == 2048 && N == 224)
3794+
result = true;
3795+
else if (L == 2048 && N == 256)
3796+
result = true;
3797+
else if (L == 3072 && N == 256)
3798+
result = true;
3799+
3800+
if (!result) {
3801+
fatal = true;
3802+
goto exit;
3803+
}
3804+
}
3805+
#endif // NODE_FIPS_MODE
3806+
37843807
if (EVP_SignFinal(&mdctx_, *sig, sig_len, pkey))
37853808
fatal = false;
37863809

0 commit comments

Comments
 (0)