Struct ed25519_dalek::ExpandedSecretKey[][src]

pub struct ExpandedSecretKey { /* fields omitted */ }
Expand description

An “expanded” secret key.

This is produced by using an hash function with 512-bits output to digest a SecretKey. The output digest is then split in half, the lower half being the actual key used to sign messages, after twiddling with some bits.¹ The upper half is used a sort of half-baked, ill-designed² pseudo-domain-separation “nonce”-like thing, which is used during signature production by concatenating it with the message to be signed before the message is hashed.

Instances of this secret are automatically overwritten with zeroes when they fall out of scope.

Implementations

impl ExpandedSecretKey[src]

pub fn to_bytes(&self) -> [u8; 64][src]

Convert this ExpandedSecretKey into an array of 64 bytes.

Returns

An array of 64 bytes. The first 32 bytes represent the “expanded” secret key, and the last 32 bytes represent the “domain-separation” “nonce”.

Examples

use rand::rngs::OsRng;
use ed25519_dalek::{SecretKey, ExpandedSecretKey};

let mut csprng = OsRng{};
let secret_key: SecretKey = SecretKey::generate(&mut csprng);
let expanded_secret_key: ExpandedSecretKey = ExpandedSecretKey::from(&secret_key);
let expanded_secret_key_bytes: [u8; 64] = expanded_secret_key.to_bytes();

assert!(&expanded_secret_key_bytes[..] != &[0u8; 64][..]);

pub fn from_bytes(bytes: &[u8]) -> Result<ExpandedSecretKey, SignatureError>[src]

Construct an ExpandedSecretKey from a slice of bytes.

Returns

A Result whose okay value is an EdDSA ExpandedSecretKey or whose error value is an SignatureError describing the error that occurred.

Examples

use rand::rngs::OsRng;
use ed25519_dalek::{SecretKey, ExpandedSecretKey};
use ed25519_dalek::SignatureError;

let mut csprng = OsRng{};
let secret_key: SecretKey = SecretKey::generate(&mut csprng);
let expanded_secret_key: ExpandedSecretKey = ExpandedSecretKey::from(&secret_key);
let bytes: [u8; 64] = expanded_secret_key.to_bytes();
let expanded_secret_key_again = ExpandedSecretKey::from_bytes(&bytes)?;

pub fn sign(&self, message: &[u8], public_key: &PublicKey) -> Signature[src]

Sign a message with this ExpandedSecretKey.

pub fn sign_prehashed<'a, D>(
    &self,
    prehashed_message: D,
    public_key: &PublicKey,
    context: Option<&'a [u8]>
) -> Result<Signature, SignatureError> where
    D: Digest<OutputSize = U64>, 
[src]

Sign a prehashed_message with this ExpandedSecretKey using the Ed25519ph algorithm defined in RFC8032 §5.1.

Inputs

  • prehashed_message is an instantiated hash digest with 512-bits of output which has had the message to be signed previously fed into its state.
  • public_key is a PublicKey which corresponds to this secret key.
  • context is an optional context string, up to 255 bytes inclusive, which may be used to provide additional domain separation. If not set, this will default to an empty string.

Returns

A Result whose Ok value is an Ed25519ph [Signature] on the prehashed_message if the context was 255 bytes or less, otherwise a SignatureError.

Trait Implementations

impl<'d> Deserialize<'d> for ExpandedSecretKey[src]

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where
    D: Deserializer<'d>, 
[src]

Deserialize this value from the given Serde deserializer. Read more

impl Drop for ExpandedSecretKey[src]

fn drop(&mut self)[src]

Executes the destructor for this type. Read more

impl<'a> From<&'a ExpandedSecretKey> for PublicKey[src]

fn from(expanded_secret_key: &ExpandedSecretKey) -> PublicKey[src]

Derive this public key from its corresponding ExpandedSecretKey.

impl<'a> From<&'a SecretKey> for ExpandedSecretKey[src]

fn from(secret_key: &'a SecretKey) -> ExpandedSecretKey[src]

Construct an ExpandedSecretKey from a SecretKey.

Examples

use rand::rngs::OsRng;
use ed25519_dalek::{SecretKey, ExpandedSecretKey};

let mut csprng = OsRng{};
let secret_key: SecretKey = SecretKey::generate(&mut csprng);
let expanded_secret_key: ExpandedSecretKey = ExpandedSecretKey::from(&secret_key);

impl Serialize for ExpandedSecretKey[src]

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where
    S: Serializer
[src]

Serialize this value into the given Serde serializer. Read more

impl Zeroize for ExpandedSecretKey[src]

fn zeroize(&mut self)[src]

Zero out this object from memory using Rust intrinsics which ensure the zeroization operation is not “optimized away” by the compiler. Read more

Auto Trait Implementations

impl RefUnwindSafe for ExpandedSecretKey

impl Send for ExpandedSecretKey

impl Sync for ExpandedSecretKey

impl Unpin for ExpandedSecretKey

impl UnwindSafe for ExpandedSecretKey

Blanket Implementations

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

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

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

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

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

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

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

pub fn from(t: T) -> T[src]

Performs the conversion.

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

pub fn into(self) -> U[src]

Performs the conversion.

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

type Output = T

Should always be Self

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.

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

Performs the conversion.

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.

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

Performs the conversion.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>, 
[src]

pub fn vzip(self) -> V[src]

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]