#include <mhash.h>
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int i;
MHASH td;
unsigned char buffer;
unsigned char *hash;
td = mhash_init(MHASH_WHIRLPOOL);
if (td == MHASH_FAILED) exit(1);
while (fread(&buffer, 1, 1, stdin) == 1) {
mhash(td, &buffer, 1);
}
hash = mhash_end(td);
for (i = 0; i < mhash_get_block_size(MHASH_WHIRLPOOL); i++) {
printf("%.2x", hash[i]);
}
printf("\n");
exit(0);
}
Hi, I have above code from the mhash example page. I need to change it, so It will keep reading from stdin
, and calculate the hash line by line, instead of waiting for EOF
cat textfile | whirlpool_line_hash
My understanding is that I keep the while loop (which waits for the EOF
) and make the hash calculation and print after I received a 10 (0x0a). After the print mhash needs to be reset, right?
I am not into C at all, but I need a fast program, so I want to do it in C. I already fail at comparing the pointer to an integer ;-)
Can someone please help?