[][src]Struct ecdsa::SecretKey

pub struct SecretKey<C> where
    C: SecretValue + Curve
{ /* fields omitted */ }
This is supported on crate feature zeroize only.

Elliptic curve secret keys.

This type wraps a secret scalar value, helping to prevent accidental exposure and securely erasing the value from memory when dropped (when the zeroize feature of this crate is enabled).

Parsing PKCS#8 Keys

PKCS#8 is a commonly used format for encoding secret keys (especially ones generated by OpenSSL).

Keys in PKCS#8 format are either binary (ASN.1 BER/DER), or PEM encoded (ASCII) and begin with the following:

-----BEGIN PRIVATE KEY-----

To decode an elliptic curve private key from PKCS#8, enable the pkcs8 feature of this crate (or the pkcs8 feature of a specific RustCrypto elliptic curve crate) and use the [pkcs8::FromPrivateKey] trait to parse it.

When the pem feature of this crate (or a specific RustCrypto elliptic curve crate) is enabled, a FromStr impl is also available.

Implementations

impl<C> SecretKey<C> where
    C: Curve + SecretValue,
    <C as SecretValue>::Secret: Clone,
    <C as SecretValue>::Secret: Zeroize,
    GenericArray<u8, <C as Curve>::FieldSize>: From<<C as SecretValue>::Secret>, 
[src]

pub fn random(rng: impl RngCore + CryptoRng) -> SecretKey<C> where
    C: ProjectiveArithmetic + SecretValue<Secret = NonZeroScalar<C>>,
    GenericArray<u8, <C as Curve>::FieldSize>: From<<<C as ProjectiveArithmetic>::ProjectivePoint as Group>::Scalar>,
    GenericArray<u8, <C as Curve>::FieldSize>: for<'a> From<&'a <<C as ProjectiveArithmetic>::ProjectivePoint as Group>::Scalar>,
    <<C as ProjectiveArithmetic>::ProjectivePoint as Group>::Scalar: PrimeField,
    <<C as ProjectiveArithmetic>::ProjectivePoint as Group>::Scalar: Zeroize,
    <<<C as ProjectiveArithmetic>::ProjectivePoint as Group>::Scalar as PrimeField>::Repr == GenericArray<u8, <C as Curve>::FieldSize>, 
[src]

Generate a random SecretKey

pub fn new(secret_value: <C as SecretValue>::Secret) -> SecretKey<C>[src]

Create a new secret key from a serialized scalar value

pub fn from_bytes(bytes: impl AsRef<[u8]>) -> Result<SecretKey<C>, Error>[src]

Deserialize raw private scalar as a big endian integer

pub fn to_bytes(&self) -> GenericArray<u8, <C as Curve>::FieldSize>[src]

Expose the byte serialization of the value this SecretKey wraps

pub fn secret_value(&self) -> &<C as SecretValue>::Secret[src]

Borrow the inner generic secret value.

Warning

This value is key material.

Please treat it with the care it deserves!

pub fn secret_scalar(
    &self
) -> &<<C as ProjectiveArithmetic>::ProjectivePoint as Group>::Scalar where
    C: ProjectiveArithmetic + SecretValue<Secret = NonZeroScalar<C>>,
    GenericArray<u8, <C as Curve>::FieldSize>: From<<<C as ProjectiveArithmetic>::ProjectivePoint as Group>::Scalar>,
    GenericArray<u8, <C as Curve>::FieldSize>: for<'a> From<&'a <<C as ProjectiveArithmetic>::ProjectivePoint as Group>::Scalar>,
    <<C as ProjectiveArithmetic>::ProjectivePoint as Group>::Scalar: PrimeField,
    <<C as ProjectiveArithmetic>::ProjectivePoint as Group>::Scalar: Zeroize,
    <<<C as ProjectiveArithmetic>::ProjectivePoint as Group>::Scalar as PrimeField>::Repr == GenericArray<u8, <C as Curve>::FieldSize>, 
[src]

Borrow the inner secret Scalar value.

Warning

This value is key material.

Please treat it with the care it deserves!

pub fn public_key(&self) -> PublicKey<C> where
    C: Curve + ProjectiveArithmetic + SecretValue<Secret = NonZeroScalar<C>>,
    GenericArray<u8, <C as Curve>::FieldSize>: From<<<C as ProjectiveArithmetic>::ProjectivePoint as Group>::Scalar>,
    GenericArray<u8, <C as Curve>::FieldSize>: for<'a> From<&'a <<C as ProjectiveArithmetic>::ProjectivePoint as Group>::Scalar>,
    <<C as ProjectiveArithmetic>::ProjectivePoint as Group>::Scalar: PrimeField,
    <<C as ProjectiveArithmetic>::ProjectivePoint as Group>::Scalar: Zeroize,
    <<C as ProjectiveArithmetic>::ProjectivePoint as Curve>::AffineRepr: Copy,
    <<C as ProjectiveArithmetic>::ProjectivePoint as Curve>::AffineRepr: Clone,
    <<C as ProjectiveArithmetic>::ProjectivePoint as Curve>::AffineRepr: Debug,
    <<C as ProjectiveArithmetic>::ProjectivePoint as Curve>::AffineRepr: Default,
    <<<C as ProjectiveArithmetic>::ProjectivePoint as Group>::Scalar as PrimeField>::Repr == GenericArray<u8, <C as Curve>::FieldSize>, 
[src]

Get the PublicKey which corresponds to this secret key

Trait Implementations

impl<C> Clone for SecretKey<C> where
    C: SecretValue + Curve + Clone,
    <C as SecretValue>::Secret: Clone
[src]

impl<C> Debug for SecretKey<C> where
    C: Curve + SecretValue
[src]

impl<C> Drop for SecretKey<C> where
    C: Curve + SecretValue
[src]

impl<C> From<SecretKey<C>> for SigningKey<C> where
    C: Curve + ProjectiveArithmetic,
    FieldBytes<C>: From<Scalar<C>> + for<'r> From<&'r Scalar<C>>,
    Scalar<C>: PrimeField<Repr = FieldBytes<C>> + ConstantTimeEq + FromDigest<C> + Invert<Output = Scalar<C>> + SignPrimitive<C> + Zeroize,
    SignatureSize<C>: ArrayLength<u8>, 
[src]

impl<C> FromPrivateKey for SecretKey<C> where
    C: Curve + AlgorithmParameters + SecretValue,
    <C as SecretValue>::Secret: Clone,
    <C as SecretValue>::Secret: Zeroize,
    GenericArray<u8, <C as Curve>::FieldSize>: From<<C as SecretValue>::Secret>, 
[src]

impl<C> FromStr for SecretKey<C> where
    C: Curve + AlgorithmParameters + SecretValue,
    <C as SecretValue>::Secret: Clone,
    <C as SecretValue>::Secret: Zeroize,
    GenericArray<u8, <C as Curve>::FieldSize>: From<<C as SecretValue>::Secret>, 
[src]

type Err = Error

The associated error which can be returned from parsing.

impl<'_, C> TryFrom<&'_ [u8]> for SecretKey<C> where
    C: Curve + SecretValue,
    <C as SecretValue>::Secret: Clone,
    <C as SecretValue>::Secret: Zeroize,
    GenericArray<u8, <C as Curve>::FieldSize>: From<<C as SecretValue>::Secret>, 
[src]

type Error = Error

The type returned in the event of a conversion error.

Auto Trait Implementations

impl<C> RefUnwindSafe for SecretKey<C> where
    <C as SecretValue>::Secret: RefUnwindSafe

impl<C> Send for SecretKey<C> where
    <C as SecretValue>::Secret: Send

impl<C> Sync for SecretKey<C> where
    <C as SecretValue>::Secret: Sync

impl<C> Unpin for SecretKey<C> where
    <C as SecretValue>::Secret: Unpin

impl<C> UnwindSafe for SecretKey<C> where
    <C as SecretValue>::Secret: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Conv for T

impl<T> FmtForward for T

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Pipe for T

impl<T> PipeAsRef for T

impl<T> PipeBorrow for T

impl<T> PipeDeref for T

impl<T> PipeRef for T

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> Tap for T

impl<T, U> TapAsRef<U> for T where
    U: ?Sized

impl<T, U> TapBorrow<U> for T where
    U: ?Sized

impl<T> TapDeref for T

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> TryConv for T

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.