Cryptography & Security

Modern cryptography replacing Udanax-Gold's placeholder crypto — Ed25519, X25519, ChaCha20-Poly1305, Argon2id, and signed key rotation

Contents

Overview

Phase 12 replaced the original Udanax-Gold placeholder crypto (NoEncrypter/NoScrambler) with production-grade modern cryptography. Every primitive comes from the RustCrypto project — pure Rust with no C dependencies, auditable and FFI-free.

Result: 62 crypto unit tests + 6 integration tests, all passing. cargo audit clean — zero known vulnerabilities.

The Crypto Stack

Ed25519

ed25519-dalek 2.1

Digital signatures for server identity, data signing, and key rotation proofs. 64-byte signatures, 32-byte keys.

X25519

x25519-dalek 2.0

Curve25519 Diffie-Hellman key exchange. Double-DH (static + ephemeral) for forward secrecy in challenge-response.

ChaCha20-Poly1305

chacha20poly1305 0.10

Authenticated encryption with associated data (AEAD). Monotonic nonce counter per session. Separate direction keys.

HKDF-SHA256

hkdf 0.12 + sha2 0.10

Key derivation with domain separation. Labels: xudanu/v1/handshake, xudanu/v1/aead/..., xudanu/v1/challenge-key.

Argon2id

argon2 0.5

Password hashing with OWASP parameters (19456 KiB, 2 iterations, 1 lane). PHC format. Constant-time verification.

BLAKE3

blake3 1.5

Content fingerprinting for transclusion identity. Already used throughout — not new in Phase 12 but part of the crypto foundation.

Module: AEAD (aead.rs)

ChaCha20-Poly1305 with per-session monotonic nonce counter. The SessionCipher maintains separate direction labels (client-to-server vs server-to-client) so the same key material can't be replayed across directions. SealedEnvelope provides a versioned wire format. Session keys are zeroized on drop.

Module: Signing (sign.rs)

Thin Ed25519 wrappers: sign_bytes(), verify_signature(), generate_signing_key(). Keys are generated with secure randomness and zeroized on drop.

Module: Key Exchange (kex.rs)

X25519 with double-DH (combining static and ephemeral keys). The transcript hash (BLAKE3 of both ephemeral public keys) binds the handshake to prevent man-in-the-middle attacks. SharedSecret zeroizes on drop.

Module: KDF (kdf.rs)

HKDF-SHA256 with domain-separated labels. Derives separate inbound/outbound session keys from the shared secret + handshake hash. Each label is prefixed xudanu/v1/ to prevent cross-protocol attacks.

Module: Password Hashing (password.rs)

Argon2id with OWASP-recommended parameters. Stores hashes in PHC format ($argon2id$v=19$...). Verification uses subtle::constant_time_eq to prevent timing attacks.

Module: Server Keys (keys.rs)

ServerKeyPair holds Ed25519 signing + X25519 kex keys with key_id, validity window, and active status. KeyHistory stores the full rotation chain — each new key is signed by the previous key, creating a tamper-evident history from the genesis key.

Lock System Security Upgrade

Gold's lock system had placeholder crypto. Phase 12 replaced both lock types:

Lock TypeBefore (Gold)After (Xudanu)
MatchLockPlaintext == comparisonArgon2id PHC hash + constant-time verify
ChallengeLockPlaceholder vec![0u8; 32]X25519 ECDH → HKDF → ChaCha20-Poly1305

Challenge-response flow

  1. Generate ephemeral X25519 key pair
  2. ECDH with peer's static public key → shared secret
  3. HKDF derive AEAD key with domain label xudanu/v1/challenge-key
  4. Encrypt challenge data with ChaCha20-Poly1305
  5. Return ephemeral_public_key || ciphertext

Server Identity & Key Rotation

The server holds a ServerKeyPair (Ed25519 + X25519) and maintains a KeyHistory — an ordered chain of key entries where each rotation is signed by the previous key.

Key rotation from day one: verify_rotation_chain() validates the entire history from the genesis key. Time-based validity (not_before/not_after) on each entry. Admin-triggered rotation via crypto_key_rotation operation.

Wire Protocol

Five operations (opcodes 0x1201–0x1205) expose crypto functionality:

OperationOpcodeAuthReturns
crypto_get_public_key0x1201Nonekey_id, signing_key[32], kex_key[32], server_id
crypto_sign_data0x1202Adminsignature[64], key_id
crypto_verify_signature0x1203Nonevalid (bool)
crypto_key_rotation0x1204Adminnew_key_id
crypto_key_history0x1205Noneserver_id, current_key_id, entries[]

C++ Equivalence

How Gold's placeholder crypto maps to Xudanu's real implementations:

C++ ComponentRust Replacement
NoEncrypter (stub)ChaCha20-Poly1305 AEAD
NoScrambler (stub)Argon2id password hashing
Encrypter::make() factoryServerKeyPair::generate()
MatchLock::encryptedPassword()MatchLockSmith with Argon2id PHC
ChallengeLock (stub)X25519 ECDH + AEAD challenge
Snefru S-boxesBLAKE3 content fingerprints

Security Design

What's protected

AssetProtection
PasswordsArgon2id (OWASP params), PHC format, constant-time verify
TransportX25519 ECDH, HKDF-derived keys, AEAD-encrypted challenges
SignaturesEd25519 for identity, data signing, key rotation proofs
DocumentsChaCha20-Poly1305, monotonic nonces, direction-separated keys
Key materialzeroize on drop for all secret types

Domain separation

All HKDF derivations use xudanu/v1/ prefixed labels. Session keys are split into separate inbound/outbound. AEAD AAD includes the direction label. This prevents cross-protocol and cross-direction attacks.

What's NOT included yet

Tests & Auditing

62 crypto unit tests: AEAD roundtrip/tamper/wrong-key/wrong-aad/empty/large, signing roundtrip/tamper/wrong-key, KDF determinism/domain-separation/session-keys, Argon2id roundtrip/PHC-format/unicode, key generation/identity/rotation/history-chain/transcript.
6 integration tests: crypto_get_public_key, crypto_sign_and_verify, crypto_verify_rejects_tampered, crypto_key_rotation, crypto_key_history, crypto_sign_requires_admin.
cargo audit clean: Zero known vulnerabilities in dependencies. Scans Cargo.lock against RustSec advisory database.

Known-value tests

23 crypto known-value tests verify that Ed25519 signatures, BLAKE3 hashes, and KDF outputs match expected byte-for-byte values. These catch regressions in the crypto implementation.

Dependencies

All from RustCrypto — pure Rust, no C dependencies, no OpenSSL:

CrateVersionPurpose
chacha20poly13050.10AEAD authenticated encryption
x25519-dalek2.0Curve25519 Diffie-Hellman
ed25519-dalek2.1Ed25519 digital signatures
sha20.10SHA-256 for HKDF
hkdf0.12HKDF-SHA256 key derivation
argon20.5Argon2id password hashing
subtle2.5Constant-time comparison
zeroize1.8Secure memory zeroization
blake31.5Content fingerprinting
ring0.17 TLS / additional primitives