Expand description
§metamorphic-crypto
Zero-knowledge end-to-end encryption core for the Metamorphic platform.
This library implements the cryptographic operations required by all Metamorphic clients (web/WASM, iOS/UniFFI, Android/UniFFI). It produces byte-compatible ciphertext with the existing JavaScript implementation so that data encrypted by one client can be decrypted by any other.
§Security guarantees
- All secret key material is [
Zeroize]-on-drop - No
unsafecode - Constant-time comparisons via the underlying RustCrypto crates
- Randomness sourced directly from the OS CSPRNG (
getrandom)
§Ciphertext formats
| Format | Layout |
|---|---|
| Secretbox | nonce (24B) || ciphertext (len + 16B MAC) |
| box_seal | ephemeral_pk (32B) || box ciphertext |
| Hybrid v2 (Cat-3) | 0x02 || ML-KEM-768 ct (1088B) || X25519 eph pk (32B) || nonce (24B) || secretbox ct |
| Hybrid v3 (Cat-5) | 0x03 || ML-KEM-1024 ct (1568B) || X25519 eph pk (32B) || nonce (24B) || secretbox ct |
Re-exports§
pub use error::CryptoError;pub use b64::parse_salt_from_key_hash;pub use box_seal::box_seal;pub use box_seal::box_seal_open;pub use hash::sha3_256;pub use hash::sha3_512;pub use hash::sha3_512_with_context;pub use hash::sha256;pub use hash::sha512;pub use hybrid::HybridKeyPair;pub use hybrid::SecurityLevel;pub use hybrid::generate_hybrid_keypair;pub use hybrid::generate_hybrid_keypair_1024;pub use hybrid::generate_hybrid_keypair_with_level;pub use hybrid::hybrid_open;pub use hybrid::hybrid_seal;pub use hybrid::hybrid_seal_1024;pub use hybrid::hybrid_seal_with_level;pub use hybrid::is_hybrid_ciphertext;pub use kdf::derive_session_key;pub use keys::KeyPair;pub use keys::decrypt_private_key;pub use keys::encrypt_private_key;pub use keys::generate_key;pub use keys::generate_keypair;pub use keys::generate_salt;pub use recovery::RecoveryKey;pub use recovery::decrypt_private_key_with_recovery;pub use recovery::encrypt_private_key_for_recovery;pub use recovery::generate_recovery_key;pub use recovery::recovery_key_to_secret;pub use seal::seal_for_user;pub use seal::seal_for_user_with_level;pub use seal::unseal_from_user;pub use secretbox::decrypt_secretbox;pub use secretbox::decrypt_secretbox_to_string;pub use secretbox::encrypt_secretbox;pub use secretbox::encrypt_secretbox_string;
Modules§
- b64
- Base64 utilities (standard alphabet, with padding).
- box_
seal - X25519 sealed box (anonymous public-key encryption).
- error
- Error types for the crypto library.
- hash
- Cryptographic hash functions (SHA-3 and SHA-2 families).
- hybrid
- Hybrid post-quantum KEM: ML-KEM-768 + X25519 (Cat-3) and ML-KEM-1024 + X25519 (Cat-5).
- kdf
- Argon2id key derivation.
- keys
- Key generation and private-key encrypt/decrypt helpers.
- recovery
- Recovery key generation and encoding.
- seal
- Unified seal/unseal that auto-detects hybrid (v2/v3) vs legacy (v1) format.
- secretbox
- XSalsa20-Poly1305 authenticated encryption (NaCl
secretbox).