Struct ecdsa::SigningKey

source ·
pub struct SigningKey<C>{ /* private fields */ }
Expand description

ECDSA secret key used for signing. Generic over prime order elliptic curves (e.g. NIST P-curves)

Requires an elliptic_curve::CurveArithmetic impl on the curve, and a SignPrimitive impl on its associated Scalar type.

§Usage

The signature crate defines the following traits which are the primary API for signing:

See the p256 crate for examples of using this type with a concrete elliptic curve.

Implementations§

source§

impl<C> SigningKey<C>

source

pub fn sign_prehash_recoverable( &self, prehash: &[u8], ) -> Result<(Signature<C>, RecoveryId)>

Sign the given message prehash, returning a signature and recovery ID.

source

pub fn sign_digest_recoverable<D>( &self, msg_digest: D, ) -> Result<(Signature<C>, RecoveryId)>
where D: Digest,

Sign the given message digest, returning a signature and recovery ID.

source

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

Sign the given message, hashing it with the curve’s default digest function, and returning a signature and recovery ID.

source§

impl<C> SigningKey<C>

source

pub fn random(rng: &mut impl CryptoRngCore) -> Self

Generate a cryptographically random SigningKey.

source

pub fn from_bytes(bytes: &FieldBytes<C>) -> Result<Self>

Initialize signing key from a raw scalar serialized as a byte array.

source

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

Initialize signing key from a raw scalar serialized as a byte slice.

source

pub fn to_bytes(&self) -> FieldBytes<C>

Serialize this SigningKey as bytes

source

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

Borrow the secret NonZeroScalar value for this key.

§⚠️ Warning

This value is key material.

Please treat it with the care it deserves!

source

pub fn verifying_key(&self) -> &VerifyingKey<C>

Get the VerifyingKey which corresponds to this SigningKey.

Trait Implementations§

source§

impl<C> AsRef<VerifyingKey<C>> for SigningKey<C>

source§

fn as_ref(&self) -> &VerifyingKey<C>

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

impl<C> Clone for SigningKey<C>

source§

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

Returns a copy 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> ConstantTimeEq for SigningKey<C>

source§

fn ct_eq(&self, other: &Self) -> Choice

Determine if two items are equal. Read more
source§

fn ct_ne(&self, other: &Self) -> Choice

Determine if two items are NOT equal. Read more
source§

impl<C> Debug for SigningKey<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>, RecoveryId)> for SigningKey<C>

source§

fn try_sign_digest(&self, msg_digest: D) -> Result<(Signature<C>, RecoveryId)>

Attempt to sign the given prehashed message Digest, returning a digital signature on success, or an error if something went wrong.
source§

fn sign_digest(&self, digest: D) -> S

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

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

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>>

Attempt to sign the given prehashed message Digest, returning a digital signature on success, or an error if something went wrong.
source§

fn sign_digest(&self, digest: D) -> S

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

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

source§

fn try_sign_digest(&self, msg_digest: D) -> Result<SignatureWithOid<C>>

Attempt to sign the given prehashed message Digest, returning a digital signature on success, or an error if something went wrong.
source§

fn sign_digest(&self, digest: D) -> S

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

impl<C> Drop for SigningKey<C>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl<C> From<&SecretKey<C>> for SigningKey<C>

source§

fn from(secret_key: &SecretKey<C>) -> Self

Converts to this type from the input type.
source§

impl<C> From<&SigningKey<C>> for SecretKey<C>

source§

fn from(secret_key: &SigningKey<C>) -> Self

Converts to this type from the input type.
source§

impl<C> From<&SigningKey<C>> for VerifyingKey<C>

source§

fn from(signing_key: &SigningKey<C>) -> VerifyingKey<C>

Converts to this type from the input type.
source§

impl<C> From<NonZeroScalar<C>> for SigningKey<C>

source§

fn from(secret_scalar: NonZeroScalar<C>) -> Self

Converts to this type from the input type.
source§

impl<C> From<SecretKey<C>> for SigningKey<C>

source§

fn from(secret_key: SecretKey<C>) -> Self

Converts to this type from the input type.
source§

impl<C> From<SigningKey<C>> for SecretKey<C>

source§

fn from(key: SigningKey<C>) -> Self

Converts to this type from the input type.
source§

impl<C> From<SigningKey<C>> for VerifyingKey<C>

source§

fn from(signing_key: SigningKey<C>) -> VerifyingKey<C>

Converts to this type from the input type.
source§

impl<C> KeypairRef for SigningKey<C>

§

type VerifyingKey = VerifyingKey<C>

Verifying key type for this keypair.
source§

impl<C> PartialEq for SigningKey<C>

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<C> PrehashSigner<(Signature<C>, RecoveryId)> for SigningKey<C>

source§

fn sign_prehash(&self, prehash: &[u8]) -> Result<(Signature<C>, RecoveryId)>

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

impl<C> PrehashSigner<Signature<C>> for SigningKey<C>

source§

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

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

impl<C> PrehashSigner<Signature<C>> for SigningKey<C>

Sign message prehash using a deterministic ephemeral scalar (k) computed using the algorithm described in RFC6979 § 3.2.

source§

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

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

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

source§

fn try_sign_digest_with_rng( &self, rng: &mut impl CryptoRngCore, msg_digest: D, ) -> Result<Signature<C>>

Attempt to sign the given prehashed message 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

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

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

source§

fn try_sign_digest_with_rng( &self, rng: &mut impl CryptoRngCore, msg_digest: D, ) -> Result<Signature<C>>

Attempt to sign the given prehashed message 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

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

impl<C> RandomizedPrehashSigner<Signature<C>> for SigningKey<C>

source§

fn sign_prehash_with_rng( &self, rng: &mut impl CryptoRngCore, prehash: &[u8], ) -> Result<Signature<C>>

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

impl<C> RandomizedPrehashSigner<Signature<C>> for SigningKey<C>

source§

fn sign_prehash_with_rng( &self, rng: &mut impl CryptoRngCore, prehash: &[u8], ) -> Result<Signature<C>>

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

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

source§

fn try_sign_with_rng( &self, rng: &mut impl CryptoRngCore, 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: &mut impl CryptoRngCore, msg: &[u8]) -> S

Sign the given message and return a digital signature
source§

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

source§

fn try_sign_with_rng( &self, rng: &mut impl CryptoRngCore, 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: &mut impl CryptoRngCore, msg: &[u8]) -> S

Sign the given message and return a digital signature
source§

impl<C> Signer<(Signature<C>, RecoveryId)> for SigningKey<C>

source§

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

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> 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> Signer<Signature<C>> for SigningKey<C>

Sign message using a deterministic ephemeral scalar (k) computed using the algorithm described in RFC6979 § 3.2.

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> Signer<SignatureWithOid<C>> for SigningKey<C>

source§

fn try_sign(&self, msg: &[u8]) -> Result<SignatureWithOid<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 SigningKey<C>

§

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> Eq for SigningKey<C>

Constant-time comparison

source§

impl<C> ZeroizeOnDrop for SigningKey<C>

Auto Trait Implementations§

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§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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<K> Keypair for K
where K: KeypairRef,

§

type VerifyingKey = <K as KeypairRef>::VerifyingKey

Verifying key type for this keypair.
source§

fn verifying_key(&self) -> <K as Keypair>::VerifyingKey

Get the verifying key which can verify signatures produced by the signing key portion of this keypair.
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<S, T> SignerMut<S> for T
where T: Signer<S>,

source§

fn try_sign(&mut self, msg: &[u8]) -> Result<S, Error>

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

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

Sign the given message, update the state, and return a digital signature.
source§

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

§

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>,

§

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>,

§

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.