Skip to main content

FalconKeyPair

Struct FalconKeyPair 

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

A Falcon key pair (private key + public key).

The key pair stores encoded keys in the Falcon wire format. Use logn = 9 for Falcon-512 (NIST Level I) or logn = 10 for Falcon-1024 (NIST Level V).

§Serialization

let kp = FalconKeyPair::generate(9).unwrap();

// Export
let sk = kp.private_key().to_vec();
let pk = kp.public_key().to_vec();

// Import
let kp2 = FalconKeyPair::from_keys(&sk, &pk).unwrap();
assert_eq!(kp.public_key(), kp2.public_key());

Implementations§

Source§

impl FalconKeyPair

Source

pub fn generate(logn: u32) -> Result<Self, FalconError>

Generate a new Falcon key pair using OS entropy.

§Arguments
  • logn — Degree parameter: 9 for Falcon-512, 10 for Falcon-1024. Values 1–8 are research-only reduced variants.
§Errors
Source

pub fn generate_deterministic( seed: &[u8], logn: u32, ) -> Result<Self, FalconError>

Generate a new Falcon key pair from a deterministic seed.

The seed is fed into a SHAKE256-based PRNG. The same seed always produces the same key pair, making this ideal for test vector reproducibility.

§Arguments
  • seed — Entropy seed (≥ 32 bytes recommended).
  • logn — Degree parameter: 9 for Falcon-512, 10 for Falcon-1024.
Source

pub fn from_keys(privkey: &[u8], pubkey: &[u8]) -> Result<Self, FalconError>

Reconstruct a key pair from previously exported private and public key bytes.

Both keys must be valid Falcon-encoded keys with matching degree.

§Example
let kp = FalconKeyPair::generate(9).unwrap();
let sk = kp.private_key().to_vec();
let pk = kp.public_key().to_vec();

let restored = FalconKeyPair::from_keys(&sk, &pk).unwrap();
assert_eq!(kp.logn(), restored.logn());
Source

pub fn from_private_key(privkey: &[u8]) -> Result<Self, FalconError>

Reconstruct a key pair from a private key only.

The public key is recomputed from the private key. This is slightly slower than from_keys but only requires the private key to be stored.

§Example
let kp = FalconKeyPair::generate(9).unwrap();
let sk = kp.private_key().to_vec();

let restored = FalconKeyPair::from_private_key(&sk).unwrap();
assert_eq!(kp.public_key(), restored.public_key());
Source

pub fn public_key_from_private(privkey: &[u8]) -> Result<Vec<u8>, FalconError>

Compute the public key bytes from a private key without creating a key pair.

Useful when you only need the public key for distribution.

Source

pub fn sign(&self, message: &[u8]) -> Result<FalconSignature, FalconError>

Sign a message using this key pair.

Uses the constant-time (CT) signature format and OS entropy. Each call produces a different signature due to random nonce generation.

§Example
let kp = FalconKeyPair::generate(9).unwrap();
let sig = kp.sign(b"my message").unwrap();

// Signature can be exported and sent over the wire
let sig_bytes = sig.to_bytes().to_vec();
Source

pub fn sign_deterministic( &self, message: &[u8], seed: &[u8], ) -> Result<FalconSignature, FalconError>

Sign a message with a deterministic seed (for testing / reproducibility).

The same (key, message, seed) triple always produces the same signature.

Source

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

Get the encoded public key bytes.

The returned bytes are in the standard Falcon wire format and can be safely distributed, stored, or passed to FalconSignature::verify.

Source

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

Get the encoded private key bytes.

⚠️ Secret material — handle with care. These bytes can be used to reconstruct the key pair via from_keys or from_private_key.

Source

pub fn logn(&self) -> u32

Get the Falcon degree parameter.

Returns 9 for Falcon-512, 10 for Falcon-1024.

Source

pub fn variant_name(&self) -> &'static str

Get the security variant name.

Trait Implementations§

Source§

impl Clone for FalconKeyPair

Source§

fn clone(&self) -> FalconKeyPair

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 FalconKeyPair

Source§

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

Formats the value using the given formatter. Read more

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> 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, 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.