ref: f9f93d1e447873ca3e5fa6c542eb34e8dd8d4b71
dir: /lib/crypto/test/ctbig.myr/
use std use crypto use testr const Nbit = 128 const Nfunky = 79 const main = { testr.run([ /* normal */ [.name="add", .fn={ctx do2(ctx, crypto.ctadd, Nbit, "5192296858610368357189246603769160", "5192296858534810493479828944327220", "75557863709417659441940") }], [.name="sub", .fn={ctx do2(ctx, crypto.ctsub, Nbit, "5192296858459252629770411284885280", "5192296858534810493479828944327220", "75557863709417659441940") }], [.name="mul", .fn={ctx do2(ctx, crypto.ctmul, Nbit, "392318858376010676506814412592879878824393346033951606800", "5192296858534810493479828944327220", "75557863709417659441940") }], [.name="growmod", .fn={ctx do2(ctx, growmod0, Nbit, "259016584597313952181375284077740334036", "137304361882109849168381018424069802644", "279268927326277818181333274586733399084") } ], /* comparisons */ [.name="lt-less", .fn={ctx dobool(ctx, crypto.ctlt, Nbit, true, "137304361882109849168381018424069802644", "279268927326277818181333274586733399084") } ], [.name="lt-equal", .fn={ctx dobool(ctx, crypto.ctlt, Nbit, false, "137304361882109849168381018424069802644", "137304361882109849168381018424069802644") } ], [.name="lt-greater", .fn={ctx dobool(ctx, crypto.ctlt, Nbit, false, "279268927326277818181333274586733399084", "137304361882109849168381018424069802644") } ], [.name="gt-less", .fn={ctx dobool(ctx, crypto.ctgt, Nbit, false, "137304361882109849168381018424069802644", "279268927326277818181333274586733399084") } ], [.name="gt-equal", .fn={ctx dobool(ctx, crypto.ctgt, Nbit, false, "137304361882109849168381018424069802644", "137304361882109849168381018424069802644") } ], [.name="gt-greater", .fn={ctx dobool(ctx, crypto.ctgt, Nbit, true, "279268927326277818181333274586733399084", "137304361882109849168381018424069802644") } ], [.name="growmodsmall", .fn={ctx do2(ctx, growmod0, Nbit, "30064771072", "7", "279268927326277818181333274586733399084") } ], [.name="addfunky", .fn={ctx do2(ctx, crypto.ctadd, Nfunky, "75540728658750274549064", "5192296858534810493479828944327220", "75557863709417659441940") }], [.name="subfunky", .fn={ctx do2(ctx, crypto.ctsub, Nfunky, "528887911047229543018272", "5192296858534810493479828944327220", "75557863709417659441940") }], [.name="mulfunky", .fn={ctx do2(ctx, crypto.ctmul, Nfunky, "434472066238453871708176", "5192296858534810493479828944327220", "75557863709417659441940") }], //[.name="div", .fn={ctx // do2(ctx, div, // "75557863709417659441940", // "392318858376010676506814412592879878824393346033951606800", // "5192296858534810493479828944327220") //}], //[.name="mod", .fn={ctx // do2(ctx, mod, // "75557863709417659441940", // "392318858376010676506814412592879878824393346033951606800", // "5192296858534810493479828944327220") //}], [.name="modpow", .fn={ctx do3(ctx, crypto.ctmodpow, Nbit, "1231231254019581241243091223098123", "1231231254019581241243091223098123", "1", "238513807008428752753137056878245001837") }], ][:]) } //const div = {r, a, b // var z // // z = crypto.ctzero(a.nbit) // crypto.ctdivmod(r, z, a, b) //} // //const mod = {r, a, b // var z // // z = crypto.ctzero(a.nbit) // crypto.ctdivmod(z, r, a, b) //} const growmod0 = {r, a, b crypto.growmod(r, a, 0, b) } const dobool : (ctx : testr.ctx#, op : (a : crypto.ctbig#, b : crypto.ctbig# -> bool), nbit : std.size, e : bool, astr : byte[:], bstr : byte[:] -> void) = {ctx, op, nbit, e, astr, bstr var r, a, ai, b, bi r = crypto.ctzero(nbit) ai = std.get(std.bigparse(astr)) bi = std.get(std.bigparse(bstr)) a = crypto.big2ct(ai, nbit) b = crypto.big2ct(bi, nbit) std.bigfree(ai) std.bigfree(bi) testr.eq(ctx, op(a, b), e) crypto.ctfree(a) crypto.ctfree(b) } const do2 = {ctx, op, nbit, estr, astr, bstr var r, a, ai, b, bi, e, ei r = crypto.ctzero(nbit) ei = std.get(std.bigparse(estr)) ai = std.get(std.bigparse(astr)) bi = std.get(std.bigparse(bstr)) e = crypto.big2ct(ei, nbit) a = crypto.big2ct(ai, nbit) b = crypto.big2ct(bi, nbit) std.bigfree(ei) std.bigfree(ai) std.bigfree(bi) op(r, a, b) testr.eq(ctx, r, e) crypto.ctfree(r) crypto.ctfree(e) crypto.ctfree(a) crypto.ctfree(b) } const do3 = {ctx, op, nbit, estr, astr, bstr, cstr var r, a, ai, b, bi, c, ci, e, ei r = crypto.ctzero(nbit) ei = std.get(std.bigparse(estr)) ai = std.get(std.bigparse(astr)) bi = std.get(std.bigparse(bstr)) ci = std.get(std.bigparse(cstr)) e = crypto.big2ct(ei, nbit) a = crypto.big2ct(ai, nbit) b = crypto.big2ct(bi, nbit) c = crypto.big2ct(ci, nbit) std.bigfree(ei) std.bigfree(ai) std.bigfree(bi) op(r, a, b, c) testr.eq(ctx, r, e) crypto.ctfree(r) crypto.ctfree(e) crypto.ctfree(a) crypto.ctfree(b) crypto.ctfree(c) }