@@ -4879,15 +4879,7 @@ static AllocatedBuffer Node_SignFinal(Environment* env,
4879
4879
return AllocatedBuffer ();
4880
4880
}
4881
4881
4882
- Sign::SignResult Sign::SignFinal (
4883
- const ManagedEVPPKey& pkey,
4884
- int padding,
4885
- const Maybe<int >& salt_len) {
4886
- if (!mdctx_)
4887
- return SignResult (kSignNotInitialised );
4888
-
4889
- EVPMDPointer mdctx = std::move (mdctx_);
4890
-
4882
+ static inline bool ValidateDSAParameters (EVP_PKEY* key) {
4891
4883
#ifdef NODE_FIPS_MODE
4892
4884
/* Validate DSA2 parameters from FIPS 186-4 */
4893
4885
if (FIPS_mode () && EVP_PKEY_DSA == EVP_PKEY_base_id (pkey.get ())) {
@@ -4898,23 +4890,29 @@ Sign::SignResult Sign::SignFinal(
4898
4890
const BIGNUM* q;
4899
4891
DSA_get0_pqg (dsa, nullptr , &q, nullptr );
4900
4892
size_t N = BN_num_bits (q);
4901
- bool result = false ;
4902
-
4903
- if (L == 1024 && N == 160 )
4904
- result = true ;
4905
- else if (L == 2048 && N == 224 )
4906
- result = true ;
4907
- else if (L == 2048 && N == 256 )
4908
- result = true ;
4909
- else if (L == 3072 && N == 256 )
4910
- result = true ;
4911
-
4912
- if (!result) {
4913
- return SignResult (kSignPrivateKey );
4914
- }
4893
+
4894
+ return (L == 1024 && N == 160 ) ||
4895
+ (L == 2048 && N == 224 ) ||
4896
+ (L == 2048 && N == 256 ) ||
4897
+ (L == 3072 && N == 256 )
4915
4898
}
4916
4899
#endif // NODE_FIPS_MODE
4917
4900
4901
+ return true ;
4902
+ }
4903
+
4904
+ Sign::SignResult Sign::SignFinal (
4905
+ const ManagedEVPPKey& pkey,
4906
+ int padding,
4907
+ const Maybe<int >& salt_len) {
4908
+ if (!mdctx_)
4909
+ return SignResult (kSignNotInitialised );
4910
+
4911
+ EVPMDPointer mdctx = std::move (mdctx_);
4912
+
4913
+ if (!ValidateDSAParameters (pkey.get ()))
4914
+ return SignResult (kSignPrivateKey );
4915
+
4918
4916
AllocatedBuffer buffer =
4919
4917
Node_SignFinal (env (), std::move (mdctx), pkey, padding, salt_len);
4920
4918
Error error = buffer.data () == nullptr ? kSignPrivateKey : kSignOk ;
@@ -4965,32 +4963,8 @@ void SignOneShot(const FunctionCallbackInfo<Value>& args) {
4965
4963
if (!key)
4966
4964
return ;
4967
4965
4968
- #ifdef NODE_FIPS_MODE
4969
- /* Validate DSA2 parameters from FIPS 186-4 */
4970
- if (FIPS_mode () && EVP_PKEY_DSA == EVP_PKEY_base_id (key.get ())) {
4971
- DSA* dsa = EVP_PKEY_get0_DSA (key.get ());
4972
- const BIGNUM* p;
4973
- DSA_get0_pqg (dsa, &p, nullptr , nullptr );
4974
- size_t L = BN_num_bits (p);
4975
- const BIGNUM* q;
4976
- DSA_get0_pqg (dsa, nullptr , &q, nullptr );
4977
- size_t N = BN_num_bits (q);
4978
- bool result = false ;
4979
-
4980
- if (L == 1024 && N == 160 )
4981
- result = true ;
4982
- else if (L == 2048 && N == 224 )
4983
- result = true ;
4984
- else if (L == 2048 && N == 256 )
4985
- result = true ;
4986
- else if (L == 3072 && N == 256 )
4987
- result = true ;
4988
-
4989
- if (!result) {
4990
- return CheckThrow (env, SignBase::Error::kSignPrivateKey );
4991
- }
4992
- }
4993
- #endif // NODE_FIPS_MODE
4966
+ if (!ValidateDSAParameters (key.get ()))
4967
+ return CheckThrow (env, SignBase::Error::kSignPrivateKey );
4994
4968
4995
4969
ArrayBufferViewContents<char > data (args[offset]);
4996
4970
0 commit comments