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

This is supported on crate feature arithmetic only.

Get the PublicKey which corresponds to this secret key

pub fn from_jwk(jwk: &JwkEcKey) -> Result<Self> where
    C: JwkParameters + ValidatePublicKey,
    UntaggedPointSize<C>: Add<U1> + ArrayLength<u8>,
    UncompressedPointSize<C>: ArrayLength<u8>, 
[src]

This is supported on crate feature jwk only.

Parse a JwkEcKey JSON Web Key (JWK) into a SecretKey.

pub fn from_jwk_str(jwk: &str) -> Result<Self> where
    C: JwkParameters + ValidatePublicKey,
    UntaggedPointSize<C>: Add<U1> + ArrayLength<u8>,
    UncompressedPointSize<C>: ArrayLength<u8>, 
[src]

This is supported on crate feature jwk only.

Parse a string containing a JSON Web Key (JWK) into a SecretKey.

pub fn to_jwk(&self) -> JwkEcKey where
    C: JwkParameters + ProjectiveArithmetic,
    AffinePoint<C>: Copy + Debug + Default + FromEncodedPoint<C> + ToEncodedPoint<C>,
    ProjectivePoint<C>: From<AffinePoint<C>>,
    Scalar<C>: PrimeField<Repr = FieldBytes<C>> + Zeroize,
    UntaggedPointSize<C>: Add<U1> + ArrayLength<u8>,
    UncompressedPointSize<C>: ArrayLength<u8>, 
[src]

This is supported on crate features arithmetic and jwk only.

Serialize this secret key as JwkEcKey JSON Web Key (JWK).

pub fn to_jwk_string(&self) -> String where
    C: JwkParameters + ProjectiveArithmetic,
    AffinePoint<C>: Copy + Debug + Default + FromEncodedPoint<C> + ToEncodedPoint<C>,
    ProjectivePoint<C>: From<AffinePoint<C>>,
    Scalar<C>: PrimeField<Repr = FieldBytes<C>> + Zeroize,
    UntaggedPointSize<C>: Add<U1> + ArrayLength<u8>,
    UncompressedPointSize<C>: ArrayLength<u8>, 
[src]

This is supported on crate features arithmetic and jwk only.

Serialize this secret key as JSON Web Key (JWK) string.

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> From<&'_ SecretKey<C>> for JwkEcKey where
    C: Curve + JwkParameters + ProjectiveArithmetic,
    AffinePoint<C>: Copy + Clone + Debug + Default + FromEncodedPoint<C> + ToEncodedPoint<C>,
    ProjectivePoint<C>: From<AffinePoint<C>>,
    Scalar<C>: PrimeField<Repr = FieldBytes<C>> + Zeroize,
    UntaggedPointSize<C>: Add<U1> + ArrayLength<u8>,
    UncompressedPointSize<C>: ArrayLength<u8>, 
[src]

This is supported on crate features arithmetic and jwk only.

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

This is supported on crate features arithmetic and jwk only.

impl<C> FromPrivateKey for SecretKey<C> where
    C: Curve + AlgorithmParameters + ValidatePublicKey + 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 + ValidatePublicKey + 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,
    AffinePoint<C>: Copy + Clone + Debug + Default + FromEncodedPoint<C> + ToEncodedPoint<C>,
    ProjectivePoint<C>: From<AffinePoint<C>>,
    Scalar<C>: PrimeField<Repr = FieldBytes<C>> + Zeroize,
    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.

impl<C> TryFrom<&'_ JwkEcKey> for SecretKey<C> where
    C: Curve + JwkParameters + ValidatePublicKey + 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 jwk only.

type Error = Error

The type returned in the event of a conversion error.

impl<C> TryFrom<JwkEcKey> for SecretKey<C> where
    C: Curve + JwkParameters + ValidatePublicKey + 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 jwk only.

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> 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 where
    T: ?Sized

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