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:
Mamy André-Ratsimbazafy 2020-02-23 21:49:51 +01:00
parent 80f822c227
commit d83101153a
No known key found for this signature in database
GPG Key ID: 7B88AD1FE79492E1
4 changed files with 1 additions and 7 deletions

View File

@ -149,7 +149,6 @@ func fromUint*(
# Serialising from internal representation to canonical format
#
# ############################################################
import strutils
template toByte(x: SomeUnsignedInt): byte =
## At compile-time, conversion to bytes checks the range

View File

@ -271,7 +271,7 @@ func sub*(a: BigIntViewMut, b: BigIntViewAny, ctl: CTBool[Word]): CTBool[Word] =
func dec*(a: BigIntViewMut, w: Word): CTBool[Word] =
## Decrement a big int by a small word
# returns the result carry
## Returns the result carry
a[0] -= w
result = a[0].isMsbSet()

View File

@ -126,7 +126,6 @@ func `*`*(a, b: Fq): Fq {.noInit.} =
## It is recommended to assign with {.noInit.}
## as Fq elements are usually large and this
## routine will zero init internally the result.
result.mres.setInternalBitLength()
result.mres.montyMul(a.mres, b.mres, Fq.C.Mod.mres, Fq.C.getNegInvModWord())
func square*(a: Fq): Fq {.noInit.} =
@ -135,7 +134,6 @@ func square*(a: Fq): Fq {.noInit.} =
## It is recommended to assign with {.noInit.}
## as Fq elements are usually large and this
## routine will zero init internally the result.
result.mres.setInternalBitLength()
result.mres.montySquare(a.mres, Fq.C.Mod.mres, Fq.C.getNegInvModWord())
func pow*(a: var Fq, exponent: BigInt) =
@ -171,7 +169,6 @@ func inv*(a: var Fq) =
## Modular inversion
## Warning ⚠️ :
## - This assumes that `Fq` is a prime field
const windowSize = 5 # TODO: find best window size for each curves
a.mres.montyPowUnsafeExponent(
Fq.C.getInvModExponent(),

View File

@ -74,8 +74,6 @@ func doubleMod(a: var BigInt, 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."
import strutils
func checkValidModulus(M: BigInt) =
const expectedMsb = M.bits-1 - WordBitSize * (M.limbs.len - 1)
let msb = log2(BaseType(M.limbs[^1]))