Expand description
Cryptographic primitives for Tenzro Network.
This crate provides cryptographic operations for the Tenzro Network blockchain, including:
- Key Management: Ed25519, Secp256k1, and Secp256r1 (P-256) keypairs with address derivation
- Signatures: Digital signature creation and verification
- WebAuthn: FIDO2 / passkey assertion verification, the device-side primitive for self-custody
- Hashing: SHA-256 and Keccak-256 (for EVM compatibility)
- Encryption: AES-256-GCM symmetric encryption and X25519 key exchange
- FROST: Real threshold Ed25519 signing (RFC 9591) where the secret key is never reconstructed
§Examples
§Generating a keypair and signing
use tenzro_crypto::{KeyPair, KeyType};
use tenzro_crypto::signatures::{Signer, Ed25519SignerImpl};
// Generate an Ed25519 keypair
let keypair = KeyPair::generate(KeyType::Ed25519)?;
let address = keypair.address();
// Sign a message
let signer = Ed25519SignerImpl::new(keypair)?;
let message = b"Tenzro Network transaction";
let signature = signer.sign(message)?;§Hashing
use tenzro_crypto::hash::{sha256, keccak256};
let data = b"Tenzro Network";
let sha_hash = sha256(data);
let keccak_hash = keccak256(data);§Encryption
use tenzro_crypto::encryption::{SymmetricKey, X25519KeyPair, envelope_encrypt, envelope_decrypt};
// Symmetric encryption
let key = SymmetricKey::generate();
let plaintext = b"secret data";
let ciphertext = key.encrypt(plaintext)?;
let decrypted = key.decrypt(&ciphertext)?;
// Envelope encryption (asymmetric)
let recipient = X25519KeyPair::generate();
let envelope = envelope_encrypt(recipient.public_key(), plaintext)?;
let decrypted = envelope_decrypt(&recipient, &envelope)?;§FROST-Ed25519 Threshold Signing (RFC 9591)
Real threshold signing — the secret key is never materialized in any
single process. Output is a 64-byte standard Ed25519 signature that
verifies under the group public key with signatures::verify.
use tenzro_crypto::frost::{
keygen_with_trusted_dealer, round1_commit, build_signing_package,
round2_sign, aggregate_signature,
};
use tenzro_crypto::signatures;
// 2-of-3 threshold key (trusted dealer; DKG variant in `frost::dkg_part1`).
let (group_pkg, shares) = keygen_with_trusted_dealer(2, 3)?;
// Round 1: each signer commits.
let (n1, c1) = round1_commit(&shares[0])?;
let (n2, c2) = round1_commit(&shares[1])?;
// Coordinator builds the signing package over the message.
let message = b"Tenzro Network FROST transaction";
let signing_pkg = build_signing_package(message, &[c1, c2])?;
// Round 2: each signer produces its signature share.
let s1 = round2_sign(&signing_pkg, &n1, &shares[0])?;
let s2 = round2_sign(&signing_pkg, &n2, &shares[1])?;
// Aggregate to a single 64-byte standard Ed25519 signature.
let sig = aggregate_signature(&signing_pkg, &[s1, s2], &group_pkg)?;
// Verifies under the group public key with the standard Ed25519 verifier.
let group_pk = group_pkg.group_public_key.as_public_key();
signatures::verify(&group_pk, message, &sig)?;Re-exports§
pub use composite::CompositePublicKey;pub use composite::CompositeSignature;pub use composite::HybridSigner;pub use composite::HybridVerifier;pub use composite::InMemoryHybridSigner;pub use composite::StandardHybridVerifier;pub use error::CryptoError;pub use error::Result;pub use frost::DkgRound1;pub use frost::DkgRound1Public;pub use frost::DkgRound1Secret;pub use frost::DkgRound2;pub use frost::DkgRound2Secret;pub use frost::DkgRound2Unicast;pub use frost::GroupPublicKey as FrostGroupPublicKey;pub use frost::PublicKeyPackage as FrostPublicKeyPackage;pub use frost::SignerIndex as FrostSignerIndex;pub use frost::SigningCommitments as FrostSigningCommitments;pub use frost::SigningNonces as FrostSigningNonces;pub use frost::SigningPackage as FrostSigningPackage;pub use frost::aggregate_signature as frost_aggregate;pub use frost::build_signing_package as frost_build_signing_package;pub use frost::dkg_part1 as frost_dkg_part1;pub use frost::dkg_part2 as frost_dkg_part2;pub use frost::dkg_part3 as frost_dkg_part3;pub use frost::keygen_with_trusted_dealer as frost_keygen;pub use frost::round1_commit as frost_round1_commit;pub use frost::round2_sign as frost_round2_sign;pub use hash::Hash;pub use hash::Hasher;pub use hash::Keccak256;pub use hash::Sha256;pub use hash::keccak256;pub use hash::sha256;pub use keys::Address;pub use keys::KeyPair;pub use keys::KeyType;pub use keys::PublicKey;pub use keys::SecretKey;pub use p256::P256_PUBLIC_KEY_LEN;pub use p256::P256_PUBLIC_KEY_SEC1_LEN;pub use p256::P256_SIGNATURE_LEN;pub use p256::P256KeyPair;pub use p256::P256Signature;pub use p256::P256Signer;pub use p256::P256Verifier;pub use p256::build_p256verify_input;pub use pq::ML_DSA_65_SIG_LEN;pub use pq::ML_DSA_65_VK_LEN;pub use pq::ML_KEM_768_CT_LEN;pub use pq::ML_KEM_768_EK_LEN;pub use pq::ML_KEM_SS_LEN;pub use pq::MlDsaSigningKey;pub use pq::MlKemDecapsulationKey;pub use pq::ml_dsa_verify;pub use pq::ml_kem_encapsulate;pub use signatures::Signature;pub use signatures::Signer;pub use signatures::Verifier;pub use webauthn::WebAuthnAssertion;pub use webauthn::WebAuthnCeremonyType;pub use webauthn::WebAuthnRelyingParty;pub use webauthn::unwrap_der_signature;pub use webauthn::verify_webauthn_assertion;pub use webauthn::webauthn_signed_hash;pub use webauthn::webauthn_signed_payload;
Modules§
- bls
- BLS12-381 signature operations for Tenzro Network.
- composite
- Hybrid (composite) signature primitives for the Tenzro post-quantum migration.
- encryption
- Encryption primitives for Tenzro Network.
- error
- Error types for Tenzro Network cryptographic operations.
- frost
- FROST-Ed25519 threshold signing (RFC 9591).
- hash
- Hashing primitives for Tenzro Network.
- keys
- Key management for Tenzro Network.
- p256
- Secp256r1 / NIST P-256 primitives for Tenzro Network.
- pq
- Post-quantum cryptographic primitives for Tenzro Network.
- rng
- Cryptographically secure random number generator (CSPRNG) for Tenzro Network
- signatures
- Signature operations for Tenzro Network.
- vrf
- Verifiable Random Function (VRF) for Tenzro Network.
- webauthn
- WebAuthn / FIDO2 signature verification primitives.