mirror of
https://github.com/logos-storage/constantine.git
synced 2026-01-03 21:53:06 +00:00
* Introduce Fr type: finite field over curve order. Need workaround for https://github.com/nim-lang/Nim/issues/16774 * Split curve properties into core and derived * Attach field properties to an instantiated field instead of the curve enum * Workaround https://github.com/nim-lang/Nim/issues/14021, yet another "working with types in macros" is difficult https://github.com/nim-lang/RFCs/issues/44 * Implement finite field over prime order of a curve subgroup * skip OpenSSL tests on windows
48 lines
1.5 KiB
Nim
48 lines
1.5 KiB
Nim
# Constantine
|
|
# Copyright (c) 2018-2019 Status Research & Development GmbH
|
|
# Copyright (c) 2020-Present Mamy André-Ratsimbazafy
|
|
# Licensed and distributed under either of
|
|
# * MIT license (license terms in the root directory or at http://opensource.org/licenses/MIT).
|
|
# * Apache v2 license (license terms in the root directory or at http://www.apache.org/licenses/LICENSE-2.0).
|
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
|
|
|
import
|
|
std/macros,
|
|
../config/[curves, type_ff],
|
|
../towers,
|
|
./bls12_377_glv,
|
|
./bls12_381_glv,
|
|
./bn254_nogami_glv,
|
|
./bn254_snarks_glv,
|
|
./bw6_761_glv
|
|
|
|
{.experimental: "dynamicBindSym".}
|
|
|
|
macro dispatch(C: static Curve, tag: static string, G: static string): untyped =
|
|
result = bindSym($C & "_" & tag & "_" & G)
|
|
|
|
template babai*(F: typedesc[Fp or Fp2]): untyped =
|
|
## Return the GLV Babai roundings vector
|
|
const G = if F is Fp: "G1"
|
|
else: "G2"
|
|
dispatch(F.C, "Babai", G)
|
|
|
|
template lattice*(F: typedesc[Fp or Fp2]): untyped =
|
|
## Returns the GLV Decomposition Lattice
|
|
const G = if F is Fp: "G1"
|
|
else: "G2"
|
|
dispatch(F.C, "Lattice", G)
|
|
|
|
macro getCubicRootOfUnity_mod_p*(C: static Curve): untyped =
|
|
## Get a non-trivial cubic root of unity (mod p) with p the prime field
|
|
result = bindSym($C & "_cubicRootOfUnity_mod_p")
|
|
|
|
func hasEndomorphismAcceleration*(C: static Curve): bool =
|
|
C in {
|
|
BN254_Nogami,
|
|
BN254_Snarks,
|
|
BLS12_377,
|
|
BLS12_381,
|
|
BW6_761
|
|
}
|