File syn_blake2s.h¶
FileList > crypto > syn_blake2s.h
Go to the source code of this file
BLAKE2s cryptographic hash — RFC 7693, pure C99. More...
#include <stddef.h>#include <stdint.h>#include <string.h>
Classes¶
| Type | Name |
|---|---|
| struct | SYN_BLAKE2s BLAKE2s hash context — caller-owned. |
| struct | SYN_HMAC_BLAKE2s HMAC-BLAKE2s context — caller-owned. |
Public Functions¶
| Type | Name |
|---|---|
| void | syn_blake2s_final (SYN_BLAKE2s * ctx, uint8_t * out) Finalize and produce the digest. |
| void | syn_blake2s_init (SYN_BLAKE2s * ctx, size_t outlen) Initialize BLAKE2s for unkeyed hashing. |
| void | syn_blake2s_init_keyed (SYN_BLAKE2s * ctx, const void * key, size_t keylen, size_t outlen) Initialize BLAKE2s for keyed hashing (MAC mode). |
| void | syn_blake2s_update (SYN_BLAKE2s * ctx, const void * data, size_t len) Feed data into the hash. |
Public Static Functions¶
| Type | Name |
|---|---|
| void | syn_blake2s (const void * data, size_t len, uint8_t * out, size_t outlen) One-shot unkeyed BLAKE2s hash. |
| void | syn_blake2s_mac (const void * key, size_t keylen, const void * data, size_t len, uint8_t * out, size_t outlen) One-shot keyed BLAKE2s MAC. |
| void | syn_hmac_blake2s (const void * key, size_t keylen, const void * data, size_t datalen, uint8_t mac) One-shot HMAC-BLAKE2s. |
| void | syn_hmac_blake2s_final (SYN_HMAC_BLAKE2s * ctx, uint8_t mac) Finalize HMAC-BLAKE2s and produce 32-byte MAC. |
| void | syn_hmac_blake2s_init (SYN_HMAC_BLAKE2s * ctx, const void * key, size_t keylen) Initialize HMAC-BLAKE2s with a key. |
| void | syn_hmac_blake2s_update (SYN_HMAC_BLAKE2s * ctx, const void * data, size_t len) Feed message data into the HMAC. |
Macros¶
| Type | Name |
|---|---|
| define | SYN_BLAKE2S_BLOCK_SIZE 64 |
| define | SYN_BLAKE2S_MAX_DIGEST 32 |
| define | SYN_BLAKE2S_MAX_KEY 32 |
Detailed Description¶
Supports both unkeyed hashing and keyed MAC mode. WireGuard uses both: unkeyed BLAKE2s-256 for chaining hash, keyed BLAKE2s for MAC.
Context is caller-owned (~120 bytes on 32-bit targets). No heap.
Also provides HMAC-BLAKE2s as static inline functions — used internally by the WireGuard module for HKDF key derivation.
** **
// Unkeyed hash:
uint8_t hash[32];
syn_blake2s(data, len, hash, 32);
// Keyed MAC (16-byte tag):
uint8_t mac[16];
syn_blake2s_mac(key, 32, data, len, mac, 16);
// Streaming:
SYN_BLAKE2s ctx;
syn_blake2s_init(&ctx, 32);
syn_blake2s_update(&ctx, chunk1, len1);
syn_blake2s_update(&ctx, chunk2, len2);
syn_blake2s_final(&ctx, hash);
Public Functions Documentation¶
function syn_blake2s_final¶
Finalize and produce the digest.
After calling this, the context must be re-initialized before reuse.
Parameters:
ctxBLAKE2s context.outOutput buffer (must be at least ctx->outlen bytes).
function syn_blake2s_init¶
Initialize BLAKE2s for unkeyed hashing.
Parameters:
ctxContext to initialize.outlenDesired digest length (1–32).
function syn_blake2s_init_keyed¶
Initialize BLAKE2s for keyed hashing (MAC mode).
Parameters:
ctxContext to initialize.keySecret key.keylenKey length (1–32).outlenDesired digest length (1–32).
function syn_blake2s_update¶
Feed data into the hash.
Parameters:
ctxBLAKE2s context.dataData to hash.lenLength in bytes.
Public Static Functions Documentation¶
function syn_blake2s¶
One-shot unkeyed BLAKE2s hash.
Parameters:
dataData to hash.lenLength in bytes.outOutput buffer.outlenDesired digest length (1–32).
function syn_blake2s_mac¶
One-shot keyed BLAKE2s MAC.
static inline void syn_blake2s_mac (
const void * key,
size_t keylen,
const void * data,
size_t len,
uint8_t * out,
size_t outlen
)
Parameters:
keySecret key.keylenKey length (1–32).dataData to authenticate.lenData length in bytes.outOutput buffer.outlenDesired MAC length (1–32).
function syn_hmac_blake2s¶
One-shot HMAC-BLAKE2s.
static inline void syn_hmac_blake2s (
const void * key,
size_t keylen,
const void * data,
size_t datalen,
uint8_t mac
)
Parameters:
keySecret key.keylenKey length in bytes.dataMessage data.datalenMessage length in bytes.macOutput buffer for the 32-byte MAC.
function syn_hmac_blake2s_final¶
Finalize HMAC-BLAKE2s and produce 32-byte MAC.
Parameters:
ctxHMAC context.macOutput buffer for the 32-byte MAC.
function syn_hmac_blake2s_init¶
Initialize HMAC-BLAKE2s with a key.
static inline void syn_hmac_blake2s_init (
SYN_HMAC_BLAKE2s * ctx,
const void * key,
size_t keylen
)
Parameters:
ctxHMAC context.keySecret key.keylenKey length in bytes.
function syn_hmac_blake2s_update¶
Feed message data into the HMAC.
static inline void syn_hmac_blake2s_update (
SYN_HMAC_BLAKE2s * ctx,
const void * data,
size_t len
)
Parameters:
ctxHMAC context.dataMessage data.lenData length in bytes.
Macro Definition Documentation¶
define SYN_BLAKE2S_BLOCK_SIZE¶
Input block size (bytes)
define SYN_BLAKE2S_MAX_DIGEST¶
Maximum digest size (bytes)
define SYN_BLAKE2S_MAX_KEY¶
Maximum key size (bytes)
The documentation for this class was generated from the following file src/syntropic/crypto/syn_blake2s.h