ExpandedSecretKey

Struct ExpandedSecretKey 

Source
pub struct ExpandedSecretKey { /* private fields */ }
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.

Implementations§

Source§

impl ExpandedSecretKey

Source

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

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;
use rand::rngs::OsRng;
use sha3::Sha3_512;
use xpx_chain_crypto::{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][..]);
Source

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

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::Rng;
use rand::rngs::OsRng;
use xpx_chain_crypto::{SecretKey, ExpandedSecretKey};
use xpx_chain_crypto::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)?;
Source

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

Sign a message with this ExpandedSecretKey.

Source

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

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

An Ed25519ph Signature on the prehashed_message.

Trait Implementations§

Source§

impl Default for ExpandedSecretKey

Source§

fn default() -> ExpandedSecretKey

Returns the “default value” for a type. Read more
Source§

impl Drop for ExpandedSecretKey

Overwrite secret key material with null bytes when it goes out of scope.

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<'a> From<&'a ExpandedSecretKey> for PublicKey

Source§

fn from(expanded_secret_key: &ExpandedSecretKey) -> PublicKey

Derive this public key from its corresponding ExpandedSecretKey.

Source§

impl<'a> From<&'a SecretKey> for ExpandedSecretKey

Source§

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

Construct an ExpandedSecretKey from a SecretKey.

§Examples
use rand::Rng;
use rand::thread_rng;
use sha3::Sha3_512;
use xpx_chain_crypto::{SecretKey, ExpandedSecretKey};

let mut csprng = thread_rng();
let secret_key: SecretKey = SecretKey::generate(&mut csprng);
let expanded_secret_key: ExpandedSecretKey = ExpandedSecretKey::from(&secret_key);

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Clear for T

Source§

fn clear(&mut self)

Completely overwrites this value.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> InitializableFromZeroed for T
where T: Default,

Source§

unsafe fn initialize(place: *mut T)

Called to initialize a place to a valid value, after it is set to all-bits-zero. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V