diff --git a/src/SybasePROP_fmt_plug.c b/src/SybasePROP_fmt_plug.c index c82c6ad..32cf6f6 100644 --- a/src/SybasePROP_fmt_plug.c +++ b/src/SybasePROP_fmt_plug.c @@ -33,7 +33,7 @@ john_register_one(&fmt_sybaseprop); #ifdef _OPENMP #include #ifndef OMP_SCALE -#define OMP_SCALE 2048 // xxx +#define OMP_SCALE 16 #endif static int omp_t = 1; #endif @@ -63,7 +63,7 @@ static int omp_t = 1; #define SALT_ALIGN 1 #define MIN_KEYS_PER_CRYPT 1 -#define MAX_KEYS_PER_CRYPT 1 +#define MAX_KEYS_PER_CRYPT 128 static struct fmt_tests SybasePROP_tests[] = { {"0x2905aeb3d00e3b80fb0695cb34c9fa9080f84ae1824b24cc51a3849dcb06", "test11"}, @@ -77,11 +77,13 @@ static ARCH_WORD_32 (*crypt_out)[BINARY_SIZE / sizeof(ARCH_WORD_32)]; static void init(struct fmt_main *self) { -#if defined (_OPENMP) +#ifdef _OPENMP omp_t = omp_get_max_threads(); - self->params.min_keys_per_crypt *= omp_t; - omp_t *= OMP_SCALE; - self->params.max_keys_per_crypt *= omp_t; + if (omp_t > 1) { + self->params.min_keys_per_crypt *= omp_t; + omp_t *= OMP_SCALE; + self->params.max_keys_per_crypt *= omp_t; + } #endif saved_key = mem_calloc(self->params.max_keys_per_crypt, sizeof(*saved_key)); @@ -122,7 +124,7 @@ static void *get_binary(char *ciphertext) int i; p = ciphertext + PREFIX_LENGTH + SALT_SIZE_HEX + 2; // last 2 bytes always seem to be "05" - for (i = 0; i < BINARY_SIZE; i++) { + for (i = 0; i < BINARY_SIZE; i++) { out[i] = (atoi16[ARCH_INDEX(*p)] << 4) | atoi16[ARCH_INDEX(p[1])]; @@ -163,17 +165,14 @@ static char *get_key(int index) static int crypt_all(int *pcount, struct db_salt *salt) { const int count = *pcount; - int index = 0; + int index; #ifdef _OPENMP #pragma omp parallel for - for (index = 0; index < count; index++) #endif - { - unsigned int g_seed = 0x3f; - struct JtR_FEAL8_CTX ctx; + for (index = 0; index < count; index++) { generate_hash((unsigned char*)saved_key[index], saved_salt, - (unsigned char*)crypt_out[index], &g_seed, &ctx); + (unsigned char*)crypt_out[index]); } return count; } diff --git a/src/feal8_plug.c b/src/feal8_plug.c index 5075e14..fed9907 100644 --- a/src/feal8_plug.c +++ b/src/feal8_plug.c @@ -9,111 +9,29 @@ #include #include +#include "common.h" #include "johnswap.h" #include "memdbg.h" -// Moved these declares out of the functions, and into global for this file. -static ByteType S0(ByteType X1, ByteType X2); -static ByteType S1(ByteType X1, ByteType X2); -static HalfWord f(HalfWord AA, QuarterWord BB); -static HalfWord MakeH1(ByteType * B); -static void DissH1(HalfWord H, ByteType * D); - -void feal_Decrypt(ByteType * Cipher, ByteType * Plain, struct JtR_FEAL8_CTX *ctx) +static MAYBE_INLINE ByteType Rot2(ByteType X) /* - Decrypt a block, using the last key set. + Evaluate the Rot2 function. */ { - HalfWord L, R, NewL; - int r; - - R = MakeH1(Cipher); - L = MakeH1(Cipher + 4); - R ^= ctx->K1213; - L ^= ctx->K1415; - L ^= R; - - for (r = 7; r >= 0; --r) { - NewL = R ^ f(L, ctx->K[r]); - R = L; - L = NewL; - } - - R ^= L; - R ^= ctx->K1011; - L ^= ctx->K89; - - DissH1(L, Plain); - DissH1(R, Plain + 4); + return (X << 2) | (X >> 6); } -static void DissH1(HalfWord H, ByteType * D) -/* - Disassemble the given halfword into 4 bytes. -*/ +static MAYBE_INLINE ByteType S0(ByteType X1, ByteType X2) { - union { - HalfWord All; - ByteType Byte[4]; - } T; - - T.All = H; - *D++ = T.Byte[0]; - *D++ = T.Byte[1]; - *D++ = T.Byte[2]; - *D = T.Byte[3]; + return Rot2((X1 + X2) & 0xff); } -static void DissQ1(QuarterWord Q, ByteType * B) -/* - Disassemble a quarterword into two Bytes. -*/ +static MAYBE_INLINE ByteType S1(ByteType X1, ByteType X2) { - union { - QuarterWord All; - ByteType Byte[2]; - } QQ; - - QQ.All = Q; - *B++ = QQ.Byte[0]; - *B = QQ.Byte[1]; -} - -void feal_Encrypt(ByteType * Plain, ByteType * Cipher, struct JtR_FEAL8_CTX *ctx) -/* - Encrypt a block, using the last key set. -*/ -{ - HalfWord L, R, NewR; - int r; - - L = MakeH1(Plain); - R = MakeH1(Plain + 4); - L ^= ctx->K89; - R ^= ctx->K1011; - R ^= L; - -#ifdef FEAL_DEBUG - printf("p: %08lx %08lx\n", L, R); -#endif - for (r = 0; r < 8; ++r) { - NewR = L ^ f(R, ctx->K[r]); - L = R; - R = NewR; -#ifdef FEAL_DEBUG - printf("%2d: %08lx %08lx\n", r, L, R); -#endif - } - - L ^= R; - R ^= ctx->K1213; - L ^= ctx->K1415; - - DissH1(R, Cipher); - DissH1(L, Cipher + 4); + return Rot2((X1 + X2 + 1) & 0xff); } -static HalfWord f(HalfWord AA, QuarterWord BB) +static MAYBE_INLINE HalfWord f(HalfWord AA, QuarterWord BB) /* Evaluate the f function. */ @@ -147,48 +65,56 @@ static HalfWord f(HalfWord AA, QuarterWord BB) return RetVal.All; } -static HalfWord FK(HalfWord AA, HalfWord BB) +static MAYBE_INLINE HalfWord MakeH1(ByteType * B) /* - Evaluate the FK function. + Assemble a HalfWord from the four bytes provided. */ { - ByteType FK1, FK2; union { HalfWord All; ByteType Byte[4]; - } RetVal, A, B; + } RetVal; - A.All = AA; - B.All = BB; - FK1 = A.Byte[1] ^ A.Byte[0]; - FK2 = A.Byte[2] ^ A.Byte[3]; - FK1 = S1(FK1, FK2 ^ B.Byte[0]); - FK2 = S0(FK2, FK1 ^ B.Byte[1]); - RetVal.Byte[1] = FK1; - RetVal.Byte[2] = FK2; - RetVal.Byte[0] = S0(A.Byte[0], FK1 ^ B.Byte[2]); - RetVal.Byte[3] = S1(A.Byte[3], FK2 ^ B.Byte[3]); + RetVal.Byte[0] = *B++; + RetVal.Byte[1] = *B++; + RetVal.Byte[2] = *B++; + RetVal.Byte[3] = *B; return RetVal.All; } -static HalfWord MakeH1(ByteType * B) +static MAYBE_INLINE void DissH1(HalfWord H, ByteType * D) /* - Assemble a HalfWord from the four bytes provided. + Disassemble the given halfword into 4 bytes. */ { union { HalfWord All; ByteType Byte[4]; - } RetVal; + } T; - RetVal.Byte[0] = *B++; - RetVal.Byte[1] = *B++; - RetVal.Byte[2] = *B++; - RetVal.Byte[3] = *B; - return RetVal.All; + T.All = H; + *D++ = T.Byte[0]; + *D++ = T.Byte[1]; + *D++ = T.Byte[2]; + *D = T.Byte[3]; +} + +static MAYBE_INLINE void DissQ1(QuarterWord Q, ByteType * B) +/* + Disassemble a quarterword into two Bytes. +*/ +{ + union { + QuarterWord All; + ByteType Byte[2]; + } QQ; + + QQ.All = Q; + *B++ = QQ.Byte[0]; + *B = QQ.Byte[1]; } -static HalfWord MakeH2(QuarterWord * Q) +static MAYBE_INLINE HalfWord MakeH2(QuarterWord * Q) /* Make a halfword from the two quarterwords given. */ @@ -200,37 +126,28 @@ static HalfWord MakeH2(QuarterWord * Q) return MakeH1(B); } -static ByteType Rot2(ByteType X) +static MAYBE_INLINE HalfWord FK(HalfWord AA, HalfWord BB) /* - Evaluate the Rot2 function. + Evaluate the FK function. */ { - static int First = 1; - static ByteType RetVal[256]; - - if (First) { - int i, High, Low; - for (i = 0, High = 0, Low = 0; i < 256; ++i) { - RetVal[i] = High + Low; - High += 4; - if (High > 255) { - High = 0; - ++Low; - } - } - First = 0; - } - return RetVal[X]; -} - -static ByteType S0(ByteType X1, ByteType X2) -{ - return Rot2((X1 + X2) & 0xff); -} + ByteType FK1, FK2; + union { + HalfWord All; + ByteType Byte[4]; + } RetVal, A, B; -static ByteType S1(ByteType X1, ByteType X2) -{ - return Rot2((X1 + X2 + 1) & 0xff); + A.All = AA; + B.All = BB; + FK1 = A.Byte[1] ^ A.Byte[0]; + FK2 = A.Byte[2] ^ A.Byte[3]; + FK1 = S1(FK1, FK2 ^ B.Byte[0]); + FK2 = S0(FK2, FK1 ^ B.Byte[1]); + RetVal.Byte[1] = FK1; + RetVal.Byte[2] = FK2; + RetVal.Byte[0] = S0(A.Byte[0], FK1 ^ B.Byte[2]); + RetVal.Byte[3] = S1(A.Byte[3], FK2 ^ B.Byte[3]); + return RetVal.All; } void feal_SetKey(ByteType * KP, struct JtR_FEAL8_CTX *ctx) @@ -276,3 +193,65 @@ void feal_SetKey(ByteType * KP, struct JtR_FEAL8_CTX *ctx) ctx->K1213 = MakeH2(ctx->K + 12); ctx->K1415 = MakeH2(ctx->K + 14); } + +void feal_Decrypt(ByteType * Cipher, ByteType * Plain, struct JtR_FEAL8_CTX *ctx) +/* + Decrypt a block, using the last key set. +*/ +{ + HalfWord L, R, NewL; + int r; + + R = MakeH1(Cipher); + L = MakeH1(Cipher + 4); + R ^= ctx->K1213; + L ^= ctx->K1415; + L ^= R; + + for (r = 7; r >= 0; --r) { + NewL = R ^ f(L, ctx->K[r]); + R = L; + L = NewL; + } + + R ^= L; + R ^= ctx->K1011; + L ^= ctx->K89; + + DissH1(L, Plain); + DissH1(R, Plain + 4); +} + +void feal_Encrypt(ByteType * Plain, ByteType * Cipher, struct JtR_FEAL8_CTX *ctx) +/* + Encrypt a block, using the last key set. +*/ +{ + HalfWord L, R, NewR; + int r; + + L = MakeH1(Plain); + R = MakeH1(Plain + 4); + L ^= ctx->K89; + R ^= ctx->K1011; + R ^= L; + +#ifdef FEAL_DEBUG + printf("p: %08lx %08lx\n", L, R); +#endif + for (r = 0; r < 8; ++r) { + NewR = L ^ f(R, ctx->K[r]); + L = R; + R = NewR; +#ifdef FEAL_DEBUG + printf("%2d: %08lx %08lx\n", r, L, R); +#endif + } + + L ^= R; + R ^= ctx->K1213; + L ^= ctx->K1415; + + DissH1(R, Cipher); + DissH1(L, Cipher + 4); +} diff --git a/src/syb-prop_repro.h b/src/syb-prop_repro.h index 8da9019..8861b60 100644 --- a/src/syb-prop_repro.h +++ b/src/syb-prop_repro.h @@ -1,16 +1,11 @@ #include #include #include -#include "feal8.h" // #define EXPANDED_PWDLEN 57 #define EXPANDED_PWDLEN 64 // PLAINTEXT_LENGTH #define META_KEYSCH_LEN 64 #define HASH_LEN 28 -// static void print_block(unsigned char * bytes, int endpos, const char * szoveg); - void generate_hash(unsigned char * password, unsigned char seed, - unsigned char * result_hash, unsigned int *g_seed, struct JtR_FEAL8_CTX *ctx); - -// static int myrand(void); + unsigned char * result_hash); diff --git a/src/syb-prop_repro_plug.c b/src/syb-prop_repro_plug.c index 751f6f2..a91d628 100644 --- a/src/syb-prop_repro_plug.c +++ b/src/syb-prop_repro_plug.c @@ -1,43 +1,33 @@ #include "syb-prop_repro.h" +#include "common.h" +#include "feal8.h" #include "memdbg.h" static unsigned char joke[] = "Q:Whydidtheflydanceonthejar?A:Becausethelidsaidtwisttoopen.HaHa!"; -static void rnd_srand(unsigned int seed, unsigned int *g_seed) +static MAYBE_INLINE void rnd_srand(unsigned int seed, unsigned int *g_seed) { *g_seed = seed; } -static int rnd_rand(unsigned int *g_seed) +static MAYBE_INLINE int rnd_rand(unsigned int *g_seed) { *g_seed = (*g_seed) * 0x343FD + 0x269EC3; return ((*g_seed) >> 0x10) & 0x7FFF; } -/* static void print_block(unsigned char *bytes, int endpos, const char *szoveg) -{ - int i; - printf("\n%s:\n", szoveg); - for (i = 0; i < endpos; i++) { - if (i % 8 == 0) - printf("\n"); - printf("%.2x", bytes[i]); - } - printf("\n"); -} */ - -static void feal_keysch_repro(unsigned char *key, struct JtR_FEAL8_CTX *ctx) +static MAYBE_INLINE void feal_keysch_repro(unsigned char *key, struct JtR_FEAL8_CTX *ctx) { feal_SetKey((ByteType *) key, ctx); } -static void feal_encrypt_repro(unsigned char *plaintext, unsigned char *ciphertext, struct JtR_FEAL8_CTX *ctx) +static MAYBE_INLINE void feal_encrypt_repro(unsigned char *plaintext, unsigned char *ciphertext, struct JtR_FEAL8_CTX *ctx) { feal_Encrypt(plaintext, ciphertext, ctx); } -static void ccat_pad_repro(unsigned char *password, unsigned char *expanded_password) +static MAYBE_INLINE void ccat_pad_repro(unsigned char *password, unsigned char *expanded_password) { int i, pwdlen; pwdlen = strlen((const char *) password); @@ -48,7 +38,7 @@ static void ccat_pad_repro(unsigned char *password, unsigned char *expanded_pass expanded_password[i] = 0x1D; } -static void syb_XOR(unsigned char *enc_result, unsigned char *password_block, +static MAYBE_INLINE void syb_XOR(unsigned char *enc_result, unsigned char *password_block, unsigned char *result) { int i; @@ -56,7 +46,7 @@ static void syb_XOR(unsigned char *enc_result, unsigned char *password_block, result[i] = enc_result[i] ^ password_block[i]; } -static void syb_apply_salt_byte(unsigned char salt, unsigned char *password, +static MAYBE_INLINE void syb_apply_salt_byte(unsigned char salt, unsigned char *password, unsigned char *result) { result[0] = salt ^ password[0]; @@ -69,7 +59,7 @@ static void syb_apply_salt_byte(unsigned char salt, unsigned char *password, result[7] = result[1] ^ password[7]; } -static unsigned char salt_prob(unsigned int *g_seed) +static MAYBE_INLINE unsigned char salt_prob(unsigned int *g_seed) { unsigned int random = rnd_rand(g_seed); @@ -79,7 +69,7 @@ static unsigned char salt_prob(unsigned int *g_seed) return (unsigned char) random; } -static void meta_keysch_repro(unsigned int seed, unsigned char *password, +static MAYBE_INLINE void meta_keysch_repro(unsigned int seed, unsigned char *password, unsigned char *result, unsigned int *g_seed, struct JtR_FEAL8_CTX *ctx) { unsigned char expanded_password[EXPANDED_PWDLEN]; @@ -116,7 +106,7 @@ static void meta_keysch_repro(unsigned int seed, unsigned char *password, } } -static void meta_encrypt_repro(unsigned char *meta_keysched, unsigned char *result, struct JtR_FEAL8_CTX *ctx) +static MAYBE_INLINE void meta_encrypt_repro(unsigned char *meta_keysched, unsigned char *result, struct JtR_FEAL8_CTX *ctx) { unsigned char act_XOR_copy_result[8]; unsigned int i; @@ -131,34 +121,17 @@ static void meta_encrypt_repro(unsigned char *meta_keysched, unsigned char *resu } } -// static int state; - -/* static int myrand(void) { - int const a = 1103515245; - int const c = 12345; - state = a * state + c; - - return (state >> 16) & 0x7FFF; -} -static int myrand(void) - -{ - int const a = 69069; - int const c = 1; - state = a * state + c; - return (state >> 16) & 0x7FFF; -} */ - void generate_hash(unsigned char *password, unsigned char seed, - unsigned char *result_hash, unsigned int *g_seed, struct JtR_FEAL8_CTX *ctx) + unsigned char *result_hash) { + struct JtR_FEAL8_CTX ctx; + unsigned int g_seed = 0x3f; unsigned char meta_keysch_result[META_KEYSCH_LEN]; unsigned char meta_encrypt_result[META_KEYSCH_LEN]; - // srand(seed); - rnd_srand(seed, g_seed); - meta_keysch_repro(seed, password, meta_keysch_result, g_seed, ctx); - meta_encrypt_repro(meta_keysch_result, meta_encrypt_result, ctx); + rnd_srand(seed, &g_seed); + meta_keysch_repro(seed, password, meta_keysch_result, &g_seed, &ctx); + meta_encrypt_repro(meta_keysch_result, meta_encrypt_result, &ctx); memcpy(result_hash, meta_encrypt_result + META_KEYSCH_LEN - HASH_LEN, HASH_LEN);