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
impl FalconKeyPair
Sourcepub fn generate(logn: u32) -> Result<Self, FalconError>
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
FalconError::BadArgumentiflognis outside 1–10.FalconError::RandomErrorif the OS RNG is unavailable.
Sourcepub fn generate_deterministic(
seed: &[u8],
logn: u32,
) -> Result<Self, FalconError>
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.
Sourcepub fn from_keys(privkey: &[u8], pubkey: &[u8]) -> Result<Self, FalconError>
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());Sourcepub fn from_private_key(privkey: &[u8]) -> Result<Self, FalconError>
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());Sourcepub fn public_key_from_private(privkey: &[u8]) -> Result<Vec<u8>, FalconError>
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.
Sourcepub fn sign(&self, message: &[u8]) -> Result<FalconSignature, FalconError>
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();Sourcepub fn sign_deterministic(
&self,
message: &[u8],
seed: &[u8],
) -> Result<FalconSignature, FalconError>
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.
Sourcepub fn public_key(&self) -> &[u8] ⓘ
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.
Sourcepub fn private_key(&self) -> &[u8] ⓘ
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.
Sourcepub fn logn(&self) -> u32
pub fn logn(&self) -> u32
Get the Falcon degree parameter.
Returns 9 for Falcon-512, 10 for Falcon-1024.
Sourcepub fn variant_name(&self) -> &'static str
pub fn variant_name(&self) -> &'static str
Get the security variant name.
Trait Implementations§
Source§impl Clone for FalconKeyPair
impl Clone for FalconKeyPair
Source§fn clone(&self) -> FalconKeyPair
fn clone(&self) -> FalconKeyPair
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more