tls

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

test-sha512.c (982B)


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