From 3bde4d0fdd35fd55991ac09904e135a04e515a33 Mon Sep 17 00:00:00 2001
From: magnum <magnum>
Date: Wed, 12 Oct 2011 10:38:18 +0200
Subject: [PATCH] j7: sapB OMP performance scaling

---
 src/sapB_fmt_plug.c |   27 ++++++++++++++-------------
 1 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/src/sapB_fmt_plug.c b/src/sapB_fmt_plug.c
index 4b61616..89c8f4a 100644
--- a/src/sapB_fmt_plug.c
+++ b/src/sapB_fmt_plug.c
@@ -123,28 +123,18 @@ static inline unsigned int calcActualSaltSize_B(char* theSalt)
 static void sapbcode_set_salt(void *salt)
 {
 	int i;
-	char *theSalt = salt;
-	//username: theSalt (we have to determine the right length...)
 	strlenUN = calcActualSaltSize_B(salt);
 
 	//transform...
 	for (i=0; i<strlenUN; i++)
-		unConverted[i] = transtable[ARCH_INDEX(theSalt[i])];
-	unConverted[i]='\0';
+		unConverted[i] = transtable[ARCH_INDEX(((char*)salt)[i])];
+	unConverted[i] = 0;
 }
 
 static void sapbcode_set_key(char *key, int index)
 {
-	int i;
-
 	strnzcpy(saved_key[index], key, PLAINTEXT_LENGTH+1);
-	enc_strupper(saved_key[index]); //only UPPERCASE passwords accepted for BCODE
-
-	strlenPW[index]=strlen(saved_key[index]);
-
-	for (i=0; i<strlenPW[index]; i++)
-		pwConverted[index][i] = transtable[ARCH_INDEX(saved_key[index][i])];
-	pwConverted[index][i]='\0';
+	strlenPW[index] = -1;
 }
 
 static char *sapbcode_get_key(int index) {
@@ -188,12 +178,23 @@ static void sapbcode_crypt_all(int count) {
 		int I4;
 		MD5_CTX ctx;
 
+		if (strlenPW[index] < 0) {
+			enc_strupper(saved_key[index]); //only UPPERCASE passwords accepted for BCODE
+
+			strlenPW[index] = strlen(saved_key[index]);
+
+			for (i = 0; i < strlenPW[index]; i++)
+				pwConverted[index][i] = transtable[ARCH_INDEX(saved_key[index][i])];
+			pwConverted[index][i] = 0;
+		}
+
 		MD5_Init(&ctx);
 		MD5_Update(&ctx, pwConverted[index], strlenPW[index]);
 		MD5_Update(&ctx, unConverted, strlenUN);
 		MD5_Final(temp_key,&ctx);
 
 		//some magic in between....yes, #4 is ignored...
+		//sum20 will be between 0x20 and 0x2F
 		sum20 = temp_key[5]%4 + temp_key[3]%4 + temp_key[2]%4 + temp_key[1]%4 + temp_key[0]%4 + 0x20;
 
 #define DEFAULT_OFFSET 15
-- 
1.7.4.1

