/* experiment with precomputed attack */ /* overwrites files in out/ */ /* mkdir out; gcc -O3 -lcrypto ossl7.c && (ulimit -S -n 1040 && time ./a.out) */ /* * Copyright © 2021 Aleksey Cherepanov * * Redistribution and use in source and binary forms, with or without * modification, are permitted. */ #pragma GCC diagnostic ignored "-Wdeclaration-after-statement" #pragma GCC optimize 3 #include #include #include #include #include /* index of candidate to static hash buffer */ unsigned char *get_hash(int idx) { /* index to candidate */ char buf[21]; sprintf(buf, "%d", idx); /* candidate to hash */ MD5_CTX ctx; static unsigned char hash_out[MD5_DIGEST_LENGTH]; MD5_Init(&ctx); MD5_Update(&ctx, buf, strlen(buf)); MD5_Final(hash_out, &ctx); return hash_out; } /* globals */ #define groups_k 1024 FILE *files[groups_k] = { 0 }; int main(void) { char buf[32]; for (int i = 0; i < groups_k; i++) { sprintf(buf, "out/%d", i); files[i] = fopen(buf, "w"); assert(files[i]); } for (int i = 0; i < 256 * 256 * 256; i++) { unsigned char *h = get_hash(i); int group = (h[0] * 256 + h[1]) % groups_k; int r = fwrite(&i, sizeof(i), 1, files[group]); assert(r == 1); } for (int i = 0; i < groups_k; i++) { int r = fclose(files[i]); assert(r == 0); } return 0; }