1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-16 04:39:03 +00:00

Add BN_div function binding

This commit is contained in:
dmiller
2017-10-18 20:26:39 +00:00
parent c72e3ac0d9
commit 3abb4c7af3
2 changed files with 22 additions and 0 deletions

View File

@@ -107,6 +107,20 @@ static int l_bignum_mod_exp( lua_State *L ) /** bignum_mod_exp( BIGNUM a, BIGNUM
return nse_pushbn(L, result);
}
static int l_bignum_div( lua_State *L ) /* bignum_div( BIGNUM a, BIGNUM d ) */
{
bignum_data_t * a = (bignum_data_t *) luaL_checkudata(L, 1, "BIGNUM");
bignum_data_t * d = (bignum_data_t *) luaL_checkudata(L, 2, "BIGNUM");
BIGNUM * dv = BN_new();
BIGNUM * rem = BN_new();
BN_CTX * ctx = BN_CTX_new();
BN_div(dv, rem, a->bn, d->bn, ctx);
BN_CTX_free( ctx );
nse_pushbn(L, dv);
nse_pushbn(L, rem);
return 2;
}
static int l_bignum_add( lua_State *L ) /** bignum_add( BIGNUM a, BIGNUM b ) */
{
bignum_data_t * a = (bignum_data_t *) luaL_checkudata(L, 1, "BIGNUM");
@@ -582,6 +596,7 @@ static const struct luaL_Reg openssllib[] = {
{ "bignum_bn2hex", l_bignum_bn2hex },
{ "bignum_add", l_bignum_add },
{ "bignum_mod_exp", l_bignum_mod_exp },
{ "bignum_div", l_bignum_div },
{ "rand_bytes", l_rand_bytes },
{ "rand_pseudo_bytes", l_rand_pseudo_bytes },
{ "md4", l_md4 },

View File

@@ -115,6 +115,13 @@ function bignum_pseudo_rand(bits)
-- @return bignum.
function bignum_mod_exp(a, p, m)
--- Returns the bignums which are the result and remainder of <code>a/b</code>
-- @param a bignum
-- @param b bignum
-- @return bignum quotient
-- @return bignum remainder (modulo)
function bignum_div(a, b)
--- Returns the bignum which is the result of <code>a+b</code>
-- @param a bignum
-- @param b bignum