Struct elliptic_curve::secret_key::SecretKey[][src]

pub struct SecretKey<C: Curve + SecretValue> { /* 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 elliptic_curve::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::Secret: Clone + Zeroize,
    FieldBytes<C>: From<C::Secret>, 
[src]

pub fn random(rng: impl CryptoRng + RngCore) -> Self where
    C: ProjectiveArithmetic + SecretValue<Secret = NonZeroScalar<C>>,
    FieldBytes<C>: From<Scalar<C>> + for<'a> From<&'a Scalar<C>>,
    Scalar<C>: PrimeField<Repr = FieldBytes<C>> + Zeroize
[src]

This is supported on crate feature arithmetic only.

Generate a random SecretKey

pub fn new(secret_value: C::Secret) -> Self[src]

Create a new secret key from a serialized scalar value

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

Deserialize raw private scalar as a big endian integer

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

Expose the byte serialization of the value this SecretKey wraps

pub fn secret_scalar(&self) -> &NonZeroScalar<C> where
    C: ProjectiveArithmetic + SecretValue<Secret = NonZeroScalar<C>>,
    FieldBytes<C>: From<Scalar<C>> + for<'a> From<&'a Scalar<C>>,
    Scalar<C>: PrimeField<Repr = FieldBytes<C>> + Zeroize
[src]

This is supported on crate feature arithmetic only.

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>>,
    FieldBytes<C>: From<Scalar<C>> + for<'a> From<&'a Scalar<C>>,
    Scalar<C>: PrimeField<Repr = FieldBytes<C>> + Zeroize,
    AffinePoint<C>: Copy + Clone + Debug + Default,
    ProjectivePoint<C>: From<AffinePoint<C>>, 
[src]

This is supported on crate feature arithmetic only.

Get the PublicKey which corresponds to this secret key

Trait Implementations

impl<C: Clone + Curve + SecretValue> Clone for SecretKey<C> where
    C::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> FromPrivateKey for SecretKey<C> where
    C: Curve + AlgorithmParameters + SecretValue,
    C::Secret: Clone + Zeroize,
    FieldBytes<C>: From<C::Secret>,
    UntaggedPointSize<C>: Add<U1> + ArrayLength<u8>,
    UncompressedPointSize<C>: ArrayLength<u8>, 
[src]

This is supported on crate feature pkcs8 only.

impl<C> FromStr for SecretKey<C> where
    C: Curve + AlgorithmParameters + SecretValue,
    C::Secret: Clone + Zeroize,
    FieldBytes<C>: From<C::Secret>,
    UntaggedPointSize<C>: Add<U1> + ArrayLength<u8>,
    UncompressedPointSize<C>: ArrayLength<u8>, 
[src]

This is supported on crate feature pem only.

type Err = Error

The associated error which can be returned from parsing.

impl<C> ToPrivateKey for SecretKey<C> where
    C: Curve + AlgorithmParameters + ProjectiveArithmetic,
    FieldBytes<C>: From<Scalar<C>> + for<'a> From<&'a Scalar<C>>,
    Scalar<C>: PrimeField<Repr = FieldBytes<C>> + Zeroize,
    AffinePoint<C>: Copy + Clone + Debug + Default + FromEncodedPoint<C> + ToEncodedPoint<C>,
    ProjectivePoint<C>: From<AffinePoint<C>>,
    UntaggedPointSize<C>: Add<U1> + ArrayLength<u8>,
    UncompressedPointSize<C>: ArrayLength<u8>, 
[src]

This is supported on crate features arithmetic and pem only.

impl<C> TryFrom<&'_ [u8]> for SecretKey<C> where
    C: Curve + SecretValue,
    C::Secret: Clone + Zeroize,
    FieldBytes<C>: From<C::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
[src]

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

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

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

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

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.