mirror of
https://github.com/logos-storage/constantine.git
synced 2026-04-05 10:33:11 +00:00
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.
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
||||||
|
|
||||||
import
|
import
|
||||||
|
std/macros,
|
||||||
|
../config/curves,
|
||||||
./bls12_377_frobenius,
|
./bls12_377_frobenius,
|
||||||
./bls12_381_frobenius,
|
./bls12_381_frobenius,
|
||||||
./bn254_nogami_frobenius,
|
./bn254_nogami_frobenius,
|
||||||
./bn254_snarks_frobenius
|
./bn254_snarks_frobenius
|
||||||
|
|
||||||
export
|
{.experimental: "dynamicBindSym".}
|
||||||
bls12_377_frobenius,
|
|
||||||
bls12_381_frobenius,
|
macro frobMapConst*(C: static Curve, coef, p_pow: static int): untyped =
|
||||||
bn254_nogami_frobenius,
|
## Access the field Frobenius map a -> a^(p^p_pow)
|
||||||
bn254_snarks_frobenius
|
## 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
|
# 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.} =
|
func frobenius_map*[C](r: var Fp4[C], a: Fp4[C], k: static int = 1) {.inline.} =
|
||||||
## Computes a^(p^k)
|
## Computes a^(p^k)
|
||||||
## The p-power frobenius automorphism on 𝔽p4
|
## The p-power frobenius automorphism on 𝔽p4
|
||||||
r.c0.frobenius_map(a.c0, k)
|
r.c0.frobenius_map(a.c0, k)
|
||||||
r.c1.frobenius_map(a.c1, 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.} =
|
func frobenius_map*[C](r: var Fp6[C], a: Fp6[C], k: static int = 1) {.inline.} =
|
||||||
## Computes a^(p^k)
|
## 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.c0.frobenius_map(a.c0, k)
|
||||||
r.c1.frobenius_map(a.c1, k)
|
r.c1.frobenius_map(a.c1, k)
|
||||||
r.c2.frobenius_map(a.c2, k)
|
r.c2.frobenius_map(a.c2, k)
|
||||||
r.c1.mulCheckSparse frobMapConst(C)[k-1][2]
|
r.c1.mulCheckSparse frobMapConst(C, 2, k)
|
||||||
r.c2.mulCheckSparse frobMapConst(C)[k-1][4]
|
r.c2.mulCheckSparse frobMapConst(C, 4, k)
|
||||||
|
|
||||||
func frobenius_map*[C](r: var Fp12[C], a: Fp12[C], k: static int = 1) {.inline.} =
|
func frobenius_map*[C](r: var Fp12[C], a: Fp12[C], k: static int = 1) {.inline.} =
|
||||||
## Computes a^(p^k)
|
## 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):
|
for r_fp2, a_fp2 in fields(r_fp4, a_fp4):
|
||||||
r_fp2.frobenius_map(a_fp2, k)
|
r_fp2.frobenius_map(a_fp2, k)
|
||||||
|
|
||||||
r.c0.c0.mulCheckSparse frobMapConst(C)[k-1][0]
|
r.c0.c0.mulCheckSparse frobMapConst(C, 0, k)
|
||||||
r.c0.c1.mulCheckSparse frobMapConst(C)[k-1][3]
|
r.c0.c1.mulCheckSparse frobMapConst(C, 3, k)
|
||||||
r.c1.c0.mulCheckSparse frobMapConst(C)[k-1][1]
|
r.c1.c0.mulCheckSparse frobMapConst(C, 1, k)
|
||||||
r.c1.c1.mulCheckSparse frobMapConst(C)[k-1][4]
|
r.c1.c1.mulCheckSparse frobMapConst(C, 4, k)
|
||||||
r.c2.c0.mulCheckSparse frobMapConst(C)[k-1][2]
|
r.c2.c0.mulCheckSparse frobMapConst(C, 2, k)
|
||||||
r.c2.c1.mulCheckSparse frobMapConst(C)[k-1][5]
|
r.c2.c1.mulCheckSparse frobMapConst(C, 5, k)
|
||||||
|
|
||||||
# ψ (Psi) - Untwist-Frobenius-Twist Endomorphisms on twisted curves
|
# ψ (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
|
# 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) =
|
func frobenius_psi*[PointG2](r: var PointG2, P: PointG2) =
|
||||||
## "Untwist-Frobenius-Twist" endomorphism
|
## "Untwist-Frobenius-Twist" endomorphism
|
||||||
## r = ψ(P)
|
## r = ψ(P)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user