diff --git a/nse_openssl.cc b/nse_openssl.cc
index 54cc69301..1b8e68a83 100644
--- a/nse_openssl.cc
+++ b/nse_openssl.cc
@@ -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 },
diff --git a/nselib/openssl.luadoc b/nselib/openssl.luadoc
index 0a32c4a4b..b01d2c35f 100644
--- a/nselib/openssl.luadoc
+++ b/nselib/openssl.luadoc
@@ -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 a/b
+-- @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 a+b
-- @param a bignum
-- @param b bignum