summaryrefslogtreecommitdiffstats
path: root/tests/helpers/test_md5.c
blob: 7f1e4f358953af21198fa5d92b53697f5b783591 (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

#include <stdio.h>
#include <unistd.h>

#include "md5.h"

int
main(int argc, char *argv[])
{
	int i, ret;
	struct MD5Context ctx;
	unsigned char digest[MD5LENGTH];
	unsigned char buf[BUFSIZ];

	MD5Init( &ctx );

	while(!feof(stdin) && !ferror(stdin)) {
		ret = fread(buf, 1, sizeof(buf), stdin);
		if (ret)
			MD5Update( &ctx, buf, ret );
	}

	fclose(stdin);
	MD5Final( digest, &ctx );

	for (i = 0; i < MD5LENGTH; i++)
		printf( "%02x", digest[i] );
	printf("  -\n");
	return 0;
}