pub struct Signature<C: PrimeCurve> { /* private fields */ }
Expand description
ECDSA signature (fixed-size). Generic over elliptic curve types.
Serialized as fixed-sized big endian scalar values with no added framing:
r
: field element size for the given curve, big-endians
: field element size for the given curve, big-endian
For example, in a curve with a 256-bit modulus like NIST P-256 or
secp256k1, r
and s
will both be 32-bytes, resulting in a signature
with a total of 64-bytes.
ASN.1 DER-encoded signatures also supported via the
Signature::from_der
and Signature::to_der
methods.
serde
support
When the serde
feature of this crate is enabled, it provides support for
serializing and deserializing ECDSA signatures using the Serialize
and
Deserialize
traits.
The serialization uses a 64-byte fixed encoding when used with binary formats, and a hexadecimal encoding when used with text formats.
Implementations§
source§impl<C> Signature<C>where
C: PrimeCurve,
SignatureSize<C>: ArrayLength<u8>,
impl<C> Signature<C>where C: PrimeCurve, SignatureSize<C>: ArrayLength<u8>,
sourcepub fn from_bytes(bytes: &SignatureBytes<C>) -> Result<Self>
pub fn from_bytes(bytes: &SignatureBytes<C>) -> Result<Self>
Parse a signature from fixed-with bytes.
sourcepub fn from_slice(slice: &[u8]) -> Result<Self>
pub fn from_slice(slice: &[u8]) -> Result<Self>
Parse a signature from a byte slice.
sourcepub fn from_der(bytes: &[u8]) -> Result<Self>where
MaxSize<C>: ArrayLength<u8>,
<FieldBytesSize<C> as Add>::Output: Add<MaxOverhead> + ArrayLength<u8>,
Available on crate feature der
only.
pub fn from_der(bytes: &[u8]) -> Result<Self>where MaxSize<C>: ArrayLength<u8>, <FieldBytesSize<C> as Add>::Output: Add<MaxOverhead> + ArrayLength<u8>,
der
only.Parse a signature from ASN.1 DER.
sourcepub fn from_scalars(
r: impl Into<FieldBytes<C>>,
s: impl Into<FieldBytes<C>>
) -> Result<Self>
pub fn from_scalars( r: impl Into<FieldBytes<C>>, s: impl Into<FieldBytes<C>> ) -> Result<Self>
Create a Signature
from the serialized r
and s
scalar values
which comprise the signature.
sourcepub fn split_bytes(&self) -> (FieldBytes<C>, FieldBytes<C>)
pub fn split_bytes(&self) -> (FieldBytes<C>, FieldBytes<C>)
Split the signature into its r
and s
components, represented as bytes.
sourcepub fn to_bytes(&self) -> SignatureBytes<C>
pub fn to_bytes(&self) -> SignatureBytes<C>
Serialize this signature as bytes.
source§impl<C> Signature<C>where
C: PrimeCurve + CurveArithmetic,
SignatureSize<C>: ArrayLength<u8>,
impl<C> Signature<C>where C: PrimeCurve + CurveArithmetic, SignatureSize<C>: ArrayLength<u8>,
sourcepub fn r(&self) -> NonZeroScalar<C>
Available on crate feature arithmetic
only.
pub fn r(&self) -> NonZeroScalar<C>
arithmetic
only.Get the r
component of this signature
sourcepub fn s(&self) -> NonZeroScalar<C>
Available on crate feature arithmetic
only.
pub fn s(&self) -> NonZeroScalar<C>
arithmetic
only.Get the s
component of this signature
sourcepub fn split_scalars(&self) -> (NonZeroScalar<C>, NonZeroScalar<C>)
Available on crate feature arithmetic
only.
pub fn split_scalars(&self) -> (NonZeroScalar<C>, NonZeroScalar<C>)
arithmetic
only.Split the signature into its r
and s
scalars.
sourcepub fn normalize_s(&self) -> Option<Self>
Available on crate feature arithmetic
only.
pub fn normalize_s(&self) -> Option<Self>
arithmetic
only.Normalize signature into “low S” form as described in BIP 0062: Dealing with Malleability.
Trait Implementations§
source§impl<C> AssociatedAlgorithmIdentifier for Signature<C>where
C: PrimeCurve,
Self: AssociatedOid,
Available on crate feature pkcs8
only.
impl<C> AssociatedAlgorithmIdentifier for Signature<C>where C: PrimeCurve, Self: AssociatedOid,
pkcs8
only.ECDSA AlgorithmIdentifier
which identifies the digest used by default
with the Signer
and Verifier
traits.
source§impl<C> AssociatedOid for Signature<C>where
C: DigestPrimitive,
C::Digest: AssociatedOid,
Available on crate features digest
and hazmat
only.
impl<C> AssociatedOid for Signature<C>where C: DigestPrimitive, C::Digest: AssociatedOid,
digest
and hazmat
only.ECDSA [ObjectIdentifier
] which identifies the digest used by default
with the Signer
and Verifier
traits.
To support non-default digest algorithms, use the SignatureWithOid
type instead.
source§impl<C> Debug for Signature<C>where
C: PrimeCurve,
SignatureSize<C>: ArrayLength<u8>,
impl<C> Debug for Signature<C>where C: PrimeCurve, SignatureSize<C>: ArrayLength<u8>,
source§impl<'de, C> Deserialize<'de> for Signature<C>where
C: PrimeCurve,
SignatureSize<C>: ArrayLength<u8>,
Available on crate feature serde
only.
impl<'de, C> Deserialize<'de> for Signature<C>where C: PrimeCurve, SignatureSize<C>: ArrayLength<u8>,
serde
only.source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where D: Deserializer<'de>,
source§impl<C, D> DigestSigner<D, Signature<C>> for SigningKey<C>where
C: PrimeCurve + CurveArithmetic + DigestPrimitive,
D: Digest + FixedOutput<OutputSize = FieldBytesSize<C>>,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + SignPrimitive<C>,
SignatureSize<C>: ArrayLength<u8>,
Available on crate feature signing
only.
impl<C, D> DigestSigner<D, Signature<C>> for SigningKey<C>where C: PrimeCurve + CurveArithmetic + DigestPrimitive, D: Digest + FixedOutput<OutputSize = FieldBytesSize<C>>, Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + SignPrimitive<C>, SignatureSize<C>: ArrayLength<u8>,
signing
only.Sign message digest using a deterministic ephemeral scalar (k
)
computed using the algorithm described in RFC6979 § 3.2.
source§fn try_sign_digest(&self, msg_digest: D) -> Result<Signature<C>>
fn try_sign_digest(&self, msg_digest: D) -> Result<Signature<C>>
Digest
, returning a
digital signature on success, or an error if something went wrong.source§fn sign_digest(&self, digest: D) -> S
fn sign_digest(&self, digest: D) -> S
source§impl<C, D> DigestVerifier<D, Signature<C>> for VerifyingKey<C>where
C: PrimeCurve + CurveArithmetic,
D: Digest + FixedOutput<OutputSize = FieldBytesSize<C>>,
AffinePoint<C>: VerifyPrimitive<C>,
SignatureSize<C>: ArrayLength<u8>,
Available on crate feature verifying
only.
impl<C, D> DigestVerifier<D, Signature<C>> for VerifyingKey<C>where C: PrimeCurve + CurveArithmetic, D: Digest + FixedOutput<OutputSize = FieldBytesSize<C>>, AffinePoint<C>: VerifyPrimitive<C>, SignatureSize<C>: ArrayLength<u8>,
verifying
only.source§impl<C> Display for Signature<C>where
C: PrimeCurve,
SignatureSize<C>: ArrayLength<u8>,
impl<C> Display for Signature<C>where C: PrimeCurve, SignatureSize<C>: ArrayLength<u8>,
source§impl<C> From<Signature<C>> for Signature<C>where
C: PrimeCurve,
MaxSize<C>: ArrayLength<u8>,
<FieldBytesSize<C> as Add>::Output: Add<MaxOverhead> + ArrayLength<u8>,
Available on crate feature der
only.
impl<C> From<Signature<C>> for Signature<C>where C: PrimeCurve, MaxSize<C>: ArrayLength<u8>, <FieldBytesSize<C> as Add>::Output: Add<MaxOverhead> + ArrayLength<u8>,
der
only.source§impl<C> From<Signature<C>> for SignatureBytes<C>where
C: PrimeCurve,
SignatureSize<C>: ArrayLength<u8>,
impl<C> From<Signature<C>> for SignatureBytes<C>where C: PrimeCurve, SignatureSize<C>: ArrayLength<u8>,
source§fn from(signature: Signature<C>) -> SignatureBytes<C>
fn from(signature: Signature<C>) -> SignatureBytes<C>
source§impl<C> From<SignatureWithOid<C>> for Signature<C>where
C: PrimeCurve,
Available on crate feature digest
only.
impl<C> From<SignatureWithOid<C>> for Signature<C>where C: PrimeCurve,
digest
only.source§fn from(sig: SignatureWithOid<C>) -> Signature<C>
fn from(sig: SignatureWithOid<C>) -> Signature<C>
source§impl<C> FromStr for Signature<C>where
C: PrimeCurve + CurveArithmetic,
SignatureSize<C>: ArrayLength<u8>,
Available on crate feature arithmetic
only.
impl<C> FromStr for Signature<C>where C: PrimeCurve + CurveArithmetic, SignatureSize<C>: ArrayLength<u8>,
arithmetic
only.source§impl<C> LowerHex for Signature<C>where
C: PrimeCurve,
SignatureSize<C>: ArrayLength<u8>,
impl<C> LowerHex for Signature<C>where C: PrimeCurve, SignatureSize<C>: ArrayLength<u8>,
source§impl<C: PartialEq + PrimeCurve> PartialEq<Signature<C>> for Signature<C>
impl<C: PartialEq + PrimeCurve> PartialEq<Signature<C>> for Signature<C>
source§impl<C> PrehashSignature for Signature<C>where
C: DigestPrimitive,
<FieldBytesSize<C> as Add>::Output: ArrayLength<u8>,
Available on crate features hazmat
and digest
only.
impl<C> PrehashSignature for Signature<C>where C: DigestPrimitive, <FieldBytesSize<C> as Add>::Output: ArrayLength<u8>,
hazmat
and digest
only.§type Digest = <C as DigestPrimitive>::Digest
type Digest = <C as DigestPrimitive>::Digest
Digest
algorithm to use when computing this signature type.source§impl<C> PrehashSigner<Signature<C>> for SigningKey<C>where
C: PrimeCurve + CurveArithmetic + DigestPrimitive,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + SignPrimitive<C>,
SignatureSize<C>: ArrayLength<u8>,
Available on crate feature signing
only.
impl<C> PrehashSigner<Signature<C>> for SigningKey<C>where C: PrimeCurve + CurveArithmetic + DigestPrimitive, Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + SignPrimitive<C>, SignatureSize<C>: ArrayLength<u8>,
signing
only.Sign message prehash using a deterministic ephemeral scalar (k
)
computed using the algorithm described in RFC6979 § 3.2.
source§impl<C> PrehashVerifier<Signature<C>> for VerifyingKey<C>where
C: PrimeCurve + CurveArithmetic,
AffinePoint<C>: VerifyPrimitive<C>,
SignatureSize<C>: ArrayLength<u8>,
Available on crate feature verifying
only.
impl<C> PrehashVerifier<Signature<C>> for VerifyingKey<C>where C: PrimeCurve + CurveArithmetic, AffinePoint<C>: VerifyPrimitive<C>, SignatureSize<C>: ArrayLength<u8>,
verifying
only.source§impl<C, D> RandomizedDigestSigner<D, Signature<C>> for SigningKey<C>where
C: PrimeCurve + CurveArithmetic + DigestPrimitive,
D: Digest + FixedOutput<OutputSize = FieldBytesSize<C>>,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + SignPrimitive<C>,
SignatureSize<C>: ArrayLength<u8>,
Available on crate feature signing
only.
impl<C, D> RandomizedDigestSigner<D, Signature<C>> for SigningKey<C>where C: PrimeCurve + CurveArithmetic + DigestPrimitive, D: Digest + FixedOutput<OutputSize = FieldBytesSize<C>>, Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + SignPrimitive<C>, SignatureSize<C>: ArrayLength<u8>,
signing
only.source§fn try_sign_digest_with_rng(
&self,
rng: &mut impl CryptoRngCore,
msg_digest: D
) -> Result<Signature<C>>
fn try_sign_digest_with_rng( &self, rng: &mut impl CryptoRngCore, msg_digest: D ) -> Result<Signature<C>>
Digest
, returning a
digital signature on success, or an error if something went wrong.source§fn sign_digest_with_rng(&self, rng: &mut impl CryptoRngCore, digest: D) -> S
fn sign_digest_with_rng(&self, rng: &mut impl CryptoRngCore, digest: D) -> S
Digest
, returning a signature. Read moresource§impl<C> RandomizedPrehashSigner<Signature<C>> for SigningKey<C>where
C: PrimeCurve + CurveArithmetic + DigestPrimitive,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + SignPrimitive<C>,
SignatureSize<C>: ArrayLength<u8>,
Available on crate feature signing
only.
impl<C> RandomizedPrehashSigner<Signature<C>> for SigningKey<C>where C: PrimeCurve + CurveArithmetic + DigestPrimitive, Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + SignPrimitive<C>, SignatureSize<C>: ArrayLength<u8>,
signing
only.source§fn sign_prehash_with_rng(
&self,
rng: &mut impl CryptoRngCore,
prehash: &[u8]
) -> Result<Signature<C>>
fn sign_prehash_with_rng( &self, rng: &mut impl CryptoRngCore, prehash: &[u8] ) -> Result<Signature<C>>
source§impl<C> RandomizedSigner<Signature<C>> for SigningKey<C>where
Self: RandomizedDigestSigner<C::Digest, Signature<C>>,
C: PrimeCurve + CurveArithmetic + DigestPrimitive,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + SignPrimitive<C>,
SignatureSize<C>: ArrayLength<u8>,
Available on crate feature signing
only.
impl<C> RandomizedSigner<Signature<C>> for SigningKey<C>where Self: RandomizedDigestSigner<C::Digest, Signature<C>>, C: PrimeCurve + CurveArithmetic + DigestPrimitive, Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + SignPrimitive<C>, SignatureSize<C>: ArrayLength<u8>,
signing
only.source§fn try_sign_with_rng(
&self,
rng: &mut impl CryptoRngCore,
msg: &[u8]
) -> Result<Signature<C>>
fn try_sign_with_rng( &self, rng: &mut impl CryptoRngCore, msg: &[u8] ) -> Result<Signature<C>>
source§fn sign_with_rng(&self, rng: &mut impl CryptoRngCore, msg: &[u8]) -> S
fn sign_with_rng(&self, rng: &mut impl CryptoRngCore, msg: &[u8]) -> S
source§impl<C> Serialize for Signature<C>where
C: PrimeCurve,
SignatureSize<C>: ArrayLength<u8>,
Available on crate feature serde
only.
impl<C> Serialize for Signature<C>where C: PrimeCurve, SignatureSize<C>: ArrayLength<u8>,
serde
only.source§impl<C> SignatureEncoding for Signature<C>where
C: PrimeCurve,
SignatureSize<C>: ArrayLength<u8>,
impl<C> SignatureEncoding for Signature<C>where C: PrimeCurve, SignatureSize<C>: ArrayLength<u8>,
§type Repr = GenericArray<u8, <<C as Curve>::FieldBytesSize as Add<<C as Curve>::FieldBytesSize>>::Output>
type Repr = GenericArray<u8, <<C as Curve>::FieldBytesSize as Add<<C as Curve>::FieldBytesSize>>::Output>
source§fn to_vec(&self) -> Vec<u8, Global>
fn to_vec(&self) -> Vec<u8, Global>
alloc
only.source§fn encoded_len(&self) -> usize
fn encoded_len(&self) -> usize
source§impl<C> Signer<Signature<C>> for SigningKey<C>where
C: PrimeCurve + CurveArithmetic + DigestPrimitive,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + SignPrimitive<C>,
SignatureSize<C>: ArrayLength<u8>,
Available on crate feature signing
only.
impl<C> Signer<Signature<C>> for SigningKey<C>where C: PrimeCurve + CurveArithmetic + DigestPrimitive, Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + SignPrimitive<C>, SignatureSize<C>: ArrayLength<u8>,
signing
only.Sign message using a deterministic ephemeral scalar (k
)
computed using the algorithm described in RFC6979 § 3.2.
source§impl<C> TryFrom<&[u8]> for Signature<C>where
C: PrimeCurve,
SignatureSize<C>: ArrayLength<u8>,
impl<C> TryFrom<&[u8]> for Signature<C>where C: PrimeCurve, SignatureSize<C>: ArrayLength<u8>,
source§impl<C> TryFrom<Signature<C>> for Signature<C>where
C: PrimeCurve,
MaxSize<C>: ArrayLength<u8>,
<FieldBytesSize<C> as Add>::Output: Add<MaxOverhead> + ArrayLength<u8>,
Available on crate feature der
only.
impl<C> TryFrom<Signature<C>> for Signature<C>where C: PrimeCurve, MaxSize<C>: ArrayLength<u8>, <FieldBytesSize<C> as Add>::Output: Add<MaxOverhead> + ArrayLength<u8>,
der
only.source§impl<C> UpperHex for Signature<C>where
C: PrimeCurve,
SignatureSize<C>: ArrayLength<u8>,
impl<C> UpperHex for Signature<C>where C: PrimeCurve, SignatureSize<C>: ArrayLength<u8>,
source§impl<C> Verifier<Signature<C>> for VerifyingKey<C>where
C: PrimeCurve + CurveArithmetic + DigestPrimitive,
AffinePoint<C>: VerifyPrimitive<C>,
SignatureSize<C>: ArrayLength<u8>,
Available on crate feature verifying
only.
impl<C> Verifier<Signature<C>> for VerifyingKey<C>where C: PrimeCurve + CurveArithmetic + DigestPrimitive, AffinePoint<C>: VerifyPrimitive<C>, SignatureSize<C>: ArrayLength<u8>,
verifying
only.impl<C> Copy for Signature<C>where C: PrimeCurve, SignatureSize<C>: ArrayLength<u8>, <SignatureSize<C> as ArrayLength<u8>>::ArrayType: Copy,
impl<C: Eq + PrimeCurve> Eq for Signature<C>
impl<C: PrimeCurve> StructuralEq for Signature<C>
impl<C: PrimeCurve> StructuralPartialEq for Signature<C>
Auto Trait Implementations§
impl<C> RefUnwindSafe for Signature<C>where <C as Curve>::Uint: RefUnwindSafe,
impl<C> Send for Signature<C>
impl<C> Sync for Signature<C>
impl<C> Unpin for Signature<C>where <C as Curve>::Uint: Unpin,
impl<C> UnwindSafe for Signature<C>where <C as Curve>::Uint: UnwindSafe,
Blanket Implementations§
§impl<T> DynAssociatedAlgorithmIdentifier for Twhere
T: AssociatedAlgorithmIdentifier,
impl<T> DynAssociatedAlgorithmIdentifier for Twhere T: AssociatedAlgorithmIdentifier,
§fn algorithm_identifier(&self) -> Result<AlgorithmIdentifier<Any>, Error>
fn algorithm_identifier(&self) -> Result<AlgorithmIdentifier<Any>, Error>
AlgorithmIdentifier
for this structure.