File syn_chacha20poly1305.h¶
FileList > crypto > syn_chacha20poly1305.h
Go to the source code of this file
ChaCha20-Poly1305 AEAD — RFC 8439, pure C99. More...
#include <stdbool.h>#include <stddef.h>#include <stdint.h>
Public Functions¶
| Type | Name |
|---|---|
| bool | syn_aead_decrypt (const uint8_t key, const uint8_t nonce, const uint8_t * aad, size_t aad_len, const uint8_t * ciphertext, size_t ct_len, const uint8_t tag, uint8_t * plaintext) Decrypt and verify (AEAD). |
| bool | syn_aead_decrypt_inplace (const uint8_t key, const uint8_t nonce, const uint8_t * aad, size_t aad_len, uint8_t * buf, size_t len, const uint8_t tag) Zero-copy in-place AEAD decryption & tag verification. |
| void | syn_aead_encrypt (const uint8_t key, const uint8_t nonce, const uint8_t * aad, size_t aad_len, const uint8_t * plaintext, size_t pt_len, uint8_t * ciphertext, uint8_t tag) Encrypt and authenticate (AEAD). |
| void | syn_aead_encrypt_inplace (const uint8_t key, const uint8_t nonce, const uint8_t * aad, size_t aad_len, uint8_t * buf, size_t len, uint8_t tag) Zero-copy in-place AEAD encryption. |
| void | syn_chacha20_block (const uint8_t key, const uint8_t nonce, uint32_t counter, uint8_t out) Generate ChaCha20 keystream block (no XOR). |
| void | syn_chacha20_xor (const uint8_t key, const uint8_t nonce, uint32_t counter, const uint8_t * in, size_t len, uint8_t * out) XOR data with ChaCha20 keystream. |
Detailed Description¶
Provides the Authenticated Encryption with Associated Data (AEAD) construction used by WireGuard for both handshake and transport encryption. Also exposes raw ChaCha20 for standalone use.
All state is caller-owned. No heap.
** **
uint8_t key[32], nonce[12], tag[16];
uint8_t plaintext[64], ciphertext[64];
// Encrypt:
syn_aead_encrypt(key, nonce, NULL, 0,
plaintext, 64, ciphertext, tag);
// Decrypt:
bool ok = syn_aead_decrypt(key, nonce, NULL, 0,
ciphertext, 64, tag, plaintext);
Public Functions Documentation¶
function syn_aead_decrypt¶
Decrypt and verify (AEAD).
bool syn_aead_decrypt (
const uint8_t key,
const uint8_t nonce,
const uint8_t * aad,
size_t aad_len,
const uint8_t * ciphertext,
size_t ct_len,
const uint8_t tag,
uint8_t * plaintext
)
Parameters:
key256-bit key (32 bytes).nonce96-bit nonce (12 bytes).aadAdditional authenticated data (or NULL).aad_lenAAD length.ciphertextData to decrypt.ct_lenCiphertext length.tagExpected 128-bit authentication tag (16 bytes).plaintextOutput plaintext (same length as ciphertext).
Returns:
true if tag is valid and decryption succeeded.
function syn_aead_decrypt_inplace¶
Zero-copy in-place AEAD decryption & tag verification.
bool syn_aead_decrypt_inplace (
const uint8_t key,
const uint8_t nonce,
const uint8_t * aad,
size_t aad_len,
uint8_t * buf,
size_t len,
const uint8_t tag
)
Parameters:
key256-bit key (32 bytes).nonce96-bit nonce (12 bytes).aadAdditional authenticated data (or NULL).aad_lenAAD length.bufIn/out buffer containing ciphertext to decrypt in-place.lenData length in bytes.tagExpected 16-byte authentication tag.
Returns:
true if tag matches and decryption succeeded, false otherwise.
function syn_aead_encrypt¶
Encrypt and authenticate (AEAD).
void syn_aead_encrypt (
const uint8_t key,
const uint8_t nonce,
const uint8_t * aad,
size_t aad_len,
const uint8_t * plaintext,
size_t pt_len,
uint8_t * ciphertext,
uint8_t tag
)
Parameters:
key256-bit key (32 bytes).nonce96-bit nonce (12 bytes).aadAdditional authenticated data (or NULL).aad_lenAAD length.plaintextData to encrypt.pt_lenPlaintext length.ciphertextOutput ciphertext (same length as plaintext).tagOutput 128-bit authentication tag (16 bytes).
function syn_aead_encrypt_inplace¶
Zero-copy in-place AEAD encryption.
void syn_aead_encrypt_inplace (
const uint8_t key,
const uint8_t nonce,
const uint8_t * aad,
size_t aad_len,
uint8_t * buf,
size_t len,
uint8_t tag
)
Parameters:
key256-bit key (32 bytes).nonce96-bit nonce (12 bytes).aadAdditional authenticated data (or NULL).aad_lenAAD length.bufIn/out buffer containing plaintext to encrypt in-place.lenData length in bytes.tagOutput 16-byte authentication tag.
function syn_chacha20_block¶
Generate ChaCha20 keystream block (no XOR).
Produces exactly 64 bytes of keystream for the given counter value.
Parameters:
key256-bit key (32 bytes).nonce96-bit nonce (12 bytes).counterBlock counter.outOutput buffer (exactly 64 bytes).
function syn_chacha20_xor¶
XOR data with ChaCha20 keystream.
void syn_chacha20_xor (
const uint8_t key,
const uint8_t nonce,
uint32_t counter,
const uint8_t * in,
size_t len,
uint8_t * out
)
Encrypts (or decrypts — same operation) by XOR-ing with the ChaCha20 keystream starting at the given block counter.
Parameters:
key256-bit key (32 bytes).nonce96-bit nonce (12 bytes).counterInitial block counter (usually 0 or 1).inInput data.lenData length in bytes.outOutput buffer (may alias in).
The documentation for this class was generated from the following file src/syntropic/crypto/syn_chacha20poly1305.h