A minimal, high-performance, security-hardened single-header C library for SHA-256.
- Pure C: Requires only
stdint.handstring.h. - Zero Allocation: No
mallocis used. - Performance: Fully unrolled compression rounds and inlined macros.
- Endianness Optimized: Fast byte-swapping for little-endian architectures.
Simply include nanosha256.h in your project.
#include "nanosha256.h"
// Streaming API
SHA256_CTX ctx;
uint8_t hash[32];
SHA256_Init(&ctx);
SHA256_Update(&ctx, "abc", 3);
SHA256_Final(hash, &ctx);
// State-based primitive API (requested)
uint32_t state[8];
sha256_init(state);
sha256_transform(state, some_64_byte_block);
sha256_final(state, hash, total_bits);To run the included tests:
make testMIT License (2026-present oopsio)