File: example.c

package info (click to toggle)
mhash 0.9.9.9-11
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,136 kB
  • sloc: ansic: 9,492; sh: 8,972; makefile: 84
file content (31 lines) | stat: -rw-r--r-- 532 bytes parent folder | download | duplicates (9)
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
/* Example program that uses mhash to hash stdin using MD5 */ 

 #include <mhash.h>
 #include <stdio.h>
 #include <stdlib.h>

 int main(void) 
 {
 	int i;
	MHASH td;
	unsigned char buffer;
	unsigned char hash[16]; /* only for md5 */

	td = mhash_init(MHASH_MD5);

	if (td == MHASH_FAILED) exit(1);

	while (fread(&buffer, 1, 1, stdin) == 1) {
		mhash(td, &buffer, 1);
	}

	mhash_deinit(td, hash);

	printf("Hash:");
	for (i = 0; i < mhash_get_block_size(MHASH_MD5); i++) {
		printf("%.2x", hash[i]);
	}
	printf("\n");

	exit(0);
 }