diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 4a40c3f..9f33fa3 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -131,13 +131,13 @@ steps: libffi-dev:i386 mkdir -p bin - - cat < EOF > bin/gcc + + cat << EOF > bin/gcc #!/bin/bash exec $(which gcc) -m32 "\$@" EOF - cat < EOF > bin/g++ + cat << EOF > bin/g++ #!/bin/bash exec $(which g++) -m32 "\$@" EOF diff --git a/constantine/arithmetic/finite_fields_inversion.nim b/constantine/arithmetic/finite_fields_inversion.nim index 99440ce..0057075 100644 --- a/constantine/arithmetic/finite_fields_inversion.nim +++ b/constantine/arithmetic/finite_fields_inversion.nim @@ -161,7 +161,10 @@ func inv*(r: var Fp, a: Fp) = # neither for Secp256k1 nor BN curves # Performance is slower than GCD # To be revisited with faster squaring/multiplications - r.mres.steinsGCD(a.mres, Fp.C.getR2modP(), Fp.C.Mod, Fp.C.getPrimePlus1div2()) + when false: # Fp.C.canUse_BN_AddchainInversion(): + r.invmod_addchain_bn(a) + else: + r.mres.steinsGCD(a.mres, Fp.C.getR2modP(), Fp.C.Mod, Fp.C.getPrimePlus1div2()) func inv*(a: var Fp) = ## Inversion modulo p @@ -175,5 +178,5 @@ func inv*(a: var Fp) = # Performance is slower than GCD # To be revisited with faster squaring/multiplications var t: typeof(a) # TODO: zero-init needed? - t.mres.steinsGCD(a.mres, Fp.C.getR2modP(), Fp.C.Mod, Fp.C.getPrimePlus1div2()) + t.inv(a) a = t diff --git a/constantine/config/curves_parser.nim b/constantine/config/curves_parser.nim index 98162e2..eba05cb 100644 --- a/constantine/config/curves_parser.nim +++ b/constantine/config/curves_parser.nim @@ -346,6 +346,14 @@ proc genMainConstants(defs: var seq[CurveParams]): NimNode = exported($curve & "_BN_can_use_addchain_inversion"), newLit true ) + curveExtraStmts.add newConstStmt( + exported($curve & "_BN_param_u"), + newCall( + bindSym"fromHex", + nnkBracketExpr.newTree(bindSym"BigInt", curveDef.bn_u_bitwidth), + curveDef.bn_u + ) + ) else: curveExtraStmts.add newConstStmt( exported($curve & "_BN_can_use_addchain_inversion"),