Skip to content

Commit 213e9b8

Browse files
committed
Remove rand feature; bump elliptic-curve and ecdsa
Updates to use the `group` crate. See: RustCrypto/traits#287. This crate has a hard `rand_core` dependency so this commit gets rid of the `rand` features across the board and makes them mandatory. (Even if we don't end up shipping the `group` crate this release, that's probably for the best to keep the number of features down) This commit additionally splits out `no_std` build testing into `tests/*_no_std` Cargo projects. This is a workaround until the Cargo resolver is fixed upstream: rust-lang/cargo#7915 rust-lang/cargo#7916
1 parent 089aab4 commit 213e9b8

29 files changed

+156
-76
lines changed

.github/workflows/k256.yml

+14-10
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ name: k256
33
on:
44
pull_request:
55
paths:
6-
- "elliptic-curve-crate/**"
76
- "k256/**"
7+
- "tests/k256_no_std/**"
88
- "Cargo.*"
99
push:
1010
branches: master
@@ -28,6 +28,9 @@ jobs:
2828
target:
2929
- thumbv7em-none-eabi
3030
- wasm32-unknown-unknown
31+
defaults:
32+
run:
33+
working-directory: tests/k256_no_std
3134
steps:
3235
- uses: actions/checkout@v1
3336
- uses: actions-rs/toolchain@v1
@@ -36,13 +39,14 @@ jobs:
3639
toolchain: ${{ matrix.rust }}
3740
target: ${{ matrix.target }}
3841
override: true
39-
- run: cargo build --no-default-features --release --target ${{ matrix.target }}
40-
- run: cargo build --no-default-features --features arithmetic --release --target ${{ matrix.target }}
41-
- run: cargo build --no-default-features --features ecdsa-core --release --target ${{ matrix.target }}
42-
# TODO(tarcieri): use new cargo resolver when stable: https://github.com/rust-lang/cargo/issues/7915
43-
#- run: cargo build --no-default-features --features ecdsa --release --target ${{ matrix.target }}
44-
#- run: cargo build --no-default-features --features rand --release --target ${{ matrix.target }}
45-
- run: cargo build --no-default-features --features sha256 --release --target ${{ matrix.target }}
42+
- run: cargo build --release --target ${{ matrix.target }}
43+
- run: cargo build --release --target ${{ matrix.target }} --features arithmetic
44+
- run: cargo build --release --target ${{ matrix.target }} --features ecdh
45+
- run: cargo build --release --target ${{ matrix.target }} --features ecdsa-core
46+
- run: cargo build --release --target ${{ matrix.target }} --features ecdsa
47+
- run: cargo build --release --target ${{ matrix.target }} --features keccak256
48+
- run: cargo build --release --target ${{ matrix.target }} --features sha256
49+
- run: cargo build --release --target ${{ matrix.target }} --all-features
4650
test:
4751
runs-on: ubuntu-latest
4852
strategy:
@@ -60,6 +64,6 @@ jobs:
6064
- run: cargo test --no-default-features
6165
- run: cargo test
6266
- run: cargo test --all-features
63-
- run: cargo test --features field-montgomery,rand
64-
- run: cargo test --features force-32-bit,rand
67+
- run: cargo test --features field-montgomery
68+
- run: cargo test --features force-32-bit
6569
- run: cargo build --all-features --benches

.github/workflows/p256.yml

+11-8
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ name: p256
33
on:
44
pull_request:
55
paths:
6-
- "elliptic-curve-crate/**"
76
- "p256/**"
7+
- "tests/p256_no_std/**"
88
- "Cargo.*"
99
push:
1010
branches: master
@@ -28,6 +28,9 @@ jobs:
2828
target:
2929
- thumbv7em-none-eabi
3030
- wasm32-unknown-unknown
31+
defaults:
32+
run:
33+
working-directory: tests/p256_no_std
3134
steps:
3235
- uses: actions/checkout@v1
3336
- uses: actions-rs/toolchain@v1
@@ -36,13 +39,13 @@ jobs:
3639
toolchain: ${{ matrix.rust }}
3740
target: ${{ matrix.target }}
3841
override: true
39-
- run: cargo build --no-default-features --release --target ${{ matrix.target }}
40-
- run: cargo build --no-default-features --features arithmetic --release --target ${{ matrix.target }}
41-
- run: cargo build --no-default-features --features ecdsa-core --release --target ${{ matrix.target }}
42-
# TODO(tarcieri): use new cargo resolver when stable: https://github.com/rust-lang/cargo/issues/7915
43-
#- run: cargo build --no-default-features --features rand --release --target ${{ matrix.target }}
44-
#- run: cargo build --no-default-features --features ecdsa --release --target ${{ matrix.target }}
45-
- run: cargo build --no-default-features --features sha256 --release --target ${{ matrix.target }}
42+
- run: cargo build --release --target ${{ matrix.target }}
43+
- run: cargo build --release --target ${{ matrix.target }} --features arithmetic
44+
- run: cargo build --release --target ${{ matrix.target }} --features ecdh
45+
- run: cargo build --release --target ${{ matrix.target }} --features ecdsa-core
46+
- run: cargo build --release --target ${{ matrix.target }} --features ecdsa
47+
- run: cargo build --release --target ${{ matrix.target }} --features sha256
48+
- run: cargo build --release --target ${{ matrix.target }} --all-features
4649
test:
4750
runs-on: ubuntu-latest
4851
strategy:

.github/workflows/p384.yml

+8-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ name: p384
33
on:
44
pull_request:
55
paths:
6-
- "elliptic-curve-crate/**"
76
- "p384/**"
7+
- "tests/p384_no_std/**"
88
- "Cargo.*"
99
push:
1010
branches: master
@@ -28,6 +28,9 @@ jobs:
2828
target:
2929
- thumbv7em-none-eabi
3030
- wasm32-unknown-unknown
31+
defaults:
32+
run:
33+
working-directory: tests/p384_no_std
3134
steps:
3235
- uses: actions/checkout@v1
3336
- uses: actions-rs/toolchain@v1
@@ -36,7 +39,10 @@ jobs:
3639
toolchain: ${{ matrix.rust }}
3740
target: ${{ matrix.target }}
3841
override: true
39-
- run: cargo build --no-default-features --release --target ${{ matrix.target }}
42+
- run: cargo build --release --target ${{ matrix.target }}
43+
- run: cargo build --release --target ${{ matrix.target }} --features ecdsa
44+
- run: cargo build --release --target ${{ matrix.target }} --features sha384
45+
- run: cargo build --release --target ${{ matrix.target }} --all-features
4046
test:
4147
runs-on: ubuntu-latest
4248
strategy:

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
target
2+
tests/Cargo.lock
23
*.sw*

Cargo.lock

+26-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ members = [
88
[patch.crates-io]
99
ecdsa = { git = "https://github.com/RustCrypto/signatures" }
1010
elliptic-curve = { git = "https://github.com/RustCrypto/traits" }
11+
group = { git = "https://github.com/zkcrypto/group.git" }

k256/Cargo.toml

+3-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ keywords = ["bitcoin", "crypto", "ecc", "ethereum", "secp256k1"]
1818
[dependencies]
1919
cfg-if = "0.1"
2020
ecdsa-core = { version = "0.7", package = "ecdsa", optional = true, default-features = false }
21-
elliptic-curve = { version = "0.5", default-features = false, features = ["weierstrass"] }
21+
elliptic-curve = { version = "0.5", default-features = false }
2222
sha2 = { version = "0.9", optional = true, default-features = false }
2323
sha3 = { version = "0.9", optional = true, default-features = false }
2424

@@ -36,15 +36,14 @@ rand_core = { version = "0.5", features = ["getrandom"] }
3636
default = ["arithmetic", "oid", "std"]
3737
arithmetic = []
3838
digest = ["elliptic-curve/digest", "ecdsa-core/digest"]
39-
ecdh = ["elliptic-curve/ecdh", "rand", "zeroize"]
40-
ecdsa = ["arithmetic", "digest", "ecdsa-core/rand", "ecdsa-core/sign", "ecdsa-core/verify", "rand", "zeroize"]
39+
ecdh = ["elliptic-curve/ecdh", "zeroize"]
40+
ecdsa = ["arithmetic", "digest", "ecdsa-core/sign", "ecdsa-core/verify", "zeroize"]
4141
endomorphism-mul = []
4242
expose-field = ["arithmetic"]
4343
field-montgomery = []
4444
force-32-bit = []
4545
keccak256 = ["digest", "sha3"]
4646
oid = ["elliptic-curve/oid"]
47-
rand = ["elliptic-curve/rand"]
4847
sha256 = ["digest", "sha2"]
4948
test-vectors = []
5049
std = ["elliptic-curve/std"]

k256/src/arithmetic.rs

-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ mod tests {
4444
assert_eq!(CURVE_EQUATION_B.to_bytes(), CURVE_EQUATION_B_BYTES.into());
4545
}
4646

47-
#[cfg(feature = "rand")]
4847
#[test]
4948
fn generate_secret_key() {
5049
use crate::SecretKey;

k256/src/arithmetic/scalar.rs

+2-14
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@ cfg_if! {
66
if #[cfg(any(target_pointer_width = "32", feature = "force-32-bit"))] {
77
mod scalar_8x32;
88
use scalar_8x32::Scalar8x32 as ScalarImpl;
9-
#[cfg(feature = "rand")]
109
use scalar_8x32::WideScalar16x32 as WideScalarImpl;
1110
} else if #[cfg(target_pointer_width = "64")] {
1211
mod scalar_4x64;
1312
use scalar_4x64::Scalar4x64 as ScalarImpl;
14-
#[cfg(feature = "rand")]
1513
use scalar_4x64::WideScalar8x64 as WideScalarImpl;
1614
}
1715
}
@@ -21,19 +19,14 @@ use core::ops::{Add, AddAssign, Mul, MulAssign, Neg, Shr, Sub, SubAssign};
2119
use elliptic_curve::{
2220
consts::U32,
2321
ops::Invert,
22+
rand_core::{CryptoRng, RngCore},
2423
subtle::{Choice, ConditionallySelectable, ConstantTimeEq, CtOption},
25-
FromBytes,
24+
FromBytes, Generate,
2625
};
2726

2827
#[cfg(feature = "digest")]
2928
use elliptic_curve::{Digest, FromDigest};
3029

31-
#[cfg(feature = "rand")]
32-
use elliptic_curve::{
33-
rand_core::{CryptoRng, RngCore},
34-
Generate,
35-
};
36-
3730
#[cfg(feature = "zeroize")]
3831
use elliptic_curve::zeroize::Zeroize;
3932

@@ -197,7 +190,6 @@ impl Scalar {
197190
}
198191

199192
/// Returns a (nearly) uniformly-random scalar, generated in constant time.
200-
#[cfg(feature = "rand")]
201193
pub fn generate_biased(mut rng: impl CryptoRng + RngCore) -> Self {
202194
// We reduce a random 512-bit value into a 256-bit field, which results in a
203195
// negligible bias from the uniform distribution, but the process is constant-time.
@@ -207,7 +199,6 @@ impl Scalar {
207199
}
208200

209201
/// Returns a uniformly-random scalar, generated using rejection sampling.
210-
#[cfg(feature = "rand")]
211202
pub fn generate_vartime(mut rng: impl CryptoRng + RngCore) -> Self {
212203
let mut bytes = ElementBytes::default();
213204

@@ -399,7 +390,6 @@ impl From<Scalar> for ElementBytes {
399390
}
400391
}
401392

402-
#[cfg(feature = "rand")]
403393
impl Generate for Scalar {
404394
fn generate(rng: impl CryptoRng + RngCore) -> Self {
405395
// Uses rejection sampling as the default random generation method,
@@ -511,7 +501,6 @@ mod tests {
511501
assert_eq!(res, res_ref);
512502
}
513503

514-
#[cfg(feature = "rand")]
515504
#[test]
516505
fn generate_biased() {
517506
use elliptic_curve::rand_core::OsRng;
@@ -520,7 +509,6 @@ mod tests {
520509
assert_eq!((a - &a).is_zero().unwrap_u8(), 1);
521510
}
522511

523-
#[cfg(feature = "rand")]
524512
#[test]
525513
fn generate_vartime() {
526514
use elliptic_curve::rand_core::OsRng;

k256/src/arithmetic/scalar/scalar_4x64.rs

-1
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,6 @@ impl ConstantTimeEq for Scalar4x64 {
413413
pub struct WideScalar8x64([u64; 8]);
414414

415415
impl WideScalar8x64 {
416-
#[cfg(feature = "rand")]
417416
pub fn from_bytes(bytes: &[u8; 64]) -> Self {
418417
let mut w = [0u64; 8];
419418
for i in 0..8 {

k256/src/arithmetic/scalar/scalar_8x32.rs

-1
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,6 @@ impl ConstantTimeEq for Scalar8x32 {
551551
pub struct WideScalar16x32([u32; 16]);
552552

553553
impl WideScalar16x32 {
554-
#[cfg(feature = "rand")]
555554
pub fn from_bytes(bytes: &[u8; 64]) -> Self {
556555
let mut w = [0u32; 16];
557556
for i in 0..16 {

k256/src/ecdsa/recoverable.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ use crate::{
4747
AffinePoint, NonZeroScalar, ProjectivePoint, Scalar,
4848
};
4949

50-
#[cfg(any(feature = "ecdsa", docsrs))]
50+
#[cfg(any(all(feature = "ecdsa", feature = "keccak256"), docsrs))]
5151
use crate::EncodedPoint;
5252

5353
#[cfg(feature = "keccak256")]
@@ -94,8 +94,9 @@ impl Signature {
9494
/// Given a public key, message, and signature, use trial recovery for both
9595
/// possible recovery IDs in an attempt to determine if a suitable
9696
/// recovery ID exists, or return an error otherwise.
97-
#[cfg(feature = "ecdsa")]
97+
#[cfg(all(feature = "ecdsa", feature = "keccak256"))]
9898
#[cfg_attr(docsrs, doc(cfg(feature = "ecdsa")))]
99+
#[cfg_attr(docsrs, doc(cfg(feature = "keccak256")))]
99100
pub fn from_trial_recovery(
100101
public_key: &EncodedPoint,
101102
msg: &[u8],
@@ -120,7 +121,8 @@ impl Signature {
120121
/// Recover the public key used to create the given signature as an
121122
/// [`EncodedPoint`].
122123
#[cfg(all(feature = "ecdsa", feature = "keccak256"))]
123-
#[cfg_attr(docsrs, doc(cfg(feature = "ecdsa")), doc(cfg(feature = "keccak256")))]
124+
#[cfg_attr(docsrs, doc(cfg(feature = "ecdsa")))]
125+
#[cfg_attr(docsrs, doc(cfg(feature = "keccak256")))]
124126
pub fn recover_verify_key(&self, msg: &[u8]) -> Result<VerifyKey, Error> {
125127
self.recover_verify_key_from_digest(Keccak256::new().chain(msg))
126128
}

k256/src/ecdsa/sign.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use elliptic_curve::{
1717
};
1818
use signature::PrehashSignature;
1919

20-
#[cfg(any(feature = "sha256", feature = "keccak256"))]
20+
#[cfg(feature = "digest")]
2121
use signature::digest::Digest;
2222

2323
/// ECDSA/secp256k1 signing key

p256/Cargo.toml

+3-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ keywords = ["crypto", "ecc", "nist", "prime256v1", "secp256r1"]
1717

1818
[dependencies]
1919
ecdsa-core = { version = "0.7", package = "ecdsa", optional = true, default-features = false }
20-
elliptic-curve = { version = "0.5", default-features = false, features = ["weierstrass"] }
20+
elliptic-curve = { version = "0.5", default-features = false }
2121
sha2 = { version = "0.9", optional = true, default-features = false }
2222

2323
[dev-dependencies]
@@ -31,10 +31,9 @@ rand_core = { version = "0.5", features = ["getrandom"] }
3131
default = ["arithmetic", "std"]
3232
arithmetic = []
3333
digest = ["elliptic-curve/digest", "ecdsa-core/digest"]
34-
ecdh = ["elliptic-curve/ecdh", "rand", "zeroize"]
35-
ecdsa = ["arithmetic", "ecdsa-core/rand", "ecdsa-core/sign", "ecdsa-core/verify", "rand", "sha256", "zeroize"]
34+
ecdh = ["elliptic-curve/ecdh", "zeroize"]
35+
ecdsa = ["arithmetic", "ecdsa-core/sign", "ecdsa-core/verify", "sha256", "zeroize"]
3636
oid = ["elliptic-curve/oid"]
37-
rand = ["elliptic-curve/rand"]
3837
sha256 = ["digest", "ecdsa-core/hazmat", "sha2"]
3938
test-vectors = []
4039
std = ["elliptic-curve/std"]

p256/src/arithmetic.rs

-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ mod tests {
5353
);
5454
}
5555

56-
#[cfg(feature = "rand")]
5756
#[test]
5857
fn generate_secret_key() {
5958
use crate::SecretKey;

0 commit comments

Comments
 (0)