aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLibravatarLibravatar daurnimator <quae@daurnimator.com> 2015-12-18 22:59:23 +1100
committerLibravatarLibravatar daurnimator <quae@daurnimator.com> 2015-12-21 19:32:54 +1100
commit67dca5b835148d971127a4c882a8de456cffd868 (patch)
tree40c3a612fb62f866ecfe3c6ad2810d47493ea828 /src
parent65248290ed3a412e9ce0caa7204b1a42fc9fe192 (diff)
downloadluaossl-67dca5b835148d971127a4c882a8de456cffd868.tar.gz
luaossl-67dca5b835148d971127a4c882a8de456cffd868.tar.bz2
luaossl-67dca5b835148d971127a4c882a8de456cffd868.zip
bignum: Add shl (lshift), shr (rshift) functions
Diffstat (limited to 'src')
-rw-r--r--src/openssl.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/openssl.c b/src/openssl.c
index 304ff9a..a1a7c58 100644
--- a/src/openssl.c
+++ b/src/openssl.c
@@ -1856,6 +1856,36 @@ static int bn__pow(lua_State *L) {
} /* bn__pow() */
+static int bn__shl(lua_State *L) {
+ BIGNUM *r, *a;
+ int n;
+
+ a = checkbig(L, 1);
+ n = luaL_checkinteger(L, 2);
+ r = bn_push(L);
+
+ if (!BN_lshift(r, a, n))
+ return auxL_error(L, auxL_EOPENSSL, "bignum:__shl");
+
+ return 1;
+} /* bn__shl() */
+
+
+static int bn__shr(lua_State *L) {
+ BIGNUM *r, *a;
+ int n;
+
+ a = checkbig(L, 1);
+ n = luaL_checkinteger(L, 2);
+ r = bn_push(L);
+
+ if (!BN_rshift(r, a, n))
+ return auxL_error(L, auxL_EOPENSSL, "bignum:__shr");
+
+ return 1;
+} /* bn__shr() */
+
+
static int bn__unm(lua_State *L) {
BIGNUM *a = checksimple(L, 1, BIGNUM_CLASS);
@@ -1947,6 +1977,8 @@ static const luaL_Reg bn_methods[] = {
{ "div", &bn__div },
{ "mod", &bn__mod },
{ "pow", &bn__pow },
+ { "shl", &bn__shl },
+ { "shr", &bn__shr },
{ "tobin", &bn_tobin },
{ NULL, NULL },
};
@@ -1959,6 +1991,8 @@ static const luaL_Reg bn_metatable[] = {
{ "__mod", &bn__mod },
{ "__pow", &bn__pow },
{ "__unm", &bn__unm },
+ { "__shl", &bn__shl },
+ { "__shr", &bn__shr },
{ "__eq", &bn__eq },
{ "__lt", &bn__lt },
{ "__le", &bn__le },