/* * md5.c by Torben Nielsen * */ #include #include #include int main(int argc, char *argv[]) { FILE *file; unsigned char *output; unsigned char *buf; int num; int size; int i; MD5_CTX *md5struct; size = sizeof(unsigned char); if (argc != 2) { printf("Usage: md5 \n"); return 1; } file = fopen(argv[1],"r"); if (file == 0) { printf("Could not open %s\n", argv[1]); return 2; } md5struct = malloc( sizeof(MD5_CTX) ); MD5_Init(md5struct); buf = malloc( size * 128); while (!feof(file)) { num = fread(buf, size, 128, file); MD5_Update(md5struct, buf, num*size) ; } fclose(file); output = malloc( size * 16); MD5_Final(output, md5struct); for (i=0;i<16;i++) { printf("%02x",output[i]); } printf(" %s\n", argv[1]); free(md5struct); free(output); return 0; }