import type { ChaChaExports } from './types.js'; /** * ChaCha20-Poly1305 AEAD encrypt (RFC 8439 §2.8). * @param x ChaCha20 WASM exports * @param key 32-byte key * @param nonce 12-byte nonce, must be unique per (key, message) * @param plaintext Data to encrypt (must be ≤ WASM CHUNK_SIZE) * @param aad Additional authenticated data * @returns `{ ciphertext, tag }`, tag is 16 bytes */ export declare function aeadEncrypt(x: ChaChaExports, key: Uint8Array, nonce: Uint8Array, plaintext: Uint8Array, aad: Uint8Array): { ciphertext: Uint8Array; tag: Uint8Array; }; /** * ChaCha20-Poly1305 AEAD decrypt with constant-time tag comparison (RFC 8439 §2.8). * Throws `AuthenticationError` on tag mismatch; never returns plaintext on failure. * @param x ChaCha20 WASM exports * @param key 32-byte key * @param nonce 12-byte nonce, must match the value used to encrypt * @param ciphertext Ciphertext bytes (must be ≤ WASM CHUNK_SIZE) * @param tag 16-byte Poly1305 tag * @param aad Additional authenticated data * @param cipherName Error label for `AuthenticationError` (default 'chacha20-poly1305') * @returns Plaintext */ export declare function aeadDecrypt(x: ChaChaExports, key: Uint8Array, nonce: Uint8Array, ciphertext: Uint8Array, tag: Uint8Array, aad: Uint8Array, cipherName?: string): Uint8Array; /** * Derive a 32-byte HChaCha20 subkey from `key` and the first 16 bytes of `nonce`. * Used as the inner key for XChaCha20-Poly1305 (draft-irtf-cfrg-xchacha §2.3). * @param x ChaCha20 WASM exports * @param key 32-byte master key * @param nonce 24-byte XChaCha20 nonce (only bytes 0-15 are used) * @returns 32-byte HChaCha20 subkey */ export declare function deriveSubkey(x: ChaChaExports, key: Uint8Array, nonce: Uint8Array): Uint8Array; /** * Build the inner 12-byte ChaCha20 nonce for XChaCha20 from bytes 16-23 of the * 24-byte XChaCha nonce (draft-irtf-cfrg-xchacha §2.3). * @param nonce 24-byte XChaCha20 nonce * @returns 12-byte inner nonce (bytes 0-3 are zero, bytes 4-11 are nonce[16:24]) */ export declare function innerNonce(nonce: Uint8Array): Uint8Array; /** * XChaCha20-Poly1305 encrypt (draft-irtf-cfrg-xchacha). * Derives HChaCha20 subkey from `key` + nonce[0:16], then runs * ChaCha20-Poly1305 with a 12-byte inner nonce (nonce[16:24]). * @param x ChaCha20 WASM exports * @param key 32-byte key * @param nonce 24-byte nonce * @param plaintext Data to encrypt * @param aad Additional authenticated data * @returns Ciphertext || 16-byte Poly1305 tag */ export declare function xcEncrypt(x: ChaChaExports, key: Uint8Array, nonce: Uint8Array, plaintext: Uint8Array, aad: Uint8Array): Uint8Array; /** * XChaCha20-Poly1305 decrypt (draft-irtf-cfrg-xchacha). * Derives HChaCha20 subkey, verifies the Poly1305 tag, then decrypts. * Throws `AuthenticationError` on tag mismatch. * @param x ChaCha20 WASM exports * @param key 32-byte key * @param nonce 24-byte nonce, must match the value used to encrypt * @param ciphertext Ciphertext || 16-byte tag (combined format from `xcEncrypt`) * @param aad Additional authenticated data * @returns Plaintext */ export declare function xcDecrypt(x: ChaChaExports, key: Uint8Array, nonce: Uint8Array, ciphertext: Uint8Array, aad: Uint8Array): Uint8Array;