Struct Signature

Source
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-endian
  • s: 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>

Source

pub fn from_der(bytes: &[u8]) -> Result<Self>

Available on crate feature der only.

Parse a signature from ASN.1 DER

Source

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.

Source

pub fn split_bytes(&self) -> (FieldBytes<C>, FieldBytes<C>)

Split the signature into its r and s components, represented as bytes.

Source

pub fn to_der(&self) -> Signature<C>

Available on crate feature der only.

Serialize this signature as ASN.1 DER

Source§

impl<C> Signature<C>

Source

pub fn r(&self) -> NonZeroScalar<C>

Available on crate feature arithmetic only.

Get the r component of this signature

Source

pub fn s(&self) -> NonZeroScalar<C>

Available on crate feature arithmetic only.

Get the s component of this signature

Source

pub fn split_scalars(&self) -> (NonZeroScalar<C>, NonZeroScalar<C>)

Available on crate feature arithmetic only.

Split the signature into its r and s scalars.

Source

pub fn normalize_s(&self) -> Option<Self>
where Scalar<C>: NormalizeLow,

Available on crate feature arithmetic only.

Normalize signature into “low S” form as described in BIP 0062: Dealing with Malleability.

Trait Implementations§

Source§

impl<C> AsRef<[u8]> for Signature<C>

Source§

fn as_ref(&self) -> &[u8]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<C: Clone + PrimeCurve> Clone for Signature<C>

Source§

fn clone(&self) -> Signature<C>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<C> Debug for Signature<C>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<C, D> DigestSigner<D, Signature<C>> for SigningKey<C>

Source§

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

Sign the given prehashed message Digest, returning a signature. Read more
Source§

impl<C, D> DigestVerifier<D, Signature<C>> for VerifyingKey<C>

Source§

fn verify_digest(&self, digest: D, signature: &Signature<C>) -> Result<()>

Verify the signature against the given Digest output.
Source§

impl<C: PartialEq + PrimeCurve> PartialEq for Signature<C>

Source§

fn eq(&self, other: &Signature<C>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<C> PrehashSignature for Signature<C>

Available on crate feature hazmat only.
Source§

type Digest = <C as DigestPrimitive>::Digest

Preferred Digest algorithm to use when computing this signature type.
Source§

impl<C, D> RandomizedDigestSigner<D, Signature<C>> for SigningKey<C>

Source§

fn try_sign_digest_with_rng( &self, rng: impl CryptoRng + RngCore, digest: D, ) -> Result<Signature<C>>

Sign message prehash using an ephemeral scalar (k) derived according to a variant of RFC 6979 (Section 3.6) which supplies additional entropy from an RNG.

Source§

fn sign_digest_with_rng(&self, rng: impl CryptoRng + RngCore, digest: D) -> S

Sign the given prehashed message Digest, returning a signature. Read more
Source§

impl<C> RandomizedSigner<Signature<C>> for SigningKey<C>

Source§

fn try_sign_with_rng( &self, rng: impl CryptoRng + RngCore, msg: &[u8], ) -> Result<Signature<C>>

Attempt to sign the given message, returning a digital signature on success, or an error if something went wrong. Read more
Source§

fn sign_with_rng(&self, rng: impl CryptoRng + RngCore, msg: &[u8]) -> S

Sign the given message and return a digital signature
Source§

impl<C> Signature for Signature<C>

Source§

fn from_bytes(bytes: &[u8]) -> Result<Self>

Parse a signature from its byte representation
Source§

fn as_bytes(&self) -> &[u8]

Borrow a byte slice representing the serialized form of this signature
Source§

impl<C> Signer<Signature<C>> for SigningKey<C>

Source§

fn try_sign(&self, msg: &[u8]) -> Result<Signature<C>>

Attempt to sign the given message, returning a digital signature on success, or an error if something went wrong. Read more
Source§

fn sign(&self, msg: &[u8]) -> S

Sign the given message and return a digital signature
Source§

impl<C> TryFrom<&[u8]> for Signature<C>

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(bytes: &[u8]) -> Result<Self>

Performs the conversion.
Source§

impl<C> TryFrom<Signature<C>> for Signature<C>

Available on crate feature der only.
Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(sig: Signature<C>) -> Result<Signature<C>>

Performs the conversion.
Source§

impl<C> Verifier<Signature<C>> for VerifyingKey<C>

Source§

fn verify(&self, msg: &[u8], signature: &Signature<C>) -> Result<()>

Use Self to verify that the provided signature for a given message bytestring is authentic. Read more
Source§

impl<C> Copy for Signature<C>

Source§

impl<C: Eq + PrimeCurve> Eq for Signature<C>

Source§

impl<C: PrimeCurve> StructuralPartialEq for Signature<C>

Auto Trait Implementations§

§

impl<C> Freeze for Signature<C>

§

impl<C> RefUnwindSafe for Signature<C>

§

impl<C> Send for Signature<C>
where <<<C as Curve>::UInt as ArrayEncoding>::ByteSize as Add>::Output: Sized,

§

impl<C> Sync for Signature<C>
where <<<C as Curve>::UInt as ArrayEncoding>::ByteSize as Add>::Output: Sized,

§

impl<C> Unpin for Signature<C>

§

impl<C> UnwindSafe for Signature<C>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.