Skip to content

Commit

Permalink
Bump ecdsa crate dependency to v0.13 (#467)
Browse files Browse the repository at this point in the history
  • Loading branch information
tarcieri authored Nov 21, 2021
1 parent af25e19 commit d85cf80
Show file tree
Hide file tree
Showing 10 changed files with 116 additions and 97 deletions.
69 changes: 34 additions & 35 deletions .github/workflows/k256.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,38 +100,37 @@ jobs:
- run: cargo test --release --target ${{ matrix.target }}
- run: cargo test --release --target ${{ matrix.target }} --all-features

# TODO(tarcieri): re-enable when new `elliptic-curve` and `ecdsa` crates are released
# cross:
# strategy:
# matrix:
# include:
# # ARM32
# - target: armv7-unknown-linux-gnueabihf
# rust: 1.56.0 # MSRV
# - target: armv7-unknown-linux-gnueabihf
# rust: stable
#
# # ARM64
# - target: aarch64-unknown-linux-gnu
# rust: 1.56.0 # MSRV
# - target: aarch64-unknown-linux-gnu
# rust: stable
#
# # PPC32
# - target: powerpc-unknown-linux-gnu
# rust: 1.56.0 # MSRV
# - target: powerpc-unknown-linux-gnu
# rust: stable
#
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v2
# - run: ${{ matrix.deps }}
# - uses: actions-rs/toolchain@v1
# with:
# profile: minimal
# toolchain: ${{ matrix.rust }}
# target: ${{ matrix.target }}
# override: true
# - run: cargo install cross
# - run: cross test --release --target ${{ matrix.target }} --all-features
cross:
strategy:
matrix:
include:
# ARM32
- target: armv7-unknown-linux-gnueabihf
rust: 1.56.0 # MSRV
- target: armv7-unknown-linux-gnueabihf
rust: stable

# ARM64
- target: aarch64-unknown-linux-gnu
rust: 1.56.0 # MSRV
- target: aarch64-unknown-linux-gnu
rust: stable

# PPC32
- target: powerpc-unknown-linux-gnu
rust: 1.56.0 # MSRV
- target: powerpc-unknown-linux-gnu
rust: stable

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: ${{ matrix.deps }}
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ matrix.rust }}
target: ${{ matrix.target }}
override: true
- run: cargo install cross
- run: cross test --release --target ${{ matrix.target }} --all-features
69 changes: 34 additions & 35 deletions .github/workflows/p256.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,38 +81,37 @@ jobs:
- run: cargo test --release --target ${{ matrix.target }}
- run: cargo test --release --target ${{ matrix.target }} --all-features

# TODO(tarcieri): re-enable when new `elliptic-curve` and `ecdsa` crates are released
# cross:
# strategy:
# matrix:
# include:
# # ARM32
# - target: armv7-unknown-linux-gnueabihf
# rust: 1.56.0 # MSRV
# - target: armv7-unknown-linux-gnueabihf
# rust: stable
#
# # ARM64
# - target: aarch64-unknown-linux-gnu
# rust: 1.56.0 # MSRV
# - target: aarch64-unknown-linux-gnu
# rust: stable
#
# # PPC32
# - target: powerpc-unknown-linux-gnu
# rust: 1.56.0 # MSRV
# - target: powerpc-unknown-linux-gnu
# rust: stable
#
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v2
# - run: ${{ matrix.deps }}
# - uses: actions-rs/toolchain@v1
# with:
# profile: minimal
# toolchain: ${{ matrix.rust }}
# target: ${{ matrix.target }}
# override: true
# - run: cargo install cross
# - run: cross test --release --target ${{ matrix.target }} --all-features
cross:
strategy:
matrix:
include:
# ARM32
- target: armv7-unknown-linux-gnueabihf
rust: 1.56.0 # MSRV
- target: armv7-unknown-linux-gnueabihf
rust: stable

# ARM64
- target: aarch64-unknown-linux-gnu
rust: 1.56.0 # MSRV
- target: aarch64-unknown-linux-gnu
rust: stable

# PPC32
- target: powerpc-unknown-linux-gnu
rust: 1.56.0 # MSRV
- target: powerpc-unknown-linux-gnu
rust: stable

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: ${{ matrix.deps }}
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ matrix.rust }}
target: ${{ matrix.target }}
override: true
- run: cargo install cross
- run: cross test --release --target ${{ matrix.target }} --all-features
22 changes: 17 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,3 @@ members = [
"p256",
"p384",
]

[patch.crates-io]
ecdsa = { git = "https://github.com/RustCrypto/signatures.git" }
2 changes: 1 addition & 1 deletion bp256/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ elliptic-curve = { version = "0.11", default-features = false, features = ["hazm
sec1 = { version = "0.2", default-features = false }

# optional dependencies
ecdsa = { version = "=0.13.0-pre", optional = true, default-features = false, features = ["der"] }
ecdsa = { version = "0.13", optional = true, default-features = false, features = ["der"] }
sha2 = { version = "0.9", optional = true, default-features = false }

[features]
Expand Down
2 changes: 1 addition & 1 deletion bp384/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ elliptic-curve = { version = "0.11", default-features = false, features = ["hazm
sec1 = { version = "0.2", default-features = false }

# optional dependencies
ecdsa = { version = "=0.13.0-pre", optional = true, default-features = false, features = ["der"] }
ecdsa = { version = "0.13", optional = true, default-features = false, features = ["der"] }
sha2 = { version = "0.9", optional = true, default-features = false }

[features]
Expand Down
4 changes: 2 additions & 2 deletions k256/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ elliptic-curve = { version = "0.11", default-features = false, features = ["hazm
sec1 = { version = "0.2", default-features = false }

# optional dependencies
ecdsa-core = { version = "=0.13.0-pre", package = "ecdsa", optional = true, default-features = false, features = ["der"] }
ecdsa-core = { version = "0.13", package = "ecdsa", optional = true, default-features = false, features = ["der"] }
hex-literal = { version = "0.3", optional = true }
sha2 = { version = "0.9", optional = true, default-features = false }
sha3 = { version = "0.9", optional = true, default-features = false }

[dev-dependencies]
blobby = "0.3"
criterion = "0.3"
ecdsa-core = { version = "=0.13.0-pre", package = "ecdsa", default-features = false, features = ["dev"] }
ecdsa-core = { version = "0.13", package = "ecdsa", default-features = false, features = ["dev"] }
hex-literal = "0.3"
num-bigint = "0.4"
num-traits = "0.2"
Expand Down
36 changes: 24 additions & 12 deletions k256/src/ecdsa/sign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ use elliptic_curve::{
ops::{Invert, Reduce},
rand_core::{CryptoRng, RngCore},
subtle::{Choice, ConstantTimeEq},
zeroize::Zeroize,
IsHigh,
zeroize::{Zeroize, Zeroizing},
Curve, IsHigh, PrimeField, ScalarCore,
};

#[cfg(any(feature = "keccak256", feature = "sha256"))]
Expand Down Expand Up @@ -107,12 +107,18 @@ where
D: BlockInput + FixedOutput<OutputSize = U32> + Clone + Default + Reset + Update,
{
fn try_sign_digest(&self, msg_digest: D) -> Result<recoverable::Signature, Error> {
let ephemeral_scalar = rfc6979::generate_k(&self.inner, msg_digest.clone(), &[]);
let x = Zeroizing::new(ScalarCore::from(self.inner));
let msg_scalar = Scalar::from_be_bytes_reduced(msg_digest.finalize_fixed());
let (signature, recid) = self
.inner
.try_sign_prehashed(**ephemeral_scalar, msg_scalar)?;

let k = Zeroizing::new(
NonZeroScalar::from_uint(*rfc6979::generate_k::<D, _>(
x.as_uint(),
&Secp256k1::ORDER,
&msg_scalar.to_repr(),
&[],
))
.unwrap(),
);
let (signature, recid) = self.inner.try_sign_prehashed(**k, msg_scalar)?;
let recoverable_id = recid.ok_or_else(Error::new)?.try_into()?;
recoverable::Signature::new(&signature, recoverable_id)
}
Expand Down Expand Up @@ -144,12 +150,18 @@ where
let mut added_entropy = FieldBytes::default();
rng.fill_bytes(&mut added_entropy);

let ephemeral_scalar = rfc6979::generate_k(&self.inner, msg_digest.clone(), &added_entropy);
let x = Zeroizing::new(ScalarCore::from(self.inner));
let msg_scalar = Scalar::from_be_bytes_reduced(msg_digest.finalize_fixed());
let (signature, recid) = self
.inner
.try_sign_prehashed(**ephemeral_scalar, msg_scalar)?;

let k = Zeroizing::new(
NonZeroScalar::from_uint(*rfc6979::generate_k::<D, _>(
x.as_uint(),
&Secp256k1::ORDER,
&msg_scalar.to_repr(),
&added_entropy,
))
.unwrap(),
);
let (signature, recid) = self.inner.try_sign_prehashed(**k, msg_scalar)?;
let recoverable_id = recid.ok_or_else(Error::new)?.try_into()?;
recoverable::Signature::new(&signature, recoverable_id)
}
Expand Down
4 changes: 2 additions & 2 deletions p256/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ elliptic-curve = { version = "0.11", default-features = false, features = ["hazm
sec1 = { version = "0.2", default-features = false }

# optional dependencies
ecdsa-core = { version = "=0.13.0-pre", package = "ecdsa", optional = true, default-features = false, features = ["der"] }
ecdsa-core = { version = "0.13", package = "ecdsa", optional = true, default-features = false, features = ["der"] }
hex-literal = { version = "0.3", optional = true }
sha2 = { version = "0.9", optional = true, default-features = false }

[dev-dependencies]
blobby = "0.3"
ecdsa-core = { version = "=0.13.0-pre", package = "ecdsa", default-features = false, features = ["dev"] }
ecdsa-core = { version = "0.13", package = "ecdsa", default-features = false, features = ["dev"] }
hex-literal = "0.3"
proptest = "1.0"
rand_core = { version = "0.6", features = ["getrandom"] }
Expand Down
2 changes: 1 addition & 1 deletion p384/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ edition = "2021"
rust-version = "1.56"

[dependencies]
ecdsa = { version = "=0.13.0-pre", optional = true, default-features = false, features = ["der"] }
ecdsa = { version = "0.13", optional = true, default-features = false, features = ["der"] }
elliptic-curve = { version = "0.11", default-features = false, features = ["hazmat", "sec1"] }
sec1 = { version = "0.2", default-features = false }
sha2 = { version = "0.9", optional = true, default-features = false }
Expand Down

0 comments on commit d85cf80

Please sign in to comment.