EXPERIMENTAL — pure-MoonBit cryptography / PKI / JOSE building blocks. Educational reference, not production-grade. No warranty.
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.
| Area | Modules | Notes |
|---|---|---|
| Encoding and foundations | asn1, cbor, crypto_bigint, getrandom | Strict DER/CBOR codecs, fixed-limb unsigned integers, and platform CSPRNG bridge. |
| Hashes, AEAD, and KDFs | hash, aead, hkdf, pbkdf2, scrypt, argon2 | SHA-1/2, RIPEMD-160, HMAC-SHA-2, BLAKE2b/3, ChaCha20/XChaCha20-Poly1305, AES-GCM/CBC, and password KDFs. |
| Key and certificate containers | pem, pkcs8, pkix, pkix_verify, ocsp, crl, cms | PEM, PKCS#8/PBES2, X.509 parsing, chain verification, revocation formats, and CMS SignedData. |
| Signature and key-exchange primitives | ed25519, x25519, p256, p384, p521, secp256k1, rsa | Ed/X25519, NIST ECDSA, secp256k1, and RSA PKCS#1 v1.5/PSS. |
| JOSE, COSE, SSH, PGP, and git formats | jwt, jwe, jwk, cose, ssh, pgp, git_object | Strict parsers/verifiers for compact JOSE, COSE_Sign1, SSHSIG-style signatures, OpenPGP detached signatures, and git signed-object bytes. |
| Wallet, box, and OTP protocols | bip39, bip32, hpke, naclbox, totp | BIP mnemonic/HD wallet helpers, HPKE base mode, libsodium-style box, and HOTP/TOTP. |
| File encryption | age_format | age v1 file decryption + deterministic encryption for X25519 recipients (X25519 + HKDF + ChaCha20-Poly1305 STREAM + Bech32); verified against the C2SP/CCTV age vectors. |
| Passwordless auth | webauthn | WebAuthn / FIDO2 verification — assertion + attestation (packed/fido-u2f/none) with rpId/UP/UV policy enforcement, authenticatorData/COSE_Key parsing (EC2 P-256/384, Ed25519, RSA RS/PS256/384/512), clientDataJSON binding; composes cbor + p256/p384/ed25519/rsa + pkix_verify. Verified against Yubico fido2 vectors. |
| Secure channel | noise | Noise Protocol Framework (25519 + ChaChaPoly + SHA256) handshake state machine — patterns NN/NK/XX/IK; verified against the flynn/noise vectors. Basis of WireGuard / Signal X3DH. |
| Transport | tls13 | TLS 1.3 (RFC 8446) client 1-RTT handshake building blocks — key schedule, record layer, handshake/message codecs, ClientHello builder, and server authentication (CertificateVerify + Finished) — wired by a one-shot client driver; verified end-to-end against RFC 8448 §3. Live ECDHE/record glue WIP. |
| Sidecar tooling | proofs, leakage_harness | SMT proof leaves and native sparse-vs-dense leakage measurement harnesses. |
| 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 |
| 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`Install
Download zipEXPERIMENTAL — pure-MoonBit cryptography / PKI / JOSE building blocks. Educational reference, not production-grade. No warranty.