aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatarLibravatar daurnimator <quae@daurnimator.com> 2016-01-03 10:42:26 +1100
committerLibravatarLibravatar daurnimator <quae@daurnimator.com> 2016-01-04 19:05:42 +1100
commit5dec5e287e60d13008373a38eadce91cf02da6a0 (patch)
tree6a1d0332101a985454214565c523290fe1dc7a25
parentae3506413067af8d209d16ffc10c2e7c99dc6bba (diff)
downloadluaossl-5dec5e287e60d13008373a38eadce91cf02da6a0.tar.gz
luaossl-5dec5e287e60d13008373a38eadce91cf02da6a0.tar.bz2
luaossl-5dec5e287e60d13008373a38eadce91cf02da6a0.zip
bignum: handle negative hex numbers
-rw-r--r--src/openssl.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/openssl.c b/src/openssl.c
index 0a444c8..66a6168 100644
--- a/src/openssl.c
+++ b/src/openssl.c
@@ -1686,6 +1686,7 @@ static BIGNUM *(checkbig)(lua_State *L, int index, _Bool *lvalue) {
BIGNUM **bn;
const char *str;
size_t len;
+ _Bool neg, hex = 0;
index = lua_absindex(L, index);
@@ -1697,11 +1698,19 @@ static BIGNUM *(checkbig)(lua_State *L, int index, _Bool *lvalue) {
luaL_argcheck(L, len > 0 && *str, index, "invalid big number string");
+ neg = (str[0] == '-');
+
+ if (str[neg] == '0' && (str[neg+1] == 'x' || str[neg+1] == 'X')) {
+ hex = 1;
+ }
+
bn = prepsimple(L, BIGNUM_CLASS);
- if (str[0] == '0' && (str[1] == 'x' || str[1] == 'X')) {
- if (!BN_hex2bn(bn, str+2))
+ if (hex) {
+ if (!BN_hex2bn(bn, str+2+neg))
auxL_error(L, auxL_EOPENSSL, "bignum");
+ if (neg)
+ BN_set_negative(*bn, 1);
} else {
if (!BN_dec2bn(bn, str))
auxL_error(L, auxL_EOPENSSL, "bignum");