Last active
April 25, 2017 18:11
-
-
Save Orc/d9d3380777d503c716e9881ce04599e4 to your computer and use it in GitHub Desktop.
Q&D md5sum clone that uses Solar Designer's md5 implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Q&D md5sum clone that uses Solar Designer's md5 implementation */ | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <sys/types.h> | |
#include <sys/stat.h> | |
#include <fcntl.h> | |
#include "md5.h" | |
void | |
md5sum(char *file) | |
{ | |
int i, fd; | |
unsigned char block[5120]; | |
int size; | |
MD5_CTX foo; | |
if (strcmp(file, "-") == 0 ) | |
fd = dup(0); | |
else if ( (fd=open(file, O_RDONLY)) == -1 ) { | |
perror(file); | |
return; | |
} | |
MD5_Init(&foo); | |
while ( (size=read(fd, block, sizeof block)) > 0 ) | |
MD5_Update(&foo, block, size); | |
MD5_Final(block, &foo); | |
for ( i=0; i < 16; i++ ) | |
printf("%02x", block[i]); | |
printf(" %s\n", file); | |
close(fd); | |
} | |
main(argc, argv) | |
char **argv; | |
{ | |
int i; | |
if ( argc < 2 ) | |
md5sum("-"); | |
else | |
for ( i=1; i < argc; i++ ) | |
md5sum(argv[i]); | |
exit(0); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment