From f1430915feb7e91ea4196753891c1036f2d3a70d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mamy=20Andr=C3=A9-Ratsimbazafy?= Date: Sun, 16 Feb 2020 12:03:01 +0100 Subject: [PATCH] Add Mersenn 61 and 127 + debugging print --- constantine/config/curves.nim | 6 ++++++ constantine/math/bigints_checked.nim | 12 ++++++++++++ constantine/math/finite_fields.nim | 6 ++++++ 3 files changed, 24 insertions(+) diff --git a/constantine/config/curves.nim b/constantine/config/curves.nim index f616ef9..46c5e84 100644 --- a/constantine/config/curves.nim +++ b/constantine/config/curves.nim @@ -58,6 +58,12 @@ else: curve Fake101: bitsize: 7 modulus: "0x65" # 101 in hex + curve Mersenne61: + bitsize: 61 + modulus: "0x1fffffffffffffff" # 2^61 - 1 + curve Mersenne127: + bitsize: 127 + modulus: "0x7fffffffffffffffffffffffffffffff" # 2^127 - 1 # ############################################################ # diff --git a/constantine/math/bigints_checked.nim b/constantine/math/bigints_checked.nim index a37e4a4..91b072e 100644 --- a/constantine/math/bigints_checked.nim +++ b/constantine/math/bigints_checked.nim @@ -72,6 +72,18 @@ debug: accum = accum or (a.limbs[i] xor b.limbs[i]) result = accum.isZero + func `$`*(a: BigInt): string = + result = "BigInt[" + result.add $BigInt.bits + result.add "](bitLength: " + result.add $a.bitLength + result.add ", limbs: [" + result.add $BaseType(a.limbs[0]) + for i in 1 ..< a.limbs.len: + result.add ", " + result.add $BaseType(a.limbs[i]) + result.add "])" + # No exceptions allowed {.push raises: [].} {.push inline.} diff --git a/constantine/math/finite_fields.nim b/constantine/math/finite_fields.nim index 8f996db..08a1efc 100644 --- a/constantine/math/finite_fields.nim +++ b/constantine/math/finite_fields.nim @@ -39,6 +39,12 @@ debug: ## Returns true if 2 big ints are equal a.mres == b.mres + func `$`*[C: static Curve](a: Fq[C]): string = + result = "Fq[" & $C + result.add "](" + result.add $a.mres + result.add ')' + # No exceptions allowed {.push raises: [].} {.push inline.}