|
C Fundamentals
Algorithms · data structures · cryptography · systems — pure C11, zero deps
|
Pure-C SHA-256 implementation, written from the FIPS 180-4 spec. More...
#include <stddef.h>#include <stdint.h>Go to the source code of this file.
Macros | |
| #define | SHA256_DIGEST_BYTES 32 |
| #define | SHA256_HEX_BYTES (SHA256_DIGEST_BYTES * 2 + 1) /* +1 for NUL */ |
Functions | |
| void | sha256 (const uint8_t *data, size_t len, uint8_t digest[SHA256_DIGEST_BYTES]) |
| void | sha256_to_hex (const uint8_t digest[SHA256_DIGEST_BYTES], char hex_out[SHA256_HEX_BYTES]) |
Pure-C SHA-256 implementation, written from the FIPS 180-4 spec.
Operates on raw bytes; outputs the 32-byte digest. A convenience helper formats the digest as a 64-char lowercase hex string. No dependencies outside libc.
Definition in file sha256.h.
| #define SHA256_HEX_BYTES (SHA256_DIGEST_BYTES * 2 + 1) /* +1 for NUL */ |
| void sha256 | ( | const uint8_t * | data, |
| size_t | len, | ||
| uint8_t | digest[SHA256_DIGEST_BYTES] | ||
| ) |
Compute SHA-256(data[0..len)) into the 32-byte digest buffer.
Definition at line 66 of file sha256.c.
References process_block().
Referenced by main().
| void sha256_to_hex | ( | const uint8_t | digest[SHA256_DIGEST_BYTES], |
| char | hex_out[SHA256_HEX_BYTES] | ||
| ) |
Format a 32-byte digest as a 64-char lowercase hex string + NUL.
Definition at line 112 of file sha256.c.
References SHA256_DIGEST_BYTES.
Referenced by main().