![]() |
Nilorea Library
C utilities for networking, threading, graphics
|
SHA-256 in portable C, fed a piece at a time. More...
#include <stddef.h>#include <stdint.h>Go to the source code of this file.
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 | |
SHA-256 in portable C, fed a piece at a time.
FIPS 180-4 SHA-256 with no library behind it, for a program that must check a download or a cache entry without linking OpenSSL (n_digest.h is the OpenSSL one, one call per buffer). The state is fed any number of pieces of any size, so a file of any length is hashed in constant memory; n_sha256_file() does that for a path. Hex output is lowercase, the form published beside downloads.
Definition in file n_sha256.h.