Skip to main content

WinternitzPrivkey

Struct WinternitzPrivkey 

Source
pub struct WinternitzPrivkey<const N: usize> { /* private fields */ }
Expand description

Private Winternitz key: N message scalars and 2 checksum scalars, each 32 bytes. Zeroized on drop.

Security: Winternitz is a one-time signature scheme. Signing two different messages with the same privkey scalars allows an attacker to forge signatures on a third message. Prefer crate::WinternitzKeypair::sign_and_increment which guarantees the keypair advances after every signature. Calling Self::sign directly places the burden of one-time-use enforcement on the caller.

Implementations§

Source§

impl<const N: usize> WinternitzPrivkey<N>

Source

pub fn as_bytes(&self) -> &[u8]

Return the privkey’s (N + 2) * 32 raw bytes (message scalars then checksum scalars), with no copy.

Source

pub fn sign(self, message: &[&[u8]]) -> WinternitzSignature<N>

Sign a message. Consumes self so the same privkey can’t be reused directly. Note that re-deriving from a WinternitzKeypair at the same position produces an identical privkey — for replay-safe signing prefer crate::WinternitzKeypair::sign_and_increment.

The message is supplied as a slice of byte slices (matching solana_sha256_hasher::hashv), so callers can mix domain-separation tags or context bytes with the payload.

Source

pub fn sign_prehashed(self, hash: &[u8; N]) -> WinternitzSignature<N>

Sign a pre-hashed message. Consumes self; same caveat as Self::sign.

Source

pub fn hash(message: &[&[u8]]) -> [u8; N]

Hash a message into the N-byte Winternitz digest used by signing. Equivalent to truncating SHA-256 of the concatenated message slices to N bytes.

Source

pub fn to_pubkey(&self) -> WinternitzPubkey<N>

Derive the corresponding WinternitzPubkey by chaining each scalar 255 times under SHA-256.

Trait Implementations§

Source§

impl<const N: usize> Display for WinternitzPrivkey<N>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<const N: usize> Drop for WinternitzPrivkey<N>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<const N: usize> From<&WinternitzPrivkey<N>> for WinternitzPubkey<N>

Source§

fn from(sk: &WinternitzPrivkey<N>) -> Self

Converts to this type from the input type.
Source§

impl<const N: usize> From<WinternitzPrivkey<N>> for WinternitzPubkey<N>

Source§

fn from(sk: WinternitzPrivkey<N>) -> Self

Converts to this type from the input type.
Source§

impl<'a, const N: usize> TryFrom<&'a [u8]> for &'a WinternitzPrivkey<N>

Source§

type Error = WinternitzError

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

fn try_from(value: &'a [u8]) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<const N: usize> Zeroize for WinternitzPrivkey<N>

Source§

fn zeroize(&mut self)

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

Auto Trait Implementations§

§

impl<const N: usize> Freeze for WinternitzPrivkey<N>

§

impl<const N: usize> RefUnwindSafe for WinternitzPrivkey<N>

§

impl<const N: usize> Send for WinternitzPrivkey<N>

§

impl<const N: usize> Sync for WinternitzPrivkey<N>

§

impl<const N: usize> Unpin for WinternitzPrivkey<N>

§

impl<const N: usize> UnsafeUnpin for WinternitzPrivkey<N>

§

impl<const N: usize> UnwindSafe for WinternitzPrivkey<N>

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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.