C Fundamentals
Algorithms · data structures · cryptography · systems — pure C11, zero deps
Loading...
Searching...
No Matches
sha256.h File Reference

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])
 

Detailed Description

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.

Macro Definition Documentation

◆ SHA256_DIGEST_BYTES

#define SHA256_DIGEST_BYTES   32

Definition at line 16 of file sha256.h.

◆ SHA256_HEX_BYTES

#define SHA256_HEX_BYTES   (SHA256_DIGEST_BYTES * 2 + 1) /* +1 for NUL */

Definition at line 17 of file sha256.h.

Function Documentation

◆ sha256()

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().

◆ sha256_to_hex()

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().