From f9ae6dfb0c3376229c7c58b34ef3b4c9be7f3524 Mon Sep 17 00:00:00 2001 From: magnum Date: Tue, 11 Aug 2015 20:34:36 +0200 Subject: [PATCH] Fix bugs in episerver SIMD --- src/episerver_fmt_plug.c | 50 ++++++++++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/src/episerver_fmt_plug.c b/src/episerver_fmt_plug.c index d83fa56..da7568c 100644 --- a/src/episerver_fmt_plug.c +++ b/src/episerver_fmt_plug.c @@ -39,12 +39,24 @@ extern struct fmt_main fmt_episerver; john_register_one(&fmt_episerver); #else -#include "sha.h" -#include "sha2.h" #include #include #include + #include "arch.h" + +//#undef _OPENMP +//#undef SIMD_COEF_32 + +#ifdef _OPENMP +#include +#ifndef OMP_SCALE +#define OMP_SCALE 2048 // core i7 no HT +#endif +#endif + +#include "sha.h" +#include "sha2.h" #include "misc.h" #include "common.h" #include "formats.h" @@ -52,12 +64,6 @@ john_register_one(&fmt_episerver); #include "options.h" #include "base64.h" #include "unicode.h" -#ifdef _OPENMP -#include -#ifndef OMP_SCALE -#define OMP_SCALE 2048 // core i7 no HT -#endif -#endif #include "memdbg.h" #define FORMAT_LABEL "EPiServer" @@ -250,7 +256,7 @@ static int crypt_all(int *pcount, struct db_salt *salt) int j, k; for (j = 0; j < NBKEYS; ++j) for (k = 0; k < 4; ++k) // copy the salt to the vector buffer - in[(j&(SIMD_COEF_32-1)) + j/SIMD_COEF_32*SHA_BUF_SIZ*SIMD_COEF_32 + k*SIMD_COEF_32] = ((uint32_t*)cur_salt->esalt)[k]; + in[(j&(SIMD_COEF_32-1)) + j/SIMD_COEF_32*SHA_BUF_SIZ*SIMD_COEF_32 + k*SIMD_COEF_32] = JOHNSWAP(((uint32_t*)cur_salt->esalt)[k]); if(cur_salt->version == 0) { SIMDSHA1body(in, out, NULL, SSEi_MIXED_IN); @@ -319,7 +325,7 @@ static int cmp_exact(char *source, int index) int i; for (i = 0; i < BINARY_SIZE/4; ++i) out[i] = crypt_out[HASH_IDX + i*SIMD_COEF_32]; - + if(cur_salt->version == 0) return !memcmp(binary, out, 20); else @@ -332,12 +338,13 @@ static int cmp_exact(char *source, int index) #endif } +/* Assumes ISO-8859-1 */ static void episerver_set_key(char *_key, int index) { #ifdef SIMD_COEF_32 unsigned char *key = (unsigned char*)_key; - uint32_t *keybuf = &saved_key[(index&(SIMD_COEF_32-1)) + (unsigned int)index/SIMD_COEF_32*SHA_BUF_SIZ*SIMD_COEF_32 + 4*SIMD_COEF_32]; - uint32_t *keybuf_word = keybuf; + uint32_t *keybuf = &saved_key[(index&(SIMD_COEF_32-1)) + (unsigned int)index/SIMD_COEF_32*SHA_BUF_SIZ*SIMD_COEF_32]; + uint32_t *keybuf_word = keybuf + 4*SIMD_COEF_32; /* skip over salt */ unsigned int len, temp2; len = 16 >> 1; // effective salt size is 16 @@ -349,16 +356,13 @@ static void episerver_set_key(char *_key, int index) } else { - *keybuf_word = JOHNSWAP(temp2); - keybuf_word += SIMD_COEF_32; - *keybuf_word = (0x80 << 8); + *keybuf_word = JOHNSWAP((0x80 << 16) | temp2); len++; goto key_cleaning; } len += 2; keybuf_word += SIMD_COEF_32; } - keybuf_word += SIMD_COEF_32; *keybuf_word = (0x80 << 24); key_cleaning: @@ -367,14 +371,14 @@ key_cleaning: *keybuf_word = 0; keybuf_word += SIMD_COEF_32; } - keybuf[(15-4)*SIMD_COEF_32] = len << 4; + keybuf[15*SIMD_COEF_32] = len << 4; #else - strcpy(saved_key[index], key); + strcpy(saved_key[index], _key); #endif } static char *get_key(int index) -{ +{ #ifdef SIMD_COEF_32 static UTF16 out[PLAINTEXT_LENGTH + 1]; unsigned int i,s; @@ -383,7 +387,7 @@ static char *get_key(int index) for(i = 0; i < s; i++) out[i] = ((unsigned char*)saved_key)[GETPOS(16 + (i<<1), index)] | (((unsigned char*)saved_key)[GETPOS(16 + (i<<1) + 1, index)] << 8); out[i] = 0; - + return (char*)utf16_to_enc(out); #else return saved_key[index]; @@ -414,7 +418,11 @@ struct fmt_main fmt_episerver = { SALT_ALIGN, MIN_KEYS_PER_CRYPT, MAX_KEYS_PER_CRYPT, - FMT_CASE | FMT_8_BIT | FMT_OMP | FMT_UNICODE | FMT_UTF8, + FMT_CASE | FMT_8_BIT | FMT_OMP | +#ifndef SIMD_COEF_32 + FMT_UTF8 | +#endif + FMT_UNICODE, { "hash type [1: SHA1 2:SHA256]", }, -- 2.4.0