Skip to content

Commit 5422aa2

Browse files
committed
Bump elliptic-curve to v0.11.0-pre
Sourced from git. This includes transitive updates to ff and group v0.11. A major notable change of these updates is switching several APIs to use `subtle::Choice` and `subtle::CtOption` instead of `bool`/`Option`. Fortunately, the crates in this repo are already written with constant-time implementations internally, so this was an easy change.
1 parent eda5854 commit 5422aa2

File tree

18 files changed

+127
-193
lines changed

18 files changed

+127
-193
lines changed

.github/workflows/k256.yml

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -99,37 +99,38 @@ jobs:
9999
- run: cargo test --release --target ${{ matrix.target }} --features field-montgomery
100100
- run: cargo test --release --target ${{ matrix.target }} --all-features
101101

102-
cross:
103-
strategy:
104-
matrix:
105-
include:
106-
# ARM32
107-
- target: armv7-unknown-linux-gnueabihf
108-
rust: 1.51.0 # MSRV
109-
- target: armv7-unknown-linux-gnueabihf
110-
rust: stable
111-
112-
# ARM64
113-
- target: aarch64-unknown-linux-gnu
114-
rust: 1.51.0 # MSRV
115-
- target: aarch64-unknown-linux-gnu
116-
rust: stable
117-
118-
# PPC32
119-
- target: powerpc-unknown-linux-gnu
120-
rust: 1.51.0 # MSRV
121-
- target: powerpc-unknown-linux-gnu
122-
rust: stable
123-
124-
runs-on: ubuntu-latest
125-
steps:
126-
- uses: actions/checkout@v2
127-
- run: ${{ matrix.deps }}
128-
- uses: actions-rs/toolchain@v1
129-
with:
130-
profile: minimal
131-
toolchain: ${{ matrix.rust }}
132-
target: ${{ matrix.target }}
133-
override: true
134-
- run: cargo install cross
135-
- run: cross test --release --target ${{ matrix.target }} --all-features
102+
# TODO(tarcieri): re-enable when new `elliptic-curve` and `ecdsa` crates are released
103+
# cross:
104+
# strategy:
105+
# matrix:
106+
# include:
107+
# # ARM32
108+
# - target: armv7-unknown-linux-gnueabihf
109+
# rust: 1.51.0 # MSRV
110+
# - target: armv7-unknown-linux-gnueabihf
111+
# rust: stable
112+
#
113+
# # ARM64
114+
# - target: aarch64-unknown-linux-gnu
115+
# rust: 1.51.0 # MSRV
116+
# - target: aarch64-unknown-linux-gnu
117+
# rust: stable
118+
#
119+
# # PPC32
120+
# - target: powerpc-unknown-linux-gnu
121+
# rust: 1.51.0 # MSRV
122+
# - target: powerpc-unknown-linux-gnu
123+
# rust: stable
124+
#
125+
# runs-on: ubuntu-latest
126+
# steps:
127+
# - uses: actions/checkout@v2
128+
# - run: ${{ matrix.deps }}
129+
# - uses: actions-rs/toolchain@v1
130+
# with:
131+
# profile: minimal
132+
# toolchain: ${{ matrix.rust }}
133+
# target: ${{ matrix.target }}
134+
# override: true
135+
# - run: cargo install cross
136+
# - run: cross test --release --target ${{ matrix.target }} --all-features

.github/workflows/p256.yml

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -80,37 +80,38 @@ jobs:
8080
- run: cargo test --release --target ${{ matrix.target }}
8181
- run: cargo test --release --target ${{ matrix.target }} --all-features
8282

83-
cross:
84-
strategy:
85-
matrix:
86-
include:
87-
# ARM32
88-
- target: armv7-unknown-linux-gnueabihf
89-
rust: 1.51.0 # MSRV
90-
- target: armv7-unknown-linux-gnueabihf
91-
rust: stable
92-
93-
# ARM64
94-
- target: aarch64-unknown-linux-gnu
95-
rust: 1.51.0 # MSRV
96-
- target: aarch64-unknown-linux-gnu
97-
rust: stable
98-
99-
# PPC32
100-
- target: powerpc-unknown-linux-gnu
101-
rust: 1.51.0 # MSRV
102-
- target: powerpc-unknown-linux-gnu
103-
rust: stable
104-
105-
runs-on: ubuntu-latest
106-
steps:
107-
- uses: actions/checkout@v2
108-
- run: ${{ matrix.deps }}
109-
- uses: actions-rs/toolchain@v1
110-
with:
111-
profile: minimal
112-
toolchain: ${{ matrix.rust }}
113-
target: ${{ matrix.target }}
114-
override: true
115-
- run: cargo install cross
116-
- run: cross test --release --target ${{ matrix.target }} --all-features
83+
# TODO(tarcieri): re-enable when new `elliptic-curve` and `ecdsa` crates are released
84+
# cross:
85+
# strategy:
86+
# matrix:
87+
# include:
88+
# # ARM32
89+
# - target: armv7-unknown-linux-gnueabihf
90+
# rust: 1.51.0 # MSRV
91+
# - target: armv7-unknown-linux-gnueabihf
92+
# rust: stable
93+
#
94+
# # ARM64
95+
# - target: aarch64-unknown-linux-gnu
96+
# rust: 1.51.0 # MSRV
97+
# - target: aarch64-unknown-linux-gnu
98+
# rust: stable
99+
#
100+
# # PPC32
101+
# - target: powerpc-unknown-linux-gnu
102+
# rust: 1.51.0 # MSRV
103+
# - target: powerpc-unknown-linux-gnu
104+
# rust: stable
105+
#
106+
# runs-on: ubuntu-latest
107+
# steps:
108+
# - uses: actions/checkout@v2
109+
# - run: ${{ matrix.deps }}
110+
# - uses: actions-rs/toolchain@v1
111+
# with:
112+
# profile: minimal
113+
# toolchain: ${{ matrix.rust }}
114+
# target: ${{ matrix.target }}
115+
# override: true
116+
# - run: cargo install cross
117+
# - run: cross test --release --target ${{ matrix.target }} --all-features

Cargo.lock

Lines changed: 8 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,7 @@ members = [
77
"p256",
88
"p384",
99
]
10+
11+
[patch.crates-io]
12+
ecdsa = { git = "https://github.com/RustCrypto/signatures.git" }
13+
elliptic-curve = { git = "https://github.com/RustCrypto/traits.git" }

bp256/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ categories = ["cryptography", "no-std"]
1212
keywords = ["brainpool", "crypto", "ecc"]
1313

1414
[dependencies]
15-
elliptic-curve = { version = "0.10", default-features = false, features = ["hazmat"] }
15+
elliptic-curve = { version = "=0.11.0-pre", default-features = false, features = ["hazmat"] }
1616

1717
# optional dependencies
18-
ecdsa = { version = "0.12", optional = true, default-features = false, features = ["der"] }
18+
ecdsa = { version = "=0.13.0-pre", optional = true, default-features = false, features = ["der"] }
1919
sha2 = { version = "0.9", optional = true, default-features = false }
2020

2121
[features]

bp384/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ categories = ["cryptography", "no-std"]
1212
keywords = ["brainpool", "crypto", "ecc"]
1313

1414
[dependencies]
15-
elliptic-curve = { version = "0.10", default-features = false, features = ["hazmat"] }
15+
elliptic-curve = { version = "=0.11.0-pre", default-features = false, features = ["hazmat"] }
1616

1717
# optional dependencies
18-
ecdsa = { version = "0.12", optional = true, default-features = false, features = ["der"] }
18+
ecdsa = { version = "=0.13.0-pre", optional = true, default-features = false, features = ["der"] }
1919
sha2 = { version = "0.9", optional = true, default-features = false }
2020

2121
[features]

k256/Cargo.toml

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,18 @@ keywords = ["bitcoin", "crypto", "ecc", "ethereum", "secp256k1"]
1818

1919
[dependencies]
2020
cfg-if = "1.0"
21-
elliptic-curve = { version = "0.10.6", default-features = false, features = ["hazmat"] }
21+
elliptic-curve = { version = "=0.11.0-pre", default-features = false, features = ["hazmat"] }
2222

2323
# optional dependencies
24+
ecdsa-core = { version = "=0.13.0-pre", package = "ecdsa", optional = true, default-features = false, features = ["der"] }
2425
hex-literal = { version = "0.3", optional = true }
2526
sha2 = { version = "0.9", optional = true, default-features = false }
2627
sha3 = { version = "0.9", optional = true, default-features = false }
2728

28-
[dependencies.ecdsa-core]
29-
version = "0.12.1"
30-
package = "ecdsa"
31-
optional = true
32-
default-features = false
33-
features = ["der"]
34-
3529
[dev-dependencies]
3630
blobby = "0.3"
3731
criterion = "0.3"
38-
ecdsa-core = { version = "0.12.1", package = "ecdsa", default-features = false, features = ["dev"] }
32+
ecdsa-core = { version = "=0.13.0-pre", package = "ecdsa", default-features = false, features = ["dev"] }
3933
hex-literal = "0.3"
4034
num-bigint = "0.4"
4135
num-traits = "0.2"

k256/src/arithmetic/scalar.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,6 @@ impl Field for Scalar {
9595
Scalar::one()
9696
}
9797

98-
fn is_zero(&self) -> bool {
99-
self.0.is_zero().into()
100-
}
101-
10298
#[must_use]
10399
fn square(&self) -> Self {
104100
Scalar::square(self)
@@ -493,16 +489,16 @@ impl PrimeField for Scalar {
493489
///
494490
/// Returns None if the byte array does not contain a big-endian integer in the range
495491
/// [0, p).
496-
fn from_repr(bytes: FieldBytes) -> Option<Self> {
497-
ScalarImpl::from_bytes(bytes.as_ref()).map(Self).into()
492+
fn from_repr(bytes: FieldBytes) -> CtOption<Self> {
493+
ScalarImpl::from_bytes(bytes.as_ref()).map(Self)
498494
}
499495

500496
fn to_repr(&self) -> FieldBytes {
501497
self.to_bytes()
502498
}
503499

504-
fn is_odd(&self) -> bool {
505-
self.0.is_odd().into()
500+
fn is_odd(&self) -> Choice {
501+
self.0.is_odd()
506502
}
507503

508504
fn multiplicative_generator() -> Self {
@@ -707,7 +703,7 @@ impl Scalar {
707703
// TODO: pre-generate several scalars to bring the probability of non-constant-timeness down?
708704
loop {
709705
rng.fill_bytes(&mut bytes);
710-
if let Some(scalar) = Scalar::from_repr(bytes) {
706+
if let Some(scalar) = Scalar::from_repr(bytes).into() {
711707
return scalar;
712708
}
713709
}

k256/src/ecdsa.rs

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,6 @@ pub use self::{sign::SigningKey, verify::VerifyingKey};
8383

8484
use crate::Secp256k1;
8585

86-
#[cfg(feature = "ecdsa")]
87-
use crate::NonZeroScalar;
88-
#[cfg(feature = "ecdsa")]
89-
use elliptic_curve::generic_array::GenericArray;
90-
9186
/// ECDSA/secp256k1 signature (fixed-size)
9287
pub type Signature = ecdsa_core::Signature<Secp256k1>;
9388

@@ -100,20 +95,6 @@ impl ecdsa_core::hazmat::DigestPrimitive for Secp256k1 {
10095
type Digest = sha2::Sha256;
10196
}
10297

103-
/// Validate that the scalars of an ECDSA signature are modulo the order
104-
#[cfg(feature = "ecdsa")]
105-
fn check_scalars(signature: &Signature) -> Result<(), Error> {
106-
let (r_bytes, s_bytes) = signature.as_ref().split_at(32);
107-
let r_valid = NonZeroScalar::from_repr(GenericArray::clone_from_slice(r_bytes)).is_some();
108-
let s_valid = NonZeroScalar::from_repr(GenericArray::clone_from_slice(s_bytes)).is_some();
109-
110-
if r_valid && s_valid {
111-
Ok(())
112-
} else {
113-
Err(Error::new())
114-
}
115-
}
116-
11798
#[cfg(all(test, feature = "ecdsa", feature = "arithmetic"))]
11899
mod tests {
119100
mod wycheproof {
@@ -165,7 +146,7 @@ mod tests {
165146
Err(_) => return Some("failed to parse signature ASN.1"),
166147
};
167148

168-
sig.normalize_s().unwrap();
149+
sig.normalize_s();
169150

170151
match verifying_key.verify(msg, &sig) {
171152
Ok(_) if pass => None,

k256/src/ecdsa/normalize.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ mod tests {
4747
]).unwrap();
4848

4949
let mut sig_normalized = sig_hi;
50-
assert!(sig_normalized.normalize_s().unwrap());
50+
assert!(sig_normalized.normalize_s());
5151
assert_eq!(sig_lo, sig_normalized);
5252
}
5353

@@ -62,7 +62,7 @@ mod tests {
6262
]).unwrap();
6363

6464
let mut sig_normalized = sig;
65-
assert!(!sig_normalized.normalize_s().unwrap());
65+
assert!(!sig_normalized.normalize_s());
6666
assert_eq!(sig, sig_normalized);
6767
}
6868
}

0 commit comments

Comments
 (0)