mirror of
https://github.com/codex-storage/constantine.git
synced 2025-01-13 12:34:31 +00:00
d41c653c8a
* Implement double-width field multiplication for double-width towering * Fp2 mul acceleration via double-width lazy reduction (pure Nim) * Inline assembly for basic add and sub * Use 2 registers instead of 12+ for ASM conditional copy * Prepare assembly for extended multiprecision multiplication support * Add assembly for mul * initial implementation of assembly reduction * stash current progress of assembly reduction * Fix clobbering issue, only P256 comparison remain buggy * Fix asm montgomery reduction for NIST P256 as well * MULX/ADCX/ADOX multi-precision multiplication * MULX/ADCX/ADOX reduction v1 * Add (deactivated) assembly for double-width substraction + rework benches * Add bench to nimble and deactivate double-width for now. slower than classic * Fix x86-32 running out of registers for mul * Clang needs to be at v9 to support flag output constraints (Xcode 11.4.2 / OSX Catalina) * 32-bit doesn't have enough registers for ASM mul * Fix again Travis Clang 9 issues * LLVM 9 is not whitelisted in travis * deactivated assembler with travis clang * syntax error * another * ... * missing space, yeah ...
41 lines
1.5 KiB
Nim
41 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/unittest,
|
|
../constantine/config/common,
|
|
../constantine/arithmetic,
|
|
../constantine/config/curves,
|
|
../constantine/io/[io_bigints, io_fields]
|
|
|
|
echo "\n------------------------------------------------------\n"
|
|
|
|
proc checkCubeRootOfUnity(curve: static Curve) =
|
|
test $curve & " cube root of unity (mod p)":
|
|
var cru = curve.getCubicRootOfUnity_mod_p()
|
|
cru.square()
|
|
cru *= curve.getCubicRootOfUnity_mod_p()
|
|
|
|
check: bool cru.isOne()
|
|
|
|
test $curve & " cube root of unity (mod r)":
|
|
var cru: BigInt[3 * curve.getCurveOrderBitwidth()]
|
|
cru.prod(curve.getCubicRootOfUnity_mod_r(), curve.getCubicRootOfUnity_mod_r())
|
|
cru.mul(curve.getCubicRootOfUnity_mod_r())
|
|
|
|
var r: BigInt[curve.getCurveOrderBitwidth()]
|
|
r.reduce(cru, curve.getCurveOrder)
|
|
|
|
check: bool r.isOne()
|
|
|
|
proc main() =
|
|
suite "Sanity checks on precomputed values" & " [" & $WordBitwidth & "-bit mode]":
|
|
checkCubeRootOfUnity(BN254_Snarks)
|
|
# checkCubeRootOfUnity(BLS12_381)
|
|
|
|
main()
|