Cosmetic changes: remove debug import strutils, BigInt.dec "returns" is now a doc comment, remove redundant setting the internal bitlength for modular multiplication
This commit is contained in:
parent
80f822c227
commit
d83101153a
|
@ -149,7 +149,6 @@ func fromUint*(
|
||||||
# Serialising from internal representation to canonical format
|
# Serialising from internal representation to canonical format
|
||||||
#
|
#
|
||||||
# ############################################################
|
# ############################################################
|
||||||
import strutils
|
|
||||||
|
|
||||||
template toByte(x: SomeUnsignedInt): byte =
|
template toByte(x: SomeUnsignedInt): byte =
|
||||||
## At compile-time, conversion to bytes checks the range
|
## At compile-time, conversion to bytes checks the range
|
||||||
|
|
|
@ -271,7 +271,7 @@ func sub*(a: BigIntViewMut, b: BigIntViewAny, ctl: CTBool[Word]): CTBool[Word] =
|
||||||
|
|
||||||
func dec*(a: BigIntViewMut, w: Word): CTBool[Word] =
|
func dec*(a: BigIntViewMut, w: Word): CTBool[Word] =
|
||||||
## Decrement a big int by a small word
|
## Decrement a big int by a small word
|
||||||
# returns the result carry
|
## Returns the result carry
|
||||||
|
|
||||||
a[0] -= w
|
a[0] -= w
|
||||||
result = a[0].isMsbSet()
|
result = a[0].isMsbSet()
|
||||||
|
|
|
@ -126,7 +126,6 @@ func `*`*(a, b: Fq): Fq {.noInit.} =
|
||||||
## It is recommended to assign with {.noInit.}
|
## It is recommended to assign with {.noInit.}
|
||||||
## as Fq elements are usually large and this
|
## as Fq elements are usually large and this
|
||||||
## routine will zero init internally the result.
|
## routine will zero init internally the result.
|
||||||
result.mres.setInternalBitLength()
|
|
||||||
result.mres.montyMul(a.mres, b.mres, Fq.C.Mod.mres, Fq.C.getNegInvModWord())
|
result.mres.montyMul(a.mres, b.mres, Fq.C.Mod.mres, Fq.C.getNegInvModWord())
|
||||||
|
|
||||||
func square*(a: Fq): Fq {.noInit.} =
|
func square*(a: Fq): Fq {.noInit.} =
|
||||||
|
@ -135,7 +134,6 @@ func square*(a: Fq): Fq {.noInit.} =
|
||||||
## It is recommended to assign with {.noInit.}
|
## It is recommended to assign with {.noInit.}
|
||||||
## as Fq elements are usually large and this
|
## as Fq elements are usually large and this
|
||||||
## routine will zero init internally the result.
|
## routine will zero init internally the result.
|
||||||
result.mres.setInternalBitLength()
|
|
||||||
result.mres.montySquare(a.mres, Fq.C.Mod.mres, Fq.C.getNegInvModWord())
|
result.mres.montySquare(a.mres, Fq.C.Mod.mres, Fq.C.getNegInvModWord())
|
||||||
|
|
||||||
func pow*(a: var Fq, exponent: BigInt) =
|
func pow*(a: var Fq, exponent: BigInt) =
|
||||||
|
@ -171,7 +169,6 @@ func inv*(a: var Fq) =
|
||||||
## Modular inversion
|
## Modular inversion
|
||||||
## Warning ⚠️ :
|
## Warning ⚠️ :
|
||||||
## - This assumes that `Fq` is a prime field
|
## - This assumes that `Fq` is a prime field
|
||||||
|
|
||||||
const windowSize = 5 # TODO: find best window size for each curves
|
const windowSize = 5 # TODO: find best window size for each curves
|
||||||
a.mres.montyPowUnsafeExponent(
|
a.mres.montyPowUnsafeExponent(
|
||||||
Fq.C.getInvModExponent(),
|
Fq.C.getInvModExponent(),
|
||||||
|
|
|
@ -74,8 +74,6 @@ func doubleMod(a: var BigInt, M: BigInt) =
|
||||||
func checkOddModulus(M: BigInt) =
|
func checkOddModulus(M: BigInt) =
|
||||||
doAssert bool(BaseType(M.limbs[0]) and 1), "Internal Error: the modulus must be odd to use the Montgomery representation."
|
doAssert bool(BaseType(M.limbs[0]) and 1), "Internal Error: the modulus must be odd to use the Montgomery representation."
|
||||||
|
|
||||||
import strutils
|
|
||||||
|
|
||||||
func checkValidModulus(M: BigInt) =
|
func checkValidModulus(M: BigInt) =
|
||||||
const expectedMsb = M.bits-1 - WordBitSize * (M.limbs.len - 1)
|
const expectedMsb = M.bits-1 - WordBitSize * (M.limbs.len - 1)
|
||||||
let msb = log2(BaseType(M.limbs[^1]))
|
let msb = log2(BaseType(M.limbs[^1]))
|
||||||
|
|
Loading…
Reference in New Issue