SHA-256
SHA-256 is the hash under TLS 1.3’s key schedule. This page hashes abc;
the digest is the “abc” test vector from FIPS 180 and RFC 6234.
Code
#define WIRED_MAIN#include "wired.h"
int wired_main(int argc, char** argv) { (void)argc; (void)argv; u8 digest[SHA256_DIGEST]; wired_sha256((const u8*)"abc", 3, digest); wired_dprintf(2, "sha256(\"abc\") = "); for (usz i = 0; i < sizeof digest; i++) wired_dprintf(2, "%02x", digest[i]); wired_dprintf(2, "\n"); return 0;}Output
$ ./tls-sha256sha256("abc") = ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015adHow it works
Section titled “How it works”wired_sha256(data, len, out)hasheslenbytes into aSHA256_DIGEST(32) byte buffer in one call.wired_dprintf(2, "%02x", byte)writes each byte as two hex digits;wired.hhas a libc-free printf (wired_snprintf,wired_dprintf).