Packages
Native Elixir authentication compatible with datadeft-auth Rust.
Current section
Files
Jump to
Current section
Files
datadeft_auth
CRYPTO-DEPENDENCIES.md
CRYPTO-DEPENDENCIES.md
# Crypto providers without a project-owned NIF
Owner approved removing the Rustler bridge from draft PR #45 after a
compiler-free compatibility probe and a Base62 benchmark. This supersedes
approval of the tiny Rust NIF; do not retain it as a fallback or restore the
Port. Rust stays the reference implementation for every wire format.
## Feature justification
1. **Problem:** Hex consumers need a straightforward installation on supported
BEAM runtimes, without a Rust compiler or platform-specific project artifacts.
2. **Existing behavior:** The Rustler bridge reuses the Rust Branca and BLAKE3
implementations. It already produces compatible bytes and bounded work.
3. **Gap:** Keeping the bridge requires source-build tooling or a checksummed
native release matrix. OTP `:crypto` does not directly provide XChaCha20-Poly1305
or BLAKE3, but the JOSE OTP backend and pure-Elixir `b3` provide the same
primitives without shipping native code. Doing nothing retains the toolchain
and artifact burden; no measured gain on normal cookies justified that cost.
4. **Smallest change:** Use JOSE's OTP-backed provider for Branca, use `b3` for
the two bounded public PoW hashes, and encode Base62 in nine-digit groups.
Keep the same limits, error types, token bytes, storage and Rust APIs. Do not
change the algorithms, add a backend option, or introduce hand-written crypto.
5. **Cost:** Two Hex dependencies replace Rustler. JOSE's backend module is
pinned and needs review on upgrades. OTP's crypto provider must support
ChaCha20 and ChaCha20-Poly1305. BEAM binaries do not promise deterministic
zeroization. Bounded Base62 work now runs on normal BEAM schedulers.
6. **Proof:** Run Rust Branca vectors, canonicality and tamper tests, shared
cookie and PoW checks, mixed storage tests, an exact Hex-archive consumer in
a Rust-free release environment, and concurrent Linux latency checks.
## Provider and failure contract
- `jose` 1.11.13: call the specific OTP-backed
`:jose_xchacha20_poly1305_crypto` module, not the global JOSE dispatcher.
Do not read or mutate JOSE's app-wide provider configuration. The backend
uses OTP ChaCha20 to derive the XChaCha subkey and OTP ChaCha20-Poly1305 for
authenticated encryption and tag checks. Provider errors fail closed; no
second provider is tried. Review those exported backend callbacks whenever
changing this pin.
- Branca keeps the exact version byte, big-endian timestamp, 24-byte OTP CSPRNG
nonce, and authenticated header. Keep the 32-byte key, 1,024-byte plaintext,
and 1,437-character token bounds. Reject noncanonical tokens before AEAD.
Decode does not authorize or check freshness. No caller-supplied mint nonce.
- `b3` 0.2.1: use its unkeyed 32-byte BLAKE3 output for the canonical PoW mint
input (at most 68 bytes) and the public challenge ID. The proof-of-work loop
still uses SHA-256, and tags still use HMAC-SHA256. No BLAKE3 key, solver, or
algorithm negotiation is exposed.
- Never log tokens, keys, payloads or provider exceptions. JOSE is MIT-licensed
and `b3` is Apache-2.0-licensed; both versions are pinned in Mix.