Skip to content

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.

void syn_blake2s_final (
    SYN_BLAKE2s * ctx,
    uint8_t * out
) 

After calling this, the context must be re-initialized before reuse.

Parameters:

  • ctx BLAKE2s context.
  • out Output buffer (must be at least ctx->outlen bytes).

function syn_blake2s_init

Initialize BLAKE2s for unkeyed hashing.

void syn_blake2s_init (
    SYN_BLAKE2s * ctx,
    size_t outlen
) 

Parameters:

  • ctx Context to initialize.
  • outlen Desired digest length (1–32).

function syn_blake2s_init_keyed

Initialize BLAKE2s for keyed hashing (MAC mode).

void syn_blake2s_init_keyed (
    SYN_BLAKE2s * ctx,
    const void * key,
    size_t keylen,
    size_t outlen
) 

Parameters:

  • ctx Context to initialize.
  • key Secret key.
  • keylen Key length (1–32).
  • outlen Desired digest length (1–32).

function syn_blake2s_update

Feed data into the hash.

void syn_blake2s_update (
    SYN_BLAKE2s * ctx,
    const void * data,
    size_t len
) 

Parameters:

  • ctx BLAKE2s context.
  • data Data to hash.
  • len Length in bytes.

Public Static Functions Documentation

function syn_blake2s

One-shot unkeyed BLAKE2s hash.

static inline void syn_blake2s (
    const void * data,
    size_t len,
    uint8_t * out,
    size_t outlen
) 

Parameters:

  • data Data to hash.
  • len Length in bytes.
  • out Output buffer.
  • outlen Desired 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:

  • key Secret key.
  • keylen Key length (1–32).
  • data Data to authenticate.
  • len Data length in bytes.
  • out Output buffer.
  • outlen Desired 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:

  • key Secret key.
  • keylen Key length in bytes.
  • data Message data.
  • datalen Message length in bytes.
  • mac Output buffer for the 32-byte MAC.

function syn_hmac_blake2s_final

Finalize HMAC-BLAKE2s and produce 32-byte MAC.

static inline void syn_hmac_blake2s_final (
    SYN_HMAC_BLAKE2s * ctx,
    uint8_t mac
) 

Parameters:

  • ctx HMAC context.
  • mac Output 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:

  • ctx HMAC context.
  • key Secret key.
  • keylen Key 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:

  • ctx HMAC context.
  • data Message data.
  • len Data length in bytes.

Macro Definition Documentation

define SYN_BLAKE2S_BLOCK_SIZE

#define SYN_BLAKE2S_BLOCK_SIZE `64`

Input block size (bytes)


define SYN_BLAKE2S_MAX_DIGEST

#define SYN_BLAKE2S_MAX_DIGEST `32`

Maximum digest size (bytes)


define SYN_BLAKE2S_MAX_KEY

#define SYN_BLAKE2S_MAX_KEY `32`

Maximum key size (bytes)



The documentation for this class was generated from the following file src/syntropic/crypto/syn_blake2s.h