aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLibravatarLibravatar daurnimator <quae@daurnimator.com> 2016-01-03 08:12:54 +1100
committerLibravatarLibravatar daurnimator <quae@daurnimator.com> 2016-01-04 19:04:59 +1100
commitf5ceb7d11ffd98baa5fe06756370b60f2379195b (patch)
treea9ef0d46e970efe8a407e75fb244f2fb0adb37e3 /src
parenta4bb486b51bf6dd74d942ce112703b746bb8173a (diff)
downloadluaossl-f5ceb7d11ffd98baa5fe06756370b60f2379195b.tar.gz
luaossl-f5ceb7d11ffd98baa5fe06756370b60f2379195b.tar.bz2
luaossl-f5ceb7d11ffd98baa5fe06756370b60f2379195b.zip
bignum.new: Allow initialisation from hex strings
Diffstat (limited to 'src')
-rw-r--r--src/openssl.c15
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) {
static BIGNUM *(checkbig)(lua_State *L, int index, _Bool *lvalue) {
BIGNUM **bn;
- const char *dec;
+ const char *str;
size_t len;
index = lua_absindex(L, index);
@@ -1682,14 +1682,19 @@ static BIGNUM *(checkbig)(lua_State *L, int index, _Bool *lvalue) {
case LUA_TSTRING:
*lvalue = 0;
- dec = lua_tolstring(L, index, &len);
+ str = lua_tolstring(L, index, &len);
- luaL_argcheck(L, len > 0 && *dec, index, "invalid big number string");
+ luaL_argcheck(L, len > 0 && *str, index, "invalid big number string");
bn = prepsimple(L, BIGNUM_CLASS);
- if (!BN_dec2bn(bn, dec))
- auxL_error(L, auxL_EOPENSSL, "bignum");
+ if (str[0] == '0' && (str[1] == 'x' || str[1] == 'X')) {
+ if (!BN_hex2bn(bn, str+2))
+ auxL_error(L, auxL_EOPENSSL, "bignum");
+ } else {
+ if (!BN_dec2bn(bn, str))
+ auxL_error(L, auxL_EOPENSSL, "bignum");
+ }
lua_replace(L, index);