Commit graph

767 commits

Author SHA1 Message Date
Henry de Valence
d0ea313e99 Remove broken impl Zeroize for FieldElement2625x4.
This implementation is broken because the packed_simd types don't implement `Zeroize`.
2019-10-25 15:38:50 -07:00
Henry de Valence
a79459a1c8
Merge pull request #289 from tarcieri/zeroize
Switch from `clear_on_drop` to `zeroize` (fixes #281)
2019-10-23 20:17:14 -07:00
Tony Arcieri
9480844b8d Switch from clear_on_drop to zeroize (fixes #281)
`zeroize` is WASM-friendly as it has no dependencies on C compilers.

Instead uses Rust's own volatile write semantics and compiler fences to
ensure zeroization is not elided by the compiler.
2019-10-23 16:39:21 -07:00
Henry de Valence
70e46c9826 Fill in missing Serde impl for MontgomeryPoint. 2019-10-23 15:55:03 -07:00
Henry de Valence
0fc534d989 Use "tuples" instead of "bytes" in the Serde datamodel.
This is a breaking change to the serialization format.  It fixes it so that the
Serde encoding can match the conventional encoding of each type of object, and
so that Serde can be used with no overhead -- when using serde-bincode, the
Serde encoding now matches the manual encoding.
2019-10-23 15:40:50 -07:00
Henry de Valence
29ce0d4fe9 Add length checks to serde-bincode tests.
This ensures that the serde Serialize and Deserialize implementations use
fixed-length Serde tuples, rather than variable-length byte arrays.  This flaw
in data modeling was pointed out by Trevor Perrin.
2019-10-23 15:28:48 -07:00
Henry de Valence
620d17ef40
Merge pull request #293 from dalek-cryptography/remove-build-rs
Remove build.rs constants generation.
2019-10-23 14:44:46 -07:00
Henry de Valence
574217694e Remove build.rs.
This was more useful at the time when we were determining, e.g., optimal lookup
table sizes and could regenerate them more easily, but it came at a massive
complexity cost.  It also meant that we were unable to implement backend
autoselection.  This commit removes the `build.rs` entirely.  In the future, a
different `build.rs` could be added that auto-selects a backend, but it seems
like the current default-u64 setup has been working fine.
2019-10-23 14:20:38 -07:00
Isis Lovecruft
019b81aa20
Clarify docs for the choice of sign for MontgomeryPoint.to_edwards(). 2019-10-23 19:49:06 +00:00
Isis Lovecruft
7c5ba69491
Update copyright year. 2019-10-23 19:43:56 +00:00
Isis Lovecruft
028c0b9d4d
Fix typo in 64-bit scalar implementation code comment. 2019-10-23 19:35:57 +00:00
François Garillot
9785f56c0f
Rust fixes for some clippy warnings
Clippy lints with instances in the project but NOT applied here, since they seem consistently at odds with the projects' style:
- [unreadable literal](https://rust-lang.github.io/rust-clippy/master/#unreadable_literal)
- [cast lossless](https://rust-lang.github.io/rust-clippy/master/#cast_lossless)
- [assign op pattern](https://rust-lang.github.io/rust-clippy/master/#assign_op_pattern)
2019-10-05 12:02:08 -07:00
François Garillot
023fdf2a2c
Rust added support for the ? operator on Option in 1.22
This converts a few instances of an early-returning unwrap to it.
2019-10-05 11:44:36 -07:00
Henry de Valence
b01888a929
Merge pull request #260 from fabric-and-ink/ed-decompress-simplify
Remove unneeded check for negativity in edwards point decompression
2019-08-07 12:57:24 -07:00
Fabian Drinck
26ae185bc9
Apply suggestion by @hdevalence
Co-Authored-By: Henry de Valence <hdevalence@hdevalence.ca>
2019-08-07 19:43:10 +02:00
Henry de Valence
cfa09d859f Use upstream IFMA intrinsics now that they exist. 2019-08-06 17:14:31 -07:00
Henry de Valence
4bbcc28cdc
Merge pull request #275 from Pratyush/fix-docs-link-on-avx2
Fix link to AVX2 docs
2019-08-06 17:08:30 -07:00
Pratyush Mishra
912fe4794f Fix link to AVX2 and IFMA docs 2019-08-06 16:53:54 -07:00
Henry de Valence
4bc2ec0082
Merge pull request #276 from dalek-cryptography/quarkslab
Fix issues found in Quarkslab audit
2019-08-06 16:08:23 -07:00
Henry de Valence
68b71578af
Merge pull request #274 from 3for/comment-fix
`curve_models` Comment fix
2019-08-06 16:07:13 -07:00
Henry de Valence
a480844992 Tighten a too-permissive debug_assert in NafLookupTable8.
This issue was found by Laurent Grémy & Nicolas Surbayrole of Quarkslab.
2019-08-06 15:21:06 -07:00
Henry de Valence
90baabe50b Ensure Scalar Add and Sub produce canonical results.
Closes #238.

This issue was discovered independently by both Jack "str4d" Grigg
(issue #238), who noted that reduction was not performed on addition, and
Laurent Grémy & Nicolas Surbayrole of Quarkslab, who noted that it was possible
to cause an overflow and compute incorrect results.
2019-08-06 15:20:19 -07:00
Jack Grigg
a3246d82e5 Tests showing that scalar addition and subtraction don't reduce mod l 2019-08-06 15:18:46 -07:00
root
ccaf86ea86 curve_models link in comment mismatch 2019-08-06 16:40:47 +08:00
Henry de Valence
01d9e904e1 Add a missing wrapping_sub in NAF computation.
Found by @3for; this only affected width-7 NAF computations, which were never
used in the source tree (only width 5, optimal for dynamic cases, and 8, better
for static cases).

Closes #272
2019-08-05 15:56:56 -07:00
root
2a46cd3b20 add non-zero assert in field batch_invert 2019-08-01 15:02:15 +08:00
Henry de Valence
5c18bfb6a7 Update doc(include) paths.
Since https://github.com/rust-lang/rust/pull/60938 the path root changed and
these new paths are required to compile on nightly.

Closes #268.
2019-07-31 14:54:24 -07:00
Daan Sprenkels
e4c086ab59
Fix a typo in AVX2
Last two (least significant) limbs should be `z8`, `z9`. Were probably
copy-paste typos.
2019-07-22 14:17:23 +02:00
Fabian Drinck
53da2aaaf4 Remove unneeded check for negativity in edwards point decompression
The function `FieldElement::sqrt_ratio_i` always returns a positive root
by definition. Therefore the test for negativity in the edwards point
decompression function always returns false and we only need to flip its
sign if `compressed_sign_bit` is set.
2019-06-07 21:04:12 +02:00
Henry de Valence
e17c98a391 Ensure NAF works on manually-constructed extremal values.
The NAF computation can generate a 1 in the last digit (only) when s = 2^255-1,
so someone who manually constructed the value s = 2^255-1 and fed it into a NAF-using
computation could generate an incorrect result.  Some version of this bug has
been present from the beginning of the library, but it has no security content,
because the NAF computations are not applied to secret data, and the error
occurs only on one value which is not constructed by any client caller.
2019-06-05 23:18:43 -07:00
Henry de Valence
389d2bc9e2 Ensure Pippenger works on manually-constructed extremal values.
When using Scalar::from_bits to manually create unreduced Scalars (e.g.,
X/Ed25519 keys with specified bit patterns), it's possible to construct Scalar
values that range up to 2^255-1.  These shouldn't ever end up in a vartime
multiscalar mul call anyways, because it doesn't handle secret data, but it is
technically allowed by the type system and should be handled.  When w=8, these
can generate terminal carries that can't be folded into the last digit, but
this can be handled by folding them into an extra digit instead.
2019-06-05 23:03:07 -07:00
Henry de Valence
5f1d73bca0 Fix a negate-with-overflow edgecase by widening before computation.
This fixes a bug in the Pippenger implementation reported by Fernando Krell and
diagnosed by Oleg Andreev.  The problem is that at the largest problem sizes
(using w=8), the signed digits fill the value range of an i8, and so doing
computation on them to calculate the bucket index can hit an overflow.

This was not caught in CI because the test suite didn't check all problem
sizes; tests for these sizes which expose this bug were added in the previous
commit.
2019-06-05 20:59:07 -07:00
Henry de Valence
6fe93564cd Add a more comprehensive random multiscalar test.
This exercises the constant- and variable- time code at large sizes, to hit
every path of Straus/Pippenger.
2019-06-05 20:54:00 -07:00
Henry de Valence
c084def3a3
Merge pull request #249 from oleganza/oleg/pippenger2
Pippenger multiscalar multiplication algorithm
2019-06-04 15:13:41 -07:00
Henry de Valence
19dcd62053 Add reference to 2012/549 2019-06-04 13:41:43 -07:00
Henry de Valence
5921d6d2ac Replace std::iter with core::iter 2019-06-04 13:36:07 -07:00
Henry de Valence
baaeed23fc
Merge pull request #251 from fabric-and-ink/quench-warning
Quench snake case warning
2019-05-26 20:35:27 -07:00
Fabian Drinck
29dca772a9 Quench snake case warning 2019-05-26 13:03:40 +02:00
Oleg Andreev
eb82a9d8b6
Update src/backend/serial/scalar_mul/pippenger.rs
Co-Authored-By: Henry de Valence <hdevalence@hdevalence.ca>
2019-05-24 18:00:34 -05:00
Oleg Andreev
9836d6622c cleaner name per Henry’s suggestion 2019-05-24 12:18:10 -07:00
Oleg Andreev
ca2926ac89 use one buffer instead of two 2019-05-22 11:48:30 -07:00
Henry de Valence
dfcac0d8e2 rustfmt and copyright fixes 2019-05-22 11:38:52 -07:00
Oleg Andreev
7fba2a1bcc avoid unnecessary allocation 2019-05-22 11:14:26 -07:00
Oleg Andreev
df745e98a2 oops - forgot to switch on pippenger 2019-05-21 14:10:56 -07:00
Oleg Andreev
33b41ac10d fix type conversions 2019-05-21 13:48:29 -07:00
Oleg Andreev
42648aa460 cgs 2019-05-21 13:32:50 -07:00
Oleg Andreev
b52c2053c1 new pippenger radix 6/7/8 implementation 2019-05-21 12:35:58 -07:00
Henry de Valence
e726147af8
Merge pull request #245 from dalek-cryptography/optimize-variable-base
Save 2.5% on variable-base scmul by squeezing some multiplications.
2019-05-21 08:52:53 -07:00
Henry de Valence
23ca520ac2
Merge pull request #226 from ebfull/faster-equality
Check the equality of `EdwardsPoint`s in the projective coordinates
2019-05-21 08:50:32 -07:00
Henry de Valence
6503378fef Save 2.5% on variable-base scmul by squeezing some multiplications.
This saves 4 point doublings by unwrapping the first loop iteration,
as well as 63 field multiplications (one per iteration) by managing
curve model choice explicitly.
2019-05-08 21:04:13 -07:00