# Cryptography builtins in the MAX runtime

Canonical page: https://keilab.io/security/max-crypto/

security · max cryptography

TLS 1.3's record layer, key schedule and handshake, Ed25519 signatures, ChaCha20-Poly1305 AEAD, Argon2id key derivation, and BLAKE2b hashing — C implementations inside the MAX runtime, exposed to MAX programs as builtins, gated against RFC known-answer vectors rather than assumed correct; the hot-path primitives also exist as FPGA RTL verified in simulation.

## Why own the implementation

Most stacks import a crypto library as an opaque dependency. The MAX runtime carries its own C implementations instead — Ed25519 ported from TweetNaCl, Argon2id and BLAKE2b ported from the Argon2 reference code, and TLS 1.3's record layer, key schedule and handshake — exposed to MAX programs as builtins. The discipline is the one the lab applies to its compiler and its OS: own the primitive end to end and verify it against the standard's own test vectors.

## How it is verified

- TLS 1.3 record layer — nonce sequencing, additional-authenticated-data framing, round-trip, and tamper-rejection all checked against known-answer tests.
- Ed25519 — verified against the RFC 8032 §7.1 official test vector, hardened against the S<L malleability, all-zero-public-key, and non-canonical-y classes of signature-forgery bugs.
- Argon2id — RFC 9106 memory-hard key derivation.
- A TLS 1.3 handshake gate replays the RFC 8448 example handshake offline, exercising the stack end to end, not just its individual primitives in isolation.

## Also as FPGA RTL — in simulation

The same per-frame crypto hot path — SHA-256 and Poly1305 — also exists as a hand-written hardware circuit (Verilog) for the programmable-logic fabric of a Xilinx Zynq-7020. It is verified in Verilator simulation against a golden-vector testbench to be byte-identical to the MAX/C software core — the same discipline applied one layer lower.

## Where it is used

These builtins serve MAX programs that need cryptography. The lab's Rust projects, such as KeiAuth and kgl-overlay, use standard open-source crypto libraries instead.

cross-references

- [→ MAX (the language)](https://keilab.io/ai/max/)
- [→ MAX-OS on silicon (FPGA)](https://keilab.io/hardware/max-os-silicon/)
- [⊘ Security overview](https://keilab.io/security/)

Status: In development

Form: C in the MAX runtime, exposed as builtins

TLS 1.3: Record layer + key schedule + handshake (RFC 8446; RFC 8448 replay)

Signatures: Ed25519, ported from TweetNaCl (RFC 8032 §7.1 / §5.1.x hardened)

AEAD: ChaCha20-Poly1305

KDF / hash: Argon2id (RFC 9106) · BLAKE2b — ported from the Argon2 reference code

FPGA RTL: SHA-256 / Poly1305 for Zynq-7020 — verified in simulation

Sensitivity: Engineering public

[⊸ Engineering inquiry](https://keilab.io/contact/)

---
KeiLab is operated by KeiSei LLC, a Wyoming limited liability company. +1 307 210 8538
Site index for AI agents: https://keilab.io/llms.txt
