#define _XOPEN_SOURCE #include #include #include #define MAX 72 int main(void) { const char *setting = "$2a$04$abcdefghijklmnopqrstuu"; char pw[MAX + 1], saved[61], *hash; unsigned int i, j, n; unsigned int total, bad; total = bad = 0; for (n = 0; n < MAX; n++) { pw[n] = 'a'; pw[n + 1] = 0; for (i = 0; i <= n; i++) { int reported = 0; pw[i] = 0xa3; memcpy(saved, crypt(pw, setting), sizeof(saved)); for (j = (i < 3) ? 0 : (i - 3); j < i; j++) { pw[j] = 'b'; hash = crypt(pw, setting); pw[j] = 'a'; if (memcmp(hash, saved, sizeof(saved))) continue; if (!reported) printf( "length %u, 8-bit @ %u overwrites @", n + 1, i + 1); printf(" %u", j + 1); reported = 1; } pw[i] = 'a'; total++; if (reported) { putchar('\n'); bad++; } } if (n != (19 - 1) && n != (MAX - 1)) continue; printf("\nBad / total {length, position}s: %u / %u = %.2f\n\n", bad, total, (double)bad / total); } return 0; }