test-sha512-256.c (777B)
1 #include "sha.h" 2 #include <stdio.h> 3 4 int 5 main(void) 6 { 7 char msg[] = "abc"; 8 9 uint8_t dgst[SHA512_256_DIGEST_SIZE]; 10 sha512_256(msg, strlen(msg), dgst); 11 12 uint8_t expected[SHA512_256_DIGEST_SIZE] = { 13 0x53, 0x04, 0x8e, 0x26, 0x81, 0x94, 0x1e, 0xf9, 14 0x9b, 0x2e, 0x29, 0xb7, 0x6b, 0x4c, 0x7d, 0xab, 15 0xe4, 0xc2, 0xd0, 0xc6, 0x34, 0xfc, 0x6d, 0x46, 16 0xe0, 0xe2, 0xf1, 0x31, 0x07, 0xe7, 0xaf, 0x23, 17 }; 18 19 printf("msg: \"%.*s\" (%lu bytes)\n", sizeof msg, msg, strlen(msg)); 20 21 printf("dgst: "); 22 for (size_t i = 0; i < sizeof dgst; i++) { 23 printf("%.2x", dgst[i]); 24 } 25 printf("\n"); 26 27 printf("exp.: "); 28 for (size_t i = 0; i < sizeof expected; i++) { 29 printf("%.2x", expected[i]); 30 } 31 printf("\n"); 32 33 return memcmp(expected, dgst, SHA512_256_DIGEST_SIZE); 34 } 35 36 #include "sha.c"