diff options
| -rw-r--r-- | src/openssl.c | 38 |
1 files changed, 24 insertions, 14 deletions
diff --git a/src/openssl.c b/src/openssl.c index e05fcc4..41262c5 100644 --- a/src/openssl.c +++ b/src/openssl.c | |||
| @@ -1558,6 +1558,16 @@ static BIGNUM *bn_push(lua_State *L) { | |||
| 1558 | } /* bn_push() */ | 1558 | } /* bn_push() */ |
| 1559 | 1559 | ||
| 1560 | 1560 | ||
| 1561 | static BIGNUM *bn_dup(lua_State *L, const BIGNUM *src) { | ||
| 1562 | BIGNUM **ud = prepsimple(L, BIGNUM_CLASS); | ||
| 1563 | |||
| 1564 | if (!(*ud = BN_dup(src))) | ||
| 1565 | auxL_error(L, auxL_EOPENSSL, "bignum.new"); | ||
| 1566 | |||
| 1567 | return *ud; | ||
| 1568 | } /* bn_dup() */ | ||
| 1569 | |||
| 1570 | |||
| 1561 | #define checkbig_(a, b, c, ...) checkbig((a), (b), (c)) | 1571 | #define checkbig_(a, b, c, ...) checkbig((a), (b), (c)) |
| 1562 | #define checkbig(...) checkbig_(__VA_ARGS__, &(_Bool){ 0 }, 0) | 1572 | #define checkbig(...) checkbig_(__VA_ARGS__, &(_Bool){ 0 }, 0) |
| 1563 | 1573 | ||
| @@ -2472,64 +2482,64 @@ static int pk_getParameters(lua_State *L) { | |||
| 2472 | switch (EVP_PKEY_base_id(key)) { | 2482 | switch (EVP_PKEY_base_id(key)) { |
| 2473 | case EVP_PKEY_RSA: | 2483 | case EVP_PKEY_RSA: |
| 2474 | /* RSA public modulus n */ | 2484 | /* RSA public modulus n */ |
| 2475 | if (!BN_copy(bn_push(L), ((RSA*)tmp)->n)) | 2485 | if (!bn_dup(L, ((RSA*)tmp)->n)) |
| 2476 | return auxL_error(L, auxL_EOPENSSL, "pkey:getParameters"); | 2486 | return auxL_error(L, auxL_EOPENSSL, "pkey:getParameters"); |
| 2477 | lua_setfield(L, -2, "n"); | 2487 | lua_setfield(L, -2, "n"); |
| 2478 | 2488 | ||
| 2479 | /* RSA public exponent e */ | 2489 | /* RSA public exponent e */ |
| 2480 | if (!BN_copy(bn_push(L), ((RSA*)tmp)->e)) | 2490 | if (!bn_dup(L, ((RSA*)tmp)->e)) |
| 2481 | return auxL_error(L, auxL_EOPENSSL, "pkey:getParameters"); | 2491 | return auxL_error(L, auxL_EOPENSSL, "pkey:getParameters"); |
| 2482 | lua_setfield(L, -2, "e"); | 2492 | lua_setfield(L, -2, "e"); |
| 2483 | 2493 | ||
| 2484 | /* RSA secret exponent d */ | 2494 | /* RSA secret exponent d */ |
| 2485 | if (!BN_copy(bn_push(L), ((RSA*)tmp)->d)) | 2495 | if (!bn_dup(L, ((RSA*)tmp)->d)) |
| 2486 | return auxL_error(L, auxL_EOPENSSL, "pkey:getParameters"); | 2496 | return auxL_error(L, auxL_EOPENSSL, "pkey:getParameters"); |
| 2487 | lua_setfield(L, -2, "d"); | 2497 | lua_setfield(L, -2, "d"); |
| 2488 | 2498 | ||
| 2489 | /* RSA secret prime p */ | 2499 | /* RSA secret prime p */ |
| 2490 | if (!BN_copy(bn_push(L), ((RSA*)tmp)->p)) | 2500 | if (!bn_dup(L, ((RSA*)tmp)->p)) |
| 2491 | return auxL_error(L, auxL_EOPENSSL, "pkey:getParameters"); | 2501 | return auxL_error(L, auxL_EOPENSSL, "pkey:getParameters"); |
| 2492 | lua_setfield(L, -2, "p"); | 2502 | lua_setfield(L, -2, "p"); |
| 2493 | 2503 | ||
| 2494 | /* RSA secret prime q with p < q */ | 2504 | /* RSA secret prime q with p < q */ |
| 2495 | if (!BN_copy(bn_push(L), ((RSA*)tmp)->q)) | 2505 | if (!bn_dup(L, ((RSA*)tmp)->q)) |
| 2496 | return auxL_error(L, auxL_EOPENSSL, "pkey:getParameters"); | 2506 | return auxL_error(L, auxL_EOPENSSL, "pkey:getParameters"); |
| 2497 | lua_setfield(L, -2, "q"); | 2507 | lua_setfield(L, -2, "q"); |
| 2498 | 2508 | ||
| 2499 | /* exponent1 */ | 2509 | /* exponent1 */ |
| 2500 | if (!BN_copy(bn_push(L), ((RSA*)tmp)->dmp1)) | 2510 | if (!bn_dup(L, ((RSA*)tmp)->dmp1)) |
| 2501 | return auxL_error(L, auxL_EOPENSSL, "pkey:getParameters"); | 2511 | return auxL_error(L, auxL_EOPENSSL, "pkey:getParameters"); |
| 2502 | lua_setfield(L, -2, "dmp1"); | 2512 | lua_setfield(L, -2, "dmp1"); |
| 2503 | 2513 | ||
| 2504 | /* exponent2 */ | 2514 | /* exponent2 */ |
| 2505 | if (!BN_copy(bn_push(L), ((RSA*)tmp)->dmq1)) | 2515 | if (!bn_dup(L, ((RSA*)tmp)->dmq1)) |
| 2506 | return auxL_error(L, auxL_EOPENSSL, "pkey:getParameters"); | 2516 | return auxL_error(L, auxL_EOPENSSL, "pkey:getParameters"); |
| 2507 | lua_setfield(L, -2, "dmq1"); | 2517 | lua_setfield(L, -2, "dmq1"); |
| 2508 | 2518 | ||
| 2509 | /* coefficient */ | 2519 | /* coefficient */ |
| 2510 | if (!BN_copy(bn_push(L), ((RSA*)tmp)->iqmp)) | 2520 | if (!bn_dup(L, ((RSA*)tmp)->iqmp)) |
| 2511 | return auxL_error(L, auxL_EOPENSSL, "pkey:getParameters"); | 2521 | return auxL_error(L, auxL_EOPENSSL, "pkey:getParameters"); |
| 2512 | lua_setfield(L, -2, "iqmp"); | 2522 | lua_setfield(L, -2, "iqmp"); |
| 2513 | 2523 | ||
| 2514 | break; | 2524 | break; |
| 2515 | case EVP_PKEY_DH: | 2525 | case EVP_PKEY_DH: |
| 2516 | /* prime */ | 2526 | /* prime */ |
| 2517 | if (!BN_copy(bn_push(L), ((DH*)tmp)->p)) | 2527 | if (!bn_dup(L, ((DH*)tmp)->p)) |
| 2518 | return auxL_error(L, auxL_EOPENSSL, "pkey:getParameters"); | 2528 | return auxL_error(L, auxL_EOPENSSL, "pkey:getParameters"); |
| 2519 | lua_setfield(L, -2, "p"); | 2529 | lua_setfield(L, -2, "p"); |
| 2520 | 2530 | ||
| 2521 | /* generator */ | 2531 | /* generator */ |
| 2522 | if (!BN_copy(bn_push(L), ((DH*)tmp)->g)) | 2532 | if (!bn_dup(L, ((DH*)tmp)->g)) |
| 2523 | return auxL_error(L, auxL_EOPENSSL, "pkey:getParameters"); | 2533 | return auxL_error(L, auxL_EOPENSSL, "pkey:getParameters"); |
| 2524 | lua_setfield(L, -2, "g"); | 2534 | lua_setfield(L, -2, "g"); |
| 2525 | 2535 | ||
| 2526 | /* pub_key */ | 2536 | /* pub_key */ |
| 2527 | if (!BN_copy(bn_push(L), ((DH*)tmp)->pub_key)) | 2537 | if (!bn_dup(L, ((DH*)tmp)->pub_key)) |
| 2528 | return auxL_error(L, auxL_EOPENSSL, "pkey:getParameters"); | 2538 | return auxL_error(L, auxL_EOPENSSL, "pkey:getParameters"); |
| 2529 | lua_setfield(L, -2, "pub_key"); | 2539 | lua_setfield(L, -2, "pub_key"); |
| 2530 | 2540 | ||
| 2531 | /* priv_key */ | 2541 | /* priv_key */ |
| 2532 | if (!BN_copy(bn_push(L), ((DH*)tmp)->priv_key)) | 2542 | if (!bn_dup(L, ((DH*)tmp)->priv_key)) |
| 2533 | return auxL_error(L, auxL_EOPENSSL, "pkey:getParameters"); | 2543 | return auxL_error(L, auxL_EOPENSSL, "pkey:getParameters"); |
| 2534 | lua_setfield(L, -2, "priv_key"); | 2544 | lua_setfield(L, -2, "priv_key"); |
| 2535 | 2545 | ||
| @@ -2538,12 +2548,12 @@ static int pk_getParameters(lua_State *L) { | |||
| 2538 | /* pub_key */ | 2548 | /* pub_key */ |
| 2539 | if (!(group = EC_KEY_get0_group(tmp)) || !(public_key = EC_KEY_get0_public_key(tmp))) | 2549 | if (!(group = EC_KEY_get0_group(tmp)) || !(public_key = EC_KEY_get0_public_key(tmp))) |
| 2540 | return auxL_error(L, auxL_EOPENSSL, "pkey:getParameters"); | 2550 | return auxL_error(L, auxL_EOPENSSL, "pkey:getParameters"); |
| 2541 | if (!BN_copy(bn_push(L), EC_POINT_point2bn(group, public_key, EC_KEY_get_conv_form(tmp), NULL, getctx(L)))) | 2551 | if (!bn_dup(L, EC_POINT_point2bn(group, public_key, EC_KEY_get_conv_form(tmp), NULL, getctx(L)))) |
| 2542 | return auxL_error(L, auxL_EOPENSSL, "pkey:getParameters"); | 2552 | return auxL_error(L, auxL_EOPENSSL, "pkey:getParameters"); |
| 2543 | lua_setfield(L, -2, "pub_key"); | 2553 | lua_setfield(L, -2, "pub_key"); |
| 2544 | 2554 | ||
| 2545 | /* priv_key */ | 2555 | /* priv_key */ |
| 2546 | if (!BN_copy(bn_push(L), EC_KEY_get0_private_key(tmp))) | 2556 | if (!bn_dup(L, EC_KEY_get0_private_key(tmp))) |
| 2547 | return auxL_error(L, auxL_EOPENSSL, "pkey:getParameters"); | 2557 | return auxL_error(L, auxL_EOPENSSL, "pkey:getParameters"); |
| 2548 | lua_setfield(L, -2, "priv_key"); | 2558 | lua_setfield(L, -2, "priv_key"); |
| 2549 | 2559 | ||
