EXPERIMENTAL — pure-MoonBit cryptography / PKI / JOSE building blocks. Educational reference, not production-grade. No warranty.
Dependencies
Status: experimental — not for production. This workspace exists to fill gaps in the MoonBit ecosystem so other people writing MoonBit code have something to read and reuse. None of the modules have been independently audited. Constant-time discipline, side-channel resistance, and on-wire format edge cases are documented but not certified.If you use any of this code in a real system, you are responsible for reviewing the source first and confirming it meets your security requirements. The author disclaims all liability for use. Prefer a vetted library (RustCrypto, dalek, BoringSSL, etc.) wherever one exists for your protocol.
| Package | RFC / Spec | Role |
|---|---|---|
| asn1 | X.690 (DER) / X.680 | Strict canonical DER encoder + decoder (MAX_DEPTH=32). |
| cbor | RFC 8949 | CBOR major types 0–7 + tags; consumed by COSE / WebAuthn. |
| crypto_bigint | — (RustCrypto crypto-bigint shape) | Fixed-limb unsigned ints, modular arithmetic, Montgomery pow. |
| getrandom | — (platform CSPRNG) | crypto.getRandomValues / arc4random_buf / getrandom(2) / BCryptGenRandom. |
| keygen | FIPS 186-5, RFC 8017 | generateKey for P-256 / P-384 / Ed25519 / X25519 + RSA (Miller–Rabin prime search) key pairs (CSPRNG-backed; native/js). |
| Package | RFC / Spec | Role |
|---|---|---|
| hash | FIPS 180-4, RFC 2104, ISO 10118-3, BLAKE2/3 | SHA-1/256/384/512, RIPEMD-160, HMAC-SHA-2, BLAKE2b/3, ct_eq. |
| sha3 | FIPS 202 | Keccak-f[1600]: SHA3-256/512 + SHAKE128/256 (used by ML-KEM). |
| mlkem | FIPS 203 | ML-KEM-768 post-quantum KEM (keygen / encaps / decaps; KAT-verified). |
| pqhybrid | draft-kwiatkowski-tls-ecdhe-mlkem (0x11ec) | X25519MLKEM768 hybrid KEX (ML-KEM-768 ‖ X25519) for TLS 1.3 — browser default. |
| aead | RFC 8439, NIST SP 800-38D / 38A | ChaCha20- / XChaCha20-Poly1305, AES-128/256-GCM, AES-CBC, AES-CTR. |
| aeskw | RFC 3394 | AES Key Wrap / Unwrap (128/192/256-bit KEK); used by jwe A256KW. |
| pkix | RFC 5280 | X.509 v3 parse + byte-stable DER round-trip. |
| pkcs8 | RFC 5208 / 5958, RFC 8018 | PrivateKeyInfo + EncryptedPrivateKeyInfo (PBES2). |
| pem | RFC 7468 | PEM encode / decode with strict label + size caps. |
| hkdf | RFC 5869 | HKDF-Extract + Expand on HMAC-SHA-256. |
| pbkdf2 | RFC 8018 | PBKDF2-HMAC-SHA-256. |
| scrypt | RFC 7914 | scrypt + PHC string encode / verify. |
| argon2 | RFC 9106 | Argon2d / i / id + PHC string encode / verify. |
| Package | RFC / Spec | Role |
|---|---|---|
| ed25519 | RFC 8032 | Ed25519 sign + verify (+ verify_strict). |
| ed448 | RFC 8032 | Ed448 signature verify (edwards448, SHAKE256, projective). |
| x25519 | RFC 7748 | X25519 ECDH (10-limb Montgomery ladder). |
| x448 | RFC 7748 | X448 ECDH (Curve448 Montgomery ladder, 16-limb radix-2^28 field, branch-free). |
| p256 | FIPS 186-5, SEC 1, RFC 5903 | ECDSA-SHA-256 sign (RFC 6979) + verify, ECDH. |
| p384 | FIPS 186-5, RFC 5903 | ECDSA-SHA-384 sign + verify, ECDH. |
| p521 | FIPS 186-5 | ECDSA-SHA-512 (ES512) sign + verify. |
| secp256k1 | SEC 2 §2.4.1 | ECDSA + RFC 6979 + BIP-62 low-s (Bitcoin / Ethereum). |
| rsa | RFC 8017 | RSA PKCS#1 v1.5 + RSA-PSS sign + verify, RSA-OAEP (SHA-1/256/384/512 + label) encrypt / decrypt. |
| Package | RFC / Spec | Role |
|---|---|---|
| pkix_verify | RFC 5280 §6 | X.509 chain validation (Ed25519 / RSA / ECDSA-SHA-2). |
| naclbox | libsodium crypto_box (XChaCha20) | Curve25519 + XChaCha20-Poly1305 box. |
| hpke | RFC 9180 | Mode_Base DHKEM(X25519) / HKDF-SHA256 / ChaCha20Poly1305. |
| ech | draft-ietf-tls-esni (0xfe0d) | Encrypted ClientHello: ECHConfigList parse + HPKE seal/open of the inner CH. |
| webpush | RFC 8291 / 8188 | Web Push aes128gcm message decrypt (P-256 ECDH + HKDF). |
| bip39 | BIP-39 | Mnemonic ↔ entropy + PBKDF2-HMAC-SHA-512 seed. |
| bip32 | BIP-32 | HD key derivation on secp256k1. |
| cose | RFC 9052 | COSE_Sign1 verify + COSE_Key parser. |
| Package | RFC / Spec | Role |
|---|---|---|
| jwt | RFC 7515 / 7519 / 7518 | JWS / JWT sign + verify (HS / RS / PS / ES / EdDSA). |
| jwe | RFC 7516 / 7518 | JWE compact (dir / RSA-OAEP-256 / A256KW + A128/256GCM). |
| jwk | RFC 7517 / 7518 / 7638 / 8037 | JWK parse / serialise / thumbprint. |
| totp | RFC 4226 / 6238 | HOTP / TOTP + provisioning URI. |
| pgp | RFC 9580 (+ RFC 4880) | OpenPGP v4 / v6 detached signature verify + sign. |
| ssh | SSHSIG-style subset | SSHSIG armor sign + verify + OpenSSH user certs. |
| cms | RFC 5652 | CMS SignedData detached verify. |
| git_object | git object format | Commit / tag signature extraction. |
| ocsp | RFC 6960 | OCSP response parse + verify. |
| ct | RFC 6962 | Certificate Transparency SCT list parse + signature verify (x509 / precert entry). |
| crl | RFC 5280 §5 | CRL parse + verify + is_revoked. |
| webauthn | W3C WebAuthn L2 / FIDO CTAP2 | Assertion + attestation (packed / fido-u2f / none) verification. |
| age_format | C2SP age v1 | age file decrypt + deterministic encrypt for X25519 recipients. |
| noise | Noise Protocol Framework | NN / NK / XX / IK handshake state machine (25519 + ChaChaPoly + SHA256). |
| tls13 | RFC 8446 (vectors: RFC 8448) | TLS 1.3 client 1-RTT handshake building blocks (live glue WIP). |
| tls12 | RFC 5246/5288/7627/8422, RFC 6066/6960 | TLS 1.2 PRF + key schedule + AES-GCM records + ECDHE handshake + verified server auth (chain + hostname + SKE + OCSP stapling). |
| quic | RFC 9001 | QUIC v1 Initial key derivation + AES-128-GCM packet protection + AES header-protection mask (vectors: RFC 9001 App. A). |
| Package | RFC / Spec | Role |
|---|---|---|
| proofs | — | SMT proof leaves (moon prove + Why3 + Z3). |
| leakage_harness | — | Native sparse-vs-dense leakage measurement. |
| gpg.format | Format | Modules |
|---|---|---|
| ssh | SSHSIG-style armor | git_object + ssh + key primitives |
| openpgp | OpenPGP detached signature armor | git_object + pgp + hash |
| x509 | CMS SignedData detached signature | git_object + cms + pkix_verify |
moon test # all sub-packages
moon test --target all # wasm-gc + wasm + native
moon test -p mizchi/experimental_crypto/asn1 # single sub-package
moon bench --release -p mizchi/experimental_crypto/x25519
moon check --target all| Operation | Time | Notes |
|---|---|---|
| asn1 encode flat SEQUENCE x100 | ~3.1 us | depth benchmarks use the enforced MAX_DEPTH=32 |
| asn1 decode flat SEQUENCE x100 | ~2.2 us | |
| crypto_bigint 256-bit pow_mod | ~108-109 us | sparse and dense exponent classes |
| crypto_bigint 256-bit inv_mod | ~109-112 us | sparse and dense input classes |
| aead ChaCha20-Poly1305 seal 1 KiB | ~5.3 us | |
| aead AES-128-GCM seal 1 KiB | ~9.2 us | portable 4-bit Shoup GHASH; no hardware CLMUL |
| x25519 ECDH | ~85 us | 10-limb Montgomery ladder |
| sha3 SHA3-256 1 KiB | ~58 us | Keccak-f[1600], pure UInt64 |
| sha3 SHA3-512 1 KiB | ~107 us | rate 72, so more permutation calls |
| quic initial_keys | ~34 us | RFC 9001 Initial secret HKDF chain |
| quic seal_payload 1200 B | ~36 us | AES-128-GCM, near-MTU packet |
| mlkem keygen / encaps / decaps | ~0.93 / 1.0 / 1.1 ms | ML-KEM-768; decaps re-encrypts (implicit reject) |
| pqhybrid server_respond / client_finish | ~1.7 / 1.4 ms | X25519MLKEM768 (ML-KEM dominates) |
| x448 ECDH | ~2.8 ms | 16-limb radix-2^28 Goldilocks field (was ~11.5 ms on @bigint) |
| ed448 verify | ~8.1 ms | limb field + Shamir double-scalar trick (was ~55 ms on @bigint) |
| p256 sign | ~2.0 ms | fixed-iteration sign-side scalar path |
| p384 sign | ~5.2 ms | fixed-iteration sign-side scalar path |
| secp256k1 sign | ~2.0 ms | fixed-iteration sign-side scalar path |
| pbkdf2 HMAC-SHA256 c=1k dkLen=32 | ~542 us | |
| pbkdf2 HMAC-SHA256 c=10k dkLen=32 | ~5.9 ms |
.
├── moon.mod # single module manifest (mizchi/experimental_crypto)
├── README.md # this file
├── .gitignore
└── <subpkg>/
├── moon.pkg # package imports, native stubs, target maps
├── <subpkg>.mbt # main source
├── <subpkg>_test.mbt # blackbox tests
├── <subpkg>_wbtest.mbt # whitebox tests (where useful)
└── pkg.generated.mbti # public API snapshot, regenerated by `moon info`EXPERIMENTAL — pure-MoonBit cryptography / PKI / JOSE building blocks. Educational reference, not production-grade. No warranty.
Dependencies