S
hab mal was zusammenkopiert, das läuft sogar... nur bringts bei jedem aufruf ein neuen Hash zustande.
#include <stdio.h>
#include <mhash.h>
#include <stdlib.h>
int main (void) {
int i;
FILE * pFile;
long lSize;
unsigned char * buffer;
size_t result;
MHASH td;
unsigned char hash[mhash_get_block_size(MHASH_SHA256)];
pFile = fopen ("test.txt" , "rb");
if (pFile == NULL) {
fputs ("File error", stderr); exit (1);
}
//obtain file size:
fseek (pFile, 0, SEEK_END);
lSize = ftell (pFile);
rewind (pFile);
// allocate memory to contain the whole file:
buffer = (unsigned char*) malloc (sizeof(unsigned char) *lSize);
if (buffer == NULL) {
fputs ("Memory error", stderr);
exit (2);
}
// copy the file into the buffer:
result = fread (buffer, sizeof(unsigned char), lSize, pFile);
if (result != lSize) {
fputs ("Reading error", stderr);
exit (3);
}
td = mhash_init(MHASH_SHA256);
mhash (td, buffer, lSize);
mhash_deinit (td, hash);
for (i = 0; i < mhash_get_block_size(MHASH_SHA256); i++) {
printf("%.2x", hash[i]);
}
printf(" test.txt\n");
fclose (pFile);
free (buffer);
}
Edit: hab ein kleines Zeichen grad entfernt und es läuft...