Skip to content

File syn_hmac.h

FileList > src > syntropic > util > syn_hmac.h

Go to the source code of this file

HMAC-SHA256 — keyed-hash message authentication code. More...

  • #include "syn_sha256.h"
  • #include <stddef.h>
  • #include <stdint.h>
  • #include <string.h>

Classes

Type Name
struct SYN_HMAC_SHA256
HMAC-SHA256 context — caller-owned.

Public Static Functions

Type Name
void syn_hmac_sha256 (const void * key, size_t key_len, const void * data, size_t data_len, uint8_t mac)
Compute HMAC-SHA256 in one shot.
void syn_hmac_sha256_final (SYN_HMAC_SHA256 * ctx, uint8_t mac)
Finalize and produce the 32-byte HMAC.
void syn_hmac_sha256_init (SYN_HMAC_SHA256 * ctx, const void * key, size_t key_len)
Initialize HMAC-SHA256 with a key.
void syn_hmac_sha256_update (SYN_HMAC_SHA256 * ctx, const void * data, size_t len)
Feed message data into the HMAC.

Macros

Type Name
define SYN_HMAC_SHA256_SIZE [**SYN\_SHA256\_DIGEST\_SIZE**](syn__sha256_8h.md#define-syn_sha256_digest_size)
HMAC-SHA256 output size in bytes.

Detailed Description

Built on top of syn_sha256. Provides the same streaming pattern: init (with key) → update → final

The context wraps two SHA-256 contexts (~224 bytes caller-owned). No heap, no external dependencies.

** **

// One-shot:
uint8_t mac[32];
syn_hmac_sha256(key, key_len, message, msg_len, mac);

// Streaming:
SYN_HMAC_SHA256 ctx;
syn_hmac_sha256_init(&ctx, key, key_len);
syn_hmac_sha256_update(&ctx, chunk1, len1);
syn_hmac_sha256_update(&ctx, chunk2, len2);
syn_hmac_sha256_final(&ctx, mac);

Public Static Functions Documentation

function syn_hmac_sha256

Compute HMAC-SHA256 in one shot.

static inline void syn_hmac_sha256 (
    const void * key,
    size_t key_len,
    const void * data,
    size_t data_len,
    uint8_t mac
) 

Parameters:

  • key Secret key.
  • key_len Key length in bytes.
  • data Message data.
  • data_len Message length in bytes.
  • mac Output buffer (must be at least 32 bytes).

function syn_hmac_sha256_final

Finalize and produce the 32-byte HMAC.

static inline void syn_hmac_sha256_final (
    SYN_HMAC_SHA256 * ctx,
    uint8_t mac
) 

Parameters:

  • ctx HMAC context.
  • mac Output buffer (must be at least 32 bytes).

function syn_hmac_sha256_init

Initialize HMAC-SHA256 with a key.

static inline void syn_hmac_sha256_init (
    SYN_HMAC_SHA256 * ctx,
    const void * key,
    size_t key_len
) 

If key_len > 64, the key is first hashed with SHA-256.

Parameters:

  • ctx HMAC context.
  • key Secret key.
  • key_len Key length in bytes.

function syn_hmac_sha256_update

Feed message data into the HMAC.

static inline void syn_hmac_sha256_update (
    SYN_HMAC_SHA256 * ctx,
    const void * data,
    size_t len
) 

Parameters:

  • ctx HMAC context.
  • data Message data.
  • len Length in bytes.

Macro Definition Documentation

define SYN_HMAC_SHA256_SIZE

HMAC-SHA256 output size in bytes.

#define SYN_HMAC_SHA256_SIZE `SYN_SHA256_DIGEST_SIZE`



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