Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
SHA256: portable streaming SHA-256

Data Structures

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

Macros

#define N_SHA256_HEX_LEN   65
 size of its lowercase hex form, terminator included
#define N_SHA256_LEN   32
 size in bytes of a SHA-256 digest

Functions

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

Detailed Description


Data Structure Documentation

◆ N_SHA256

struct N_SHA256

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

Examples
ex_sha256.c.

Definition at line 57 of file n_sha256.h.

Collaboration diagram for N_SHA256:
Data Fields
unsigned char block[64] the block being filled
uint64_t length bytes hashed so far
uint32_t state[8] the eight working words
size_t used how much of it is filled

Macro Definition Documentation

◆ N_SHA256_HEX_LEN

#define N_SHA256_HEX_LEN   65

size of its lowercase hex form, terminator included

Examples
ex_sha256.c.

Definition at line 54 of file n_sha256.h.

Referenced by hex_is(), and n_sha256_hex().

◆ N_SHA256_LEN

#define N_SHA256_LEN   32

size in bytes of a SHA-256 digest

Examples
ex_sha256.c.

Definition at line 52 of file n_sha256.h.

Referenced by hex_is(), main(), n_sha256(), n_sha256_file(), n_sha256_final(), and n_sha256_hex().

Function Documentation

◆ n_sha256()

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

hash one buffer

Parameters
datathe bytes, may be NULL when len is 0
lenhow many
outreceives N_SHA256_LEN bytes

Definition at line 158 of file n_sha256.c.

References n_sha256_final(), n_sha256_init(), N_SHA256_LEN, and n_sha256_update().

Referenced by hex_is(), and main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ n_sha256_file()

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

hash a file, read in pieces

Parameters
paththe file
outreceives N_SHA256_LEN bytes
Returns
0, or -1 when the file cannot be opened or read

Definition at line 166 of file n_sha256.c.

References n_sha256_final(), n_sha256_init(), N_SHA256_LEN, and n_sha256_update().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ n_sha256_final()

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

finish: the digest, the state left spent

Parameters
ctxthe hash
outreceives N_SHA256_LEN bytes

Definition at line 132 of file n_sha256.c.

References _sha256_block(), N_SHA256::block, N_SHA256::length, N_SHA256_LEN, N_SHA256::state, and N_SHA256::used.

Referenced by main(), n_sha256(), and n_sha256_file().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ n_sha256_hex()

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

a digest as lowercase hex

Parameters
digestN_SHA256_LEN bytes
outreceives N_SHA256_HEX_LEN characters, terminator included

Definition at line 195 of file n_sha256.c.

References N_SHA256_HEX_LEN, and N_SHA256_LEN.

Referenced by hex_is().

Here is the caller graph for this function:

◆ n_sha256_init()

void n_sha256_init ( N_SHA256 * ctx)

start a hash

Parameters
ctxthe state to set up

Definition at line 91 of file n_sha256.c.

References N_SHA256::length, N_SHA256::state, and N_SHA256::used.

Referenced by main(), n_sha256(), and n_sha256_file().

Here is the caller graph for this function:

◆ n_sha256_update()

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

feed bytes

Parameters
ctxthe hash
datathe bytes, may be NULL when len is 0
lenhow many

Definition at line 103 of file n_sha256.c.

References _sha256_block(), N_SHA256::block, N_SHA256::length, N_SHA256::state, and N_SHA256::used.

Referenced by main(), n_sha256(), and n_sha256_file().

Here is the call graph for this function:
Here is the caller graph for this function: