pub struct Signature<C: PrimeCurve>where
SignatureSize<C>: ArrayLength<u8>,{ /* 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_der(bytes: &[u8]) -> Result<Self>where
MaxSize<C>: ArrayLength<u8>,
<FieldSize<C> as Add>::Output: Add<MaxOverhead> + ArrayLength<u8>,
pub fn from_der(bytes: &[u8]) -> Result<Self>where MaxSize<C>: ArrayLength<u8>, <FieldSize<C> as Add>::Output: Add<MaxOverhead> + ArrayLength<u8>,
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_der(&self) -> Signature<C>where
MaxSize<C>: ArrayLength<u8>,
<FieldSize<C> as Add>::Output: Add<MaxOverhead> + ArrayLength<u8>,
pub fn to_der(&self) -> Signature<C>where MaxSize<C>: ArrayLength<u8>, <FieldSize<C> as Add>::Output: Add<MaxOverhead> + ArrayLength<u8>,
Serialize this signature as ASN.1 DER
source§impl<C> Signature<C>where
C: PrimeCurve + ScalarArithmetic,
SignatureSize<C>: ArrayLength<u8>,
impl<C> Signature<C>where C: PrimeCurve + ScalarArithmetic, SignatureSize<C>: ArrayLength<u8>,
sourcepub fn r(&self) -> NonZeroScalar<C>
pub fn r(&self) -> NonZeroScalar<C>
Get the r
component of this signature
sourcepub fn s(&self) -> NonZeroScalar<C>
pub fn s(&self) -> NonZeroScalar<C>
Get the s
component of this signature
sourcepub fn split_scalars(&self) -> (NonZeroScalar<C>, NonZeroScalar<C>)
pub fn split_scalars(&self) -> (NonZeroScalar<C>, NonZeroScalar<C>)
Split the signature into its r
and s
scalars.
sourcepub fn normalize_s(&self) -> Option<Self>
pub fn normalize_s(&self) -> Option<Self>
Normalize signature into “low S” form as described in BIP 0062: Dealing with Malleability.
Trait Implementations§
source§impl<C> AsRef<[u8]> for Signature<C>where
C: PrimeCurve,
SignatureSize<C>: ArrayLength<u8>,
impl<C> AsRef<[u8]> for Signature<C>where C: PrimeCurve, SignatureSize<C>: ArrayLength<u8>,
source§impl<C: Clone + PrimeCurve> Clone for Signature<C>where
SignatureSize<C>: ArrayLength<u8>,
impl<C: Clone + PrimeCurve> Clone for Signature<C>where SignatureSize<C>: ArrayLength<u8>,
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<C, D> DigestSigner<D, Signature<C>> for SigningKey<C>where
C: PrimeCurve + ProjectiveArithmetic,
C::UInt: for<'a> From<&'a Scalar<C>>,
D: Digest + BlockSizeUser + FixedOutput<OutputSize = FieldSize<C>> + FixedOutputReset,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + Reduce<C::UInt> + SignPrimitive<C>,
SignatureSize<C>: ArrayLength<u8>,
impl<C, D> DigestSigner<D, Signature<C>> for SigningKey<C>where C: PrimeCurve + ProjectiveArithmetic, C::UInt: for<'a> From<&'a Scalar<C>>, D: Digest + BlockSizeUser + FixedOutput<OutputSize = FieldSize<C>> + FixedOutputReset, Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + Reduce<C::UInt> + SignPrimitive<C>, SignatureSize<C>: ArrayLength<u8>,
source§fn try_sign_digest(&self, msg_digest: D) -> Result<Signature<C>>
fn try_sign_digest(&self, msg_digest: D) -> Result<Signature<C>>
Sign message digest using a deterministic ephemeral scalar (k
)
computed using the algorithm described in RFC6979 § 3.2.
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 + ProjectiveArithmetic,
D: Digest + FixedOutput<OutputSize = FieldSize<C>>,
AffinePoint<C>: VerifyPrimitive<C>,
Scalar<C>: Reduce<C::UInt>,
SignatureSize<C>: ArrayLength<u8>,
impl<C, D> DigestVerifier<D, Signature<C>> for VerifyingKey<C>where C: PrimeCurve + ProjectiveArithmetic, D: Digest + FixedOutput<OutputSize = FieldSize<C>>, AffinePoint<C>: VerifyPrimitive<C>, Scalar<C>: Reduce<C::UInt>, SignatureSize<C>: ArrayLength<u8>,
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> FromStr for Signature<C>where
C: PrimeCurve + ScalarArithmetic,
SignatureSize<C>: ArrayLength<u8>,
impl<C> FromStr for Signature<C>where C: PrimeCurve + ScalarArithmetic, SignatureSize<C>: ArrayLength<u8>,
source§impl<C> Keypair<Signature<C>> for SigningKey<C>where
C: PrimeCurve + ProjectiveArithmetic,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + Reduce<C::UInt> + SignPrimitive<C>,
SignatureSize<C>: ArrayLength<u8>,
impl<C> Keypair<Signature<C>> for SigningKey<C>where C: PrimeCurve + ProjectiveArithmetic, Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + Reduce<C::UInt> + SignPrimitive<C>, SignatureSize<C>: ArrayLength<u8>,
§type VerifyingKey = VerifyingKey<C>
type VerifyingKey = VerifyingKey<C>
source§fn verifying_key(&self) -> &Self::VerifyingKey
fn verifying_key(&self) -> &Self::VerifyingKey
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>where
SignatureSize<C>: ArrayLength<u8>,
impl<C: PartialEq + PrimeCurve> PartialEq<Signature<C>> for Signature<C>where SignatureSize<C>: ArrayLength<u8>,
source§impl<C> PrehashSignature for Signature<C>where
C: DigestPrimitive,
<FieldSize<C> as Add>::Output: ArrayLength<u8>,
impl<C> PrehashSignature for Signature<C>where C: DigestPrimitive, <FieldSize<C> as Add>::Output: ArrayLength<u8>,
§type Digest = <C as DigestPrimitive>::Digest
type Digest = <C as DigestPrimitive>::Digest
Digest
algorithm to use when computing this signature type.