tls

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

test-sha256.c (782B)


      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[SHA256_DIGEST_SIZE];
     12 	sha256(msg, strlen(msg), dgst);
     13 
     14 	uint8_t expected[SHA256_DIGEST_SIZE] = {
     15 		0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea,
     16 		0x41, 0x41, 0x40, 0xde, 0x5d, 0xae, 0x22, 0x23,
     17 		0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c,
     18 		0xb4, 0x10, 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad,
     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, SHA256_DIGEST_SIZE);
     36 }
     37 
     38 #include "sha.c"