Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ecdsa: switch from ScalarBytes<C> to ScalarCore<C> #356

Merged
merged 1 commit into from
Sep 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/ecdsa.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ jobs:
- run: cargo build --no-default-features --release --target ${{ matrix.target }} --features pem
- run: cargo build --no-default-features --release --target ${{ matrix.target }} --features sign
- run: cargo build --no-default-features --release --target ${{ matrix.target }} --features verify
- run: cargo build --no-default-features --release --target ${{ matrix.target }} --features zeroize
- run: cargo build --no-default-features --release --target ${{ matrix.target }} --features arithmetic,dev,digest,hazmat,pkcs8,pem,sign,verify,zeroize
- run: cargo build --no-default-features --release --target ${{ matrix.target }} --features arithmetic,dev,digest,hazmat,pkcs8,pem,sign,verify

test:
runs-on: ubuntu-latest
Expand Down
5 changes: 2 additions & 3 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
members = ["ecdsa", "ed25519"]

[patch.crates-io]
crypto-bigint = { git = "https://github.com/RustCrypto/utils.git" }
elliptic-curve = { git = "https://github.com/RustCrypto/traits.git" }
5 changes: 2 additions & 3 deletions ecdsa/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,14 @@ sha2 = { version = "0.9", default-features = false }
default = ["digest"]
alloc = []
arithmetic = ["elliptic-curve/arithmetic"]
dev = ["arithmetic", "digest", "elliptic-curve/dev", "hazmat", "zeroize"]
dev = ["arithmetic", "digest", "elliptic-curve/dev", "hazmat"]
digest = ["signature/digest-preview"]
hazmat = []
pkcs8 = ["elliptic-curve/pkcs8", "der"]
pem = ["elliptic-curve/pem", "pkcs8"]
sign = ["arithmetic", "digest", "hazmat", "hmac", "zeroize"]
sign = ["arithmetic", "digest", "hazmat", "hmac"]
std = ["alloc", "elliptic-curve/std", "signature/std"]
verify = ["arithmetic", "digest", "hazmat"]
zeroize = ["elliptic-curve/zeroize"]

[package.metadata.docs.rs]
all-features = true
Expand Down
8 changes: 4 additions & 4 deletions ecdsa/src/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

use crate::hazmat::FromDigest;
use elliptic_curve::{
bigint::Encoding as _,
bigint::{ArrayEncoding, Encoding},
consts::U32,
dev::{MockCurve, Scalar, ScalarBytes},
dev::{MockCurve, Scalar},
group::ff::PrimeField,
subtle::{ConditionallySelectable, ConstantTimeLess},
Curve,
};
Expand All @@ -25,8 +26,7 @@ impl FromDigest<MockCurve> for Scalar {
overflow,
));

// TODO(tarcieri): simpler conversion
ScalarBytes::from_uint(&scalar).unwrap().into_scalar()
Self::from_repr(scalar.to_be_byte_array()).unwrap()
}
}

Expand Down
4 changes: 2 additions & 2 deletions ecdsa/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ use core::{
use elliptic_curve::{
bigint::Encoding as _,
generic_array::{sequence::Concat, ArrayLength, GenericArray},
FieldBytes, FieldSize, ScalarBytes,
FieldBytes, FieldSize, ScalarCore,
};

#[cfg(feature = "arithmetic")]
Expand Down Expand Up @@ -277,7 +277,7 @@ where
return Err(Error::new());
}

if ScalarBytes::<C>::new(GenericArray::clone_from_slice(scalar))
if ScalarCore::<C>::from_bytes_be(GenericArray::clone_from_slice(scalar))
.is_none()
.into()
{
Expand Down
2 changes: 1 addition & 1 deletion ecdsa/src/sign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ where

/// Initialize signing key from a raw scalar serialized as a byte slice.
pub fn from_bytes(bytes: &[u8]) -> Result<Self> {
let inner = SecretKey::from_bytes(bytes)
let inner = SecretKey::from_bytes_be(bytes)
.map(|sk| sk.to_secret_scalar())
.map_err(|_| Error::new())?;

Expand Down