5 Module N_SHA256
gullradriel edited this page 2026-10-09 00:55:18 +02:00

SHA256: portable streaming SHA-256

Structures

Name
struct N_SHA256
a SHA-256 in progress: plain data, copyable to fork a hash

Functions

Name
void n_sha256_update(N_SHA256 * ctx, const void * data, size_t len)
feed bytes
void n_sha256_init(N_SHA256 * ctx)
start a hash
void n_sha256_hex(const unsigned char digest[32], char out[65])
a digest as lowercase hex
void n_sha256_final(N_SHA256 * ctx, unsigned char out[32])
finish: the digest, the state left spent
int n_sha256_file(const char * path, unsigned char out[32])
hash a file, read in pieces
void n_sha256(const void * data, size_t len, unsigned char out[32])
hash one buffer

Defines

Name
N_SHA256_LEN
size in bytes of a SHA-256 digest
N_SHA256_HEX_LEN
size of its lowercase hex form, terminator included

Functions Documentation

function n_sha256_update

void n_sha256_update(
    N_SHA256 * ctx,
    const void * data,
    size_t len
)

feed bytes

Parameters:

  • ctx the hash
  • data the bytes, may be NULL when len is 0
  • len how many

function n_sha256_init

void n_sha256_init(
    N_SHA256 * ctx
)

start a hash

Parameters:

  • ctx the state to set up

function n_sha256_hex

void n_sha256_hex(
    const unsigned char digest[32],
    char out[65]
)

a digest as lowercase hex

Parameters:

  • digest N_SHA256_LEN bytes
  • out receives N_SHA256_HEX_LEN characters, terminator included

function n_sha256_final

void n_sha256_final(
    N_SHA256 * ctx,
    unsigned char out[32]
)

finish: the digest, the state left spent

Parameters:

  • ctx the hash
  • out receives N_SHA256_LEN bytes

function n_sha256_file

int n_sha256_file(
    const char * path,
    unsigned char out[32]
)

hash a file, read in pieces

Parameters:

  • path the file
  • out receives N_SHA256_LEN bytes

Return: 0, or -1 when the file cannot be opened or read

function n_sha256

void n_sha256(
    const void * data,
    size_t len,
    unsigned char out[32]
)

hash one buffer

Parameters:

  • data the bytes, may be NULL when len is 0
  • len how many
  • out receives N_SHA256_LEN bytes

Macros Documentation

define N_SHA256_LEN

#define N_SHA256_LEN 32

size in bytes of a SHA-256 digest

define N_SHA256_HEX_LEN

#define N_SHA256_HEX_LEN 65

size of its lowercase hex form, terminator included