crypto — Overview
A pure-Vex cryptographic package with checked algorithm facades. It has no OpenSSL or libsodium dependency. Application code should prefer the checked Aes128Gcm, Aes256Gcm, ChaCha20Poly1305, HkdfSha256, HkdfSha384, Pbkdf2Sha256, Argon2id, X25519, and Ed25519 facades; raw RawBuf functions exist for protocol and runtime integration and require the caller to uphold buffer dimensions.
Module Map
| Category | Algorithms | Files |
|---|---|---|
| Hashes | SHA-1, SHA-256, SHA-384, SHA-512, BLAKE2b | sha1.vx, sha256.vx, sha512.vx, blake2b.vx |
| MACs | HMAC-SHA1, HMAC-SHA256, HMAC-SHA384 | hmac.vx |
| AEAD | AES-GCM, ChaCha20-Poly1305 | aes_gcm.vx, chacha20.vx, poly1305.vx, aead.vx |
| Symmetric | AES (128/256) | aes.vx |
| KDF | Argon2id, PBKDF2, HKDF | argon2id.vx, pbkdf2.vx, hkdf.vx |
| Signatures | Ed25519 | ed25519.vx |
| Key Exchange | X25519 (ECDH) | x25519.vx |
| Field Math | Curve25519 field | field25519.vx |
| Encoding | Hex, Base64 | hex.vx, base64.vx |
| Utilities | Byte ops, SIMD helpers | bytes.vx, simd.vx, utils.vx |
Design Principles
- Vex implementations: algorithms are visible to the compiler; actual inlining and vectorization depend on the selected build and target
- Hardware Acceleration: When
Crypto.*builtins are available (AES-NI, ARMv8 CE), they are used transparently - Software Fallbacks: Portable fixed-flow implementations preserve the same
Crypto.*semantics when a target lacks a native instruction - Failure safety: checked AEAD open operations release no unauthenticated plaintext and clear reusable output on failure
- Constant-flow primitives: tag comparison, AES portable fallback and polynomial multiplication avoid secret-dependent lookup tables and branches
- Target-width raw memory: every byte offset crossing a
RawBufboundary is a canonicalusize. Algorithms may retain wider logical counters or block indices, but never narrow them implicitly while addressing memory.
Raw integration boundary
Checked facades are the application API. Raw functions exist for runtimes and protocol implementations that already own exact storage; their capacities and aliasing requirements are explicit caller obligations. They fail closed rather than truncate an unaddressable u64 length. In particular, CTR requests are validated before their first output write, so a counter stream can never wrap and reuse keystream bytes. The initial-counter AES-CTR form permits its final u32::MAX block exactly once and rejects any request beyond that boundary.