aboutsummaryrefslogtreecommitdiff
path: root/c/sha1/main.c
blob: 9ea4aab2caf27c5abb5daf0c7c99c2c15def7dfa (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "sha1.h"

static uint8_t bigbuf1[1000000];
static uint8_t bigbuf2[1000000];

int
main(int argc, char **argv)
{
	(void)argc;

	int e = 0;
	sha1_t s;
	uint8_t dgst[SHA1DGSTSZ];

	memset(bigbuf1, 'a', sizeof(bigbuf1));
	memset(bigbuf2, 'b', sizeof(bigbuf2));

	sha1init(&s);
	e |= sha1hash(&s, bigbuf1, sizeof(bigbuf1));
	e |= sha1hash(&s, bigbuf2, sizeof(bigbuf2));
	sha1end(&s, dgst);

	if (e != 0) {
		fprintf(stderr, "%s: %s\n", argv[0], strerror(e));
		exit(EXIT_FAILURE);
	}

	for (int i = 0; i < sizeof(dgst); i++)
		printf("%02" PRIx8, dgst[i]);
	putchar('\n');
	return EXIT_SUCCESS;
}