Expand description
Implementation of Lamport’s one-time signature scheme.
§Usage
use lamport_signature_plus::{VerifyingKey, SigningKey, LamportFixedDigest};
use sha2::Sha256;
use rand_chacha::{ChaChaRng, rand_core::SeedableRng};
let mut rng = ChaChaRng::from_rng(&mut rand::rng());
let mut signing_key = SigningKey::<LamportFixedDigest<Sha256>>::random(rng);
let verifying_key = VerifyingKey::from(&signing_key);
let signature = signing_key.sign(b"Hello, World!").expect("signing failed");
assert!(verifying_key.verify(&signature, b"Hello, World!").is_ok());§Digest algorithms
SigningKey and VerifyingKey accept hash functions provided by
RustCrypto/hashes. Use
LamportFixedDigest for fixed-output functions or
LamportExtendableDigest for extendable-output functions. Extendable-output
functions use a 64-byte output.
§Extendable-output example
use lamport_signature_plus::{VerifyingKey, SigningKey, LamportExtendableDigest};
use shake::Shake128;
use rand_chacha::{ChaChaRng, rand_core::SeedableRng};
let mut rng = ChaChaRng::from_rng(&mut rand::rng());
let mut signing = SigningKey::<LamportExtendableDigest<Shake128>>::random(rng);
let verifying = VerifyingKey::from(&signing);
let signature = signing.sign(b"Hello, World!").expect("signing failed");
assert!(verifying.verify(&signature, b"Hello, World!").is_ok());§Random number generators
SigningKey requires a cryptographically secure random number generator
that implements CryptoRng.
§Note
A SigningKey can securely sign only one message. Attempting to sign with
a used key returns an error.
§Merkle-tree Lamport signatures
MtSigningKey commits 2, 4, or 8 one-time Lamport public keys in a
Merkle tree. Its compact MtVerifyingKey is only the tree depth and root.
Each MtSignature carries its leaf public key and authentication path.
use lamport_signature_plus::{LamportFixedDigest, generate_mt_keys};
use rand::SeedableRng;
use rand_chacha::ChaCha8Rng;
use sha2::Sha256;
let mut rng = ChaCha8Rng::from_seed([7; 32]);
let (mut signing_key, verifying_key) =
generate_mt_keys::<LamportFixedDigest<Sha256>, _>(2, &mut rng)?;
let signature = signing_key.sign(b"first message")?;
assert_eq!(signature.index(), 0);
verifying_key.verify(&signature, b"first message")?;The MT signing key is stateful. Persist its updated state after every signature; restoring an older copy can reuse a Lamport leaf and destroy security. Each signing operation destroys the consumed leaf secret, so the canonical signing-key state becomes smaller as indices are consumed.
Structs§
- Lamport
Extendable Digest - A Lamport signature scheme that uses extendable-output functions.
- Lamport
Fixed Digest - A Lamport signature scheme that uses fixed-output functions.
- MtSignature
- A Lamport signature bundled with its leaf public key and Merkle authentication path.
- MtSignature
Share - A participant’s threshold signature share with its Merkle inclusion proof.
- MtSigning
Key - A stateful collection of Lamport one-time signing keys committed by a Merkle tree.
- MtSigning
KeyShare - One participant’s threshold shares for the unused MT-Lamport leaves.
- MtVerifying
Key - A compact Merkle root that verifies up to eight Lamport one-time signatures.
- Multi
Vec - A multidimensional vector that is faster and simpler than
Vec<Vec<T>>. - Signature
- A signature generated by
SigningKey. - Signature
Share - A signature share generated by
SigningKeyShare. - Signing
Key - A one-time signing private key.
- Signing
KeyShare - A key share used to reconstruct a signing key or create a partial signature.
- Verifying
Key - A one-time signing public key.
Enums§
- Lamport
Error - Errors produced by the Lamport signature scheme.
Traits§
- Lamport
Digest - Digest operations required by the Lamport signature scheme.
Functions§
- generate_
keys - Generate a new key pair.
- generate_
mt_ keys - Generate a stateful Merkle-tree Lamport key pair.
Type Aliases§
- Lamport
Result - Result type for Lamport errors.