diff options
author | daurnimator <quae@daurnimator.com> | 2016-01-03 08:12:54 +1100 |
---|---|---|
committer | daurnimator <quae@daurnimator.com> | 2016-01-04 19:04:59 +1100 |
commit | f5ceb7d11ffd98baa5fe06756370b60f2379195b (patch) | |
tree | a9ef0d46e970efe8a407e75fb244f2fb0adb37e3 /src/openssl.c | |
parent | a4bb486b51bf6dd74d942ce112703b746bb8173a (diff) | |
download | luaossl-f5ceb7d11ffd98baa5fe06756370b60f2379195b.tar.gz luaossl-f5ceb7d11ffd98baa5fe06756370b60f2379195b.tar.bz2 luaossl-f5ceb7d11ffd98baa5fe06756370b60f2379195b.zip |
bignum.new: Allow initialisation from hex strings
Diffstat (limited to 'src/openssl.c')
-rw-r--r-- | src/openssl.c | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/src/openssl.c b/src/openssl.c index 71aaed4..82f3298 100644 --- a/src/openssl.c +++ b/src/openssl.c | |||
@@ -1673,7 +1673,7 @@ static _Bool f2bn(BIGNUM **bn, double f) { | |||
1673 | 1673 | ||
1674 | static BIGNUM *(checkbig)(lua_State *L, int index, _Bool *lvalue) { | 1674 | static BIGNUM *(checkbig)(lua_State *L, int index, _Bool *lvalue) { |
1675 | BIGNUM **bn; | 1675 | BIGNUM **bn; |
1676 | const char *dec; | 1676 | const char *str; |
1677 | size_t len; | 1677 | size_t len; |
1678 | 1678 | ||
1679 | index = lua_absindex(L, index); | 1679 | index = lua_absindex(L, index); |
@@ -1682,14 +1682,19 @@ static BIGNUM *(checkbig)(lua_State *L, int index, _Bool *lvalue) { | |||
1682 | case LUA_TSTRING: | 1682 | case LUA_TSTRING: |
1683 | *lvalue = 0; | 1683 | *lvalue = 0; |
1684 | 1684 | ||
1685 | dec = lua_tolstring(L, index, &len); | 1685 | str = lua_tolstring(L, index, &len); |
1686 | 1686 | ||
1687 | luaL_argcheck(L, len > 0 && *dec, index, "invalid big number string"); | 1687 | luaL_argcheck(L, len > 0 && *str, index, "invalid big number string"); |
1688 | 1688 | ||
1689 | bn = prepsimple(L, BIGNUM_CLASS); | 1689 | bn = prepsimple(L, BIGNUM_CLASS); |
1690 | 1690 | ||
1691 | if (!BN_dec2bn(bn, dec)) | 1691 | if (str[0] == '0' && (str[1] == 'x' || str[1] == 'X')) { |
1692 | auxL_error(L, auxL_EOPENSSL, "bignum"); | 1692 | if (!BN_hex2bn(bn, str+2)) |
1693 | auxL_error(L, auxL_EOPENSSL, "bignum"); | ||
1694 | } else { | ||
1695 | if (!BN_dec2bn(bn, str)) | ||
1696 | auxL_error(L, auxL_EOPENSSL, "bignum"); | ||
1697 | } | ||
1693 | 1698 | ||
1694 | lua_replace(L, index); | 1699 | lua_replace(L, index); |
1695 | 1700 | ||