Mamy André-Ratsimbazafy
23ecb9a221
Add a (failing) test vs GMP for modular multiplication on BN254 curve Field
2020-02-16 02:20:08 +01:00
Mamy André-Ratsimbazafy
10346d83a4
Benchmark: BigInt -> Montgomery conversion:
...
- shlAddMod (with assembly division) is already 4x slower than Montgomery Multiplication based.
- constant-time division will be even slower
- use montgomery-multiplication based conversion
2020-02-16 01:43:17 +01:00
Mamy André-Ratsimbazafy
bd1430157f
Add BLS12-381 curve:
...
- don't create "Mod" in curve parser: compile-time type incompatibility
- don't use "Mod" in const sections: compile-time type incompat --> create a macro to get montgomery magics instead of a const array
2020-02-16 00:44:01 +01:00
Mamy André-Ratsimbazafy
05a2c6a34b
Properly precompute the montomery cosntants at compile-time and store them in ROM
2020-02-15 20:43:38 +01:00
Mamy André-Ratsimbazafy
4970572393
Introduce alternate conversion to Montgomery Residue based on Montgomery Multiplication
2020-02-15 19:22:40 +01:00
Mamy André-Ratsimbazafy
e2333dce3c
Terminology nres -> mres, montgomeryResidue, montyResidue
2020-02-15 16:11:17 +01:00
Mamy André-Ratsimbazafy
d3ad4acb3a
Do less in curve generator macro:
...
- no more monty magic "negInvModWord"
- no public "matchingBigInt"
Improve comment on Montgomery procedures
2020-02-15 13:56:13 +01:00
Mamy André-Ratsimbazafy
398b871c4f
Reorg the repo to introduce prepare for introducing the R² (mod p) magic constant
2020-02-15 13:13:01 +01:00
Mamy André-Ratsimbazafy
eb94c3d1bc
Add Montgomery Modular Multiplication
2020-02-15 02:59:08 +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
f418e08746
For finite fields, we will use the Montgomery n-residue form by default
2020-02-14 13:36:34 +01:00
Mamy André-Ratsimbazafy
f6b229b19c
Modular addition and substraction tests
2020-02-13 00:11:45 +01:00
Mamy André-Ratsimbazafy
4cac44358f
Update security level of BN254 to ~100bits
2020-02-13 00:11:04 +01:00
Mamy André-Ratsimbazafy
3eb22f8fc7
Fix curve parser, implement smoke test for finite field
2020-02-12 23:57:51 +01:00
Mamy André-Ratsimbazafy
6226d86726
Update IO: dumpHex -> toHex dumpRawUint -> serializeRawUint
2020-02-12 21:57:39 +01:00
Mamy André-Ratsimbazafy
343399ba1c
Remove TODO comment about bound checking, UncheckedArray in the raw API are not bound checked
2020-02-12 00:33:12 +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
fe59efb8d8
reorganize the repo
2020-02-12 00:20:31 +01:00
Mamy André-Ratsimbazafy
28c9c472b3
Fix generated code duplication due to templates
2020-02-11 14:28:21 +01:00
Mamy André-Ratsimbazafy
2a438653a8
Don't emit useless inline C functions
2020-02-11 12:42:24 +01:00
Mamy André-Ratsimbazafy
24b0477ad7
Typo when testing for "negative" bigint, now passing testing vs GMP
2020-02-10 23:56:57 +01:00
Mamy André-Ratsimbazafy
b53f203e30
Fix raw uint serialization and start testing against GMP for 2000+bits bigints
2020-02-10 23:09:32 +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
73b71a184c
Fix off-by-one copy, pass small bigints modulo tests
2020-02-10 19:57:35 +01:00
Mamy André-Ratsimbazafy
b689223cf5
Refactoring, optimize code-size: use type-erased views to avoid monomorphization of compute kernels
2020-02-10 18:16:34 +01:00
Mamy André-Ratsimbazafy
ade919b003
Fix carry and modulus offset in bigint
2020-02-10 02:58:37 +01:00
Mamy André-Ratsimbazafy
3033ae30f8
Fix uint32 extended precision multiplication
2020-02-10 02:12:44 +01:00
Mamy André-Ratsimbazafy
30f8756dfc
Temp switch to uint32 words for testing modulo. Remove tests that depend on word size
2020-02-10 00:16:46 +01:00
Mamy André-Ratsimbazafy
166a1075b1
add bigint display in GMP test
2020-02-09 23:26:39 +01:00
Mamy André-Ratsimbazafy
08ed81af34
Don't forget to exit when dumpingraw integer
2020-02-09 23:05:23 +01:00
Mamy André-Ratsimbazafy
a389e5c38c
in-place add/sub fix + Add note that native x86 division is flawed:
...
SIGFPE on quotient that don't fit in a word size
2020-02-09 23:00:21 +01:00
Mamy André-Ratsimbazafy
216ed9bdc1
Property-based testing framework vs GMP
2020-02-09 22:01:01 +01:00
Mamy André-Ratsimbazafy
f2c79ece26
Remove the limitation that the number of bits in constructed has to be greater than the source integer bitsize
2020-02-09 21:35:23 +01:00
Mamy André-Ratsimbazafy
66c0b5805e
Add modular reduce / bigint mod from 2 arbitrarily size bigint
2020-02-09 18:17:32 +01:00
Mamy André-Ratsimbazafy
514715dff0
Allow muxing / cmov on bools
2020-02-09 17:49:38 +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
57ee2cb6bd
Fix inline assembly comments breaking build
2020-02-09 15:53:21 +01:00
Mamy André-Ratsimbazafy
b9a37825a3
COnsistent IO API between fromRawUint and fromHex and add fromUint
2020-02-09 15:38:30 +01:00
Mamy André-Ratsimbazafy
1d92ab1f48
Remove the limb accessor templates, introduce config file for debug template
2020-02-09 13:02:09 +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
Mamy André-Ratsimbazafy
edd728610c
Add addition limbs carry test
2020-02-08 19:09:20 +01:00
Mamy André-Ratsimbazafy
2c750cbc5b
Add bigint isZero, and equality and initial tests
2020-02-08 18:50:01 +01:00
Mamy André-Ratsimbazafy
3034c07525
fromHex supports space and underscores
2020-02-08 18:22:19 +01:00
Mamy André-Ratsimbazafy
706678d2ee
Compiler enforced no exceptions
2020-02-08 18:21:47 +01:00
Mamy André-Ratsimbazafy
8da9e20ebb
Cosmetic changes: dumpHex with 0x prefix, montgomery magic part of curve param
2020-02-08 17:03:30 +01:00
Mamy André-Ratsimbazafy
18625cc5ac
Allow compilation of FInite Field and Montgomery domain, workaround showstopper bug: https://github.com/nim-lang/Nim/issues/11142 and #5
2020-02-08 15:33:05 +01:00
Mamy André-Ratsimbazafy
bd2b10817e
Add curve configuration + BN254 config (zkSnarks, ZCash, Ethereum 1 precompile)
2020-02-08 14:55:49 +01:00
Mamy André-Ratsimbazafy
f18a958d5e
Support 1.0+ int128 (can't use magic for bitnot)
2020-02-08 13:28:43 +01:00
Mamy André-Ratsimbazafy
8229bf384b
Remove specialization for static big int. They will be stored in the binary bss section and passed as ptr + length to save on codesize anyway.
2020-02-08 11:51:17 +01:00