diff options
author | William Ahern <william@25thandClement.com> | 2015-12-17 15:42:23 +0800 |
---|---|---|
committer | William Ahern <william@25thandClement.com> | 2015-12-17 15:42:23 +0800 |
commit | a7063a8467c4c0db8eb8f9b1c9e6c9f33c3f664f (patch) | |
tree | 1602edef5399d3ac20b9d0fa22002b0434aa0330 /src | |
parent | 739031aea27fa166771c76153db12c009677601b (diff) | |
parent | 0bb54ebc3779461101daa6d10ec24f53be540663 (diff) | |
download | luaossl-a7063a8467c4c0db8eb8f9b1c9e6c9f33c3f664f.tar.gz luaossl-a7063a8467c4c0db8eb8f9b1c9e6c9f33c3f664f.tar.bz2 luaossl-a7063a8467c4c0db8eb8f9b1c9e6c9f33c3f664f.zip |
Merge branch 'daurnimator-19-bignum-modulo'
Diffstat (limited to 'src')
-rw-r--r-- | src/openssl.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/openssl.c b/src/openssl.c index 9dbcda7..69115ce 100644 --- a/src/openssl.c +++ b/src/openssl.c @@ -1809,6 +1809,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() */ |