silk/chacha20_poly1305
Profiles: aarch64-apple-darwin, aarch64-unknown-linux-gnu, aarch64-unknown-linux-gnu-no-libc, wasm32-unknown-unknown, x86_64-unknown-linux-gnu, x86_64-unknown-linux-gnu-no-libc.
Detached ChaCha20-Poly1305 authenticated encryption from RFC 8439.
When to use
Use ChaCha20Poly1305 when a protocol specifies the IETF 96-bit nonce variant.
Details
Operations borrow inputs and write caller-owned destinations without allocation or services. Every rejected operation leaves every destination unchanged. Opening authenticates first.
Gotchas
Never reuse a nonce with a key, including across processes or restarts. Callers own nonce allocation and per-key usage limits. Fixed-work source is not a constant-time or secure-erasure guarantee for every compiler and target. This module does not implement a transport protocol.
Import as ChaCha20Poly1305 with import silk.chacha20_poly1305 { ChaCha20Poly1305 }.
Public declarations: 2.
AeadError
pub enum AeadErrorThe first rejected condition, in declaration order.
InvalidKey
InvalidKey = 0The key is not exactly 32 bytes.
InvalidNonce
InvalidNonce = 1The nonce is not exactly 12 bytes.
InvalidTag
InvalidTag = 2The detached tag is not exactly 16 bytes.
OutputTooSmall
OutputTooSmall = 3The payload destination is shorter than the input payload.
LimitExceeded
LimitExceeded = 4The payload exceeds 274877906880 bytes, exhausting the 32-bit block counter.
AuthenticationFailed
AuthenticationFailed = 5The complete 16-byte authentication tag does not match.
ChaCha20Poly1305
pub struct ChaCha20Poly1305The allocation-free IETF ChaCha20-Poly1305 authenticated-encryption operations.
Details
Keys are 32 bytes, nonces 12 bytes, and detached tags 16 bytes. Payloads may contain at most
274877906880 bytes; AAD lengths must fit u64, as all addressable Silk slices do.
Output capacity may exceed the payload length; the unused suffix is preserved.
Associated function ChaCha20Poly1305.seal
pub fn seal<'life0, 'life1, 'life2, 'life3, 'life4, 'life5>(key: &'life0 [u8], nonce: &'life1 [u8], aad: &'life2 [u8], plaintext: &'life3 [u8], ciphertext: &'life4 mut [u8], tag: &'life5 mut [u8]) -> silk/result.Result<(), silk/chacha20_poly1305.AeadError>Encrypts plaintext into ciphertext and writes its detached authentication tag.
Details
Checks key, nonce, tag, capacity, then counter limits before writing either destination.
Returns the first AeadError on rejection and preserves both destinations completely.
Gotchas
The caller must provide a unique nonce for each encryption under the same key.
Associated function ChaCha20Poly1305.open
pub fn open<'life0, 'life1, 'life2, 'life3, 'life4, 'life5>(key: &'life0 [u8], nonce: &'life1 [u8], aad: &'life2 [u8], ciphertext: &'life3 [u8], tag: &'life4 [u8], plaintext: &'life5 mut [u8]) -> silk/result.Result<(), silk/chacha20_poly1305.AeadError>Authenticates ciphertext and decrypts it into plaintext only when its tag matches.
Details
Checks key, nonce, tag, capacity, then counter limits before authentication. All 16 tag bytes participate in comparison. Every failure preserves the entire plaintext destination. A successful operation writes only the prefix corresponding to the ciphertext length.