Module crypto

Module crypto 

Source
Expand description

Message-level cryptography for the Zoe protocol

This module provides cryptographic primitives for message encryption, key derivation, and mnemonic-based key management used in the Zoe messaging protocol.

§Key Features

  • ChaCha20-Poly1305 encryption for message content
  • BIP39 mnemonic phrase support for key derivation
  • Ed25519 and ML-DSA key generation from mnemonics
  • Self-encryption and ephemeral ECDH patterns
  • Argon2 key derivation with configurable parameters

Structs§

Argon2Params
ChaCha20Poly1305Content
Minimal encrypted content for wire protocol messages Optimized for space - no key_id since it’s determined by channel context
Ed25519SelfEncryptedContent
Ed25519-derived ChaCha20-Poly1305 encrypted content Simple self-encryption using only the sender’s ed25519 keypair derived from mnemonic Only the sender can decrypt this content (encrypt-to-self pattern) Public key is available from message sender field - no need to duplicate
EncryptionKey
ChaCha20-Poly1305 encryption key
EphemeralEcdhContent
Ephemeral ECDH ChaCha20-Poly1305 encrypted content Simple public key encryption using ephemeral X25519 keys Anyone can encrypt for the recipient using only their public key
KeyDerivationInfo
Information about how a key was derived
MlDsaSelfEncryptedContent
ML-DSA-derived ChaCha20-Poly1305 encrypted content Simple self-encryption using only the sender’s ML-DSA keypair derived from mnemonic Only the sender can decrypt this content (encrypt-to-self pattern) Public key is available from message sender field - no need to duplicate
MnemonicPhrase
Mnemonic phrase for key derivation

Enums§

CryptoError
KeyDerivationMethod
Key derivation methods supported by the system
PqxdhEncryptedContent
PQXDH encrypted content for asynchronous secure communication

Functions§

ed25519_to_x25519_private
Convert Ed25519 private key to X25519 private key Both curves use the same underlying Curve25519
ed25519_to_x25519_public
Convert Ed25519 public key to X25519 public key Derives X25519 public key from the corresponding Ed25519 private key Note: This is a simplified approach that requires the private key
ed25519_to_x25519_public_from_verifying_key
Convert Ed25519 public key (VerifyingKey) to X25519 public key Uses curve25519-dalek’s Edwards to Montgomery conversion to match the same conversion that happens in the private key derivation path
generate_ed25519_from_mnemonic
Generate an ed25519 signing key from a mnemonic phrase
generate_ml_dsa_from_mnemonic
Generate an ML-DSA signing key from a mnemonic phrase
recover_ed25519_from_mnemonic
Recover an ed25519 signing key from a mnemonic phrase (deterministic)
recover_ml_dsa_from_mnemonic
Recover an ML-DSA signing key from a mnemonic phrase (deterministic)