diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/openssl.c | 37 |
1 files changed, 29 insertions, 8 deletions
diff --git a/src/openssl.c b/src/openssl.c index 0354666..6e4600a 100644 --- a/src/openssl.c +++ b/src/openssl.c | |||
@@ -3211,7 +3211,7 @@ static int pk_new(lua_State *L) { | |||
3211 | if (lua_istable(L, 1) || lua_isnil(L, 1)) { | 3211 | if (lua_istable(L, 1) || lua_isnil(L, 1)) { |
3212 | int type = EVP_PKEY_RSA; | 3212 | int type = EVP_PKEY_RSA; |
3213 | unsigned bits = 1024; | 3213 | unsigned bits = 1024; |
3214 | unsigned exp = 65537; | 3214 | BIGNUM *exp = NULL; |
3215 | int generator = 2; | 3215 | int generator = 2; |
3216 | int curve = NID_X9_62_prime192v1; | 3216 | int curve = NID_X9_62_prime192v1; |
3217 | const char *id; | 3217 | const char *id; |
@@ -3249,9 +3249,13 @@ static int pk_new(lua_State *L) { | |||
3249 | bits = (unsigned)n; | 3249 | bits = (unsigned)n; |
3250 | } | 3250 | } |
3251 | 3251 | ||
3252 | if (loadfield(L, 1, "exp", LUA_TNUMBER, &n)) { | 3252 | if (!getfield(L, 1, "exp")) { |
3253 | luaL_argcheck(L, n > 0 && n < UINT_MAX, 1, lua_pushfstring(L, "%f: `exp' invalid", n)); | 3253 | exp = checkbig(L, -1); |
3254 | exp = (unsigned)n; | 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"); | ||
3255 | } | 3259 | } |
3256 | break; | 3260 | break; |
3257 | case EVP_PKEY_DH: | 3261 | case EVP_PKEY_DH: |
@@ -3287,8 +3291,13 @@ creat: | |||
3287 | case EVP_PKEY_RSA: { | 3291 | case EVP_PKEY_RSA: { |
3288 | RSA *rsa; | 3292 | RSA *rsa; |
3289 | 3293 | ||
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); | ||
3291 | return auxL_error(L, auxL_EOPENSSL, "pkey.new"); | 3299 | return auxL_error(L, auxL_EOPENSSL, "pkey.new"); |
3300 | } | ||
3292 | 3301 | ||
3293 | EVP_PKEY_set1_RSA(*ud, rsa); | 3302 | EVP_PKEY_set1_RSA(*ud, rsa); |
3294 | 3303 | ||
@@ -3299,8 +3308,13 @@ creat: | |||
3299 | case EVP_PKEY_DSA: { | 3308 | case EVP_PKEY_DSA: { |
3300 | DSA *dsa; | 3309 | DSA *dsa; |
3301 | 3310 | ||
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); | ||
3303 | return auxL_error(L, auxL_EOPENSSL, "pkey.new"); | 3316 | return auxL_error(L, auxL_EOPENSSL, "pkey.new"); |
3317 | } | ||
3304 | 3318 | ||
3305 | if (!DSA_generate_key(dsa)) { | 3319 | if (!DSA_generate_key(dsa)) { |
3306 | DSA_free(dsa); | 3320 | DSA_free(dsa); |
@@ -3329,8 +3343,15 @@ creat: | |||
3329 | BIO_free(bio); | 3343 | BIO_free(bio); |
3330 | if (!dh) | 3344 | if (!dh) |
3331 | return auxL_error(L, auxL_EOPENSSL, "pkey.new"); | 3345 | return auxL_error(L, auxL_EOPENSSL, "pkey.new"); |
3332 | } else if (!(dh = DH_generate_parameters(bits, generator, 0, 0))) | 3346 | } else { |
3333 | return auxL_error(L, auxL_EOPENSSL, "pkey.new"); | 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 | } | ||
3334 | 3355 | ||
3335 | 3356 | ||
3336 | if (!DH_generate_key(dh)) { | 3357 | if (!DH_generate_key(dh)) { |