tls

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

test-sha256.c (761B)


      1 #include "sha.h"
      2 #include <stdio.h>
      3 
      4 int
      5 main(void)
      6 {
      7 	char msg[] = "abc";
      8 
      9 	uint8_t dgst[SHA256_DIGEST_SIZE];
     10 	sha256(msg, strlen(msg), dgst);
     11 
     12 	uint8_t expected[SHA256_DIGEST_SIZE] = {
     13 		0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea,
     14 		0x41, 0x41, 0x40, 0xde, 0x5d, 0xae, 0x22, 0x23,
     15 		0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c,
     16 		0xb4, 0x10, 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad,
     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, SHA256_DIGEST_SIZE);
     34 }
     35 
     36 #include "sha.c"