@@ -27,6 +27,7 @@ local format_error = require("resty.openssl.err").format_error
27
27
local OPENSSL_11_OR_LATER = require (" resty.openssl.version" ).OPENSSL_11_OR_LATER
28
28
local OPENSSL_111_OR_LATER = require (" resty.openssl.version" ).OPENSSL_111_OR_LATER
29
29
local OPENSSL_30 = require (" resty.openssl.version" ).OPENSSL_30
30
+ local BORINGSSL = require (" resty.openssl.version" ).BORINGSSL
30
31
31
32
local ptr_of_uint = ctypes .ptr_of_uint
32
33
local ptr_of_size_t = ctypes .ptr_of_size_t
@@ -162,23 +163,16 @@ local function generate_param(key_type, config)
162
163
if nid == 0 then
163
164
return nil , " unknown curve " .. curve
164
165
end
165
- -- EVP_PKEY_CTX_set_ec_paramgen_curve_nid
166
- if C .EVP_PKEY_CTX_ctrl (pctx ,
167
- evp_macro .EVP_PKEY_EC ,
168
- evp_macro .EVP_PKEY_OP_PARAMGEN + evp_macro .EVP_PKEY_OP_KEYGEN ,
169
- evp_macro .EVP_PKEY_CTRL_EC_PARAMGEN_CURVE_NID ,
170
- nid , nil ) <= 0 then
166
+ if evp_macro .EVP_PKEY_CTX_set_ec_paramgen_curve_nid (pctx , nid ) <= 0 then
171
167
return nil , format_error (" EVP_PKEY_CTX_ctrl: EC: curve_nid" )
172
168
end
173
- -- use the named-curve encoding for best backward-compatibilty
174
- -- and for playing well with go:crypto/x509
175
- -- # define OPENSSL_EC_NAMED_CURVE 0x001
176
- if C .EVP_PKEY_CTX_ctrl (pctx ,
177
- evp_macro .EVP_PKEY_EC ,
178
- evp_macro .EVP_PKEY_OP_PARAMGEN + evp_macro .EVP_PKEY_OP_KEYGEN ,
179
- evp_macro .EVP_PKEY_CTRL_EC_PARAM_ENC ,
180
- 1 , nil ) <= 0 then
181
- return nil , format_error (" EVP_PKEY_CTX_ctrl: EC: param_enc" )
169
+ if not BORINGSSL then
170
+ -- use the named-curve encoding for best backward-compatibilty
171
+ -- and for playing well with go:crypto/x509
172
+ -- # define OPENSSL_EC_NAMED_CURVE 0x001
173
+ if evp_macro .EVP_PKEY_CTX_set_ec_param_enc (pctx , 1 ) <= 0 then
174
+ return nil , format_error (" EVP_PKEY_CTX_ctrl: EC: param_enc" )
175
+ end
182
176
end
183
177
elseif key_type == evp_macro .EVP_PKEY_DH then
184
178
local bits = config .bits
@@ -302,11 +296,7 @@ local function generate_key(config)
302
296
return nil , " bits out of range"
303
297
end
304
298
305
- -- EVP_PKEY_CTX_set_rsa_keygen_bits
306
- if C .EVP_PKEY_CTX_ctrl (pctx ,
307
- evp_macro .EVP_PKEY_RSA , evp_macro .EVP_PKEY_OP_KEYGEN ,
308
- evp_macro .EVP_PKEY_CTRL_RSA_KEYGEN_BITS ,
309
- bits , nil ) <= 0 then
299
+ if evp_macro .EVP_PKEY_CTX_set_rsa_keygen_bits (pctx , bits ) <= 0 then
310
300
return nil , format_error (" EVP_PKEY_CTX_ctrl: RSA: bits" )
311
301
end
312
302
@@ -317,11 +307,8 @@ local function generate_key(config)
317
307
return nil , " BN_new() failed"
318
308
end
319
309
C .BN_set_word (exp , config .exp )
320
- -- EVP_PKEY_CTX_set_rsa_keygen_pubexp
321
- if C .EVP_PKEY_CTX_ctrl (pctx ,
322
- evp_macro .EVP_PKEY_RSA , evp_macro .EVP_PKEY_OP_KEYGEN ,
323
- evp_macro .EVP_PKEY_CTRL_RSA_KEYGEN_PUBEXP ,
324
- 0 , exp ) <= 0 then
310
+
311
+ if evp_macro .EVP_PKEY_CTX_set_rsa_keygen_pubexp (pctx , exp ) <= 0 then
325
312
return nil , format_error (" EVP_PKEY_CTX_ctrl: RSA: exp" )
326
313
end
327
314
end
@@ -608,15 +595,7 @@ local function asymmetric_routine(self, s, op, padding)
608
595
609
596
-- EVP_PKEY_CTX_ctrl must be called after *_init
610
597
if self .key_type == evp_macro .EVP_PKEY_RSA and padding then
611
- local code
612
- if OPENSSL_30 then
613
- code = C .EVP_PKEY_CTX_set_rsa_padding (pkey_ctx , padding )
614
- else
615
- code = C .EVP_PKEY_CTX_ctrl (pkey_ctx , evp_macro .EVP_PKEY_RSA , - 1 ,
616
- evp_macro .EVP_PKEY_CTRL_RSA_PADDING ,
617
- padding , nil )
618
- end
619
- if code ~= 1 then
598
+ if evp_macro .EVP_PKEY_CTX_set_rsa_padding (pkey_ctx , padding ) ~= 1 then
620
599
return nil , format_error (" pkey:asymmetric_routine EVP_PKEY_CTX_ctrl" )
621
600
end
622
601
self .rsa_padding = padding
0 commit comments