Skip to content

Commit f9c773e

Browse files
committed
ecdsa: Signer would only be implemented with hazmat
1 parent 37b1204 commit f9c773e

File tree

7 files changed

+62
-56
lines changed

7 files changed

+62
-56
lines changed

ecdsa/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -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::DigestPrimitive,
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 = "`DigestPrimitive` is no longer in `hazmat`, please use `ecdsa::DigestPrimitive` instead"
43+
)]
44+
pub use crate::DigestPrimitive;
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

+41-11
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,10 +467,10 @@ 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: DigestPrimitive,
470474
C::Digest: AssociatedOid,
471475
{
472476
const OID: ObjectIdentifier = match ecdsa_oid_for_digest(C::Digest::OID) {
@@ -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 [`DigestPrimitive`].
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: DigestPrimitive,
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 [`DigestPrimitive`].
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: DigestPrimitive,
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 DigestPrimitive: 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: DigestPrimitive,
799+
<FieldBytesSize<C> as Add>::Output: ArraySize,
800+
{
801+
type Digest = C::Digest;
802+
}

ecdsa/src/recovery.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@ use {
2828

2929
#[cfg(any(feature = "signing", feature = "verifying"))]
3030
use {
31-
crate::{
32-
EcdsaCurve, Signature, SignatureSize,
33-
hazmat::{DigestPrimitive, bits2field},
34-
},
31+
crate::{DigestPrimitive, EcdsaCurve, Signature, SignatureSize, hazmat::bits2field},
3532
elliptic_curve::{CurveArithmetic, Scalar, array::ArraySize, ops::Invert},
3633
signature::digest::Digest,
3734
};

ecdsa/src/signing.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
//! ECDSA signing: producing signatures using a [`SigningKey`].
22
33
use crate::{
4-
EcdsaCurve, Error, Result, Signature, SignatureSize, SignatureWithOid, ecdsa_oid_for_digest,
5-
hazmat::{DigestPrimitive, bits2field, sign_prehashed_rfc6979},
4+
DigestPrimitive, EcdsaCurve, Error, Result, Signature, SignatureSize, SignatureWithOid,
5+
ecdsa_oid_for_digest,
6+
hazmat::{bits2field, sign_prehashed_rfc6979},
67
};
78
use core::fmt::{self, Debug};
89
use digest::{Digest, FixedOutput, const_oid::AssociatedOid};

ecdsa/src/verifying.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use crate::{
44
EcdsaCurve, Error, Result, Signature, SignatureSize,
5-
hazmat::{self, DigestPrimitive, bits2field},
5+
hazmat::{self, bits2field},
66
};
77
use core::{cmp::Ordering, fmt::Debug};
88
use elliptic_curve::{
@@ -13,7 +13,7 @@ use elliptic_curve::{
1313
sec1::{self, CompressedPoint, EncodedPoint, FromEncodedPoint, ToEncodedPoint},
1414
};
1515
use signature::{
16-
DigestVerifier, Verifier,
16+
DigestVerifier,
1717
digest::{Digest, FixedOutput},
1818
hazmat::PrehashVerifier,
1919
};
@@ -42,9 +42,11 @@ use serdect::serde::{Deserialize, Serialize, de, ser};
4242
#[cfg(feature = "sha2")]
4343
use {
4444
crate::{
45-
ECDSA_SHA224_OID, ECDSA_SHA256_OID, ECDSA_SHA384_OID, ECDSA_SHA512_OID, SignatureWithOid,
45+
DigestPrimitive, ECDSA_SHA224_OID, ECDSA_SHA256_OID, ECDSA_SHA384_OID, ECDSA_SHA512_OID,
46+
SignatureWithOid,
4647
},
4748
sha2::{Sha224, Sha256, Sha384, Sha512},
49+
signature::Verifier,
4850
};
4951

5052
#[cfg(all(feature = "alloc", feature = "pkcs8"))]

0 commit comments

Comments
 (0)