Commit Graph

202 Commits

Author SHA1 Message Date
Mamy Ratsimbazafy 82ceca6e3b
Scalar mul tests (#28)
* Add sage script for BN254

* Implement (failing) scalar multiplication tests

* Add a first test against sagemath

* Finish the tests against SAGE for BN254

* Add significant test coverage of scalar multiplication with reference checks for BN254_Snarks and BLS12_381
2020-06-04 20:37:29 +02:00
Mamy André-Ratsimbazafy 71a2acc202
Report interesting moduli for BLS and BN curves 2020-05-22 17:55:03 +02:00
Mamy André-Ratsimbazafy ff9dec4813
Initial impl of side-channel resistant scalar mul to securely handle secret keys inputs. 2020-04-17 22:17:28 +02:00
Mamy André-Ratsimbazafy 44350d08af
Add elliptic doubling in projective coordinates 2020-04-15 22:23:46 +02:00
Mamy André-Ratsimbazafy f7818b566b
Fix ARM bench and ignore Windows 32-bit bench 2020-04-15 21:28:37 +02:00
Mamy André-Ratsimbazafy 7ae0f51000
benchmarking skips cycle counting for ARM 2020-04-15 21:24:18 +02:00
Mamy André-Ratsimbazafy d7e170288f
Add benches to the test suite to prevent forgetting about updating them 2020-04-15 19:46:25 +02:00
Mamy André-Ratsimbazafy ce350d1dac
add EC bench to nimble tasks 2020-04-15 19:43:31 +02:00
Mamy André-Ratsimbazafy e0c1e0b1c8
Add EC bench on G1 + Add throughput to benches 2020-04-15 19:38:02 +02:00
Mamy André-Ratsimbazafy 4ccea4fcff
Implement Chung-Hasan SQR3 2020-04-15 03:18:23 +02:00
Mamy André-Ratsimbazafy aff44f4d8e
Implement constant-time `div2` on finite and extension fields 2020-04-15 02:12:45 +02:00
Mamy André-Ratsimbazafy 8a9cb9287c Highlight that bools and words are "Secret" in the codebase 2020-04-15 00:04:44 +02:00
Mamy André-Ratsimbazafy 75557d88d8 Generalize the tower extensions tests 1000+ lines saved 2020-04-15 00:04:44 +02:00
Mamy André-Ratsimbazafy 1559bda56c Use our prng through most of the test suite 2020-04-15 00:04:44 +02:00
Mamy André-Ratsimbazafy 0115d3fd8e Rename the test PRNG to unsafe and prepare random number generation for integer ranges to not depend on the stdlib and have a single unified seed. 2020-04-15 00:04:44 +02:00
Mamy André-Ratsimbazafy d61680e1ad Fix substraction being addition following tower refactor 2020-04-15 00:04:44 +02:00
Mamy André-Ratsimbazafy 5784e78606 Towered extension comparison bug: squaring in 𝔽p6 is not properly implemented 2020-04-15 00:04:44 +02:00
Mamy André-Ratsimbazafy c8935f0a1d More tests to ensure that inversion of zero is zero 2020-04-15 00:04:44 +02:00
Mamy Ratsimbazafy c04721a04e
Refactor: Higher-Kinded Tower of Extension Fields (#25)
* Mention that the inverse of 0 is 0 (TODO tests)

* Introduce "Higher-Kinded tower extensions"

* rename isCOmplexExtension -> fromComplexExtension

* update benchmarks with the new tower scheme

* Try to recover some speed on mul/squaring for an optimal tower (but this was not it)
2020-04-14 02:05:42 +02:00
Mamy Ratsimbazafy 2f839cb1bf
Initial support for Elliptic Curve (#24)
* Elliptic curve and Twisted curve templates - initial commit

* Support EC Add on G2 (Sextic Twisted curve for BN and BLS12 families)

* Refactor the config parser to prepare for elliptic coefficient support

* Add elliptic curve parameter for BN254 (Snarks), BLS12-381 and Zexe curve BLS12-377

* Add accessors to curve parameters

* Allow computing the right-hand-side of of Weierstrass equation "y² = x³ + a x + b"

* Randomized test infrastructure for elliptic curves

* Start a testing suite on ellptic curve addition (failing)

* detail projective addition

* Fix EC addition test (forgot initializing Z=1 and that there ar emultiple infinity points)

* Test with random Z coordinate + add elliptic curve test to test suite

* fix reference to the (deactivated) addchain inversion for BN curves [skip ci]

* .nims file leftover [skip ci]
2020-04-13 19:25:59 +02:00
Mamy Ratsimbazafy 1889fc4eeb
Improve bn curve family support (#23)
* Allow tagging BarretoNaehrig family

* Refactor the constant generation and fix XDeclaredButNotUsed

* BN field inversion via addition chain (but slower than generic :/ so deactivated)
2020-04-12 16:09:38 +02:00
Mamy André-Ratsimbazafy 33314fe725
Properly distinguish between Nogami and Snark/Ethereum BN254 closes #19 2020-04-12 03:01:50 +02:00
Mamy Ratsimbazafy 42109d4f1c
Square roots (#22)
* Add modular square root for p ≡ 3 (mod 4)

* Exhaustive tests for sqrt with p ≡ 3 (mod 4)

* fix typo
2020-04-11 23:53:21 +02:00
Mamy André-Ratsimbazafy a6e4517be2
Implement 𝔽p12 inversion, enable 𝔽p12 tests and bench 2020-04-09 14:28:01 +02:00
Mamy André-Ratsimbazafy 3a1a5f8847
More coverage and crosscheck between multiplication, squaring, addition, substraction, negation 2020-04-09 13:58:56 +02:00
Mamy André-Ratsimbazafy 3a2b35ba26
Fix multiplication in 𝔽p12 2020-04-09 13:37:45 +02:00
Mamy André-Ratsimbazafy d081fca612
Fix squaring in 𝔽p6 (𝔽p2 squaring require separate target and source buffer) 2020-04-09 13:20:05 +02:00
Mamy André-Ratsimbazafy f24d87fb00
Fix squaring in 𝔽p12, mul in 𝔽p6 MUST NOT share buffer (i.e. broken value semantics) 2020-04-09 02:00:45 +02:00
Mamy André-Ratsimbazafy 8c478df0c1
𝔽p12 extension - initial commit of squaring 2020-04-09 01:23:10 +02:00
Mamy André-Ratsimbazafy e47159e40d
Somewhat working (?) sage script for quadratic/cubic non-residues 2020-03-22 21:57:15 +01:00
Mamy André-Ratsimbazafy 8b7374f405
Cleanup in Montgomery Mul, Square, Pow 2020-03-22 13:24:37 +01:00
Mamy André-Ratsimbazafy 2d5b173a39
Less magics, les macros, faster compile-times (or not, Fp6 starts to get really slow, like 5s) + some cleanups in curve families + test 𝔽p6 on 32-bit 2020-03-22 12:28:53 +01:00
Mamy André-Ratsimbazafy c40bc1977d
Inverse in cubic extension field 𝔽p6 = 𝔽p2[∛(1 + 𝑖)] 2020-03-21 23:47:43 +01:00
Mamy André-Ratsimbazafy ff4a54daba
Add multiplication in 𝔽p6 = 𝔽p2[∛(1+𝑖)] 2020-03-21 19:03:57 +01:00
Mamy André-Ratsimbazafy 964533494f
Struggling with sage to verify non-residues of extension towers 2020-03-21 17:42:06 +01:00
Mamy André-Ratsimbazafy 1282c38845
Add sage script for BN and BLS12 curve families 2020-03-21 15:50:39 +01:00
Mamy André-Ratsimbazafy 12363020e1
Fix link to curves config 2020-03-21 13:41:40 +01:00
Mamy André-Ratsimbazafy 1855d14497
Add more curves for testing: Curve25519, BLS12-377, BN446, FKM-447, BLS12-461, BN462 2020-03-21 13:05:58 +01:00
Mamy André-Ratsimbazafy 9e78cd5d6d
Benchmark template for 𝔽p, 𝔽p2, 𝔽p6 2020-03-21 02:31:31 +01:00
Mamy André-Ratsimbazafy 03898b2292
Implement squaring for 𝔽p6 = 𝔽p2[∛(1+𝑖)] 2020-03-21 01:59:23 +01:00
Mamy André-Ratsimbazafy bde619155b
30% faster constant-time inversion 2020-03-20 23:03:52 +01:00
Mamy André-Ratsimbazafy 1958356a09
duplicate the timer to mak formal verification self contained 2020-03-19 00:25:22 +01:00
Mamy André-Ratsimbazafy fafebacd05
Add formally verified and prover generated BLS12_381 implementation 2020-03-19 00:22:00 +01:00
Mamy Ratsimbazafy 6423be0dfb
Add optimized squaring (~15% speedup) (#18)
* Add optimized squaring (~15% speedup)

* avoid repetitions in tests
2020-03-17 22:04:37 +01:00
Mamy Ratsimbazafy 4ff0e3d90b
Internals refactor + renewed focus on perf (#17)
* Lay out the refactoring objectives and tradeoffs

* Refactor the 32 and 64-bit primitives [skip ci]

* BigInts and Modular BigInts compile

* Make the bigints test compile

* Fix modular reduction

* Fix reduction tests vs GMP

* Implement montegomery mul, pow, inverse, WIP finite field compilation

* Make FiniteField compile

* Fix exponentiation compilation

* Fix Montgomery magic constant computation  for 2^64 words

* Fix typo in non-optimized CIOS - passing finite fields IO tests

* Add limbs comparisons [skip ci]

* Fix on precomputation of the Montgomery magic constant

* Passing all tests including 𝔽p2

* modular addition, the test for mersenne prime was wrong

* update benches

* Fix "nimble test" + typo on out-of-place field addition

* bigint division, normalization is needed: https://travis-ci.com/github/mratsim/constantine/jobs/298359743

* missing conversion in subborrow non-x86 fallback - https://travis-ci.com/github/mratsim/constantine/jobs/298359744

* Fix little-endian serialization

* Constantine32 flag to run 32-bit constantine on 64-bit machines

* IO Field test, ensure that BaseType is used instead of uint64 when the prime can field in uint32

* Implement proper addcarry and subborrow fallback for the compile-time VM

* Fix export issue when the logical wordbitwidth == physical wordbitwidth - passes all tests (32-bit and 64-bit)

* Fix uint128 on ARM

* Fix C++ conditional copy and ARM addcarry/subborrow

* Add investigation for SIGFPE in Travis

* Fix debug display for unsafeDiv2n1n

* multiplexer typo

* moveMem bug in glibc of Ubuntu 16.04?

* Was probably missing an early clobbered register annotation on conditional mov

* Note on Montgomery-friendly moduli

* Strongly suspect a GCC before GCC 7 codegen bug (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87139)

* hex conversion was (for debugging) not taking requested order into account + inlining comment

* Use 32-bit limbs on ARM64, uint128 builtin __udivti4 bug?

* Revert "Use 32-bit limbs on ARM64, uint128 builtin __udivti4 bug?"

This reverts commit 087f9aa7fb40bbd058d05cbd8eec7fc082911f49.

* Fix subborrow fallback for non-x86 (need to maks the borrow)
2020-03-16 16:33:51 +01:00
Mamy André-Ratsimbazafy 191bb7710c
Add a warmup to the Fp bench to deal with CPU scaling 2020-03-15 21:02:17 +01:00
Mamy André-Ratsimbazafy b810422486
Add benchmark for Ethereum 1 and Ethereum 2 curves 2020-03-15 20:54:14 +01:00
Mamy André-Ratsimbazafy dc0c1c181c
enable substraction benchmarks 2020-03-07 12:23:46 +01:00
Mamy André-Ratsimbazafy 472823b749
more comprehensive benchmark of Fp 2020-03-06 17:44:30 +01:00
Mamy André-Ratsimbazafy adc630f3af
Fix overflow on win32 2020-03-01 17:05:14 +01:00