/************************************************************ * Lovepump's MD5 Hasher * * For the Phorce Forums * * Enjoy! * *************************************************************/ #include #include #include #include #define HASHSIZE 16 #define TARGETSIZE 16 #define HASH "MD5" #define WRITESIZE 4096 #define FILENAME "test.bin" /* Define T_OUT to have the target string written to the output file as well as the hash #define T_OUT */ FILE *fd; int file_open() { fd = fopen(FILENAME, "wb"); if(!fd) return -1; return 1; } int file_close(){ fclose(fd); return 1; } int file_write(unsigned char *buf, unsigned int size) { unsigned int rv; rv = fwrite(buf, size, 1, fd); if(rv < size) return -1; return 1; } void put_results(const unsigned char *target, const unsigned char *hash) { int i; static unsigned int fill = 0; static unsigned char buffer[WRITESIZE]; if(target == NULL && hash == NULL) { file_write(buffer, fill); fill = 0; return; } #ifdef T_OUT if((fill + HASHSIZE + TARGETSIZE) > WRITESIZE) { file_write(buffer, fill); fill = 0; } for(i = 0; i < TARGETSIZE; i++) buffer[fill + i] = target[i]; fill += TARGETSIZE; for(i = 0; i < HASHSIZE; i++) buffer[fill + i] = hash[i]; fill += HASHSIZE; #else if((fill + HASHSIZE) > WRITESIZE) { file_write(buffer, fill); fill = 0; } for(i = 0; i < HASHSIZE; i++) buffer[fill + i] = hash[i]; fill += HASHSIZE; #endif } int main(int argc, char **argv) { EVP_MD_CTX ctx; const EVP_MD *md; unsigned int i, len, ret, bn_size; unsigned char target[100]; BIGNUM *t, *one; t = BN_new(); one = BN_new(); BN_zero(t); BN_one(one); unsigned char digest[HASHSIZE]; memset(target, 0, TARGETSIZE); OpenSSL_add_all_digests(); file_open(); EVP_MD_CTX_init(&ctx); md = EVP_get_digestbyname(HASH); ret = EVP_DigestInit_ex(&ctx, md, NULL); for(i = 0; i < 16777215; i++) { bn_size = BN_num_bytes(t); BN_bn2bin(t, target); /* printf("Message: "); for(k = 0; k < TARGETSIZE; k++) printf("%02x ", target[k]); */ EVP_DigestUpdate(&ctx, target, bn_size); EVP_DigestFinal_ex(&ctx, digest, &len); put_results(target, digest); /* printf("Digest: "); for(k = 0; k < HASHSIZE; k++) printf("%02x ", digest[k]); printf("\n"); */ BN_add(t, t, one); } put_results(NULL, NULL); file_close(); }