A Rust implementation of At the Top of the Hypercube by Khovratovich et al. And XMSS with TSL, which introduced in hypercube.
# Build in release mode
cargo build --release
# Run all tests
cargo test
# Run benchmarks
cargo benchAdd the following to your Cargo.toml:
[dependencies]
hypercube-signatures = { git = "https://github.com/ts21/hypercube" }Or if you want to use a specific branch or commit:
[dependencies]
hypercube-signatures = { git = "https://github.com/ts21/hypercube", branch = "main" }use hypercube_signatures::{XMSSParams, XMSSKeypair};
fn main() {
// Create XMSS parameters
// Parameters: (tree_height, winternitz_parameter, len)
let params = XMSSParams::new(10, 67, 16);
// Generate a keypair
let mut keypair = XMSSKeypair::generate(¶ms);
// Sign a message
let message = b"Hello, XMSS!";
let signature = keypair.sign(message);
// Verify the signature
let is_valid = keypair.public_key().verify(message, &signature, keypair.params());
println!("Signature valid: {}", is_valid);
}The crate re-exports the following main types for convenient access:
XMSSParams- Parameters for XMSS schemeXMSSKeypair- XMSS key pair for signing and verificationXMSSPrivateKey- Private key componentXMSSPublicKey- Public key componentXMSSSignature- Signature typeAuthPath- Authentication path for Merkle treeMerkleTree- Merkle tree implementationWOTSPlusParams- WOTS+ parameters
- The keypair must be mutable when signing because XMSS is a stateful signature scheme
- Each private key can only sign a limited number of messages (2^tree_height)
- The verify method requires the params to be passed along with the message and signature
To use the Hypercube signatures with TSL scheme, you can follow this example that demonstrates how to create a TSL (Tree-based Signature Layer) configuration, generate a keypair, sign a message, and verify the signature. For now, TSL is the only supported scheme, but TL1C and TLFC using actual bigger parameters will be added in the future.
use hypercube_signatures::schemes::tsl::{TSL, TSLConfig};
use hypercube_signatures::wots::{WotsParams, WotsKeypair};
// Create TSL configuration for 128-bit security
let config = TSLConfig::new(128);
let tsl = TSL::new(config);
// Generate WOTS keypair
let params = WotsParams::from_tsl(&tsl);
let keypair = WotsKeypair::generate(¶ms);
// Sign a message
let message = b"Hello, world!";
let signature = keypair.sign(message, &tsl);
// Verify the signature
assert!(keypair.verify(message, &signature, &tsl));See the examples/ directory in the repository for more usage examples.
The implementation includes comprehensive test suites:
# Run unit tests
cargo test
# Run specific scheme tests
cargo test test_tsl
cargo test test_tl1c
cargo test test_tlfc
# Run with output
cargo test -- --nocapture