Commit graph

440 commits

Author SHA1 Message Date
Tony Arcieri
384cf1df31 no_std import cleanups
- Gate no_std on the "std" feature
- Import core when std is present
- Import collections when std is absent
- Add a placeholder gated "use" directive for Box in curve.rs
2017-03-08 00:19:08 -08:00
Henry de Valence
ab6d32efe1 Make functions pub to suppress dead code warnings 2017-03-07 23:03:48 -08:00
Henry de Valence
0e9dc1d38d Remove warnings about unused variables
These bindings are shadowed by the later let statements, so they're considered unused.
2017-03-07 23:01:49 -08:00
Henry de Valence
3f208359b3 Merge branch 'feature/test-reorg' into develop 2017-03-07 22:20:22 -08:00
Henry de Valence
b61ed818b8 Remove all remaining warnings 2017-03-07 01:37:31 -08:00
Henry de Valence
913e699145 Rename Decaf tests 2017-03-07 01:28:38 -08:00
Henry de Valence
e446bc8a1f The identity point is already in EIGHT_TORSION 2017-03-07 00:58:32 -08:00
Henry de Valence
cf24cb8900 Also test points that are not the identity 2017-03-07 00:58:32 -08:00
Henry de Valence
47143e9114 Rewrite conditional assignment test for AffineNielsPoints 2017-03-07 00:58:32 -08:00
Henry de Valence
9414a2f4db Remove old tests that aren't so useful any more 2017-03-07 00:49:21 -08:00
Henry de Valence
78fe9c490d Eliminate BASE_CMPRSSD or rename it to constants::BASE_CMPRSSD and do misc cleanup 2017-03-07 00:48:36 -08:00
Henry de Valence
94416eb1cb Clean decompression_sign_handling 2017-03-07 00:11:47 -08:00
Henry de Valence
b5b0ac7628 Add doc comments to test vectors 2017-03-07 00:11:16 -08:00
Henry de Valence
0585af6c68 Move sqrt(-(A+2)) test to constants.rs 2017-03-07 00:03:59 -08:00
Henry de Valence
3a9ee16a30 Remove test_ prefix from test functions in curve.rs 2017-03-06 23:59:49 -08:00
Henry de Valence
31c350b6f2 Split benchmarks into their own module 2017-03-06 23:53:38 -08:00
Isis Lovecruft
9f0c6c86f3
Change another unittest compress() to compress_edwards(). 2017-03-07 01:33:38 +00:00
Henry & Isis
e5f5dea444 Rename to_{cached,precomputed} to to_{projective,affine}_niels 2017-03-05 15:27:26 -08:00
Isis Lovecruft
9171a03894
Merge branch 'feature/rename-compress' into develop 2017-03-04 05:52:57 +00:00
Isis Lovecruft
b81f84bee8
Merge branch 'feature/montgomery-x-format_r1' into develop 2017-03-04 05:48:12 +00:00
Isis Lovecruft
2c83d48cfa
Demote a docstring note to inline code comment to avoid confusing users. 2017-03-04 05:29:19 +00:00
Isis Lovecruft
20ace8da48
Rename compress() to compress_edwards(). 2017-03-04 03:41:47 +00:00
Isis Lovecruft
cfd0e8ad6e
Add method for recovery of Edwards x-coordinate given Montgomery (u, v).
This function is necessary for matching Signal's hash_to_point() behaviour.
2017-03-04 03:39:58 +00:00
Isis Lovecruft
b9de92aeaf
Add benchmarks for Edwards-Y and Mongomery-U decompression. 2017-03-04 03:39:57 +00:00
Isis Lovecruft
915f41c643
Fixup CompressedMontgomeryU::decompress() and ensure no divide-by-zeroes.
Also, match Signal behaviour, and split off recovery of other
coordinates into separate functions.
2017-03-04 03:39:56 +00:00
Isis Lovecruft
5edd8d6d26
Merge remote-tracking branch 'hdevalence/feature/montgomery-x-format_r1' into develop 2017-03-04 02:40:17 +00:00
Isis Lovecruft
1c9637490c
Obsessive whitespace fix. 2017-03-04 02:00:59 +00:00
Henry de Valence
5d3d114628 fixup! Properly handle exceptional points. 2017-02-27 23:15:39 -08:00
Isis Lovecruft
f48947fb57
Merge remote-tracking branch 'hdevalence/feature/some-cleanup-tweaks' into develop 2017-02-28 05:50:22 +00:00
Henry de Valence
db53b58e89 Properly handle exceptional points. 2017-02-27 21:13:24 -08:00
Henry de Valence
19d452c2dc Test decompressing an invalid montgomery point 2017-02-27 13:42:13 -08:00
Henry de Valence
45fbcb45f6 First notes and code on Montgomery conversion 2017-02-27 13:41:50 -08:00
Henry de Valence
fe15bc1d0b Add note on fn main() in doctest 2017-02-27 11:22:07 -08:00
Henry de Valence
a93798d209 Add a function to hash a byte slice to a scalar. 2017-02-27 11:19:06 -08:00
Henry de Valence
e5c0d789fd Add a Scalar::as_bytes() method. 2017-02-26 15:25:05 -08:00
Henry de Valence
950519b97b Implement Debug for Scalar 2017-02-26 15:25:05 -08:00
Henry de Valence
1dac2f53bb Implement Identity for CompressedEdwardsY 2017-02-26 15:25:05 -08:00
Henry de Valence
f39566cf16 Change CompressedDecaf::to_bytes to ::as_bytes 2017-02-26 15:25:05 -08:00
Henry de Valence
2cef5fcecd Add CompressedEdwardsY::as_bytes 2017-02-26 15:25:05 -08:00
Isis Lovecruft
e6b7192d5e
Merge branch 'feature/rename-niels-point' into develop 2017-02-25 01:26:33 +00:00
Isis Lovecruft
a649ea38ee
Rename {PreComputed,Cached}Point → {Affine,Projective}NielsPoint.
* FIXES Issue #28: https://github.com/isislovecruft/curve25519-dalek/issues/28
2017-02-25 00:47:06 +00:00
Henry de Valence
d450659b7f Rewrite CompressedEdwardsY::decompress() to use FieldElement::sqrt_ratio 2017-02-22 20:59:51 -08:00
Henry de Valence
1febf3f753 Add an invsqrt_ratio function. 2017-02-22 20:59:50 -08:00
Henry de Valence
a202f36916 Rewrite invsqrt to avoid using an Option type. 2017-02-22 16:24:11 -08:00
Isis Lovecruft
74feb0db75
Merge remote-tracking branch 'hdevalence/feature/decaf_r15' into develop 2017-02-22 05:30:18 +00:00
Isis Lovecruft
ff28cacd13
Enable std and std macros during test builds. 2017-02-22 03:07:57 +00:00
Henry de Valence
f93dd4ccf5 Use is_identity() in the torsion subgroup tests.
ht @dconnolly for pointing this out
2017-02-21 15:13:18 -08:00
Henry de Valence
9473299d04 Add benchmarks for Decaf [de]compression 2017-02-21 14:59:25 -08:00
Henry de Valence
dd8f17dfb3 Add note on feature-gating 2017-02-21 13:43:10 -08:00
Henry de Valence
95bf09a335 Check xy is nonnegative, y nonzero in decoding. 2017-02-21 13:43:09 -08:00
Henry de Valence
5daa217b18 Fix sign error 2017-02-21 13:43:09 -08:00
Henry de Valence
6b3dbf6870 Add another test and some notes 2017-02-21 13:43:09 -08:00
Henry de Valence
93be83c6df Check that s = |s| in decompression. 2017-02-21 13:43:09 -08:00
Henry de Valence
9cb48c44ba Use conditional_negate in Decaf 2017-02-21 13:43:03 -08:00
Henry & Isis
c2bee88c0f Add a feature gate for unfinished implementations. 2017-02-21 13:39:01 -08:00
Henry & Isis
ea5efcdc29 Add impl of Identity for DecafPoint and CompressedDecaf 2017-02-21 13:39:00 -08:00
Henry & Isis
f06afbc493 Add a coset4 function for debugging 2017-02-21 13:39:00 -08:00
Henry & Isis
375d326e75 Change some tests to use new API 2017-02-21 13:39:00 -08:00
Henry & Isis
db17dc4b78 Add Eq implementation for DecafPoint 2017-02-21 13:39:00 -08:00
Henry & Isis
bf19df64f0 Add ScalarMult and BasepointMult impls for DecafPoint 2017-02-21 13:39:00 -08:00
Henry & Isis
084c29c4ed Implement addition and subtraction for DecafPoint. 2017-02-21 13:39:00 -08:00
Henry & Isis
f52e2ee37e Create BasepointMult and ScalarMult traits. 2017-02-21 13:38:59 -08:00
Henry de Valence
66e598a47c Minor doc tweaks 2017-02-21 13:38:59 -08:00
Henry de Valence
0992237233 XY is a misleading variable name, use T instead 2017-02-21 13:38:59 -08:00
Henry de Valence
ec82e7a4f4 Create a DecafPoint struct, wrapping an ExtendedPoint 2017-02-21 13:38:59 -08:00
Henry de Valence
08fc10f356 Rename DecafPoint -> CompressedDecaf 2017-02-21 13:38:59 -08:00
Henry de Valence
eec7747be7 Move Decaf code to decaf.rs 2017-02-21 13:38:59 -08:00
Henry de Valence
f18ebe9430 First draft of decaf decompression 2017-02-21 13:38:58 -08:00
Henry de Valence
a415caa9fb Add a seperate invsqrt function.
This code isn't constant-time, but maybe should be.  However that would
prevent a bunch of nice things (e.g., Option types).  Probably good to
think about this.
2017-02-21 13:38:58 -08:00
Henry de Valence
ee5958c407 Add is_[non]negative_decaf functions.
Computes whether a point is nonnegative in the same way as Mike Hamburg's code.
2017-02-21 13:37:50 -08:00
Henry de Valence
3fc5f75300 Rename is_negative to is_negative_ed25519 2017-02-21 13:23:57 -08:00
Henry de Valence
5720e249ab Add constants for points of the eight-torsion subgroup. 2017-02-21 13:23:57 -08:00
Henry de Valence
ee5ea0a013 Make double functions public 2017-02-21 13:23:11 -08:00
Henry de Valence
dd23a48ade Make ExtendedPoint attrs pub as we need them in constants.rs 2017-02-21 13:23:11 -08:00
Henry de Valence
82041c2c67 Add constant for bytes of (p-1)/2. 2017-02-21 13:23:11 -08:00
Henry de Valence
363ea405d4 Add constant for a-d = -1-d 2017-02-21 13:23:11 -08:00
Henry de Valence
6fd3028956 Add constant for 4*d 2017-02-21 13:23:10 -08:00
Henry de Valence
fb0c431184 Add constant for MSQRT_M1, equal to -SQRT_M1 2017-02-21 13:23:10 -08:00
Henry de Valence
e1feb653be Add constant value of 1/2 (mod p) 2017-02-21 13:23:10 -08:00
Henry de Valence
79afc6bd0f Add debugging checks to test if points are on the curve 2017-02-21 13:23:10 -08:00
Henry de Valence
cb4ff3097c Add FieldElement::is_zero() 2017-02-21 13:23:10 -08:00
Isis Lovecruft
44e7d500db
Remove unused import of PartialEq and Eq in curve module. 2017-02-21 21:01:58 +00:00
Isis Lovecruft
e4d041836e
Move load3 and load4 to new utils module and remove #[allow(dead_code)]. 2017-02-21 06:15:08 +00:00
Isis Lovecruft
4b738c7e19
Remove #[allow(dead_code)] from arrays_equal_ct(). 2017-02-21 06:06:16 +00:00
Isis Lovecruft
6f67a7d716
Rename util module to subtle.
* CHANGE subtle module documentation slightly to clarify the module's purpose.
 * FIXES issue #25.
2017-02-21 06:01:22 +00:00
Isis Lovecruft
3eb5dcaae7
Implement CTEq for ExtendedPoint. 2017-02-21 05:45:37 +00:00
Isis Lovecruft
b1afdf5204
Implement CTEq for FieldElement. 2017-02-21 05:44:35 +00:00
Isis Lovecruft
5308fef210
Add CTEq trait and implement it for Scalar. 2017-02-21 05:44:35 +00:00
Isis Lovecruft
1381e07ffb
Implement a method for determining if an element is the identity.
This corresponds to ge_isneutral() in Open Whispersystems' ed25519 library.
2017-02-21 05:43:20 +00:00
Isis Lovecruft
03589dff43
Add method for determining if an ExtendedPoint is of small order. 2017-02-21 05:41:16 +00:00
Isis Lovecruft
7b57be69fd
Implement constant time equality check for scalars. 2017-02-21 05:41:14 +00:00
Isis Lovecruft
32da4c7d50
Implement Neg for Scalar. 2017-02-21 05:41:14 +00:00
Isis Lovecruft
51f59565f5
Typo fix; Negateable → Negatable.
* Fixup on #22.
2017-02-21 04:15:15 +00:00
Isis Lovecruft
9154e59ec1
Merge remote-tracking branch 'hdevalence/feature/conditional-negation' into develop 2017-02-21 04:13:29 +00:00
Isis Lovecruft
8c432ef78a
Another obsessive compulsive whitespace fix. 2017-02-21 01:46:01 +00:00
Henry de Valence
dc5621f527 Use conditional_negate in select_precomputed_point 2017-02-20 15:30:59 -08:00
Henry de Valence
8a1c13ef49 Make a CTNegateable trait with a generic impl for better ergonomics 2017-02-20 15:30:59 -08:00
Henry de Valence
5f4de0074d Add a conditional negation function. 2017-02-20 15:30:59 -08:00
Isis Lovecruft
57884ecefa
Merge remote-tracking branch 'hdevalence/feature/derive-eq-partialeq-compressededwardsy' into develop 2017-02-20 02:14:37 +00:00
Isis Lovecruft
5f70ab55f8
Obsessive compulsive whitespace fix. 2017-02-20 01:58:56 +00:00
Henry de Valence
eaa5d3e595 Derive Eq, PartialEq for CompressedEdwardsY 2017-02-19 17:39:48 -05:00
Isis Lovecruft
1e7199dcc4
Remove now unused core::clone::Clone from scalar. 2017-01-27 02:16:30 +00:00
Isis Lovecruft
366e9029bf
Rename a CompressedPoint from #17 to CompressedEdwardsY (from #6). 2017-01-27 02:15:31 +00:00
Isis Lovecruft
d88b6c01c4
Merge remote-tracking branch 'tarcieri/no-std' into develop 2017-01-27 02:13:04 +00:00
Isis Lovecruft
d4cccbc4d8
Whitespace cleanup in constants module. 2017-01-27 01:38:56 +00:00
Isis Lovecruft
0c14f58797
Merge remote-tracking branch 'burdges/patch-1' into develop 2017-01-27 00:40:32 +00:00
Isis Lovecruft
8c986fb3da
Allow non-snakecase in constants.
We follow the standard mathematical naming convention of lowercase to
denote affine coordinates and uppercase to for projective.
2017-01-27 00:34:38 +00:00
Isis Lovecruft
3f900e60bd
Change CompressedPoint in constants module to CompressedEdwardsY. 2017-01-27 00:33:59 +00:00
Isis Lovecruft
1d964fa4b7
Merge remote-tracking branch 'hdevalence/feature/seperate-constants-file' into develop 2017-01-27 00:15:31 +00:00
Jeff Burdges
b96281ab12 Link needs http://www. 2017-01-23 00:29:02 -05:00
Isis Lovecruft
39f417f75e
Merge remote-tracking branch 'hdevalence/feature/move-ct-traits' into develop 2017-01-20 21:51:19 +00:00
Isis Lovecruft
6d2ab84d38
Merge remote-tracking branch 'hdevalence/feature/add-mult-cofactor-fn' into develop 2017-01-19 23:37:50 +00:00
Isis Lovecruft
761ef304d4
Merge remote-tracking branch 'hdevalence/feature/rename-compressed-point' into develop 2017-01-19 23:33:58 +00:00
Tony Arcieri
d08bc7395e Add #![no_std] (fixes #16)
Use ::core in lieu of ::std, allowing this crate to be usable in #![no_std]
environments.

Gates features that presently depend on ::std (presently just rand) behind a
"std" cargo feature, which is enabled by default.
2017-01-18 15:16:01 -08:00
Henry de Valence
46bf69b80e Test basepoint multiple generation 2017-01-09 16:15:23 -05:00
Henry de Valence
187d4d3c09 Make some conversions public 2017-01-09 16:15:23 -05:00
Henry de Valence
6559e1de37 Derive Eq for PreComputedPoints 2017-01-09 16:15:22 -05:00
Henry de Valence
d94edc6a36 Move compressed basepoint into constants
Would be good to have the basepoint itself, but this doesn't seem possible: the
fields of an ExtendedPoint are not public, so we can't construct them outside
of curve.rs (by design, to prevent constructing invalid points).  Maybe const
fn support could change this.
2017-01-09 16:15:22 -05:00
Henry de Valence
ff9e78572c Add a way to construct precomputed points 2017-01-09 16:15:22 -05:00
Henry de Valence
16b4be6663 Add fixme on SQRT_MINUS_A 2017-01-08 15:11:16 -05:00
Henry de Valence
7ee568780b Shorten docstring on monty A value 2017-01-08 15:11:16 -05:00
Henry de Valence
8a5332b220 Remove unused, incorrect a value
This was presumably added for use with formulas that use two multiplications by
small constants (i.e., 121665 and 121666) instead of one multiplication by a
large constant (i.e., -121665/121666), but we don't use those formulas.
2017-01-08 15:11:16 -05:00
Henry de Valence
8fb9e44dd2 Test that d = -121665/121666 2017-01-08 15:11:16 -05:00
Henry de Valence
3f7d06138a Test that SQRT_M1 is a square root of -1 2017-01-08 15:11:15 -05:00
Henry de Valence
a9e3c330a6 Move constants into its own module 2017-01-08 14:39:25 -05:00
Henry de Valence
63e7e9f8de Implement CTAssignable for Scalar 2017-01-06 12:56:53 -05:00
Henry de Valence
74049e039e Make FieldElement's conditional_assign a trait impl 2017-01-06 12:34:57 -05:00
Henry de Valence
c92ebdd0ac Remove unused conditional_choose function 2017-01-06 12:29:24 -05:00
Henry de Valence
098ff2ffca Move CTAssignable trait to util.rs from curve.rs 2017-01-06 12:26:43 -05:00
Henry de Valence
4a5d7052a9 Add convenience wrapper around mult_by_pow_2 to clear cofactor 2017-01-06 10:47:05 -05:00
Henry de Valence
d1599410ee Rename CompressedPoint -> CompressedEdwardsY
This allows other compression formats (e.g., CompressedMontgomeryX).
2016-12-23 17:50:24 -08:00
Henry de Valence
ef2987349f Add bench for unpacked multiply_add 2016-12-23 13:01:16 -08:00
Henry de Valence
85d4b7e98c Split the Scalar type into Scalar and UnpackedScalar
The Scalar type is stored in memory as an array of bytes.  This allows easy
access to the bits of a scalar for Scalar x Point operations, at the cost of
forcing a pack/unpack for Scalar x Scalar.  This commit splits the Scalar type
into Scalar (packed) and UnpackedScalar (limbs).
2016-12-23 12:49:00 -08:00
Henry de Valence
e2dfa17879 Add fixme on load3/4 as utilities 2016-12-23 10:03:30 -08:00
Isis Lovecruft
c9b0e45afb
Specify the RNG for Scalar::random. 2016-12-14 05:54:22 +00:00
Henry de Valence
c6b1b497b0 Add benchmark for Scalar::random() 2016-12-09 17:45:54 -08:00
Henry de Valence
d8476fe6cf Add a Scalar::random() constructor
This adds a dependency on the `rand` crate, used to construct an
OS-backed CSPRNG.  The implementation in this commit is somewhat
inefficient as it constructs a new OsRng object every time; it might be
better to construct it once.  (Seems like a lot of overhead for a few
getrandom(2) calls...)
2016-12-09 17:38:51 -08:00
Henry de Valence
71bf0d5e53 Remove port of Montgomery conversion from Adam's code
This should be brought back later as part of reworking the compressed
point formats / serialization code.  Right now there's just
"CompressedPoint" which is in the ed25519 format.  Ideally, users should
be able to serialize points to formats used for X25519, for decaf, etc.
and not have to worry too much about the internal model.
2016-12-09 14:49:27 -08:00
Isis Lovecruft
f7972041ab
Fix a typo in lib.rs module documention. 2016-12-08 21:59:52 +00:00
Isis Lovecruft
387a56fe2c
Initial commit. 2016-12-08 05:12:00 +00:00