From fcd7076005e7e81e37e31df9e5b712214cead2c6 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Thu, 10 Dec 2015 23:11:35 +1100 Subject: pk_getParameters: Add 'public_only' flag to only export the public key parameters Should possibly a string/table instead? --- src/openssl.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/openssl.c b/src/openssl.c index 41262c5..82483af 100644 --- a/src/openssl.c +++ b/src/openssl.c @@ -2470,6 +2470,8 @@ static int pk_toPEM(lua_State *L) { static int pk_getParameters(lua_State *L) { EVP_PKEY *key = checksimple(L, 1, PKEY_CLASS); + _Bool public_only = lua_toboolean(L, 2); + void *tmp; const EC_GROUP *group; const EC_POINT *public_key; @@ -2491,6 +2493,8 @@ static int pk_getParameters(lua_State *L) { return auxL_error(L, auxL_EOPENSSL, "pkey:getParameters"); lua_setfield(L, -2, "e"); + if (public_only) break; + /* RSA secret exponent d */ if (!bn_dup(L, ((RSA*)tmp)->d)) return auxL_error(L, auxL_EOPENSSL, "pkey:getParameters"); @@ -2538,6 +2542,8 @@ static int pk_getParameters(lua_State *L) { return auxL_error(L, auxL_EOPENSSL, "pkey:getParameters"); lua_setfield(L, -2, "pub_key"); + if (public_only) break; + /* priv_key */ if (!bn_dup(L, ((DH*)tmp)->priv_key)) return auxL_error(L, auxL_EOPENSSL, "pkey:getParameters"); @@ -2552,6 +2558,8 @@ static int pk_getParameters(lua_State *L) { return auxL_error(L, auxL_EOPENSSL, "pkey:getParameters"); lua_setfield(L, -2, "pub_key"); + if (public_only) break; + /* priv_key */ if (!bn_dup(L, EC_KEY_get0_private_key(tmp))) return auxL_error(L, auxL_EOPENSSL, "pkey:getParameters"); -- cgit v1.2.3-59-g8ed1b