Skip to content

File syn_sha512.h

FileList > crypto > syn_sha512.h

Go to the source code of this file

SHA-512 & SHA-384 cryptographic hash and HMAC — pure C99, zero dependencies. More...

  • #include <stddef.h>
  • #include <stdint.h>

Classes

Type Name
struct SYN_HMAC_SHA384
HMAC-SHA384 context — caller-owned.
struct SYN_HMAC_SHA512
HMAC-SHA512 context — caller-owned.
struct SYN_SHA512
SHA-512 / SHA-384 hash context — caller-owned.

Public Functions

Type Name
void syn_hmac_sha384 (const void * key, size_t key_len, const void * data, size_t data_len, uint8_t mac)
Compute HMAC-SHA384 over data using secret key (RFC 4231).
void syn_hmac_sha384_final (SYN_HMAC_SHA384 * ctx, uint8_t mac)
Finalize HMAC-SHA384 computation and retrieve 48-byte MAC.
void syn_hmac_sha384_init (SYN_HMAC_SHA384 * ctx, const void * key, size_t key_len)
Initialize HMAC-SHA384 context with a key.
void syn_hmac_sha384_update (SYN_HMAC_SHA384 * ctx, const void * data, size_t len)
Feed data chunk into HMAC-SHA384 computation.
void syn_hmac_sha512 (const void * key, size_t key_len, const void * data, size_t data_len, uint8_t mac)
Compute HMAC-SHA512 over data using secret key (RFC 4231).
void syn_hmac_sha512_final (SYN_HMAC_SHA512 * ctx, uint8_t mac)
Finalize HMAC-SHA512 computation and retrieve 64-byte MAC.
void syn_hmac_sha512_init (SYN_HMAC_SHA512 * ctx, const void * key, size_t key_len)
Initialize HMAC-SHA512 context with a key.
void syn_hmac_sha512_update (SYN_HMAC_SHA512 * ctx, const void * data, size_t len)
Feed data chunk into HMAC-SHA512 computation.
void syn_sha384 (const void * data, size_t len, uint8_t hash)
One-shot SHA-384 calculation.
void syn_sha384_final (SYN_SHA512 * ctx, uint8_t hash)
Finalize SHA-384 hash and produce 48-byte digest.
void syn_sha384_init (SYN_SHA512 * ctx)
Initialize context for SHA-384 hashing.
void syn_sha512 (const void * data, size_t len, uint8_t hash)
One-shot SHA-512 calculation.
void syn_sha512_final (SYN_SHA512 * ctx, uint8_t hash)
Finalize SHA-512 hash and produce 64-byte digest.
void syn_sha512_init (SYN_SHA512 * ctx)
Initialize context for SHA-512 hashing.
void syn_sha512_update (SYN_SHA512 * ctx, const void * data, size_t len)
Feed data into the SHA-512 / SHA-384 hash.

Macros

Type Name
define SYN_SHA384_DIGEST_SIZE 48U
SHA-384 digest size in bytes (48).
define SYN_SHA512_BLOCK_SIZE 128U
SHA-512 / SHA-384 block size in bytes (128).
define SYN_SHA512_DIGEST_SIZE 64U
SHA-512 digest size in bytes (64).

Detailed Description

Implements FIPS 180-4 compliant SHA-512 and SHA-384 secure hash algorithms and RFC 4231 HMAC-SHA512 / HMAC-SHA384 message authentication.

Follows the streaming pattern: init → update (repeated) → final

The context struct is caller-owned (~216 bytes on 32-bit/64-bit targets). Zero heap allocation, zero floating point.

** **

// One-shot SHA-512:
uint8_t hash512[64];
syn_sha512("abc", 3, hash512);

// One-shot SHA-384:
uint8_t hash384[48];
syn_sha384("abc", 3, hash384);

// Streaming SHA-512:
SYN_SHA512 ctx;
syn_sha512_init(&ctx);
syn_sha512_update(&ctx, chunk1, len1);
syn_sha512_update(&ctx, chunk2, len2);
syn_sha512_final(&ctx, hash512);

Public Functions Documentation

function syn_hmac_sha384

Compute HMAC-SHA384 over data using secret key (RFC 4231).

void syn_hmac_sha384 (
    const void * key,
    size_t key_len,
    const void * data,
    size_t data_len,
    uint8_t mac
) 

Parameters:

  • key Secret key buffer.
  • key_len Secret key length in bytes.
  • data Data buffer to authenticate.
  • data_len Data length in bytes.
  • mac Output 48-byte MAC buffer.

function syn_hmac_sha384_final

Finalize HMAC-SHA384 computation and retrieve 48-byte MAC.

void syn_hmac_sha384_final (
    SYN_HMAC_SHA384 * ctx,
    uint8_t mac
) 

Parameters:

  • ctx HMAC-SHA384 context.
  • mac Output 48-byte MAC buffer.

function syn_hmac_sha384_init

Initialize HMAC-SHA384 context with a key.

void syn_hmac_sha384_init (
    SYN_HMAC_SHA384 * ctx,
    const void * key,
    size_t key_len
) 

Parameters:

  • ctx HMAC-SHA384 context.
  • key Secret key buffer.
  • key_len Secret key length in bytes.

function syn_hmac_sha384_update

Feed data chunk into HMAC-SHA384 computation.

void syn_hmac_sha384_update (
    SYN_HMAC_SHA384 * ctx,
    const void * data,
    size_t len
) 

Parameters:

  • ctx HMAC-SHA384 context.
  • data Data buffer to authenticate.
  • len Length in bytes.

function syn_hmac_sha512

Compute HMAC-SHA512 over data using secret key (RFC 4231).

void syn_hmac_sha512 (
    const void * key,
    size_t key_len,
    const void * data,
    size_t data_len,
    uint8_t mac
) 

Parameters:

  • key Secret key buffer.
  • key_len Secret key length in bytes.
  • data Data buffer to authenticate.
  • data_len Data length in bytes.
  • mac Output 64-byte MAC buffer.

function syn_hmac_sha512_final

Finalize HMAC-SHA512 computation and retrieve 64-byte MAC.

void syn_hmac_sha512_final (
    SYN_HMAC_SHA512 * ctx,
    uint8_t mac
) 

Parameters:

  • ctx HMAC-SHA512 context.
  • mac Output 64-byte MAC buffer.

function syn_hmac_sha512_init

Initialize HMAC-SHA512 context with a key.

void syn_hmac_sha512_init (
    SYN_HMAC_SHA512 * ctx,
    const void * key,
    size_t key_len
) 

Parameters:

  • ctx HMAC-SHA512 context.
  • key Secret key buffer.
  • key_len Secret key length in bytes.

function syn_hmac_sha512_update

Feed data chunk into HMAC-SHA512 computation.

void syn_hmac_sha512_update (
    SYN_HMAC_SHA512 * ctx,
    const void * data,
    size_t len
) 

Parameters:

  • ctx HMAC-SHA512 context.
  • data Data buffer to authenticate.
  • len Length in bytes.

function syn_sha384

One-shot SHA-384 calculation.

void syn_sha384 (
    const void * data,
    size_t len,
    uint8_t hash
) 

Parameters:

  • data Data to hash.
  • len Length in bytes.
  • hash Output 48-byte digest buffer.

function syn_sha384_final

Finalize SHA-384 hash and produce 48-byte digest.

void syn_sha384_final (
    SYN_SHA512 * ctx,
    uint8_t hash
) 

Parameters:

  • ctx SHA-512 context initialized with syn_sha384_init().
  • hash Output buffer (must be at least 48 bytes).

function syn_sha384_init

Initialize context for SHA-384 hashing.

void syn_sha384_init (
    SYN_SHA512 * ctx
) 

Parameters:

  • ctx Context to initialize.

function syn_sha512

One-shot SHA-512 calculation.

void syn_sha512 (
    const void * data,
    size_t len,
    uint8_t hash
) 

Parameters:

  • data Data to hash.
  • len Length in bytes.
  • hash Output 64-byte digest buffer.

function syn_sha512_final

Finalize SHA-512 hash and produce 64-byte digest.

void syn_sha512_final (
    SYN_SHA512 * ctx,
    uint8_t hash
) 

Parameters:

  • ctx SHA-512 context.
  • hash Output buffer (must be at least 64 bytes).

function syn_sha512_init

Initialize context for SHA-512 hashing.

void syn_sha512_init (
    SYN_SHA512 * ctx
) 

Parameters:

  • ctx Context to initialize.

function syn_sha512_update

Feed data into the SHA-512 / SHA-384 hash.

void syn_sha512_update (
    SYN_SHA512 * ctx,
    const void * data,
    size_t len
) 

Parameters:

  • ctx SHA-512 context.
  • data Data buffer to hash.
  • len Length in bytes.

Macro Definition Documentation

define SYN_SHA384_DIGEST_SIZE

SHA-384 digest size in bytes (48).

#define SYN_SHA384_DIGEST_SIZE `48U`


define SYN_SHA512_BLOCK_SIZE

SHA-512 / SHA-384 block size in bytes (128).

#define SYN_SHA512_BLOCK_SIZE `128U`


define SYN_SHA512_DIGEST_SIZE

SHA-512 digest size in bytes (64).

#define SYN_SHA512_DIGEST_SIZE `64U`



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