Skip to content

Commit e879869

Browse files
plotskogwqisislovecruft
authored andcommitted
Merge branch 'release/0.9.0'
2 parents aeebd3b + b5f87b5 commit e879869

12 files changed

+353
-62
lines changed

.travis.yml

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ rust:
66
- nightly
77

88
env:
9-
- TEST_COMMAND=test FEATURES=--features="yolocrypto"
10-
- TEST_COMMAND=test FEATURES=--features="yolocrypto serde"
11-
- TEST_COMMAND=test FEATURES=--features="yolocrypto nightly"
12-
- TEST_COMMAND=bench FEATURES=--features="yolocrypto bench"
13-
- TEST_COMMAND=bench FEATURES=--features="yolocrypto nightly bench"
14-
- TEST_COMMAND=build FEATURES=--no-default-features
9+
- TEST_COMMAND=test EXTRA_FLAGS='' FEATURES='yolocrypto'
10+
- TEST_COMMAND=test EXTRA_FLAGS='' FEATURES='yolocrypto serde'
11+
- TEST_COMMAND=test EXTRA_FLAGS='' FEATURES='yolocrypto nightly'
12+
- TEST_COMMAND=bench EXTRA_FLAGS='' FEATURES='yolocrypto bench'
13+
- TEST_COMMAND=bench EXTRA_FLAGS='' FEATURES='yolocrypto nightly bench'
14+
- TEST_COMMAND=build EXTRA_FLAGS=--no-default-features FEATURES=''
1515

1616
matrix:
1717
exclude:
@@ -20,23 +20,23 @@ matrix:
2020
# run benchmarks, which causes dalek not to build on stable. See
2121
# https://github.com/isislovecruft/curve25519-dalek/pull/38#issuecomment-286027562
2222
- rust: stable
23-
env: TEST_COMMAND=bench FEATURES=--features="yolocrypto bench"
23+
env: TEST_COMMAND=bench EXTRA_FLAGS='' FEATURES='yolocrypto bench'
2424
- rust: beta
25-
env: TEST_COMMAND=bench FEATURES=--features="yolocrypto bench"
25+
env: TEST_COMMAND=bench EXTRA_FLAGS='' FEATURES='yolocrypto bench'
2626
- rust: stable
27-
env: TEST_COMMAND=bench FEATURES=--features="yolocrypto nightly bench"
27+
env: TEST_COMMAND=bench EXTRA_FLAGS='' FEATURES='yolocrypto nightly bench'
2828
- rust: beta
29-
env: TEST_COMMAND=bench FEATURES=--features="yolocrypto nightly bench"
29+
env: TEST_COMMAND=bench EXTRA_FLAGS='' FEATURES='yolocrypto nightly bench'
3030
# Test nightly features, such as radix_51, only on nightly.
3131
- rust: stable
32-
env: TEST_COMMAND=test FEATURES=--features="yolocrypto nightly"
32+
env: TEST_COMMAND=test EXTRA_FLAGS='' FEATURES='yolocrypto nightly'
3333
- rust: beta
34-
env: TEST_COMMAND=test FEATURES=--features="yolocrypto nightly"
34+
env: TEST_COMMAND=test EXTRA_FLAGS='' FEATURES='yolocrypto nightly'
3535
# Test no_std only on nightly.
3636
- rust: stable
37-
env: TEST_COMMAND=build FEATURES=--no-default-features
37+
env: TEST_COMMAND=build EXTRA_FLAGS=--no-default-features FEATURES=''
3838
- rust: beta
39-
env: TEST_COMMAND=build FEATURES=--no-default-features
39+
env: TEST_COMMAND=build EXTRA_FLAGS=--no-default-features FEATURES=''
4040

4141
script:
42-
- cargo $TEST_COMMAND $FEATURES
42+
- cargo $TEST_COMMAND --features="$FEATURES" $EXTRA_FLAGS

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "curve25519-dalek"
3-
version = "0.8.1"
3+
version = "0.9.0"
44
authors = ["Isis Lovecruft <[email protected]>",
55
"Henry de Valence <[email protected]>"]
66
readme = "README.md"

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
# curve25519-dalek ![](https://img.shields.io/crates/v/curve25519-dalek.svg) ![](https://docs.rs/curve25519-dalek/badge.svg) ![](https://travis-ci.org/isislovecruft/curve25519-dalek.svg?branch=master)
2+
# curve25519-dalek [![](https://img.shields.io/crates/v/curve25519-dalek.svg)](https://crates.io/curve25519-dalek) [![](https://docs.rs/curve25519-dalek/badge.svg)](https://docs.rs/curve25519-dalek) [![](https://travis-ci.org/isislovecruft/curve25519-dalek.svg?branch=master)](https://travis-ci.org/isislovecruft/curve25519-dalek)
33

44
**A low-level cryptographic library for point, group, field, and scalar
55
operations on a curve isomorphic to the twisted Edwards curve defined by -x²+y²
@@ -44,7 +44,7 @@ Extensive documentation is available [here](https://docs.rs/curve25519-dalek).
4444
To install, add the following to the dependencies section of your project's
4545
`Cargo.toml`:
4646

47-
curve25519-dalek = "^0.8"
47+
curve25519-dalek = "^0.9"
4848

4949
Then, in your library or executable source, add:
5050

@@ -57,7 +57,6 @@ fast.
5757
## TODO
5858

5959
* Implement hashing to a point on the curve (Elligator).
60-
* Maybe use serde for serialization.
6160
* Make a new `mask` type in `subtle.rs` and return that instead of `u8`s.
6261
* Implement all utilities in Golang's `crypto/subtle` package, and
6362
move the module to its own crate.

fuzz/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
target
3+
corpus
4+
artifacts

fuzz/Cargo.toml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
[package]
3+
name = "curve25519-dalek-fuzz"
4+
version = "0.0.1"
5+
authors = ["Automatically generated"]
6+
publish = false
7+
8+
[package.metadata]
9+
cargo-fuzz = true
10+
11+
[dependencies.curve25519-dalek]
12+
path = ".."
13+
features = ["yolocrypto"]
14+
15+
[dependencies.libfuzzer-sys]
16+
git = "https://github.com/rust-fuzz/libfuzzer-sys.git"
17+
18+
# Prevent this from interfering with workspaces
19+
[workspace]
20+
members = ["."]
21+
22+
[[bin]]
23+
name = "decaf"
24+
path = "fuzzers/decaf.rs"

fuzz/fuzzers/decaf.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#![no_main]
2+
#[macro_use] extern crate libfuzzer_sys;
3+
extern crate curve25519_dalek;
4+
5+
use curve25519_dalek::curve::ValidityCheck;
6+
use curve25519_dalek::decaf::DecafPoint;
7+
use curve25519_dalek::field::FieldElement;
8+
9+
fuzz_target!(|data: &[u8]| {
10+
if data.len() != 32 {
11+
return;
12+
}
13+
let mut field_bytes = [0u8; 32];
14+
for (by, data) in field_bytes.iter_mut().zip(data.iter()) {
15+
*by = *data;
16+
}
17+
let fe = FieldElement::from_bytes(&field_bytes);
18+
let p = DecafPoint::elligator_decaf_flavour(&fe);
19+
assert!(p.0.is_valid());
20+
p.compress();
21+
});

src/constants.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,23 @@ pub const a_minus_d: FieldElement = FieldElement([
5555
8787816, 6275908, 3247719, 18696448, 12055116, ]);
5656
#[cfg(feature="radix_51")]
5757
pub const a_minus_d: FieldElement = FieldElement([1321844580190025, 1785434093556034, 589740348686294, 217950738957124, 809005158844672]);
58+
#[cfg(feature="radix_51")]
59+
pub const invsqrt_a_minus_d: FieldElement = FieldElement([
60+
278908739862762, 821645201101625, 8113234426968, 1777959178193151, 2118520810568447
61+
]);
62+
#[cfg(not(feature="radix_51"))]
63+
pub const invsqrt_a_minus_d: FieldElement = FieldElement([
64+
6111485, 4156064, -27798727, 12243468, -25904040,
65+
120897, 20826367, -7060776, 6093568, -1986012
66+
]);
67+
#[cfg(feature="radix_51")]
68+
pub const inv_a_minus_d: FieldElement = FieldElement([
69+
2251799813563563, 2251799813685247, 2251799813685247, 2251799813685247, 2251799813685247
70+
]);
71+
#[cfg(not(feature="radix_51"))]
72+
pub const inv_a_minus_d: FieldElement = FieldElement([
73+
-121666, 0, 0, 0, 0, 0, 0, 0, 0, 0
74+
]);
5875

5976
/// (p-1)/2, in little-endian bytes.
6077
pub const HALF_P_MINUS_1_BYTES: [u8; 32] =
@@ -3247,5 +3264,10 @@ mod test {
32473264
let a = FieldElement::minus_one();
32483265
let a_minus_d = &a - &constants::d;
32493266
assert_eq!(a_minus_d, constants::a_minus_d);
3267+
let (_, invsqrt_a_minus_d) = constants::a_minus_d.invsqrt();
3268+
assert_eq!(invsqrt_a_minus_d, constants::invsqrt_a_minus_d);
3269+
let inv_a_minus_d = invsqrt_a_minus_d.square();
3270+
assert_eq!(inv_a_minus_d, constants::inv_a_minus_d);
3271+
assert_eq!(&inv_a_minus_d * &a_minus_d, FieldElement::one());
32503272
}
32513273
}

src/curve.rs

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,14 @@ use collections::Vec;
8383
use core::fmt::Debug;
8484
use core::iter::Iterator;
8585
use core::ops::{Add, Sub, Neg};
86+
use core::ops::{AddAssign, SubAssign};
8687
use core::ops::{Mul, MulAssign};
8788
use core::ops::Index;
8889

8990
use constants;
9091
use field::FieldElement;
9192
use scalar::Scalar;
92-
use subtle::arrays_equal_ct;
93+
use subtle::arrays_equal;
9394
use subtle::bytes_equal_ct;
9495
use subtle::CTAssignable;
9596
use subtle::CTEq;
@@ -517,8 +518,8 @@ impl CTAssignable for ExtendedPoint {
517518

518519
impl CTEq for ExtendedPoint {
519520
fn ct_eq(&self, other: &ExtendedPoint) -> u8 {
520-
arrays_equal_ct( self.compress_edwards().as_bytes(),
521-
other.compress_edwards().as_bytes())
521+
arrays_equal( self.compress_edwards().as_bytes(),
522+
other.compress_edwards().as_bytes())
522523
}
523524
}
524525

@@ -802,13 +803,29 @@ impl<'a,'b> Add<&'b ExtendedPoint> for &'a ExtendedPoint {
802803
}
803804
}
804805

806+
impl<'b> AddAssign<&'b ExtendedPoint> for ExtendedPoint {
807+
fn add_assign(&mut self, _rhs: &'b ExtendedPoint) {
808+
*self = (self as &ExtendedPoint) + _rhs;
809+
}
810+
}
811+
805812
impl<'a,'b> Sub<&'b ExtendedPoint> for &'a ExtendedPoint {
806813
type Output = ExtendedPoint;
807814
fn sub(self, other: &'b ExtendedPoint) -> ExtendedPoint {
808815
(self - &other.to_projective_niels()).to_extended()
809816
}
810817
}
811818

819+
impl<'b> SubAssign<&'b ExtendedPoint> for ExtendedPoint {
820+
fn sub_assign(&mut self, _rhs: &'b ExtendedPoint) {
821+
*self = (self as &ExtendedPoint) - _rhs;
822+
}
823+
}
824+
825+
// ------------------------------------------------------------------------
826+
// Negation
827+
// ------------------------------------------------------------------------
828+
812829
impl<'a> Neg for &'a ExtendedPoint {
813830
type Output = ExtendedPoint;
814831

@@ -1654,6 +1671,18 @@ mod bench {
16541671
use super::*;
16551672
use super::test::{A_SCALAR};
16561673

1674+
#[bench]
1675+
fn edwards_decompress(b: &mut Bencher) {
1676+
let B = &constants::BASE_CMPRSSD;
1677+
b.iter(|| B.decompress().unwrap());
1678+
}
1679+
1680+
#[bench]
1681+
fn edwards_compress(b: &mut Bencher) {
1682+
let B = &constants::ED25519_BASEPOINT;
1683+
b.iter(|| B.compress_edwards());
1684+
}
1685+
16571686
#[bench]
16581687
fn basepoint_mult(b: &mut Bencher) {
16591688
let B = &constants::ED25519_BASEPOINT_TABLE;

0 commit comments

Comments
 (0)