mooncrypt — cryptographic algorithms for MoonBit, one algorithm per package: SHA-1, SHA-2, MD5, HMAC, HKDF, PBKDF2, Ed25519, ECDSA P-256 and RSA PKCS#1 v1.5, on a small set of traits so a third algorithm drops in without touching the library.
Dependencies
let sha256 = fn() -> &@spec.Hash { @sha2.Hasher::new() }
// A digest, a MAC, and a key derived from a password.
let digest = @sha2.hash(b"the quick brown fox"[:])
let tag = @hmac.mac(b"shared secret"[:], b"the quick brown fox"[:], sha256)
let key = @pbkdf2.key(b"correct horse"[:], b"battery staple"[:], sha256,
rounds=600000, len=32)
// A signature. Both schemes here are deterministic: the same key and message
// always give the same bytes, so there is no entropy source to get wrong.
let sk = @ed25519.PrivateKey::new(seed[:])
let sig = sk.sign(b"the quick brown fox"[:])
sk.public().verify(b"the quick brown fox"[:], sig[:]) // true| Package | What | Specification |
|---|---|---|
| spec | The Hash, Mac, Block, Aead, Signer and Verifier traits, constant-time comparison, erasure | — |
| hash/sha2 | SHA-224, SHA-256, SHA-384, SHA-512, SHA-512/224, SHA-512/256 | FIPS 180-4 |
| hash/sha1 | SHA-1 | FIPS 180-4 |
| hash/md5 | MD5 | RFC 1321 |
| mac/hmac | HMAC over any Hash | RFC 2104, FIPS 198-1 |
| kdf/hkdf | HKDF, extract and expand separately | RFC 5869 |
| kdf/pbkdf2 | PBKDF2 | RFC 8018 §5.2 |
| sign/ed25519 | Ed25519 | RFC 8032 |
| sign/ecdsa | ECDSA over P-256, P-384, P-521 and secp256k1, with RFC 6979 nonces | FIPS 186-4, RFC 6979 |
| sign/rsa | RSA PKCS#1 v1.5 and PSS signatures | RFC 8017 |
| cipher/aes | AES-128, AES-192 and AES-256, both directions | FIPS 197 |
| aead/gcm | GCM over any 128-bit block cipher, any nonce length, the seven tag lengths | SP 800-38D |
| kex/x25519 | X25519, with a low-order point refused | RFC 7748 |
| asn1 | ASN.1 DER, read and write — the layer a key file and a certificate are built on | ITU-T X.690 |
| Setting | Why there is no default | |
|---|---|---|
| pbkdf2.key(rounds~) | The iteration count is the whole security argument and goes out of date silently. Python's hashlib.pbkdf2_hmac, Go's pbkdf2.Key and Node's crypto.pbkdf2 all require it, so requiring it is the mainstream default | |
| len~ on both KDFs | How many bytes of key are wanted is a property of what the key is for | |
| gcm.Gcm::new(tag~) | 16 | The full 128-bit tag, the only length SP 800-38D appendix C leaves unqualified. The shorter ones it defines are there, and each costs forgery resistance the appendix works out |
moon add moonbitstack/mooncryptInstall
Download zipmooncrypt — cryptographic algorithms for MoonBit, one algorithm per package: SHA-1, SHA-2, MD5, HMAC, HKDF, PBKDF2, Ed25519, ECDSA P-256 and RSA PKCS#1 v1.5, on a small set of traits so a third algorithm drops in without touching the library.
Dependencies