Skip to content

Commit 30ba7cf

Browse files
committed
fix(kdf) correct FFI definition for BoringSSL
1 parent 8c107e3 commit 30ba7cf

File tree

2 files changed

+27
-23
lines changed

2 files changed

+27
-23
lines changed

lib/resty/openssl/include/evp.lua

+26-11
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,33 @@ local bit = require("bit")
55
require "resty.openssl.include.ossl_typ"
66
require "resty.openssl.include.objects"
77
local OPENSSL_30 = require("resty.openssl.version").OPENSSL_30
8+
local BORINGSSL = require("resty.openssl.version").BORINGSSL
89

9-
ffi.cdef [[
10-
/* KDF */
11-
int PKCS5_PBKDF2_HMAC(const char *pass, int passlen,
12-
const unsigned char *salt, int saltlen, int iter,
13-
const EVP_MD *digest, int keylen, unsigned char *out);
14-
15-
int EVP_PBE_scrypt(const char *pass, size_t passlen,
16-
const unsigned char *salt, size_t saltlen,
17-
uint64_t N, uint64_t r, uint64_t p, uint64_t maxmem,
18-
unsigned char *key, size_t keylen);
19-
]]
10+
if BORINGSSL then
11+
ffi.cdef [[
12+
int PKCS5_PBKDF2_HMAC(const char *password, size_t password_len,
13+
const uint8_t *salt, size_t salt_len,
14+
unsigned iterations, const EVP_MD *digest,
15+
size_t key_len, uint8_t *out_key);
16+
int EVP_PBE_scrypt(const char *password, size_t password_len,
17+
const uint8_t *salt, size_t salt_len,
18+
uint64_t N, uint64_t r, uint64_t p,
19+
size_t max_mem, uint8_t *out_key,
20+
size_t key_len);
21+
]]
22+
else
23+
ffi.cdef [[
24+
/* KDF */
25+
int PKCS5_PBKDF2_HMAC(const char *pass, int passlen,
26+
const unsigned char *salt, int saltlen, int iter,
27+
const EVP_MD *digest, int keylen, unsigned char *out);
28+
29+
int EVP_PBE_scrypt(const char *pass, size_t passlen,
30+
const unsigned char *salt, size_t saltlen,
31+
uint64_t N, uint64_t r, uint64_t p, uint64_t maxmem,
32+
unsigned char *key, size_t keylen);
33+
]]
34+
end
2035

2136
if OPENSSL_30 then
2237
require "resty.openssl.include.provider"

t/openssl/kdf.t

+1-12
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use Cwd qw(cwd);
77
my $pwd = cwd();
88

99
my $use_luacov = $ENV{'TEST_NGINX_USE_LUACOV'} // '';
10-
my $on_github_actions = $ENV{'CI'} // '';
1110

1211
our $HttpConfig = qq{
1312
lua_package_path "$pwd/t/openssl/?.lua;$pwd/lib/?.lua;$pwd/lib/?/init.lua;;";
@@ -17,7 +16,6 @@ our $HttpConfig = qq{
1716
jit.off()
1817
end
1918
_G.myassert = require("helper").myassert
20-
_G.on_github_actions = "$on_github_actions" ~= ""
2119
}
2220
};
2321

@@ -73,11 +71,7 @@ kdf.derive: unknown type 19823718236128632
7371
--- config
7472
location =/t {
7573
content_by_lua_block {
76-
-- boringssl has pbkdf2 working, but not github actions, why?
77-
if require("resty.openssl.version").BORINGSSL and _G.on_github_actions then
78-
ngx.say("cDRFLQ7NWt+AP4i0TdBzog==")
79-
ngx.exit(0)
80-
end
74+
8175
local kdf = require("resty.openssl.kdf")
8276
local key = myassert(kdf.derive({
8377
type = kdf.PBKDF2,
@@ -103,11 +97,6 @@ kdf.derive: unknown type 19823718236128632
10397
--- config
10498
location =/t {
10599
content_by_lua_block {
106-
-- boringssl has pbkdf2 working, but not github actions, why?
107-
if require("resty.openssl.version").BORINGSSL and _G.on_github_actions then
108-
ngx.say("HkN6HHnXW+YekRQdriCv/A==")
109-
ngx.exit(0)
110-
end
111100
local kdf = require("resty.openssl.kdf")
112101
local key = myassert(kdf.derive({
113102
type = kdf.PBKDF2,

0 commit comments

Comments
 (0)