Last active
December 19, 2015 17:19
-
-
Save iwillspeak/5990820 to your computer and use it in GitHub Desktop.
Just some hashing stuff
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
#include <stdio.h> | |
#include <stdlib.h> | |
#include <errno.h> | |
#include <string.h> | |
#include <openssl/ripemd.h> | |
int main(int argc, const char* argv[]) { | |
FILE* file; | |
int length; | |
unsigned char* buffer; | |
unsigned char hash[RIPEMD160_DIGEST_LENGTH] = { 0 }; | |
if (argc != 2) | |
return 1; | |
if (!(file = fopen(argv[1], "r"))) { | |
fprintf(stderr, "open failed:\n%s\n", strerror(errno)); | |
return 1; | |
} | |
if (fseek(file, 0, SEEK_END) == -1) { | |
fprintf(stderr, "Seek failed:\n%s\n", strerror(errno)); | |
return 1; | |
} | |
if ((length = ftell(file)) == -1) { | |
fprintf(stderr, "tell failed:\n%s\n", strerror(errno)); | |
return 1; | |
} | |
if (fseek(file, 0, SEEK_SET) == -1) { | |
fprintf(stderr, "set fialed:\n%s\n", strerror(errno)); | |
return 1; | |
} | |
if (!(buffer = calloc(1, length))) { | |
fprintf(stderr, "alloc failed:\n%s\n", strerror(errno)); | |
return 1; | |
} | |
if (fread(buffer, 1, length, file) != length) { | |
fprintf(stderr, "read failed:\n%s\n", strerror(errno)); | |
return 1; | |
} | |
fclose(file); | |
// Do the hashing | |
RIPEMD160(buffer, length, hash); | |
// print out the sha | |
for (int i = 0; i < RIPEMD160_DIGEST_LENGTH; i++) { | |
printf("%02x", hash[i]); | |
} | |
printf("\n"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment