QPMS
Electromagnetic multiple scattering library and toolkit.
Loading...
Searching...
No Matches
Data Structures | Functions
sha256.h File Reference

Self-contained SHA-256 (FIPS 180-4) for content fingerprints. More...

#include <stddef.h>
#include <stdint.h>
Include dependency graph for sha256.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  qpms_sha256_t
 Incremental SHA-256 state. More...
 

Functions

void qpms_sha256_init (qpms_sha256_t *ctx)
 Initialises the hash state.
 
void qpms_sha256_update (qpms_sha256_t *ctx, const void *data, size_t len)
 Feeds len bytes into the hash.
 
void qpms_sha256_final (qpms_sha256_t *ctx, uint8_t out[32])
 Finishes the hash and writes the 32-byte digest to out.
 
void qpms_sha256_hex (char hex[65], const void *data, size_t len)
 One-shot SHA-256 of a buffer.
 
int qpms_sha256_file_hex (char hex[65], const char *path)
 One-shot SHA-256 of a whole file.
 

Detailed Description

Self-contained SHA-256 (FIPS 180-4) for content fingerprints.

Used e.g. by the scatspec/simspec fingerprint helpers (system provenance and append-reuse checks in the results container); deliberately free of external dependencies.

Function Documentation

◆ qpms_sha256_file_hex()

int qpms_sha256_file_hex ( char  hex[65],
const char *  path 
)

One-shot SHA-256 of a whole file.

Writes 64 lowercase hex characters plus the terminating NUL into hex (which must have room for 65 bytes).

Returns
0 on success, -1 on I/O error.

◆ qpms_sha256_final()

void qpms_sha256_final ( qpms_sha256_t *  ctx,
uint8_t  out[32] 
)

Finishes the hash and writes the 32-byte digest to out.

The context is left unspecified afterwards.

◆ qpms_sha256_hex()

void qpms_sha256_hex ( char  hex[65],
const void *  data,
size_t  len 
)

One-shot SHA-256 of a buffer.

Writes 64 lowercase hex characters plus the terminating NUL into hex (which must have room for 65 bytes).