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.
Implementations§
Source§impl<C> Signature<C>
impl<C> Signature<C>
Sourcepub fn from_der(bytes: &[u8]) -> Result<Self>where
MaxSize<C>: ArrayLength<u8>,
<FieldSize<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>,
<FieldSize<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_der(&self) -> Signature<C>where
MaxSize<C>: ArrayLength<u8>,
<FieldSize<C> as Add>::Output: Add<MaxOverhead> + ArrayLength<u8>,
Available on crate feature der
only.
pub fn to_der(&self) -> Signature<C>where
MaxSize<C>: ArrayLength<u8>,
<FieldSize<C> as Add>::Output: Add<MaxOverhead> + ArrayLength<u8>,
der
only.Serialize this signature as ASN.1 DER
Source§impl<C> Signature<C>
impl<C> Signature<C>
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>where
Scalar<C>: NormalizeLow,
Available on crate feature arithmetic
only.
pub fn normalize_s(&self) -> Option<Self>where
Scalar<C>: NormalizeLow,
arithmetic
only.Normalize signature into “low S” form as described in BIP 0062: Dealing with Malleability.
Trait Implementations§
Source§impl<C, D> DigestSigner<D, Signature<C>> for SigningKey<C>where
C: PrimeCurve + ProjectiveArithmetic,
D: FixedOutput<OutputSize = FieldSize<C>> + BlockInput + Clone + Default + Reset + Update,
Scalar<C>: FromDigest<C> + Invert<Output = Scalar<C>> + SignPrimitive<C>,
SignatureSize<C>: ArrayLength<u8>,
impl<C, D> DigestSigner<D, Signature<C>> for SigningKey<C>where
C: PrimeCurve + ProjectiveArithmetic,
D: FixedOutput<OutputSize = FieldSize<C>> + BlockInput + Clone + Default + Reset + Update,
Scalar<C>: FromDigest<C> + Invert<Output = Scalar<C>> + SignPrimitive<C>,
SignatureSize<C>: ArrayLength<u8>,
Source§fn try_sign_digest(&self, digest: D) -> Result<Signature<C>>
fn try_sign_digest(&self, digest: D) -> Result<Signature<C>>
Sign message prehash using a deterministic ephemeral scalar (k
)
computed using the algorithm described in RFC 6979 (Section 3.2):
https://tools.ietf.org/html/rfc6979#section-3
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<OutputSize = FieldSize<C>>,
AffinePoint<C>: VerifyPrimitive<C>,
Scalar<C>: FromDigest<C>,
SignatureSize<C>: ArrayLength<u8>,
impl<C, D> DigestVerifier<D, Signature<C>> for VerifyingKey<C>where
C: PrimeCurve + ProjectiveArithmetic,
D: Digest<OutputSize = FieldSize<C>>,
AffinePoint<C>: VerifyPrimitive<C>,
Scalar<C>: FromDigest<C>,
SignatureSize<C>: ArrayLength<u8>,
Source§impl<C> PrehashSignature for Signature<C>
Available on crate feature hazmat
only.
impl<C> PrehashSignature for Signature<C>
hazmat
only.Source§type Digest = <C as DigestPrimitive>::Digest
type Digest = <C as DigestPrimitive>::Digest
Digest
algorithm to use when computing this signature type.Source§impl<C, D> RandomizedDigestSigner<D, Signature<C>> for SigningKey<C>where
C: PrimeCurve + ProjectiveArithmetic,
D: FixedOutput<OutputSize = FieldSize<C>> + BlockInput + Clone + Default + Reset + Update,
Scalar<C>: FromDigest<C> + Invert<Output = Scalar<C>> + SignPrimitive<C>,
SignatureSize<C>: ArrayLength<u8>,
impl<C, D> RandomizedDigestSigner<D, Signature<C>> for SigningKey<C>where
C: PrimeCurve + ProjectiveArithmetic,
D: FixedOutput<OutputSize = FieldSize<C>> + BlockInput + Clone + Default + Reset + Update,
Scalar<C>: FromDigest<C> + Invert<Output = Scalar<C>> + SignPrimitive<C>,
SignatureSize<C>: ArrayLength<u8>,
Source§impl<C> RandomizedSigner<Signature<C>> for SigningKey<C>where
Self: RandomizedDigestSigner<C::Digest, Signature<C>>,
C: PrimeCurve + ProjectiveArithmetic + DigestPrimitive,
Scalar<C>: FromDigest<C> + Invert<Output = Scalar<C>> + SignPrimitive<C>,
SignatureSize<C>: ArrayLength<u8>,
impl<C> RandomizedSigner<Signature<C>> for SigningKey<C>where
Self: RandomizedDigestSigner<C::Digest, Signature<C>>,
C: PrimeCurve + ProjectiveArithmetic + DigestPrimitive,
Scalar<C>: FromDigest<C> + Invert<Output = Scalar<C>> + SignPrimitive<C>,
SignatureSize<C>: ArrayLength<u8>,
Source§impl<C> Signer<Signature<C>> for SigningKey<C>where
Self: DigestSigner<C::Digest, Signature<C>>,
C: PrimeCurve + ProjectiveArithmetic + DigestPrimitive,
Scalar<C>: FromDigest<C> + Invert<Output = Scalar<C>> + SignPrimitive<C>,
SignatureSize<C>: ArrayLength<u8>,
impl<C> Signer<Signature<C>> for SigningKey<C>where
Self: DigestSigner<C::Digest, Signature<C>>,
C: PrimeCurve + ProjectiveArithmetic + DigestPrimitive,
Scalar<C>: FromDigest<C> + Invert<Output = Scalar<C>> + SignPrimitive<C>,
SignatureSize<C>: ArrayLength<u8>,
Source§impl<C> TryFrom<Signature<C>> for Signature<C>where
C: PrimeCurve,
MaxSize<C>: ArrayLength<u8>,
<FieldSize<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>,
<FieldSize<C> as Add>::Output: Add<MaxOverhead> + ArrayLength<u8>,
der
only.