move frobenius macros
This commit is contained in:
parent
fd45a790eb
commit
e676e06959
|
@ -7,13 +7,28 @@
|
|||
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
||||
|
||||
import
|
||||
std/macros,
|
||||
../config/curves,
|
||||
./bls12_377_frobenius,
|
||||
./bls12_381_frobenius,
|
||||
./bn254_nogami_frobenius,
|
||||
./bn254_snarks_frobenius
|
||||
|
||||
export
|
||||
bls12_377_frobenius,
|
||||
bls12_381_frobenius,
|
||||
bn254_nogami_frobenius,
|
||||
bn254_snarks_frobenius
|
||||
{.experimental: "dynamicBindSym".}
|
||||
|
||||
macro frobMapConst*(C: static Curve, coef, p_pow: static int): untyped =
|
||||
## Access the field Frobenius map a -> a^(p^p_pow)
|
||||
## Call with
|
||||
## frobMapConst(Curve, coef, p_pow)
|
||||
##
|
||||
## With pow the
|
||||
return nnkBracketExpr.newTree(
|
||||
nnkBracketExpr.newTree(
|
||||
bindSym("FrobMapConst_" & $C),
|
||||
newLit(p_pow-1)
|
||||
),
|
||||
newLit coef
|
||||
)
|
||||
|
||||
macro frobPsiConst*(C: static Curve, psipow, coefpow: static int): untyped =
|
||||
return bindSym("FrobPsiConst_" & $C & "_psi" & $psipow & "_coef" & $coefpow)
|
||||
|
|
|
@ -67,17 +67,12 @@ template mulCheckSparse[Fp2](a: var Fp2, b: Fp2) =
|
|||
# Frobenius map - on extension fields
|
||||
# -----------------------------------------------------------------
|
||||
|
||||
{.experimental: "dynamicBindSym".}
|
||||
|
||||
macro frobMapConst(C: static Curve): untyped =
|
||||
return bindSym("FrobMapConst_" & $C)
|
||||
|
||||
func frobenius_map*[C](r: var Fp4[C], a: Fp4[C], k: static int = 1) {.inline.} =
|
||||
## Computes a^(p^k)
|
||||
## The p-power frobenius automorphism on 𝔽p4
|
||||
r.c0.frobenius_map(a.c0, k)
|
||||
r.c1.frobenius_map(a.c1, k)
|
||||
r.c1.mulCheckSparse frobMapConst(C)[k-1][3]
|
||||
r.c1.mulCheckSparse frobMapConst(C, 3, k)
|
||||
|
||||
func frobenius_map*[C](r: var Fp6[C], a: Fp6[C], k: static int = 1) {.inline.} =
|
||||
## Computes a^(p^k)
|
||||
|
@ -85,8 +80,8 @@ func frobenius_map*[C](r: var Fp6[C], a: Fp6[C], k: static int = 1) {.inline.} =
|
|||
r.c0.frobenius_map(a.c0, k)
|
||||
r.c1.frobenius_map(a.c1, k)
|
||||
r.c2.frobenius_map(a.c2, k)
|
||||
r.c1.mulCheckSparse frobMapConst(C)[k-1][2]
|
||||
r.c2.mulCheckSparse frobMapConst(C)[k-1][4]
|
||||
r.c1.mulCheckSparse frobMapConst(C, 2, k)
|
||||
r.c2.mulCheckSparse frobMapConst(C, 4, k)
|
||||
|
||||
func frobenius_map*[C](r: var Fp12[C], a: Fp12[C], k: static int = 1) {.inline.} =
|
||||
## Computes a^(p^k)
|
||||
|
@ -96,12 +91,12 @@ func frobenius_map*[C](r: var Fp12[C], a: Fp12[C], k: static int = 1) {.inline.}
|
|||
for r_fp2, a_fp2 in fields(r_fp4, a_fp4):
|
||||
r_fp2.frobenius_map(a_fp2, k)
|
||||
|
||||
r.c0.c0.mulCheckSparse frobMapConst(C)[k-1][0]
|
||||
r.c0.c1.mulCheckSparse frobMapConst(C)[k-1][3]
|
||||
r.c1.c0.mulCheckSparse frobMapConst(C)[k-1][1]
|
||||
r.c1.c1.mulCheckSparse frobMapConst(C)[k-1][4]
|
||||
r.c2.c0.mulCheckSparse frobMapConst(C)[k-1][2]
|
||||
r.c2.c1.mulCheckSparse frobMapConst(C)[k-1][5]
|
||||
r.c0.c0.mulCheckSparse frobMapConst(C, 0, k)
|
||||
r.c0.c1.mulCheckSparse frobMapConst(C, 3, k)
|
||||
r.c1.c0.mulCheckSparse frobMapConst(C, 1, k)
|
||||
r.c1.c1.mulCheckSparse frobMapConst(C, 4, k)
|
||||
r.c2.c0.mulCheckSparse frobMapConst(C, 2, k)
|
||||
r.c2.c1.mulCheckSparse frobMapConst(C, 5, k)
|
||||
|
||||
# ψ (Psi) - Untwist-Frobenius-Twist Endomorphisms on twisted curves
|
||||
# -----------------------------------------------------------------
|
||||
|
@ -111,9 +106,6 @@ func frobenius_map*[C](r: var Fp12[C], a: Fp12[C], k: static int = 1) {.inline.}
|
|||
# with SNR the sextic non-residue
|
||||
#
|
||||
|
||||
macro frobPsiConst(C: static Curve, psipow, coefpow: static int): untyped =
|
||||
return bindSym("FrobPsiConst_" & $C & "_psi" & $psipow & "_coef" & $coefpow)
|
||||
|
||||
func frobenius_psi*[PointG2](r: var PointG2, P: PointG2) =
|
||||
## "Untwist-Frobenius-Twist" endomorphism
|
||||
## r = ψ(P)
|
||||
|
|
Loading…
Reference in New Issue