diff --git a/src/pkey.c b/src/pkey.c index bc3bf528..ae06ce66 100644 --- a/src/pkey.c +++ b/src/pkey.c @@ -18,8 +18,14 @@ static const char *evp_pkey_type2name(int type); int openssl_pkey_is_private(EVP_PKEY* pkey) { int ret = 0; - int typ; assert(pkey != NULL); +#if (OPENSSL_VERSION_NUMBER >= 0x30000000L) + EVP_PKEY_CTX *ctx = EVP_PKEY_CTX_new_from_pkey(NULL, pkey, NULL); + if (EVP_PKEY_private_check(ctx)) + ret = 1; + EVP_PKEY_CTX_free(ctx); +#else + int typ; typ = EVP_PKEY_type(EVP_PKEY_id(pkey)); switch (typ) { @@ -69,6 +75,7 @@ int openssl_pkey_is_private(EVP_PKEY* pkey) default: break; } +#endif return ret; } diff --git a/test/4.pkey.lua b/test/4.pkey.lua index 6c99ebd8..5f608805 100644 --- a/test/4.pkey.lua +++ b/test/4.pkey.lua @@ -109,6 +109,16 @@ function TestPKEYMY:testBasic() end end +if helper.openssl3 then + function testED25519() + local key = openssl.pkey.ctx_new('ED25519'):keygen() + assert(key:is_private()) + local pem = key:export('pem', true) + key = openssl.pkey.read(pem, true, 'pem') + assert(key:is_private()) + end +end + function testRSA() local nrsa = {'rsa', 1024, 3} local rsa = pkey.new(unpack(nrsa))