Skip to content

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

main.c
#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

Terminal window
$ ./tls-sha256
sha256("abc") = ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad
  • wired_sha256(data, len, out) hashes len bytes into a SHA256_DIGEST (32) byte buffer in one call.
  • wired_dprintf(2, "%02x", byte) writes each byte as two hex digits; wired.h has a libc-free printf (wired_snprintf, wired_dprintf).