summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2016-01-03 11:53:32 +1100
committerdaurnimator <quae@daurnimator.com>2016-01-03 12:35:23 +1100
commit0706e6447e3b6e7b8283686b6f89b46c68f8e1fd (patch)
treeaa8fa129c4ade1373861336e8e064e770d3270dc
parent7a31bf07493d365f5b44581dc4aaf3c9d48179f0 (diff)
downloadluaossl-0706e6447e3b6e7b8283686b6f89b46c68f8e1fd.tar.gz
luaossl-0706e6447e3b6e7b8283686b6f89b46c68f8e1fd.tar.bz2
luaossl-0706e6447e3b6e7b8283686b6f89b46c68f8e1fd.zip
bignum: Add :isPrime
-rw-r--r--src/openssl.c45
1 files changed, 30 insertions, 15 deletions
diff --git a/src/openssl.c b/src/openssl.c
index a73917a..c311ba6 100644
--- a/src/openssl.c
+++ b/src/openssl.c
@@ -1976,6 +1976,20 @@ static int bn__gc(lua_State *L) {
1976} /* bn__gc() */ 1976} /* bn__gc() */
1977 1977
1978 1978
1979static int bn_isPrime(lua_State *L) {
1980 BIGNUM *bn = checksimple(L, 1, BIGNUM_CLASS);
1981 int nchecks = luaL_optinteger(L, 2, BN_prime_checks);
1982 int res = BN_is_prime_ex(bn, nchecks, getctx(L), NULL);
1983
1984 if (res == -1)
1985 return auxL_error(L, auxL_EOPENSSL, "bignum:isPrime");
1986
1987 lua_pushboolean(L, res);
1988
1989 return 1;
1990} /* bn_isPrime() */
1991
1992
1979static BIO *getbio(lua_State *); 1993static BIO *getbio(lua_State *);
1980 1994
1981static int bn_todec(lua_State *L) { 1995static int bn_todec(lua_State *L) {
@@ -2037,21 +2051,22 @@ sslerr:
2037 2051
2038 2052
2039static const luaL_Reg bn_methods[] = { 2053static const luaL_Reg bn_methods[] = {
2040 { "add", &bn__add }, 2054 { "add", &bn__add },
2041 { "sub", &bn__sub }, 2055 { "sub", &bn__sub },
2042 { "mul", &bn__mul }, 2056 { "mul", &bn__mul },
2043 { "sqr", &bn_sqr }, 2057 { "sqr", &bn_sqr },
2044 { "idiv", &bn__idiv }, 2058 { "idiv", &bn__idiv },
2045 { "mod", &bn__mod }, 2059 { "mod", &bn__mod },
2046 { "nnmod", &bn_nnmod }, 2060 { "nnmod", &bn_nnmod },
2047 { "exp", &bn__pow }, 2061 { "exp", &bn__pow },
2048 { "gcd", &bn_gcd }, 2062 { "gcd", &bn_gcd },
2049 { "lshift", &bn__shl }, 2063 { "lshift", &bn__shl },
2050 { "rshift", &bn__shr }, 2064 { "rshift", &bn__shr },
2051 { "tobin", &bn_tobin }, 2065 { "isPrime", &bn_isPrime },
2052 { "todec", &bn_todec }, 2066 { "tobin", &bn_tobin },
2053 { "tohex", &bn_tohex }, 2067 { "todec", &bn_todec },
2054 { NULL, NULL }, 2068 { "tohex", &bn_tohex },
2069 { NULL, NULL },
2055}; 2070};
2056 2071
2057static const luaL_Reg bn_metatable[] = { 2072static const luaL_Reg bn_metatable[] = {