From cff5910982e3201d4b79178b8204d5dc5b95f166 Mon Sep 17 00:00:00 2001 From: "Nicolas \"Pixel\" Noble" Date: Mon, 12 Aug 2013 17:55:04 +0200 Subject: Adding BigInt support and test to Dalos. --- Balau | 2 +- src/Dalos-cli.cc | 2 ++ tests/alltests.lua | 2 +- tests/test3.lua | 22 ++++++++-------------- 4 files changed, 12 insertions(+), 16 deletions(-) diff --git a/Balau b/Balau index e4212db..7584692 160000 --- a/Balau +++ b/Balau @@ -1 +1 @@ -Subproject commit e4212db6a548b96b9b288eaa450ef1a18d2e250d +Subproject commit 758469279bda5810ed7cef45b5f301234bfc7596 diff --git a/src/Dalos-cli.cc b/src/Dalos-cli.cc index 887d7d1..b331f15 100644 --- a/src/Dalos-cli.cc +++ b/src/Dalos-cli.cc @@ -4,6 +4,7 @@ #include #include #include +#include #include #include "BReadline.h" #include "LuaLoad.h" @@ -43,6 +44,7 @@ namespace { class DalosInit : public LuaExecCell { virtual void run(Lua & L) override { registerLuaLoad(L); + registerLuaBigInt(L); registerLuaHandle(L); } }; diff --git a/tests/alltests.lua b/tests/alltests.lua index de3385f..2879e57 100644 --- a/tests/alltests.lua +++ b/tests/alltests.lua @@ -5,5 +5,5 @@ load "tests/test3.lua" function runtests() test1() test2() --- test3() + test3() end diff --git a/tests/test3.lua b/tests/test3.lua index 15c59e3..aeea660 100644 --- a/tests/test3.lua +++ b/tests/test3.lua @@ -1,16 +1,10 @@ function test3() - print "testing rsa" - local bits = 2048 - local e = 65537 - local key = rsa:gen_key(bits, 65537) - --for k, v in pairs(key) do print(k.."=lcrypt.bigint(lcrypt.fromhex('"..lcrypt.tohex(tostring(v)).."'))") end - - msg = lcrypt.random(bits/8 - 5) - s = rsa:sign_oaep(msg, 'jello', key) - if rsa:verify_oaep(s, msg, 'jello', key) then - print "ok" - else - --for k, v in pairs(key) do print(k.."=lcrypt.bigint(lcrypt.fromhex('"..lcrypt.tohex(tostring(v)).."'))") end - error "rsa failure" - end + local x = BigInt.new "1234" + local y = BigInt.new "5678" + local z = x + y + if tostring(z) ~= "6912" then error "bigint1" end + -- unlike PHP, Lua is smarter. An object and a number aren't the same things, thus aren't equal. + if z == 6912 then error "bigint2" end + -- this is the proper comparison. + if z ~= BigInt.new(6912) then error "bigint3" end end -- cgit v1.2.3