// aead.h // ChaCha20-Poly1305 (RFC 8439) with Noise-style nonces. // // The 96-bit nonce is 32 zero bits followed by a 64-bit little-endian counter (Noise spec, section 12.3). // Every key in this library is used in one direction only, so a counter never repeats under a key. #ifndef BRAVAIS_AEAD_H #define BRAVAIS_AEAD_H #include #include #include "bravais.h" #include "bravais_internal.h" // Encrypt. out receives ptLen + BRAVAIS_AEAD_TAG_LENGTH bytes and may equal pt (in place). void bravais_aead_seal(const uint8_t* key, uint64_t counter, const uint8_t* ad, size_t adLen, const uint8_t* pt, size_t ptLen, uint8_t* out); // Decrypt and verify. out receives ctLen - BRAVAIS_AEAD_TAG_LENGTH bytes and may equal ct (in place). // BRAVAIS_ERR_AUTH on a bad tag (out is zeroed), BRAVAIS_ERR_MALFORMED if ctLen is shorter than a tag. bravais_result_t bravais_aead_open(const uint8_t* key, uint64_t counter, const uint8_t* ad, size_t adLen, const uint8_t* ct, size_t ctLen, uint8_t* out); #endif // BRAVAIS_AEAD_H