Skip to content
xero edited this page Mar 28, 2026 · 21 revisions

Leviathan Crypto Library

  ██     ▐█████ ██     ▐█▌  ▄█▌   ███▌ ▀███████▀▄██▌  ▐█▌  ███▌    ██▌   ▓▓
 ▐█▌     ▐█▌    ▓█     ▐█▌  ▓██  ▐█▌██    ▐█▌   ███   ██▌ ▐█▌██    ▓██   ██
 ██▌     ░███   ▐█▌    ██   ▀▀   ██ ▐█▌   ██   ▐██▌   █▓  ▓█ ▐█▌  ▐███▌  █▓
 ██      ██     ▐█▌    █▓  ▐██  ▐█▌  █▓   ██   ▐██▄▄ ▐█▌ ▐█▌  ██  ▐█▌██ ▐█▌
▐█▌     ▐█▌      ██   ▐█▌  ██   ██   ██  ▐█▌   ██▀▀████▌ ██   ██  ██ ▐█▌▐█▌
▐▒▌     ▐▒▌      ▐▒▌  ██   ▒█   ██▀▀▀██▌ ▐▒▌   ▒█    █▓░ ▒█▀▀▀██▌ ▒█  ██▐█
█▓ ▄▄▓█ █▓ ▄▄▓█   ▓▓ ▐▓▌  ▐▓▌  ▐█▌   ▐▒▌ █▓   ▐▓▌   ▐▓█ ▐▓▌   ▐▒▌▐▓▌  ▐███
▓██▀▀   ▓██▀▀      ▓█▓█   ▐█▌  ▐█▌   ▐▓▌ ▓█   ▐█▌   ▐█▓ ▐█▌   ▐▓▌▐█▌   ██▓
                    ▓█                               ▀▀        ▐█▌▌▌

Web cryptography built on Serpent-256 paranoia and XChaCha20-Poly1305 elegance.


Quick Start

bun i leviathan-crypto
# or npm
npm install leviathan-crypto
import { init, SerpentSeal, randomBytes } from 'leviathan-crypto'

await init(['serpent', 'sha2'])

const key = randomBytes(64)
const seal = new SerpentSeal()

const ciphertext = seal.encrypt(key, plaintext)
const decrypted  = seal.decrypt(key, ciphertext) // throws on tamper

seal.dispose()

For more: streaming, chunking, hashing, key derivation, and both ciphers: see the examples page.


Getting Started

Document Description
architecture.md Architecture overview, build pipeline, module relationships, buffer layouts
init.md init() API, three loading modes, subpath imports, tree-shaking
wasm.md WebAssembly primer in the context of this library
examples.md Code examples for every primitive
exports.md Comprehensive export reference detailing each class, function, and type

API Reference

Serpent-256

Module Description
serpent.md TypeScript API: SerpentSeal, SerpentStream, SerpentStreamPool, SerpentStreamSealer, SerpentStreamOpener, Serpent, SerpentCtr, SerpentCbc
asm_serpent.md WASM implementation: bitslice S-boxes, key schedule, CTR/CBC modes

XChaCha20 / Poly1305

Module Description
chacha20.md TypeScript API: ChaCha20, Poly1305, ChaCha20Poly1305, XChaCha20Poly1305
chacha20_pool.md XChaCha20Poly1305Pool: parallel worker pool for authenticated encryption
asm_chacha.md WASM implementation: quarter-round, Poly1305 accumulator, HChaCha20

SHA-2

Module Description
sha2.md TypeScript API: SHA256, SHA512, SHA384, HMAC_SHA256, HMAC_SHA384, HMAC_SHA512, HKDF_SHA256, HKDF_SHA512
asm_sha2.md WASM implementation: compression functions, HMAC inner/outer padding

SHA-3

Module Description
sha3.md TypeScript API: SHA3_224, SHA3_256, SHA3_384, SHA3_512, SHAKE128, SHAKE256
asm_sha3.md WASM implementation: Keccak permutation (1600-bit state), sponge construction

Fortuna CSPRNG

Module Description
fortuna.md Fortuna: CSPRNG with forward secrecy, 32 entropy pools, browser + Node.js collectors

Utilities & Types

Module Description
utils.md Encoding helpers, constantTimeEqual, wipe, randomBytes no init() required
types.md TypeScript interfaces: Hash, KeyedHash, Blockcipher, Streamcipher, AEAD

Internal

Module Description
loader.md WASM binary loading: embedded (base64), streaming (fetch), manual

Project Documentation

Document Description
architecture.md Repository structure, architecture diagram, build pipeline, module relationships, buffer layouts, correctness contract, limitations
test-suite.md Test suite structure, vector corpus, gate discipline
serpent_reference.md Serpent algorithm: S-boxes, linear transform, round structure, known attacks
wasm.md WebAssembly primer in the context of this library
argon2id.md Key derivation and password hashing with Argon2id alongside Leviathan primitives
branding.md Project artwork and branding materials

Performance

Document Description
serpent_simd_bench.md Serpent-256 SIMD benchmark results: CTR and CBC-decrypt inter-block 4-wide, scalar vs SIMD across V8, SpiderMonkey, and JSC
chacha_simd_bench.md ChaCha20 SIMD benchmark results: 4-wide inter-block parallelism, scalar vs SIMD across V8, SpiderMonkey, and JSC. Includes documented negative result for intra-block approach

Algorithm Correctness and Verifications

Primitive Audit Description
serpent_audit.md Correctness verification, side-channel analysis, cryptanalytic attack paper review
chacha_audit.md XChaCha20-Poly1305 correctness, Poly1305 field arithmetic, HChaCha20 nonce extension
sha2_audit.md SHA-256/512/384 correctness, HMAC and HKDF composition, constant verification
sha3_audit.md Keccak permutation correctness, θ/ρ/π/χ/ι step verification, round constant derivation
hmac_audit.md HMAC-SHA256/512/384 construction, key processing, RFC 4231 vector coverage
hkdf_audit.md HKDF extract-then-expand, info field domain separation, SerpentStream key derivation

Demos

Name Link Code Docs Description
lvthn-web 🛈 Encrypt text or files using Serpent-256-CBC and Argon2id key derivation from a single local html file, with armored output. No server, installation, or network connection required after initial load.
lvthn-chat 🛈 End-to-end encrypted chat featuring two-party messaging over X25519 key exchange and XChaCha20-Poly1305 message encryption. Relay server functions as a dumb WebSocket pipe never seeing plaintexts.
lvthn-cli 🛈 File encryption CLI tool supporting both Serpent-256 and XChaCha20-Poly1305 via the --cipher flag. Keyfiles are compatible with both ciphers; the header byte determines decryption automatically.

Leviathan-Crypto Wiki

Leviathan logo

Getting Started

Authenticated Encryption

Digital Signatures

Ciphers

  • Serpent-256 TypeScript | WASM
    • Serpent, SerpentCtr, SerpentCbc, SerpentGenerator
  • ChaCha20 TypeScript | WASM
    • ChaCha20, Poly1305, ChaCha20Poly1305, XChaCha20Poly1305, ChaCha20Generator
  • AES TypeScript | WASM
    • AES, AESCbc, AESCtr, AESGCM, AESGCMSIV, AESGenerator

Signature Primitives

  • ML-DSA TypeScript | WASM
    • pure (FIPS 204): MlDsa44, MlDsa65, MlDsa87
    • pure-mode suites: MlDsa44Suite, MlDsa65Suite, MlDsa87Suite
    • prehash suites: MlDsa44PreHashSuite, MlDsa65PreHashSuite, MlDsa87PreHashSuite
  • SLH-DSA TypeScript | WASM
    • pure (FIPS 205): SlhDsa128f, SlhDsa192f, SlhDsa256f
    • pure-mode suites: SlhDsa128fSuite, SlhDsa192fSuite, SlhDsa256fSuite
    • prehash suites: SlhDsa128fPreHashSuite, SlhDsa192fPreHashSuite, SlhDsa256fPreHashSuite
  • Ed25519 TypeScript | WASM
    • Ed25519 (pure + Ed25519ph), Ed25519Suite, Ed25519PreHashSuite
  • ECDSA-P256 TypeScript | WASM
    • EcdsaP256 (hedged + RFC 6979), EcdsaP256Suite
    • DER codec: ecdsaSignatureToDer, ecdsaSignatureFromDer, encodeEcPrivateKey, decodeEcPrivateKey, pointDecompress
  • Hybrid composites PQ-only | Classical+PQ
    • PQ-only: MlDsa44SlhDsa128fSuite, MlDsa65SlhDsa192fSuite, MlDsa87SlhDsa256fSuite
    • Classical+PQ: MlDsa44Ed25519Suite, MlDsa65Ed25519Suite, MlDsa44EcdsaP256Suite, MlDsa65EcdsaP256Suite

Key Agreement

Post-Quantum

  • ML-KEM TypeScript | WASM
    • MlKem512, MlKem768, MlKem1024
  • Ratchet (SPQR)
    • KDFChain, ratchetInit, kemRatchetEncap, kemRatchetDecap, RatchetKeypair, SkippedKeyStore

Hashing

  • Hashing overview
  • SHA-2 TypeScript | WASM
    • SHA256, SHA384, SHA512, SHA224, SHA512_224, SHA512_256
    • HMAC_SHA256, HMAC_SHA384, HMAC_SHA512, HKDF_SHA256, HKDF_SHA512
  • SHA-3 TypeScript | WASM
    • SHA3_224, SHA3_256, SHA3_384, SHA3_512, SHAKE128, SHAKE256
  • BLAKE3 TypeScript | WASM
    • BLAKE3, BLAKE3Stream, BLAKE3KeyedHash, BLAKE3KeyedHashStream
    • BLAKE3DeriveKey, BLAKE3DeriveKeyStream, BLAKE3OutputReader, BLAKE3Hash
  • KMAC
    • CSHAKE128, CSHAKE256, KMAC128, KMAC256, KMACXOF128, KMACXOF256

Transparency Log

  • Merkle
    • MerkleVerifier, MerkleLog
    • SignedLog, Sha256Tree, Blake3Tree, MemoryStorage

Utilities

  • Fortuna CSPRNG
    • Fortuna, SerpentGenerator, ChaCha20Generator, AESGenerator, SHA256Hash, SHA3_256Hash, BLAKE3Hash
  • Utils TypeScript | WASM
    • constantTimeEqual, randomBytes, wipe, encoding helpers
  • TypeScript interfaces
    • Hash, KeyedHash, Blockcipher, Streamcipher, AEAD, Generator, HashFn

Project

Reference

Clone this wiki locally