mirror of
https://github.com/logos-storage/constantine.git
synced 2026-01-02 21:23:11 +00:00
Fix compiler hints and warnings (unused import/variables, ...)
This commit is contained in:
parent
99c9730793
commit
a17fb3b4c1
@ -14,11 +14,11 @@ type
|
||||
vesta_fr = Fr[Vesta]
|
||||
vesta_fp = Fp[Vesta]
|
||||
pallas_ec_aff = ECP_ShortW_Aff[Fp[Pallas], G1]
|
||||
pallas_ec_jac = ECP_ShortW_Aff[Fp[Pallas], G1]
|
||||
pallas_ec_prj = ECP_ShortW_Aff[Fp[Pallas], G1]
|
||||
pallas_ec_jac = ECP_ShortW_Jac[Fp[Pallas], G1]
|
||||
pallas_ec_prj = ECP_ShortW_Prj[Fp[Pallas], G1]
|
||||
vesta_ec_aff = ECP_ShortW_Aff[Fp[Vesta], G1]
|
||||
vesta_ec_jac = ECP_ShortW_Aff[Fp[Vesta], G1]
|
||||
vesta_ec_prj = ECP_ShortW_Aff[Fp[Vesta], G1]
|
||||
vesta_ec_jac = ECP_ShortW_Jac[Fp[Vesta], G1]
|
||||
vesta_ec_prj = ECP_ShortW_Prj[Fp[Vesta], G1]
|
||||
|
||||
collectBindings(cBindings):
|
||||
genBindingsField(pallas_fr)
|
||||
@ -28,7 +28,11 @@ collectBindings(cBindings):
|
||||
genBindingsField(vesta_fp)
|
||||
genBindingsFieldSqrt(vesta_fp)
|
||||
genBindings_EC_ShortW_Affine(pallas_ec_aff, pallas_fp)
|
||||
genBindings_EC_ShortW_NonAffine(pallas_ec_jac, pallas_ec_aff, pallas_fp)
|
||||
genBindings_EC_ShortW_NonAffine(pallas_ec_prj, pallas_ec_aff, pallas_fp)
|
||||
genBindings_EC_ShortW_Affine(vesta_ec_aff, pallas_fp)
|
||||
genBindings_EC_ShortW_NonAffine(vesta_ec_jac, vesta_ec_aff, vesta_fp)
|
||||
genBindings_EC_ShortW_NonAffine(vesta_ec_prj, vesta_ec_aff, vesta_fp)
|
||||
|
||||
# Write header
|
||||
when isMainModule and defined(CttGenerateHeaders):
|
||||
|
||||
@ -198,6 +198,36 @@ secret_bool ctt_pallas_ec_aff_is_on_curve(const pallas_fp* x, const pallas_fp* y
|
||||
void ctt_pallas_ec_aff_neg(pallas_ec_aff* P, const pallas_ec_aff* Q);
|
||||
void ctt_pallas_ec_aff_neg_in_place(pallas_ec_aff* P);
|
||||
|
||||
secret_bool ctt_pallas_ec_jac_is_eq(const pallas_ec_jac* P, const pallas_ec_jac* Q);
|
||||
secret_bool ctt_pallas_ec_jac_is_inf(const pallas_ec_jac* P);
|
||||
void ctt_pallas_ec_jac_set_inf(pallas_ec_jac* P);
|
||||
void ctt_pallas_ec_jac_ccopy(pallas_ec_jac* P, const pallas_ec_jac* Q, const secret_bool ctl);
|
||||
void ctt_pallas_ec_jac_neg(pallas_ec_jac* P, const pallas_ec_jac* Q);
|
||||
void ctt_pallas_ec_jac_neg_in_place(pallas_ec_jac* P);
|
||||
void ctt_pallas_ec_jac_cneg_in_place(pallas_ec_jac* P, const secret_bool ctl);
|
||||
void ctt_pallas_ec_jac_sum(pallas_ec_jac* r, const pallas_ec_jac* P, const pallas_ec_jac* Q);
|
||||
void ctt_pallas_ec_jac_add_in_place(pallas_ec_jac* P, const pallas_ec_jac* Q);
|
||||
void ctt_pallas_ec_jac_diff(pallas_ec_jac* r, const pallas_ec_jac* P, const pallas_ec_jac* Q);
|
||||
void ctt_pallas_ec_jac_double(pallas_ec_jac* r, const pallas_ec_jac* P);
|
||||
void ctt_pallas_ec_jac_double_in_place(pallas_ec_jac* P);
|
||||
void ctt_pallas_ec_jac_affine(pallas_ec_aff* dst, const pallas_ec_jac* src);
|
||||
void ctt_pallas_ec_jac_from_affine(pallas_ec_jac* dst, const pallas_ec_aff* src);
|
||||
|
||||
secret_bool ctt_pallas_ec_prj_is_eq(const pallas_ec_prj* P, const pallas_ec_prj* Q);
|
||||
secret_bool ctt_pallas_ec_prj_is_inf(const pallas_ec_prj* P);
|
||||
void ctt_pallas_ec_prj_set_inf(pallas_ec_prj* P);
|
||||
void ctt_pallas_ec_prj_ccopy(pallas_ec_prj* P, const pallas_ec_prj* Q, const secret_bool ctl);
|
||||
void ctt_pallas_ec_prj_neg(pallas_ec_prj* P, const pallas_ec_prj* Q);
|
||||
void ctt_pallas_ec_prj_neg_in_place(pallas_ec_prj* P);
|
||||
void ctt_pallas_ec_prj_cneg_in_place(pallas_ec_prj* P, const secret_bool ctl);
|
||||
void ctt_pallas_ec_prj_sum(pallas_ec_prj* r, const pallas_ec_prj* P, const pallas_ec_prj* Q);
|
||||
void ctt_pallas_ec_prj_add_in_place(pallas_ec_prj* P, const pallas_ec_prj* Q);
|
||||
void ctt_pallas_ec_prj_diff(pallas_ec_prj* r, const pallas_ec_prj* P, const pallas_ec_prj* Q);
|
||||
void ctt_pallas_ec_prj_double(pallas_ec_prj* r, const pallas_ec_prj* P);
|
||||
void ctt_pallas_ec_prj_double_in_place(pallas_ec_prj* P);
|
||||
void ctt_pallas_ec_prj_affine(pallas_ec_aff* dst, const pallas_ec_prj* src);
|
||||
void ctt_pallas_ec_prj_from_affine(pallas_ec_prj* dst, const pallas_ec_aff* src);
|
||||
|
||||
secret_bool ctt_vesta_ec_aff_is_eq(const vesta_ec_aff* P, const vesta_ec_aff* Q);
|
||||
secret_bool ctt_vesta_ec_aff_is_inf(const vesta_ec_aff* P);
|
||||
void ctt_vesta_ec_aff_set_inf(vesta_ec_aff* P);
|
||||
@ -206,6 +236,36 @@ secret_bool ctt_vesta_ec_aff_is_on_curve(const pallas_fp* x, const pallas_fp* y)
|
||||
void ctt_vesta_ec_aff_neg(vesta_ec_aff* P, const vesta_ec_aff* Q);
|
||||
void ctt_vesta_ec_aff_neg_in_place(vesta_ec_aff* P);
|
||||
|
||||
secret_bool ctt_vesta_ec_jac_is_eq(const vesta_ec_jac* P, const vesta_ec_jac* Q);
|
||||
secret_bool ctt_vesta_ec_jac_is_inf(const vesta_ec_jac* P);
|
||||
void ctt_vesta_ec_jac_set_inf(vesta_ec_jac* P);
|
||||
void ctt_vesta_ec_jac_ccopy(vesta_ec_jac* P, const vesta_ec_jac* Q, const secret_bool ctl);
|
||||
void ctt_vesta_ec_jac_neg(vesta_ec_jac* P, const vesta_ec_jac* Q);
|
||||
void ctt_vesta_ec_jac_neg_in_place(vesta_ec_jac* P);
|
||||
void ctt_vesta_ec_jac_cneg_in_place(vesta_ec_jac* P, const secret_bool ctl);
|
||||
void ctt_vesta_ec_jac_sum(vesta_ec_jac* r, const vesta_ec_jac* P, const vesta_ec_jac* Q);
|
||||
void ctt_vesta_ec_jac_add_in_place(vesta_ec_jac* P, const vesta_ec_jac* Q);
|
||||
void ctt_vesta_ec_jac_diff(vesta_ec_jac* r, const vesta_ec_jac* P, const vesta_ec_jac* Q);
|
||||
void ctt_vesta_ec_jac_double(vesta_ec_jac* r, const vesta_ec_jac* P);
|
||||
void ctt_vesta_ec_jac_double_in_place(vesta_ec_jac* P);
|
||||
void ctt_vesta_ec_jac_affine(vesta_ec_aff* dst, const vesta_ec_jac* src);
|
||||
void ctt_vesta_ec_jac_from_affine(vesta_ec_jac* dst, const vesta_ec_aff* src);
|
||||
|
||||
secret_bool ctt_vesta_ec_prj_is_eq(const vesta_ec_prj* P, const vesta_ec_prj* Q);
|
||||
secret_bool ctt_vesta_ec_prj_is_inf(const vesta_ec_prj* P);
|
||||
void ctt_vesta_ec_prj_set_inf(vesta_ec_prj* P);
|
||||
void ctt_vesta_ec_prj_ccopy(vesta_ec_prj* P, const vesta_ec_prj* Q, const secret_bool ctl);
|
||||
void ctt_vesta_ec_prj_neg(vesta_ec_prj* P, const vesta_ec_prj* Q);
|
||||
void ctt_vesta_ec_prj_neg_in_place(vesta_ec_prj* P);
|
||||
void ctt_vesta_ec_prj_cneg_in_place(vesta_ec_prj* P, const secret_bool ctl);
|
||||
void ctt_vesta_ec_prj_sum(vesta_ec_prj* r, const vesta_ec_prj* P, const vesta_ec_prj* Q);
|
||||
void ctt_vesta_ec_prj_add_in_place(vesta_ec_prj* P, const vesta_ec_prj* Q);
|
||||
void ctt_vesta_ec_prj_diff(vesta_ec_prj* r, const vesta_ec_prj* P, const vesta_ec_prj* Q);
|
||||
void ctt_vesta_ec_prj_double(vesta_ec_prj* r, const vesta_ec_prj* P);
|
||||
void ctt_vesta_ec_prj_double_in_place(vesta_ec_prj* P);
|
||||
void ctt_vesta_ec_prj_affine(vesta_ec_aff* dst, const vesta_ec_prj* src);
|
||||
void ctt_vesta_ec_prj_from_affine(vesta_ec_prj* dst, const vesta_ec_aff* src);
|
||||
|
||||
/*
|
||||
* Initializes the library:
|
||||
* - the Nim runtime if heap-allocated types are used,
|
||||
|
||||
@ -16,7 +16,7 @@ import
|
||||
curves/zoo_subgroups,
|
||||
curves/zoo_generators
|
||||
],
|
||||
./math/io/[io_bigints, io_fields, io_ec],
|
||||
./math/io/[io_bigints, io_fields],
|
||||
./math/isogenies/frobenius,
|
||||
./math/pairings,
|
||||
./math/pairing/[
|
||||
|
||||
@ -235,7 +235,7 @@ macro negmod2x_gen[N: static int](R: var Limbs[N], A: Limbs[N], m: Limbs[N div 2
|
||||
let usym = u.nimSymbol
|
||||
result.add quote do:
|
||||
var `isZerosym`{.noInit.}: BaseType
|
||||
var `usym`{.noinit.}: typeof(`A`)
|
||||
var `usym`{.noinit, used.}: typeof(`A`)
|
||||
result.add ctx.generate
|
||||
|
||||
func negmod2x_asm*[N: static int](r: var Limbs[N], a: Limbs[N], M: Limbs[N div 2]) =
|
||||
|
||||
@ -151,7 +151,7 @@ macro addmod_gen[N: static int](R: var Limbs[N], A, B, m: Limbs[N], spareBits: s
|
||||
let usym = u.nimSymbol
|
||||
let vsym = v.nimSymbol
|
||||
result.add quote do:
|
||||
var `usym`{.noinit.}, `vsym` {.noInit.}: typeof(`A`)
|
||||
var `usym`{.noinit.}, `vsym` {.noInit, used.}: typeof(`A`)
|
||||
staticFor i, 0, `N`:
|
||||
`usym`[i] = `A`[i]
|
||||
|
||||
@ -204,7 +204,7 @@ macro submod_gen[N: static int](R: var Limbs[N], A, B, m: Limbs[N]): untyped =
|
||||
let usym = u.nimSymbol
|
||||
let vsym = v.nimSymbol
|
||||
result.add quote do:
|
||||
var `usym`{.noinit.}, `vsym` {.noInit.}: typeof(`A`)
|
||||
var `usym`{.noinit.}, `vsym` {.noInit, used.}: typeof(`A`)
|
||||
staticFor i, 0, `N`:
|
||||
`usym`[i] = `A`[i]
|
||||
|
||||
@ -278,7 +278,7 @@ macro negmod_gen[N: static int](R: var Limbs[N], A, m: Limbs[N]): untyped =
|
||||
|
||||
let usym = u.nimSymbol
|
||||
result.add quote do:
|
||||
var `usym`{.noinit.}: typeof(`A`)
|
||||
var `usym`{.noinit, used.}: typeof(`A`)
|
||||
result.add ctx.generate
|
||||
|
||||
func negmod_asm*(r: var Limbs, a, m: Limbs) =
|
||||
|
||||
@ -101,7 +101,7 @@ macro mulMont_CIOS_sparebit_gen[N: static int](
|
||||
result.add quote do:
|
||||
static: doAssert: sizeof(SecretWord) == sizeof(ByteAddress)
|
||||
|
||||
var `tsym`: typeof(`r_PIR`) # zero init
|
||||
var `tsym`{.noInit, used.}: typeof(`r_PIR`)
|
||||
# Assumes 64-bit limbs on 64-bit arch (or you can't store an address)
|
||||
var `scratchSym` {.noInit.}: Limbs[`scratchSlots`]
|
||||
`scratchSym`[0] = cast[SecretWord](`a_PIR`[0].unsafeAddr)
|
||||
|
||||
@ -227,7 +227,7 @@ macro mulMont_CIOS_sparebit_adx_gen[N: static int](
|
||||
result.add quote do:
|
||||
static: doAssert: sizeof(SecretWord) == sizeof(ByteAddress)
|
||||
|
||||
var `tsym`{.noInit.}: typeof(`r_PIR`) # zero init
|
||||
var `tsym`{.noInit, used.}: typeof(`r_PIR`)
|
||||
# Assumes 64-bit limbs on 64-bit arch (or you can't store an address)
|
||||
var `scratchSym` {.noInit.}: Limbs[`scratchSlots`]
|
||||
`scratchSym`[0] = cast[SecretWord](`a_PIR`[0].unsafeAddr)
|
||||
|
||||
@ -136,7 +136,7 @@ macro mulx_gen[rLen, aLen, bLen: static int](r_PIR: var Limbs[rLen], a_PIR: Limb
|
||||
# Prologue
|
||||
let tsym = t.nimSymbol
|
||||
result.add quote do:
|
||||
var `tsym`{.noInit.}: array[`tSlots`, BaseType]
|
||||
var `tsym`{.noInit, used.}: array[`tSlots`, BaseType]
|
||||
|
||||
for i in 0 ..< min(rLen, bLen):
|
||||
if i == 0:
|
||||
@ -591,7 +591,7 @@ macro sqrx_gen*[rLen, aLen: static int](r_PIR: var Limbs[rLen], a_PIR: Limbs[aLe
|
||||
# -------------------------------
|
||||
let tsym = t.nimSymbol
|
||||
result.add quote do:
|
||||
var `tsym`{.noInit.}: array[`tSlots`, BaseType]
|
||||
var `tsym`{.noInit, used.}: array[`tSlots`, BaseType]
|
||||
|
||||
if aLen == 4:
|
||||
ctx.sqrx_gen4L(r, a, t)
|
||||
|
||||
@ -62,7 +62,7 @@ macro redc2xMont_gen*[N: static int](
|
||||
let usym = u.nimSymbol
|
||||
let vsym = v.nimSymbol
|
||||
result.add quote do:
|
||||
var `usym`{.noinit.}: Limbs[`uSlots`]
|
||||
var `usym`{.noinit, used.}: Limbs[`uSlots`]
|
||||
var `vsym` {.noInit.}: Limbs[`vSlots`]
|
||||
`vsym`[0] = cast[SecretWord](`r_PIR`[0].unsafeAddr)
|
||||
`vsym`[1] = cast[SecretWord](`a_PIR`[0].unsafeAddr)
|
||||
@ -233,7 +233,7 @@ macro mulMont_by_1_gen[N: static int](
|
||||
|
||||
# Copy a in t
|
||||
result.add quote do:
|
||||
var `scratchSym` {.noInit.}: Limbs[`scratchSlots`]
|
||||
var `scratchSym` {.noInit, used.}: Limbs[`scratchSlots`]
|
||||
|
||||
# Algorithm
|
||||
# ---------------------------------------------------------
|
||||
|
||||
@ -62,7 +62,7 @@ macro redc2xMont_adx_gen[N: static int](
|
||||
let vsym = v.nimSymbol
|
||||
result.add quote do:
|
||||
static: doAssert: sizeof(SecretWord) == sizeof(ByteAddress)
|
||||
var `usym`{.noinit.}: Limbs[`uSlots`]
|
||||
var `usym`{.noinit, used.}: Limbs[`uSlots`]
|
||||
var `vsym` {.noInit.}: Limbs[`vSlots`]
|
||||
`vsym`[0] = cast[SecretWord](`r_PIR`[0].unsafeAddr)
|
||||
`vsym`[1] = cast[SecretWord](`a_PIR`[0].unsafeAddr)
|
||||
@ -208,7 +208,7 @@ macro mulMont_by_1_adx_gen[N: static int](
|
||||
|
||||
# Copy a in t
|
||||
result.add quote do:
|
||||
var `scratchSym` {.noInit.}: Limbs[`scratchSlots`]
|
||||
var `scratchSym` {.noInit, used.}: Limbs[`scratchSlots`]
|
||||
|
||||
# Algorithm
|
||||
# ---------------------------------------------------------
|
||||
|
||||
@ -114,9 +114,6 @@ func powMontUnsafeExponent*[mBits: static int](
|
||||
var scratchSpace {.noInit.}: array[scratchLen, Limbs[mBits.wordsRequired]]
|
||||
powMontUnsafeExponent(a.limbs, exponent, M.limbs, one.limbs, negInvModWord, scratchSpace, spareBits)
|
||||
|
||||
from ../io/io_bigints import marshal
|
||||
# Workaround recursive dependencies
|
||||
|
||||
func powMont*[mBits, eBits: static int](
|
||||
a: var BigInt[mBits], exponent: BigInt[eBits],
|
||||
M, one: BigInt[mBits], negInvModWord: static BaseType, windowSize: static int,
|
||||
|
||||
@ -72,7 +72,6 @@ func square2x*(r: var FpDbl, a: Fp) =
|
||||
func redc2x*(r: var Fp, a: FpDbl) =
|
||||
## Reduce a double-precision field element into r
|
||||
## from [0, 2ⁿp) range to [0, p) range
|
||||
const N = r.mres.limbs.len
|
||||
redc2xMont(
|
||||
r.mres.limbs,
|
||||
a.limbs2x,
|
||||
|
||||
@ -161,7 +161,7 @@ func square_Comba[rLen, aLen](
|
||||
|
||||
func square_operandScan[rLen, aLen](
|
||||
r: var Limbs[rLen],
|
||||
a: Limbs[aLen]) =
|
||||
a: Limbs[aLen]) {.used.} =
|
||||
## Multi-precision squaring using Operand Scanning
|
||||
const stopEx = min(a.len * 2, r.len)
|
||||
var t: typeof(r) # zero-init, ensure on stack
|
||||
|
||||
@ -125,7 +125,7 @@ func redc2xMont_Comba[N: static int](
|
||||
r: var array[N, SecretWord],
|
||||
a: array[N*2, SecretWord],
|
||||
M: array[N, SecretWord],
|
||||
m0ninv: BaseType, skipFinalSub: static bool = false) =
|
||||
m0ninv: BaseType, skipFinalSub: static bool = false) {.used.} =
|
||||
## Montgomery reduce a double-precision bigint modulo M
|
||||
##
|
||||
## This maps
|
||||
|
||||
@ -148,7 +148,7 @@ func fromUnsatRepr*[LU, E, LP: static int](
|
||||
"\n WordBitwidth * LP: " & $WordBitwidth & " * " & $LP & " = " & $(WordBitwidth * LP)
|
||||
|
||||
var
|
||||
srcIdx, dstIdx = 0
|
||||
srcIdx {.used.}, dstIdx = 0
|
||||
acc = Zero
|
||||
accLen = 0
|
||||
|
||||
|
||||
@ -11,6 +11,8 @@ import
|
||||
./type_bigint,
|
||||
../io/io_bigints
|
||||
|
||||
{.used.}
|
||||
|
||||
# Precomputed constants
|
||||
# We need alternate code paths for the VM
|
||||
# for various reasons
|
||||
@ -161,7 +163,7 @@ func muladd2(hi, lo: var BaseType, a, b, c1, c2: BaseType) {.inline.}=
|
||||
addC(carry2, lo, lo, c2, 0)
|
||||
addC(carry2, hi, hi, 0, carry2)
|
||||
|
||||
func cadd(a: var BigInt, b: BigInt, ctl: bool): bool =
|
||||
func cadd(a: var BigInt, b: BigInt, ctl: bool): bool {.used.} =
|
||||
## In-place optional addition
|
||||
##
|
||||
## It is NOT constant-time and is intended
|
||||
|
||||
@ -8,7 +8,9 @@
|
||||
|
||||
import
|
||||
../config/curves,
|
||||
../io/[io_fields, io_extfields]
|
||||
../io/io_extfields
|
||||
|
||||
{.used.}
|
||||
|
||||
# Curve precomputed parameters
|
||||
# -----------------------------------------------------------------
|
||||
|
||||
@ -10,6 +10,8 @@ import
|
||||
../config/curves,
|
||||
../io/[io_bigints, io_fields]
|
||||
|
||||
{.used.}
|
||||
|
||||
# BLS12_377 G1
|
||||
# ------------------------------------------------------------
|
||||
|
||||
|
||||
@ -11,6 +11,8 @@ import
|
||||
../extension_fields,
|
||||
../io/io_extfields
|
||||
|
||||
{.used.}
|
||||
|
||||
# Frobenius map - on extension fields
|
||||
# -----------------------------------------------------------------
|
||||
|
||||
|
||||
@ -8,7 +8,9 @@
|
||||
|
||||
import
|
||||
../config/curves,
|
||||
../io/[io_fields, io_extfields]
|
||||
../io/io_extfields
|
||||
|
||||
{.used.}
|
||||
|
||||
# Curve precomputed parameters
|
||||
# -----------------------------------------------------------------
|
||||
|
||||
@ -10,6 +10,8 @@ import
|
||||
../config/curves,
|
||||
../io/[io_bigints, io_fields]
|
||||
|
||||
{.used.}
|
||||
|
||||
# BLS12_381 G1
|
||||
# ------------------------------------------------------------
|
||||
|
||||
|
||||
@ -11,6 +11,8 @@ import
|
||||
../extension_fields,
|
||||
../io/io_extfields
|
||||
|
||||
{.used.}
|
||||
|
||||
# Frobenius map - on extension fields
|
||||
# -----------------------------------------------------------------
|
||||
|
||||
|
||||
@ -11,6 +11,8 @@ import
|
||||
../elliptic/ec_shortweierstrass_affine,
|
||||
../io/[io_fields, io_extfields]
|
||||
|
||||
{.used.}
|
||||
|
||||
# Generators
|
||||
# -----------------------------------------------------------------
|
||||
# https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-pairing-friendly-curves-10#section-4.2.1
|
||||
|
||||
@ -10,6 +10,8 @@ import
|
||||
../config/curves,
|
||||
../io/io_fields
|
||||
|
||||
{.used.}
|
||||
|
||||
# Hash-to-Curve Shallue-van de Woestijne (SVDW) BLS12_381 G1 map
|
||||
# -----------------------------------------------------------------
|
||||
# Spec:
|
||||
|
||||
@ -10,6 +10,8 @@ import
|
||||
../config/curves,
|
||||
../io/[io_fields, io_extfields]
|
||||
|
||||
{.used.}
|
||||
|
||||
# Hash-to-Curve Shallue-van de Woestijne (SVDW) BLS12_381 G2 map
|
||||
# -----------------------------------------------------------------
|
||||
# Spec:
|
||||
|
||||
@ -10,6 +10,8 @@ import
|
||||
../config/curves,
|
||||
../io/io_extfields
|
||||
|
||||
{.used.}
|
||||
|
||||
# Square Root Fp2 constants
|
||||
# -----------------------------------------------------------------
|
||||
const BLS12_381_sqrt_fp2_QNR* = Fp2[BLS12_381].fromHex(
|
||||
|
||||
@ -8,7 +8,9 @@
|
||||
|
||||
import
|
||||
../config/curves,
|
||||
../io/[io_fields, io_extfields]
|
||||
../io/io_extfields
|
||||
|
||||
{.used.}
|
||||
|
||||
# Curve precomputed parameters
|
||||
# -----------------------------------------------------------------
|
||||
|
||||
@ -10,6 +10,8 @@ import
|
||||
../config/curves,
|
||||
../io/[io_bigints, io_fields]
|
||||
|
||||
{.used.}
|
||||
|
||||
# BN254_Nogami G1
|
||||
# ------------------------------------------------------------
|
||||
|
||||
|
||||
@ -11,6 +11,8 @@ import
|
||||
../extension_fields,
|
||||
../io/io_extfields
|
||||
|
||||
{.used.}
|
||||
|
||||
# Frobenius map - on extension fields
|
||||
# -----------------------------------------------------------------
|
||||
|
||||
|
||||
@ -37,8 +37,6 @@ func invsqrt_addchain*(r: var Fp[BN254_Nogami], a: Fp[BN254_Nogami]) {.addchain.
|
||||
r35 {.noInit.}: Fp[BN254_Nogami]
|
||||
r36 {.noInit.}: Fp[BN254_Nogami]
|
||||
r37 {.noInit.}: Fp[BN254_Nogami]
|
||||
r98 {.noInit.}: Fp[BN254_Nogami]
|
||||
r263 {.noInit.}: Fp[BN254_Nogami]
|
||||
|
||||
r10.square_repeated(x11, 7)
|
||||
r10 *= x11
|
||||
|
||||
@ -10,6 +10,8 @@ import
|
||||
../config/curves,
|
||||
../io/io_extfields
|
||||
|
||||
{.used.}
|
||||
|
||||
# Square Root Fp2 constants
|
||||
# -----------------------------------------------------------------
|
||||
const BN254_Nogami_sqrt_fp2_QNR* = Fp2[BN254_Nogami].fromHex(
|
||||
|
||||
@ -43,7 +43,7 @@ func pow_BN254_Nogami_minus_u[ECP: ECP_ShortW[Fp[BN254_Nogami], G1] or
|
||||
ECP_ShortW[Fp2[BN254_Nogami], G2]](
|
||||
r{.noalias.}: var ECP,
|
||||
P{.noalias.}: ECP
|
||||
) {.inline.}=
|
||||
) {.inline, used.}=
|
||||
## Does the scalar multiplication [-u]P
|
||||
## with u the BN curve parameter
|
||||
pow_BN254_Nogami_abs_u(r, P)
|
||||
@ -54,7 +54,6 @@ func pow_BN254_Nogami_minus_u[ECP: ECP_ShortW[Fp[BN254_Nogami], G1] or
|
||||
#
|
||||
# ############################################################
|
||||
|
||||
const Cofactor_Eff_BN254_Nogami_G1 = BigInt[1].fromHex"0x1"
|
||||
const Cofactor_Eff_BN254_Nogami_G2 = BigInt[444].fromHex"0xab11da940a5bd10e25327cb22360008556b23c24080002d6845e3404000009a4f95b60000000145460100000000018544800000000000c8"
|
||||
# r = 36x⁴ + 36x³ + 18x² + 6x + 1
|
||||
# G2.order() = (36x⁴ + 36x³ + 18x² + 6x + 1)(36x⁴ + 36x³ + 30x² + 6x + 1)
|
||||
|
||||
@ -8,7 +8,9 @@
|
||||
|
||||
import
|
||||
../config/curves,
|
||||
../io/[io_fields, io_extfields]
|
||||
../io/io_extfields
|
||||
|
||||
{.used.}
|
||||
|
||||
# Curve precomputed parameters
|
||||
# -----------------------------------------------------------------
|
||||
|
||||
@ -10,6 +10,8 @@ import
|
||||
../config/curves,
|
||||
../io/[io_bigints, io_fields]
|
||||
|
||||
{.used.}
|
||||
|
||||
# BN254_Snarks G1
|
||||
# ------------------------------------------------------------
|
||||
|
||||
|
||||
@ -11,6 +11,8 @@ import
|
||||
../extension_fields,
|
||||
../io/io_extfields
|
||||
|
||||
{.used.}
|
||||
|
||||
# Frobenius map - on extension fields
|
||||
# -----------------------------------------------------------------
|
||||
|
||||
|
||||
@ -11,6 +11,8 @@ import
|
||||
../elliptic/ec_shortweierstrass_affine,
|
||||
../io/[io_fields, io_extfields]
|
||||
|
||||
{.used.}
|
||||
|
||||
# Generators
|
||||
# -----------------------------------------------------------------
|
||||
# https://github.com/ethereum/EIPs/blob/master/EIPS/eip-197.md
|
||||
|
||||
@ -10,6 +10,8 @@ import
|
||||
../config/curves,
|
||||
../io/io_fields
|
||||
|
||||
{.used.}
|
||||
|
||||
# Hash-to-Curve Shallue-van de Woestijne BN254_Snarks G1 map
|
||||
# -----------------------------------------------------------------
|
||||
# Spec:
|
||||
|
||||
@ -8,7 +8,9 @@
|
||||
|
||||
import
|
||||
../config/curves,
|
||||
../io/[io_fields, io_extfields]
|
||||
../io/io_extfields
|
||||
|
||||
{.used.}
|
||||
|
||||
# Hash-to-Curve Shallue-van de Woestijne BN254_Snarks G2 map
|
||||
# -----------------------------------------------------------------
|
||||
|
||||
@ -11,8 +11,7 @@ import
|
||||
../config/curves,
|
||||
../io/io_bigints,
|
||||
../extension_fields,
|
||||
../elliptic/[ec_shortweierstrass_affine, ec_shortweierstrass_projective],
|
||||
../pairing/[cyclotomic_subgroup, miller_loops],
|
||||
../pairing/cyclotomic_subgroup,
|
||||
../isogenies/frobenius
|
||||
|
||||
# Slow generic implementation
|
||||
|
||||
@ -10,6 +10,8 @@ import
|
||||
../config/curves,
|
||||
../io/io_extfields
|
||||
|
||||
{.used.}
|
||||
|
||||
# Square Root Fp2 constants
|
||||
# -----------------------------------------------------------------
|
||||
const BN254_Snarks_sqrt_fp2_QNR* = Fp2[BN254_Snarks].fromHex(
|
||||
|
||||
@ -106,7 +106,7 @@ func pow_bn254_snarks_minus_u[ECP: ECP_ShortW[Fp[BN254_Snarks], G1] or
|
||||
ECP_ShortW[Fp2[BN254_Snarks], G2]](
|
||||
r{.noalias.}: var ECP,
|
||||
P{.noalias.}: ECP
|
||||
) {.inline.}=
|
||||
) {.inline, used.}=
|
||||
## Does the scalar multiplication [-u]P
|
||||
## with the BN curve parameter
|
||||
pow_bn254_snarks_abs_u(r, P)
|
||||
@ -118,7 +118,6 @@ func pow_bn254_snarks_minus_u[ECP: ECP_ShortW[Fp[BN254_Snarks], G1] or
|
||||
#
|
||||
# ############################################################
|
||||
|
||||
const Cofactor_Eff_BN254_Snarks_G1 = BigInt[1].fromHex"0x1"
|
||||
const Cofactor_Eff_BN254_Snarks_G2 = BigInt[445].fromHex"0x10fdac342d9d118eaade453b741519b8e1d63b3400132e99468a9c2b25de5b5f1bf35b43bcc5da2335a0d8a112d43476616edcfabef338ea"
|
||||
# r = 36x⁴ + 36x³ + 18x² + 6x + 1
|
||||
# G2.order() = (36x⁴ + 36x³ + 18x² + 6x + 1)(36x⁴ + 36x³ + 30x² + 6x + 1)
|
||||
|
||||
@ -10,6 +10,8 @@ import
|
||||
../config/curves,
|
||||
../io/[io_fields, io_extfields]
|
||||
|
||||
{.used.}
|
||||
|
||||
# Curve precomputed parameters
|
||||
# -----------------------------------------------------------------
|
||||
const BW6_761_coefB_G2* = Fp[BW6_761].fromHex(
|
||||
|
||||
@ -10,6 +10,8 @@ import
|
||||
../config/curves,
|
||||
../io/[io_bigints, io_fields]
|
||||
|
||||
{.used.}
|
||||
|
||||
# BW6_761 G1
|
||||
# ------------------------------------------------------------
|
||||
|
||||
|
||||
@ -11,6 +11,8 @@ import
|
||||
../extension_fields,
|
||||
../io/[io_fields, io_extfields]
|
||||
|
||||
{.used.}
|
||||
|
||||
# Frobenius map - on extension fields
|
||||
# -----------------------------------------------------------------
|
||||
|
||||
|
||||
@ -13,8 +13,8 @@ import
|
||||
../arithmetic,
|
||||
../extension_fields,
|
||||
../ec_shortweierstrass,
|
||||
../io/io_bigints,
|
||||
../isogenies/frobenius
|
||||
../io/io_bigints
|
||||
# ../isogenies/frobenius
|
||||
|
||||
# ############################################################
|
||||
#
|
||||
|
||||
@ -10,6 +10,8 @@ import
|
||||
../config/curves,
|
||||
../io/[io_bigints, io_fields]
|
||||
|
||||
{.used.}
|
||||
|
||||
# Pallas G1
|
||||
# ------------------------------------------------------------
|
||||
|
||||
|
||||
@ -11,9 +11,7 @@ import
|
||||
../../platforms/abstractions,
|
||||
../config/curves,
|
||||
../arithmetic,
|
||||
../extension_fields,
|
||||
../ec_shortweierstrass,
|
||||
../io/io_bigints
|
||||
../ec_shortweierstrass
|
||||
|
||||
# ############################################################
|
||||
#
|
||||
@ -21,8 +19,6 @@ import
|
||||
#
|
||||
# ############################################################
|
||||
|
||||
const Cofactor_Eff_Pallas_G1 = BigInt[1].fromHex"0x1"
|
||||
|
||||
func clearCofactorReference*(P: var ECP_ShortW_Prj[Fp[Pallas], G1]) {.inline.} =
|
||||
## Clear the cofactor of Pallas G1
|
||||
## The Pasta curves have a prime-order group so this is a no-op
|
||||
|
||||
@ -10,6 +10,8 @@ import
|
||||
../config/curves,
|
||||
../io/[io_bigints, io_fields]
|
||||
|
||||
{.used.}
|
||||
|
||||
# Vesta G1
|
||||
# ------------------------------------------------------------
|
||||
|
||||
|
||||
@ -11,9 +11,7 @@ import
|
||||
../../platforms/abstractions,
|
||||
../config/curves,
|
||||
../arithmetic,
|
||||
../extension_fields,
|
||||
../ec_shortweierstrass,
|
||||
../io/io_bigints
|
||||
../ec_shortweierstrass
|
||||
|
||||
# ############################################################
|
||||
#
|
||||
@ -21,10 +19,8 @@ import
|
||||
#
|
||||
# ############################################################
|
||||
|
||||
const Cofactor_Eff_Pallas_G1 = BigInt[1].fromHex"0x1"
|
||||
|
||||
func clearCofactorReference*(P: var ECP_ShortW_Prj[Fp[Pallas], G1]) {.inline.} =
|
||||
## Clear the cofactor of Pallas G1
|
||||
func clearCofactorReference*(P: var ECP_ShortW_Prj[Fp[Vesta], G1]) {.inline.} =
|
||||
## Clear the cofactor of Vesta G1
|
||||
## The Pasta curves have a prime-order group so this is a no-op
|
||||
discard
|
||||
|
||||
@ -34,7 +30,7 @@ func clearCofactorReference*(P: var ECP_ShortW_Prj[Fp[Pallas], G1]) {.inline.} =
|
||||
#
|
||||
# ############################################################
|
||||
|
||||
func isInSubgroup*(P: ECP_ShortW[Fp[Pallas], G1]): SecretBool {.inline.} =
|
||||
func isInSubgroup*(P: ECP_ShortW[Fp[Vesta], G1]): SecretBool {.inline.} =
|
||||
## Returns true if P is in G1 subgroup, i.e. P is a point of order r.
|
||||
## A point may be on a curve but not on the prime order r subgroup.
|
||||
## Not checking subgroup exposes a protocol to small subgroup attacks.
|
||||
|
||||
@ -248,7 +248,7 @@ template sumImpl[F; G: static Subgroup](
|
||||
# which causes issues when CoefA isn't an int but Fp or Fp2
|
||||
when CoefA is int:
|
||||
const CoefA_eq_zero = CoefA == 0
|
||||
const CoefA_eq_minus3 = CoefA == -3
|
||||
const CoefA_eq_minus3 {.used.} = CoefA == -3
|
||||
else:
|
||||
const CoefA_eq_zero = false
|
||||
const CoefA_eq_minus3 = false
|
||||
|
||||
@ -32,10 +32,10 @@ func mux_fallback[T](ctl: CTBool[T], x, y: T): T {.inline.}=
|
||||
## This is a constant-time operation
|
||||
y xor (-T(ctl) and (x xor y))
|
||||
|
||||
func mux_fallback[T: CTBool](ctl: CTBool, x, y: T): T {.inline.}=
|
||||
func mux_fallback[T: CTBool](ctl, x, y: T): T {.inline.}=
|
||||
## result = if ctl: x else: y
|
||||
## This is a constant-time operation
|
||||
T(T.T(y) xor (-T.T(ctl) and T.T(x xor y)))
|
||||
T(T.T(y) xor (-T.T(ctl) and (T.T(x) xor T.T(y))))
|
||||
|
||||
func ccopy_fallback[T](ctl: CTBool[T], x: var T, y: T) {.inline.}=
|
||||
## Conditional copy
|
||||
|
||||
@ -608,12 +608,12 @@ func add*(a: var Assembler_x86, dst: Register, src: Operand) =
|
||||
func adc*(a: var Assembler_x86, dst, src: Operand) =
|
||||
## Does: dst <- dst + src + carry
|
||||
doAssert dst.desc.constraint in OutputReg
|
||||
doAssert dst.desc.rm notin {Mem, MemOffsettable, AnyRegOrMem},
|
||||
"Using addcarry with a memory destination, this incurs significant performance penalties."
|
||||
|
||||
a.codeFragment("adc", src, dst)
|
||||
a.areFlagsClobbered = true
|
||||
|
||||
if dst.desc.rm in {Mem, MemOffsettable, AnyRegOrMem}:
|
||||
{.warning: "Using addcarry with a memory destination, this incurs significant performance penalties.".}
|
||||
|
||||
func adc*(a: var Assembler_x86, dst, src: Register) =
|
||||
## Does: dst <- dst + src + carry
|
||||
a.codeFragment("adc", src, dst)
|
||||
@ -622,12 +622,12 @@ func adc*(a: var Assembler_x86, dst, src: Register) =
|
||||
func adc*(a: var Assembler_x86, dst: Operand, imm: int) =
|
||||
## Does: dst <- dst + imm + borrow
|
||||
doAssert dst.desc.constraint in OutputReg
|
||||
doAssert dst.desc.rm notin {Mem, MemOffsettable, AnyRegOrMem},
|
||||
"Using addcarry with a memory destination, this incurs significant performance penalties."
|
||||
|
||||
a.codeFragment("adc", imm, dst)
|
||||
a.areFlagsClobbered = true
|
||||
|
||||
if dst.desc.rm in {Mem, MemOffsettable, AnyRegOrMem}:
|
||||
{.warning: "Using addcarry with a memory destination, this incurs significant performance penalties.".}
|
||||
|
||||
func adc*(a: var Assembler_x86, dst: Operand, src: Register) =
|
||||
## Does: dst <- dst + src
|
||||
doAssert dst.desc.constraint in OutputReg
|
||||
@ -648,21 +648,21 @@ func sub*(a: var Assembler_x86, dst, src: Operand) =
|
||||
func sbb*(a: var Assembler_x86, dst, src: Operand) =
|
||||
## Does: dst <- dst - src - borrow
|
||||
doAssert dst.desc.constraint in OutputReg
|
||||
doAssert dst.desc.rm notin {Mem, MemOffsettable, AnyRegOrMem},
|
||||
"Using subborrow with a memory destination, this incurs significant performance penalties."
|
||||
|
||||
a.codeFragment("sbb", src, dst)
|
||||
a.areFlagsClobbered = true
|
||||
|
||||
if dst.desc.rm != Reg:
|
||||
{.warning: "Using subborrow with a memory destination, this incurs significant performance penalties.".}
|
||||
|
||||
func sbb*(a: var Assembler_x86, dst: Operand, imm: int) =
|
||||
## Does: dst <- dst - imm - borrow
|
||||
doAssert dst.desc.constraint in OutputReg
|
||||
doAssert dst.desc.rm notin {Mem, MemOffsettable, AnyRegOrMem},
|
||||
"Using subborrow with a memory destination, this incurs significant performance penalties."
|
||||
|
||||
a.codeFragment("sbb", imm, dst)
|
||||
a.areFlagsClobbered = true
|
||||
|
||||
if dst.desc.rm != Reg:
|
||||
{.warning: "Using subborrow with a memory destination, this incurs significant performance penalties.".}
|
||||
|
||||
func sbb*(a: var Assembler_x86, dst: Register, imm: int) =
|
||||
## Does: dst <- dst - imm - borrow
|
||||
a.codeFragment("sbb", imm, dst)
|
||||
|
||||
@ -45,7 +45,7 @@ type
|
||||
when SupportsGetTicks:
|
||||
cumulatedCycles*: int64
|
||||
|
||||
template mtag(tagname: string){.pragma.}
|
||||
template mtag(tagname: string){.pragma, used.}
|
||||
## This will allow tagging proc in the future with
|
||||
## "Fp", "ec", "polynomial"
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user