diff options
| author | William Ahern <william@25thandClement.com> | 2015-12-18 14:14:53 +0800 |
|---|---|---|
| committer | William Ahern <william@25thandClement.com> | 2015-12-18 14:14:53 +0800 |
| commit | 73b1a614759da1bc064d3b6cfff221981b04d8b8 (patch) | |
| tree | 4657110add562408abe1d98deed160f80de1c7d5 | |
| parent | b105f09ccc6ef4a90b97745f50a46a5910edcdc1 (diff) | |
| download | luaossl-73b1a614759da1bc064d3b6cfff221981b04d8b8.tar.gz luaossl-73b1a614759da1bc064d3b6cfff221981b04d8b8.tar.bz2 luaossl-73b1a614759da1bc064d3b6cfff221981b04d8b8.zip | |
bn_dup only returns on success, so remove error handling from bn_dup calls
| -rw-r--r-- | src/openssl.c | 60 |
1 files changed, 26 insertions, 34 deletions
diff --git a/src/openssl.c b/src/openssl.c index dea175e..5bc42ab 100644 --- a/src/openssl.c +++ b/src/openssl.c | |||
| @@ -1562,7 +1562,7 @@ static BIGNUM *bn_dup(lua_State *L, const BIGNUM *src) { | |||
| 1562 | BIGNUM **ud = prepsimple(L, BIGNUM_CLASS); | 1562 | BIGNUM **ud = prepsimple(L, BIGNUM_CLASS); |
| 1563 | 1563 | ||
| 1564 | if (!(*ud = BN_dup(src))) | 1564 | if (!(*ud = BN_dup(src))) |
| 1565 | auxL_error(L, auxL_EOPENSSL, "bignum.new"); | 1565 | auxL_error(L, auxL_EOPENSSL, "bignum"); |
| 1566 | 1566 | ||
| 1567 | return *ud; | 1567 | return *ud; |
| 1568 | } /* bn_dup() */ | 1568 | } /* bn_dup() */ |
| @@ -2514,76 +2514,66 @@ static int pk_getParameters(lua_State *L) { | |||
| 2514 | void *tmp; | 2514 | void *tmp; |
| 2515 | 2515 | ||
| 2516 | if (!(tmp = EVP_PKEY_get0(key))) | 2516 | if (!(tmp = EVP_PKEY_get0(key))) |
| 2517 | return auxL_error(L, auxL_EOPENSSL, "pkey:getParameters"); | 2517 | goto sslerr; |
| 2518 | 2518 | ||
| 2519 | lua_newtable(L); | 2519 | lua_newtable(L); |
| 2520 | 2520 | ||
| 2521 | switch (EVP_PKEY_base_id(key)) { | 2521 | switch (EVP_PKEY_base_id(key)) { |
| 2522 | case EVP_PKEY_RSA: | 2522 | case EVP_PKEY_RSA: |
| 2523 | /* RSA public modulus n */ | 2523 | /* RSA public modulus n */ |
| 2524 | if (!bn_dup(L, ((RSA*)tmp)->n)) | 2524 | bn_dup(L, ((RSA*)tmp)->n); |
| 2525 | return auxL_error(L, auxL_EOPENSSL, "pkey:getParameters"); | ||
| 2526 | lua_setfield(L, -2, "n"); | 2525 | lua_setfield(L, -2, "n"); |
| 2527 | 2526 | ||
| 2528 | /* RSA public exponent e */ | 2527 | /* RSA public exponent e */ |
| 2529 | if (!bn_dup(L, ((RSA*)tmp)->e)) | 2528 | bn_dup(L, ((RSA*)tmp)->e); |
| 2530 | return auxL_error(L, auxL_EOPENSSL, "pkey:getParameters"); | ||
| 2531 | lua_setfield(L, -2, "e"); | 2529 | lua_setfield(L, -2, "e"); |
| 2532 | 2530 | ||
| 2533 | if (public_only) break; | 2531 | if (public_only) |
| 2532 | break; | ||
| 2534 | 2533 | ||
| 2535 | /* RSA secret exponent d */ | 2534 | /* RSA secret exponent d */ |
| 2536 | if (!bn_dup(L, ((RSA*)tmp)->d)) | 2535 | bn_dup(L, ((RSA*)tmp)->d); |
| 2537 | return auxL_error(L, auxL_EOPENSSL, "pkey:getParameters"); | ||
| 2538 | lua_setfield(L, -2, "d"); | 2536 | lua_setfield(L, -2, "d"); |
| 2539 | 2537 | ||
| 2540 | /* RSA secret prime p */ | 2538 | /* RSA secret prime p */ |
| 2541 | if (!bn_dup(L, ((RSA*)tmp)->p)) | 2539 | bn_dup(L, ((RSA*)tmp)->p); |
| 2542 | return auxL_error(L, auxL_EOPENSSL, "pkey:getParameters"); | ||
| 2543 | lua_setfield(L, -2, "p"); | 2540 | lua_setfield(L, -2, "p"); |
| 2544 | 2541 | ||
| 2545 | /* RSA secret prime q with p < q */ | 2542 | /* RSA secret prime q with p < q */ |
| 2546 | if (!bn_dup(L, ((RSA*)tmp)->q)) | 2543 | bn_dup(L, ((RSA*)tmp)->q); |
| 2547 | return auxL_error(L, auxL_EOPENSSL, "pkey:getParameters"); | ||
| 2548 | lua_setfield(L, -2, "q"); | 2544 | lua_setfield(L, -2, "q"); |
| 2549 | 2545 | ||
| 2550 | /* exponent1 */ | 2546 | /* exponent1 */ |
| 2551 | if (!bn_dup(L, ((RSA*)tmp)->dmp1)) | 2547 | bn_dup(L, ((RSA*)tmp)->dmp1); |
| 2552 | return auxL_error(L, auxL_EOPENSSL, "pkey:getParameters"); | ||
| 2553 | lua_setfield(L, -2, "dmp1"); | 2548 | lua_setfield(L, -2, "dmp1"); |
| 2554 | 2549 | ||
| 2555 | /* exponent2 */ | 2550 | /* exponent2 */ |
| 2556 | if (!bn_dup(L, ((RSA*)tmp)->dmq1)) | 2551 | bn_dup(L, ((RSA*)tmp)->dmq1); |
| 2557 | return auxL_error(L, auxL_EOPENSSL, "pkey:getParameters"); | ||
| 2558 | lua_setfield(L, -2, "dmq1"); | 2552 | lua_setfield(L, -2, "dmq1"); |
| 2559 | 2553 | ||
| 2560 | /* coefficient */ | 2554 | /* coefficient */ |
| 2561 | if (!bn_dup(L, ((RSA*)tmp)->iqmp)) | 2555 | bn_dup(L, ((RSA*)tmp)->iqmp); |
| 2562 | return auxL_error(L, auxL_EOPENSSL, "pkey:getParameters"); | ||
| 2563 | lua_setfield(L, -2, "iqmp"); | 2556 | lua_setfield(L, -2, "iqmp"); |
| 2564 | 2557 | ||
| 2565 | break; | 2558 | break; |
| 2566 | case EVP_PKEY_DH: | 2559 | case EVP_PKEY_DH: |
| 2567 | /* prime */ | 2560 | /* prime */ |
| 2568 | if (!bn_dup(L, ((DH*)tmp)->p)) | 2561 | bn_dup(L, ((DH*)tmp)->p); |
| 2569 | return auxL_error(L, auxL_EOPENSSL, "pkey:getParameters"); | ||
| 2570 | lua_setfield(L, -2, "p"); | 2562 | lua_setfield(L, -2, "p"); |
| 2571 | 2563 | ||
| 2572 | /* generator */ | 2564 | /* generator */ |
| 2573 | if (!bn_dup(L, ((DH*)tmp)->g)) | 2565 | bn_dup(L, ((DH*)tmp)->g); |
| 2574 | return auxL_error(L, auxL_EOPENSSL, "pkey:getParameters"); | ||
| 2575 | lua_setfield(L, -2, "g"); | 2566 | lua_setfield(L, -2, "g"); |
| 2576 | 2567 | ||
| 2577 | /* pub_key */ | 2568 | /* pub_key */ |
| 2578 | if (!bn_dup(L, ((DH*)tmp)->pub_key)) | 2569 | bn_dup(L, ((DH*)tmp)->pub_key); |
| 2579 | return auxL_error(L, auxL_EOPENSSL, "pkey:getParameters"); | ||
| 2580 | lua_setfield(L, -2, "pub_key"); | 2570 | lua_setfield(L, -2, "pub_key"); |
| 2581 | 2571 | ||
| 2582 | if (public_only) break; | 2572 | if (public_only) |
| 2573 | break; | ||
| 2583 | 2574 | ||
| 2584 | /* priv_key */ | 2575 | /* priv_key */ |
| 2585 | if (!bn_dup(L, ((DH*)tmp)->priv_key)) | 2576 | bn_dup(L, ((DH*)tmp)->priv_key); |
| 2586 | return auxL_error(L, auxL_EOPENSSL, "pkey:getParameters"); | ||
| 2587 | lua_setfield(L, -2, "priv_key"); | 2577 | lua_setfield(L, -2, "priv_key"); |
| 2588 | 2578 | ||
| 2589 | break; | 2579 | break; |
| @@ -2594,16 +2584,16 @@ static int pk_getParameters(lua_State *L) { | |||
| 2594 | 2584 | ||
| 2595 | /* pub_key */ | 2585 | /* pub_key */ |
| 2596 | if (!(group = EC_KEY_get0_group(tmp)) || !(public_key = EC_KEY_get0_public_key(tmp))) | 2586 | if (!(group = EC_KEY_get0_group(tmp)) || !(public_key = EC_KEY_get0_public_key(tmp))) |
| 2597 | return auxL_error(L, auxL_EOPENSSL, "pkey:getParameters"); | 2587 | goto sslerr; |
| 2598 | if (!bn_dup(L, EC_POINT_point2bn(group, public_key, EC_KEY_get_conv_form(tmp), NULL, getctx(L)))) | 2588 | bn_dup(L, EC_POINT_point2bn(group, public_key, EC_KEY_get_conv_form(tmp), NULL, getctx(L))); |
| 2599 | return auxL_error(L, auxL_EOPENSSL, "pkey:getParameters"); | ||
| 2600 | lua_setfield(L, -2, "pub_key"); | 2589 | lua_setfield(L, -2, "pub_key"); |
| 2601 | 2590 | ||
| 2602 | if (public_only) break; | 2591 | if (public_only) |
| 2592 | break; | ||
| 2603 | 2593 | ||
| 2604 | /* priv_key */ | 2594 | /* priv_key */ |
| 2605 | if (!bn_dup(L, EC_KEY_get0_private_key(tmp))) | 2595 | bn_dup(L, EC_KEY_get0_private_key(tmp)); |
| 2606 | return auxL_error(L, auxL_EOPENSSL, "pkey:getParameters"); | 2596 | goto sslerr; |
| 2607 | lua_setfield(L, -2, "priv_key"); | 2597 | lua_setfield(L, -2, "priv_key"); |
| 2608 | 2598 | ||
| 2609 | break; | 2599 | break; |
| @@ -2614,6 +2604,8 @@ static int pk_getParameters(lua_State *L) { | |||
| 2614 | } /* switch() */ | 2604 | } /* switch() */ |
| 2615 | 2605 | ||
| 2616 | return 1; | 2606 | return 1; |
| 2607 | sslerr: | ||
| 2608 | return auxL_error(L, auxL_EOPENSSL, "pkey:getParameters"); | ||
| 2617 | } /* pk_getParameters() */ | 2609 | } /* pk_getParameters() */ |
| 2618 | 2610 | ||
| 2619 | 2611 | ||
