From 16e0a8449f3365317e82e379b1e51212ac336c3c Mon Sep 17 00:00:00 2001 From: patrik Date: Tue, 9 Mar 2010 20:54:01 +0000 Subject: [PATCH] o Added the function bignum_add to the nse_openssl library to support BIGNUM addition [Patrik] --- CHANGELOG | 3 +++ nse_openssl.cc | 14 ++++++++++++++ nselib/openssl.luadoc | 6 ++++++ 3 files changed, 23 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 8cd74eac6..b3750cc47 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,6 +2,9 @@ [NOT YET RELEASED] +o Added the function bignum_add to the nse_openssl library to support BIGNUM + addition [Patrik] + o [NSE] Added checks for missing OpenSSL to MySQL scripts and library [Patrik] o Made --resume work with recent changes to normal output. [jlanthea] diff --git a/nse_openssl.cc b/nse_openssl.cc index 2b267cab3..9973e0a7a 100644 --- a/nse_openssl.cc +++ b/nse_openssl.cc @@ -107,6 +107,19 @@ static int l_bignum_mod_exp( lua_State *L ) /** bignum_mod_exp( BIGNUM a, BIGNUM return 1; } +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"); + bignum_data_t * b = (bignum_data_t *) luaL_checkudata(L, 2, "BIGNUM"); + BIGNUM * result = BN_new(); + BN_add( result, a->bn, b->bn ); + bignum_data_t * data = (bignum_data_t *) lua_newuserdata( L, sizeof(bignum_data_t)); + luaL_getmetatable( L, "BIGNUM" ); + lua_setmetatable( L, -2 ); + data->bn = result; + return 1; +} + static int l_bignum_num_bits( lua_State *L ) /** bignum_num_bits( BIGNUM bn ) */ { bignum_data_t * userdata = (bignum_data_t *) luaL_checkudata(L, 1, "BIGNUM"); @@ -466,6 +479,7 @@ static const struct luaL_reg openssllib[] = { { "bignum_bn2bin", l_bignum_bn2bin }, { "bignum_bn2dec", l_bignum_bn2dec }, { "bignum_bn2hex", l_bignum_bn2hex }, + { "bignum_add", l_bignum_add }, { "bignum_mod_exp", l_bignum_mod_exp }, { "rand_bytes", l_rand_bytes }, { "rand_pseudo_bytes", l_rand_pseudo_bytes }, diff --git a/nselib/openssl.luadoc b/nselib/openssl.luadoc index 8e2161a16..5d4efb1e1 100644 --- a/nselib/openssl.luadoc +++ b/nselib/openssl.luadoc @@ -95,6 +95,12 @@ function bignum_pseudo_rand(bits) -- @return bignum. function bignum_mod_exp(a, p, m) +--- Returns the bignum which is the result of a+b +-- @param a bignum +-- @param b bignum +-- @return bignum +function bignum_add(a, b) + --- Returns a string containing random data. -- @param bytes Length of the returned string in bytes. -- @return Random string.