Skip to content

Commit 8e6bb26

Browse files
authored
ecdsa: use blanket impl from signature 3 (#945)
- Renames `DigestPrimitive` to `DigestAlgorithm` - `DigestAlgorithm` now exported from crate root instead of `hazmat`
1 parent a83c494 commit 8e6bb26

14 files changed

+125
-233
lines changed

Cargo.lock

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

Cargo.toml

+1-4
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,4 @@ slh-dsa = { path = "./slh-dsa" }
3434
# https://github.com/RustCrypto/traits/pull/1774
3535
# https://github.com/RustCrypto/traits/pull/1822
3636
elliptic-curve = { git = "https://github.com/RustCrypto/traits.git" }
37-
38-
# https://github.com/RustCrypto/crypto-bigint/pull/762
39-
# https://github.com/RustCrypto/crypto-bigint/pull/765
40-
crypto-bigint = { git = "https://github.com/RustCrypto/crypto-bigint.git" }
37+
signature = { git = "https://github.com/RustCrypto/traits.git" }

ecdsa/CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## 0.17.0 (UNRELEASED)
8+
9+
### Changed
10+
- `DigestPrimitive` was moved off of hazmat ([#945])
11+
- `DigestPrimitive` has been renamed `DigestAlgorithm` ([#945])
12+
13+
[#945]: https://github.com/RustCrypto/signatures/pull/945
14+
715
## 0.16.9 (2023-11-16)
816
### Changed
917
- Loosen `signature` bound to `2.0, <2.3` ([#756])

ecdsa/Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ rust-version = "1.85"
1818

1919
[dependencies]
2020
elliptic-curve = { version = "0.14.0-rc.1", default-features = false, features = ["sec1"] }
21-
signature = { version = "=2.3.0-pre.7", default-features = false, features = ["rand_core"] }
21+
signature = { version = "=3.0.0-pre", default-features = false, features = ["rand_core"] }
2222

2323
# optional dependencies
2424
der = { version = "0.8.0-rc.1", optional = true }
@@ -44,6 +44,7 @@ digest = ["dep:digest", "elliptic-curve/digest", "signature/digest"]
4444
hazmat = []
4545
pkcs8 = ["digest", "elliptic-curve/pkcs8", "der"]
4646
pem = ["elliptic-curve/pem", "pkcs8"]
47+
rfc6979 = ["arithmetic", "digest", "dep:rfc6979"]
4748
serde = ["elliptic-curve/serde", "pkcs8", "serdect"]
4849
signing = ["arithmetic", "digest", "hazmat", "rfc6979"]
4950
verifying = ["arithmetic", "digest", "hazmat"]

ecdsa/src/der.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -382,10 +382,10 @@ fn find_scalar_range(outer: &[u8], inner: &[u8]) -> Result<Range<usize>> {
382382
Ok(Range { start, end })
383383
}
384384

385-
#[cfg(all(feature = "digest", feature = "hazmat"))]
385+
#[cfg(feature = "digest")]
386386
impl<C> signature::PrehashSignature for Signature<C>
387387
where
388-
C: EcdsaCurve + crate::hazmat::DigestPrimitive,
388+
C: EcdsaCurve + crate::DigestAlgorithm,
389389
MaxSize<C>: ArraySize,
390390
<FieldBytesSize<C> as Add>::Output: Add<MaxOverhead> + ArraySize,
391391
{

ecdsa/src/hazmat.rs

+9-34
Original file line numberDiff line numberDiff line change
@@ -27,46 +27,21 @@ use {
2727
},
2828
};
2929

30-
#[cfg(feature = "digest")]
30+
#[cfg(feature = "rfc6979")]
3131
use {
32-
elliptic_curve::FieldBytesSize,
33-
signature::{
34-
PrehashSignature,
35-
digest::{Digest, FixedOutput, FixedOutputReset, core_api::BlockSizeUser},
36-
},
32+
elliptic_curve::FieldBytesEncoding,
33+
signature::digest::{Digest, FixedOutput, FixedOutputReset, core_api::BlockSizeUser},
3734
};
3835

39-
#[cfg(feature = "rfc6979")]
40-
use elliptic_curve::FieldBytesEncoding;
41-
42-
#[cfg(any(feature = "arithmetic", feature = "digest"))]
36+
#[cfg(any(feature = "arithmetic", feature = "rfc6979"))]
4337
use crate::{Signature, elliptic_curve::array::ArraySize};
4438

45-
/// Bind a preferred [`Digest`] algorithm to an elliptic curve type.
46-
///
47-
/// Generally there is a preferred variety of the SHA-2 family used with ECDSA
48-
/// for a particular elliptic curve.
49-
///
50-
/// This trait can be used to specify it, and with it receive a blanket impl of
51-
/// [`PrehashSignature`], used by [`signature_derive`][1]) for the [`Signature`]
52-
/// type for a particular elliptic curve.
53-
///
54-
/// [1]: https://github.com/RustCrypto/traits/tree/master/signature/derive
55-
#[cfg(feature = "digest")]
56-
pub trait DigestPrimitive: EcdsaCurve {
57-
/// Preferred digest to use when computing ECDSA signatures for this
58-
/// elliptic curve. This is typically a member of the SHA-2 family.
59-
type Digest: BlockSizeUser + Digest + FixedOutput + FixedOutputReset;
60-
}
61-
6239
#[cfg(feature = "digest")]
63-
impl<C> PrehashSignature for Signature<C>
64-
where
65-
C: DigestPrimitive,
66-
<FieldBytesSize<C> as core::ops::Add>::Output: ArraySize,
67-
{
68-
type Digest = C::Digest;
69-
}
40+
#[deprecated(
41+
since = "0.17.0",
42+
note = "`DigestAlgorithm` is no longer in `hazmat`, please use `ecdsa::DigestAlgorithm` instead"
43+
)]
44+
pub use crate::DigestAlgorithm;
7045

7146
/// Partial implementation of the `bits2int` function as defined in
7247
/// [RFC6979 § 2.3.2] as well as [SEC1] § 2.3.8.

ecdsa/src/lib.rs

+42-12
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,13 @@ use {
101101
};
102102

103103
#[cfg(feature = "digest")]
104-
use digest::{
105-
Digest,
106-
const_oid::{AssociatedOid, ObjectIdentifier},
104+
use {
105+
digest::{
106+
Digest, FixedOutput, FixedOutputReset,
107+
const_oid::{AssociatedOid, ObjectIdentifier},
108+
core_api::BlockSizeUser,
109+
},
110+
signature::PrehashSignature,
107111
};
108112

109113
#[cfg(feature = "pkcs8")]
@@ -463,15 +467,15 @@ where
463467
///
464468
/// To support non-default digest algorithms, use the [`SignatureWithOid`]
465469
/// type instead.
466-
#[cfg(all(feature = "digest", feature = "hazmat"))]
470+
#[cfg(feature = "digest")]
467471
impl<C> AssociatedOid for Signature<C>
468472
where
469-
C: hazmat::DigestPrimitive,
473+
C: DigestAlgorithm,
470474
C::Digest: AssociatedOid,
471475
{
472476
const OID: ObjectIdentifier = match ecdsa_oid_for_digest(C::Digest::OID) {
473477
Some(oid) => oid,
474-
None => panic!("no RFC5758 ECDSA OID defined for DigestPrimitive::Digest"),
478+
None => panic!("no RFC5758 ECDSA OID defined for DigestAlgorithm::Digest"),
475479
};
476480
}
477481

@@ -713,29 +717,29 @@ where
713717
}
714718

715719
/// NOTE: this implementation assumes the default digest for the given elliptic
716-
/// curve as defined by [`hazmat::DigestPrimitive`].
720+
/// curve as defined by [`DigestAlgorithm`].
717721
///
718722
/// When working with alternative digests, you will need to use e.g.
719723
/// [`SignatureWithOid::new_with_digest`].
720-
#[cfg(all(feature = "digest", feature = "hazmat"))]
724+
#[cfg(feature = "digest")]
721725
impl<C> SignatureEncoding for SignatureWithOid<C>
722726
where
723-
C: hazmat::DigestPrimitive,
727+
C: DigestAlgorithm,
724728
C::Digest: AssociatedOid,
725729
SignatureSize<C>: ArraySize,
726730
{
727731
type Repr = SignatureBytes<C>;
728732
}
729733

730734
/// NOTE: this implementation assumes the default digest for the given elliptic
731-
/// curve as defined by [`hazmat::DigestPrimitive`].
735+
/// curve as defined by [`DigestAlgorithm`].
732736
///
733737
/// When working with alternative digests, you will need to use e.g.
734738
/// [`SignatureWithOid::new_with_digest`].
735-
#[cfg(all(feature = "digest", feature = "hazmat"))]
739+
#[cfg(feature = "digest")]
736740
impl<C> TryFrom<&[u8]> for SignatureWithOid<C>
737741
where
738-
C: hazmat::DigestPrimitive,
742+
C: DigestAlgorithm,
739743
C::Digest: AssociatedOid,
740744
SignatureSize<C>: ArraySize,
741745
{
@@ -770,3 +774,29 @@ const fn ecdsa_oid_for_digest(digest_oid: ObjectIdentifier) -> Option<ObjectIden
770774
_ => None,
771775
}
772776
}
777+
778+
/// Bind a preferred [`Digest`] algorithm to an elliptic curve type.
779+
///
780+
/// Generally there is a preferred variety of the SHA-2 family used with ECDSA
781+
/// for a particular elliptic curve.
782+
///
783+
/// This trait can be used to specify it, and with it receive a blanket impl of
784+
/// [`PrehashSignature`], used by [`signature_derive`][1]) for the [`Signature`]
785+
/// type for a particular elliptic curve.
786+
///
787+
/// [1]: https://github.com/RustCrypto/traits/tree/master/signature/derive
788+
#[cfg(feature = "digest")]
789+
pub trait DigestAlgorithm: EcdsaCurve {
790+
/// Preferred digest to use when computing ECDSA signatures for this
791+
/// elliptic curve. This is typically a member of the SHA-2 family.
792+
type Digest: BlockSizeUser + Digest + FixedOutput + FixedOutputReset;
793+
}
794+
795+
#[cfg(feature = "digest")]
796+
impl<C> PrehashSignature for Signature<C>
797+
where
798+
C: DigestAlgorithm,
799+
<FieldBytesSize<C> as Add>::Output: ArraySize,
800+
{
801+
type Digest = C::Digest;
802+
}

0 commit comments

Comments
 (0)