diff options
author | daurnimator <quae@daurnimator.com> | 2016-01-03 11:22:14 +1100 |
---|---|---|
committer | daurnimator <quae@daurnimator.com> | 2016-01-03 11:39:33 +1100 |
commit | b2b301db7ad41238fdd1b6236eb917c11bf0bbbc (patch) | |
tree | aa781c8f1de160e099787cdc5b041f789438e440 | |
parent | 436209e6400764817be4126b35712ba07abe3870 (diff) | |
download | luaossl-b2b301db7ad41238fdd1b6236eb917c11bf0bbbc.tar.gz luaossl-b2b301db7ad41238fdd1b6236eb917c11bf0bbbc.tar.bz2 luaossl-b2b301db7ad41238fdd1b6236eb917c11bf0bbbc.zip |
bignum: Bind sqr, nnmod and gcd
-rw-r--r-- | src/openssl.c | 39 |
1 files changed, 39 insertions, 0 deletions
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) { | |||
1814 | } /* bn__mul() */ | 1814 | } /* bn__mul() */ |
1815 | 1815 | ||
1816 | 1816 | ||
1817 | static int bn_sqr(lua_State *L) { | ||
1818 | BIGNUM *r, *a; | ||
1819 | |||
1820 | bn_prepops(L, &r, &a, NULL, 1); | ||
1821 | |||
1822 | if (!BN_sqr(r, a, getctx(L))) | ||
1823 | return auxL_error(L, auxL_EOPENSSL, "bignum:sqr"); | ||
1824 | |||
1825 | return 1; | ||
1826 | } /* bn_sqr() */ | ||
1827 | |||
1828 | |||
1817 | static int bn__idiv(lua_State *L) { | 1829 | static int bn__idiv(lua_State *L) { |
1818 | BIGNUM *dv, *a, *b; | 1830 | BIGNUM *dv, *a, *b; |
1819 | 1831 | ||
@@ -1844,6 +1856,18 @@ static int bn__mod(lua_State *L) { | |||
1844 | } /* bn__mod() */ | 1856 | } /* bn__mod() */ |
1845 | 1857 | ||
1846 | 1858 | ||
1859 | static int bn_nnmod(lua_State *L) { | ||
1860 | BIGNUM *r, *a, *b; | ||
1861 | |||
1862 | bn_prepops(L, &r, &a, &b, 0); | ||
1863 | |||
1864 | if (!BN_nnmod(r, a, b, getctx(L))) | ||
1865 | return auxL_error(L, auxL_EOPENSSL, "bignum:nnmod"); | ||
1866 | |||
1867 | return 1; | ||
1868 | } /* bn_nnmod() */ | ||
1869 | |||
1870 | |||
1847 | static int bn__pow(lua_State *L) { | 1871 | static int bn__pow(lua_State *L) { |
1848 | BIGNUM *r, *a, *b; | 1872 | BIGNUM *r, *a, *b; |
1849 | 1873 | ||
@@ -1856,6 +1880,18 @@ static int bn__pow(lua_State *L) { | |||
1856 | } /* bn__pow() */ | 1880 | } /* bn__pow() */ |
1857 | 1881 | ||
1858 | 1882 | ||
1883 | static int bn_gcd(lua_State *L) { | ||
1884 | BIGNUM *r, *a, *b; | ||
1885 | |||
1886 | bn_prepops(L, &r, &a, &b, 1); | ||
1887 | |||
1888 | if (!BN_gcd(r, a, b, getctx(L))) | ||
1889 | return auxL_error(L, auxL_EOPENSSL, "bignum:gcd"); | ||
1890 | |||
1891 | return 1; | ||
1892 | } /* bn_gcd() */ | ||
1893 | |||
1894 | |||
1859 | static int bn__shl(lua_State *L) { | 1895 | static int bn__shl(lua_State *L) { |
1860 | BIGNUM *r, *a; | 1896 | BIGNUM *r, *a; |
1861 | int n; | 1897 | int n; |
@@ -2003,9 +2039,12 @@ static const luaL_Reg bn_methods[] = { | |||
2003 | { "add", &bn__add }, | 2039 | { "add", &bn__add }, |
2004 | { "sub", &bn__sub }, | 2040 | { "sub", &bn__sub }, |
2005 | { "mul", &bn__mul }, | 2041 | { "mul", &bn__mul }, |
2042 | { "sqr", &bn_sqr }, | ||
2006 | { "idiv", &bn__idiv }, | 2043 | { "idiv", &bn__idiv }, |
2007 | { "mod", &bn__mod }, | 2044 | { "mod", &bn__mod }, |
2045 | { "nnmod", &bn_nnmod }, | ||
2008 | { "exp", &bn__pow }, | 2046 | { "exp", &bn__pow }, |
2047 | { "gcd", &bn_gcd }, | ||
2009 | { "lshift", &bn__shl }, | 2048 | { "lshift", &bn__shl }, |
2010 | { "rshift", &bn__shr }, | 2049 | { "rshift", &bn__shr }, |
2011 | { "tobin", &bn_tobin }, | 2050 | { "tobin", &bn_tobin }, |