From cb5d5ec0f88271ff85039c3fc41d38fd026eb0af Mon Sep 17 00:00:00 2001
From: magnum <magnum>
Date: Tue, 22 Nov 2011 19:41:31 +0100
Subject: [PATCH 2/6] Fixes for dynamic_fmt vs. new MD5_std.c

---
 src/MD5_std.c     |    8 ++++----
 src/dynamic_fmt.c |   36 ++++++++++++++++++++++++++++++------
 2 files changed, 34 insertions(+), 10 deletions(-)

diff --git a/src/MD5_std.c b/src/MD5_std.c
index d3a31b8..af53399 100644
--- a/src/MD5_std.c
+++ b/src/MD5_std.c
@@ -481,10 +481,10 @@ extern void MD5_body(MD5_word x[15], MD5_word out[4]);
 #if MD5_std_mt
 #define MD5_body(x, out) \
 	MD5_body_for_thread(t, x, out)
-static MAYBE_INLINE_BODY void MD5_body_for_thread(int t,
+MAYBE_INLINE_BODY void MD5_body_for_thread(int t,
 	MD5_word x[15], MD5_word out[4])
 #else
-static MAYBE_INLINE_BODY void MD5_body(MD5_word x[15], MD5_word out[4])
+MAYBE_INLINE_BODY void MD5_body(MD5_word x[15], MD5_word out[4])
 #endif
 {
 	MD5_word a, b = Cb, c = Cc, d;
@@ -580,11 +580,11 @@ static MAYBE_INLINE_BODY void MD5_body(MD5_word x[15], MD5_word out[4])
 #if MD5_std_mt
 #define MD5_body(x0, x1, out0, out1) \
 	MD5_body_for_thread(t, x0, x1, out0, out1)
-static MAYBE_INLINE_BODY void MD5_body_for_thread(int t,
+MAYBE_INLINE_BODY void MD5_body_for_thread(int t,
 	MD5_word x0[15], MD5_word x1[15],
 	MD5_word out0[4], MD5_word out1[4])
 #else
-static MAYBE_INLINE_BODY void MD5_body(MD5_word x0[15], MD5_word x1[15],
+MAYBE_INLINE_BODY void MD5_body(MD5_word x0[15], MD5_word x1[15],
 	MD5_word out0[4], MD5_word out1[4])
 #endif
 {
diff --git a/src/dynamic_fmt.c b/src/dynamic_fmt.c
index 102f211..722c925 100644
--- a/src/dynamic_fmt.c
+++ b/src/dynamic_fmt.c
@@ -310,9 +310,15 @@ static void __SSE_gen_BenchLowLevelFunctions();
 #define MIN_KEYS_PER_CRYPT_X86	1
 #define MAX_KEYS_PER_CRYPT_X86	128
 extern void MD5_Go2 (unsigned char *data, unsigned int len, unsigned char *result);
-#if MD5_X2
-#define ALGORITHM_NAME_X86		"64x2 (MD5_Body)"
+#if MD5_X2 && (!MD5_ASM)
+#if defined(_OPENMP)
+#define MD5_body(x0, x1, out0, out1) \
+	MD5_body_for_thread(0, x0, x1, out0, out1)
+extern void MD5_body_for_thread(int t, MD5_word x[15], MD5_word x2[15], MD5_word out[4], MD5_word out2[4]);
+#else
 extern void MD5_body(MD5_word x[15], MD5_word x2[15], MD5_word out[4], MD5_word out2[4]);
+#endif
+#define ALGORITHM_NAME_X86		"64x2 (MD5_Body)"
 #define DoMD5(A,L,C) do{if(!force_md5_ctx&&(L[0])<55&&(L[1])<55) {A.x1.b[L[0]]=0x80;A.x2.b2[L[1]]=0x80;A.x1.w[14]=(L[0]<<3);A.x2.w2[14]=(L[1]<<3);MD5_swap(A.x1.w,A.x1.w,(L[0]+4)>>2);MD5_swap(A.x2.w2,A.x2.w2,(L[1]+4)>>2);MD5_body(A.x1.w,A.x2.w2,C.x1.w,C.x2.w2);MD5_swap2(C.x1.w,C.x2.w2,C.x1.w,C.x2.w2,4);} else {MD5_Go2(A.x1.B,L[0],C.x1.B); MD5_Go2(A.x2.B2,L[1],C.x2.B2);} }while(0)
 #define DoMD5o(A,L,C) do{if((L[0])<55&&(L[1])<55) {MD5_body(A.x1.w,A.x2.w2,C.x1.w,C.x2.w2);} else {MD5_Go2(A.x1.B,L[0],C.x1.B); MD5_Go2(A.x2.B2,L[1],C.x2.B2);} }while(0)
 #if ARCH_LITTLE_ENDIAN
@@ -323,8 +329,14 @@ extern void MD5_body(MD5_word x[15], MD5_word x2[15], MD5_word out[4], MD5_word
 #define DoMD5a2(A,L,C,D) do{MD5_body(A->x1.w,A->x2.w2,tmpOut.x1.w,tmpOut.x2.w2);MD5_swap2(tmpOut.x1.w,tmpOut.x2.w2,tmpOut.x1.w,tmpOut.x2.w2,4);memcpy(&(C->x1.b[D[0]]),tmpOut.x1.b,16);memcpy(&(C->x2.b2[D[1]]),tmpOut.x2.b2,16);}while(0)
 #endif
 #else
-#define ALGORITHM_NAME_X86		"128x1 (MD5_Body)"
+#if defined(_OPENMP) && !MD5_ASM
+#define MD5_body(x, out) \
+	MD5_body_for_thread(0, x, out)
+extern void MD5_body_for_thread(int t, ARCH_WORD_32 x[15], ARCH_WORD_32 out[4]);
+#else
 extern void MD5_body(ARCH_WORD_32 x[15], ARCH_WORD_32 out[4]);
+#endif
+#define ALGORITHM_NAME_X86		"128x1 (MD5_Body)"
 #define DoMD5(A,L,C) do{if(!force_md5_ctx&&(L)<55) {A.x1.b[L]=0x80;A.x1.w[14]=(L<<3);MD5_swap(A.x1.w,A.x1.w,((L+4)>>2));MD5_body(A.x1.w,C.x1.w);MD5_swap(C.x1.w,C.x1.w,4);} else MD5_Go2(A.x1.B,L,C.x1.B); }while(0)
 #define DoMD5o(A,L,C) do{if((L)<55) {MD5_body(A.x1.w,C.x1.w);} else MD5_Go2(A.x1.B,L,C.x1.B); }while(0)
 #if ARCH_LITTLE_ENDIAN
@@ -340,16 +352,28 @@ static MD5_OUT tmpOut;
 static MD5_OUT tmpOut;
 #define MIN_KEYS_PER_CRYPT_X86	1
 #define MAX_KEYS_PER_CRYPT_X86	128
-#if MD5_X2
+#if MD5_X2 && (!MD5_ASM)
+#if defined(_OPENMP)
+#define MD5_body(x0, x1, out0, out1) \
+	MD5_body_for_thread(0, x0, x1, out0, out1)
+extern void MD5_body_for_thread(int t, ARCH_WORD_32 x1[15], ARCH_WORD_32 x2[15], ARCH_WORD_32 out1[4], ARCH_WORD_32 out2[4]);
+#else
+extern void MD5_body(ARCH_WORD_32 x1[15], ARCH_WORD_32 x2[15], ARCH_WORD_32 out1[4], ARCH_WORD_32 out2[4]);
+#endif
 #define ALGORITHM_NAME_X86		"64x2 (MD5_body)"
-void MD5_body(ARCH_WORD_32 x1[15], ARCH_WORD_32 x2[15], ARCH_WORD_32 out1[4], ARCH_WORD_32 out2[4]);
 #define DoMD5(A,L,C) do{if(!force_md5_ctx&&(L[0])<55&&(L[1])<55) {A.x1.b[L[0]]=0x80;A.x2.b2[L[1]]=0x80;A.x1.w[14]=(L[0]<<3);A.x2.w2[14]=(L[1]<<3);MD5_swap(A.x1.w,A.x1.w,(L[0]+4)>>2);MD5_swap(A.x2.w2,A.x2.w2,(L[1]+4)>>2);MD5_body(A.x1.w,A.x2.w2,C.x1.w,C.x2.w2);MD5_swap2(C.x1.w,C.x2.w2,C.x1.w,C.x2.w2,4);} else {MD5_CTX ctx; MD5_Init(&ctx); MD5_Update(&ctx,A.x1.b,L[0]); MD5_Final((unsigned char *)(C.x1.b),&ctx); MD5_Init(&ctx); MD5_Update(&ctx,A.x2.b2,L[1]); MD5_Final((unsigned char *)(C.x2.b2),&ctx);} }while(0)
 #define DoMD5o(A,L,C) do{if((L[0])<55&&(L[1])<55) {MD5_body(A.x1.w,A.x2.w2,C.x1.w,C.x2.w2);} else {MD5_CTX ctx; MD5_Init(&ctx); MD5_Update(&ctx,A.x1.b,L[0]); MD5_Final((unsigned char *)(C.x1.b),&ctx); MD5_Init(&ctx); MD5_Update(&ctx,A.x2.b2,L[1]); MD5_Final((unsigned char *)(C.x2.b2),&ctx);} }while(0)
 #define DoMD5a(A,L,C) do{MD5_body(A->x1.w,A->x2.w2,C->x1.w,C->x2.w2);}while(0)
 #define DoMD5a2(A,L,C,D) do{MD5_body(A->x1.w,A->x2.w2,tmpOut.x1.w,tmpOut.x2.w2);MD5_swap(C->x1.w,C->x1.w,(D[0]+21)>>2);MD5_swap(C->x2.w2,C->x2.w2,(D[1]+21)>>2);MD5_swap(tmpOut.x1.w,tmpOut.x1.w,4);MD5_swap(tmpOut.x2.w2,tmpOut.x2.w2,4);memcpy(&(C->x1.b[D[0]]),tmpOut.x1.b,16);memcpy(&(C->x2.b2[D[1]]),tmpOut.x2.b2,16);MD5_swap(C->x1.w,C->x1.w,(D[0]+21)>>2);MD5_swap(C->x2.w2,C->x2.w2,(D[1]+21)>>2);}while(0)
 #else
-#define ALGORITHM_NAME_X86		"128x1 (MD5_body)"
+#if defined(_OPENMP) && !MD5_ASM
+#define MD5_body(x, out) \
+	MD5_body_for_thread(0, x, out)
+extern void MD5_body_for_thread(int t, MD5_word x[15],MD5_word out[4]);
+#else
 extern void MD5_body(MD5_word x[15],MD5_word out[4]);
+#endif
+#define ALGORITHM_NAME_X86		"128x1 (MD5_body)"
 #define DoMD5(A,L,C) do{if(!force_md5_ctx&&(L)<55) {A.x1.b[L]=0x80;A.x1.w[14]=(L<<3);MD5_swap(A.x1.w,A.x1.w,((L+4)>>2));MD5_body(A.x1.w,C.x1.w);MD5_swap(C.x1.w,C.x1.w,4);} else {MD5_CTX ctx; MD5_Init(&ctx); MD5_Update(&ctx,A.x1.b,L); MD5_Final((unsigned char *)(C.x1.b),&ctx); } }while(0)
 #define DoMD5o(A,L,C) do{if((L)<55) {MD5_body(A.x1.w,C.x1.w);} else {MD5_CTX ctx; MD5_Init(&ctx); MD5_Update(&ctx,A.x1.b,L); MD5_Final((unsigned char *)(C.x1.b),&ctx); } }while(0)
 #define DoMD5a(A,L,C) do{MD5_body(A->x1.w,C->x1.w);}while(0)
-- 
1.7.5.4

