diff options
author | daurnimator <quae@daurnimator.com> | 2015-12-18 22:59:23 +1100 |
---|---|---|
committer | daurnimator <quae@daurnimator.com> | 2015-12-21 19:32:54 +1100 |
commit | 67dca5b835148d971127a4c882a8de456cffd868 (patch) | |
tree | 40c3a612fb62f866ecfe3c6ad2810d47493ea828 | |
parent | 65248290ed3a412e9ce0caa7204b1a42fc9fe192 (diff) | |
download | luaossl-67dca5b835148d971127a4c882a8de456cffd868.tar.gz luaossl-67dca5b835148d971127a4c882a8de456cffd868.tar.bz2 luaossl-67dca5b835148d971127a4c882a8de456cffd868.zip |
bignum: Add shl (lshift), shr (rshift) functions
-rw-r--r-- | src/openssl.c | 34 |
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) { | |||
1856 | } /* bn__pow() */ | 1856 | } /* bn__pow() */ |
1857 | 1857 | ||
1858 | 1858 | ||
1859 | static int bn__shl(lua_State *L) { | ||
1860 | BIGNUM *r, *a; | ||
1861 | int n; | ||
1862 | |||
1863 | a = checkbig(L, 1); | ||
1864 | n = luaL_checkinteger(L, 2); | ||
1865 | r = bn_push(L); | ||
1866 | |||
1867 | if (!BN_lshift(r, a, n)) | ||
1868 | return auxL_error(L, auxL_EOPENSSL, "bignum:__shl"); | ||
1869 | |||
1870 | return 1; | ||
1871 | } /* bn__shl() */ | ||
1872 | |||
1873 | |||
1874 | static int bn__shr(lua_State *L) { | ||
1875 | BIGNUM *r, *a; | ||
1876 | int n; | ||
1877 | |||
1878 | a = checkbig(L, 1); | ||
1879 | n = luaL_checkinteger(L, 2); | ||
1880 | r = bn_push(L); | ||
1881 | |||
1882 | if (!BN_rshift(r, a, n)) | ||
1883 | return auxL_error(L, auxL_EOPENSSL, "bignum:__shr"); | ||
1884 | |||
1885 | return 1; | ||
1886 | } /* bn__shr() */ | ||
1887 | |||
1888 | |||
1859 | static int bn__unm(lua_State *L) { | 1889 | static int bn__unm(lua_State *L) { |
1860 | BIGNUM *a = checksimple(L, 1, BIGNUM_CLASS); | 1890 | BIGNUM *a = checksimple(L, 1, BIGNUM_CLASS); |
1861 | 1891 | ||
@@ -1947,6 +1977,8 @@ static const luaL_Reg bn_methods[] = { | |||
1947 | { "div", &bn__div }, | 1977 | { "div", &bn__div }, |
1948 | { "mod", &bn__mod }, | 1978 | { "mod", &bn__mod }, |
1949 | { "pow", &bn__pow }, | 1979 | { "pow", &bn__pow }, |
1980 | { "shl", &bn__shl }, | ||
1981 | { "shr", &bn__shr }, | ||
1950 | { "tobin", &bn_tobin }, | 1982 | { "tobin", &bn_tobin }, |
1951 | { NULL, NULL }, | 1983 | { NULL, NULL }, |
1952 | }; | 1984 | }; |
@@ -1959,6 +1991,8 @@ static const luaL_Reg bn_metatable[] = { | |||
1959 | { "__mod", &bn__mod }, | 1991 | { "__mod", &bn__mod }, |
1960 | { "__pow", &bn__pow }, | 1992 | { "__pow", &bn__pow }, |
1961 | { "__unm", &bn__unm }, | 1993 | { "__unm", &bn__unm }, |
1994 | { "__shl", &bn__shl }, | ||
1995 | { "__shr", &bn__shr }, | ||
1962 | { "__eq", &bn__eq }, | 1996 | { "__eq", &bn__eq }, |
1963 | { "__lt", &bn__lt }, | 1997 | { "__lt", &bn__lt }, |
1964 | { "__le", &bn__le }, | 1998 | { "__le", &bn__le }, |