@@ -3211,7 +3211,7 @@ static int pk_new(lua_State *L) {
32113211 if (lua_istable (L , 1 ) || lua_isnil (L , 1 )) {
32123212 int type = EVP_PKEY_RSA ;
32133213 unsigned bits = 1024 ;
3214- unsigned exp = 65537 ;
3214+ BIGNUM * exp = NULL ;
32153215 int generator = 2 ;
32163216 int curve = NID_X9_62_prime192v1 ;
32173217 const char * id ;
@@ -3249,9 +3249,13 @@ static int pk_new(lua_State *L) {
32493249 bits = (unsigned )n ;
32503250 }
32513251
3252- if (loadfield (L , 1 , "exp" , LUA_TNUMBER , & n )) {
3253- luaL_argcheck (L , n > 0 && n < UINT_MAX , 1 , lua_pushfstring (L , "%f: `exp' invalid" , n ));
3254- exp = (unsigned )n ;
3252+ if (!getfield (L , 1 , "exp" )) {
3253+ exp = checkbig (L , -1 );
3254+ } else {
3255+ /* default to 65537 */
3256+ exp = bn_push (L );
3257+ if (!BN_add_word (exp , 65537 ))
3258+ return auxL_error (L , auxL_EOPENSSL , "pkey.new" );
32553259 }
32563260 break ;
32573261 case EVP_PKEY_DH :
@@ -3287,8 +3291,13 @@ static int pk_new(lua_State *L) {
32873291 case EVP_PKEY_RSA : {
32883292 RSA * rsa ;
32893293
3290- if (!(rsa = RSA_generate_key (bits , exp , 0 , 0 )))
3294+ if (!(rsa = RSA_new ()))
3295+ return auxL_error (L , auxL_EOPENSSL , "pkey.new" );
3296+
3297+ if (!RSA_generate_key_ex (rsa , bits , exp , 0 )) {
3298+ RSA_free (rsa );
32913299 return auxL_error (L , auxL_EOPENSSL , "pkey.new" );
3300+ }
32923301
32933302 EVP_PKEY_set1_RSA (* ud , rsa );
32943303
@@ -3299,8 +3308,13 @@ static int pk_new(lua_State *L) {
32993308 case EVP_PKEY_DSA : {
33003309 DSA * dsa ;
33013310
3302- if (!(dsa = DSA_generate_parameters (bits , 0 , 0 , 0 , 0 , 0 , 0 )))
3311+ if (!(dsa = DSA_new ()))
3312+ return auxL_error (L , auxL_EOPENSSL , "pkey.new" );
3313+
3314+ if (!DSA_generate_parameters_ex (dsa , bits , 0 , 0 , 0 , 0 , 0 )) {
3315+ DSA_free (dsa );
33033316 return auxL_error (L , auxL_EOPENSSL , "pkey.new" );
3317+ }
33043318
33053319 if (!DSA_generate_key (dsa )) {
33063320 DSA_free (dsa );
@@ -3329,8 +3343,15 @@ static int pk_new(lua_State *L) {
33293343 BIO_free (bio );
33303344 if (!dh )
33313345 return auxL_error (L , auxL_EOPENSSL , "pkey.new" );
3332- } else if (!(dh = DH_generate_parameters (bits , generator , 0 , 0 )))
3333- return auxL_error (L , auxL_EOPENSSL , "pkey.new" );
3346+ } else {
3347+ if (!(dh = DH_new ()))
3348+ return auxL_error (L , auxL_EOPENSSL , "pkey.new" );
3349+
3350+ if (!DH_generate_parameters_ex (dh , bits , generator , 0 )) {
3351+ DH_free (dh );
3352+ return auxL_error (L , auxL_EOPENSSL , "pkey.new" );
3353+ }
3354+ }
33343355
33353356
33363357 if (!DH_generate_key (dh )) {
0 commit comments