test-sha512.c (961B)
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_DIGEST_SIZE]; 10 sha512(msg, strlen(msg), dgst); 11 12 uint8_t expected[SHA512_DIGEST_SIZE] = { 13 0xdd, 0xaf, 0x35, 0xa1, 0x93, 0x61, 0x7a, 0xba, 14 0xcc, 0x41, 0x73, 0x49, 0xae, 0x20, 0x41, 0x31, 15 0x12, 0xe6, 0xfa, 0x4e, 0x89, 0xa9, 0x7e, 0xa2, 16 0x0a, 0x9e, 0xee, 0xe6, 0x4b, 0x55, 0xd3, 0x9a, 17 0x21, 0x92, 0x99, 0x2a, 0x27, 0x4f, 0xc1, 0xa8, 18 0x36, 0xba, 0x3c, 0x23, 0xa3, 0xfe, 0xeb, 0xbd, 19 0x45, 0x4d, 0x44, 0x23, 0x64, 0x3c, 0xe8, 0x0e, 20 0x2a, 0x9a, 0xc9, 0x4f, 0xa5, 0x4c, 0xa4, 0x9f, 21 }; 22 23 printf("msg: \"%.*s\" (%lu bytes)\n", sizeof msg, msg, strlen(msg)); 24 25 printf("dgst: "); 26 for (size_t i = 0; i < sizeof dgst; i++) { 27 printf("%.2x", dgst[i]); 28 } 29 printf("\n"); 30 31 printf("exp.: "); 32 for (size_t i = 0; i < sizeof expected; i++) { 33 printf("%.2x", expected[i]); 34 } 35 printf("\n"); 36 37 return memcmp(expected, dgst, SHA512_DIGEST_SIZE); 38 } 39 40 #include "sha.c"