print montgomery magics at compile-time
This commit is contained in:
parent
f1430915fe
commit
7740bfbae4
|
@ -131,3 +131,32 @@ macro getR2modP*(C: static Curve): untyped =
|
|||
macro getNegInvModWord*(C: static Curve): untyped =
|
||||
## Get the Montgomery "-1/P[0] mod 2^WordBitSize" constant associated to a curve field modulus
|
||||
result = bindSym($C & "_NegInvModWord")
|
||||
|
||||
# ############################################################
|
||||
#
|
||||
# Debug info printed at compile-time
|
||||
#
|
||||
# ############################################################
|
||||
|
||||
macro debugConsts(): untyped =
|
||||
let curves = bindSym("Curve")
|
||||
let E = curves.getImpl[2]
|
||||
|
||||
result = newStmtList()
|
||||
for i in 1 ..< E.len:
|
||||
let curve = E[i]
|
||||
let curveName = $curve
|
||||
let modulus = bindSym(curveName & "_Modulus")
|
||||
let r2modp = bindSym(curveName & "_R2modP")
|
||||
let negInvModWord = bindSym(curveName & "_NegInvModWord")
|
||||
|
||||
result.add quote do:
|
||||
echo "Curve ", `curveName`,':'
|
||||
echo " Field Modulus: ", `modulus`
|
||||
echo " Montgomery R² (mod P): ", `r2modp`
|
||||
echo " Montgomery -1/P[0] (mod 2^", WordBitSize, "): ", `negInvModWord`
|
||||
result.add quote do:
|
||||
echo "----------------------------------------------------------------------------"
|
||||
|
||||
debug:
|
||||
debugConsts()
|
||||
|
|
|
@ -330,7 +330,6 @@ func fromHex*(T: type BigInt, s: string): T =
|
|||
# 1. Convert to canonical uint
|
||||
const canonLen = (T.bits + 8 - 1) div 8
|
||||
var bytes: array[canonLen, byte]
|
||||
debugEcho "canonLen: ", canonLen
|
||||
hexToPaddedByteArray(s, bytes, littleEndian)
|
||||
|
||||
# 2. Convert canonical uint to Big Int
|
||||
|
|
Loading…
Reference in New Issue