Openwall GNU/*/Linux - a small security-enhanced Linux distro for servers
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date: Fri, 31 May 2013 09:18:26 -0300
From: Claudio André <claudioandre.br@...il.com>
To: john-dev@...ts.openwall.com
Subject: Re: Unify internal form of mscash2 hashes?

On 30-05-2013 14:57, Claudio André wrote:
> On 29-05-2013 22:10, magnum wrote:
>> On 30 May, 2013, at 2:47 , "jfoug" <jfoug@....net> wrote:
>>
>>> From: magnum Sent: Wednesday, May 29, 2013 18:01
>>>> If I replace those three functions with the CPU versions, problem goes
>>> away.
> In my TODO list, i was planning something much simpler (example
> attached). Just put these functions on a new header file.

The idea is to do something like this:
- move everything common to something shared (format ID, ROUNDS-*,
cipherlenght).
- use it.

PS: it is not a tested patch, but works on CPU.

Claudio


diff --git a/src/cryptsha512_fmt_plug.c b/src/cryptsha512_fmt_plug.c
index afd69f6..b44453a 100644
--- a/src/cryptsha512_fmt_plug.c
+++ b/src/cryptsha512_fmt_plug.c
@@ -25,18 +25,14 @@
 #endif
 
 #define FORMAT_LABEL			"sha512crypt"
-#define FORMAT_NAME			"sha512crypt"
+#define FORMAT_NAME			FORMAT_ID
 #if ARCH_BITS >= 64
 #define ALGORITHM_NAME			"64/" ARCH_BITS_STR " " SHA2_LIB
 #else
 #define ALGORITHM_NAME			"32/" ARCH_BITS_STR " " SHA2_LIB
 #endif
 
-#define BENCHMARK_COMMENT		" (rounds=5000)"
-#define BENCHMARK_LENGTH		-1
-
 #define PLAINTEXT_LENGTH		125
-#define CIPHERTEXT_LENGTH		86
 
 #define BINARY_SIZE			64
 #define BINARY_ALIGN			4
@@ -58,16 +54,6 @@ static struct fmt_tests tests[] = {
 	{NULL}
 };
 
-/* Prefix for optional rounds specification.  */
-static const char sha512_rounds_prefix[] = "rounds=";
-
-/* Default number of rounds if not explicitly specified.  */
-#define ROUNDS_DEFAULT 5000
-/* Minimum number of rounds.  */
-#define ROUNDS_MIN 1	/* Drepper has it as 1000 */
-/* Maximum number of rounds.  */
-#define ROUNDS_MAX 999999999
-
 static int (*saved_key_length);
 static char (*saved_key)[PLAINTEXT_LENGTH + 1];
 static ARCH_WORD_32 (*crypt_out)[BINARY_SIZE / sizeof(ARCH_WORD_32)];
@@ -269,9 +255,9 @@ static void *get_salt(char *ciphertext)
 
 	out.rounds = ROUNDS_DEFAULT;
 	ciphertext += 3;
-	if (!strncmp(ciphertext, sha512_rounds_prefix,
-	             sizeof(sha512_rounds_prefix) - 1)) {
-		const char *num = ciphertext + sizeof(sha512_rounds_prefix) - 1;
+	if (!strncmp(ciphertext, ROUNDS_PREFIX,
+	             sizeof(ROUNDS_PREFIX) - 1)) {
+		const char *num = ciphertext + sizeof(ROUNDS_PREFIX) - 1;
 		char *endp;
 		unsigned long int srounds = strtoul(num, &endp, 10);
 		if (*endp == '$')
diff --git a/src/cryptsha512_valid.h b/src/cryptsha512_valid.h
index c9484a4..6e6d254 100644
--- a/src/cryptsha512_valid.h
+++ b/src/cryptsha512_valid.h
@@ -8,9 +8,20 @@
  * There's ABSOLUTELY NO WARRANTY, express or implied.
  */
 
-/* ------ Contains (at least) prepare(), valid() and split() ------ */
+/* Prefix for optional rounds specification.			*/
+#define ROUNDS_PREFIX          "rounds="
+/* Default number of rounds if not explicitly specified.	*/
+#define ROUNDS_DEFAULT		5000
+/* Minimum number of rounds. Drepper has it as 1000.		*/
+#define ROUNDS_MIN		1 
+/* Maximum number of rounds.					*/
+#define ROUNDS_MAX		999999999
 
-#define ROUNDS_PREFIX           "rounds="
+#define FORMAT_ID		"sha512crypt"
+#define CIPHERTEXT_LENGTH	86
+
+#define BENCHMARK_COMMENT	" (rounds=5000)"
+#define BENCHMARK_LENGTH	-1
 
 /* ------- Check if the ciphertext if a valid SHA-512 crypt ------- */
 static int valid(char * ciphertext, struct fmt_main * self) {
diff --git a/src/cuda_cryptsha512_fmt.c b/src/cuda_cryptsha512_fmt.c
index 5e672d8..19ea1b0 100644
--- a/src/cuda_cryptsha512_fmt.c
+++ b/src/cuda_cryptsha512_fmt.c
@@ -12,19 +12,14 @@
 #include "cuda_common.h"
 
 #define FORMAT_LABEL		"sha512crypt-cuda"
-#define FORMAT_NAME		"sha512crypt"
+#define FORMAT_NAME		FORMAT_ID
 
 #define ALGORITHM_NAME		"CUDA"
 
-#define BENCHMARK_COMMENT	" (rounds=5000)"
-#define BENCHMARK_LENGTH	-1
-
 #define PLAINTEXT_LENGTH	15
-#define CIPHERTEXT_LENGTH	34
 #define BINARY_SIZE		(3+16+86)
 #define MD5_DIGEST_LENGTH 	16
 
-
 #define SALT_SIZE		(3+7+9+16)
 
 #define MIN_KEYS_PER_CRYPT	THREADS
@@ -78,96 +73,12 @@ static void init(struct fmt_main *self)
   cuda_init(cuda_gpu_id);
 }
 
-static int valid(char *ciphertext,struct fmt_main *self)
-{
-	uint32_t i, j;
-	int len = strlen(ciphertext);
-	char *p;
-
-	if (strncmp(ciphertext, "$6$", 3) != 0)
-		return 0;
-	p = strrchr(ciphertext, '$');
-	if (p == NULL)
-		return 0;
-	for (i = p - ciphertext + 1; i < len; i++) {
-		int found = 0;
-		for (j = 0; j < 64; j++)
-			if (itoa64[j] == ARCH_INDEX(ciphertext[i]))
-				found = 1;
-		if (found == 0) {
-			puts("not found");
-			return 0;
-		}
-	}
-	if (len - (p - ciphertext + 1) != 86)
-		return 0;
-	return 1;
-};
-
 static int findb64(char c)
 {
 	int ret = ARCH_INDEX(atoi64[(uint8_t) c]);
 	return ret != 0x7f ? ret : 0;
 }
 
-static void magic(char *crypt, unsigned char *alt)
-{
-
-#define _24bit_from_b64(I,B2,B1,B0) \
-  {\
-      uint8_t c1,c2,c3,c4,b0,b1,b2;\
-      uint32_t w;\
-      c1=findb64(crypt[I+0]);\
-      c2=findb64(crypt[I+1]);\
-      c3=findb64(crypt[I+2]);\
-      c4=findb64(crypt[I+3]);\
-      w=c4<<18|c3<<12|c2<<6|c1;\
-      b2=w&0xff;w>>=8;\
-      b1=w&0xff;w>>=8;\
-      b0=w&0xff;w>>=8;\
-      alt[B2]=b0;\
-      alt[B1]=b1;\
-      alt[B0]=b2;\
-  }
-	uint32_t w;
-	_24bit_from_b64(0, 0, 21, 42);
-	_24bit_from_b64(4, 22, 43, 1);
-	_24bit_from_b64(8, 44, 2, 23);
-	_24bit_from_b64(12, 3, 24, 45);
-	_24bit_from_b64(16, 25, 46, 4);
-	_24bit_from_b64(20, 47, 5, 26);
-	_24bit_from_b64(24, 6, 27, 48);
-	_24bit_from_b64(28, 28, 49, 7);
-	_24bit_from_b64(32, 50, 8, 29);
-	_24bit_from_b64(36, 9, 30, 51);
-	_24bit_from_b64(40, 31, 52, 10);
-	_24bit_from_b64(44, 53, 11, 32);
-	_24bit_from_b64(48, 12, 33, 54);
-	_24bit_from_b64(52, 34, 55, 13);
-	_24bit_from_b64(56, 56, 14, 35);
-	_24bit_from_b64(60, 15, 36, 57);
-	_24bit_from_b64(64, 37, 58, 16);
-	_24bit_from_b64(68, 59, 17, 38);
-	_24bit_from_b64(72, 18, 39, 60);
-	_24bit_from_b64(76, 40, 61, 19);
-	_24bit_from_b64(80, 62, 20, 41);
-
-	w = findb64(crypt[85]) << 6 | findb64(crypt[84]) << 0;
-	alt[63] = (w & 0xff);
-}
-
-
-static void *binary(char *ciphertext)
-{
-	static unsigned char b[BINARY_SIZE];
-	char *p = strrchr(ciphertext, '$');
-	memset(b, 0, BINARY_SIZE);
-	if(p!=NULL)
-	  magic(p+1, b);
-	return (void *) b;
-}
-
-
 static void *salt(char *ciphertext)
 {
 	int end = 0, i, len = strlen(ciphertext);
@@ -359,7 +270,7 @@ struct fmt_main fmt_cuda_cryptsha512 = {
 		fmt_default_prepare,
 		valid,
 		fmt_default_split,
-		binary,
+		get_binary,
 		salt,
 		fmt_default_source,
 		{
diff --git a/src/opencl_cryptsha512.h b/src/opencl_cryptsha512.h
index 796b613..a4fa463 100644
--- a/src/opencl_cryptsha512.h
+++ b/src/opencl_cryptsha512.h
@@ -17,15 +17,9 @@
 #include "opencl_device_info.h"
 #include "opencl_sha512.h"
 
-//Constants.
-#define ROUNDS_DEFAULT          5000
-#define ROUNDS_MIN              1	/* Drepper has it as 1000 */
-#define ROUNDS_MAX              999999999
-
 #define SALT_LENGTH             16
 #define SALT_ALIGN              4
 #define PLAINTEXT_LENGTH        24
-#define CIPHERTEXT_LENGTH	86
 #define BUFFER_ARRAY            8
 #define SALT_ARRAY              (SALT_LENGTH / 8)
 #define PLAINTEXT_ARRAY         (PLAINTEXT_LENGTH / 8)
@@ -84,4 +78,4 @@ typedef struct {
 };
 #endif
 
-#endif  /* _CRYPTSHA512_H */
\ No newline at end of file
+#endif  /* _CRYPTSHA512_H */
diff --git a/src/opencl_cryptsha512_fmt.c b/src/opencl_cryptsha512_fmt.c
index ff5180c..6809d69 100644
--- a/src/opencl_cryptsha512_fmt.c
+++ b/src/opencl_cryptsha512_fmt.c
@@ -21,12 +21,9 @@
 #include "cryptsha512_valid.h"
 
 #define FORMAT_LABEL			"sha512crypt-opencl"
-#define FORMAT_NAME			"sha512crypt"
+#define FORMAT_NAME			FORMAT_ID
 #define ALGORITHM_NAME			"OpenCL"
 
-#define BENCHMARK_COMMENT		" (rounds=5000)"
-#define BENCHMARK_LENGTH		-1
-
 #define CONFIG_NAME			"sha512crypt"
 
 //Checks for source code to pick (parameters, sizes, kernels to execute, etc.)

Powered by blists - more mailing lists

Your e-mail address:

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