diff -r d1a3c634cf0d src/zip_fmt.c --- a/src/zip_fmt.c Wed Jul 06 18:35:50 2011 -0700 +++ b/src/zip_fmt.c Mon Jul 18 20:00:36 2011 -0700 @@ -24,7 +24,8 @@ #include "common.h" #include "formats.h" #include "gladman_fileenc.h" -#include + +#include #include #include @@ -37,10 +38,10 @@ #define BINARY_SIZE 2 #define SALT_SIZE 512 #define MIN_KEYS_PER_CRYPT 1 -#define MAX_KEYS_PER_CRYPT 1 +#define MAX_KEYS_PER_CRYPT 96 -static char saved_key[PLAINTEXT_LENGTH + 1]; -static int has_been_cracked = 0; +static char saved_key[MAX_KEYS_PER_CRYPT][PLAINTEXT_LENGTH + 1]; +static int has_been_cracked[MAX_KEYS_PER_CRYPT]; static unsigned char *saved_salt; static unsigned char passverify[2]; static int type; /* type of zip file */ @@ -51,16 +52,30 @@ {NULL} }; +struct fmt_main zip_fmt; + static void init(struct fmt_main *pFmt) { /* OpenSSL init, cleanup part is left to OS */ SSL_load_error_strings(); + SSL_library_init(); OpenSSL_add_all_algorithms(); + +#if defined(_OPENMP) && OPENSSL_VERSION_NUMBER >= 0x10000000 + if (SSLeay() < 0x10000000) { + fprintf(stderr, "Warning: compiled against OpenSSL 1.0+, " + "but running with an older version -\n" + "disabling OpenMP for zip because of thread-safety issues " + "of older OpenSSL\n"); + zip_fmt.params.min_keys_per_crypt = + zip_fmt.params.max_keys_per_crypt = 1; + zip_fmt.params.flags &= ~FMT_OMP; + } +#endif } static int valid(char *ciphertext, struct fmt_main *pFmt) { -// printf("%s\n", ciphertext); return !strncmp(ciphertext, "$zip$*", 6); } @@ -104,7 +119,7 @@ for (i = 0; i < 2; i++) passverify[i] = atoi16[ARCH_INDEX(p[i * 2])] * 16 + atoi16[ARCH_INDEX(p[i * 2 + 1])]; - has_been_cracked = 0; + memset(has_been_cracked, 0, MAX_KEYS_PER_CRYPT); free(saltcopy_mem); } @@ -113,41 +128,47 @@ int saved_key_length = strlen(key); if (saved_key_length > PLAINTEXT_LENGTH) saved_key_length = PLAINTEXT_LENGTH; - memcpy(saved_key, key, saved_key_length); - saved_key[saved_key_length] = 0; + memcpy(saved_key[index], key, saved_key_length); + saved_key[index][saved_key_length] = 0; } static char *get_key(int index) { - return saved_key; + return saved_key[index]; } static void crypt_all(int count) { - unsigned char pwd_ver[2] = { 0 }; - unsigned char kbuf[2 * MAX_KEY_LENGTH + PWD_VER_LENGTH]; - /* derive the encryption and authetication keys and the password verifier */ - derive_key((unsigned char *)saved_key, strlen(saved_key), - saved_salt, SALT_LENGTH(mode), - KEYING_ITERATIONS, kbuf, 2 * KEY_LENGTH(mode) + PWD_VER_LENGTH); - memcpy(pwd_ver, kbuf + 2 * KEY_LENGTH(mode), PWD_VER_LENGTH); - has_been_cracked = !memcmp(pwd_ver, passverify, 2); + int index; +#if defined(_OPENMP) && OPENSSL_VERSION_NUMBER >= 0x10000000 +#pragma omp parallel for default(none) private(index) shared(count, passverify, has_been_cracked, saved_key, saved_salt, mode) +#endif + for (index = 0; index < count; index++) { + unsigned char pwd_ver[2] = { 0 }; + unsigned char kbuf[2 * MAX_KEY_LENGTH + PWD_VER_LENGTH]; + /* derive the encryption and authetication keys and the password verifier */ + derive_key((unsigned char *)saved_key[index], strlen(saved_key[index]), + saved_salt, SALT_LENGTH(mode), + KEYING_ITERATIONS, kbuf, 2 * KEY_LENGTH(mode) + PWD_VER_LENGTH); + memcpy(pwd_ver, kbuf + 2 * KEY_LENGTH(mode), PWD_VER_LENGTH); + has_been_cracked[index] = !memcmp(pwd_ver, passverify, 2); + } } static int cmp_all(void *binary, int count) { - return has_been_cracked; + return 1; } static int cmp_one(void *binary, int index) { - return 1; + return has_been_cracked[index]; } static int cmp_exact(char *source, int index) { - return 1; + return has_been_cracked[index]; } struct fmt_main zip_fmt = { @@ -162,6 +183,9 @@ SALT_SIZE, MIN_KEYS_PER_CRYPT, MAX_KEYS_PER_CRYPT, +#if defined(_OPENMP) && OPENSSL_VERSION_NUMBER >= 0x10000000 + FMT_OMP | +#endif FMT_CASE | FMT_8_BIT, zip_tests }, {