summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2016-01-03 10:42:26 +1100
committerdaurnimator <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) {
1686 BIGNUM **bn; 1686 BIGNUM **bn;
1687 const char *str; 1687 const char *str;
1688 size_t len; 1688 size_t len;
1689 _Bool neg, hex = 0;
1689 1690
1690 index = lua_absindex(L, index); 1691 index = lua_absindex(L, index);
1691 1692
@@ -1697,11 +1698,19 @@ static BIGNUM *(checkbig)(lua_State *L, int index, _Bool *lvalue) {
1697 1698
1698 luaL_argcheck(L, len > 0 && *str, index, "invalid big number string"); 1699 luaL_argcheck(L, len > 0 && *str, index, "invalid big number string");
1699 1700
1701 neg = (str[0] == '-');
1702
1703 if (str[neg] == '0' && (str[neg+1] == 'x' || str[neg+1] == 'X')) {
1704 hex = 1;
1705 }
1706
1700 bn = prepsimple(L, BIGNUM_CLASS); 1707 bn = prepsimple(L, BIGNUM_CLASS);
1701 1708
1702 if (str[0] == '0' && (str[1] == 'x' || str[1] == 'X')) { 1709 if (hex) {
1703 if (!BN_hex2bn(bn, str+2)) 1710 if (!BN_hex2bn(bn, str+2+neg))
1704 auxL_error(L, auxL_EOPENSSL, "bignum"); 1711 auxL_error(L, auxL_EOPENSSL, "bignum");
1712 if (neg)
1713 BN_set_negative(*bn, 1);
1705 } else { 1714 } else {
1706 if (!BN_dec2bn(bn, str)) 1715 if (!BN_dec2bn(bn, str))
1707 auxL_error(L, auxL_EOPENSSL, "bignum"); 1716 auxL_error(L, auxL_EOPENSSL, "bignum");