From e2333dce3cafe68cd53accf80449eba8162a20ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mamy=20Andr=C3=A9-Ratsimbazafy?= Date: Sat, 15 Feb 2020 16:11:17 +0100 Subject: [PATCH] Terminology nres -> mres, montgomeryResidue, montyResidue --- constantine/config/curves_parser.nim | 6 +++--- constantine/io/io_fields.nim | 4 ++-- constantine/math/bigints_checked.nim | 12 ++++++------ constantine/math/bigints_raw.nim | 2 +- constantine/math/finite_fields.nim | 20 ++++++++++---------- 5 files changed, 22 insertions(+), 22 deletions(-) diff --git a/constantine/config/curves_parser.nim b/constantine/config/curves_parser.nim index 0fa15bc..7853a82 100644 --- a/constantine/config/curves_parser.nim +++ b/constantine/config/curves_parser.nim @@ -95,7 +95,7 @@ macro declareCurves*(curves: untyped): untyped = nnkObjConstr.newTree( nnkBracketExpr.newTree(Fq, curve), nnkExprColonExpr.newTree( - ident"nres", + ident"mres", newCall( bindSym"fromHex", nnkBracketExpr.newTree(bindSym"BigInt", bitSize), @@ -151,7 +151,7 @@ macro declareCurves*(curves: untyped): untyped = # ## P being the prime modulus of the Curve C # ## Internally, data is stored in Montgomery n-residue form # ## with the magic constant chosen for convenient division (a power of 2 depending on P bitsize) - # nres*: matchingBigInt(C) + # mres*: matchingBigInt(C) result.add nnkTypeSection.newTree( nnkTypeDef.newTree( nnkPostfix.newTree(ident"*", Fq), @@ -164,7 +164,7 @@ macro declareCurves*(curves: untyped): untyped = newEmptyNode(), nnkRecList.newTree( newIdentDefs( - nnkPostfix.newTree(ident"*", ident"nres"), + nnkPostfix.newTree(ident"*", ident"mres"), newCall(matchingBigInt, C) ) ) diff --git a/constantine/io/io_fields.nim b/constantine/io/io_fields.nim index 33d7822..2434848 100644 --- a/constantine/io/io_fields.nim +++ b/constantine/io/io_fields.nim @@ -21,8 +21,8 @@ func fromUint*(dst: var Fq, src: SomeUnsignedInt) = ## Parse a regular unsigned integer ## and store it into a BigInt of size `bits` - dst.nres.fromRawUint(cast[array[sizeof(src), byte]](src), cpuEndian) - dst.nres.unsafeMontgomeryResidue(Fq.C.Mod.nres) + dst.mres.fromRawUint(cast[array[sizeof(src), byte]](src), cpuEndian) + dst.mres.unsafeMontyResidue(Fq.C.Mod.mres) func serializeRawUint*(dst: var openarray[byte], src: Fq, diff --git a/constantine/math/bigints_checked.nim b/constantine/math/bigints_checked.nim index 458cd75..57e5e11 100644 --- a/constantine/math/bigints_checked.nim +++ b/constantine/math/bigints_checked.nim @@ -111,26 +111,26 @@ func reduce*[aBits, mBits](r: var BigInt[mBits], a: BigInt[aBits], M: BigInt[mBi # pass a pointer+length to a fixed session of the BSS. reduce(r.view, a.view, M.view) -func unsafeMontgomeryResidue*[mBits](nres: var BigInt[mBits], N: BigInt[mBits]) = +func unsafeMontyResidue*[mBits](mres: var BigInt[mBits], N: BigInt[mBits]) = ## Convert a BigInt from its natural representation ## to the Montgomery n-residue form ## - ## `nres` is modified in-place + ## `mres` is modified in-place ## ## Caller must take care of properly switching between ## the natural and montgomery domain. ## Nesting Montgomery form is possible by applying this function twice. - montgomeryResidue(nres.view, N.view) + montyResidue(mres.view, N.view) -func unsafeRedc*[mBits](nres: var BigInt[mBits], N: BigInt[mBits], negInvModWord: static BaseType) = +func unsafeRedc*[mBits](mres: var BigInt[mBits], N: BigInt[mBits], negInvModWord: static BaseType) = ## Convert a BigInt from its Montgomery n-residue form ## to the natural representation ## - ## `nres` is modified in-place + ## `mres` is modified in-place ## ## Caller must take care of properly switching between ## the natural and montgomery domain. - redc(nres.view, N.view, Word(negInvModWord)) + redc(mres.view, N.view, Word(negInvModWord)) func montyMul*[mBits](r: var BigInt[mBits], a, b, M: BigInt[mBits], negInvModWord: static BaseType) = ## Compute r <- a*b (mod M) in the Montgomery domain diff --git a/constantine/math/bigints_raw.nim b/constantine/math/bigints_raw.nim index 309fd27..3ee6c8b 100644 --- a/constantine/math/bigints_raw.nim +++ b/constantine/math/bigints_raw.nim @@ -393,7 +393,7 @@ func reduce*(r: BigIntViewMut, a: BigIntViewAny, M: BigIntViewConst) = # # ############################################################ -func montgomeryResidue*(a: BigIntViewMut, N: BigIntViewConst) = +func montyResidue*(a: BigIntViewMut, N: BigIntViewConst) = ## Transform a bigint ``a`` from it's natural representation (mod N) ## to a the Montgomery n-residue representation ## diff --git a/constantine/math/finite_fields.nim b/constantine/math/finite_fields.nim index 8e69871..5cd172c 100644 --- a/constantine/math/finite_fields.nim +++ b/constantine/math/finite_fields.nim @@ -31,13 +31,13 @@ import # ## P being the prime modulus of the Curve C # ## Internally, data is stored in Montgomery n-residue form # ## with the magic constant chosen for convenient division (a power of 2 depending on P bitsize) -# nres*: matchingBigInt(C) +# mres*: matchingBigInt(C) export Fq # defined in ../config/curves to avoid recursive module dependencies debug: func `==`*(a, b: Fq): CTBool[Word] = ## Returns true if 2 big ints are equal - a.nres == b.nres + a.mres == b.mres # No exceptions allowed {.push raises: [].} @@ -51,13 +51,13 @@ debug: func fromBig*(T: type Fq, src: BigInt): T = ## Convert a BigInt to its Montgomery form - result.nres = src - result.nres.unsafeMontgomeryResidue(Fq.C.Mod) + result.mres = src + result.mres.unsafeMontyResidue(Fq.C.Mod) func toBig*(src: Fq): auto = ## Convert a finite-field element to a BigInt in natral representation - result = src.nres - result.unsafeRedC(Fq.C.Mod.nres, Fq.C.Mod.nres.negInvModWord()) + result = src.mres + result.unsafeRedC(Fq.C.Mod.mres, Fq.C.Mod.mres.negInvModWord()) # ############################################################ # @@ -72,7 +72,7 @@ template add(a: var Fq, b: Fq, ctl: CTBool[Word]): CTBool[Word] = ## ## a and b MAY be the same buffer ## a and b MUST have the same announced bitlength (i.e. `bits` static parameters) - add(a.nres, b.nres, ctl) + add(a.mres, b.mres, ctl) template sub(a: var Fq, b: Fq, ctl: CTBool[Word]): CTBool[Word] = ## Constant-time big integer in-place optional substraction @@ -81,7 +81,7 @@ template sub(a: var Fq, b: Fq, ctl: CTBool[Word]): CTBool[Word] = ## ## a and b MAY be the same buffer ## a and b MUST have the same announced bitlength (i.e. `bits` static parameters) - sub(a.nres, b.nres, ctl) + sub(a.mres, b.mres, ctl) # ############################################################ # @@ -114,5 +114,5 @@ 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.nres.setInternalBitLength() - result.nres.montyMul(a.nres, b.nres, Fq.C.Mod.nres, Fq.C.Mod.nres.negInvModWord()) + result.mres.setInternalBitLength() + result.mres.montyMul(a.mres, b.mres, Fq.C.Mod.mres, Fq.C.Mod.mres.negInvModWord())