Commit Graph

25 Commits

Author SHA1 Message Date
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 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 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 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 ff4a54daba
Add multiplication in 𝔽p6 = 𝔽p2[∛(1+𝑖)] 2020-03-21 19:03:57 +01:00
Mamy André-Ratsimbazafy 9e78cd5d6d
Benchmark template for 𝔽p, 𝔽p2, 𝔽p6 2020-03-21 02:31:31 +01:00
Mamy André-Ratsimbazafy bde619155b
30% faster constant-time inversion 2020-03-20 23:03:52 +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 feacf2b2ea
Fix 64-bit limbs, passing all tests 2020-02-29 14:49:38 +01:00
Mamy Ratsimbazafy 80f822c227
Set up CI with Azure Pipelines (#13)
* Set up CI with Azure Pipelines

[skip ci]

* Add task for testing without GMP

* Add C++ testing + no GMP on windows

* Add the Nim wrapper for GMP to Azure build

* Add Azure badge

* Fix nimble test tasks

* Workaround windows path in Azure

* Fix nim binaries path and mingw on 32-bit

* add stew test dependency

* Fix nim/nimble path

* disable GMP tests on windows
2020-02-23 18:27:26 +01:00
Mamy André-Ratsimbazafy acfc99c4f0
Add an unsafe modular exponentiation that may leak exponent bits to timing attacks/oscilloscopes/memory cache attacks 2020-02-22 18:18:17 +01:00
Mamy André-Ratsimbazafy 4b65d0d723
Skeleton of modular exponentiation 2020-02-22 16:37:31 +01:00
Mamy André-Ratsimbazafy d7d20c50b6
Add primitive for window-based modular exponentiation 2020-02-17 00:13:42 +01:00
Mamy André-Ratsimbazafy 5620bbfaee
rename io tests ti io bigints 2020-02-16 11:29:27 +01:00
Mamy André-Ratsimbazafy 301cf20195
Use Montgomery representation by default for Finite Field
- Fix montyMagic, modular inversion mode 2^2k was missing an iteration
- Fix test for buffer size in BigInt serialization
- Add UINT/Hex serialization for finite fields
- Montgomery conversion and redc
2020-02-15 00:26:40 +01:00
Mamy André-Ratsimbazafy 6226d86726
Update IO: dumpHex -> toHex dumpRawUint -> serializeRawUint 2020-02-12 21:57:39 +01:00
Mamy André-Ratsimbazafy 89fce3b1c4
Wrap tests in main. Fixes C codegen bug due to templates invocation on global variable in test_primitives 2020-02-12 00:25:48 +01:00
Mamy André-Ratsimbazafy 8d160189d1
Fix extended prec multiplication carry. Passing modulo tests against medium BigInt (192~256 bits) 2020-02-10 22:19:47 +01:00
Mamy André-Ratsimbazafy 153e898263
word_types -> primitives + delete the "config" file / debug template 2020-02-09 16:22:55 +01:00
Mamy André-Ratsimbazafy ff8b22e1d1
Use file-wide "no exceptions" enforcement 2020-02-09 01:03:06 +01:00
Mamy André-Ratsimbazafy 9db77ad0eb
Prepare for testing finite fields, comment cleanups 2020-02-09 00:52:24 +01:00
mratsim eb15fb33b5 Rebrand to Constantine. Bigints representation should stay opaque. Exporting just the word_types would make a super small library. 2018-12-01 20:12:05 +01:00