aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/openssl.c23
-rw-r--r--src/openssl.ssl.context.lua13
2 files changed, 35 insertions, 1 deletions
diff --git a/src/openssl.c b/src/openssl.c
index d0be29e..a5e1a52 100644
--- a/src/openssl.c
+++ b/src/openssl.c
@@ -1753,6 +1753,20 @@ static BN_CTX *getctx(lua_State *L) {
} /* getctx() */
+static int bn_tobin(lua_State *L) {
+ BIGNUM *bn = checksimple(L, 1, BIGNUM_CLASS);
+ size_t len;
+ void *dst;
+
+ len = BN_num_bytes(bn);
+ dst = lua_newuserdata(L, len);
+ BN_bn2bin(bn, dst);
+ lua_pushlstring(L, dst, len);
+
+ return 1;
+} /* bn_tobin() */
+
+
static int bn__add(lua_State *L) {
BIGNUM *r, *a, *b;
@@ -1809,6 +1823,12 @@ static int bn__mod(lua_State *L) {
if (!BN_mod(r, a, b, getctx(L)))
return auxL_error(L, auxL_EOPENSSL, "bignum:__mod");
+ /* lua has different rounding behaviour for mod than C */
+ if (!BN_is_zero(r) && (BN_is_negative(a) ^ BN_is_negative(b))) {
+ if (!BN_add(r, r, b))
+ return auxL_error(L, auxL_EOPENSSL, "bignum:__mod");
+ }
+
return 1;
} /* bn__mod() */
@@ -1892,7 +1912,8 @@ static int bn__tostring(lua_State *L) {
static const luaL_Reg bn_methods[] = {
- { NULL, NULL },
+ { "tobin", &bn_tobin },
+ { NULL, NULL },
};
static const luaL_Reg bn_metatable[] = {
diff --git a/src/openssl.ssl.context.lua b/src/openssl.ssl.context.lua
index 44a9163..2098b54 100644
--- a/src/openssl.ssl.context.lua
+++ b/src/openssl.ssl.context.lua
@@ -1,3 +1,16 @@
local ctx = require"_openssl.ssl.context"
+local pack = table.pack or function(...) return { n = select("#", ...); ... } end
+
+-- Allow passing a vararg of ciphers, or an array
+local setCipherList; setCipherList = ctx.interpose("setCipherList", function (self, ciphers, ...)
+ if (...) then
+ local ciphers_t = pack(ciphers, ...)
+ ciphers = table.concat(ciphers_t, ":", 1, ciphers_t.n)
+ elseif type(ciphers) == "table" then
+ ciphers = table.concat(ciphers, ":")
+ end
+ return setCipherList(self, ciphers)
+end)
+
return ctx