7
7
#include " memory_tracker-inl.h"
8
8
#include " ncrypto.h"
9
9
#include " node_errors.h"
10
+ #ifndef OPENSSL_IS_BORINGSSL
10
11
#include " openssl/bnerr.h"
12
+ #endif
11
13
#include " openssl/dh.h"
12
14
#include " threadpoolwork-inl.h"
13
15
#include " v8.h"
@@ -88,11 +90,15 @@ void New(const FunctionCallbackInfo<Value>& args) {
88
90
if (args[0 ]->IsInt32 ()) {
89
91
int32_t bits = args[0 ].As <Int32>()->Value ();
90
92
if (bits < 2 ) {
93
+ #ifndef OPENSSL_IS_BORINGSSL
91
94
#if OPENSSL_VERSION_MAJOR >= 3
92
95
ERR_put_error (ERR_LIB_DH, 0 , DH_R_MODULUS_TOO_SMALL, __FILE__, __LINE__);
93
96
#else
94
97
ERR_put_error (ERR_LIB_BN, 0 , BN_R_BITS_TOO_SMALL, __FILE__, __LINE__);
95
- #endif
98
+ #endif // OPENSSL_VERSION_MAJOR >= 3
99
+ #else // OPENSSL_IS_BORINGSSL
100
+ OPENSSL_PUT_ERROR (BN, BN_R_BITS_TOO_SMALL);
101
+ #endif // OPENSSL_IS_BORINGSSL
96
102
return ThrowCryptoError (env, ERR_get_error (), " Invalid prime length" );
97
103
}
98
104
@@ -105,7 +111,11 @@ void New(const FunctionCallbackInfo<Value>& args) {
105
111
}
106
112
int32_t generator = args[1 ].As <Int32>()->Value ();
107
113
if (generator < 2 ) {
114
+ #ifndef OPENSSL_IS_BORINGSSL
108
115
ERR_put_error (ERR_LIB_DH, 0 , DH_R_BAD_GENERATOR, __FILE__, __LINE__);
116
+ #else
117
+ OPENSSL_PUT_ERROR (DH, DH_R_BAD_GENERATOR);
118
+ #endif
109
119
return ThrowCryptoError (env, ERR_get_error (), " Invalid generator" );
110
120
}
111
121
@@ -134,12 +144,20 @@ void New(const FunctionCallbackInfo<Value>& args) {
134
144
if (args[1 ]->IsInt32 ()) {
135
145
int32_t generator = args[1 ].As <Int32>()->Value ();
136
146
if (generator < 2 ) {
147
+ #ifndef OPENSSL_IS_BORINGSSL
137
148
ERR_put_error (ERR_LIB_DH, 0 , DH_R_BAD_GENERATOR, __FILE__, __LINE__);
149
+ #else
150
+ OPENSSL_PUT_ERROR (DH, DH_R_BAD_GENERATOR);
151
+ #endif
138
152
return ThrowCryptoError (env, ERR_get_error (), " Invalid generator" );
139
153
}
140
154
bn_g = BignumPointer::New ();
141
155
if (!bn_g.setWord (generator)) {
156
+ #ifndef OPENSSL_IS_BORINGSSL
142
157
ERR_put_error (ERR_LIB_DH, 0 , DH_R_BAD_GENERATOR, __FILE__, __LINE__);
158
+ #else
159
+ OPENSSL_PUT_ERROR (DH, DH_R_BAD_GENERATOR);
160
+ #endif
143
161
return ThrowCryptoError (env, ERR_get_error (), " Invalid generator" );
144
162
}
145
163
} else {
@@ -148,11 +166,19 @@ void New(const FunctionCallbackInfo<Value>& args) {
148
166
return THROW_ERR_OUT_OF_RANGE (env, " generator is too big" );
149
167
bn_g = BignumPointer (reinterpret_cast <uint8_t *>(arg1.data ()), arg1.size ());
150
168
if (!bn_g) {
169
+ #ifndef OPENSSL_IS_BORINGSSL
151
170
ERR_put_error (ERR_LIB_DH, 0 , DH_R_BAD_GENERATOR, __FILE__, __LINE__);
171
+ #else
172
+ OPENSSL_PUT_ERROR (DH, DH_R_BAD_GENERATOR);
173
+ #endif
152
174
return ThrowCryptoError (env, ERR_get_error (), " Invalid generator" );
153
175
}
154
176
if (bn_g.getWord () < 2 ) {
177
+ #ifndef OPENSSL_IS_BORINGSSL
155
178
ERR_put_error (ERR_LIB_DH, 0 , DH_R_BAD_GENERATOR, __FILE__, __LINE__);
179
+ #else
180
+ OPENSSL_PUT_ERROR (DH, DH_R_BAD_GENERATOR);
181
+ #endif
156
182
return ThrowCryptoError (env, ERR_get_error (), " Invalid generator" );
157
183
}
158
184
}
@@ -398,14 +424,19 @@ EVPKeyCtxPointer DhKeyGenTraits::Setup(DhKeyPairGenConfig* params) {
398
424
if (!dh) return {};
399
425
400
426
key_params = EVPKeyPointer::NewDH (std::move (dh));
401
- } else if (int * prime_size = std::get_if<int >(¶ms->params .prime )) {
427
+ } else if (std::get_if<int >(¶ms->params .prime )) {
402
428
auto param_ctx = EVPKeyCtxPointer::NewFromID (EVP_PKEY_DH);
429
+ #ifndef OPENSSL_IS_BORINGSSL
430
+ int * prime_size = std::get_if<int >(¶ms->params .prime );
403
431
if (!param_ctx.initForParamgen () ||
404
432
!param_ctx.setDhParameters (*prime_size, params->params .generator )) {
405
433
return {};
406
434
}
407
435
408
436
key_params = param_ctx.paramgen ();
437
+ #else
438
+ return {};
439
+ #endif
409
440
} else {
410
441
UNREACHABLE ();
411
442
}
0 commit comments