SecretKey

Struct SecretKey 

Source
pub struct SecretKey { /* private fields */ }
Expand description

Represents the secret key for Falcon DSA.

The secret key is a quadruple [[g, -f], [G, -F]] of polynomials with integer coefficients. Each polynomial is of degree at most N = 512 and computations with these polynomials is done modulo the monic irreducible polynomial ϕ = x^N + 1. The secret key is a basis for a lattice and has the property of being short with respect to a certain norm and an upper bound appropriate for a given security parameter. The public key on the other hand is another basis for the same lattice and can be described by a single polynomial h with integer coefficients modulo ϕ. The two keys are related by the following relation:

  1. h = g /f [mod ϕ][mod p]
  2. f.G - g.F = p [mod ϕ]

where p = 12289 is the Falcon prime. Equation 2 is called the NTRU equation. The secret key is generated by first sampling a random pair (f, g) of polynomials using an appropriate distribution that yields short but not too short polynomials with integer coefficients modulo ϕ. The NTRU equation is then used to find a matching pair (F, G). The public key is then derived from the secret key using equation 1.

To allow for fast signature generation, the secret key is pre-processed into a more suitable form, called the LDL tree, and this allows for fast sampling of short vectors in the lattice using Fast Fourier sampling during signature generation (ffSampling algorithm 11 in 1).

Implementations§

Source§

impl SecretKey

Source

pub fn new() -> SecretKey

Generates a secret key from OS-provided randomness.

Source

pub fn with_rng<R>(rng: &mut R) -> SecretKey
where R: Rng,

Generates a secret_key using the provided random number generator Rng.

Source

pub fn short_lattice_basis(&self) -> &[Polynomial<i16>; 4]

Returns the polynomials of the short lattice basis of this secret key.

Source

pub fn public_key(&self) -> PublicKey

Returns the public key corresponding to this secret key.

Source

pub fn tree(&self) -> &LdlTree

Returns the LDL tree associated to this secret key.

Source

pub fn sign(&self, message: Word) -> Signature

Signs a message with this secret key.

Source

pub fn sign_with_rng<R>(&self, message: Word, rng: &mut R) -> Signature
where R: Rng,

Signs a message with the secret key relying on the provided randomness generator.

Trait Implementations§

Source§

impl Clone for SecretKey

Source§

fn clone(&self) -> SecretKey

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SecretKey

Source§

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

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

impl Deserializable for SecretKey

Source§

fn read_from<R>(source: &mut R) -> Result<SecretKey, DeserializationError>
where R: ByteReader,

Reads a sequence of bytes from the provided source, attempts to deserialize these bytes into Self, and returns the result. Read more
Source§

fn read_from_bytes(bytes: &[u8]) -> Result<Self, DeserializationError>

Attempts to deserialize the provided bytes into Self and returns the result. Read more
Source§

impl Display for SecretKey

Source§

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

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

impl Drop for SecretKey

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl PartialEq for SecretKey

Source§

fn eq(&self, other: &SecretKey) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serializable for SecretKey

Source§

fn write_into<W>(&self, target: &mut W)
where W: ByteWriter,

Serializes self into bytes and writes these bytes into the target.
Source§

fn to_bytes(&self) -> Vec<u8>

Serializes self into a vector of bytes.
Source§

fn get_size_hint(&self) -> usize

Returns an estimate of how many bytes are needed to represent self. Read more
Source§

impl Zeroize for SecretKey

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

impl Eq for SecretKey

Source§

impl ZeroizeOnDrop for SecretKey

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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