Commit Graph

401 Commits

Author SHA1 Message Date
Mamy Ratsimbazafy 8993789ddf
fix #221 2023-02-16 13:54:21 +01:00
Mamy Ratsimbazafy e5612f5705
Multi-Scalar-Multiplication / Linear combination (#220)
* unoptimized msm

* MSM: reorder loops

* add a signed windowed recoding technique

* improve wNAF table access

* use batchAffine

* revamp EC tests

* MSM signed digit support

* refactor MSM: recode signed ahead of time

* missing test vector

* refactor allocs and Alloca sideeffect

* add an endomorphism threshold

* Add Jacobian extended coordinates

* refactor recodings, prepare for parallelizable on-the-fly signed recoding

* recoding changes, introduce proper NAF for pairings

* more pairings refactoring, introduce miller accumulator for EVM

* some optim to the addchain miller loop

* start optimizing multi-pairing

* finish multi-miller loop refactoring

* minor tuning

* MSM: signed encoding suitable for parallelism (no precompute)

* cleanup signed window encoding

* add prefetching

* add metering

* properly init result to infinity

* comment on prefetching

* introduce vartime inversion for batch additions

* fix JacExt infinity conversion

* add batchAffine for MSM, though slower than JacExtended at the moment

* add a batch affine scheduler for MSM

* Add Multi-Scalar-Multiplication endomorphism acceleration

* some tuning

* signed integer fixes + 32-bit + tuning

* Some more tuning

* common msm bench + don't use affine for c < 9

* nit
2023-02-16 12:45:05 +01:00
Mamy Ratsimbazafy 082cd1deb9
MSB-to-LSB minimum Hamming Weight Recoding (#219)
* signed recoding

* use recoding
2023-02-07 16:27:53 +01:00
Mamy Ratsimbazafy 7c5421ffdc
move staticFor to the inner repo, not helpers/ for unblocking nimble install (#216) 2023-02-07 13:11:44 +01:00
Mamy Ratsimbazafy a11fca9c60
panics:on (#218) 2023-02-07 13:11:15 +01:00
Mamy Ratsimbazafy cbb454fff1
Codecs (#217)
* create a codecs.nim file for hex/base64 and other encoding conversions

* improve maintenance/readability of hex conversion

* add skeleton of constant-time base64 decoding

* use raw casts

* use raw casts only for same size types
2023-02-07 13:10:17 +01:00
Mamy Ratsimbazafy 95114bf707
move research sanity check to research/ [skip ci] 2023-01-30 20:57:12 +01:00
Mamy Ratsimbazafy 495ef4497b
Parallel batchadd (#215)
* [Threadpool] Fix syncAll releasing while a thread was attempting to steal + force no exception in tasks

* fix unguarded access on MacOS barriers

* parallel batchadd

* moved import
2023-01-29 01:06:37 +01:00
Mamy Ratsimbazafy a385acf2b8
Fix isZeroMask in SignedSecretWord 2023-01-29 01:05:54 +01:00
Mamy Ratsimbazafy 915f89fdd6
remove static/constant constraint on Montgomery 2023-01-28 18:25:30 +01:00
Mamy Ratsimbazafy ff8c26c1fe
BLS Aggregate and Batch verify (#214)
* pairing -> pairings, and use alloca arrays instead of static arrays

* aggregate and batched BLS signature

* DLL generation broken by path changes
2023-01-27 00:42:12 +01:00
Mamy Ratsimbazafy 7c01affe24
speedup test suite, focus on "integration" tests 2023-01-25 05:47:57 +01:00
Mamy Ratsimbazafy 2931913b67
Add a threadpool (#213)
* Implement a threadpool

* int and SomeUnsignedInt ...

* Type conversion for windows SynchronizationBarrier

* Use the latest MacOS 11, Big Sur API (jan 2021) for MacOS futexes, Github action offers MacOS 12 and can test them

* bench need posix timer not available on windows and darwin futex

* Windows: nimble exec empty line is an error, Mac: use defined(osx) instead of defined(macos)

* file rename

* okay, that's the last one hopefully

* deactivate stealHalf for now
2023-01-24 02:32:28 +01:00
Mamy Ratsimbazafy 188f3e710c
add fast_aggregate_verify 2023-01-23 01:54:40 +01:00
Mamy Ratsimbazafy 4be89d309f
chore: remove stew/byteutils dependencies and unneeded imports 2023-01-12 20:25:57 +01:00
Mamy Ratsimbazafy 4052a07611
chore: cleanup TODOs, unused constants 2023-01-12 01:27:23 +01:00
Mamy Ratsimbazafy 1f4bb174a3
[Backend] Add support for Nvidia GPUs (#210)
* Add PoC of JIT exec on Nvidia GPUs [skip ci]

* Split GPU bindings into low-level (ABI) and high-level [skip ci]

* small typedef reorg [skip ci]

* refine LLVM IR/Nvidia GPU hello worlds

* [Nvidia GPU] PoC implementation of field addition [skip ci]

* prod-ready field addition + tests on Nvidia GPUs via LLVM codegen
2023-01-12 01:01:57 +01:00
Mamy Ratsimbazafy c0b30a08be
style: casing of WordBitWidth/WordBitwidth 2023-01-11 19:31:23 +01:00
Mamy Ratsimbazafy 53a5729442
Remove sanity checks 'when isMainModule' superceded by comprehensive tests 2023-01-10 00:23:07 +01:00
Mamy Ratsimbazafy 928f515582
Batch additions (#207)
* Batch elliptic curve addition

* accelerate chained muls

* jac mixed add handle doubling. jac additions handle aliasing when adding infinity

* properly skip sanitizer on BLS signature test

* properly skip sanitizer² on BLS signature test
2022-10-29 22:43:40 +02:00
Mamy Ratsimbazafy 93654d580e
pararun: Ignore error #259, sha256: add back a paper 2022-09-19 09:11:16 +02:00
Mamy Ratsimbazafy d515bebdba
pararun: MacOS, weird error 259 when accumulating pipes or processes 2022-09-19 03:14:44 +02:00
Mamy Ratsimbazafy 351a3f6bd2
Sha256 refactor (#206)
* sha256: separate message scheduling and state updates to help implement specific use-cases like #205; also implement SSSE3 acceleration (2006, Intel Core 2 Duo)

* sha256: simplify update flow, store less metadata in context

* sha256: Fix reworked update function

* Implement x86 hardware SHA acceleration

* typo
2022-09-19 02:02:57 +02:00
Mamy Ratsimbazafy b901dd5878
CI: pure C can link to GMP, but Nim cannot LoadLib GMP, not found 2022-09-19 02:02:04 +02:00
Mamy Ratsimbazafy 495d5fa9fd
don't run afoul of pipe limits 2022-09-19 01:47:18 +02:00
Mamy Ratsimbazafy fb594c5938
OpenSSL upstream: no more SHA256 public function :/, skip in Windows CI 2022-09-19 01:22:01 +02:00
Mamy Ratsimbazafy 7c7290115f
nimble: fix bench_poly1305, improve reporting in pararun 2022-09-19 00:41:37 +02:00
Mamy Ratsimbazafy cc47c27cca
pararun: don't swallow failures 2022-09-18 23:37:35 +02:00
Mamy Ratsimbazafy 2f6144fb7a
add missing benches compilation to test suite 2022-09-18 15:26:42 +02:00
Mamy Ratsimbazafy d4e202ead5
Don't use array[^1], it can throw and cannot be locally turn off 2022-09-17 18:52:52 +02:00
Mamy Ratsimbazafy df048112c3
Example+Test C API vs GMP (#203)
* Example+Test C API vs GMP

* Create build directory for bindings test

* --nimMainPrefix is 1.6 only

* Add libdl for  dynamic loading

* absolute paths

* add static link test

* Fix man main, rename Nimmain to init_NimMain

* Deal with MacOS annoying linker w.r.t. static libraries

* use .exe extension to satisfy windows (?)

* annoying GCC which doesn't create paths

* Try skipping DLL test on windows

* windows extensions ...

* no lib prefix on windows
2022-09-15 17:11:57 +02:00
Mamy Ratsimbazafy 962e7ccf49
CI: enable GMP tests on Windows and Linux 32-bit and fix caching (#204)
* Try to compile with GMP on windows and 32-bit linux

* remove leftover msys shell

* Don't use GMP Mersenne Twister, bad randomness and untested Nim wrapper

* properly cache nim

* fix path after cache

* run pacman in msys2 env

* rework msys2 ... again

* shell compat for file clearing

* shell compat try-again for file clearing

* force bash for clearing parallel builds on windows

* Use nimscript directly (why didn't it work last time?)

* Avoid IO redirection to support any shell

* Avoid IO redirection v2 to support any shell

* add debug data

* add debug again

* Introduce pararun, a parallel test runner to remove need of GNU parallel

* pararun: style
2022-09-15 09:33:34 +02:00
Mamy Ratsimbazafy 094445482b
Eip2333 (#202)
* HMAC-SHA256

* EIP2333

* activate EIP2333 tests and faster random test case generation
2022-08-16 12:07:57 +02:00
Mamy Ratsimbazafy 9770b3108c
Fp12 over fp6 (#201)
* introduce sumprod for direct fp6_mul

* change curves -> constants

* forgotten constants

* Full pairing using Fp2->Fp6->Fp12 towering
2022-08-14 09:48:10 +02:00
Mamy Ratsimbazafy 37354e9ca8
faster isSquare: faster hash_to_curve (BN254) and point deserialization (BLS12-377) closes #199 2022-08-07 20:50:24 +02:00
Mamy Ratsimbazafy 74a23244d2
bench isSquare 2022-08-07 19:50:28 +02:00
Mamy Ratsimbazafy f35257d947
camelCase in C -> snake_case 2022-08-06 22:11:03 +02:00
Mamy Ratsimbazafy a17fb3b4c1
Fix compiler hints and warnings (unused import/variables, ...) 2022-08-06 19:55:35 +02:00
Mamy Ratsimbazafy 99c9730793
Self-contained bindings generation (#196)
* First draft at bindings generation

* finite field bindings PoC

* support openarray, export NimMain

* PoC extension fields and elliptic curve bindings

* Pasta

* expose more bindings, remove nimZeroMem, remove tracer when unused, codegen name_mangling`gensym issue

* workaround bad C gensym codegen with {.inline.} pragma in non-dirty template nested in generic proc instantiated by template
2022-08-06 19:05:54 +02:00
Mamy Ratsimbazafy 7d29cb947a
Prepare for bindings generation 2022-07-16 13:34:27 +02:00
Mamy Ratsimbazafy e29e529f18
Add multipairing for BN curves (#194) 2022-05-08 19:01:23 +02:00
Csaba Kiraly 21f880dde9
adding BN254 Snarks generators (#193)
adding generator values based on
https://github.com/ethereum/EIPs/blob/master/EIPS/eip-197.md

Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
2022-05-06 11:42:06 +02:00
Mamy Ratsimbazafy f678815563
Polish (#192)
* cyclotomic subgroup - 0 is not in the cyclotomic subgroup

* [doc] division is now constant-time

* Mention the newly added Pasta Curves / Halo 2 in README [skip ci]
2022-04-27 14:59:14 +02:00
Mamy Ratsimbazafy 39a8a413de
Pasta curves (#191)
* Pasta curves field arithmetic

* implement elliptic curve arith for the Pasta curves
2022-04-27 00:58:48 +02:00
Mamy Ratsimbazafy e9e7a1809c
BN254 - Hash-to-Curve (SVDW method) (#190)
* Hash to BN254-Snarks

* Test SVDW code path with old v7 vectors for BLS12-381

* add benches
2022-04-26 21:24:07 +02:00
Mamy Ratsimbazafy 062ae56867
Try to use hash-to-curve for BN254_Snarks but no low-degree isogeny [skip ci] 2022-04-12 23:40:07 +02:00
Mamy Ratsimbazafy 65eedd1cf7
Hash-to-Curve BLS12-381 G1 (#189)
* Skeleton of hash to curve for BLS12-381 G1

* Remove isodegree parameter

* Fix polynomial evaluation of hashToG1

* Optimize hash_to_curve and add bench for hash to G1

* slight optim of jacobian isomap + v7 test vectors
2022-04-11 00:57:16 +02:00
Mamy Ratsimbazafy bde4f97b56
Line refactor (#188)
* Align line evaluations to papers notations

* Adjust line fusion op

* precompute G2 b' for costly D-Twists
2022-04-04 10:10:36 +02:00
Mamy Ratsimbazafy 742cecce08
Poly1305 Message Authentication Code (#186)
* Groundwork for Poly1305 MAC

* Implement fast reduction for Poly1305

* don't import assembly files when compiling without assembly
2022-03-05 23:39:24 +01:00
Mamy Ratsimbazafy c2eb42b769
Add ChaCha20 stream cipher 2022-03-02 01:18:47 +01:00