Struct ed25519_dalek::ExpandedSecretKey
[−]
[src]
#[repr(C)]pub struct ExpandedSecretKey { /* fields omitted */ }
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.
Methods
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::{Rng, OsRng}; use sha2::Sha512; use ed25519_dalek::{SecretKey, ExpandedSecretKey}; let mut csprng: OsRng = OsRng::new().unwrap(); 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, DecodingError>
[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 DecodingError
describing the error that occurred.
Examples
use rand::{Rng, OsRng}; use ed25519_dalek::{SecretKey, ExpandedSecretKey}; use ed25519_dalek::DecodingError; let mut csprng: OsRng = OsRng::new().unwrap(); 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 from_secret_key<D>(secret_key: &SecretKey) -> ExpandedSecretKey where
D: Digest<OutputSize = U64> + Default,
[src]
D: Digest<OutputSize = U64> + Default,
Construct an ExpandedSecretKey
from a SecretKey
, using hash function D
.
Examples
use rand::{Rng, OsRng}; use sha2::Sha512; use ed25519_dalek::{SecretKey, ExpandedSecretKey}; let mut csprng: OsRng = OsRng::new().unwrap(); let secret_key: SecretKey = SecretKey::generate(&mut csprng); let expanded_secret_key: ExpandedSecretKey = ExpandedSecretKey::from_secret_key::<Sha512>(&secret_key);
pub fn sign<D>(&self, message: &[u8], public_key: &PublicKey) -> Signature where
D: Digest<OutputSize = U64> + Default,
[src]
D: Digest<OutputSize = U64> + Default,
Sign a message with this ExpandedSecretKey
.