tls

tls.git
git clone git://git.lenczewski.org/tls.git
Log | Files | Refs

test-sha512-256.c (798B)


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