Expose the equality proc beyond the debugConstantine flag
This commit is contained in:
parent
9f7c8515a4
commit
e2096297cf
|
@ -67,13 +67,6 @@ template view*(a: var BigInt): BigIntViewMut =
|
|||
debug:
|
||||
import strutils
|
||||
|
||||
func `==`*(a, b: BigInt): CTBool[Word] =
|
||||
## Returns true if 2 big ints are equal
|
||||
var accum: Word
|
||||
for i in static(0 ..< a.limbs.len):
|
||||
accum = accum or (a.limbs[i] xor b.limbs[i])
|
||||
result = accum.isZero
|
||||
|
||||
func `$`*(a: BigInt): string =
|
||||
result = "BigInt["
|
||||
result.add $BigInt.bits
|
||||
|
@ -97,6 +90,14 @@ func setInternalBitLength*(a: var BigInt) =
|
|||
## to that computed value.
|
||||
a.bitLength = uint32 static(a.bits + a.bits div WordBitSize)
|
||||
|
||||
func `==`*(a, b: BigInt): CTBool[Word] =
|
||||
## Returns true if 2 big ints are equal
|
||||
## Comparison is constant-time
|
||||
var accum: Word
|
||||
for i in static(0 ..< a.limbs.len):
|
||||
accum = accum or (a.limbs[i] xor b.limbs[i])
|
||||
result = accum.isZero
|
||||
|
||||
func isZero*(a: BigInt): CTBool[Word] =
|
||||
## Returns true if a big int is equal to zero
|
||||
a.view.isZero
|
||||
|
|
|
@ -216,6 +216,15 @@ debug:
|
|||
#
|
||||
# ############################################################
|
||||
|
||||
func `==`*(a, b: distinct BigIntViewAny): CTBool[Word] =
|
||||
## Returns true if 2 big ints are equal
|
||||
## Comparison is constant-time
|
||||
checkMatchingBitlengths(a, b)
|
||||
var accum: Word
|
||||
for i in 0 ..< a.numLimbs():
|
||||
accum = accum or (a[i] xor b[i])
|
||||
result = accum.isZero
|
||||
|
||||
func isZero*(a: BigIntViewAny): CTBool[Word] =
|
||||
## Returns true if a big int is equal to zero
|
||||
var accum: Word
|
||||
|
@ -336,7 +345,7 @@ func sub*(a: BigIntViewMut, b: BigIntViewAny): CTBool[Word] =
|
|||
result = a[i].isMsbSet()
|
||||
a[i] = a[i].mask()
|
||||
|
||||
func sum*(r: BigIntViewMut, a, b: BigIntViewAny): CTBool[Word] =
|
||||
func sum*(r: BigIntViewMut, a, b: distinct BigIntViewAny): CTBool[Word] =
|
||||
## Sum `a` and `b` into `r`.
|
||||
## `r` is initialized/overwritten
|
||||
##
|
||||
|
@ -350,7 +359,7 @@ func sum*(r: BigIntViewMut, a, b: BigIntViewAny): CTBool[Word] =
|
|||
result = a[i].isMsbSet()
|
||||
r[i] = r[i].mask()
|
||||
|
||||
func diff*(r: BigIntViewMut, a, b: BigIntViewAny): CTBool[Word] =
|
||||
func diff*(r: BigIntViewMut, a, b: distinct BigIntViewAny): CTBool[Word] =
|
||||
## Substract `b` from `a` and store the result into `r`.
|
||||
## `r` is initialized/overwritten
|
||||
##
|
||||
|
|
|
@ -39,10 +39,6 @@ import
|
|||
export Fp # defined in ../config/curves to avoid recursive module dependencies
|
||||
|
||||
debug:
|
||||
func `==`*(a, b: Fp): CTBool[Word] =
|
||||
## Returns true if 2 big ints are equal
|
||||
a.mres == b.mres
|
||||
|
||||
func `$`*[C: static Curve](a: Fp[C]): string =
|
||||
result = "Fp[" & $C
|
||||
result.add "]("
|
||||
|
@ -87,6 +83,10 @@ func toBig*(src: Fp): auto {.noInit.} =
|
|||
# - Golden Primes (φ^2 - φ - 1 with φ = 2^k for example Ed448-Goldilocks: 2^448 - 2^224 - 1)
|
||||
# exist and can be implemented with compile-time specialization.
|
||||
|
||||
func `==`*(a, b: Fp): CTBool[Word] =
|
||||
## Constant-time equality check
|
||||
a.mres == b.mres
|
||||
|
||||
func setZero*(a: var Fp) =
|
||||
## Set ``a`` to zero
|
||||
a.mres.setZero()
|
||||
|
|
|
@ -7,7 +7,9 @@
|
|||
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
||||
|
||||
import
|
||||
../arithmetic/finite_fields
|
||||
../arithmetic/finite_fields,
|
||||
../config/common,
|
||||
../primitives/constant_time
|
||||
|
||||
# ############################################################
|
||||
#
|
||||
|
@ -40,6 +42,10 @@ type
|
|||
x.c0 is BaseField
|
||||
x.c1 is BaseField
|
||||
|
||||
func `==`*(a, b: QuadExtAddGroup): CTBool[Word] =
|
||||
## Constant-time equality check
|
||||
(a.c0 == b.c0) and (a.c1 == b.c1)
|
||||
|
||||
func setZero*(a: var QuadExtAddGroup) =
|
||||
## Set ``a`` to zero in the extension field
|
||||
## Coordinates 0 + 0 𝛼
|
||||
|
@ -93,6 +99,10 @@ type
|
|||
x.c1 is BaseField
|
||||
x.c2 is BaseField
|
||||
|
||||
func `==`*(a, b: CubicExtAddGroup): CTBool[Word] =
|
||||
## Constant-time equality check
|
||||
(a.c0 == b.c0) and (a.c1 == b.c1) and (a.c2 == b.c2)
|
||||
|
||||
func setZero*(a: var CubicExtAddGroup) =
|
||||
## Set ``a`` to zero in the extension field
|
||||
## Coordinates 0 + 0 w + 0 w²
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
-d:debugConstantine
|
|
@ -1 +0,0 @@
|
|||
-d:debugConstantine
|
|
@ -1,2 +1 @@
|
|||
-d:testingCurves
|
||||
-d:debugConstantine
|
||||
|
|
|
@ -1,2 +1 @@
|
|||
-d:testingCurves
|
||||
-d:debugConstantine
|
||||
|
|
|
@ -1,2 +1 @@
|
|||
-d:testingCurves
|
||||
-d:debugConstantine
|
||||
|
|
Loading…
Reference in New Issue