Openwall GNU/*/Linux - a small security-enhanced Linux distro for servers
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date: Sat, 7 Jul 2012 11:18:05 +0400
From: Solar Designer <solar@...nwall.com>
To: john-dev@...ts.openwall.com
Subject: RAdmin, SIP speedup

Dhiru, Jim, magnum -

The attached patch implements an equivalent of Dhiru's RAdmin format as
a dynamic format, optimizes a few things in the standalone RAdmin format
(still meaningful due to OpenMP), and fixes the poor performance of the
SIP format in non-OpenMP builds.

Jim - by the way, if I remove the "Func=DynamicFunc__clean_input" line,
I get not only a meaningful error message, but also a segfault.  You
could want to investigate this.

RAdmin speed before changes:

Benchmarking: RAdmin v2.x MD5 [32/64]... DONE
Raw:    3054K c/s real, 3054K c/s virtual

After:

Benchmarking: RAdmin v2.x MD5 [32/64]... DONE
Raw:    3401K c/s real, 3401K c/s virtual

Dynamic is slightly faster:

Benchmarking: dynamic_1010 dynamic_1010: RAdmin v2.x MD5 [32/64 64x2 (MD5_Body)]... DONE
Raw:    3526K c/s real, 3526K c/s virtual

However, RAadmin with OpenMP is faster yet:

Benchmarking: RAdmin v2.x MD5 [32/64]... (8xOMP) DONE
Raw:    10754K c/s real, 1344K c/s virtual

SIP speed before changes:

Benchmarking: SIP MD5 [32/64]... DONE
Raw:    302458 c/s real, 305483 c/s virtual

After:

Benchmarking: SIP MD5 [32/64]... DONE
Raw:    1665K c/s real, 1665K c/s virtual

OpenMP (unchanged with this patch):

Benchmarking: SIP MD5 [32/64]... (8xOMP) DONE
Raw:    9044K c/s real, 1130K c/s virtual

These are on bull.

Of course, there's lots of room for optimization and code cleanups, but
this is not my code and I am only making easy and obvious changes to it.

Alexander

diff --git a/run/dynamic.conf b/run/dynamic.conf
index ab06d8f..f13cc3a 100644
--- a/run/dynamic.conf
+++ b/run/dynamic.conf
@@ -220,3 +220,17 @@ Func=DynamicFunc__append_salt
 Func=DynamicFunc__append_keys
 Func=DynamicFunc__crypt_md5
 Test=$dynamic_1009$0b9b9fdf75fc79d85c5b69aa1de26288$Salt:test1
+
+[List.Generic:dynamic_1010]
+Expression=dynamic_1010: RAdmin v2.x MD5
+Flag=MGF_NOTSSE2Safe
+Func=DynamicFunc__clean_input
+Func=DynamicFunc__append_keys
+Func=DynamicFunc__set_input_len_100
+Func=DynamicFunc__crypt_md5
+Test=$dynamic_1010$B137F09CF92F465CABCA06AB1B283C1F:lastwolf
+Test=$dynamic_1010$14e897b1a9354f875df51047bb1a0765:podebradka
+Test=$dynamic_1010$02ba5e187e2589be6f80da0046aa7e3c:12345678
+Test=$dynamic_1010$b4e13c7149ebde51e510959f30319ac7:firebaLL
+Test=$dynamic_1010$3d2c8cae4621edf8abb081408569482b:yamaha12345
+Test=$dynamic_1010$60cb8e411b02c10ecc3c98e29e830de8:xplicit
diff --git a/src/dynamic.h b/src/dynamic.h
index 3738986..7505724 100644
--- a/src/dynamic.h
+++ b/src/dynamic.h
@@ -155,6 +155,7 @@ extern void DynamicFunc__append_salt();
 extern void DynamicFunc__set_input_len_16();
 extern void DynamicFunc__set_input_len_32();
 extern void DynamicFunc__set_input_len_64();
+extern void DynamicFunc__set_input_len_100();
 
 extern void DynamicFunc__clean_input2();
 extern void DynamicFunc__clean_input2_kwik();
diff --git a/src/dynamic_fmt.c b/src/dynamic_fmt.c
index b43ab61..1d92a64 100644
--- a/src/dynamic_fmt.c
+++ b/src/dynamic_fmt.c
@@ -3864,6 +3864,21 @@ void DynamicFunc__set_input_len_64()
 		total_len_X86[j] = 64;
 	}
 }
+
+void DynamicFunc__set_input_len_100()
+{
+	unsigned j;
+#ifdef MMX_COEF
+	if (dynamic_use_sse==1) {
+		exit(!!fprintf(stderr, "Error, in your DYNAMIC script.\nIt is NOT valid to call DynamicFunc__set_input_len_100 in SSE2/MMX mode\n"));
+	}
+#endif
+	for (j = 0; j < m_count; ++j)
+	{
+		total_len_X86[j] = 100;
+	}
+}
+
 void DynamicFunc__set_input2_len_64()
 {
 	unsigned j;
diff --git a/src/dynamic_parser.c b/src/dynamic_parser.c
index a3793bb..089f500 100644
--- a/src/dynamic_parser.c
+++ b/src/dynamic_parser.c
@@ -136,6 +136,7 @@ static MD5Gen_Predicate_t MD5Gen_Predicate[] =  {
 	{ "DynamicFunc__set_input_len_16", DynamicFunc__set_input_len_16},
 	{ "DynamicFunc__set_input2_len_16", DynamicFunc__set_input2_len_16},
 	{ "DynamicFunc__set_input_len_64", DynamicFunc__set_input_len_64 },
+	{ "DynamicFunc__set_input_len_100", DynamicFunc__set_input_len_100 },
 	{ "DynamicFunc__set_input2_len_64", DynamicFunc__set_input2_len_64 },
 	{ "DynamicFunc__overwrite_salt_to_input1_no_size_fix", DynamicFunc__overwrite_salt_to_input1_no_size_fix },
 	{ "DynamicFunc__overwrite_salt_to_input2_no_size_fix", DynamicFunc__overwrite_salt_to_input2_no_size_fix },
diff --git a/src/radmin_fmt_plug.c b/src/radmin_fmt_plug.c
index d41b7a4..f59f2de 100644
--- a/src/radmin_fmt_plug.c
+++ b/src/radmin_fmt_plug.c
@@ -20,7 +20,7 @@
 #include "options.h"
 #ifdef _OPENMP
 #include <omp.h>
-#define OMP_SCALE               64
+#define OMP_SCALE               1
 #endif
 
 #define FORMAT_LABEL		"radmin"
@@ -28,12 +28,12 @@
 #define ALGORITHM_NAME		"32/" ARCH_BITS_STR
 #define BENCHMARK_COMMENT	""
 #define BENCHMARK_LENGTH	-1
-#define PLAINTEXT_LENGTH	32
+#define PLAINTEXT_LENGTH	100
 #define CIPHERTEXT_LENGTH	32
 #define BINARY_SIZE		16
 #define SALT_SIZE		0
 #define MIN_KEYS_PER_CRYPT	1
-#define MAX_KEYS_PER_CRYPT	1
+#define MAX_KEYS_PER_CRYPT	64
 
 static struct fmt_tests radmin_tests[] = {
 	{"$radmin2$B137F09CF92F465CABCA06AB1B283C1F", "lastwolf"},
@@ -45,7 +45,7 @@ static struct fmt_tests radmin_tests[] = {
 	{NULL}
 };
 
-static char (*saved_key)[PLAINTEXT_LENGTH + 1];
+static char (*saved_key)[PLAINTEXT_LENGTH];
 static ARCH_WORD_32 (*crypt_out)[8];
 
 static void init(struct fmt_main *pFmt)
@@ -108,25 +108,21 @@ static void crypt_all(int count)
 	int index = 0;
 #ifdef _OPENMP
 #pragma omp parallel for
-	for (index = 0; index < count; index++)
 #endif
+	for (index = 0; index < count; index++)
 	{
-		unsigned char input[100] = { 0 };
 		MD5_CTX ctx;
 		MD5_Init(&ctx);
-		strcpy((char*)input, (const char*)saved_key[index]);
-		MD5_Update(&ctx, input, 100);
+		MD5_Update(&ctx, saved_key[index], sizeof(saved_key[index]));
 		MD5_Final((unsigned char *)crypt_out[index], &ctx);
 	}
 }
 
 static int cmp_all(void *binary, int count)
 {
-	int index = 0;
-#ifdef _OPENMP
-	for (; index < count; index++)
-#endif
-		if (!memcmp(binary, crypt_out[index], BINARY_SIZE))
+	int index;
+	for (index = 0; index < count; index++)
+		if (*(ARCH_WORD_32 *)binary == crypt_out[index][0])
 			return 1;
 	return 0;
 }
@@ -143,16 +139,16 @@ static int cmp_exact(char *source, int index)
 
 static void radmin_set_key(char *key, int index)
 {
-	int saved_key_length = strlen(key);
-	if (saved_key_length > PLAINTEXT_LENGTH)
-		saved_key_length = PLAINTEXT_LENGTH;
-	memcpy(saved_key[index], key, saved_key_length);
-	saved_key[index][saved_key_length] = 0;
+	/* NUL padding is intentional */
+	strncpy(saved_key[index], key, sizeof(saved_key[index]));
 }
 
 static char *get_key(int index)
 {
-	return saved_key[index];
+	static char out[PLAINTEXT_LENGTH + 1];
+	memcpy(out, saved_key[index], PLAINTEXT_LENGTH);
+	out[PLAINTEXT_LENGTH] = 0;
+	return out;
 }
 
 struct fmt_main radmin_fmt = {
diff --git a/src/sip_fmt_plug.c b/src/sip_fmt_plug.c
index 2c93fce..e13d122 100644
--- a/src/sip_fmt_plug.c
+++ b/src/sip_fmt_plug.c
@@ -21,7 +21,7 @@
 #include "sip_fmt_plug.h"
 #ifdef _OPENMP
 #include <omp.h>
-#define OMP_SCALE               64
+#define OMP_SCALE		1
 #endif
 
 #ifdef _MSC_VER
@@ -38,7 +38,7 @@
 #define BINARY_SIZE		16
 #define SALT_SIZE		256
 #define MIN_KEYS_PER_CRYPT	1
-#define MAX_KEYS_PER_CRYPT	1
+#define MAX_KEYS_PER_CRYPT	64
 
 static struct fmt_tests sip_tests[] = {
 /* XXX: need more test vectors, then try benchmarking for "many salts" */
@@ -57,7 +57,7 @@ static login_t *login = NULL;
 
 static void init(struct fmt_main *pFmt)
 {
-#if defined (_OPENMP)
+#ifdef _OPENMP
 	omp_t = omp_get_max_threads();
 	pFmt->params.min_keys_per_crypt *= omp_t;
 	omp_t *= OMP_SCALE;
@@ -157,9 +157,8 @@ static void crypt_all(int count)
 	int index = 0;
 #ifdef _OPENMP
 #pragma omp parallel for
-	for (index = 0; index < count; index++)
 #endif
-	{
+	for (index = 0; index < count; index++) {
 		/* password */
 		MD5_CTX md5_ctx;
 		unsigned char md5_bin_hash[MD5_LEN];

Powered by blists - more mailing lists

Your e-mail address:

Powered by Openwall GNU/*/Linux - Powered by OpenVZ