feat(std/cipher): add ChaCha20-Poly1305 AEAD (RFC 8439) #266
Loading…
Reference in a new issue
No description provided.
Delete branch "loop/264-std-cipher"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Task
Closes #264
What
New package
std/cipherwithChaCha20Poly1305(RFC 8439), modelled onstd/signatureandstd/digest:ChaCha20Poly1305.tryFrom(key)takes exactly 32 bytes (CipherError.WrongLengthotherwise);seal(nonce, plaintext, associated)answers the ciphertext followed by the 16-byte tag,open(nonce, sealed, associated)answers the plaintext orCipherError.Forgedwith no detail. The nonce is exactly 12 bytes. Methods, not free functions.opencomputes the tag first, compares it withstd/digestconstantTimeEqual, and decrypts only after it matched.CipherErrorare exported. ChaCha20 and Poly1305 stay in the package and are tested directly.ShowandEncodeof a key write no key byte.docs/standard-library/cipher.mdand the index: nonce reuse (never repeat a nonce under one key; random 96-bit nonces are safe up to about 2^32 messages per key), what is and is not constant time, measured speed (32 bytes and 1 MiB, VM and native).benchmarks/cipher.trbproduces the numbers;skills/regenerated.Test
torb test std/cipher/tests(VM, published toolchain): 26 passed. Native and VM in CI: CI of the previous push ran every cipher test green in both; the one other red test of that run (Formatting > a call of a field that holds a function ...incompiler/tests/language-server.test.trb) is not in this change.Encode) is fixed and tested, its documentation findings are applied.cf52b743e761b439511d61b439511dcd168a5565cd168a55652a1d8ae385std/cipherwith ChaCha20-Poly1305 (RFC 8439) #264Approved. Checklist for head
2a1d8ae:h/gselect by mask and the add ofswith carries are all right. The AEAD construction (padding, length trailer, one-time key from block 0, counter starting at 1) matches section 2.8.openverifies the tag before it decrypts.constantTimeEqual. All failures are the single detail-freeForged.Show/Encodewrite no key byte and a test covers it. Only the AEAD andCipherErrorare exported. No secrets in the diff.docs/standard-library/cipher.md, the index and the regeneratedskills/are present. They cover nonce reuse, the limits of the constant-time claim, and measured speeds.std/signaturelayout.Non-blocking:
benchmarks/cipher.trbis not run by CI orrun.sh, so the quoted speeds are not reproducible by a gate. That is fine as documented.1 MiBtiming in the docs is VM-bound (about 0.13 MiB/s). The docs already say so.std/cipherwith ChaCha20-Poly1305 (RFC 8439) #264std/cipherwith ChaCha20-Poly1305 (RFC 8439) #264std/cipherwith ChaCha20-Poly1305 (RFC 8439) #264