From b2b301db7ad41238fdd1b6236eb917c11bf0bbbc Mon Sep 17 00:00:00 2001 From: daurnimator Date: Sun, 3 Jan 2016 11:22:14 +1100 Subject: bignum: Bind sqr, nnmod and gcd --- src/openssl.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/openssl.c b/src/openssl.c index 991cba5..e146098 100644 --- a/src/openssl.c +++ b/src/openssl.c @@ -1814,6 +1814,18 @@ static int bn__mul(lua_State *L) { } /* bn__mul() */ +static int bn_sqr(lua_State *L) { + BIGNUM *r, *a; + + bn_prepops(L, &r, &a, NULL, 1); + + if (!BN_sqr(r, a, getctx(L))) + return auxL_error(L, auxL_EOPENSSL, "bignum:sqr"); + + return 1; +} /* bn_sqr() */ + + static int bn__idiv(lua_State *L) { BIGNUM *dv, *a, *b; @@ -1844,6 +1856,18 @@ static int bn__mod(lua_State *L) { } /* bn__mod() */ +static int bn_nnmod(lua_State *L) { + BIGNUM *r, *a, *b; + + bn_prepops(L, &r, &a, &b, 0); + + if (!BN_nnmod(r, a, b, getctx(L))) + return auxL_error(L, auxL_EOPENSSL, "bignum:nnmod"); + + return 1; +} /* bn_nnmod() */ + + static int bn__pow(lua_State *L) { BIGNUM *r, *a, *b; @@ -1856,6 +1880,18 @@ static int bn__pow(lua_State *L) { } /* bn__pow() */ +static int bn_gcd(lua_State *L) { + BIGNUM *r, *a, *b; + + bn_prepops(L, &r, &a, &b, 1); + + if (!BN_gcd(r, a, b, getctx(L))) + return auxL_error(L, auxL_EOPENSSL, "bignum:gcd"); + + return 1; +} /* bn_gcd() */ + + static int bn__shl(lua_State *L) { BIGNUM *r, *a; int n; @@ -2003,9 +2039,12 @@ static const luaL_Reg bn_methods[] = { { "add", &bn__add }, { "sub", &bn__sub }, { "mul", &bn__mul }, + { "sqr", &bn_sqr }, { "idiv", &bn__idiv }, { "mod", &bn__mod }, + { "nnmod", &bn_nnmod }, { "exp", &bn__pow }, + { "gcd", &bn_gcd }, { "lshift", &bn__shl }, { "rshift", &bn__shr }, { "tobin", &bn_tobin }, -- cgit v1.2.3-59-g8ed1b