C Fundamentals
Algorithms · data structures · cryptography · systems — pure C11, zero deps
Loading...
Searching...
No Matches
sha256.h
Go to the documentation of this file.
1/**
2 * @file sha256.h
3 * @brief Pure-C SHA-256 implementation, written from the FIPS 180-4 spec.
4 *
5 * Operates on raw bytes; outputs the 32-byte digest. A convenience helper
6 * formats the digest as a 64-char lowercase hex string. No dependencies
7 * outside libc.
8 */
9
10#ifndef SHA256_H
11#define SHA256_H
12
13#include <stddef.h>
14#include <stdint.h>
15
16#define SHA256_DIGEST_BYTES 32
17#define SHA256_HEX_BYTES (SHA256_DIGEST_BYTES * 2 + 1) /* +1 for NUL */
18
19/** Compute SHA-256(data[0..len)) into the 32-byte `digest` buffer. */
20void sha256(const uint8_t *data, size_t len, uint8_t digest[SHA256_DIGEST_BYTES]);
21
22/** Format a 32-byte digest as a 64-char lowercase hex string + NUL. */
23void sha256_to_hex(const uint8_t digest[SHA256_DIGEST_BYTES],
24 char hex_out[SHA256_HEX_BYTES]);
25
26#endif /* SHA256_H */
#define SHA256_HEX_BYTES
Definition sha256.h:17
void sha256(const uint8_t *data, size_t len, uint8_t digest[SHA256_DIGEST_BYTES])
Definition sha256.c:66
void sha256_to_hex(const uint8_t digest[SHA256_DIGEST_BYTES], char hex_out[SHA256_HEX_BYTES])
Definition sha256.c:112
#define SHA256_DIGEST_BYTES
Definition sha256.h:16