Skip to content

Commit 5ebcfef

Browse files
authored
ecdsa: impl SignatureAlgorithmIdentifier (#688)
Propagates the `AssociatedAlgorithmIdentifier` from `Signature<C>` to `SigningKey<C>` and `VerifyingKey<C>`.
1 parent 56dd91a commit 5ebcfef

File tree

3 files changed

+44
-8
lines changed

3 files changed

+44
-8
lines changed

Cargo.lock

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

ecdsa/src/signing.rs

+20-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@ use {
3131

3232
#[cfg(feature = "pkcs8")]
3333
use crate::elliptic_curve::{
34-
pkcs8::{self, AssociatedOid},
34+
pkcs8::{
35+
self,
36+
der::AnyRef,
37+
spki::{AlgorithmIdentifier, AssociatedAlgorithmIdentifier, SignatureAlgorithmIdentifier},
38+
AssociatedOid,
39+
},
3540
sec1::{self, FromEncodedPoint, ToEncodedPoint},
3641
AffinePoint,
3742
};
@@ -364,8 +369,6 @@ where
364369
SignatureSize<C>: ArrayLength<u8>,
365370
{
366371
}
367-
368-
/// Constant-time comparison
369372
impl<C> PartialEq for SigningKey<C>
370373
where
371374
C: PrimeCurve + CurveArithmetic,
@@ -494,6 +497,20 @@ where
494497
type VerifyingKey = VerifyingKey<C>;
495498
}
496499

500+
#[cfg(feature = "pkcs8")]
501+
impl<C> SignatureAlgorithmIdentifier for SigningKey<C>
502+
where
503+
C: PrimeCurve + CurveArithmetic,
504+
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + SignPrimitive<C>,
505+
SignatureSize<C>: ArrayLength<u8>,
506+
Signature<C>: AssociatedAlgorithmIdentifier<Params = AnyRef<'static>>,
507+
{
508+
type Params = AnyRef<'static>;
509+
510+
const SIGNATURE_ALGORITHM_IDENTIFIER: AlgorithmIdentifier<Self::Params> =
511+
Signature::<C>::ALGORITHM_IDENTIFIER;
512+
}
513+
497514
#[cfg(feature = "pkcs8")]
498515
impl<C> TryFrom<pkcs8::PrivateKeyInfo<'_>> for SigningKey<C>
499516
where

ecdsa/src/verifying.rs

+20-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,12 @@ use {
3030
};
3131

3232
#[cfg(feature = "pkcs8")]
33-
use elliptic_curve::pkcs8::{self, AssociatedOid};
33+
use elliptic_curve::pkcs8::{
34+
self,
35+
der::AnyRef,
36+
spki::{AlgorithmIdentifier, AssociatedAlgorithmIdentifier, SignatureAlgorithmIdentifier},
37+
AssociatedOid,
38+
};
3439

3540
#[cfg(all(feature = "pem", feature = "serde"))]
3641
use serdect::serde::{de, ser, Deserialize, Serialize};
@@ -353,6 +358,20 @@ where
353358
}
354359
}
355360

361+
#[cfg(feature = "pkcs8")]
362+
impl<C> SignatureAlgorithmIdentifier for VerifyingKey<C>
363+
where
364+
C: PrimeCurve + CurveArithmetic,
365+
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
366+
FieldBytesSize<C>: sec1::ModulusSize,
367+
Signature<C>: AssociatedAlgorithmIdentifier<Params = AnyRef<'static>>,
368+
{
369+
type Params = AnyRef<'static>;
370+
371+
const SIGNATURE_ALGORITHM_IDENTIFIER: AlgorithmIdentifier<Self::Params> =
372+
Signature::<C>::ALGORITHM_IDENTIFIER;
373+
}
374+
356375
#[cfg(feature = "pkcs8")]
357376
impl<C> TryFrom<pkcs8::SubjectPublicKeyInfoRef<'_>> for VerifyingKey<C>
358377
where

0 commit comments

Comments
 (0)