Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 122435
Collapse All | Expand All

(-)john-1.7.0.1/doc/JOHN-BIGPATCH-FAQ (+54 lines)
Line 0 Link Here
1
2
Q: What's this?
3
A: It's a patch to Solar Designer's "john the ripper" password cracker.
4
5
Q: What's it good for, then?
6
A: It enables cracking of many different hashes. The list includes:
7
	- Kerberos AFS DES
8
	- Eggdrop Blowfish
9
	- OpenBSD Blowfish
10
	- BSDI DES
11
	- Traditional DES
12
	- NT LM DES
13
	- Lotus V5 web password
14
	- Apache MD5
15
	- FreeBSD MD5
16
	- MS Cache Hash
17
	- MYSQL
18
	- Netscape LDAP SHA
19
	- NTHASH (md4)
20
	- Raw MD5
21
	- Raw SHA1
22
	- Oracle
23
24
Q: Who made this?
25
A: The original patches are from the /contrib/ directory of john the ripper.
26
Their respective authors are shown on the john page, except:
27
	- Domino v5 by Jeff Fay
28
	- mscash, raw-md5, raw-sha1, hmac-md5, oracle 
29
	by Bartavelle@bandecon.com
30
31
Q: How do I install it?
32
A: I assume you are able to install john from a source distribution,
33
   if you are not, PLEASE read john's documentation before e-mailing me. 
34
   To install run 'gunzip -c john-1.6.37-bigpatch.x.ge | patch -p0' from the
35
   directory containing john   and then run 'make (your-system-type-here)' to 
36
   build john.
37
38
Q: NT hash support is broken!
39
A: NT hash support works with file whose format is:
40
USERNAME:$NT$A04B60AC43771EB386B94FEBAC779BBC
41
if your file looks that way:
42
USERNAME:A04B60AC43771EB386B94FEBAC779BBC
43
use the "-format:NT" option.
44
45
Q: It doesn't work!
46
A: This big patch has not been extensively tested. It should work most of the
47
time on all architectures. Please send all questions to bartavelle@bandecon.com
48
49
Thanks to:
50
Solar Designer for john and the advises
51
Arnaud Pilon for the MS Cash algorithm and the CacheDump tool
52
Moof (from thinko.net) for the macintosh shell
53
HP for their testdrive systems, and the fact they allow me to use john on their
54
servers.
(-)john-1.7.0.1/doc/JOHN-NTLM-FAQ (+29 lines)
Line 0 Link Here
1
2
Q: What's this?
3
A: It's a patch to Solar Designer's "john the ripper" password cracker.
4
5
Q: What's it good for, then?
6
A: It enables cracking of Windows NT/2000 MD4 (case-sensitive) password hashes.
7
8
Q: Who made this?
9
A: This patch was thrown together on a boring Sunday by Olle Segerdahl.
10
   It uses Andrew Tridgell's NTLM and MD4 code stolen from samba-2.0.7 .
11
12
Q: How do I install it?
13
A: I assume you are able to install john from a source distribution,
14
   if you are not, PLEASE read john's documentation before e-mailing me. 
15
   To install run 'patch < john-ntlm-v02.diff' from the john "src" directory
16
   and then run 'make (your-system-type-here)' to build john.
17
18
Q: How do I use john to crack NT password hashes?
19
A: Use pwdump2 or L0phtcrack to dump the password hashes into a file,
20
   then run 'john pwfile -format:NT' to start cracking!
21
22
Q: I get all kinds of compile errors!
23
A: This patch was made against john-1.6.36, lots of stuff might have broken
24
   source compatibility since then... Use something closer to john-1.6.36.
25
26
Q: I have a question not covered by this FAQ!
27
A: Make sure you have read all there is to read about john, then
28
   mail me at olle@nxs.se with "JOHN-NTLM" in the subject.
29
(-)john-1.7.0.1/run/john.conf.rej (+15 lines)
Line 0 Link Here
1
***************
2
*** 1,6 ****
3
  #
4
  # This file is part of John the Ripper password cracker,
5
- # Copyright (c) 1996-2004 by Solar Designer
6
  #
7
  
8
  [Options]
9
--- 1,6 ----
10
  #
11
  # This file is part of John the Ripper password cracker,
12
+ # Copyright (c) 1996-2003 by Solar Designer
13
  #
14
  
15
  [Options]
(-)john-1.7.0.1/src/BFEgg_fmt.c (+125 lines)
Line 0 Link Here
1
/*
2
 * This file is part of Eggdrop blowfish patch for John The Ripper.
3
 * Copyright (c) 2002 by Sun-Zero <sun-zero@freemail.hu>
4
 * This is a free software distributable under terms of the GNU GPL. 
5
 */
6
7
#include <string.h>
8
9
#include "misc.h"
10
#include "formats.h"
11
#include "common.h"
12
#include "blowfish.c"
13
14
#define FORMAT_LABEL			"bfegg"
15
#define FORMAT_NAME			"Eggdrop"
16
#define ALG_NAME			"blowfish"
17
18
#define BENCHMARK_COMMENT		""
19
#define BENCHMARK_LENGTH		-1
20
21
#define PLAINTEXT_LENGTH		31
22
#define CIPHERTEXT_LENGTH		33
23
24
#define BINARY_SIZE			13
25
#define SALT_SIZE			0
26
27
#define MIN_KEYS_PER_CRYPT		1
28
#define MAX_KEYS_PER_CRYPT		1
29
30
static struct fmt_tests tests[] = {
31
    {"+9F93o1OxwgK1", "123456"},
32
    {"+C/.8o.Wuph9.", "qwerty"},
33
    {"+EEHgy/MBLDd0", "walkman"},
34
    {"+vPBrs07OTXE/", "tesztuser"},
35
    {"+zIvO/1nDsd9.", "654321"},
36
    {NULL}
37
};
38
39
int zerolengthkey = 0;
40
41
static char crypt_key[BINARY_SIZE + 1]; //changed by bartavelle so that it works on alpha
42
static char saved_key[PLAINTEXT_LENGTH + 1];
43
44
static int valid(char *ciphertext) {
45
    if (strncmp(ciphertext, "+", 1) != 0) return 0;
46
    if (strlen(ciphertext) != 13) return 0;
47
    
48
    return 1;
49
}
50
51
void init() {
52
    blowfish_first_init();
53
}
54
55
56
static void set_key(char *key, int index) {
57
    strnzcpy(saved_key, key, PLAINTEXT_LENGTH+1);
58
}
59
60
static char *get_key(int index) {
61
  return saved_key;
62
}
63
64
static int cmp_all(void *binary, int index) {
65
  if (zerolengthkey) return 0;
66
  return !memcmp(binary, crypt_key, BINARY_SIZE);
67
}
68
69
static int cmp_exact(char *source, int index) {
70
  return 1;
71
}
72
73
static void set_salt(void *salt) { }
74
75
static void crypt_all(int count) {  
76
    if (saved_key[0] == '\0') {
77
	zerolengthkey = 1;
78
    } else {
79
	zerolengthkey = 0;
80
        blowfish_encrypt_pass(saved_key, crypt_key);
81
    }
82
}
83
84
struct fmt_main fmt_BFEgg = {
85
  {
86
    FORMAT_LABEL,
87
    FORMAT_NAME,
88
    ALG_NAME,
89
    BENCHMARK_COMMENT,
90
    BENCHMARK_LENGTH,
91
    PLAINTEXT_LENGTH,
92
    BINARY_SIZE,
93
    SALT_SIZE,
94
    MIN_KEYS_PER_CRYPT,
95
    MAX_KEYS_PER_CRYPT,
96
    FMT_CASE | FMT_8_BIT,
97
    tests
98
  }, {
99
    init,
100
    valid,
101
    fmt_default_split,
102
    fmt_default_binary,
103
    fmt_default_salt,
104
    {
105
	fmt_default_binary_hash,
106
	fmt_default_binary_hash,
107
	fmt_default_binary_hash,
108
    },
109
	fmt_default_salt_hash,
110
	set_salt,
111
	set_key,
112
	get_key,
113
	fmt_default_clear_keys,
114
	crypt_all, 
115
	{
116
	    fmt_default_get_hash,
117
	    fmt_default_get_hash,
118
	    fmt_default_get_hash,
119
	},
120
	    cmp_all,
121
	    cmp_all,
122
	    cmp_exact
123
  }
124
};
125
(-)john-1.7.0.1/src/MD5_apache_fmt.c (+201 lines)
Line 0 Link Here
1
/*
2
    Modified by Sun-Zero <sun-zero@freemail.hu>
3
    2004. 07. 26. 
4
    
5
    Now, its work with md5 hash of apache.
6
    The original john patch came from 
7
    http://lists.jammed.com/pen-test/2001/11/0134.html by
8
    Kostas Evangelinos (kos@bastard.net)
9
*/
10
11
/*
12
 * This file is part of John the Ripper password cracker,
13
 * Copyright (c) 1996-2001 by Solar Designer
14
 */
15
16
#include <string.h>
17
18
#include "arch.h"
19
#include "misc.h"
20
#include "MD5_std.h"
21
#include "common.h"
22
#include "formats.h"
23
24
#define FORMAT_LABEL			"md5a"
25
#define FORMAT_NAME			"Apache MD5"
26
27
#define BENCHMARK_COMMENT		""
28
#define BENCHMARK_LENGTH		-1
29
30
#define PLAINTEXT_LENGTH		15
31
#define CIPHERTEXT_LENGTH		22
32
33
#define BINARY_SIZE			4
34
#define SALT_SIZE			8
35
36
#define MIN_KEYS_PER_CRYPT		MD5_N
37
#define MAX_KEYS_PER_CRYPT		MD5_N
38
39
40
static struct fmt_tests tests[] = {
41
	{"$apr1$Q6ZYh...$RV6ft2bZ8j.NGrxLYaJt9.", "test"},
42
	{"$apr1$rBXqc...$NlXxN9myBOk95T0AyLAsJ0", "john"},
43
	{"$apr1$Grpld/..$qp5GyjwM2dnA5Cdej9b411", "the"},
44
	{"$apr1$GBx.D/..$yfVeeYFCIiEXInfRhBRpy/", "ripper"},
45
	{NULL}
46
};
47
48
static char saved_key[MD5_N][PLAINTEXT_LENGTH + 1];
49
50
static int valid(char *ciphertext)
51
{
52
	char *pos, *start;
53
54
	if (strncmp(ciphertext, "$apr1$", 6)) return 0;
55
56
        /* magic string */
57
        start = &ciphertext[1];
58
	for (pos = start; *pos && *pos != '$'; pos++);
59
    		if (!*pos || pos < start+1 || pos > start+MD5_MAGIC_LENGTH+1) 
60
		    return 0;
61
62
        /* salt */
63
        start = ++pos;
64
        for (pos = start; *pos && *pos != '$'; pos++);
65
    	    if (!*pos || pos < start || pos > start+8) 
66
		return 0;
67
68
69
	start = ++pos;
70
	while (atoi64[ARCH_INDEX(*pos)] != 0x7F) pos++;
71
	if (*pos || pos - start != CIPHERTEXT_LENGTH) return 0;
72
73
	if (atoi64[ARCH_INDEX(*(pos - 1))] & 0x3C) return 0;
74
75
	return 1;
76
}
77
78
static int binary_hash_0(void *binary)
79
{
80
	return *(MD5_word *)binary & 0xF;
81
}
82
83
static int binary_hash_1(void *binary)
84
{
85
	return *(MD5_word *)binary & 0xFF;
86
}
87
88
static int binary_hash_2(void *binary)
89
{
90
	return *(MD5_word *)binary & 0xFFF;
91
}
92
93
static int get_hash_0(int index)
94
{
95
	return MD5_out[index][0] & 0xF;
96
}
97
98
static int get_hash_1(int index)
99
{
100
	return MD5_out[index][0] & 0xFF;
101
}
102
103
static int get_hash_2(int index)
104
{
105
	return MD5_out[index][0] & 0xFFF;
106
}
107
108
static int salt_hash(void *salt)
109
{
110
	return
111
		((int)atoi64[ARCH_INDEX(((char *)salt)[0])] |
112
		((int)atoi64[ARCH_INDEX(((char *)salt)[1])] << 6)) & 0x3FF;
113
}
114
115
static void set_key(char *key, int index)
116
{
117
	MD5_std_set_key(key, index);
118
119
	strnfcpy(saved_key[index], key, PLAINTEXT_LENGTH);
120
}
121
122
static char *get_key(int index)
123
{
124
	saved_key[index][PLAINTEXT_LENGTH] = 0;
125
126
	return saved_key[index];
127
}
128
129
static int cmp_all(void *binary, int index)
130
{
131
132
#if MD5_X2
133
	return *(MD5_word *)binary == MD5_out[0][0] ||
134
		*(MD5_word *)binary == MD5_out[1][0];
135
#else
136
	return *(MD5_word *)binary == MD5_out[0][0];
137
#endif
138
}
139
140
141
static int cmp_exact(char *source, int index)
142
{
143
	return !memcmp(MD5_std_get_binary(source, MD5_TYPE_APACHE), MD5_out[index],
144
		sizeof(MD5_binary));
145
}
146
147
148
static void crypt_all(int count) {
149
    MD5_std_crypt(MD5_TYPE_APACHE);
150
}
151
152
static void *get_salt(char *ciphertext) {
153
    return MD5_std_get_salt(ciphertext, MD5_TYPE_APACHE);
154
}
155
156
static void *get_binary(char *ciphertext) {
157
    return MD5_std_get_binary(ciphertext, MD5_TYPE_APACHE);
158
}
159
160
161
struct fmt_main fmt_MD5_apache = {
162
	{
163
		FORMAT_LABEL,
164
		FORMAT_NAME,
165
		MD5_ALGORITHM_NAME,
166
		BENCHMARK_COMMENT,
167
		BENCHMARK_LENGTH,
168
		PLAINTEXT_LENGTH,
169
		BINARY_SIZE,
170
		SALT_SIZE,
171
		MIN_KEYS_PER_CRYPT,
172
		MAX_KEYS_PER_CRYPT,
173
		FMT_CASE | FMT_8_BIT,
174
		tests
175
	}, {
176
		MD5_std_init,
177
		valid,
178
		fmt_default_split,
179
		get_binary,		//(void *(*)(char *))MD5_std_get_binary,
180
		get_salt,  		//(void *(*)(char *))MD5_std_get_salt,
181
		{
182
			binary_hash_0,
183
			binary_hash_1,
184
			binary_hash_2
185
		},
186
		salt_hash,
187
		(void (*)(void *))MD5_std_set_salt,
188
		set_key,
189
		get_key,
190
		fmt_default_clear_keys,
191
		crypt_all,		//(void (*)(int))MD5_std_crypt,
192
		{
193
			get_hash_0,
194
			get_hash_1,
195
			get_hash_2
196
		},
197
		cmp_all,
198
		cmp_all,
199
		cmp_exact
200
	}
201
};
(-)john-1.7.0.1/src/MD5_fmt.c (-4 / +16 lines)
Lines 117-126 Link Here
117
117
118
static int cmp_exact(char *source, int index)
118
static int cmp_exact(char *source, int index)
119
{
119
{
120
	return !memcmp(MD5_std_get_binary(source), MD5_out[index],
120
	return !memcmp(MD5_std_get_binary(source, MD5_TYPE_STD), MD5_out[index],
121
		sizeof(MD5_binary));
121
		sizeof(MD5_binary));
122
}
122
}
123
123
124
static void crypt_all(int count) {
125
	MD5_std_crypt(MD5_TYPE_STD);
126
}
127
128
static void *get_salt(char *ciphertext) {
129
	return MD5_std_get_salt(ciphertext, MD5_TYPE_STD);
130
}
131
132
static void *get_binary(char *ciphertext) {
133
	return MD5_std_get_binary(ciphertext, MD5_TYPE_STD);
134
}
135
124
struct fmt_main fmt_MD5 = {
136
struct fmt_main fmt_MD5 = {
125
	{
137
	{
126
		FORMAT_LABEL,
138
		FORMAT_LABEL,
Lines 139-146 Link Here
139
		MD5_std_init,
151
		MD5_std_init,
140
		valid,
152
		valid,
141
		fmt_default_split,
153
		fmt_default_split,
142
		(void *(*)(char *))MD5_std_get_binary,
154
		get_binary,		/* (void *(*)(char *))MD5_std_get_binary, */
143
		(void *(*)(char *))MD5_std_get_salt,
155
		get_salt,		/* (void *(*)(char *))MD5_std_get_salt, */
144
		{
156
		{
145
			binary_hash_0,
157
			binary_hash_0,
146
			binary_hash_1,
158
			binary_hash_1,
Lines 151-157 Link Here
151
		set_key,
163
		set_key,
152
		get_key,
164
		get_key,
153
		fmt_default_clear_keys,
165
		fmt_default_clear_keys,
154
		(void (*)(int))MD5_std_crypt,
166
		crypt_all,		/* (void (*)(int))MD5_std_crypt, */
155
		{
167
		{
156
			get_hash_0,
168
			get_hash_0,
157
			get_hash_1,
169
			get_hash_1,
(-)john-1.7.0.1/src/MD5_std.c (-11 / +41 lines)
Lines 400-406 Link Here
400
	order[19][index].length = current->l.pp;
400
	order[19][index].length = current->l.pp;
401
}
401
}
402
402
403
void MD5_std_crypt(void)
403
void MD5_std_crypt(int md5_type)
404
{
404
{
405
	int length, index, mask;
405
	int length, index, mask;
406
	MD5_pattern *line;
406
	MD5_pattern *line;
Lines 483-493 Link Here
483
	for (index = 0, key = pool; index < MD5_N; index++, key++) {
483
	for (index = 0, key = pool; index < MD5_N; index++, key++) {
484
#endif
484
#endif
485
		memcpy(&block[index], key->o.p.b, key->l.p);
485
		memcpy(&block[index], key->o.p.b, key->l.p);
486
		memcpy(&block[index].b[key->l.p], "$1$", 3);
486
		if (md5_type == MD5_TYPE_APACHE) {
487
		memcpy(&block[index].b[key->l.p + 3], key->s, key->l.s);
487
			memcpy(&block[index].b[key->l.p], "$apr1$", 6);
488
		memcpy(&block[index].b[key->l.ps + 3],
488
			memcpy(&block[index].b[key->l.p + 6], key->s, key->l.s);
489
			MD5_out[index], key->l.p);
489
			memcpy(&block[index].b[key->l.ps + 6],
490
		length = key->l.psp + 3;
490
				MD5_out[index], key->l.p);
491
			length = key->l.psp + 6;
492
		} else {
493
			memcpy(&block[index].b[key->l.p], "$1$", 3);
494
			memcpy(&block[index].b[key->l.p + 3], key->s, key->l.s);
495
			memcpy(&block[index].b[key->l.ps + 3],
496
				MD5_out[index], key->l.p);
497
			length = key->l.psp + 3;
498
		}
491
		if ((mask = key->l.p))
499
		if ((mask = key->l.p))
492
		do {
500
		do {
493
			block[index].b[length++] =
501
			block[index].b[length++] =
Lines 853-865 Link Here
853
861
854
#endif
862
#endif
855
863
856
char *MD5_std_get_salt(char *ciphertext)
864
char *MD5_std_get_salt(char *ciphertext, int md5_type)
857
{
865
{
858
	static char out[9];
866
	static char out[9];
859
	int length;
867
	int length;
868
	char *pos;
869
	char *start;
870
871
	start = &ciphertext[1];
872
	if (md5_type == MD5_TYPE_APACHE) {
873
		for (pos = start; *pos && *pos != '$'; pos++);
874
		start = ++pos;
875
	}
860
876
861
	for (length = 0; length < 8; length++)
877
	for (length = 0; length < 8; length++) {
862
	if ((out[length] = ciphertext[3 + length]) == '$') break;
878
		if (md5_type == MD5_TYPE_APACHE) {
879
			if ((out[length] = start[length]) == '$') break;
880
		} else {
881
			if ((out[length] = ciphertext[3 + length]) == '$') break;
882
		}
883
	}
863
	out[length] = 0;
884
	out[length] = 0;
864
885
865
	return out;
886
	return out;
Lines 876-882 Link Here
876
	out.b[b2] = value >> 8; \
897
	out.b[b2] = value >> 8; \
877
	out.b[b3] = value;
898
	out.b[b3] = value;
878
899
879
MD5_word *MD5_std_get_binary(char *ciphertext)
900
MD5_word *MD5_std_get_binary(char *ciphertext, int md5_type)
880
{
901
{
881
	static union {
902
	static union {
882
		MD5_binary w;
903
		MD5_binary w;
Lines 885-891 Link Here
885
	char *pos;
906
	char *pos;
886
	MD5_word value;
907
	MD5_word value;
887
908
888
	pos = ciphertext + 3; while (*pos++ != '$');
909
	char *start;
910
	if (md5_type == MD5_TYPE_APACHE) {
911
		start = &ciphertext[1];
912
		for (pos = start; *pos && *pos != '$'; pos++);
913
		if (!*pos || pos < start+1 || pos > start+MD5_MAGIC_LENGTH+1) return 0;
914
		pos++;
915
		while (*pos++ != '$');
916
	} else {
917
		pos = ciphertext + 3; while (*pos++ != '$');
918
	}
889
919
890
	TO_BINARY(0, 6, 12);
920
	TO_BINARY(0, 6, 12);
891
	TO_BINARY(1, 7, 13);
921
	TO_BINARY(1, 7, 13);
(-)john-1.7.0.1/src/MD5_std.h (-3 / +8 lines)
Lines 13-18 Link Here
13
#include "arch.h"
13
#include "arch.h"
14
#include "common.h"
14
#include "common.h"
15
15
16
#define MD5_TYPE_STD			0
17
#define MD5_TYPE_APACHE			1
18
16
typedef ARCH_WORD_32 MD5_word;
19
typedef ARCH_WORD_32 MD5_word;
17
20
18
/*
21
/*
Lines 88-93 Link Here
88
#define MD5_ALGORITHM_NAME		"32/" ARCH_BITS_STR
91
#define MD5_ALGORITHM_NAME		"32/" ARCH_BITS_STR
89
#endif
92
#endif
90
93
94
#define MD5_MAGIC_LENGTH		10
95
91
/*
96
/*
92
 * Initializes the internal structures.
97
 * Initializes the internal structures.
93
 */
98
 */
Lines 107-122 Link Here
107
/*
112
/*
108
 * Main encryption routine, sets MD5_out.
113
 * Main encryption routine, sets MD5_out.
109
 */
114
 */
110
extern void MD5_std_crypt(void);
115
extern void MD5_std_crypt(int md5_type);
111
116
112
/*
117
/*
113
 * Returns the salt for MD5_std_set_salt().
118
 * Returns the salt for MD5_std_set_salt().
114
 */
119
 */
115
extern char *MD5_std_get_salt(char *ciphertext);
120
extern char *MD5_std_get_salt(char *ciphertext, int md5_type);
116
121
117
/*
122
/*
118
 * Converts an ASCII ciphertext to binary.
123
 * Converts an ASCII ciphertext to binary.
119
 */
124
 */
120
extern MD5_word *MD5_std_get_binary(char *ciphertext);
125
extern MD5_word *MD5_std_get_binary(char *ciphertext, int md5_type);
121
126
122
#endif
127
#endif
(-)john-1.7.0.1/src/MYSQL_fmt.c (+251 lines)
Line 0 Link Here
1
////////////////////////////////////////////////////////////////
2
// MySQL password cracker - v1.0 - 16.1.2003
3
//
4
//    by Andrew Hintz <http://guh.nu> drew@overt.org
5
//  
6
//    This production has been brought to you by
7
//    4tphi <http://4tphi.net> and violating <http://violating.us>
8
//
9
// This file is an add-on to John the Ripper <http://www.openwall.com/john/> 
10
//
11
// Part of this code is based on the MySQL brute password cracker
12
//   mysqlpassword.c by Chris Given
13
// This program executes about 75% faster than mysqlpassword.c
14
// John the ripper also performs sophisticated password guessing.
15
//
16
// John the Ripper will expect the MySQL password file to be
17
// in the following format (without the leading // ):
18
// dumb_user:5d2e19393cc5ef67
19
// another_luser:28ff8d49159ffbaf
20
//
21
// performance enhancements by bartavelle@bandecon.com
22
23
#include <string.h>
24
#include <stdio.h>
25
#include <stdlib.h>
26
#include <math.h>
27
28
// johntr includes
29
#include "arch.h"
30
#include "misc.h"
31
#include "formats.h"
32
#include "common.h"
33
34
//johntr defines
35
#define FORMAT_LABEL "mysql"
36
#define FORMAT_NAME "mysql"
37
#define ALGORITHM_NAME "mysql"
38
39
#define BENCHMARK_COMMENT ""
40
#define BENCHMARK_LENGTH -1
41
42
// Increase the PLAINTEXT_LENGTH value for longer passwords.
43
// You can also set it to 8 when using MySQL systems that truncate 
44
//  the password to only 8 characters.
45
#define PLAINTEXT_LENGTH 32
46
47
#define CIPHERTEXT_LENGTH 16
48
49
#define BINARY_SIZE 16
50
#define SALT_SIZE 0
51
52
#define MIN_KEYS_PER_CRYPT 1
53
#define MAX_KEYS_PER_CRYPT 1
54
55
56
//used for mysql scramble function
57
struct rand_struct {
58
  unsigned long seed1,seed2,max_value;
59
  double max_value_dbl;
60
};
61
62
63
void make_scrambled_password(char *,const char *);
64
char *scramble(char *,const char *,const char *, int);
65
66
//test cases
67
static struct fmt_tests mysql_tests[] = {
68
  {"30f098972cc8924d", "http://guh.nu"},
69
  {"3fc56f6037218993", "Andrew Hintz"},
70
  {"697a7de87c5390b2", "drew"},
71
  {"1eb71cf460712b3e", "http://4tphi.net"},
72
  {"28ff8d49159ffbaf", "http://violating.us"},
73
  {"5d2e19393cc5ef67", "password"},
74
  {NULL}
75
};
76
77
78
//stores the ciphertext for value currently being tested
79
static char crypt_key[BINARY_SIZE+1];
80
81
//used by set_key
82
static char saved_key[PLAINTEXT_LENGTH + 1];
83
84
static int mysql_valid(char *ciphertext) { //returns 0 for invalid ciphertexts
85
86
  int i; //used as counter in loop
87
  
88
  //ciphertext is 16 characters
89
  if (strlen(ciphertext) != 16) return 0;  
90
91
  //ciphertext is ASCII representation of hex digits
92
  for (i = 0; i < 16; i++){
93
    if (!(  ((48 <= ciphertext[i])&&(ciphertext[i] <= 57)) ||
94
	    ((97 <= ciphertext[i])&&(ciphertext[i] <= 102))  ))
95
      return 0;
96
  }
97
98
  return 1;
99
}
100
101
static void mysql_set_salt(void *salt) { }
102
103
static void mysql_set_key(char *key, int index) {
104
  strnzcpy(saved_key, key, PLAINTEXT_LENGTH+1);
105
}
106
107
static char *mysql_get_key(int index) {
108
    return saved_key;
109
}
110
111
static int mysql_cmp_all(void *binary, int index) { //also is mysql_cmp_one
112
	int i = 0;
113
	while(i<BINARY_SIZE)
114
	{
115
		if(((char *)binary)[i]!=((char *)crypt_key)[i])
116
			return 0;
117
		i++;
118
	}
119
	return 1;
120
}
121
122
static int mysql_cmp_exact(char *source, int count){
123
  return (1); //  mysql_cmp_all fallthrough?
124
}
125
126
static void mysql_crypt_all(int count) {  
127
  // get plaintext input in saved_key put it into ciphertext crypt_key
128
  make_scrambled_password(crypt_key,saved_key);
129
}
130
131
////////////////////////////////////////////////////////////////
132
//begin mysql code
133
// This code was copied from mysqlpassword.c by Chris Given
134
// He probably copied it from password.c in the MySQL source
135
// The code is GPLed
136
137
void randominit(struct rand_struct *rand_st,unsigned long seed1, unsigned long seed2) {
138
  rand_st->max_value= 0x3FFFFFFFL;
139
  rand_st->max_value_dbl=(double) rand_st->max_value;
140
  rand_st->seed1=seed1%rand_st->max_value ;
141
  rand_st->seed2=seed2%rand_st->max_value;
142
}
143
static void old_randominit(struct rand_struct *rand_st,unsigned long seed1) {
144
  rand_st->max_value= 0x01FFFFFFL;
145
  rand_st->max_value_dbl=(double) rand_st->max_value;
146
  seed1%=rand_st->max_value;
147
  rand_st->seed1=seed1 ; rand_st->seed2=seed1/2;
148
}
149
double rnd(struct rand_struct *rand_st) {
150
  rand_st->seed1=(rand_st->seed1*3+rand_st->seed2) %
151
    rand_st->max_value;
152
  rand_st->seed2=(rand_st->seed1+rand_st->seed2+33) %
153
    rand_st->max_value;
154
  return(((double) rand_st->seed1)/rand_st->max_value_dbl);
155
}
156
void hash_password(unsigned long *result, const char *password) {
157
  unsigned long nr=1345345333L, add=7, nr2=0x12345671L;
158
  unsigned long tmp;
159
  for (; *password ; password++) {
160
    if (*password == ' ' || *password == '\t')
161
      continue;
162
    //tmp= (unsigned long) (unsigned char) *password;
163
    tmp= (unsigned long) (*password & 0xFF);
164
    nr^= (((nr & 63)+add)*tmp)+ (nr << 8);
165
    nr2+=(nr2 << 8) ^ nr;
166
    add+=tmp;
167
  }
168
  result[0]=nr & (((unsigned long) 1L << 31) -1L); /* Don't use sign bit
169
					      (str2int) */;
170
  result[1]=nr2 & (((unsigned long) 1L << 31) -1L);
171
  return;
172
}
173
void make_scrambled_password(char *to,const char *password) {
174
  unsigned long hash_res[2];
175
  hash_password(hash_res,password);
176
  sprintf(to,"%08lx%08lx",hash_res[0],hash_res[1]);
177
}
178
static inline unsigned int char_val(char X) {
179
  return (unsigned int) (X >= '0' && X <= '9' ? X-'0' : X >= 'A' && X <= 'Z' ?
180
		 X-'A'+10 : X-'a'+10);
181
}
182
char *scramble(char *to,const char *message,const char *password, int
183
	       old_ver) {
184
  struct rand_struct rand_st;
185
  unsigned long hash_pass[2],hash_message[2];
186
  if(password && password[0]) {
187
    char *to_start=to;
188
    hash_password(hash_pass,password);
189
    hash_password(hash_message,message);
190
    if (old_ver)
191
      old_randominit(&rand_st,hash_pass[0] ^
192
		     hash_message[0]);
193
    else
194
      randominit(&rand_st,hash_pass[0] ^ hash_message[0],
195
		 hash_pass[1] ^ hash_message[1]);
196
    while (*message++)
197
      *to++= (char) (floor(rnd(&rand_st)*31)+64);
198
    if (!old_ver) {
199
      char extra=(char) (floor(rnd(&rand_st)*31));
200
      while(to_start != to)
201
        *(to_start++)^=extra;
202
    }
203
  }
204
  *to=0;
205
  return to;
206
}
207
208
//end mysql code
209
////////////////////////////////////////////////////////////////
210
211
struct fmt_main fmt_MYSQL = {
212
  {
213
    FORMAT_LABEL,
214
    FORMAT_NAME,
215
    ALGORITHM_NAME,
216
    BENCHMARK_COMMENT,
217
    BENCHMARK_LENGTH,
218
    PLAINTEXT_LENGTH,
219
    BINARY_SIZE,
220
    SALT_SIZE,
221
    MIN_KEYS_PER_CRYPT,
222
    MAX_KEYS_PER_CRYPT,
223
    FMT_CASE | FMT_8_BIT,
224
    mysql_tests
225
    }, {
226
      fmt_default_init,
227
      mysql_valid, 
228
      fmt_default_split,
229
      fmt_default_binary,
230
      fmt_default_salt,
231
      {
232
	fmt_default_binary_hash,
233
	fmt_default_binary_hash,
234
	fmt_default_binary_hash
235
      },
236
      fmt_default_salt_hash,
237
      mysql_set_salt,
238
      mysql_set_key,
239
      mysql_get_key,
240
      fmt_default_clear_keys,
241
      mysql_crypt_all,
242
      {
243
	fmt_default_get_hash,
244
	fmt_default_get_hash,
245
	fmt_default_get_hash
246
      },
247
      mysql_cmp_all,
248
      mysql_cmp_all, //should it be the same as cmp_all or same as cmp_exact?
249
      mysql_cmp_exact //fallthrough
250
    }
251
};
(-)john-1.7.0.1/src/Makefile (-10 / +53 lines)
Lines 20-25 Link Here
20
LDFLAGS = -s
20
LDFLAGS = -s
21
OPT_NORMAL = -funroll-loops
21
OPT_NORMAL = -funroll-loops
22
OPT_INLINE = -finline-functions
22
OPT_INLINE = -finline-functions
23
LIBS =
23
24
24
JOHN_OBJS_MINIMAL = \
25
JOHN_OBJS_MINIMAL = \
25
	DES_fmt.o DES_std.o DES_bs.o \
26
	DES_fmt.o DES_std.o DES_bs.o \
Lines 28-39 Link Here
28
	BF_fmt.o BF_std.o \
29
	BF_fmt.o BF_std.o \
29
	AFS_fmt.o \
30
	AFS_fmt.o \
30
	LM_fmt.o \
31
	LM_fmt.o \
32
	des.o \
33
	MD5_apache_fmt.o \
34
	BFEgg_fmt.o \
35
	lotus5_fmt.o \
36
	md5.o \
37
	NSLDAP_fmt.o sha1.o base64.o \
38
	MYSQL_fmt.o \
39
	NT_fmt.o \
40
	md4.o smbencrypt.o \
41
	rawMD5_fmt.o \
42
	rawSHA1_fmt.o \
43
	mssql_fmt.o \
44
	hmacMD5_fmt.o \
45
	WPAPSK_fmt.o \
46
	mscash_fmt.o \
47
	oracle_fmt.o \
31
	batch.o bench.o charset.o common.o compiler.o config.o cracker.o \
48
	batch.o bench.o charset.o common.o compiler.o config.o cracker.o \
32
	crc32.o external.o formats.o getopt.o idle.o inc.o john.o list.o \
49
	crc32.o external.o formats.o getopt.o idle.o inc.o john.o list.o \
33
	loader.o logger.o math.o memory.o misc.o options.o params.o path.o \
50
	loader.o logger.o math.o memory.o misc.o options.o params.o path.o \
34
	recovery.o rpp.o rules.o signals.o single.o status.o tty.o wordlist.o \
51
	recovery.o rpp.o rules.o signals.o single.o status.o tty.o wordlist.o \
35
	unshadow.o \
52
	unshadow.o \
36
	unafs.o \
53
	unafs.o \
54
	undrop.o \
37
	unique.o
55
	unique.o
38
56
39
JOHN_OBJS_ORIG = \
57
JOHN_OBJS_ORIG = \
Lines 66-82 Link Here
66
	bench.o best.o common.o config.o formats.o math.o memory.o miscnl.o \
84
	bench.o best.o common.o config.o formats.o math.o memory.o miscnl.o \
67
	params.o path.o signals.o tty.o
85
	params.o path.o signals.o tty.o
68
86
69
PROJ = ../run/john ../run/unshadow ../run/unafs ../run/unique
87
PROJ = ../run/john ../run/unshadow ../run/unafs ../run/unique ../run/undrop
70
PROJ_DOS = ../run/john.bin ../run/john.com \
88
PROJ_DOS = ../run/john.bin ../run/john.com \
71
	../run/unshadow.com ../run/unafs.com ../run/unique.com
89
	../run/unshadow.com ../run/unafs.com ../run/unique.com ../run/undrop.com
72
PROJ_WIN32 = ../run/john.exe \
90
PROJ_WIN32 = ../run/john.exe \
73
	../run/unshadow.exe ../run/unafs.exe ../run/unique.exe
91
	../run/unshadow.exe ../run/unafs.exe ../run/unique.exe ../run/undrop.exe
74
92
75
default:
93
default:
76
	@echo "To build John the Ripper, type:"
94
	@echo "To build John the Ripper, type:"
77
	@echo "	make clean SYSTEM"
95
	@echo "	make clean SYSTEM"
78
	@echo "where SYSTEM can be one of the following:"
96
	@echo "where SYSTEM can be one of the following:"
79
	@echo "linux-x86-mmx            Linux, x86 with MMX (best)"
97
	@echo "linux-x86-mmx            Linux, x86 with MMX (best)"
98
	@echo "linux-x86-sse2            Linux, x86 with SSE2, ELF binaries"
80
	@echo "linux-x86-any            Linux, x86"
99
	@echo "linux-x86-any            Linux, x86"
81
	@echo "linux-x86-any-a.out      Linux, x86, a.out binaries (obsolete)"
100
	@echo "linux-x86-any-a.out      Linux, x86, a.out binaries (obsolete)"
82
	@echo "linux-x86-64             Linux, AMD x86-64, 64-bit native"
101
	@echo "linux-x86-64             Linux, AMD x86-64, 64-bit native"
Lines 127-132 Link Here
127
	@echo "dos-djgpp-x86-mmx        DOS, DJGPP 2.x, x86 with MMX (best)"
146
	@echo "dos-djgpp-x86-mmx        DOS, DJGPP 2.x, x86 with MMX (best)"
128
	@echo "dos-djgpp-x86-any        DOS, DJGPP 2.x, x86"
147
	@echo "dos-djgpp-x86-any        DOS, DJGPP 2.x, x86"
129
	@echo "win32-cygwin-x86-mmx     Win32, Cygwin, x86 with MMX (best)"
148
	@echo "win32-cygwin-x86-mmx     Win32, Cygwin, x86 with MMX (best)"
149
	@echo "win32-cygwin-x86-sse2     Win32, Cygwin, x86 with SSE2"
130
	@echo "win32-cygwin-x86-any     Win32, Cygwin, x86"
150
	@echo "win32-cygwin-x86-any     Win32, Cygwin, x86"
131
	@echo "beos-x86-mmx             BeOS, x86 with MMX"
151
	@echo "beos-x86-mmx             BeOS, x86 with MMX"
132
	@echo "beos-x86-any             BeOS, x86"
152
	@echo "beos-x86-any             BeOS, x86"
Lines 135-141 Link Here
135
linux-x86-mmx:
155
linux-x86-mmx:
136
	$(LN) x86-mmx.h arch.h
156
	$(LN) x86-mmx.h arch.h
137
	$(MAKE) $(PROJ) \
157
	$(MAKE) $(PROJ) \
138
		JOHN_OBJS="$(JOHN_OBJS_MINIMAL) x86.o x86-mmx.o"
158
		JOHN_OBJS="$(JOHN_OBJS_MINIMAL) x86.o x86-mmx.o md4-mmx.o NTmmx_fmt.o md5-mmx.o sha1-mmx.o"
159
160
linux-x86-sse2:
161
	$(LN) x86-sse2.h arch.h
162
	$(MAKE) $(PROJ) \
163
		JOHN_OBJS="$(JOHN_OBJS_MINIMAL) x86.o x86-mmx.o md4-sse2.o NTmmx_fmt.o md5-mmx.o sha1-mmx.o"
139
164
140
linux-x86-any:
165
linux-x86-any:
141
	$(LN) x86-any.h arch.h
166
	$(LN) x86-any.h arch.h
Lines 156-162 Link Here
156
linux-x86-64-mmx:
181
linux-x86-64-mmx:
157
	$(LN) x86-mmx.h arch.h
182
	$(LN) x86-mmx.h arch.h
158
	$(MAKE) $(PROJ) \
183
	$(MAKE) $(PROJ) \
159
		JOHN_OBJS="$(JOHN_OBJS_MINIMAL) x86.o x86-mmx.o" \
184
		JOHN_OBJS="$(JOHN_OBJS_MINIMAL) x86.o x86-mmx.o md4-mmx.o NTmmx_fmt.o" \
160
		CFLAGS="$(CFLAGS) -m32" \
185
		CFLAGS="$(CFLAGS) -m32" \
161
		ASFLAGS="$(ASFLAGS) -m32" \
186
		ASFLAGS="$(ASFLAGS) -m32" \
162
		LDFLAGS="$(LDFLAGS) -m32"
187
		LDFLAGS="$(LDFLAGS) -m32"
Lines 236-242 Link Here
236
openbsd-x86-mmx:
261
openbsd-x86-mmx:
237
	$(LN) x86-mmx.h arch.h
262
	$(LN) x86-mmx.h arch.h
238
	$(MAKE) $(PROJ) \
263
	$(MAKE) $(PROJ) \
239
		JOHN_OBJS="$(JOHN_OBJS_MINIMAL) x86.o x86-mmx.o" \
264
		JOHN_OBJS="$(JOHN_OBJS_MINIMAL) x86.o x86-mmx.o md4-mmx.o NTmmx_fmt.o" \
240
		ASFLAGS="$(ASFLAGS) -DBSD"
265
		ASFLAGS="$(ASFLAGS) -DBSD"
241
266
242
openbsd-x86-any:
267
openbsd-x86-any:
Lines 541-547 Link Here
541
dos-djgpp-x86-mmx:
566
dos-djgpp-x86-mmx:
542
	copy x86-mmx.h arch.h
567
	copy x86-mmx.h arch.h
543
	$(MAKE) $(PROJ_DOS) \
568
	$(MAKE) $(PROJ_DOS) \
544
		JOHN_OBJS="$(JOHN_OBJS_MINIMAL) x86.o x86-mmx.o" \
569
		JOHN_OBJS="$(JOHN_OBJS_MINIMAL) x86.o x86-mmx.o md4-mmx.o NTmmx_fmt.o" \
545
		CFLAGS="$(CFLAGS) -mpreferred-stack-boundary=2" \
570
		CFLAGS="$(CFLAGS) -mpreferred-stack-boundary=2" \
546
		ASFLAGS="$(ASFLAGS) -DUNDERSCORES -DALIGN_LOG"
571
		ASFLAGS="$(ASFLAGS) -DUNDERSCORES -DALIGN_LOG"
547
572
Lines 555-561 Link Here
555
win32-cygwin-x86-mmx:
580
win32-cygwin-x86-mmx:
556
	$(CP) x86-mmx.h arch.h
581
	$(CP) x86-mmx.h arch.h
557
	$(MAKE) $(PROJ_WIN32) \
582
	$(MAKE) $(PROJ_WIN32) \
558
		JOHN_OBJS="$(JOHN_OBJS_MINIMAL) x86.o x86-mmx.o" \
583
		JOHN_OBJS="$(JOHN_OBJS_MINIMAL) x86.o x86-mmx.o md4-mmx.o NTmmx_fmt.o md5_mmx.o sha1-mmx.o" \
584
		CFLAGS="$(CFLAGS) -mpreferred-stack-boundary=2" \
585
		ASFLAGS="$(ASFLAGS) -DUNDERSCORES"
586
587
win32-cygwin-x86-sse2:
588
	$(CP) x86-sse2.h arch.h
589
	$(MAKE) $(PROJ_WIN32) \
590
		JOHN_OBJS="$(JOHN_OBJS_MINIMAL) x86.o x86-mmx.o md4-sse2.o NTmmx_fmt.o md5_mmx.o sha1-mmx.o" \
559
		CFLAGS="$(CFLAGS) -mpreferred-stack-boundary=2" \
591
		CFLAGS="$(CFLAGS) -mpreferred-stack-boundary=2" \
560
		ASFLAGS="$(ASFLAGS) -DUNDERSCORES"
592
		ASFLAGS="$(ASFLAGS) -DUNDERSCORES"
561
593
Lines 569-575 Link Here
569
beos-x86-mmx:
601
beos-x86-mmx:
570
	$(LN) x86-mmx.h arch.h
602
	$(LN) x86-mmx.h arch.h
571
	$(MAKE) $(PROJ) \
603
	$(MAKE) $(PROJ) \
572
		JOHN_OBJS="$(JOHN_OBJS_MINIMAL) x86.o x86-mmx.o"
604
		JOHN_OBJS="$(JOHN_OBJS_MINIMAL) x86.o x86-mmx.o md4-mmx.o NTmmx_fmt.o"
573
605
574
beos-x86-any:
606
beos-x86-any:
575
	$(LN) x86-any.h arch.h
607
	$(LN) x86-any.h arch.h
Lines 595-601 Link Here
595
	$(LD) $(LDFLAGS) $(BENCH_OBJS) -o bench
627
	$(LD) $(LDFLAGS) $(BENCH_OBJS) -o bench
596
628
597
../run/john: $(JOHN_OBJS)
629
../run/john: $(JOHN_OBJS)
598
	$(LD) $(LDFLAGS) $(JOHN_OBJS) -o ../run/john
630
	$(LD) $(LDFLAGS) $(JOHN_OBJS) -o ../run/john ${LIBS}
599
631
600
../run/unshadow: ../run/john
632
../run/unshadow: ../run/john
601
	$(RM) ../run/unshadow
633
	$(RM) ../run/unshadow
Lines 605-610 Link Here
605
	$(RM) ../run/unafs
637
	$(RM) ../run/unafs
606
	ln -s john ../run/unafs
638
	ln -s john ../run/unafs
607
639
640
../run/undrop: ../run/john
641
	$(RM) ../run/undrop
642
	ln -s john ../run/undrop
643
608
../run/unique: ../run/john
644
../run/unique: ../run/john
609
	$(RM) ../run/unique
645
	$(RM) ../run/unique
610
	ln -s john ../run/unique
646
	ln -s john ../run/unique
Lines 623-628 Link Here
623
../run/unafs.com: john.com
659
../run/unafs.com: john.com
624
	copy john.com ..\run\unafs.com
660
	copy john.com ..\run\unafs.com
625
661
662
../run/undrop.com: john.com
663
	copy john.com ..\run\undrop.com
664
626
../run/unique.com: john.com
665
../run/unique.com: john.com
627
	copy john.com ..\run\unique.com
666
	copy john.com ..\run\unique.com
628
667
Lines 641-646 Link Here
641
	$(CC) symlink.c -o ../run/unafs.exe
680
	$(CC) symlink.c -o ../run/unafs.exe
642
	strip ../run/unafs.exe
681
	strip ../run/unafs.exe
643
682
683
../run/undrop.exe: symlink.c
684
	$(CC) symlink.c -o ../run/undrop.exe
685
	strip ../run/undrop.exe
686
644
../run/unique.exe: symlink.c
687
../run/unique.exe: symlink.c
645
	$(CC) symlink.c -o ../run/unique.exe
688
	$(CC) symlink.c -o ../run/unique.exe
646
	strip ../run/unique.exe
689
	strip ../run/unique.exe
(-)john-1.7.0.1/src/NSLDAP_fmt.c (+259 lines)
Line 0 Link Here
1
// Fix for john the ripper 1.6.37 by Sun-Zero, 2004. 07. 26.
2
/*
3
 * This file is part of John the Ripper password cracker,
4
 * Copyright (c) 1996-98 by Solar Designer
5
 *
6
 * Minor performance enhancement by bartavelle@bandecon.com
7
 */
8
9
#include <string.h>
10
11
#include "misc.h"
12
#include "formats.h"
13
#include "common.h"
14
15
#include "sha.h"
16
#include "base64.h"
17
18
#define FORMAT_LABEL			"nsldap"
19
#define FORMAT_NAME			"Netscape LDAP SHA"
20
#define SHA_TYPE                        "SHA1"
21
22
#ifdef MMX_TYPE
23
#define BENCHMARK_COMMENT		MMX_TYPE
24
#else
25
#define BENCHMARK_COMMENT		""
26
#endif
27
#define BENCHMARK_LENGTH		-1
28
29
#define PLAINTEXT_LENGTH		32
30
#define CIPHERTEXT_LENGTH		33
31
32
#define BINARY_SIZE			20
33
#define SALT_SIZE			0
34
35
#ifdef MMX_COEF
36
#define MIN_KEYS_PER_CRYPT		MMX_COEF
37
#define MAX_KEYS_PER_CRYPT		MMX_COEF
38
#define GETPOS(i, index)		( (index)*4 + (i& (0xffffffff-3) )*MMX_COEF + (3-((i)&3)) )
39
#else
40
#define MIN_KEYS_PER_CRYPT		1
41
#define MAX_KEYS_PER_CRYPT		1
42
#endif
43
44
#define NSLDAP_MAGIC "{sha}"
45
#define NSLDAP_MAGIC_LENGTH 5
46
47
static struct fmt_tests tests[] = {
48
  {"{SHA}cMiB1KJphN3OeV9vcYF8nPRIDnk=", "aaaa"},  
49
  {"{SHA}iu0TIuVFC62weOH7YKgXod8loso=", "bbbb"},  
50
  {"{SHA}0ijZPTcJXMa+t2XnEbEwSOkvQu0=", "ccccccccc"},  
51
  {"{SHA}vNR9eUfJfcKmdkLDqNoKagho+qU=", "dddddddddd"},  
52
  {NULL}
53
};
54
55
#ifdef MMX_COEF
56
static char crypt_key[BINARY_SIZE*MMX_COEF];
57
static char saved_key[(PLAINTEXT_LENGTH+1)*MMX_COEF];
58
unsigned long total_len;
59
unsigned char buffer[80*4*MMX_COEF] __attribute__ ((aligned(8*MMX_COEF)));
60
unsigned char out[PLAINTEXT_LENGTH];
61
#else
62
static char crypt_key[BINARY_SIZE];
63
static char saved_key[PLAINTEXT_LENGTH + 1];
64
#endif
65
66
static void *
67
binary(char *ciphertext) {
68
  static char realcipher[BINARY_SIZE + 9];
69
70
  /* stupid overflows */
71
  memset(realcipher, 0, BINARY_SIZE + 9);
72
  base64_decode(NSLDAP_MAGIC_LENGTH+ciphertext, CIPHERTEXT_LENGTH, realcipher);
73
  return (void *)realcipher;
74
}
75
76
static int 
77
valid(char *ciphertext)
78
{
79
  if(ciphertext && strlen(ciphertext) == CIPHERTEXT_LENGTH)
80
    return !strncasecmp(ciphertext, NSLDAP_MAGIC, NSLDAP_MAGIC_LENGTH);
81
  return 0;
82
}
83
84
static int binary_hash_0(void *binary)
85
{
86
  return ((int *)binary)[0] & 0xF;
87
}
88
89
static int binary_hash_1(void *binary)
90
{
91
  return ((int *)binary)[0] & 0xFF;
92
}
93
94
static int binary_hash_2(void *binary)
95
{
96
  return ((int *)binary)[0] & 0xFFF;
97
}
98
99
static int get_hash_0(int index)
100
{
101
  return ((int *)crypt_key)[index] & 0xF;
102
}
103
104
static int get_hash_1(int index)
105
{
106
  return ((int *)crypt_key)[index] & 0xFF;
107
}
108
109
static int get_hash_2(int index)
110
{
111
  return ((int *)crypt_key)[index] & 0xFFF;
112
}
113
114
static void set_key(char *key, int index)
115
{
116
#ifdef MMX_COEF
117
	int len;
118
	int i;
119
	
120
	if(index==0)
121
	{
122
		total_len = 0;
123
		memset(saved_key, 0, PLAINTEXT_LENGTH*MMX_COEF);
124
	}
125
	len = strlen(key);
126
	if(len>PLAINTEXT_LENGTH)
127
		len = PLAINTEXT_LENGTH;
128
129
	total_len += len << ( ( (32/MMX_COEF) * index ) );
130
	for(i=0;i<len;i++)
131
		saved_key[GETPOS(i, index)] = key[i];
132
133
	saved_key[GETPOS(i, index)] = 0x80;
134
#else
135
  strnzcpy(saved_key, key, PLAINTEXT_LENGTH+1);
136
#endif
137
}
138
139
static char *get_key(int index)
140
{
141
#ifdef MMX_COEF
142
	unsigned int i,s;
143
	
144
	s = (total_len >> (((32/MMX_COEF)*(index)))) & 0xff;
145
	for(i=0;i<s;i++)
146
		out[i] = saved_key[ GETPOS(i, index) ];
147
	out[i] = 0;
148
	return out;
149
#else
150
  return saved_key;
151
#endif
152
}
153
154
static int 
155
cmp_all(void *binary, int index)
156
{
157
	int i = 0;
158
#ifdef MMX_COEF
159
	while(i< (BINARY_SIZE/4) )
160
	{
161
		if (
162
			( ((unsigned long *)binary)[i] != ((unsigned long *)crypt_key)[i*MMX_COEF])
163
			&& ( ((unsigned long *)binary)[i] != ((unsigned long *)crypt_key)[i*MMX_COEF+1])
164
#if (MMX_COEF > 3)
165
			&& ( ((unsigned long *)binary)[i] != ((unsigned long *)crypt_key)[i*MMX_COEF+2])
166
			&& ( ((unsigned long *)binary)[i] != ((unsigned long *)crypt_key)[i*MMX_COEF+3])
167
#endif
168
		)
169
			return 0;
170
		i++;
171
	}
172
#else
173
	while(i<BINARY_SIZE)
174
	{
175
		if(((char *)binary)[i]!=((char *)crypt_key)[i])
176
			return 0;
177
		i++;
178
	}
179
#endif
180
	return 1;
181
}
182
183
static int 
184
cmp_exact(char *source, int index)
185
{
186
  return 1;
187
}
188
189
static int cmp_one(void * binary, int index)
190
{
191
#ifdef MMX_COEF
192
	int i = 0;
193
	for(i=0;i<(BINARY_SIZE/4);i++)
194
		if ( ((unsigned long *)binary)[i] != ((unsigned long *)crypt_key)[i*MMX_COEF+index] )
195
			return 0;
196
	return 1;
197
#else
198
	return cmp_all(binary, index);
199
#endif
200
}
201
202
static void set_salt(void *salt) {
203
}
204
205
static void
206
crypt_all(int count) {  
207
#ifdef MMX_COEF
208
	memcpy(buffer, saved_key, 32*MMX_COEF);
209
	shammx(crypt_key, buffer, total_len);
210
#else
211
  static SHA_CTX ctx;
212
  SHA1_Init(&ctx);
213
  SHA1_Update(&ctx, saved_key, strlen(saved_key));
214
  SHA1_Final(crypt_key, &ctx);
215
#endif
216
}
217
218
struct fmt_main fmt_NSLDAP = {
219
	{
220
		FORMAT_LABEL,
221
		FORMAT_NAME,
222
		SHA_TYPE,
223
		BENCHMARK_COMMENT,
224
		BENCHMARK_LENGTH,
225
		PLAINTEXT_LENGTH,
226
		BINARY_SIZE,
227
		SALT_SIZE,
228
		MIN_KEYS_PER_CRYPT,
229
		MAX_KEYS_PER_CRYPT,
230
		FMT_CASE | FMT_8_BIT,
231
		tests
232
	}, {
233
		fmt_default_init,
234
		valid,
235
		fmt_default_split,
236
		binary,
237
		fmt_default_salt,
238
		{
239
			binary_hash_0,
240
			binary_hash_1,
241
			binary_hash_2
242
		},
243
		fmt_default_salt_hash,
244
		set_salt,
245
		set_key,
246
		get_key,
247
		fmt_default_clear_keys,
248
		crypt_all, 
249
		{
250
			get_hash_0,
251
			get_hash_1,
252
			get_hash_2
253
		},
254
		cmp_all,
255
		cmp_one,
256
		cmp_exact
257
	}
258
};
259
(-)john-1.7.0.1/src/NT_fmt.c (+194 lines)
Line 0 Link Here
1
/*
2
 * NTLM patch for john version 0.3
3
 *
4
 * (C) 2001 Olle Segerdahl <olle@nxs.se>
5
 *
6
 * license: GPL <http://www.gnu.org/licenses/gpl.html>
7
 *
8
 * This file is based on code from John the Ripper,
9
 * Copyright (c) 1996-99 by Solar Designer
10
 *
11
 * performance enhancements by bartavelle@bandecon.com
12
 */
13
14
#include <string.h>
15
16
#include "arch.h"
17
#include "memory.h"
18
#include "common.h"
19
#include "formats.h"
20
21
#ifndef uchar
22
#define uchar unsigned char
23
#endif
24
25
#define FORMAT_LABEL			"nt"
26
#define FORMAT_NAME			"NT MD4"
27
28
#define BENCHMARK_COMMENT		""
29
#define BENCHMARK_LENGTH		-1
30
31
#define PLAINTEXT_LENGTH		54
32
#define CIPHERTEXT_LENGTH		36
33
34
35
static struct fmt_tests tests[] = {
36
	{"$NT$b7e4b9022cd45f275334bbdb83bb5be5", "John the Ripper"},
37
	{"$NT$8846f7eaee8fb117ad06bdd830b7586c", "password"},
38
	{"$NT$0cb6948805f797bf2a82807973b89537", "test"},
39
	{"$NT$31d6cfe0d16ae931b73c59d7e0c089c0", ""},
40
	{NULL}
41
};
42
43
#define ALGORITHM_NAME			"TridgeMD4"
44
45
#define BINARY_SIZE			16
46
#define SALT_SIZE			0
47
48
#define MIN_KEYS_PER_CRYPT		1
49
#define MAX_KEYS_PER_CRYPT		1
50
51
uchar saved_plain[PLAINTEXT_LENGTH + 1];
52
uchar output[BINARY_SIZE + 1];
53
54
extern void E_md4hash(uchar *passwd, uchar *p16);
55
56
57
static int valid(char *ciphertext)
58
{
59
        char *pos;
60
61
	if (strncmp(ciphertext, "$NT$", 4)!=0) return 0;
62
63
        for (pos = &ciphertext[4]; atoi16[ARCH_INDEX(*pos)] != 0x7F; pos++);
64
65
        if (!*pos && pos - ciphertext == CIPHERTEXT_LENGTH)
66
		return 1;
67
        else
68
        	return 0;
69
70
}
71
72
static void *get_binary(char *ciphertext)
73
{
74
	static uchar binary[BINARY_SIZE];
75
	int i;
76
77
	ciphertext+=4;
78
	for (i=0; i<BINARY_SIZE; i++)
79
	{
80
 		binary[i] = (atoi16[ARCH_INDEX(ciphertext[i*2])])<<4;
81
 		binary[i] |= (atoi16[ARCH_INDEX(ciphertext[i*2+1])]);
82
	}
83
84
	return binary;
85
}
86
87
static int binary_hash_0(void *binary)
88
{
89
	return ((uchar *)binary)[0] & 0x0F;
90
}
91
92
static int binary_hash_1(void *binary)
93
{
94
	return ((uchar *)binary)[0];
95
}
96
97
static int binary_hash_2(void *binary)
98
{
99
	return (((uchar *)binary)[0] << 4) + (((uchar *)binary)[1] & 0x0F);
100
}
101
102
static int get_hash_0(int index)
103
{
104
	return output[0] & 0x0F;
105
}
106
107
static int get_hash_1(int index)
108
{
109
	return output[0];
110
}
111
112
static int get_hash_2(int index)
113
{
114
	return (output[0] << 4) + (output[1] & 0x0F);
115
}
116
117
static void crypt_all(int count)
118
{
119
	E_md4hash(saved_plain, output);
120
}
121
122
static int cmp_all(void *binary, int count)
123
{
124
	int i = 0;
125
	while(i<BINARY_SIZE)
126
	{
127
		if(((char *)binary)[i]!=((char *)output)[i])
128
			return 0;
129
		i++;
130
	}
131
	return 1;
132
}
133
134
static int cmp_exact(char *source, int index)
135
{
136
	return !memcmp(output, get_binary(source), index);
137
}
138
139
static void set_salt(void *salt)
140
{
141
}
142
143
static void set_key(char *key, int index)
144
{
145
	strncpy(saved_plain, key, PLAINTEXT_LENGTH);
146
	saved_plain[PLAINTEXT_LENGTH] = 0;
147
}
148
149
static char *get_key(int index)
150
{
151
	return saved_plain;
152
}
153
154
struct fmt_main fmt_NT = {
155
	{
156
		FORMAT_LABEL,
157
		FORMAT_NAME,
158
		ALGORITHM_NAME,
159
		BENCHMARK_COMMENT,
160
		BENCHMARK_LENGTH,
161
		PLAINTEXT_LENGTH,
162
		BINARY_SIZE,
163
		SALT_SIZE,
164
		MIN_KEYS_PER_CRYPT,
165
		MAX_KEYS_PER_CRYPT,
166
		FMT_CASE | FMT_8_BIT,
167
		tests
168
	}, {
169
		fmt_default_init,
170
		valid,
171
		fmt_default_split,
172
		get_binary,
173
		fmt_default_salt,
174
		{
175
			binary_hash_0,
176
			binary_hash_1,
177
			binary_hash_2
178
		},
179
		fmt_default_salt_hash,
180
		set_salt,
181
		set_key,
182
		get_key,
183
		fmt_default_clear_keys,
184
		crypt_all,
185
		{
186
			get_hash_0,
187
			get_hash_1,
188
			get_hash_2
189
		},
190
		cmp_all,
191
		cmp_all,
192
		cmp_exact
193
	}
194
};
(-)john-1.7.0.1/src/NTmmx_fmt.c (+254 lines)
Line 0 Link Here
1
/*
2
 * NTLM patch for john version 0.3
3
 *
4
 * (C) 2001 Olle Segerdahl <olle@nxs.se>
5
 *
6
 * license: GPL <http://www.gnu.org/licenses/gpl.html>
7
 *
8
 * This file is based on code from John the Ripper,
9
 * Copyright (c) 1996-99 by Solar Designer
10
 *
11
 * performance enhancements by bartavelle@bandecon.com
12
 */
13
14
#include <string.h>
15
16
#include "arch.h"
17
#include "memory.h"
18
#include "common.h"
19
#include "formats.h"
20
#include "md4.h"
21
22
#ifndef uchar
23
#define uchar unsigned char
24
#endif
25
26
#define FORMAT_LABEL			"ntmmx"
27
#define FORMAT_NAME			"NT MD4 MMX"
28
29
#define BENCHMARK_COMMENT		MMX_TYPE
30
#define BENCHMARK_LENGTH		-1
31
32
#define PLAINTEXT_LENGTH		32
33
#define CIPHERTEXT_LENGTH		36
34
35
36
static struct fmt_tests tests[] = {
37
	{"$NT$b7e4b9022cd45f275334bbdb83bb5be5", "John the Ripper"},
38
	{"$NT$8846f7eaee8fb117ad06bdd830b7586c", "password"},
39
	{"$NT$0cb6948805f797bf2a82807973b89537", "test"},
40
	{"$NT$31d6cfe0d16ae931b73c59d7e0c089c0", ""},
41
	{NULL}
42
};
43
44
#define ALGORITHM_NAME			"bartavelle"
45
46
#define BINARY_SIZE			16
47
#define SALT_SIZE			0
48
49
50
#define MIN_KEYS_PER_CRYPT		MMX_COEF
51
#define MAX_KEYS_PER_CRYPT		MMX_COEF
52
53
#define GETPOS(i,idx)	( ((i)&0xfffe)*MMX_COEF + ((i)&1) + ((idx)<<1) )
54
55
//uchar saved_plain[PLAINTEXT_LENGTH + 1];
56
57
static unsigned char saved_plain[64 * MMX_COEF] __attribute__ ((aligned(32)));
58
/*static unsigned char tmpbuf[64 * MMX_COEF] __attribute__ ((aligned(32)));*/
59
static unsigned char output[BINARY_SIZE*MMX_COEF + 1] __attribute__ ((aligned(32)));
60
static unsigned char out[32];
61
static unsigned long total_len;
62
/*static int global_watch = 0;*/
63
64
static int valid(char *ciphertext)
65
{
66
        char *pos;
67
68
	if (strncmp(ciphertext, "$NT$", 4)!=0) return 0;
69
70
        for (pos = &ciphertext[4]; atoi16[ARCH_INDEX(*pos)] != 0x7F; pos++);
71
72
        if (!*pos && pos - ciphertext == CIPHERTEXT_LENGTH)
73
		return 1;
74
        else
75
        	return 0;
76
77
}
78
79
static void *get_binary(char *ciphertext)
80
{
81
	static uchar binary[BINARY_SIZE];
82
	int i;
83
84
	ciphertext+=4;
85
	for (i=0; i<BINARY_SIZE; i++)
86
	{
87
 		binary[i] = (atoi16[ARCH_INDEX(ciphertext[i*2])])<<4;
88
 		binary[i] |= (atoi16[ARCH_INDEX(ciphertext[i*2+1])]);
89
	}
90
91
	return binary;
92
}
93
94
static int binary_hash_0(void *binary)
95
{
96
	return ((uchar *)binary)[0] & 0x0F;
97
}
98
99
static int binary_hash_1(void *binary)
100
{
101
	return ((uchar *)binary)[0];
102
}
103
104
static int binary_hash_2(void *binary)
105
{
106
	return (((uchar *)binary)[0] << 4) + (((uchar *)binary)[1] & 0x0F);
107
}
108
109
static int get_hash_0(int index)
110
{
111
	return output[index*4] & 0x0F;
112
}
113
114
static int get_hash_1(int index)
115
{
116
	return output[index*4];
117
}
118
119
static int get_hash_2(int index)
120
{
121
	return (output[index*4] << 4) + (output[index*4+1] & 0x0F);
122
}
123
124
static void crypt_all(int count)
125
{
126
#if (MMX_COEF == 2)
127
        mdfourmmx(output, saved_plain, total_len);
128
#endif
129
#if (MMX_COEF == 4)
130
        mdfoursse2(output, saved_plain, total_len);
131
#endif
132
}
133
134
static int cmp_all(void *binary, int count)
135
{
136
	int i = 0;
137
138
	while(i<(BINARY_SIZE/4))
139
	{
140
		if (
141
			( ((unsigned long *)binary)[i] != ((unsigned long *)output)[i*MMX_COEF])
142
#if (MMX_COEF > 1 )
143
			&& ( ((unsigned long *)binary)[i] != ((unsigned long *)output)[i*MMX_COEF+1])
144
#endif
145
#if (MMX_COEF > 3)
146
			&& ( ((unsigned long *)binary)[i] != ((unsigned long *)output)[i*MMX_COEF+2])
147
			&& ( ((unsigned long *)binary)[i] != ((unsigned long *)output)[i*MMX_COEF+3])
148
#endif	
149
150
		)
151
			return 0;
152
		i++;
153
	}
154
	return 1;
155
}
156
157
static int cmp_one(void * binary, int index)
158
{
159
	int i = 0;
160
	for(i=0;i<(BINARY_SIZE/4);i++)
161
		if ( ((unsigned long *)binary)[i] != ((unsigned long *)output)[i*MMX_COEF+index] )
162
			return 0;
163
	return 1;
164
}
165
166
static int cmp_exact(char *source, int index)
167
{
168
	return 1;
169
}
170
171
static void set_salt(void *salt)
172
{
173
}
174
175
static void set_key(char *key, int index)
176
{
177
	int len;
178
	int i;
179
180
	if(index==0)
181
	{
182
		total_len = 0;
183
		memset(saved_plain, 0, 64*MMX_COEF);
184
	}
185
	len = strlen(key);
186
	if(len > 32)
187
                len = 32;
188
189
	total_len += len << (1 + ( (32/MMX_COEF) * index ) );
190
191
	for(i=0;i<len;i++)
192
		((unsigned short *)saved_plain)[ GETPOS(i, index) ] = key[i] ;
193
	((unsigned short *)saved_plain)[ GETPOS(i, index) ] = 0x80;
194
}
195
196
static char *get_key(int index)
197
{
198
	unsigned int s, i;
199
200
#if (MMX_COEF == 4)
201
	s = (total_len >> (1+((32/MMX_COEF)*(index)))) & 0xff;
202
#else
203
	if(index == 0)
204
		s = (total_len & 0xffff) >> 1 ;
205
	else
206
		s = total_len >> 17;
207
#endif
208
	for(i=0;i<s;i++)
209
		out[i] = ((unsigned short *)saved_plain)[ GETPOS(i, index) ];
210
	out[i]=0;
211
	return out;
212
}
213
214
struct fmt_main fmt_NTmmx = {
215
	{
216
		FORMAT_LABEL,
217
		FORMAT_NAME,
218
		ALGORITHM_NAME,
219
		BENCHMARK_COMMENT,
220
		BENCHMARK_LENGTH,
221
		PLAINTEXT_LENGTH,
222
		BINARY_SIZE,
223
		SALT_SIZE,
224
		MIN_KEYS_PER_CRYPT,
225
		MAX_KEYS_PER_CRYPT,
226
		FMT_CASE | FMT_8_BIT,
227
		tests
228
	}, {
229
		fmt_default_init,
230
		valid,
231
		fmt_default_split,
232
		get_binary,
233
		fmt_default_salt,
234
		{
235
			binary_hash_0,
236
			binary_hash_1,
237
			binary_hash_2
238
		},
239
		fmt_default_salt_hash,
240
		set_salt,
241
		set_key,
242
		get_key,
243
		fmt_default_clear_keys,
244
		crypt_all,
245
		{
246
			get_hash_0,
247
			get_hash_1,
248
			get_hash_2
249
		},
250
		cmp_all,
251
		cmp_one,
252
		cmp_exact
253
	}
254
};
(-)john-1.7.0.1/src/WPAPSK_fmt.c (+482 lines)
Line 0 Link Here
1
/*
2
 * Copyright (c) 2004 bartavelle
3
 * bartavelle@bandecon.com
4
 *
5
 * Simple MD5 hashes cracker
6
 * It uses the Solar Designer's md5 implementation
7
 * 
8
 */
9
10
#include <string.h>
11
12
#include "arch.h"
13
#include "misc.h"
14
#include "common.h"
15
#include "formats.h"
16
#include "md5.h"
17
#include "sha.h"
18
19
#define FORMAT_LABEL			"wpapsk"
20
#define FORMAT_NAME			"WPA PSK"
21
#ifdef MMX_COEF
22
#if (MMX_COEF == 2)
23
#define ALGORITHM_NAME			"wpa-psk MMX"
24
#else
25
#define ALGORITHM_NAME			"pwa-psk SSE2"
26
#endif
27
#else
28
#define ALGORITHM_NAME			"wpa-psk"
29
#endif
30
31
#ifdef MMX_TYPE
32
#define BENCHMARK_COMMENT		MMX_TYPE
33
#else
34
#define BENCHMARK_COMMENT		""
35
#endif
36
#define BENCHMARK_LENGTH		-1
37
38
#define PLAINTEXT_LENGTH		60
39
#define CIPHERTEXT_LENGTH		(128+400)
40
41
#define BINARY_SIZE			16
42
#define SHA_SIZE			20
43
#define SALT_SIZE			64
44
45
#ifdef MMX_COEF
46
#define MIN_KEYS_PER_CRYPT		MMX_COEF
47
#define MAX_KEYS_PER_CRYPT		MMX_COEF
48
#define GETPOS(i, index)		( (index)*4 + ((i)& (0xffffffff-3) )*MMX_COEF + (((i)&3)) )
49
#else
50
#define MIN_KEYS_PER_CRYPT		1
51
#define MAX_KEYS_PER_CRYPT		1
52
#endif
53
54
// format : essid#MIC AA SPA snonce anonce keymic eapolframe
55
static struct fmt_tests wpapsk_tests[] = {
56
	{"somethingclever#c016873ee6bb01499d77bde7c5e7a4be 00026f01b8fb000c413f313e289f35c24325dda9e773a11cd0416a880622c3589a37886e318120a7e0ad68dd8a4b70c7b368bac5b4476a9e6071270d1d5734e484cf09ddd3f29966e20136de 0103005ffe010900200000000000000001289f35c24325dda9e773a11cd0416a880622c3589a37886e318120a7e0ad68dd", "family movie night"},
57
	{NULL}
58
};
59
60
#ifdef MMX_COEF
61
//static char saved_key[PLAINTEXT_LENGTH*MMX_COEF*2 + 1] __attribute__ ((aligned(16)));
62
static char crypt_key[64*MMX_COEF] __attribute__ ((aligned(16)));
63
unsigned long total_len;
64
unsigned char opad[PLAINTEXT_LENGTH*MMX_COEF] __attribute__ ((aligned(16)));
65
unsigned char ipad[PLAINTEXT_LENGTH*MMX_COEF] __attribute__ ((aligned(16)));
66
unsigned char cursalt[SALT_SIZE*MMX_COEF] __attribute__ ((aligned(16)));
67
unsigned char dump[80*4*MMX_COEF] __attribute__((aligned(16)));
68
#else
69
//static char saved_key[PLAINTEXT_LENGTH + 1];
70
static char crypt_key[BINARY_SIZE+1];
71
static SHA_CTX ctx;
72
unsigned char opad[64];
73
unsigned char ipad[64];
74
unsigned char nopad[64];
75
unsigned char nipad[64];
76
unsigned char cursalt[SALT_SIZE];
77
unsigned char dump[SHA_SIZE];
78
#endif
79
unsigned char out[PLAINTEXT_LENGTH];
80
81
unsigned char DATA[12+64];
82
unsigned char nDATA[12+64+23+1];
83
unsigned char EAPOL[99];
84
85
static void wpapsk_init(void)
86
{
87
#ifdef MMX_COEF
88
	memset(crypt_key, 0, 64*MMX_COEF);
89
	memset(cursalt, 0, 64*MMX_COEF);
90
	crypt_key[GETPOS(BINARY_SIZE,0)] = 0x80;
91
	crypt_key[GETPOS(BINARY_SIZE,1)] = 0x80;
92
#if (MMX_COEF == 4)
93
	crypt_key[GETPOS(BINARY_SIZE,2)] = 0x80;
94
	crypt_key[GETPOS(BINARY_SIZE,3)] = 0x80;
95
#endif
96
#else
97
	memset(nipad, 0x36, 64);
98
	memset(nopad, 0x5C, 64);
99
	memset(EAPOL, 0, sizeof(EAPOL));
100
	strcpy(nDATA, "Pairwise key expansion");
101
#endif
102
}
103
104
static int valid(char *ciphertext)
105
{
106
	int pos, i;
107
108
	for(i=0;(i<strlen(ciphertext)) && (ciphertext[i]!='#');i++) ;
109
	if(i==strlen(ciphertext))
110
		return 0;
111
	pos = i+1;
112
	for (i = pos; i < BINARY_SIZE*2+pos; i++){
113
		if (!(  (('0' <= ciphertext[i])&&(ciphertext[i] <= '9')) ||
114
					(('a' <= ciphertext[i])&&(ciphertext[i] <= 'f'))  
115
					|| (('A' <= ciphertext[i])&&(ciphertext[i] <= 'F'))))
116
			return 0;
117
	}
118
	return 1;
119
}
120
121
static void wpapsk_set_salt(void *salt) 
122
{
123
#ifdef MMX_COEF
124
	total_len = 0;
125
	while( ((unsigned char *)salt)[total_len] )
126
	{
127
		cursalt[GETPOS(total_len, 0)] = ((unsigned char *)salt)[total_len];
128
		cursalt[GETPOS(total_len, 1)] = ((unsigned char *)salt)[total_len];
129
#if (MMX_COEF == 4)
130
		cursalt[GETPOS(total_len, 2)] = ((unsigned char *)salt)[total_len];
131
		cursalt[GETPOS(total_len, 3)] = ((unsigned char *)salt)[total_len];
132
#endif
133
		total_len ++;
134
	}
135
	while( ((unsigned char *)salt)[total_len-4] )
136
	{
137
		cursalt[GETPOS(total_len, 0)] = ((unsigned char *)salt)[total_len];
138
		cursalt[GETPOS(total_len, 1)] = ((unsigned char *)salt)[total_len];
139
#if (MMX_COEF == 4)
140
		cursalt[GETPOS(total_len, 2)] = ((unsigned char *)salt)[total_len];
141
		cursalt[GETPOS(total_len, 3)] = ((unsigned char *)salt)[total_len];
142
#endif
143
		total_len ++;
144
	}
145
146
	cursalt[GETPOS(total_len, 0)] = 0x80;
147
	cursalt[GETPOS(total_len, 1)] = 0x80;
148
#if (MMX_COEF == 4)
149
	cursalt[GETPOS(total_len, 2)] = 0x80;
150
	cursalt[GETPOS(total_len, 3)] = 0x80;
151
#endif
152
#else
153
	memcpy(cursalt, salt, SALT_SIZE);
154
#endif
155
}
156
157
static void wpapsk_set_key(char *key, int index) {
158
	int i;
159
	int len;
160
	
161
	len = strlen(key);
162
	if(len>PLAINTEXT_LENGTH)
163
		len = PLAINTEXT_LENGTH;
164
165
#ifdef MMX_COEF
166
	if(index==0)
167
	{
168
		memset(ipad, 0x36, 64*MMX_COEF);
169
		memset(opad, 0x5C, 64*MMX_COEF);
170
	}
171
	
172
	for(i=0;i<len;i++)
173
	{
174
		ipad[GETPOS(i, index)] = 0x36 ^ key[i];
175
		opad[GETPOS(i, index)] = 0x5C ^ key[i];
176
	}
177
178
	//saved_key[GETPOS(i, index)] = 0x80;
179
#else
180
	memset(ipad, 0x36, 64);
181
	memset(opad, 0x5C, 64);
182
	for(i=0;i<len;i++)
183
	{
184
		ipad[i] ^= key[i];
185
		opad[i] ^= key[i];
186
	}
187
#endif
188
}
189
190
static char *wpapsk_get_key(int index) {
191
	unsigned int i;
192
	for(i=0;i<PLAINTEXT_LENGTH;i++)
193
#ifdef MMX_COEF
194
		out[i] = ipad[ GETPOS(i, index) ] ^ 0x36;
195
#else
196
		out[i] = ipad[ i ] ^ 0x36;
197
#endif
198
	return out;
199
}
200
201
static int wpapsk_cmp_all(void *binary, int index) { 
202
	int i=0;
203
#ifdef MMX_COEF
204
	while(i< (BINARY_SIZE/4) )
205
	{
206
		if (
207
			( ((unsigned long *)binary)[i] != ((unsigned long *)crypt_key)[i*MMX_COEF])
208
			&& ( ((unsigned long *)binary)[i] != ((unsigned long *)crypt_key)[i*MMX_COEF+1])
209
#if (MMX_COEF > 3)
210
			&& ( ((unsigned long *)binary)[i] != ((unsigned long *)crypt_key)[i*MMX_COEF+2])
211
			&& ( ((unsigned long *)binary)[i] != ((unsigned long *)crypt_key)[i*MMX_COEF+3])
212
#endif
213
		)
214
			return 0;
215
		i++;
216
	}
217
#else
218
	while(i<BINARY_SIZE)
219
	{
220
		if(((char *)binary)[i]!=((char *)crypt_key)[i])
221
			return 0;
222
		i++;
223
	}
224
#endif
225
	return 1;
226
}
227
228
static int wpapsk_cmp_exact(char *source, int count){
229
  return (1);
230
}
231
232
static int wpapsk_cmp_one(void * binary, int index)
233
{
234
#ifdef MMX_COEF
235
	int i = 0;
236
	for(i=0;i<(BINARY_SIZE/4);i++)
237
		if ( ((unsigned long *)binary)[i] != ((unsigned long *)crypt_key)[i*MMX_COEF+index] )
238
			return 0;
239
	return 1;
240
#else
241
	return wpapsk_cmp_all(binary, index);
242
#endif
243
}
244
245
/*
246
 * ça ne marche pas et ça m'a gonflé
247
 */
248
249
static void wpapsk_crypt_all(int count) {  
250
#ifdef MMX_COEF
251
	/*int i;*/
252
	printf("\n");
253
	dump_stuff_mmx(ipad, 64, 0);
254
	memcpy(dump, ipad, 64*MMX_COEF);
255
	shammx_nosizeupdate( dump, dump, 64);
256
257
	memcpy(dump, cursalt, 64*MMX_COEF);
258
	shammx_noinit_uniformsizeupdate(dump, dump, total_len + 64 );
259
	dump_stuff_mmx(dump, SHA_SIZE, 0);
260
261
	shammx_nosizeupdate( dump, opad, 64);
262
	shammx_noinit_uniformsizeupdate(dump, dump, SHA_SIZE + 64);
263
	dump_stuff_mmx(dump, SHA_SIZE, 0);
264
265
	return;
266
#else
267
	unsigned char dump[SHA_SIZE];
268
	unsigned char digest[SHA_SIZE];
269
	unsigned char ptk[20*4];
270
	unsigned int i,j;
271
	MD5_CTX md5ctx;
272
	
273
	//printf("\n");
274
	//first calculation - left part
275
	SHA1_Init( &ctx );
276
	SHA1_Update( &ctx, ipad, 64 );
277
	SHA1_Update( &ctx, cursalt, strlen(cursalt) + 4 );
278
	SHA1_Final( dump, &ctx);
279
	SHA1_Init( &ctx );
280
	SHA1_Update( &ctx, opad, 64 );
281
	SHA1_Update( &ctx, dump, SHA_SIZE);
282
	SHA1_Final( dump, &ctx);
283
	memcpy(digest, dump, SHA_SIZE);
284
	for(i=1;i<4096;i++)
285
	{
286
		SHA1_Init( &ctx );
287
		SHA1_Update( &ctx, ipad, 64 );
288
		SHA1_Update( &ctx, dump, SHA_SIZE );
289
		SHA1_Final( dump, &ctx);
290
		SHA1_Init( &ctx );
291
		SHA1_Update( &ctx, opad, 64 );
292
		SHA1_Update( &ctx, dump, SHA_SIZE);
293
		SHA1_Final( dump, &ctx);
294
		for(j=0;j<SHA_SIZE;j++)
295
			digest[j] ^= dump[j];
296
	}
297
	//first calculation - right part
298
	cursalt[ strlen(cursalt) + 3 ] = 2;
299
	SHA1_Init( &ctx );
300
	SHA1_Update( &ctx, ipad, 64 );
301
	SHA1_Update( &ctx, cursalt, strlen(cursalt) + 4 );
302
	SHA1_Final( dump, &ctx);
303
	SHA1_Init( &ctx );
304
	SHA1_Update( &ctx, opad, 64 );
305
	SHA1_Update( &ctx, dump, SHA_SIZE);
306
	SHA1_Final( dump, &ctx);
307
	memcpy(digest+SHA_SIZE, dump, 32-SHA_SIZE);
308
	for(i=1;i<4096;i++)
309
	{
310
		SHA1_Init( &ctx );
311
		SHA1_Update( &ctx, ipad, 64 );
312
		SHA1_Update( &ctx, dump, SHA_SIZE );
313
		SHA1_Final( dump, &ctx);
314
		SHA1_Init( &ctx );
315
		SHA1_Update( &ctx, opad, 64 );
316
		SHA1_Update( &ctx, dump, SHA_SIZE);
317
		SHA1_Final( dump, &ctx);
318
		for(j=0;j<32-SHA_SIZE;j++)
319
			digest[j+SHA_SIZE] ^= dump[j];
320
	}
321
	//we now got pmk in digest,32
322
	//dump_stuff(digest, 32 );
323
	for(i=0;i<32;i++)
324
	{
325
		nipad[i] = 0x36 ^ digest[i];
326
		nopad[i] = 0x5c ^ digest[i];
327
	}
328
	//a hmac must be done with secret key pmk/32, and text "Pairwise key expansion",0,DATA,counter
329
	nDATA[23+64+12] = 0;
330
	SHA1_Init( &ctx );
331
	SHA1_Update( &ctx, nipad, 64 );
332
	SHA1_Update( &ctx, nDATA, 22+1+12+64+1 );
333
	SHA1_Final( dump, &ctx );
334
	SHA1_Init( &ctx );
335
	SHA1_Update( &ctx, nopad, 64 );
336
	SHA1_Update( &ctx, dump, SHA_SIZE);
337
	SHA1_Final( ptk, &ctx);
338
339
	//seems not to be used ...
340
	/*
341
	nDATA[23+64+12] = 1;
342
	SHA1_Init( &ctx );
343
	SHA1_Update( &ctx, nipad, 64 );
344
	SHA1_Update( &ctx, nDATA, 22+1+12+64+1 );
345
	SHA1_Final( dump, &ctx );
346
	SHA1_Init( &ctx );
347
	SHA1_Update( &ctx, nopad, 64 );
348
	SHA1_Update( &ctx, dump, SHA_SIZE);
349
	SHA1_Final( ptk + 20, &ctx);
350
351
	nDATA[23+64+12] = 2;
352
	SHA1_Init( &ctx );
353
	SHA1_Update( &ctx, nipad, 64 );
354
	SHA1_Update( &ctx, nDATA, 22+1+12+64+1 );
355
	SHA1_Final( dump, &ctx );
356
	SHA1_Init( &ctx );
357
	SHA1_Update( &ctx, nopad, 64 );
358
	SHA1_Update( &ctx, dump, SHA_SIZE);
359
	SHA1_Final( ptk + 40, &ctx);
360
361
	nDATA[23+64+12] = 3;
362
	SHA1_Init( &ctx );
363
	SHA1_Update( &ctx, nipad, 64 );
364
	SHA1_Update( &ctx, nDATA, 22+1+12+64+1 );
365
	SHA1_Final( dump, &ctx );
366
	SHA1_Init( &ctx );
367
	SHA1_Update( &ctx, nopad, 64 );
368
	SHA1_Update( &ctx, dump, SHA_SIZE);
369
	SHA1_Final( ptk + 60, &ctx);
370
	*/
371
	//we now have the ptk ...
372
373
	//now hmac md5 ...
374
	memset(nipad + 16, 0x36 , 16); 
375
	memset(nopad + 16, 0x5C , 16); 
376
	for(i=0;i<16;i++)
377
	{
378
		nipad[i] = 0x36 ^ ptk[i];
379
		nopad[i] = 0x5C ^ ptk[i];
380
	}
381
	MD5_Init( &md5ctx );
382
	MD5_Update( &md5ctx, nipad, 64 );
383
	MD5_Update( &md5ctx, EAPOL, sizeof(EAPOL) );
384
	MD5_Final ( dump, &md5ctx );
385
	MD5_Init( &md5ctx );
386
	MD5_Update( &md5ctx, nopad, 64 );
387
	MD5_Update( &md5ctx, dump, 16 );
388
	MD5_Final ( crypt_key, &md5ctx );
389
#endif
390
  
391
}
392
393
static void * wpapsk_binary(char *ciphertext) 
394
{
395
	static unsigned char realcipher[BINARY_SIZE];
396
	int i,pos;
397
	
398
	for(i=0;ciphertext[i]!='#';i++);
399
	pos=i+1;
400
	for(i=0;i<BINARY_SIZE;i++)
401
	{
402
		realcipher[i] = atoi16[ARCH_INDEX(ciphertext[i*2+pos])]*16 + atoi16[ARCH_INDEX(ciphertext[i*2+1+pos])];
403
	}
404
	pos += i*2+1;
405
	i=0;
406
	while(ciphertext[pos]!=' ')
407
	{
408
		DATA[i] = atoi16[ARCH_INDEX(ciphertext[pos])]*16 + atoi16[ARCH_INDEX(ciphertext[1+pos])];
409
		i++;
410
		pos += 2;
411
	}
412
	memcpy(nDATA+23, DATA, 12+64);
413
	pos++;
414
	i=0;
415
	while(ciphertext[pos])
416
	{
417
		EAPOL[i] = atoi16[ARCH_INDEX(ciphertext[pos])]*16 + atoi16[ARCH_INDEX(ciphertext[1+pos])];
418
		i++;
419
		pos += 2;
420
	}
421
422
	return (void *)realcipher;
423
}
424
425
static void * wpapsk_salt(char *ciphertext)
426
{
427
	static unsigned char salt[SALT_SIZE];
428
	memset(salt, 0, SALT_SIZE);
429
	int i=0;
430
	while(ciphertext[i]!='#')
431
	{
432
		salt[i] = ciphertext[i];
433
		i++;
434
	}
435
	salt[i]=0;
436
	salt[i+1]=0;
437
	salt[i+2]=0;
438
	salt[i+3]=1;
439
	return salt;
440
}
441
442
struct fmt_main fmt_WPAPSK = {
443
	{
444
		FORMAT_LABEL,
445
		FORMAT_NAME,
446
		ALGORITHM_NAME,
447
		BENCHMARK_COMMENT,
448
		BENCHMARK_LENGTH,
449
		PLAINTEXT_LENGTH,
450
		BINARY_SIZE,
451
		SALT_SIZE,
452
		MIN_KEYS_PER_CRYPT,
453
		MAX_KEYS_PER_CRYPT,
454
		FMT_CASE | FMT_8_BIT,
455
		wpapsk_tests
456
	}, {
457
		wpapsk_init,
458
		valid,
459
		fmt_default_split,
460
		wpapsk_binary,
461
		wpapsk_salt,
462
		{
463
			fmt_default_binary_hash,
464
			fmt_default_binary_hash,
465
			fmt_default_binary_hash
466
		},
467
		fmt_default_salt_hash,
468
		wpapsk_set_salt,
469
		wpapsk_set_key,
470
		wpapsk_get_key,
471
		fmt_default_clear_keys,
472
		wpapsk_crypt_all,
473
		{
474
			fmt_default_get_hash,
475
			fmt_default_get_hash,
476
			fmt_default_get_hash
477
		},
478
		wpapsk_cmp_all,
479
		wpapsk_cmp_one,
480
		wpapsk_cmp_exact
481
	}
482
};
(-)john-1.7.0.1/src/alpha.S (+3 lines)
Lines 318-320 Link Here
318
.space 128
318
.space 128
319
319
320
.comm DES_KS_table, (8 * 128 * 16 * 8), 128
320
.comm DES_KS_table, (8 * 128 * 16 * 8), 128
321
#ifdef __ELF__
322
.section .note.GNU-stack,"",@progbits
323
#endif
(-)john-1.7.0.1/src/base64.c (+74 lines)
Line 0 Link Here
1
2
#include <stdio.h>
3
#include <string.h>
4
#include <sys/types.h>
5
#include <sys/stat.h>
6
7
void base64_unmap(char *in_block) {
8
  int i;
9
  unsigned char *c;
10
  
11
  for(i=0; i<4; i++) {
12
    c = in_block + i;
13
    
14
    if(*c>='A' && *c<='Z') {
15
      *c -= 'A';
16
      continue;
17
    }
18
    
19
    if(*c>='a' && *c<='z') {
20
      *c -= 'a';
21
      *c += 26;
22
      continue;
23
    }
24
    
25
    if(*c == '+') {
26
      *c = 62;
27
      continue;
28
    }
29
    
30
    if(*c == '/') {
31
      *c = 63;
32
      continue;
33
    }
34
    
35
    if(*c == '=') {
36
      *c = 0;
37
    }
38
    
39
    *c -= '0';
40
    *c += 52;
41
  }
42
}
43
44
int base64_decode(char *in, int inlen, char *out) {
45
  int i;
46
  char *in_block;
47
  char *out_block;
48
  char temp[4];
49
50
  out_block = out;
51
  in_block = in;
52
53
  for(i=0; i<inlen; i+=4) {
54
55
    if(*in_block == '=')
56
      return 0;
57
58
    memcpy(temp, in_block, 4);
59
    memset(out_block, 0, 3);
60
    base64_unmap(temp);
61
62
    out_block[0] = 
63
      ((temp[0]<<2) & 0xfc) | ((temp[1]>>4) & 3);
64
    out_block[1] = 
65
      ((temp[1]<<4) & 0xf0) | ((temp[2]>>2) & 0xf);
66
    out_block[2] = 
67
      ((temp[2]<<6) & 0xc0) | ((temp[3]   ) & 0x3f);
68
69
    out_block += 3;
70
    in_block += 4;
71
  }
72
  
73
  return 0;
74
}
(-)john-1.7.0.1/src/base64.h (+6 lines)
Line 0 Link Here
1
#ifndef _BASE64_H
2
#define _BASE64_H
3
4
int base64_decode(char *in, int inlen, char *out);
5
6
#endif
(-)john-1.7.0.1/src/bf_tab.h (+277 lines)
Line 0 Link Here
1
/* bf_tab.h: Blowfish P-box and S-box tables */
2
#ifndef _H_TAB_BF
3
#define _H_TAB_BF
4
5
static UWORD_32bits initbf_P[bf_N + 2] =
6
{
7
  0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344,
8
  0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89,
9
  0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c,
10
  0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917,
11
  0x9216d5d9, 0x8979fb1b,
12
};
13
static UWORD_32bits initbf_S[4][256] =
14
{
15
  {
16
    0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7,
17
    0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99,
18
    0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16,
19
    0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e,
20
    0x0d95748f, 0x728eb658, 0x718bcd58, 0x82154aee,
21
    0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013,
22
    0xc5d1b023, 0x286085f0, 0xca417918, 0xb8db38ef,
23
    0x8e79dcb0, 0x603a180e, 0x6c9e0e8b, 0xb01e8a3e,
24
    0xd71577c1, 0xbd314b27, 0x78af2fda, 0x55605c60,
25
    0xe65525f3, 0xaa55ab94, 0x57489862, 0x63e81440,
26
    0x55ca396a, 0x2aab10b6, 0xb4cc5c34, 0x1141e8ce,
27
    0xa15486af, 0x7c72e993, 0xb3ee1411, 0x636fbc2a,
28
    0x2ba9c55d, 0x741831f6, 0xce5c3e16, 0x9b87931e,
29
    0xafd6ba33, 0x6c24cf5c, 0x7a325381, 0x28958677,
30
    0x3b8f4898, 0x6b4bb9af, 0xc4bfe81b, 0x66282193,
31
    0x61d809cc, 0xfb21a991, 0x487cac60, 0x5dec8032,
32
    0xef845d5d, 0xe98575b1, 0xdc262302, 0xeb651b88,
33
    0x23893e81, 0xd396acc5, 0x0f6d6ff3, 0x83f44239,
34
    0x2e0b4482, 0xa4842004, 0x69c8f04a, 0x9e1f9b5e,
35
    0x21c66842, 0xf6e96c9a, 0x670c9c61, 0xabd388f0,
36
    0x6a51a0d2, 0xd8542f68, 0x960fa728, 0xab5133a3,
37
    0x6eef0b6c, 0x137a3be4, 0xba3bf050, 0x7efb2a98,
38
    0xa1f1651d, 0x39af0176, 0x66ca593e, 0x82430e88,
39
    0x8cee8619, 0x456f9fb4, 0x7d84a5c3, 0x3b8b5ebe,
40
    0xe06f75d8, 0x85c12073, 0x401a449f, 0x56c16aa6,
41
    0x4ed3aa62, 0x363f7706, 0x1bfedf72, 0x429b023d,
42
    0x37d0d724, 0xd00a1248, 0xdb0fead3, 0x49f1c09b,
43
    0x075372c9, 0x80991b7b, 0x25d479d8, 0xf6e8def7,
44
    0xe3fe501a, 0xb6794c3b, 0x976ce0bd, 0x04c006ba,
45
    0xc1a94fb6, 0x409f60c4, 0x5e5c9ec2, 0x196a2463,
46
    0x68fb6faf, 0x3e6c53b5, 0x1339b2eb, 0x3b52ec6f,
47
    0x6dfc511f, 0x9b30952c, 0xcc814544, 0xaf5ebd09,
48
    0xbee3d004, 0xde334afd, 0x660f2807, 0x192e4bb3,
49
    0xc0cba857, 0x45c8740f, 0xd20b5f39, 0xb9d3fbdb,
50
    0x5579c0bd, 0x1a60320a, 0xd6a100c6, 0x402c7279,
51
    0x679f25fe, 0xfb1fa3cc, 0x8ea5e9f8, 0xdb3222f8,
52
    0x3c7516df, 0xfd616b15, 0x2f501ec8, 0xad0552ab,
53
    0x323db5fa, 0xfd238760, 0x53317b48, 0x3e00df82,
54
    0x9e5c57bb, 0xca6f8ca0, 0x1a87562e, 0xdf1769db,
55
    0xd542a8f6, 0x287effc3, 0xac6732c6, 0x8c4f5573,
56
    0x695b27b0, 0xbbca58c8, 0xe1ffa35d, 0xb8f011a0,
57
    0x10fa3d98, 0xfd2183b8, 0x4afcb56c, 0x2dd1d35b,
58
    0x9a53e479, 0xb6f84565, 0xd28e49bc, 0x4bfb9790,
59
    0xe1ddf2da, 0xa4cb7e33, 0x62fb1341, 0xcee4c6e8,
60
    0xef20cada, 0x36774c01, 0xd07e9efe, 0x2bf11fb4,
61
    0x95dbda4d, 0xae909198, 0xeaad8e71, 0x6b93d5a0,
62
    0xd08ed1d0, 0xafc725e0, 0x8e3c5b2f, 0x8e7594b7,
63
    0x8ff6e2fb, 0xf2122b64, 0x8888b812, 0x900df01c,
64
    0x4fad5ea0, 0x688fc31c, 0xd1cff191, 0xb3a8c1ad,
65
    0x2f2f2218, 0xbe0e1777, 0xea752dfe, 0x8b021fa1,
66
    0xe5a0cc0f, 0xb56f74e8, 0x18acf3d6, 0xce89e299,
67
    0xb4a84fe0, 0xfd13e0b7, 0x7cc43b81, 0xd2ada8d9,
68
    0x165fa266, 0x80957705, 0x93cc7314, 0x211a1477,
69
    0xe6ad2065, 0x77b5fa86, 0xc75442f5, 0xfb9d35cf,
70
    0xebcdaf0c, 0x7b3e89a0, 0xd6411bd3, 0xae1e7e49,
71
    0x00250e2d, 0x2071b35e, 0x226800bb, 0x57b8e0af,
72
    0x2464369b, 0xf009b91e, 0x5563911d, 0x59dfa6aa,
73
    0x78c14389, 0xd95a537f, 0x207d5ba2, 0x02e5b9c5,
74
    0x83260376, 0x6295cfa9, 0x11c81968, 0x4e734a41,
75
    0xb3472dca, 0x7b14a94a, 0x1b510052, 0x9a532915,
76
    0xd60f573f, 0xbc9bc6e4, 0x2b60a476, 0x81e67400,
77
    0x08ba6fb5, 0x571be91f, 0xf296ec6b, 0x2a0dd915,
78
    0xb6636521, 0xe7b9f9b6, 0xff34052e, 0xc5855664,
79
    0x53b02d5d, 0xa99f8fa1, 0x08ba4799, 0x6e85076a},
80
  {
81
    0x4b7a70e9, 0xb5b32944, 0xdb75092e, 0xc4192623,
82
    0xad6ea6b0, 0x49a7df7d, 0x9cee60b8, 0x8fedb266,
83
    0xecaa8c71, 0x699a17ff, 0x5664526c, 0xc2b19ee1,
84
    0x193602a5, 0x75094c29, 0xa0591340, 0xe4183a3e,
85
    0x3f54989a, 0x5b429d65, 0x6b8fe4d6, 0x99f73fd6,
86
    0xa1d29c07, 0xefe830f5, 0x4d2d38e6, 0xf0255dc1,
87
    0x4cdd2086, 0x8470eb26, 0x6382e9c6, 0x021ecc5e,
88
    0x09686b3f, 0x3ebaefc9, 0x3c971814, 0x6b6a70a1,
89
    0x687f3584, 0x52a0e286, 0xb79c5305, 0xaa500737,
90
    0x3e07841c, 0x7fdeae5c, 0x8e7d44ec, 0x5716f2b8,
91
    0xb03ada37, 0xf0500c0d, 0xf01c1f04, 0x0200b3ff,
92
    0xae0cf51a, 0x3cb574b2, 0x25837a58, 0xdc0921bd,
93
    0xd19113f9, 0x7ca92ff6, 0x94324773, 0x22f54701,
94
    0x3ae5e581, 0x37c2dadc, 0xc8b57634, 0x9af3dda7,
95
    0xa9446146, 0x0fd0030e, 0xecc8c73e, 0xa4751e41,
96
    0xe238cd99, 0x3bea0e2f, 0x3280bba1, 0x183eb331,
97
    0x4e548b38, 0x4f6db908, 0x6f420d03, 0xf60a04bf,
98
    0x2cb81290, 0x24977c79, 0x5679b072, 0xbcaf89af,
99
    0xde9a771f, 0xd9930810, 0xb38bae12, 0xdccf3f2e,
100
    0x5512721f, 0x2e6b7124, 0x501adde6, 0x9f84cd87,
101
    0x7a584718, 0x7408da17, 0xbc9f9abc, 0xe94b7d8c,
102
    0xec7aec3a, 0xdb851dfa, 0x63094366, 0xc464c3d2,
103
    0xef1c1847, 0x3215d908, 0xdd433b37, 0x24c2ba16,
104
    0x12a14d43, 0x2a65c451, 0x50940002, 0x133ae4dd,
105
    0x71dff89e, 0x10314e55, 0x81ac77d6, 0x5f11199b,
106
    0x043556f1, 0xd7a3c76b, 0x3c11183b, 0x5924a509,
107
    0xf28fe6ed, 0x97f1fbfa, 0x9ebabf2c, 0x1e153c6e,
108
    0x86e34570, 0xeae96fb1, 0x860e5e0a, 0x5a3e2ab3,
109
    0x771fe71c, 0x4e3d06fa, 0x2965dcb9, 0x99e71d0f,
110
    0x803e89d6, 0x5266c825, 0x2e4cc978, 0x9c10b36a,
111
    0xc6150eba, 0x94e2ea78, 0xa5fc3c53, 0x1e0a2df4,
112
    0xf2f74ea7, 0x361d2b3d, 0x1939260f, 0x19c27960,
113
    0x5223a708, 0xf71312b6, 0xebadfe6e, 0xeac31f66,
114
    0xe3bc4595, 0xa67bc883, 0xb17f37d1, 0x018cff28,
115
    0xc332ddef, 0xbe6c5aa5, 0x65582185, 0x68ab9802,
116
    0xeecea50f, 0xdb2f953b, 0x2aef7dad, 0x5b6e2f84,
117
    0x1521b628, 0x29076170, 0xecdd4775, 0x619f1510,
118
    0x13cca830, 0xeb61bd96, 0x0334fe1e, 0xaa0363cf,
119
    0xb5735c90, 0x4c70a239, 0xd59e9e0b, 0xcbaade14,
120
    0xeecc86bc, 0x60622ca7, 0x9cab5cab, 0xb2f3846e,
121
    0x648b1eaf, 0x19bdf0ca, 0xa02369b9, 0x655abb50,
122
    0x40685a32, 0x3c2ab4b3, 0x319ee9d5, 0xc021b8f7,
123
    0x9b540b19, 0x875fa099, 0x95f7997e, 0x623d7da8,
124
    0xf837889a, 0x97e32d77, 0x11ed935f, 0x16681281,
125
    0x0e358829, 0xc7e61fd6, 0x96dedfa1, 0x7858ba99,
126
    0x57f584a5, 0x1b227263, 0x9b83c3ff, 0x1ac24696,
127
    0xcdb30aeb, 0x532e3054, 0x8fd948e4, 0x6dbc3128,
128
    0x58ebf2ef, 0x34c6ffea, 0xfe28ed61, 0xee7c3c73,
129
    0x5d4a14d9, 0xe864b7e3, 0x42105d14, 0x203e13e0,
130
    0x45eee2b6, 0xa3aaabea, 0xdb6c4f15, 0xfacb4fd0,
131
    0xc742f442, 0xef6abbb5, 0x654f3b1d, 0x41cd2105,
132
    0xd81e799e, 0x86854dc7, 0xe44b476a, 0x3d816250,
133
    0xcf62a1f2, 0x5b8d2646, 0xfc8883a0, 0xc1c7b6a3,
134
    0x7f1524c3, 0x69cb7492, 0x47848a0b, 0x5692b285,
135
    0x095bbf00, 0xad19489d, 0x1462b174, 0x23820e00,
136
    0x58428d2a, 0x0c55f5ea, 0x1dadf43e, 0x233f7061,
137
    0x3372f092, 0x8d937e41, 0xd65fecf1, 0x6c223bdb,
138
    0x7cde3759, 0xcbee7460, 0x4085f2a7, 0xce77326e,
139
    0xa6078084, 0x19f8509e, 0xe8efd855, 0x61d99735,
140
    0xa969a7aa, 0xc50c06c2, 0x5a04abfc, 0x800bcadc,
141
    0x9e447a2e, 0xc3453484, 0xfdd56705, 0x0e1e9ec9,
142
    0xdb73dbd3, 0x105588cd, 0x675fda79, 0xe3674340,
143
    0xc5c43465, 0x713e38d8, 0x3d28f89e, 0xf16dff20,
144
    0x153e21e7, 0x8fb03d4a, 0xe6e39f2b, 0xdb83adf7},
145
  {
146
    0xe93d5a68, 0x948140f7, 0xf64c261c, 0x94692934,
147
    0x411520f7, 0x7602d4f7, 0xbcf46b2e, 0xd4a20068,
148
    0xd4082471, 0x3320f46a, 0x43b7d4b7, 0x500061af,
149
    0x1e39f62e, 0x97244546, 0x14214f74, 0xbf8b8840,
150
    0x4d95fc1d, 0x96b591af, 0x70f4ddd3, 0x66a02f45,
151
    0xbfbc09ec, 0x03bd9785, 0x7fac6dd0, 0x31cb8504,
152
    0x96eb27b3, 0x55fd3941, 0xda2547e6, 0xabca0a9a,
153
    0x28507825, 0x530429f4, 0x0a2c86da, 0xe9b66dfb,
154
    0x68dc1462, 0xd7486900, 0x680ec0a4, 0x27a18dee,
155
    0x4f3ffea2, 0xe887ad8c, 0xb58ce006, 0x7af4d6b6,
156
    0xaace1e7c, 0xd3375fec, 0xce78a399, 0x406b2a42,
157
    0x20fe9e35, 0xd9f385b9, 0xee39d7ab, 0x3b124e8b,
158
    0x1dc9faf7, 0x4b6d1856, 0x26a36631, 0xeae397b2,
159
    0x3a6efa74, 0xdd5b4332, 0x6841e7f7, 0xca7820fb,
160
    0xfb0af54e, 0xd8feb397, 0x454056ac, 0xba489527,
161
    0x55533a3a, 0x20838d87, 0xfe6ba9b7, 0xd096954b,
162
    0x55a867bc, 0xa1159a58, 0xcca92963, 0x99e1db33,
163
    0xa62a4a56, 0x3f3125f9, 0x5ef47e1c, 0x9029317c,
164
    0xfdf8e802, 0x04272f70, 0x80bb155c, 0x05282ce3,
165
    0x95c11548, 0xe4c66d22, 0x48c1133f, 0xc70f86dc,
166
    0x07f9c9ee, 0x41041f0f, 0x404779a4, 0x5d886e17,
167
    0x325f51eb, 0xd59bc0d1, 0xf2bcc18f, 0x41113564,
168
    0x257b7834, 0x602a9c60, 0xdff8e8a3, 0x1f636c1b,
169
    0x0e12b4c2, 0x02e1329e, 0xaf664fd1, 0xcad18115,
170
    0x6b2395e0, 0x333e92e1, 0x3b240b62, 0xeebeb922,
171
    0x85b2a20e, 0xe6ba0d99, 0xde720c8c, 0x2da2f728,
172
    0xd0127845, 0x95b794fd, 0x647d0862, 0xe7ccf5f0,
173
    0x5449a36f, 0x877d48fa, 0xc39dfd27, 0xf33e8d1e,
174
    0x0a476341, 0x992eff74, 0x3a6f6eab, 0xf4f8fd37,
175
    0xa812dc60, 0xa1ebddf8, 0x991be14c, 0xdb6e6b0d,
176
    0xc67b5510, 0x6d672c37, 0x2765d43b, 0xdcd0e804,
177
    0xf1290dc7, 0xcc00ffa3, 0xb5390f92, 0x690fed0b,
178
    0x667b9ffb, 0xcedb7d9c, 0xa091cf0b, 0xd9155ea3,
179
    0xbb132f88, 0x515bad24, 0x7b9479bf, 0x763bd6eb,
180
    0x37392eb3, 0xcc115979, 0x8026e297, 0xf42e312d,
181
    0x6842ada7, 0xc66a2b3b, 0x12754ccc, 0x782ef11c,
182
    0x6a124237, 0xb79251e7, 0x06a1bbe6, 0x4bfb6350,
183
    0x1a6b1018, 0x11caedfa, 0x3d25bdd8, 0xe2e1c3c9,
184
    0x44421659, 0x0a121386, 0xd90cec6e, 0xd5abea2a,
185
    0x64af674e, 0xda86a85f, 0xbebfe988, 0x64e4c3fe,
186
    0x9dbc8057, 0xf0f7c086, 0x60787bf8, 0x6003604d,
187
    0xd1fd8346, 0xf6381fb0, 0x7745ae04, 0xd736fccc,
188
    0x83426b33, 0xf01eab71, 0xb0804187, 0x3c005e5f,
189
    0x77a057be, 0xbde8ae24, 0x55464299, 0xbf582e61,
190
    0x4e58f48f, 0xf2ddfda2, 0xf474ef38, 0x8789bdc2,
191
    0x5366f9c3, 0xc8b38e74, 0xb475f255, 0x46fcd9b9,
192
    0x7aeb2661, 0x8b1ddf84, 0x846a0e79, 0x915f95e2,
193
    0x466e598e, 0x20b45770, 0x8cd55591, 0xc902de4c,
194
    0xb90bace1, 0xbb8205d0, 0x11a86248, 0x7574a99e,
195
    0xb77f19b6, 0xe0a9dc09, 0x662d09a1, 0xc4324633,
196
    0xe85a1f02, 0x09f0be8c, 0x4a99a025, 0x1d6efe10,
197
    0x1ab93d1d, 0x0ba5a4df, 0xa186f20f, 0x2868f169,
198
    0xdcb7da83, 0x573906fe, 0xa1e2ce9b, 0x4fcd7f52,
199
    0x50115e01, 0xa70683fa, 0xa002b5c4, 0x0de6d027,
200
    0x9af88c27, 0x773f8641, 0xc3604c06, 0x61a806b5,
201
    0xf0177a28, 0xc0f586e0, 0x006058aa, 0x30dc7d62,
202
    0x11e69ed7, 0x2338ea63, 0x53c2dd94, 0xc2c21634,
203
    0xbbcbee56, 0x90bcb6de, 0xebfc7da1, 0xce591d76,
204
    0x6f05e409, 0x4b7c0188, 0x39720a3d, 0x7c927c24,
205
    0x86e3725f, 0x724d9db9, 0x1ac15bb4, 0xd39eb8fc,
206
    0xed545578, 0x08fca5b5, 0xd83d7cd3, 0x4dad0fc4,
207
    0x1e50ef5e, 0xb161e6f8, 0xa28514d9, 0x6c51133c,
208
    0x6fd5c7e7, 0x56e14ec4, 0x362abfce, 0xddc6c837,
209
    0xd79a3234, 0x92638212, 0x670efa8e, 0x406000e0},
210
  {
211
    0x3a39ce37, 0xd3faf5cf, 0xabc27737, 0x5ac52d1b,
212
    0x5cb0679e, 0x4fa33742, 0xd3822740, 0x99bc9bbe,
213
    0xd5118e9d, 0xbf0f7315, 0xd62d1c7e, 0xc700c47b,
214
    0xb78c1b6b, 0x21a19045, 0xb26eb1be, 0x6a366eb4,
215
    0x5748ab2f, 0xbc946e79, 0xc6a376d2, 0x6549c2c8,
216
    0x530ff8ee, 0x468dde7d, 0xd5730a1d, 0x4cd04dc6,
217
    0x2939bbdb, 0xa9ba4650, 0xac9526e8, 0xbe5ee304,
218
    0xa1fad5f0, 0x6a2d519a, 0x63ef8ce2, 0x9a86ee22,
219
    0xc089c2b8, 0x43242ef6, 0xa51e03aa, 0x9cf2d0a4,
220
    0x83c061ba, 0x9be96a4d, 0x8fe51550, 0xba645bd6,
221
    0x2826a2f9, 0xa73a3ae1, 0x4ba99586, 0xef5562e9,
222
    0xc72fefd3, 0xf752f7da, 0x3f046f69, 0x77fa0a59,
223
    0x80e4a915, 0x87b08601, 0x9b09e6ad, 0x3b3ee593,
224
    0xe990fd5a, 0x9e34d797, 0x2cf0b7d9, 0x022b8b51,
225
    0x96d5ac3a, 0x017da67d, 0xd1cf3ed6, 0x7c7d2d28,
226
    0x1f9f25cf, 0xadf2b89b, 0x5ad6b472, 0x5a88f54c,
227
    0xe029ac71, 0xe019a5e6, 0x47b0acfd, 0xed93fa9b,
228
    0xe8d3c48d, 0x283b57cc, 0xf8d56629, 0x79132e28,
229
    0x785f0191, 0xed756055, 0xf7960e44, 0xe3d35e8c,
230
    0x15056dd4, 0x88f46dba, 0x03a16125, 0x0564f0bd,
231
    0xc3eb9e15, 0x3c9057a2, 0x97271aec, 0xa93a072a,
232
    0x1b3f6d9b, 0x1e6321f5, 0xf59c66fb, 0x26dcf319,
233
    0x7533d928, 0xb155fdf5, 0x03563482, 0x8aba3cbb,
234
    0x28517711, 0xc20ad9f8, 0xabcc5167, 0xccad925f,
235
    0x4de81751, 0x3830dc8e, 0x379d5862, 0x9320f991,
236
    0xea7a90c2, 0xfb3e7bce, 0x5121ce64, 0x774fbe32,
237
    0xa8b6e37e, 0xc3293d46, 0x48de5369, 0x6413e680,
238
    0xa2ae0810, 0xdd6db224, 0x69852dfd, 0x09072166,
239
    0xb39a460a, 0x6445c0dd, 0x586cdecf, 0x1c20c8ae,
240
    0x5bbef7dd, 0x1b588d40, 0xccd2017f, 0x6bb4e3bb,
241
    0xdda26a7e, 0x3a59ff45, 0x3e350a44, 0xbcb4cdd5,
242
    0x72eacea8, 0xfa6484bb, 0x8d6612ae, 0xbf3c6f47,
243
    0xd29be463, 0x542f5d9e, 0xaec2771b, 0xf64e6370,
244
    0x740e0d8d, 0xe75b1357, 0xf8721671, 0xaf537d5d,
245
    0x4040cb08, 0x4eb4e2cc, 0x34d2466a, 0x0115af84,
246
    0xe1b00428, 0x95983a1d, 0x06b89fb4, 0xce6ea048,
247
    0x6f3f3b82, 0x3520ab82, 0x011a1d4b, 0x277227f8,
248
    0x611560b1, 0xe7933fdc, 0xbb3a792b, 0x344525bd,
249
    0xa08839e1, 0x51ce794b, 0x2f32c9b7, 0xa01fbac9,
250
    0xe01cc87e, 0xbcc7d1f6, 0xcf0111c3, 0xa1e8aac7,
251
    0x1a908749, 0xd44fbd9a, 0xd0dadecb, 0xd50ada38,
252
    0x0339c32a, 0xc6913667, 0x8df9317c, 0xe0b12b4f,
253
    0xf79e59b7, 0x43f5bb3a, 0xf2d519ff, 0x27d9459c,
254
    0xbf97222c, 0x15e6fc2a, 0x0f91fc71, 0x9b941525,
255
    0xfae59361, 0xceb69ceb, 0xc2a86459, 0x12baa8d1,
256
    0xb6c1075e, 0xe3056a0c, 0x10d25065, 0xcb03a442,
257
    0xe0ec6e0e, 0x1698db3b, 0x4c98a0be, 0x3278e964,
258
    0x9f1f9532, 0xe0d392df, 0xd3a0342b, 0x8971f21e,
259
    0x1b0a7441, 0x4ba3348c, 0xc5be7120, 0xc37632d8,
260
    0xdf359f8d, 0x9b992f2e, 0xe60b6f47, 0x0fe3f11d,
261
    0xe54cda54, 0x1edad891, 0xce6279cf, 0xcd3e7e6f,
262
    0x1618b166, 0xfd2c1d05, 0x848fd2c5, 0xf6fb2299,
263
    0xf523f357, 0xa6327623, 0x93a83531, 0x56cccd02,
264
    0xacf08162, 0x5a75ebb5, 0x6e163697, 0x88d273cc,
265
    0xde966292, 0x81b949d0, 0x4c50901b, 0x71c65614,
266
    0xe6c6c7bd, 0x327a140a, 0x45e1d006, 0xc3f27b9a,
267
    0xc9aa53fd, 0x62a80f00, 0xbb25bfe2, 0x35bdd2f6,
268
    0x71126905, 0xb2040222, 0xb6cbcf7c, 0xcd769c2b,
269
    0x53113ec0, 0x1640e3d3, 0x38abbd60, 0x2547adf0,
270
    0xba38209c, 0xf746ce76, 0x77afa1c5, 0x20756060,
271
    0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e,
272
    0x1948c25c, 0x02fb8a8c, 0x01c36ae4, 0xd6ebe1f9,
273
    0x90d4f869, 0xa65cdea0, 0x3f09252d, 0xc208e69f,
274
    0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6}
275
};
276
277
#endif
(-)john-1.7.0.1/src/blowfish.c (+186 lines)
Line 0 Link Here
1
/* 
2
 * blowfish.c - part of blowfish.mod
3
 * handles: encryption and decryption of passwords
4
 */
5
/* 
6
 * The first half of this is very lightly edited from public domain
7
 * sourcecode.  For simplicity, this entire module will remain public
8
 * domain.
9
 */
10
/* 
11
 * This is ripped from eggdrop 1.3.28's source files (blowfish.mod)
12
 * Modified by Sun-Zero <sun-zero@freemail.hu>
13
 * 2002-04-16
14
*/
15
16
#include <stdlib.h>
17
18
#include "blowfish.h"
19
#include "bf_tab.h"		/* P-box P-array, S-box */
20
21
/* #define S(x,i) (bf_S[i][x.w.byte##i]) */
22
#define S0(x) (bf_S[0][x.w.byte0])
23
#define S1(x) (bf_S[1][x.w.byte1])
24
#define S2(x) (bf_S[2][x.w.byte2])
25
#define S3(x) (bf_S[3][x.w.byte3])
26
#define bf_F(x) (((S0(x) + S1(x)) ^ S2(x)) + S3(x))
27
#define ROUND(a,b,n) (a.word ^= bf_F(b) ^ bf_P[n])
28
29
#include <time.h>
30
31
/* keep a set of rotating P & S boxes */
32
static struct box_t {
33
  UWORD_32bits *P;
34
  UWORD_32bits **S;
35
  char key[81];
36
  char keybytes;
37
} box;
38
39
//static UWORD_32bits bf_P[bf_N+2];
40
//static UWORD_32bits bf_S[4][256];
41
static UWORD_32bits *bf_P;
42
static UWORD_32bits **bf_S;
43
44
45
void blowfish_first_init(void) {
46
      box.P = NULL;
47
      box.S = NULL;
48
      box.key[0] = 0;
49
}
50
51
static void blowfish_encipher(UWORD_32bits * xl, UWORD_32bits * xr)
52
{
53
  union aword Xl;
54
  union aword Xr;
55
56
  Xl.word = *xl;
57
  Xr.word = *xr;
58
59
  Xl.word ^= bf_P[0];
60
  ROUND(Xr, Xl, 1);
61
  ROUND(Xl, Xr, 2);
62
  ROUND(Xr, Xl, 3);
63
  ROUND(Xl, Xr, 4);
64
  ROUND(Xr, Xl, 5);
65
  ROUND(Xl, Xr, 6);
66
  ROUND(Xr, Xl, 7);
67
  ROUND(Xl, Xr, 8);
68
  ROUND(Xr, Xl, 9);
69
  ROUND(Xl, Xr, 10);
70
  ROUND(Xr, Xl, 11);
71
  ROUND(Xl, Xr, 12);
72
  ROUND(Xr, Xl, 13);
73
  ROUND(Xl, Xr, 14);
74
  ROUND(Xr, Xl, 15);
75
  ROUND(Xl, Xr, 16);
76
  Xr.word ^= bf_P[17];
77
78
  *xr = Xl.word;
79
  *xl = Xr.word;
80
}
81
82
static void blowfish_init(UBYTE_08bits * key, short keybytes)
83
{
84
  int i, j;
85
  UWORD_32bits data;
86
  UWORD_32bits datal;
87
  UWORD_32bits datar;
88
  union aword temp;
89
90
  /* is buffer already allocated for this? */
91
  if (box.P != NULL) {
92
      if ((box.keybytes == keybytes) &&
93
	  (!strncmp((char *) (box.key), (char *) key, keybytes))) {
94
	/* match! */
95
	bf_P = box.P;
96
	bf_S = box.S;
97
	return;
98
      }
99
        free(box.P);
100
        for (i = 0; i < 4; i++)
101
          free(box.S[i]);
102
        free(box.S);
103
  }
104
  /* initialize new buffer */
105
  /* uh... this is over 4k */
106
  box.P = (UWORD_32bits *) malloc((bf_N + 2) * sizeof(UWORD_32bits));
107
  box.S = (UWORD_32bits **) malloc(4 * sizeof(UWORD_32bits *));
108
  for (i = 0; i < 4; i++)
109
    box.S[i] = (UWORD_32bits *) malloc(256 * sizeof(UWORD_32bits));
110
  bf_P = box.P;
111
  bf_S = box.S;
112
  box.keybytes = keybytes;
113
  strncpy(box.key, key, keybytes);
114
  /* robey: reset blowfish boxes to initial state */
115
  /* (i guess normally it just keeps scrambling them, but here it's
116
   * important to get the same encrypted result each time) */
117
  for (i = 0; i < bf_N + 2; i++)
118
    bf_P[i] = initbf_P[i];
119
  for (i = 0; i < 4; i++)
120
    for (j = 0; j < 256; j++)
121
      bf_S[i][j] = initbf_S[i][j];
122
123
  j = 0;
124
  for (i = 0; i < bf_N + 2; ++i) {
125
    temp.word = 0;
126
    temp.w.byte0 = key[j];
127
    temp.w.byte1 = key[(j + 1) % keybytes];
128
    temp.w.byte2 = key[(j + 2) % keybytes];
129
    temp.w.byte3 = key[(j + 3) % keybytes];
130
    data = temp.word;
131
    bf_P[i] = bf_P[i] ^ data;
132
    j = (j + 4) % keybytes;
133
  }
134
  datal = 0x00000000;
135
  datar = 0x00000000;
136
  for (i = 0; i < bf_N + 2; i += 2) {
137
    blowfish_encipher(&datal, &datar);
138
    bf_P[i] = datal;
139
    bf_P[i + 1] = datar;
140
  }
141
  for (i = 0; i < 4; ++i) {
142
    for (j = 0; j < 256; j += 2) {
143
      blowfish_encipher(&datal, &datar);
144
      bf_S[i][j] = datal;
145
      bf_S[i][j + 1] = datar;
146
    }
147
  }
148
}
149
150
/* stuff below this line was written by robey for eggdrop use */
151
152
/* of course, if you change either of these, then your userfile will
153
 * no longer be able to be shared. :) */
154
#define SALT1  0xdeadd061
155
#define SALT2  0x23f6b095
156
157
/* convert 64-bit encrypted password to text for userfile */
158
static char *base64 = "./0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
159
160
static void blowfish_encrypt_pass(char *text, char *new)
161
{
162
  UWORD_32bits left, right;
163
  int n;
164
  char *p;
165
166
  blowfish_init(text, strlen(text));
167
  left = SALT1;
168
  right = SALT2;
169
  blowfish_encipher(&left, &right);
170
  p = new;
171
  *p++ = '+';			/* + means encrypted pass */
172
  n = 32;
173
  while (n > 0) {
174
    *p++ = base64[right & 0x3f];
175
    right = (right >> 6);
176
    n -= 6;
177
  }
178
  n = 32;
179
  while (n > 0) {
180
    *p++ = base64[left & 0x3f];
181
    left = (left >> 6);
182
    n -= 6;
183
  }
184
  *p = 0;
185
}
186
(-)john-1.7.0.1/src/blowfish.h (+55 lines)
Line 0 Link Here
1
/* modified 19jul1996 by robey -- uses autoconf values now */
2
#ifndef _H_BLOWFISH
3
#define _H_BLOWFISH
4
5
#include "arch.h"
6
7
#define bf_N             16
8
#define noErr            0
9
#define DATAERROR        -1
10
11
#define UBYTE_08bits  unsigned char
12
#define UWORD_16bits  unsigned short
13
14
#define SIZEOF_INT 4
15
16
#if SIZEOF_INT==4
17
#define UWORD_32bits  unsigned int
18
#else
19
#if SIZEOF_LONG==4
20
#define UWORD_32bits  unsigned long
21
#endif
22
#endif
23
24
/* choose a byte order for your hardware */
25
26
#if !ARCH_LITTLE_ENDIAN
27
/* ABCD - big endian - motorola */
28
union aword {
29
  UWORD_32bits word;
30
  UBYTE_08bits byte[4];
31
  struct {
32
    unsigned int byte0:8;
33
    unsigned int byte1:8;
34
    unsigned int byte2:8;
35
    unsigned int byte3:8;
36
  } w;
37
};
38
#endif				/* !ARCH_LITTLE_ENDIAN */
39
40
#if ARCH_LITTLE_ENDIAN
41
/* DCBA - little endian - intel */
42
union aword {
43
  UWORD_32bits word;
44
  UBYTE_08bits byte[4];
45
  struct {
46
    unsigned int byte3:8;
47
    unsigned int byte2:8;
48
    unsigned int byte1:8;
49
    unsigned int byte0:8;
50
  } w;
51
};
52
53
#endif				/* ARCH_LITTLE_ENDIAN */
54
55
#endif
(-)john-1.7.0.1/src/byteorder.h (+274 lines)
Line 0 Link Here
1
/* 
2
   Unix SMB/Netbios implementation.
3
   Version 1.9.
4
   SMB Byte handling
5
   Copyright (C) Andrew Tridgell 1992-1998
6
   
7
   This program is free software; you can redistribute it and/or modify
8
   it under the terms of the GNU General Public License as published by
9
   the Free Software Foundation; either version 2 of the License, or
10
   (at your option) any later version.
11
   
12
   This program is distributed in the hope that it will be useful,
13
   but WITHOUT ANY WARRANTY; without even the implied warranty of
14
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
   GNU General Public License for more details.
16
   
17
   You should have received a copy of the GNU General Public License
18
   along with this program; if not, write to the Free Software
19
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
*/
21
22
#ifndef _BYTEORDER_H
23
#define _BYTEORDER_H
24
25
/*
26
   This file implements macros for machine independent short and 
27
   int manipulation
28
29
Here is a description of this file that I emailed to the samba list once:
30
31
> I am confused about the way that byteorder.h works in Samba. I have
32
> looked at it, and I would have thought that you might make a distinction
33
> between LE and BE machines, but you only seem to distinguish between 386
34
> and all other architectures.
35
> 
36
> Can you give me a clue?
37
38
sure.
39
40
The distinction between 386 and other architectures is only there as
41
an optimisation. You can take it out completely and it will make no
42
difference. The routines (macros) in byteorder.h are totally byteorder
43
independent. The 386 optimsation just takes advantage of the fact that
44
the x86 processors don't care about alignment, so we don't have to
45
align ints on int boundaries etc. If there are other processors out
46
there that aren't alignment sensitive then you could also define
47
CAREFUL_ALIGNMENT=0 on those processors as well.
48
49
Ok, now to the macros themselves. I'll take a simple example, say we
50
want to extract a 2 byte integer from a SMB packet and put it into a
51
type called uint16 that is in the local machines byte order, and you
52
want to do it with only the assumption that uint16 is _at_least_ 16
53
bits long (this last condition is very important for architectures
54
that don't have any int types that are 2 bytes long)
55
56
You do this:
57
58
#define CVAL(buf,pos) (((unsigned char *)(buf))[pos])
59
#define PVAL(buf,pos) ((unsigned)CVAL(buf,pos))
60
#define SVAL(buf,pos) (PVAL(buf,pos)|PVAL(buf,(pos)+1)<<8)
61
62
then to extract a uint16 value at offset 25 in a buffer you do this:
63
64
char *buffer = foo_bar();
65
uint16 xx = SVAL(buffer,25);
66
67
We are using the byteoder independence of the ANSI C bitshifts to do
68
the work. A good optimising compiler should turn this into efficient
69
code, especially if it happens to have the right byteorder :-)
70
71
I know these macros can be made a bit tidier by removing some of the
72
casts, but you need to look at byteorder.h as a whole to see the
73
reasoning behind them. byteorder.h defines the following macros:
74
75
SVAL(buf,pos) - extract a 2 byte SMB value
76
IVAL(buf,pos) - extract a 4 byte SMB value
77
SVALS(buf,pos) signed version of SVAL()
78
IVALS(buf,pos) signed version of IVAL()
79
80
SSVAL(buf,pos,val) - put a 2 byte SMB value into a buffer
81
SIVAL(buf,pos,val) - put a 4 byte SMB value into a buffer
82
SSVALS(buf,pos,val) - signed version of SSVAL()
83
SIVALS(buf,pos,val) - signed version of SIVAL()
84
85
RSVAL(buf,pos) - like SVAL() but for NMB byte ordering
86
RSVALS(buf,pos) - like SVALS() but for NMB byte ordering
87
RIVAL(buf,pos) - like IVAL() but for NMB byte ordering
88
RIVALS(buf,pos) - like IVALS() but for NMB byte ordering
89
RSSVAL(buf,pos,val) - like SSVAL() but for NMB ordering
90
RSIVAL(buf,pos,val) - like SIVAL() but for NMB ordering
91
RSIVALS(buf,pos,val) - like SIVALS() but for NMB ordering
92
93
it also defines lots of intermediate macros, just ignore those :-)
94
95
*/
96
97
/* some switch macros that do both store and read to and from SMB buffers */
98
99
#define RW_PCVAL(read,inbuf,outbuf,len) \
100
	{ if (read) { PCVAL (inbuf,0,outbuf,len); } \
101
	else      { PSCVAL(inbuf,0,outbuf,len); } }
102
103
#define RW_PIVAL(read,big_endian,inbuf,outbuf,len) \
104
	{ if (read) { if (big_endian) { RPIVAL(inbuf,0,outbuf,len); } else { PIVAL(inbuf,0,outbuf,len); } } \
105
	else      { if (big_endian) { RPSIVAL(inbuf,0,outbuf,len); } else { PSIVAL(inbuf,0,outbuf,len); } } }
106
107
#define RW_PSVAL(read,big_endian,inbuf,outbuf,len) \
108
	{ if (read) { if (big_endian) { RPSVAL(inbuf,0,outbuf,len); } else { PSVAL(inbuf,0,outbuf,len); } } \
109
	else      { if (big_endian) { RPSSVAL(inbuf,0,outbuf,len); } else { PSSVAL(inbuf,0,outbuf,len); } } }
110
111
#define RW_CVAL(read, inbuf, outbuf, offset) \
112
	{ if (read) { (outbuf) = CVAL (inbuf,offset); } \
113
	else      { SCVAL(inbuf,offset,outbuf); } }
114
115
#define RW_IVAL(read, big_endian, inbuf, outbuf, offset) \
116
	{ if (read) { (outbuf) = ((big_endian) ? RIVAL(inbuf,offset) : IVAL (inbuf,offset)); } \
117
	else      { if (big_endian) { RSIVAL(inbuf,offset,outbuf); } else { SIVAL(inbuf,offset,outbuf); } } }
118
119
#define RW_SVAL(read, big_endian, inbuf, outbuf, offset) \
120
	{ if (read) { (outbuf) = ((big_endian) ? RSVAL(inbuf,offset) : SVAL (inbuf,offset)); } \
121
	else      { if (big_endian) { RSSVAL(inbuf,offset,outbuf); } else { SSVAL(inbuf,offset,outbuf); } } }
122
123
#undef CAREFUL_ALIGNMENT
124
125
/* we know that the 386 can handle misalignment and has the "right" 
126
   byteorder */
127
#ifdef __i386__
128
#define CAREFUL_ALIGNMENT 0
129
#endif
130
131
#ifndef CAREFUL_ALIGNMENT
132
#define CAREFUL_ALIGNMENT 1
133
#endif
134
135
#define CVAL(buf,pos) (((unsigned char *)(buf))[pos])
136
#define PVAL(buf,pos) ((unsigned)CVAL(buf,pos))
137
#define SCVAL(buf,pos,val) (CVAL(buf,pos) = (val))
138
139
140
#if CAREFUL_ALIGNMENT
141
142
#define SVAL(buf,pos) (PVAL(buf,pos)|PVAL(buf,(pos)+1)<<8)
143
#define IVAL(buf,pos) (SVAL(buf,pos)|SVAL(buf,(pos)+2)<<16)
144
#define SSVALX(buf,pos,val) (CVAL(buf,pos)=(val)&0xFF,CVAL(buf,pos+1)=(val)>>8)
145
#define SIVALX(buf,pos,val) (SSVALX(buf,pos,val&0xFFFF),SSVALX(buf,pos+2,val>>16))
146
#define SVALS(buf,pos) ((int16)SVAL(buf,pos))
147
#define IVALS(buf,pos) ((int32)IVAL(buf,pos))
148
#define SSVAL(buf,pos,val) SSVALX((buf),(pos),((uint16)(val)))
149
#define SIVAL(buf,pos,val) SIVALX((buf),(pos),((uint32)(val)))
150
#define SSVALS(buf,pos,val) SSVALX((buf),(pos),((int16)(val)))
151
#define SIVALS(buf,pos,val) SIVALX((buf),(pos),((int32)(val)))
152
153
#else /* CAREFUL_ALIGNMENT */
154
155
/* this handles things for architectures like the 386 that can handle
156
   alignment errors */
157
/*
158
   WARNING: This section is dependent on the length of int16 and int32
159
   being correct 
160
*/
161
162
/* get single value from an SMB buffer */
163
#define SVAL(buf,pos) (*(const uint16 *)((const char *)(buf) + (pos)))
164
#define IVAL(buf,pos) (*(const uint32 *)((const char *)(buf) + (pos)))
165
#define SVALS(buf,pos) (*(const int16 *)((const char *)(buf) + (pos)))
166
#define IVALS(buf,pos) (*(const int32 *)((const char *)(buf) + (pos)))
167
168
/* store single value in an SMB buffer */
169
#define SVALMOD(buf,pos) (*(uint16 *)((char *)(buf) + (pos)))
170
#define IVALMOD(buf,pos) (*(uint32 *)((char *)(buf) + (pos)))
171
#define SVALSMOD(buf,pos) (*(int16 *)((char *)(buf) + (pos)))
172
#define IVALSMOD(buf,pos) (*(int32 *)((char *)(buf) + (pos)))
173
174
#define SSVAL(buf,pos,val) SVALMOD(buf,pos)=((uint16)(val))
175
#define SIVAL(buf,pos,val) IVALMOD(buf,pos)=((uint32)(val))
176
#define SSVALS(buf,pos,val) SVALSMOD(buf,pos)=((int16)(val))
177
#define SIVALS(buf,pos,val) IVALSMOD(buf,pos)=((int32)(val))
178
179
#endif /* CAREFUL_ALIGNMENT */
180
181
/* macros for reading / writing arrays */
182
183
#define SMBMACRO(macro,buf,pos,val,len,size) \
184
{ uint32 l; for (l = 0; l < (uint32)(len); l++) (val)[l] = macro((buf), (pos) + (size)*l); }
185
186
#define SSMBMACRO(macro,buf,pos,val,len,size) \
187
{ uint32 l; for (l = 0; l < (uint32)(len); l++) macro((buf), (pos) + (size)*l, (val)[l]); }
188
189
/* reads multiple data from an SMB buffer */
190
#define PCVAL(buf,pos,val,len) SMBMACRO(CVAL,buf,pos,val,len,1)
191
#define PSVAL(buf,pos,val,len) SMBMACRO(SVAL,buf,pos,val,len,2)
192
#define PIVAL(buf,pos,val,len) SMBMACRO(IVAL,buf,pos,val,len,4)
193
#define PCVALS(buf,pos,val,len) SMBMACRO(CVALS,buf,pos,val,len,1)
194
#define PSVALS(buf,pos,val,len) SMBMACRO(SVALS,buf,pos,val,len,2)
195
#define PIVALS(buf,pos,val,len) SMBMACRO(IVALS,buf,pos,val,len,4)
196
197
/* stores multiple data in an SMB buffer */
198
#define PSCVAL(buf,pos,val,len) SSMBMACRO(SCVAL,buf,pos,val,len,1)
199
#define PSSVAL(buf,pos,val,len) SSMBMACRO(SSVAL,buf,pos,val,len,2)
200
#define PSIVAL(buf,pos,val,len) SSMBMACRO(SIVAL,buf,pos,val,len,4)
201
#define PSCVALS(buf,pos,val,len) SSMBMACRO(SCVALS,buf,pos,val,len,1)
202
#define PSSVALS(buf,pos,val,len) SSMBMACRO(SSVALS,buf,pos,val,len,2)
203
#define PSIVALS(buf,pos,val,len) SSMBMACRO(SIVALS,buf,pos,val,len,4)
204
205
206
/* now the reverse routines - these are used in nmb packets (mostly) */
207
#define SREV(x) ((((x)&0xFF)<<8) | (((x)>>8)&0xFF))
208
#define IREV(x) ((SREV(x)<<16) | (SREV((x)>>16)))
209
210
#define RSVAL(buf,pos) SREV(SVAL(buf,pos))
211
#define RSVALS(buf,pos) SREV(SVALS(buf,pos))
212
#define RIVAL(buf,pos) IREV(IVAL(buf,pos))
213
#define RIVALS(buf,pos) IREV(IVALS(buf,pos))
214
#define RSSVAL(buf,pos,val) SSVAL(buf,pos,SREV(val))
215
#define RSSVALS(buf,pos,val) SSVALS(buf,pos,SREV(val))
216
#define RSIVAL(buf,pos,val) SIVAL(buf,pos,IREV(val))
217
#define RSIVALS(buf,pos,val) SIVALS(buf,pos,IREV(val))
218
219
/* reads multiple data from an SMB buffer (big-endian) */
220
#define RPSVAL(buf,pos,val,len) SMBMACRO(RSVAL,buf,pos,val,len,2)
221
#define RPIVAL(buf,pos,val,len) SMBMACRO(RIVAL,buf,pos,val,len,4)
222
#define RPSVALS(buf,pos,val,len) SMBMACRO(RSVALS,buf,pos,val,len,2)
223
#define RPIVALS(buf,pos,val,len) SMBMACRO(RIVALS,buf,pos,val,len,4)
224
225
/* stores multiple data in an SMB buffer (big-endian) */
226
#define RPSSVAL(buf,pos,val,len) SSMBMACRO(RSSVAL,buf,pos,val,len,2)
227
#define RPSIVAL(buf,pos,val,len) SSMBMACRO(RSIVAL,buf,pos,val,len,4)
228
#define RPSSVALS(buf,pos,val,len) SSMBMACRO(RSSVALS,buf,pos,val,len,2)
229
#define RPSIVALS(buf,pos,val,len) SSMBMACRO(RSIVALS,buf,pos,val,len,4)
230
231
#define DBG_RW_PCVAL(charmode,string,depth,base,read,inbuf,outbuf,len) \
232
	{ RW_PCVAL(read,inbuf,outbuf,len) \
233
	DEBUG(5,("%s%04x %s: ", \
234
             tab_depth(depth), base,string)); \
235
    if (charmode) print_asc(5, (unsigned char*)(outbuf), (len)); else \
236
	{ uint32 idx; for (idx = 0; idx < len; idx++) { DEBUG(5,("%02x ", (outbuf)[idx])); } } \
237
	DEBUG(5,("\n")); } 
238
239
#define DBG_RW_PSVAL(charmode,string,depth,base,read,big_endian,inbuf,outbuf,len) \
240
	{ RW_PSVAL(read,big_endian,inbuf,outbuf,len) \
241
	DEBUG(5,("%s%04x %s: ", \
242
             tab_depth(depth), base,string)); \
243
    if (charmode) print_asc(5, (unsigned char*)(outbuf), 2*(len)); else \
244
	{ uint32 idx; for (idx = 0; idx < len; idx++) { DEBUG(5,("%04x ", (outbuf)[idx])); } } \
245
	DEBUG(5,("\n")); }
246
247
#define DBG_RW_PIVAL(charmode,string,depth,base,read,big_endian,inbuf,outbuf,len) \
248
	{ RW_PIVAL(read,big_endian,inbuf,outbuf,len) \
249
	DEBUG(5,("%s%04x %s: ", \
250
             tab_depth(depth), base,string)); \
251
    if (charmode) print_asc(5, (unsigned char*)(outbuf), 4*(len)); else \
252
	{ uint32 idx; for (idx = 0; idx < len; idx++) { DEBUG(5,("%08x ", (outbuf)[idx])); } } \
253
	DEBUG(5,("\n")); }
254
255
#define DBG_RW_CVAL(string,depth,base,read,inbuf,outbuf) \
256
	{ RW_CVAL(read,inbuf,outbuf,0) \
257
	DEBUG(5,("%s%04x %s: %02x\n", \
258
             tab_depth(depth), base, string, outbuf)); }
259
260
#define DBG_RW_SVAL(string,depth,base,read,big_endian,inbuf,outbuf) \
261
	{ RW_SVAL(read,big_endian,inbuf,outbuf,0) \
262
	DEBUG(5,("%s%04x %s: %04x\n", \
263
             tab_depth(depth), base, string, outbuf)); }
264
265
#define DBG_RW_IVAL(string,depth,base,read,big_endian,inbuf,outbuf) \
266
	{ RW_IVAL(read,big_endian,inbuf,outbuf,0) \
267
	DEBUG(5,("%s%04x %s: %08x\n", \
268
             tab_depth(depth), base, string, outbuf)); }
269
270
/* Alignment macros. */
271
#define ALIGN4(p,base) ((p) + ((4 - (PTR_DIFF((p), (base)) & 3)) & 3))
272
#define ALIGN2(p,base) ((p) + ((2 - (PTR_DIFF((p), (base)) & 1)) & 1))
273
274
#endif /* _BYTEORDER_H */
(-)john-1.7.0.1/src/des.c (+517 lines)
Line 0 Link Here
1
#include "des.h"
2
3
static const DES_LONG DES_SPtrans[8][64]={
4
{
5
/* nibble 0 */
6
0x02080800L, 0x00080000L, 0x02000002L, 0x02080802L,
7
0x02000000L, 0x00080802L, 0x00080002L, 0x02000002L,
8
0x00080802L, 0x02080800L, 0x02080000L, 0x00000802L,
9
0x02000802L, 0x02000000L, 0x00000000L, 0x00080002L,
10
0x00080000L, 0x00000002L, 0x02000800L, 0x00080800L,
11
0x02080802L, 0x02080000L, 0x00000802L, 0x02000800L,
12
0x00000002L, 0x00000800L, 0x00080800L, 0x02080002L,
13
0x00000800L, 0x02000802L, 0x02080002L, 0x00000000L,
14
0x00000000L, 0x02080802L, 0x02000800L, 0x00080002L,
15
0x02080800L, 0x00080000L, 0x00000802L, 0x02000800L,
16
0x02080002L, 0x00000800L, 0x00080800L, 0x02000002L,
17
0x00080802L, 0x00000002L, 0x02000002L, 0x02080000L,
18
0x02080802L, 0x00080800L, 0x02080000L, 0x02000802L,
19
0x02000000L, 0x00000802L, 0x00080002L, 0x00000000L,
20
0x00080000L, 0x02000000L, 0x02000802L, 0x02080800L,
21
0x00000002L, 0x02080002L, 0x00000800L, 0x00080802L,
22
},{
23
/* nibble 1 */
24
0x40108010L, 0x00000000L, 0x00108000L, 0x40100000L,
25
0x40000010L, 0x00008010L, 0x40008000L, 0x00108000L,
26
0x00008000L, 0x40100010L, 0x00000010L, 0x40008000L,
27
0x00100010L, 0x40108000L, 0x40100000L, 0x00000010L,
28
0x00100000L, 0x40008010L, 0x40100010L, 0x00008000L,
29
0x00108010L, 0x40000000L, 0x00000000L, 0x00100010L,
30
0x40008010L, 0x00108010L, 0x40108000L, 0x40000010L,
31
0x40000000L, 0x00100000L, 0x00008010L, 0x40108010L,
32
0x00100010L, 0x40108000L, 0x40008000L, 0x00108010L,
33
0x40108010L, 0x00100010L, 0x40000010L, 0x00000000L,
34
0x40000000L, 0x00008010L, 0x00100000L, 0x40100010L,
35
0x00008000L, 0x40000000L, 0x00108010L, 0x40008010L,
36
0x40108000L, 0x00008000L, 0x00000000L, 0x40000010L,
37
0x00000010L, 0x40108010L, 0x00108000L, 0x40100000L,
38
0x40100010L, 0x00100000L, 0x00008010L, 0x40008000L,
39
0x40008010L, 0x00000010L, 0x40100000L, 0x00108000L,
40
},{
41
/* nibble 2 */
42
0x04000001L, 0x04040100L, 0x00000100L, 0x04000101L,
43
0x00040001L, 0x04000000L, 0x04000101L, 0x00040100L,
44
0x04000100L, 0x00040000L, 0x04040000L, 0x00000001L,
45
0x04040101L, 0x00000101L, 0x00000001L, 0x04040001L,
46
0x00000000L, 0x00040001L, 0x04040100L, 0x00000100L,
47
0x00000101L, 0x04040101L, 0x00040000L, 0x04000001L,
48
0x04040001L, 0x04000100L, 0x00040101L, 0x04040000L,
49
0x00040100L, 0x00000000L, 0x04000000L, 0x00040101L,
50
0x04040100L, 0x00000100L, 0x00000001L, 0x00040000L,
51
0x00000101L, 0x00040001L, 0x04040000L, 0x04000101L,
52
0x00000000L, 0x04040100L, 0x00040100L, 0x04040001L,
53
0x00040001L, 0x04000000L, 0x04040101L, 0x00000001L,
54
0x00040101L, 0x04000001L, 0x04000000L, 0x04040101L,
55
0x00040000L, 0x04000100L, 0x04000101L, 0x00040100L,
56
0x04000100L, 0x00000000L, 0x04040001L, 0x00000101L,
57
0x04000001L, 0x00040101L, 0x00000100L, 0x04040000L,
58
},{
59
/* nibble 3 */
60
0x00401008L, 0x10001000L, 0x00000008L, 0x10401008L,
61
0x00000000L, 0x10400000L, 0x10001008L, 0x00400008L,
62
0x10401000L, 0x10000008L, 0x10000000L, 0x00001008L,
63
0x10000008L, 0x00401008L, 0x00400000L, 0x10000000L,
64
0x10400008L, 0x00401000L, 0x00001000L, 0x00000008L,
65
0x00401000L, 0x10001008L, 0x10400000L, 0x00001000L,
66
0x00001008L, 0x00000000L, 0x00400008L, 0x10401000L,
67
0x10001000L, 0x10400008L, 0x10401008L, 0x00400000L,
68
0x10400008L, 0x00001008L, 0x00400000L, 0x10000008L,
69
0x00401000L, 0x10001000L, 0x00000008L, 0x10400000L,
70
0x10001008L, 0x00000000L, 0x00001000L, 0x00400008L,
71
0x00000000L, 0x10400008L, 0x10401000L, 0x00001000L,
72
0x10000000L, 0x10401008L, 0x00401008L, 0x00400000L,
73
0x10401008L, 0x00000008L, 0x10001000L, 0x00401008L,
74
0x00400008L, 0x00401000L, 0x10400000L, 0x10001008L,
75
0x00001008L, 0x10000000L, 0x10000008L, 0x10401000L,
76
},{
77
/* nibble 4 */
78
0x08000000L, 0x00010000L, 0x00000400L, 0x08010420L,
79
0x08010020L, 0x08000400L, 0x00010420L, 0x08010000L,
80
0x00010000L, 0x00000020L, 0x08000020L, 0x00010400L,
81
0x08000420L, 0x08010020L, 0x08010400L, 0x00000000L,
82
0x00010400L, 0x08000000L, 0x00010020L, 0x00000420L,
83
0x08000400L, 0x00010420L, 0x00000000L, 0x08000020L,
84
0x00000020L, 0x08000420L, 0x08010420L, 0x00010020L,
85
0x08010000L, 0x00000400L, 0x00000420L, 0x08010400L,
86
0x08010400L, 0x08000420L, 0x00010020L, 0x08010000L,
87
0x00010000L, 0x00000020L, 0x08000020L, 0x08000400L,
88
0x08000000L, 0x00010400L, 0x08010420L, 0x00000000L,
89
0x00010420L, 0x08000000L, 0x00000400L, 0x00010020L,
90
0x08000420L, 0x00000400L, 0x00000000L, 0x08010420L,
91
0x08010020L, 0x08010400L, 0x00000420L, 0x00010000L,
92
0x00010400L, 0x08010020L, 0x08000400L, 0x00000420L,
93
0x00000020L, 0x00010420L, 0x08010000L, 0x08000020L,
94
},{
95
/* nibble 5 */
96
0x80000040L, 0x00200040L, 0x00000000L, 0x80202000L,
97
0x00200040L, 0x00002000L, 0x80002040L, 0x00200000L,
98
0x00002040L, 0x80202040L, 0x00202000L, 0x80000000L,
99
0x80002000L, 0x80000040L, 0x80200000L, 0x00202040L,
100
0x00200000L, 0x80002040L, 0x80200040L, 0x00000000L,
101
0x00002000L, 0x00000040L, 0x80202000L, 0x80200040L,
102
0x80202040L, 0x80200000L, 0x80000000L, 0x00002040L,
103
0x00000040L, 0x00202000L, 0x00202040L, 0x80002000L,
104
0x00002040L, 0x80000000L, 0x80002000L, 0x00202040L,
105
0x80202000L, 0x00200040L, 0x00000000L, 0x80002000L,
106
0x80000000L, 0x00002000L, 0x80200040L, 0x00200000L,
107
0x00200040L, 0x80202040L, 0x00202000L, 0x00000040L,
108
0x80202040L, 0x00202000L, 0x00200000L, 0x80002040L,
109
0x80000040L, 0x80200000L, 0x00202040L, 0x00000000L,
110
0x00002000L, 0x80000040L, 0x80002040L, 0x80202000L,
111
0x80200000L, 0x00002040L, 0x00000040L, 0x80200040L,
112
},{
113
/* nibble 6 */
114
0x00004000L, 0x00000200L, 0x01000200L, 0x01000004L,
115
0x01004204L, 0x00004004L, 0x00004200L, 0x00000000L,
116
0x01000000L, 0x01000204L, 0x00000204L, 0x01004000L,
117
0x00000004L, 0x01004200L, 0x01004000L, 0x00000204L,
118
0x01000204L, 0x00004000L, 0x00004004L, 0x01004204L,
119
0x00000000L, 0x01000200L, 0x01000004L, 0x00004200L,
120
0x01004004L, 0x00004204L, 0x01004200L, 0x00000004L,
121
0x00004204L, 0x01004004L, 0x00000200L, 0x01000000L,
122
0x00004204L, 0x01004000L, 0x01004004L, 0x00000204L,
123
0x00004000L, 0x00000200L, 0x01000000L, 0x01004004L,
124
0x01000204L, 0x00004204L, 0x00004200L, 0x00000000L,
125
0x00000200L, 0x01000004L, 0x00000004L, 0x01000200L,
126
0x00000000L, 0x01000204L, 0x01000200L, 0x00004200L,
127
0x00000204L, 0x00004000L, 0x01004204L, 0x01000000L,
128
0x01004200L, 0x00000004L, 0x00004004L, 0x01004204L,
129
0x01000004L, 0x01004200L, 0x01004000L, 0x00004004L,
130
},{
131
/* nibble 7 */
132
0x20800080L, 0x20820000L, 0x00020080L, 0x00000000L,
133
0x20020000L, 0x00800080L, 0x20800000L, 0x20820080L,
134
0x00000080L, 0x20000000L, 0x00820000L, 0x00020080L,
135
0x00820080L, 0x20020080L, 0x20000080L, 0x20800000L,
136
0x00020000L, 0x00820080L, 0x00800080L, 0x20020000L,
137
0x20820080L, 0x20000080L, 0x00000000L, 0x00820000L,
138
0x20000000L, 0x00800000L, 0x20020080L, 0x20800080L,
139
0x00800000L, 0x00020000L, 0x20820000L, 0x00000080L,
140
0x00800000L, 0x00020000L, 0x20000080L, 0x20820080L,
141
0x00020080L, 0x20000000L, 0x00000000L, 0x00820000L,
142
0x20800080L, 0x20020080L, 0x20020000L, 0x00800080L,
143
0x20820000L, 0x00000080L, 0x00800080L, 0x20020000L,
144
0x20820080L, 0x00800000L, 0x20800000L, 0x20000080L,
145
0x00820000L, 0x00020080L, 0x20020080L, 0x20800000L,
146
0x00000080L, 0x20820000L, 0x00820080L, 0x00000000L,
147
0x20000000L, 0x20800080L, 0x00020000L, 0x00820080L,
148
}};
149
150
static const DES_LONG des_skb[8][64]={
151
	{
152
	/* for C bits (numbered as per FIPS 46) 1 2 3 4 5 6 */
153
	0x00000000L,0x00000010L,0x20000000L,0x20000010L,
154
	0x00010000L,0x00010010L,0x20010000L,0x20010010L,
155
	0x00000800L,0x00000810L,0x20000800L,0x20000810L,
156
	0x00010800L,0x00010810L,0x20010800L,0x20010810L,
157
	0x00000020L,0x00000030L,0x20000020L,0x20000030L,
158
	0x00010020L,0x00010030L,0x20010020L,0x20010030L,
159
	0x00000820L,0x00000830L,0x20000820L,0x20000830L,
160
	0x00010820L,0x00010830L,0x20010820L,0x20010830L,
161
	0x00080000L,0x00080010L,0x20080000L,0x20080010L,
162
	0x00090000L,0x00090010L,0x20090000L,0x20090010L,
163
	0x00080800L,0x00080810L,0x20080800L,0x20080810L,
164
	0x00090800L,0x00090810L,0x20090800L,0x20090810L,
165
	0x00080020L,0x00080030L,0x20080020L,0x20080030L,
166
	0x00090020L,0x00090030L,0x20090020L,0x20090030L,
167
	0x00080820L,0x00080830L,0x20080820L,0x20080830L,
168
	0x00090820L,0x00090830L,0x20090820L,0x20090830L,
169
	},{
170
	/* for C bits (numbered as per FIPS 46) 7 8 10 11 12 13 */
171
	0x00000000L,0x02000000L,0x00002000L,0x02002000L,
172
	0x00200000L,0x02200000L,0x00202000L,0x02202000L,
173
	0x00000004L,0x02000004L,0x00002004L,0x02002004L,
174
	0x00200004L,0x02200004L,0x00202004L,0x02202004L,
175
	0x00000400L,0x02000400L,0x00002400L,0x02002400L,
176
	0x00200400L,0x02200400L,0x00202400L,0x02202400L,
177
	0x00000404L,0x02000404L,0x00002404L,0x02002404L,
178
	0x00200404L,0x02200404L,0x00202404L,0x02202404L,
179
	0x10000000L,0x12000000L,0x10002000L,0x12002000L,
180
	0x10200000L,0x12200000L,0x10202000L,0x12202000L,
181
	0x10000004L,0x12000004L,0x10002004L,0x12002004L,
182
	0x10200004L,0x12200004L,0x10202004L,0x12202004L,
183
	0x10000400L,0x12000400L,0x10002400L,0x12002400L,
184
	0x10200400L,0x12200400L,0x10202400L,0x12202400L,
185
	0x10000404L,0x12000404L,0x10002404L,0x12002404L,
186
	0x10200404L,0x12200404L,0x10202404L,0x12202404L,
187
	},{
188
	/* for C bits (numbered as per FIPS 46) 14 15 16 17 19 20 */
189
	0x00000000L,0x00000001L,0x00040000L,0x00040001L,
190
	0x01000000L,0x01000001L,0x01040000L,0x01040001L,
191
	0x00000002L,0x00000003L,0x00040002L,0x00040003L,
192
	0x01000002L,0x01000003L,0x01040002L,0x01040003L,
193
	0x00000200L,0x00000201L,0x00040200L,0x00040201L,
194
	0x01000200L,0x01000201L,0x01040200L,0x01040201L,
195
	0x00000202L,0x00000203L,0x00040202L,0x00040203L,
196
	0x01000202L,0x01000203L,0x01040202L,0x01040203L,
197
	0x08000000L,0x08000001L,0x08040000L,0x08040001L,
198
	0x09000000L,0x09000001L,0x09040000L,0x09040001L,
199
	0x08000002L,0x08000003L,0x08040002L,0x08040003L,
200
	0x09000002L,0x09000003L,0x09040002L,0x09040003L,
201
	0x08000200L,0x08000201L,0x08040200L,0x08040201L,
202
	0x09000200L,0x09000201L,0x09040200L,0x09040201L,
203
	0x08000202L,0x08000203L,0x08040202L,0x08040203L,
204
	0x09000202L,0x09000203L,0x09040202L,0x09040203L,
205
	},{
206
	/* for C bits (numbered as per FIPS 46) 21 23 24 26 27 28 */
207
	0x00000000L,0x00100000L,0x00000100L,0x00100100L,
208
	0x00000008L,0x00100008L,0x00000108L,0x00100108L,
209
	0x00001000L,0x00101000L,0x00001100L,0x00101100L,
210
	0x00001008L,0x00101008L,0x00001108L,0x00101108L,
211
	0x04000000L,0x04100000L,0x04000100L,0x04100100L,
212
	0x04000008L,0x04100008L,0x04000108L,0x04100108L,
213
	0x04001000L,0x04101000L,0x04001100L,0x04101100L,
214
	0x04001008L,0x04101008L,0x04001108L,0x04101108L,
215
	0x00020000L,0x00120000L,0x00020100L,0x00120100L,
216
	0x00020008L,0x00120008L,0x00020108L,0x00120108L,
217
	0x00021000L,0x00121000L,0x00021100L,0x00121100L,
218
	0x00021008L,0x00121008L,0x00021108L,0x00121108L,
219
	0x04020000L,0x04120000L,0x04020100L,0x04120100L,
220
	0x04020008L,0x04120008L,0x04020108L,0x04120108L,
221
	0x04021000L,0x04121000L,0x04021100L,0x04121100L,
222
	0x04021008L,0x04121008L,0x04021108L,0x04121108L,
223
	},{
224
	/* for D bits (numbered as per FIPS 46) 1 2 3 4 5 6 */
225
	0x00000000L,0x10000000L,0x00010000L,0x10010000L,
226
	0x00000004L,0x10000004L,0x00010004L,0x10010004L,
227
	0x20000000L,0x30000000L,0x20010000L,0x30010000L,
228
	0x20000004L,0x30000004L,0x20010004L,0x30010004L,
229
	0x00100000L,0x10100000L,0x00110000L,0x10110000L,
230
	0x00100004L,0x10100004L,0x00110004L,0x10110004L,
231
	0x20100000L,0x30100000L,0x20110000L,0x30110000L,
232
	0x20100004L,0x30100004L,0x20110004L,0x30110004L,
233
	0x00001000L,0x10001000L,0x00011000L,0x10011000L,
234
	0x00001004L,0x10001004L,0x00011004L,0x10011004L,
235
	0x20001000L,0x30001000L,0x20011000L,0x30011000L,
236
	0x20001004L,0x30001004L,0x20011004L,0x30011004L,
237
	0x00101000L,0x10101000L,0x00111000L,0x10111000L,
238
	0x00101004L,0x10101004L,0x00111004L,0x10111004L,
239
	0x20101000L,0x30101000L,0x20111000L,0x30111000L,
240
	0x20101004L,0x30101004L,0x20111004L,0x30111004L,
241
	},{
242
	/* for D bits (numbered as per FIPS 46) 8 9 11 12 13 14 */
243
	0x00000000L,0x08000000L,0x00000008L,0x08000008L,
244
	0x00000400L,0x08000400L,0x00000408L,0x08000408L,
245
	0x00020000L,0x08020000L,0x00020008L,0x08020008L,
246
	0x00020400L,0x08020400L,0x00020408L,0x08020408L,
247
	0x00000001L,0x08000001L,0x00000009L,0x08000009L,
248
	0x00000401L,0x08000401L,0x00000409L,0x08000409L,
249
	0x00020001L,0x08020001L,0x00020009L,0x08020009L,
250
	0x00020401L,0x08020401L,0x00020409L,0x08020409L,
251
	0x02000000L,0x0A000000L,0x02000008L,0x0A000008L,
252
	0x02000400L,0x0A000400L,0x02000408L,0x0A000408L,
253
	0x02020000L,0x0A020000L,0x02020008L,0x0A020008L,
254
	0x02020400L,0x0A020400L,0x02020408L,0x0A020408L,
255
	0x02000001L,0x0A000001L,0x02000009L,0x0A000009L,
256
	0x02000401L,0x0A000401L,0x02000409L,0x0A000409L,
257
	0x02020001L,0x0A020001L,0x02020009L,0x0A020009L,
258
	0x02020401L,0x0A020401L,0x02020409L,0x0A020409L,
259
	},{
260
	/* for D bits (numbered as per FIPS 46) 16 17 18 19 20 21 */
261
	0x00000000L,0x00000100L,0x00080000L,0x00080100L,
262
	0x01000000L,0x01000100L,0x01080000L,0x01080100L,
263
	0x00000010L,0x00000110L,0x00080010L,0x00080110L,
264
	0x01000010L,0x01000110L,0x01080010L,0x01080110L,
265
	0x00200000L,0x00200100L,0x00280000L,0x00280100L,
266
	0x01200000L,0x01200100L,0x01280000L,0x01280100L,
267
	0x00200010L,0x00200110L,0x00280010L,0x00280110L,
268
	0x01200010L,0x01200110L,0x01280010L,0x01280110L,
269
	0x00000200L,0x00000300L,0x00080200L,0x00080300L,
270
	0x01000200L,0x01000300L,0x01080200L,0x01080300L,
271
	0x00000210L,0x00000310L,0x00080210L,0x00080310L,
272
	0x01000210L,0x01000310L,0x01080210L,0x01080310L,
273
	0x00200200L,0x00200300L,0x00280200L,0x00280300L,
274
	0x01200200L,0x01200300L,0x01280200L,0x01280300L,
275
	0x00200210L,0x00200310L,0x00280210L,0x00280310L,
276
	0x01200210L,0x01200310L,0x01280210L,0x01280310L,
277
	},{
278
	/* for D bits (numbered as per FIPS 46) 22 23 24 25 27 28 */
279
	0x00000000L,0x04000000L,0x00040000L,0x04040000L,
280
	0x00000002L,0x04000002L,0x00040002L,0x04040002L,
281
	0x00002000L,0x04002000L,0x00042000L,0x04042000L,
282
	0x00002002L,0x04002002L,0x00042002L,0x04042002L,
283
	0x00000020L,0x04000020L,0x00040020L,0x04040020L,
284
	0x00000022L,0x04000022L,0x00040022L,0x04040022L,
285
	0x00002020L,0x04002020L,0x00042020L,0x04042020L,
286
	0x00002022L,0x04002022L,0x00042022L,0x04042022L,
287
	0x00000800L,0x04000800L,0x00040800L,0x04040800L,
288
	0x00000802L,0x04000802L,0x00040802L,0x04040802L,
289
	0x00002800L,0x04002800L,0x00042800L,0x04042800L,
290
	0x00002802L,0x04002802L,0x00042802L,0x04042802L,
291
	0x00000820L,0x04000820L,0x00040820L,0x04040820L,
292
	0x00000822L,0x04000822L,0x00040822L,0x04040822L,
293
	0x00002820L,0x04002820L,0x00042820L,0x04042820L,
294
	0x00002822L,0x04002822L,0x00042822L,0x04042822L,
295
	}};
296
297
#define c2l(c,l)        (l =((DES_LONG)(*((c)++)))    , \
298
                         l|=((DES_LONG)(*((c)++)))<< 8L, \
299
                         l|=((DES_LONG)(*((c)++)))<<16L, \
300
                         l|=((DES_LONG)(*((c)++)))<<24L)
301
302
#define l2c(l,c)        (*((c)++)=(unsigned char)(((l)     )&0xff), \
303
                         *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
304
                         *((c)++)=(unsigned char)(((l)>>16L)&0xff), \
305
                         *((c)++)=(unsigned char)(((l)>>24L)&0xff))
306
#define c2ln(c,l1,l2,n) { \
307
                        c+=n; \
308
                        l1=l2=0; \
309
                        switch (n) { \
310
                        case 8: l2 =((DES_LONG)(*(--(c))))<<24L; \
311
                        case 7: l2|=((DES_LONG)(*(--(c))))<<16L; \
312
                        case 6: l2|=((DES_LONG)(*(--(c))))<< 8L; \
313
                        case 5: l2|=((DES_LONG)(*(--(c))));     \
314
                        case 4: l1 =((DES_LONG)(*(--(c))))<<24L; \
315
                        case 3: l1|=((DES_LONG)(*(--(c))))<<16L; \
316
                        case 2: l1|=((DES_LONG)(*(--(c))))<< 8L; \
317
                        case 1: l1|=((DES_LONG)(*(--(c))));     \
318
                                } \
319
                        }
320
321
#define HPERM_OP(a,t,n,m) ((t)=((((a)<<(16-(n)))^(a))&(m)),\
322
	(a)=(a)^(t)^(t>>(16-(n))))
323
324
#define PERM_OP(a,b,t,n,m) ((t)=((((a)>>(n))^(b))&(m)),\
325
 	(b)^=(t),\
326
 	(a)=((a)^((t)<<(n))))
327
328
#define ROTATE(a,n)     (((a)>>(n))+((a)<<(32-(n))))
329
330
#define IP(l,r) \
331
	{ \
332
	register DES_LONG tt; \
333
	PERM_OP(r,l,tt, 4,0x0f0f0f0fL); \
334
	PERM_OP(l,r,tt,16,0x0000ffffL); \
335
	PERM_OP(r,l,tt, 2,0x33333333L); \
336
	PERM_OP(l,r,tt, 8,0x00ff00ffL); \
337
	PERM_OP(r,l,tt, 1,0x55555555L); \
338
	}
339
340
#define FP(l,r) \
341
	{ \
342
	register DES_LONG tt; \
343
	PERM_OP(l,r,tt, 1,0x55555555L); \
344
	PERM_OP(r,l,tt, 8,0x00ff00ffL); \
345
	PERM_OP(l,r,tt, 2,0x33333333L); \
346
	PERM_OP(r,l,tt,16,0x0000ffffL); \
347
	PERM_OP(l,r,tt, 4,0x0f0f0f0fL); \
348
	}
349
#define LOAD_DATA(R,S,u,t,E0,E1,tmp) \
350
	u=R^s[S  ]; \
351
	t=R^s[S+1]
352
#define LOAD_DATA_tmp(a,b,c,d,e,f) LOAD_DATA(a,b,c,d,e,f,g)
353
354
#define D_ENCRYPT(LL,R,S) { \
355
	LOAD_DATA_tmp(R,S,u,t,E0,E1); \
356
	t=ROTATE(t,4); \
357
	LL^= \
358
	*(const DES_LONG *)(des_SP      +((u     )&0xfc))^ \
359
	*(const DES_LONG *)(des_SP+0x200+((u>> 8L)&0xfc))^ \
360
	*(const DES_LONG *)(des_SP+0x400+((u>>16L)&0xfc))^ \
361
	*(const DES_LONG *)(des_SP+0x600+((u>>24L)&0xfc))^ \
362
	*(const DES_LONG *)(des_SP+0x100+((t     )&0xfc))^ \
363
	*(const DES_LONG *)(des_SP+0x300+((t>> 8L)&0xfc))^ \
364
	*(const DES_LONG *)(des_SP+0x500+((t>>16L)&0xfc))^ \
365
	*(const DES_LONG *)(des_SP+0x700+((t>>24L)&0xfc)); }
366
367
void my_des_set_key(DES_cblock *key, DES_key_schedule *schedule)
368
{
369
	//DES_set_key_unchecked(key, schedule);
370
	static int shifts2[16]={0,0,1,1,1,1,1,1,0,1,1,1,1,1,1,0};
371
	register DES_LONG c,d,t,s,t2;
372
	register const unsigned char *in;
373
	register DES_LONG *k;
374
	register int i;
375
376
	k = &schedule->ks->deslong[0];
377
	in = &(*key)[0];
378
379
	c2l(in,c);
380
	c2l(in,d);
381
382
	/* do PC1 in 47 simple operations :-)
383
	 * Thanks to John Fletcher (john_fletcher@lccmail.ocf.llnl.gov)
384
	 * for the inspiration. :-) */
385
	PERM_OP (d,c,t,4,0x0f0f0f0fL);
386
	HPERM_OP(c,t,-2,0xcccc0000L);
387
	HPERM_OP(d,t,-2,0xcccc0000L);
388
	PERM_OP (d,c,t,1,0x55555555L);
389
	PERM_OP (c,d,t,8,0x00ff00ffL);
390
	PERM_OP (d,c,t,1,0x55555555L);
391
	d=	(((d&0x000000ffL)<<16L)| (d&0x0000ff00L)     |
392
			((d&0x00ff0000L)>>16L)|((c&0xf0000000L)>>4L));
393
	c&=0x0fffffffL;
394
395
	for (i=0; i<16; i++)
396
	{
397
		if (shifts2[i])
398
		{ 
399
			c=((c>>2L)|(c<<26L));
400
			d=((d>>2L)|(d<<26L)); 
401
		}
402
		else
403
		{ 
404
			c=((c>>1L)|(c<<27L));
405
			d=((d>>1L)|(d<<27L));
406
		}
407
		c&=0x0fffffffL;
408
		d&=0x0fffffffL;
409
		/* could be a few less shifts but I am to lazy at this
410
		 * point in time to investigate */
411
		s=	des_skb[0][ (c    )&0x3f                ]|
412
			des_skb[1][((c>> 6L)&0x03)|((c>> 7L)&0x3c)]|
413
			des_skb[2][((c>>13L)&0x0f)|((c>>14L)&0x30)]|
414
			des_skb[3][((c>>20L)&0x01)|((c>>21L)&0x06) |
415
			((c>>22L)&0x38)];
416
		t=	des_skb[4][ (d    )&0x3f                ]|
417
			des_skb[5][((d>> 7L)&0x03)|((d>> 8L)&0x3c)]|
418
			des_skb[6][ (d>>15L)&0x3f                ]|
419
			des_skb[7][((d>>21L)&0x0f)|((d>>22L)&0x30)];
420
421
		/* table contained 0213 4657 */
422
		t2=((t<<16L)|(s&0x0000ffffL))&0xffffffffL;
423
		*(k++)=ROTATE(t2,30)&0xffffffffL;
424
425
		t2=((s>>16L)|(t&0xffff0000L));
426
		*(k++)=ROTATE(t2,26)&0xffffffffL;
427
	}
428
}
429
430
static void DES_encrypt1(DES_LONG *data, DES_key_schedule *ks)
431
{
432
	register DES_LONG l,r,t,u;
433
	register DES_LONG *s;
434
	register const unsigned char *des_SP=(const unsigned char *)DES_SPtrans;
435
436
	r=data[0];
437
	l=data[1];
438
439
	IP(r,l);
440
	/* Things have been modified so that the initial rotate is
441
	 * done outside the loop.  This required the
442
	 * DES_SPtrans values in sp.h to be rotated 1 bit to the right.
443
	 * One perl script later and things have a 5% speed up on a sparc2.
444
	 * Thanks to Richard Outerbridge <71755.204@CompuServe.COM>
445
	 * for pointing this out. */
446
	/* clear the top bits on machines with 8byte longs */
447
	/* shift left by 2 */
448
	r=ROTATE(r,29)&0xffffffffL;
449
	l=ROTATE(l,29)&0xffffffffL;
450
451
	s=ks->ks->deslong;
452
	/* I don't know if it is worth the effort of loop unrolling the
453
	 * inner loop */
454
	D_ENCRYPT(l,r, 0); /*  1 */
455
	D_ENCRYPT(r,l, 2); /*  2 */
456
	D_ENCRYPT(l,r, 4); /*  3 */
457
	D_ENCRYPT(r,l, 6); /*  4 */
458
	D_ENCRYPT(l,r, 8); /*  5 */
459
	D_ENCRYPT(r,l,10); /*  6 */
460
	D_ENCRYPT(l,r,12); /*  7 */
461
	D_ENCRYPT(r,l,14); /*  8 */
462
	D_ENCRYPT(l,r,16); /*  9 */
463
	D_ENCRYPT(r,l,18); /*  10 */
464
	D_ENCRYPT(l,r,20); /*  11 */
465
	D_ENCRYPT(r,l,22); /*  12 */
466
	D_ENCRYPT(l,r,24); /*  13 */
467
	D_ENCRYPT(r,l,26); /*  14 */
468
	D_ENCRYPT(l,r,28); /*  15 */
469
	D_ENCRYPT(r,l,30); /*  16 */
470
	
471
	/* rotate and clear the top bits on machines with 8byte longs */
472
	l=ROTATE(l,3)&0xffffffffL;
473
	r=ROTATE(r,3)&0xffffffffL;
474
475
	FP(r,l);
476
	data[0]=l;
477
	data[1]=r;
478
	//l=r=t=u=0;
479
}
480
481
void my_des_ncbc_encrypt(const unsigned char *in,
482
		long length, DES_key_schedule *schedule, DES_cblock *ivec)
483
{
484
	register DES_LONG tin0,tin1;
485
	register DES_LONG tout0,tout1;
486
	register long l=length;
487
	DES_LONG tin[2];
488
	unsigned char *iv;
489
490
	iv = &(*ivec)[0];
491
	c2l(iv,tout0);
492
	c2l(iv,tout1);
493
494
	for (l-=8; l>=0; l-=8)
495
	{
496
		c2l(in,tin0);
497
		c2l(in,tin1);
498
		tin0^=tout0; tin[0]=tin0;
499
		tin1^=tout1; tin[1]=tin1;
500
		DES_encrypt1((DES_LONG *)tin,schedule);
501
		tout0=tin[0];
502
		tout1=tin[1];
503
	}
504
	if (l != -8)
505
	{
506
		c2ln(in,tin0,tin1,l+8);
507
		tin0^=tout0; tin[0]=tin0;
508
		tin1^=tout1; tin[1]=tin1;
509
		DES_encrypt1((DES_LONG *)tin,schedule);
510
		tout0=tin[0];
511
		tout1=tin[1];
512
	}
513
514
	iv = &(*ivec)[0];
515
	l2c(tout0,iv);
516
	l2c(tout1,iv);
517
}
(-)john-1.7.0.1/src/des.h (+27 lines)
Line 0 Link Here
1
#ifndef _DES_H
2
#define _DES_H
3
4
//#include <openssl/des.h>
5
typedef unsigned long DES_LONG;
6
7
typedef unsigned char DES_cblock[8];
8
9
typedef struct DES_ks
10
    {
11
    union
12
	{
13
	DES_cblock cblock;
14
	/* make sure things are correct size on machines with
15
	 * 8 byte longs */
16
	DES_LONG deslong[2];
17
	} ks[16];
18
    } DES_key_schedule;
19
20
21
22
void my_des_ncbc_encrypt(const unsigned char *input,
23
               long length, DES_key_schedule *schedule, DES_cblock *ivec);
24
void my_des_set_key(DES_cblock *key, DES_key_schedule *schedule);
25
26
27
#endif
(-)john-1.7.0.1/src/hmacMD5_fmt.c (+310 lines)
Line 0 Link Here
1
/*
2
 * Copyright (c) 2004 bartavelle
3
 * bartavelle@bandecon.com
4
 *
5
 * Simple MD5 hashes cracker
6
 * It uses the Solar Designer's md5 implementation
7
 * 
8
 */
9
10
#include <string.h>
11
12
#include "arch.h"
13
#include "misc.h"
14
#include "common.h"
15
#include "formats.h"
16
#include "md5.h"
17
18
#define FORMAT_LABEL			"hmac-md5"
19
#define FORMAT_NAME			"HMAC MD5"
20
#ifdef MMX_COEF
21
#if (MMX_COEF == 2)
22
#define ALGORITHM_NAME			"hmac-md5 MMX"
23
#else
24
#define ALGORITHM_NAME			"hmac-md5 SSE2"
25
#endif
26
#else
27
#define ALGORITHM_NAME			"hmac-md5"
28
#endif
29
30
#ifdef MMX_TYPE
31
#define BENCHMARK_COMMENT		MMX_TYPE
32
#else
33
#define BENCHMARK_COMMENT		""
34
#endif
35
#define BENCHMARK_LENGTH		-1
36
37
#define PLAINTEXT_LENGTH		64
38
#define CIPHERTEXT_LENGTH		128
39
40
#define BINARY_SIZE			16
41
#define SALT_SIZE			64
42
43
#ifdef MMX_COEF
44
#define MIN_KEYS_PER_CRYPT		MMX_COEF
45
#define MAX_KEYS_PER_CRYPT		MMX_COEF
46
#define GETPOS(i, index)		( (index)*4 + (i& (0xffffffff-3) )*MMX_COEF + ((i)&3) )
47
#else
48
#define MIN_KEYS_PER_CRYPT		1
49
#define MAX_KEYS_PER_CRYPT		1
50
#endif
51
52
static struct fmt_tests hmacmd5_tests[] = {
53
	{"what do ya want for nothing?#750c783e6ab0b503eaa86e310a5db738", "Jefe"},
54
	{NULL}
55
};
56
57
#ifdef MMX_COEF
58
//static char saved_key[PLAINTEXT_LENGTH*MMX_COEF*2 + 1] __attribute__ ((aligned(16)));
59
static char crypt_key[64*MMX_COEF] __attribute__ ((aligned(16)));
60
unsigned long total_len;
61
unsigned char opad[PLAINTEXT_LENGTH*MMX_COEF] __attribute__ ((aligned(16)));
62
unsigned char ipad[PLAINTEXT_LENGTH*MMX_COEF] __attribute__ ((aligned(16)));
63
unsigned char cursalt[SALT_SIZE*MMX_COEF] __attribute__ ((aligned(16)));
64
unsigned char dump[BINARY_SIZE*MMX_COEF] __attribute__((aligned(16)));
65
#else
66
//static char saved_key[PLAINTEXT_LENGTH + 1];
67
static char crypt_key[BINARY_SIZE+1];
68
static MD5_CTX ctx;
69
unsigned char opad[PLAINTEXT_LENGTH];
70
unsigned char ipad[PLAINTEXT_LENGTH];
71
unsigned char cursalt[SALT_SIZE];
72
#endif
73
unsigned char out[PLAINTEXT_LENGTH];
74
75
static void hmacmd5_init(void)
76
{
77
#ifdef MMX_COEF
78
	memset(crypt_key, 0, 64*MMX_COEF);
79
	crypt_key[GETPOS(BINARY_SIZE,0)] = 0x80;
80
	crypt_key[GETPOS(BINARY_SIZE,1)] = 0x80;
81
#if (MMX_COEF == 4)
82
	crypt_key[GETPOS(BINARY_SIZE,2)] = 0x80;
83
	crypt_key[GETPOS(BINARY_SIZE,3)] = 0x80;
84
#endif
85
#endif
86
}
87
88
static int valid(char *ciphertext)
89
{
90
	int pos, i;
91
92
	for(i=0;(i<strlen(ciphertext)) && (ciphertext[i]!='#');i++) ;
93
	if(i==strlen(ciphertext))
94
		return 0;
95
	pos = i+1;
96
	if (strlen(ciphertext+pos) != BINARY_SIZE*2) return 0;
97
	for (i = pos; i < BINARY_SIZE*2+pos; i++){
98
		if (!(  (('0' <= ciphertext[i])&&(ciphertext[i] <= '9')) ||
99
					(('a' <= ciphertext[i])&&(ciphertext[i] <= 'f'))  
100
					|| (('A' <= ciphertext[i])&&(ciphertext[i] <= 'F'))))
101
			return 0;
102
	}
103
	return 1;
104
}
105
106
static void hmacmd5_set_salt(void *salt) 
107
{
108
#ifdef MMX_COEF
109
	total_len = 0;
110
	while(((unsigned char *)salt)[total_len])
111
	{
112
		cursalt[GETPOS(total_len, 0)] = ((unsigned char *)salt)[total_len];
113
		cursalt[GETPOS(total_len, 1)] = ((unsigned char *)salt)[total_len];
114
#if (MMX_COEF == 4)
115
		cursalt[GETPOS(total_len, 2)] = ((unsigned char *)salt)[total_len];
116
		cursalt[GETPOS(total_len, 3)] = ((unsigned char *)salt)[total_len];
117
#endif
118
		total_len ++;
119
	}
120
	cursalt[GETPOS(total_len, 0)] = 0x80;
121
	cursalt[GETPOS(total_len, 1)] = 0x80;
122
#if (MMX_COEF == 4)
123
	cursalt[GETPOS(total_len, 2)] = 0x80;
124
	cursalt[GETPOS(total_len, 3)] = 0x80;
125
#endif
126
	//total_len += 64;
127
	//total_len += (total_len<<16);
128
#else
129
	memcpy(cursalt, salt, SALT_SIZE);
130
#endif
131
}
132
133
static void hmacmd5_set_key(char *key, int index) {
134
	int i;
135
	int len;
136
	
137
	len = strlen(key);
138
	if(len>PLAINTEXT_LENGTH)
139
		len = PLAINTEXT_LENGTH;
140
141
#ifdef MMX_COEF
142
	if(index==0)
143
	{
144
		memset(ipad, 0x36, PLAINTEXT_LENGTH*MMX_COEF);
145
		memset(opad, 0x5C, PLAINTEXT_LENGTH*MMX_COEF);
146
	}
147
	
148
	for(i=0;i<len;i++)
149
	{
150
		ipad[GETPOS(i, index)] ^= key[i];
151
		opad[GETPOS(i, index)] ^= key[i];
152
	}
153
154
	//saved_key[GETPOS(i, index)] = 0x80;
155
#else
156
	memset(ipad, 0x36, PLAINTEXT_LENGTH);
157
	memset(opad, 0x5C, PLAINTEXT_LENGTH);
158
	for(i=0;i<len;i++)
159
	{
160
		ipad[i] ^= key[i];
161
		opad[i] ^= key[i];
162
	}
163
#endif
164
}
165
166
static char *hmacmd5_get_key(int index) {
167
	unsigned int i;
168
	for(i=0;i<PLAINTEXT_LENGTH;i++)
169
#ifdef MMX_COEF
170
		out[i] = ipad[ GETPOS(i, index) ] ^ 0x36;
171
#else
172
		out[i] = ipad[ i ] ^ 0x36;
173
#endif
174
	return out;
175
}
176
177
static int hmacmd5_cmp_all(void *binary, int index) { 
178
	int i=0;
179
#ifdef MMX_COEF
180
	while(i< (BINARY_SIZE/4) )
181
	{
182
		if (
183
			( ((unsigned long *)binary)[i] != ((unsigned long *)crypt_key)[i*MMX_COEF])
184
			&& ( ((unsigned long *)binary)[i] != ((unsigned long *)crypt_key)[i*MMX_COEF+1])
185
#if (MMX_COEF > 3)
186
			&& ( ((unsigned long *)binary)[i] != ((unsigned long *)crypt_key)[i*MMX_COEF+2])
187
			&& ( ((unsigned long *)binary)[i] != ((unsigned long *)crypt_key)[i*MMX_COEF+3])
188
#endif
189
		)
190
			return 0;
191
		i++;
192
	}
193
#else
194
	while(i<BINARY_SIZE)
195
	{
196
		if(((char *)binary)[i]!=((char *)crypt_key)[i])
197
			return 0;
198
		i++;
199
	}
200
#endif
201
	return 1;
202
}
203
204
static int hmacmd5_cmp_exact(char *source, int count){
205
  return (1);
206
}
207
208
static int hmacmd5_cmp_one(void * binary, int index)
209
{
210
#ifdef MMX_COEF
211
	int i = 0;
212
	for(i=0;i<(BINARY_SIZE/4);i++)
213
		if ( ((unsigned long *)binary)[i] != ((unsigned long *)crypt_key)[i*MMX_COEF+index] )
214
			return 0;
215
	return 1;
216
#else
217
	return hmacmd5_cmp_all(binary, index);
218
#endif
219
}
220
221
static void hmacmd5_crypt_all(int count) {  
222
223
#ifdef MMX_COEF
224
	int i;
225
	i = mdfivemmx_nosizeupdate( dump, ipad, 64);
226
	i = mdfivemmx_noinit_uniformsizeupdate(crypt_key, cursalt, total_len + 64);
227
	i = mdfivemmx_nosizeupdate( dump, opad, 64);
228
	i = mdfivemmx_noinit_uniformsizeupdate(crypt_key, crypt_key, BINARY_SIZE + 64);
229
#else
230
	MD5_Init( &ctx );
231
	MD5_Update( &ctx, ipad, 64 );
232
	MD5_Update( &ctx, cursalt, strlen(cursalt) );
233
	MD5_Final( crypt_key, &ctx);
234
	MD5_Init( &ctx );
235
	MD5_Update( &ctx, opad, 64 );
236
	MD5_Update( &ctx, crypt_key, BINARY_SIZE);
237
	MD5_Final( crypt_key, &ctx);
238
#endif
239
  
240
}
241
242
static void * hmacmd5_binary(char *ciphertext) 
243
{
244
	static unsigned char realcipher[BINARY_SIZE];
245
	int i,pos;
246
	
247
	for(i=0;ciphertext[i]!='#';i++);
248
	pos=i+1;
249
	for(i=0;i<BINARY_SIZE;i++)
250
	{
251
		realcipher[i] = atoi16[ARCH_INDEX(ciphertext[i*2+pos])]*16 + atoi16[ARCH_INDEX(ciphertext[i*2+1+pos])];
252
	}
253
	return (void *)realcipher;
254
}
255
256
static void * hmacmd5_salt(char *ciphertext)
257
{
258
	static unsigned char salt[SALT_SIZE];
259
	memset(salt, 0, SALT_SIZE);
260
	int i=0;
261
	while(ciphertext[i]!='#')
262
	{
263
		salt[i] = ciphertext[i];
264
		i++;
265
	}
266
	salt[i]=0;
267
	return salt;
268
}
269
270
struct fmt_main fmt_hmacMD5 = {
271
	{
272
		FORMAT_LABEL,
273
		FORMAT_NAME,
274
		ALGORITHM_NAME,
275
		BENCHMARK_COMMENT,
276
		BENCHMARK_LENGTH,
277
		PLAINTEXT_LENGTH,
278
		BINARY_SIZE,
279
		SALT_SIZE,
280
		MIN_KEYS_PER_CRYPT,
281
		MAX_KEYS_PER_CRYPT,
282
		FMT_CASE | FMT_8_BIT,
283
		hmacmd5_tests
284
	}, {
285
		hmacmd5_init,
286
		valid,
287
		fmt_default_split,
288
		hmacmd5_binary,
289
		hmacmd5_salt,
290
		{
291
			fmt_default_binary_hash,
292
			fmt_default_binary_hash,
293
			fmt_default_binary_hash
294
		},
295
		fmt_default_salt_hash,
296
		hmacmd5_set_salt,
297
		hmacmd5_set_key,
298
		hmacmd5_get_key,
299
		fmt_default_clear_keys,
300
		hmacmd5_crypt_all,
301
		{
302
			fmt_default_get_hash,
303
			fmt_default_get_hash,
304
			fmt_default_get_hash
305
		},
306
		hmacmd5_cmp_all,
307
		hmacmd5_cmp_one,
308
		hmacmd5_cmp_exact
309
	}
310
};
(-)john-1.7.0.1/src/john.c (-1 / +37 lines)
Lines 37-47 Link Here
37
#endif
37
#endif
38
38
39
extern struct fmt_main fmt_DES, fmt_BSDI, fmt_MD5, fmt_BF;
39
extern struct fmt_main fmt_DES, fmt_BSDI, fmt_MD5, fmt_BF;
40
extern struct fmt_main fmt_AFS, fmt_LM;
40
extern struct fmt_main fmt_AFS, fmt_LM, fmt_rawMD5, fmt_NT;
41
extern struct fmt_main fmt_MD5_apache;
42
extern struct fmt_main fmt_BFEgg;
43
extern struct fmt_main fmt_MYSQL;
44
extern struct fmt_main fmt_NSLDAP;
45
extern struct fmt_main fmt_lotus5;
46
extern struct fmt_main fmt_mscash;
47
extern struct fmt_main fmt_rawSHA1;
48
extern struct fmt_main fmt_mssql;
49
extern struct fmt_main fmt_hmacMD5;
50
extern struct fmt_main fmt_WPAPSK;
51
extern struct fmt_main fmt_oracle;
52
#ifdef MMX_COEF
53
extern struct fmt_main fmt_NTmmx;
54
#endif
41
55
42
extern int unshadow(int argc, char **argv);
56
extern int unshadow(int argc, char **argv);
43
extern int unafs(int argc, char **argv);
57
extern int unafs(int argc, char **argv);
44
extern int unique(int argc, char **argv);
58
extern int unique(int argc, char **argv);
59
extern int undrop(int argc, char **argv);
45
60
46
static struct db_main database;
61
static struct db_main database;
47
static struct fmt_main dummy_format;
62
static struct fmt_main dummy_format;
Lines 65-70 Link Here
65
	john_register_one(&fmt_AFS);
80
	john_register_one(&fmt_AFS);
66
	john_register_one(&fmt_LM);
81
	john_register_one(&fmt_LM);
67
82
83
	/* new ciphers */
84
	john_register_one(&fmt_MD5_apache);
85
	john_register_one(&fmt_MYSQL);
86
	john_register_one(&fmt_NSLDAP);
87
	john_register_one(&fmt_NT);
88
	john_register_one(&fmt_lotus5);
89
	john_register_one(&fmt_mscash);
90
	john_register_one(&fmt_rawMD5);
91
	john_register_one(&fmt_BFEgg);
92
	john_register_one(&fmt_rawSHA1);
93
	john_register_one(&fmt_mssql);
94
	john_register_one(&fmt_hmacMD5);
95
	john_register_one(&fmt_WPAPSK);
96
	john_register_one(&fmt_oracle);
97
	#ifdef MMX_COEF
98
		john_register_one(&fmt_NTmmx);
99
	#endif
100
68
	if (!fmt_list) {
101
	if (!fmt_list) {
69
		fprintf(stderr, "Unknown ciphertext format name requested\n");
102
		fprintf(stderr, "Unknown ciphertext format name requested\n");
70
		error();
103
		error();
Lines 341-346 Link Here
341
	if (!strcmp(name, "unique"))
374
	if (!strcmp(name, "unique"))
342
		return unique(argc, argv);
375
		return unique(argc, argv);
343
376
377
	if (!strcmp(name, "undrop"))
378
		return undrop(argc, argv);
379
344
	john_init(name, argc, argv);
380
	john_init(name, argc, argv);
345
	john_run();
381
	john_run();
346
	john_done();
382
	john_done();
(-)john-1.7.0.1/src/loader.c (-1 / +64 lines)
Lines 206-211 Link Here
206
		if (!strncmp(*ciphertext, "NO PASSWORD", 11))
206
		if (!strncmp(*ciphertext, "NO PASSWORD", 11))
207
			*ciphertext = "";
207
			*ciphertext = "";
208
208
209
		/* NT loader hack starts here ! */
210
		extern struct fmt_main fmt_NT;
211
212
		/* TODO test !!! */
213
		if (&fmt_NT == *format) {
214
215
			/*
216
				tmp = ldr_get_field(&line);
217
				*ciphertext = tmp;
218
			*/
219
220
			if (!strncmp(*ciphertext, "NO PASSWORD", 11))
221
				*ciphertext = "";
222
			else {
223
				*ciphertext -= 4;
224
				strncpy(*ciphertext,"$NT$",4);
225
			}
226
		}
227
228
		/* NT loader hack ends here ! */
229
209
		if (source) sprintf(source, "%s:%s", uid, line);
230
		if (source) sprintf(source, "%s:%s", uid, line);
210
	}
231
	}
211
232
Lines 287-292 Link Here
287
	struct list_main *words;
308
	struct list_main *words;
288
	size_t pw_size, salt_size;
309
	size_t pw_size, salt_size;
289
310
311
	extern struct fmt_main fmt_mscash;
312
	extern struct fmt_main fmt_oracle;
313
290
	count = ldr_split_line(&login, &ciphertext, &gecos, &home,
314
	count = ldr_split_line(&login, &ciphertext, &gecos, &home,
291
		NULL, &db->format, db->options, line);
315
		NULL, &db->format, db->options, line);
292
	if (count <= 0) return;
316
	if (count <= 0) return;
Lines 311-317 Link Here
311
	}
335
	}
312
336
313
	for (index = 0; index < count; index++) {
337
	for (index = 0; index < count; index++) {
314
		piece = format->methods.split(ciphertext, index);
338
		if (db->format == &fmt_mscash) {
339
			piece = (char *) mem_alloc_tiny(strlen(login) + strlen(ciphertext) + 4, MEM_ALIGN_NONE);
340
			sprintf(piece, "M$%s#%s", login, ciphertext);
341
		} else if (db->format == &fmt_oracle) {
342
			piece = (char *) mem_alloc_tiny(strlen(login) + strlen(ciphertext) + 4, MEM_ALIGN_NONE);
343
			sprintf(piece, "O$%s#%s", login, ciphertext);
344
		} else
345
			piece = format->methods.split(ciphertext, index);
315
346
316
		binary = format->methods.binary(piece);
347
		binary = format->methods.binary(piece);
317
		pw_hash = LDR_HASH_FUNC(binary);
348
		pw_hash = LDR_HASH_FUNC(binary);
Lines 644-649 Link Here
644
	int hash;
675
	int hash;
645
	struct db_cracked *current;
676
	struct db_cracked *current;
646
677
678
	extern struct fmt_main fmt_mscash;
679
	extern struct fmt_main fmt_oracle;
680
647
	format = NULL;
681
	format = NULL;
648
	count = ldr_split_line(&login, &ciphertext, &gecos, &home,
682
	count = ldr_split_line(&login, &ciphertext, &gecos, &home,
649
		source, &format, db->options, line);
683
		source, &format, db->options, line);
Lines 653-658 Link Here
653
687
654
	if (format) {
688
	if (format) {
655
		split = format->methods.split;
689
		split = format->methods.split;
690
 		if (format == &fmt_mscash) {
691
 			char * ciphertext2 = (char *) mem_alloc_tiny(strlen(login) + strlen(ciphertext) + 4, MEM_ALIGN_NONE);
692
 			sprintf(ciphertext2, "M$%s#%s", login, ciphertext);
693
 			ciphertext = ciphertext2;
694
 		}
695
 		if (format == &fmt_oracle) {
696
 			char * ciphertext2 = (char *) mem_alloc_tiny(strlen(login) + strlen(ciphertext) + 4, MEM_ALIGN_NONE);
697
 			sprintf(ciphertext2, "O$%s#%s", login, ciphertext);
698
 			ciphertext = ciphertext2;
699
 		}
656
		unify = format->params.flags & FMT_SPLIT_UNIFIES_CASE;
700
		unify = format->params.flags & FMT_SPLIT_UNIFIES_CASE;
657
	} else {
701
	} else {
658
		split = fmt_default_split;
702
		split = fmt_default_split;
Lines 692-697 Link Here
692
			MEM_FREE(piece);
736
			MEM_FREE(piece);
693
737
694
		if (pass) {
738
		if (pass) {
739
 			/* modification by bartavelle, catches the no format bug */
740
 			/*
741
	 			if(format)
742
 					chars = format->params.plaintext_length;
743
 				else
744
 					chars = 0;
745
 
746
	 			if (current && show && index < count - 1)
747
	 			if ((int)strlen(current->plaintext) != chars)
748
 					current = NULL;
749
 			*/
750
695
			chars = 0;
751
			chars = 0;
696
			if (show) {
752
			if (show) {
697
				if (format)
753
				if (format)
Lines 710-715 Link Here
710
766
711
				db->guess_count++;
767
				db->guess_count++;
712
			} else
768
			} else
769
			/*
770
				if (show)
771
				do {
772
					putchar('?');
773
				} while (--chars);
774
			*/
775
713
			while (chars--)
776
			while (chars--)
714
				putchar('?');
777
				putchar('?');
715
		} else
778
		} else
(-)john-1.7.0.1/src/lotus5_fmt.c (+247 lines)
Line 0 Link Here
1
//original work by Jeff Fay
2
//some optimisations by bartavelle@bandecon.com
3
4
#include <stdio.h>
5
#include <string.h>
6
#include "misc.h"
7
#include "formats.h"
8
#include "common.h"
9
10
/*preprocessor constants that John The Ripper likes*/
11
#define FORMAT_LABEL                   "lotus5"
12
#define FORMAT_NAME                    "Lotus5"
13
#define ALGORITHM_NAME			"Lotus v5 Proprietary"
14
#define BENCHMARK_COMMENT              ""
15
#define BENCHMARK_LENGTH               -1
16
#define PLAINTEXT_LENGTH               16
17
#define CIPHERTEXT_LENGTH              32
18
#define BINARY_SIZE                    16
19
#define SALT_SIZE                      0
20
#define MIN_KEYS_PER_CRYPT             1
21
#define MAX_KEYS_PER_CRYPT             1
22
23
/*A struct used for JTR's benchmarks*/
24
static struct fmt_tests tests[] = {
25
  {"06E0A50B579AD2CD5FFDC48564627EE7", "secret"},
26
  {"355E98E7C7B59BD810ED845AD0FD2FC4", "password"},
27
  {"CD2D90E8E00D8A2A63A81F531EA8A9A3", "lotus"},
28
  {"69D90B46B1AC0912E5CCF858094BBBFC", "dirtydog"},
29
  {NULL}
30
};
31
32
static const char lotus_magic_table[256] = {
33
  0xbd, 0x56, 0xea, 0xf2, 0xa2, 0xf1, 0xac, 0x2a,
34
  0xb0, 0x93, 0xd1, 0x9c, 0x1b, 0x33, 0xfd, 0xd0,
35
  0x30, 0x04, 0xb6, 0xdc, 0x7d, 0xdf, 0x32, 0x4b,
36
  0xf7, 0xcb, 0x45, 0x9b, 0x31, 0xbb, 0x21, 0x5a,
37
  0x41, 0x9f, 0xe1, 0xd9, 0x4a, 0x4d, 0x9e, 0xda,
38
  0xa0, 0x68, 0x2c, 0xc3, 0x27, 0x5f, 0x80, 0x36,
39
  0x3e, 0xee, 0xfb, 0x95, 0x1a, 0xfe, 0xce, 0xa8,
40
  0x34, 0xa9, 0x13, 0xf0, 0xa6, 0x3f, 0xd8, 0x0c,
41
  0x78, 0x24, 0xaf, 0x23, 0x52, 0xc1, 0x67, 0x17,
42
  0xf5, 0x66, 0x90, 0xe7, 0xe8, 0x07, 0xb8, 0x60,
43
  0x48, 0xe6, 0x1e, 0x53, 0xf3, 0x92, 0xa4, 0x72,
44
  0x8c, 0x08, 0x15, 0x6e, 0x86, 0x00, 0x84, 0xfa,
45
  0xf4, 0x7f, 0x8a, 0x42, 0x19, 0xf6, 0xdb, 0xcd,
46
  0x14, 0x8d, 0x50, 0x12, 0xba, 0x3c, 0x06, 0x4e,
47
  0xec, 0xb3, 0x35, 0x11, 0xa1, 0x88, 0x8e, 0x2b,
48
  0x94, 0x99, 0xb7, 0x71, 0x74, 0xd3, 0xe4, 0xbf,
49
  0x3a, 0xde, 0x96, 0x0e, 0xbc, 0x0a, 0xed, 0x77,
50
  0xfc, 0x37, 0x6b, 0x03, 0x79, 0x89, 0x62, 0xc6,
51
  0xd7, 0xc0, 0xd2, 0x7c, 0x6a, 0x8b, 0x22, 0xa3,
52
  0x5b, 0x05, 0x5d, 0x02, 0x75, 0xd5, 0x61, 0xe3,
53
  0x18, 0x8f, 0x55, 0x51, 0xad, 0x1f, 0x0b, 0x5e,
54
  0x85, 0xe5, 0xc2, 0x57, 0x63, 0xca, 0x3d, 0x6c,
55
  0xb4, 0xc5, 0xcc, 0x70, 0xb2, 0x91, 0x59, 0x0d,
56
  0x47, 0x20, 0xc8, 0x4f, 0x58, 0xe0, 0x01, 0xe2,
57
  0x16, 0x38, 0xc4, 0x6f, 0x3b, 0x0f, 0x65, 0x46,
58
  0xbe, 0x7e, 0x2d, 0x7b, 0x82, 0xf9, 0x40, 0xb5,
59
  0x1d, 0x73, 0xf8, 0xeb, 0x26, 0xc7, 0x87, 0x97,
60
  0x25, 0x54, 0xb1, 0x28, 0xaa, 0x98, 0x9d, 0xa5,
61
  0x64, 0x6d, 0x7a, 0xd4, 0x10, 0x81, 0x44, 0xef,
62
  0x49, 0xd6, 0xae, 0x2e, 0xdd, 0x76, 0x5c, 0x2f,
63
  0xa7, 0x1c, 0xc9, 0x09, 0x69, 0x9a, 0x83, 0xcf,
64
  0x29, 0x39, 0xb9, 0xe9, 0x4c, 0xff, 0x43, 0xab,
65
};
66
67
/*Some more JTR variables*/
68
static char crypt_key[BINARY_SIZE+1];
69
static char saved_key[PLAINTEXT_LENGTH + 1];
70
71
/*Utility function to convert hex to bin */
72
static void * binary (char *ciphertext)
73
{
74
  static char realcipher[BINARY_SIZE];
75
  int i;
76
  for (i = 0; i < BINARY_SIZE; i++)
77
      realcipher[i] = atoi16[ARCH_INDEX(ciphertext[i*2])]*16 + atoi16[ARCH_INDEX(ciphertext[i*2+1])];
78
  return ((void *) realcipher);
79
}
80
81
/*Another function required by JTR: decides whether we have a valid
82
 * ciphertext */
83
static int
84
valid (char *ciphertext)
85
{
86
  int i;
87
  
88
  for (i = 0; i < CIPHERTEXT_LENGTH; i++)
89
	  if (!(((ciphertext[i] >= '0') && (ciphertext[i] <= '9'))
90
				  || ((ciphertext[i] >= 'a') && (ciphertext[i] <= 'f'))
91
				  || ((ciphertext[i] >= 'A') && (ciphertext[i] <= 'F'))))
92
	  {
93
		  return 0;
94
	  }
95
  return 1;
96
}
97
98
/*sets the value of saved_key so we can play with it*/
99
static void set_key (char *key, int index)
100
{
101
  strnzcpy (saved_key, key, PLAINTEXT_LENGTH + 1);
102
}
103
104
/*retrieves the saved key; used by JTR*/
105
static char * get_key (int index)
106
{
107
  return saved_key;
108
}
109
static int
110
cmp_all (void *binary, int index)
111
{
112
	int i = 0;
113
	while(i<BINARY_SIZE)
114
	{
115
		if(((char *)binary)[i]!=((char *)crypt_key)[i])
116
			return 0;
117
		i++;
118
	}
119
	return 1;
120
}
121
static int cmp_exact (char *source, int index) 
122
{
123
  return 1;
124
}
125
126
static void set_salt (void *salt) { }
127
128
129
/*Beginning of private functions*/
130
/* Takes the plaintext password and generates the second row of our
131
 * working matrix for the final call to the mixing function*/
132
void
133
lotus_transform_password (unsigned char *inpass, unsigned char *outh)
134
{
135
  unsigned char prevbyte;
136
  int i;
137
138
  prevbyte = 0x00;
139
  for (i = 0; i < 16; i++)
140
    {
141
      *outh = lotus_magic_table[ARCH_INDEX((*inpass) ^ prevbyte)];
142
      prevbyte = *outh;
143
      ++outh;
144
      ++inpass;
145
    }
146
}
147
148
/* The mixing function: perturbs the first three rows of the matrix*/
149
void lotus_mix (unsigned char *lotus_matrix)
150
{
151
  int i, j;
152
  unsigned char prevbyte;
153
  unsigned char *temp;
154
155
  prevbyte = 0x00;
156
157
  for (i = 18; i > 0; i--)
158
    {
159
      temp = lotus_matrix;
160
      for (j = 48; j > 0; j--)
161
	{
162
	  *temp = *temp ^ lotus_magic_table[ARCH_INDEX((j + prevbyte) & 0xff)];
163
	  prevbyte = *temp;
164
	  temp++;
165
	}
166
    }
167
}
168
169
170
/*the last public function; generates ciphertext*/
171
static void crypt_all (int count)
172
{
173
  unsigned char password[PLAINTEXT_LENGTH];
174
  unsigned char lotus_matrix[64], *lotus_matrix1, *lotus_matrix2, *lotus_matrix3, *lotus_matrix4;
175
  int i;
176
  int password_length;
177
178
  password_length = strlen (saved_key);
179
  memset (password, (PLAINTEXT_LENGTH - password_length), PLAINTEXT_LENGTH);
180
  lotus_matrix1 = lotus_matrix;
181
  lotus_matrix2 = lotus_matrix1 + 16;
182
  lotus_matrix3 = lotus_matrix2 + 16;
183
  lotus_matrix4 = lotus_matrix3 + 16;
184
  memcpy (password, saved_key, password_length);
185
186
  memset (lotus_matrix1, 0, 16);
187
  memcpy (lotus_matrix2, password, 16);
188
  memcpy (lotus_matrix3, password, 16);
189
  lotus_transform_password (lotus_matrix2, lotus_matrix4);
190
  lotus_mix (lotus_matrix);
191
  memcpy (lotus_matrix2, lotus_matrix4, 16);
192
  for (i = 0; i < 16; i++)
193
    {
194
      lotus_matrix3[i] = lotus_matrix1[i] ^ lotus_matrix2[i];
195
    }
196
  lotus_mix (lotus_matrix);
197
  memcpy (crypt_key, lotus_matrix1, BINARY_SIZE);
198
}
199
200
static int get_hash1(int index) { return (((unsigned int *)crypt_key)[0] & 0xf); }
201
static int get_hash2(int index) { return (((unsigned int *)crypt_key)[0] & 0xff); }
202
static int get_hash3(int index) { return (((unsigned int *)crypt_key)[0] & 0xfff); }
203
static int binary_hash1(void * binary) { return (((unsigned int *)binary)[0] & 0xf); }
204
static int binary_hash2(void * binary) { return (((unsigned int *)binary)[0] & 0xff); }
205
static int binary_hash3(void * binary) { return (((unsigned int *)binary)[0] & 0xfff); }
206
207
/* C's version of a class specifier */
208
struct fmt_main fmt_lotus5 = {
209
	{
210
		FORMAT_LABEL,
211
		FORMAT_NAME,
212
		ALGORITHM_NAME,
213
		BENCHMARK_COMMENT,
214
		BENCHMARK_LENGTH,
215
		PLAINTEXT_LENGTH,
216
		BINARY_SIZE,
217
		SALT_SIZE,
218
		MIN_KEYS_PER_CRYPT,
219
		MAX_KEYS_PER_CRYPT,
220
		FMT_CASE | FMT_8_BIT,
221
		tests
222
	}, {
223
		fmt_default_init,
224
		valid,
225
		fmt_default_split,
226
		binary,
227
		fmt_default_salt,
228
		{
229
			binary_hash1,
230
                        binary_hash2,
231
                        binary_hash3
232
		},
233
		fmt_default_salt_hash,
234
		set_salt,
235
		set_key,
236
		get_key,
237
		fmt_default_clear_keys,
238
		crypt_all,
239
		{
240
			get_hash1,
241
                        get_hash2,
242
                        get_hash3
243
		},
244
		cmp_all,
245
		cmp_all,
246
		cmp_exact}
247
};
(-)john-1.7.0.1/src/md4-mmx.S (+194 lines)
Line 0 Link Here
1
2
// extern int mdfourmmx(unsigned char *out, unsigned char *in, int n) __attribute__((regparm(3)));
3
4
#ifdef UNDERSCORES
5
#define mdfourmmx	_mdfourmmx
6
#endif
7
8
.globl mdfourmmx
9
10
.data
11
.align(16)
12
const_init_a:
13
.long 0x67452301
14
.long 0x67452301
15
const_init_b:
16
.long 0xefcdab89
17
.long 0xefcdab89
18
const_init_c:
19
.long 0x98badcfe
20
.long 0x98badcfe
21
const_init_d:
22
.long 0x10325476
23
.long 0x10325476
24
25
const_stage2:
26
.long 0x5a827999
27
.long 0x5a827999
28
const_stage3:
29
.long 0x6ed9eba1
30
.long 0x6ed9eba1
31
32
.align(16)
33
buffer:
34
.zero(64*2)
35
36
#define ctxa %mm0
37
#define ctxb %mm1
38
#define ctxc %mm2
39
#define ctxd %mm3
40
#define tmp1 %mm4
41
#define tmp2 %mm5
42
#define tmp3 %mm6
43
#define tmp4 %mm7
44
45
46
//#define F_MMX(x, y, z)			(z ^ (x & (y ^ z)))
47
48
#define F(x,y,z) \
49
	movq y, tmp1; \
50
	pxor z, tmp1; \
51
	pand x, tmp1; \
52
	pxor z, tmp1
53
54
//#define G_MMX(x, y, z)			((x & (y | z)) | (y & z))
55
56
#define G(x,y,z) \
57
	movq y, tmp1; \
58
	movq y, tmp2; \
59
	por z, tmp1; \
60
	pand z, tmp2; \
61
	pand x, tmp1; \
62
	por tmp2, tmp1
63
64
//#define H_MMX(x, y, z)			(x ^ y ^ z)
65
#define H(x,y,z) \
66
	movq x, tmp1; \
67
	pxor y, tmp1; \
68
	pxor z, tmp1
69
70
//#define STEP_MMX(f, a, b, c, d, x, s) \
71
//	(a) += f((b), (c), (d)) + (x); \
72
//	(a) = (((a) << (s)) | (((a) & 0xffffffff) >> (32 - (s))));
73
74
#define STEP1(f, a, b, c, d, x, s) \
75
	f(b, c, d); \
76
	paddd (x*8)(%edx), tmp1; \
77
	paddd tmp1, a; \
78
	movq a, tmp3; \
79
	pslld $s, a; \
80
	psrld $(32-s), tmp3; \
81
	por tmp3, a
82
83
#define STEP2(f, a, b, c, d, x, s) \
84
	f(b, c, d); \
85
	paddd (x*8)(%edx), tmp1; \
86
	paddd tmp4, tmp1; \
87
	paddd tmp1, a; \
88
	movq a, tmp3; \
89
	pslld $s, a; \
90
	psrld $(32-s), tmp3; \
91
	por tmp3, a
92
93
94
.text
95
/*
96
 * Try to do some asm md4 w/ mmx
97
 * %eax ptr -> out
98
 * %edx ptr -> in
99
 * %ecx n
100
 */
101
102
mdfourmmx:
103
	 //MD4 Init
104
	 pusha
105
	
106
	shl $3, %ecx
107
	mov %ecx, %ebx
108
	and $0xffff, %ecx
109
	shrl $16,  %ebx
110
	// %ecx contient la taille du premier mdp
111
	// %edx celle du second
112
	mov %ecx, (14*8)(%edx)
113
	mov %ebx, (14*8+4)(%edx)
114
115
	movq const_init_a, ctxa
116
	movq const_init_b, ctxb
117
	movq const_init_c, ctxc
118
	movq const_init_d, ctxd
119
120
	STEP1(F, ctxa, ctxb, ctxc, ctxd, 0, 3)
121
	STEP1(F, ctxd, ctxa, ctxb, ctxc, 1, 7)
122
	STEP1(F, ctxc, ctxd, ctxa, ctxb, 2, 11)
123
	STEP1(F, ctxb, ctxc, ctxd, ctxa, 3, 19)
124
	STEP1(F, ctxa, ctxb, ctxc, ctxd, 4, 3)
125
	STEP1(F, ctxd, ctxa, ctxb, ctxc, 5, 7)
126
	STEP1(F, ctxc, ctxd, ctxa, ctxb, 6, 11)
127
	STEP1(F, ctxb, ctxc, ctxd, ctxa, 7, 19)
128
	STEP1(F, ctxa, ctxb, ctxc, ctxd, 8, 3)
129
	STEP1(F, ctxd, ctxa, ctxb, ctxc, 9, 7)
130
	STEP1(F, ctxc, ctxd, ctxa, ctxb, 10, 11)
131
	STEP1(F, ctxb, ctxc, ctxd, ctxa, 11, 19)
132
	STEP1(F, ctxa, ctxb, ctxc, ctxd, 12, 3)
133
	STEP1(F, ctxd, ctxa, ctxb, ctxc, 13, 7)
134
	STEP1(F, ctxc, ctxd, ctxa, ctxb, 14, 11)
135
	STEP1(F, ctxb, ctxc, ctxd, ctxa, 15, 19)
136
137
	movq const_stage2, tmp4
138
139
	STEP2(G, ctxa, ctxb, ctxc, ctxd, 0, 3)
140
	STEP2(G, ctxd, ctxa, ctxb, ctxc, 4, 5)
141
	STEP2(G, ctxc, ctxd, ctxa, ctxb, 8, 9)
142
	STEP2(G, ctxb, ctxc, ctxd, ctxa, 12, 13)
143
	STEP2(G, ctxa, ctxb, ctxc, ctxd, 1, 3)
144
	STEP2(G, ctxd, ctxa, ctxb, ctxc, 5, 5)
145
	STEP2(G, ctxc, ctxd, ctxa, ctxb, 9, 9)
146
	STEP2(G, ctxb, ctxc, ctxd, ctxa, 13, 13)
147
	STEP2(G, ctxa, ctxb, ctxc, ctxd, 2, 3)
148
	STEP2(G, ctxd, ctxa, ctxb, ctxc, 6, 5)
149
	STEP2(G, ctxc, ctxd, ctxa, ctxb, 10, 9)
150
	STEP2(G, ctxb, ctxc, ctxd, ctxa, 14, 13)
151
	STEP2(G, ctxa, ctxb, ctxc, ctxd, 3, 3)
152
	STEP2(G, ctxd, ctxa, ctxb, ctxc, 7, 5)
153
	STEP2(G, ctxc, ctxd, ctxa, ctxb, 11, 9)
154
	STEP2(G, ctxb, ctxc, ctxd, ctxa, 15, 13)
155
156
	movq const_stage3, tmp4
157
158
	STEP2(H, ctxa, ctxb, ctxc, ctxd, 0, 3)
159
	STEP2(H, ctxd, ctxa, ctxb, ctxc, 8, 9)
160
	STEP2(H, ctxc, ctxd, ctxa, ctxb, 4, 11)
161
	STEP2(H, ctxb, ctxc, ctxd, ctxa, 12, 15)
162
	STEP2(H, ctxa, ctxb, ctxc, ctxd, 2, 3)
163
	STEP2(H, ctxd, ctxa, ctxb, ctxc, 10, 9)
164
	STEP2(H, ctxc, ctxd, ctxa, ctxb, 6, 11)
165
	STEP2(H, ctxb, ctxc, ctxd, ctxa, 14, 15)
166
	STEP2(H, ctxa, ctxb, ctxc, ctxd, 1, 3)
167
	STEP2(H, ctxd, ctxa, ctxb, ctxc, 9, 9)
168
	STEP2(H, ctxc, ctxd, ctxa, ctxb, 5, 11)
169
	STEP2(H, ctxb, ctxc, ctxd, ctxa, 13, 15)
170
	STEP2(H, ctxa, ctxb, ctxc, ctxd, 3, 3)
171
	STEP2(H, ctxd, ctxa, ctxb, ctxc, 11, 9)
172
	STEP2(H, ctxc, ctxd, ctxa, ctxb, 7, 11)
173
	STEP2(H, ctxb, ctxc, ctxd, ctxa, 15, 15)
174
175
	paddd const_init_a, ctxa
176
	paddd const_init_b, ctxb
177
	paddd const_init_c, ctxc
178
	paddd const_init_d, ctxd
179
180
181
	movq ctxa, 0(%eax)
182
	movq ctxb, 8(%eax)
183
	movq ctxc, 16(%eax)
184
	movq ctxd, 24(%eax)
185
186
	popa
187
	movd ctxa, %eax
188
	emms
189
	
190
	ret
191
192
#ifdef __ELF__
193
.section .note.GNU-stack,"",@progbits
194
#endif
(-)john-1.7.0.1/src/md4-sse2.S (+223 lines)
Line 0 Link Here
1
2
// extern int mdfoursse2(unsigned char *out, unsigned char *in, int n) __attribute__((regparm(3)));
3
4
#ifdef UNDERSCORES
5
#define mdfoursse2	_mdfoursse2
6
#endif
7
8
.globl mdfoursse2
9
10
.data
11
.align(16)
12
const_init_a:
13
.long 0x67452301
14
.long 0x67452301
15
.long 0x67452301
16
.long 0x67452301
17
const_init_b:
18
.long 0xefcdab89
19
.long 0xefcdab89
20
.long 0xefcdab89
21
.long 0xefcdab89
22
const_init_c:
23
.long 0x98badcfe
24
.long 0x98badcfe
25
.long 0x98badcfe
26
.long 0x98badcfe
27
const_init_d:
28
.long 0x10325476
29
.long 0x10325476
30
.long 0x10325476
31
.long 0x10325476
32
33
const_stage2:
34
.long 0x5a827999
35
.long 0x5a827999
36
.long 0x5a827999
37
.long 0x5a827999
38
const_stage3:
39
.long 0x6ed9eba1
40
.long 0x6ed9eba1
41
.long 0x6ed9eba1
42
.long 0x6ed9eba1
43
44
.align(16)
45
buffer:
46
.zero(64*4)
47
48
#define ctxa %xmm0
49
#define ctxb %xmm1
50
#define ctxc %xmm2
51
#define ctxd %xmm3
52
#define tmp1 %xmm4
53
#define tmp2 %xmm5
54
#define tmp3 %xmm6
55
#define tmp4 %xmm7
56
57
58
//#define F_MMX(x, y, z)			(z ^ (x & (y ^ z)))
59
60
#define F(x,y,z) \
61
	movapd y, tmp1; \
62
	pxor z, tmp1; \
63
	pand x, tmp1; \
64
	pxor z, tmp1
65
66
//#define G_MMX(x, y, z)			((x & (y | z)) | (y & z))
67
68
#define G(x,y,z) \
69
	movapd y, tmp1; \
70
	movapd y, tmp2; \
71
	por z, tmp1; \
72
	pand z, tmp2; \
73
	pand x, tmp1; \
74
	por tmp2, tmp1
75
76
//#define H_MMX(x, y, z)			(x ^ y ^ z)
77
#define H(x,y,z) \
78
	movapd x, tmp1; \
79
	pxor y, tmp1; \
80
	pxor z, tmp1
81
82
//#define STEP_MMX(f, a, b, c, d, x, s) \
83
//	(a) += f((b), (c), (d)) + (x); \
84
//	(a) = (((a) << (s)) | (((a) & 0xffffffff) >> (32 - (s))));
85
86
#define STEP1(f, a, b, c, d, x, s) \
87
	f(b, c, d); \
88
	paddd (x*16)(%edx), tmp1; \
89
	paddd tmp1, a; \
90
	movapd a, tmp3; \
91
	pslld $s, a; \
92
	psrld $(32-s), tmp3; \
93
	por tmp3, a
94
95
#define STEP2(f, a, b, c, d, x, s) \
96
	f(b, c, d); \
97
	paddd (x*16)(%edx), tmp1; \
98
	paddd tmp4, tmp1; \
99
	paddd tmp1, a; \
100
	movapd a, tmp3; \
101
	pslld $s, a; \
102
	psrld $(32-s), tmp3; \
103
	por tmp3, a
104
105
106
.text
107
/*
108
 * Try to do some asm md4 w/ sse2
109
 * %eax ptr -> out
110
 * %edx ptr -> in
111
 * %ecx n
112
 */
113
114
mdfoursse2:
115
	 //MD4 Init
116
	 pusha
117
	
118
	//mov %edx, %eax
119
	//ret
120
121
//	shl $3, %ecx
122
	mov %ecx, %ebx
123
	shr $8, %ecx
124
	and $0xff, %ebx
125
	shl $3, %ebx
126
	mov %ebx, (14*16)(%edx)
127
	
128
	mov %ecx, %ebx
129
	shr $8, %ecx
130
	and $0xff, %ebx
131
	shl $3, %ebx
132
	mov %ebx, (14*16+4)(%edx)
133
134
	mov %ecx, %ebx
135
	shr $8, %ecx
136
	and $0xff, %ebx
137
	shl $3, %ebx
138
	mov %ebx, (14*16+8)(%edx)
139
140
	and $0xff, %ecx
141
	shl $3, %ecx
142
	mov %ecx, (14*16+12)(%edx)
143
144
	movapd const_init_a, ctxa
145
	movapd const_init_b, ctxb
146
	movapd const_init_c, ctxc
147
	movapd const_init_d, ctxd
148
149
	STEP1(F, ctxa, ctxb, ctxc, ctxd, 0, 3)
150
	STEP1(F, ctxd, ctxa, ctxb, ctxc, 1, 7)
151
	STEP1(F, ctxc, ctxd, ctxa, ctxb, 2, 11)
152
	STEP1(F, ctxb, ctxc, ctxd, ctxa, 3, 19)
153
	STEP1(F, ctxa, ctxb, ctxc, ctxd, 4, 3)
154
	STEP1(F, ctxd, ctxa, ctxb, ctxc, 5, 7)
155
	STEP1(F, ctxc, ctxd, ctxa, ctxb, 6, 11)
156
	STEP1(F, ctxb, ctxc, ctxd, ctxa, 7, 19)
157
	STEP1(F, ctxa, ctxb, ctxc, ctxd, 8, 3)
158
	STEP1(F, ctxd, ctxa, ctxb, ctxc, 9, 7)
159
	STEP1(F, ctxc, ctxd, ctxa, ctxb, 10, 11)
160
	STEP1(F, ctxb, ctxc, ctxd, ctxa, 11, 19)
161
	STEP1(F, ctxa, ctxb, ctxc, ctxd, 12, 3)
162
	STEP1(F, ctxd, ctxa, ctxb, ctxc, 13, 7)
163
	STEP1(F, ctxc, ctxd, ctxa, ctxb, 14, 11)
164
	STEP1(F, ctxb, ctxc, ctxd, ctxa, 15, 19)
165
166
	movapd const_stage2, tmp4
167
168
	STEP2(G, ctxa, ctxb, ctxc, ctxd, 0, 3)
169
	STEP2(G, ctxd, ctxa, ctxb, ctxc, 4, 5)
170
	STEP2(G, ctxc, ctxd, ctxa, ctxb, 8, 9)
171
	STEP2(G, ctxb, ctxc, ctxd, ctxa, 12, 13)
172
	STEP2(G, ctxa, ctxb, ctxc, ctxd, 1, 3)
173
	STEP2(G, ctxd, ctxa, ctxb, ctxc, 5, 5)
174
	STEP2(G, ctxc, ctxd, ctxa, ctxb, 9, 9)
175
	STEP2(G, ctxb, ctxc, ctxd, ctxa, 13, 13)
176
	STEP2(G, ctxa, ctxb, ctxc, ctxd, 2, 3)
177
	STEP2(G, ctxd, ctxa, ctxb, ctxc, 6, 5)
178
	STEP2(G, ctxc, ctxd, ctxa, ctxb, 10, 9)
179
	STEP2(G, ctxb, ctxc, ctxd, ctxa, 14, 13)
180
	STEP2(G, ctxa, ctxb, ctxc, ctxd, 3, 3)
181
	STEP2(G, ctxd, ctxa, ctxb, ctxc, 7, 5)
182
	STEP2(G, ctxc, ctxd, ctxa, ctxb, 11, 9)
183
	STEP2(G, ctxb, ctxc, ctxd, ctxa, 15, 13)
184
185
	movapd const_stage3, tmp4
186
187
	STEP2(H, ctxa, ctxb, ctxc, ctxd, 0, 3)
188
	STEP2(H, ctxd, ctxa, ctxb, ctxc, 8, 9)
189
	STEP2(H, ctxc, ctxd, ctxa, ctxb, 4, 11)
190
	STEP2(H, ctxb, ctxc, ctxd, ctxa, 12, 15)
191
	STEP2(H, ctxa, ctxb, ctxc, ctxd, 2, 3)
192
	STEP2(H, ctxd, ctxa, ctxb, ctxc, 10, 9)
193
	STEP2(H, ctxc, ctxd, ctxa, ctxb, 6, 11)
194
	STEP2(H, ctxb, ctxc, ctxd, ctxa, 14, 15)
195
	STEP2(H, ctxa, ctxb, ctxc, ctxd, 1, 3)
196
	STEP2(H, ctxd, ctxa, ctxb, ctxc, 9, 9)
197
	STEP2(H, ctxc, ctxd, ctxa, ctxb, 5, 11)
198
	STEP2(H, ctxb, ctxc, ctxd, ctxa, 13, 15)
199
	STEP2(H, ctxa, ctxb, ctxc, ctxd, 3, 3)
200
	STEP2(H, ctxd, ctxa, ctxb, ctxc, 11, 9)
201
	STEP2(H, ctxc, ctxd, ctxa, ctxb, 7, 11)
202
	STEP2(H, ctxb, ctxc, ctxd, ctxa, 15, 15)
203
204
	paddd const_init_a, ctxa
205
	paddd const_init_b, ctxb
206
	paddd const_init_c, ctxc
207
	paddd const_init_d, ctxd
208
209
210
	movapd ctxa, 0(%eax)
211
	movapd ctxb, 16(%eax)
212
	movapd ctxc, 32(%eax)
213
	movapd ctxd, 48(%eax)
214
215
	popa
216
	movd ctxa, %eax
217
	emms
218
	
219
	ret
220
221
#ifdef __ELF__
222
.section .note.GNU-stack,"",@progbits
223
#endif
(-)john-1.7.0.1/src/md4.c (+276 lines)
Line 0 Link Here
1
/*
2
 * This is an OpenSSL-compatible implementation of the RSA Data Security,
3
 * Inc. MD4 Message-Digest Algorithm (RFC 1320).
4
 *
5
 * Written by Solar Designer <solar at openwall.com> in 2005, and placed
6
 * in the public domain.  There's absolutely no warranty.
7
 *
8
 * This differs from Colin Plumb's older public domain implementation in
9
 * that no 32-bit integer data type is required, there's no compile-time
10
 * endianness configuration, and the function prototypes match OpenSSL's.
11
 * The primary goals are portability and ease of use.
12
 *
13
 * This implementation is meant to be fast, but not as fast as possible.
14
 * Some known optimizations are not included to reduce source code size
15
 * and avoid compile-time configuration.
16
 */
17
18
#ifndef HAVE_OPENSSL
19
20
#include <string.h>
21
#include "md4.h"
22
23
/*
24
 * The basic MD4 functions.
25
 *
26
 * F and G are optimized compared to their RFC 1320 definitions, with the
27
 * optimization for F borrowed from Colin Plumb's MD5 implementation.
28
 */
29
#define F(x, y, z)			((z) ^ ((x) & ((y) ^ (z))))
30
#define G(x, y, z)			(((x) & ((y) | (z))) | ((y) & (z)))
31
#define H(x, y, z)			((x) ^ (y) ^ (z))
32
33
/*
34
 * The MD4 transformation for all three rounds.
35
 */
36
#define STEP(f, a, b, c, d, x, s) \
37
	(a) += f((b), (c), (d)) + (x); \
38
	(a) = (((a) << (s)) | (((a) & 0xffffffff) >> (32 - (s))));
39
40
/*
41
 * SET reads 4 input bytes in little-endian byte order and stores them
42
 * in a properly aligned word in host byte order.
43
 *
44
 * The check for little-endian architectures which tolerate unaligned
45
 * memory accesses is just an optimization.  Nothing will break if it
46
 * doesn't work.
47
 */
48
#if defined(__i386__) || defined(__vax__)
49
#define SET(n) \
50
	(*(MD4_u32plus *)&ptr[(n) * 4])
51
#define GET(n) \
52
	SET(n)
53
#else
54
#define SET(n) \
55
	(ctx->block[(n)] = \
56
	(MD4_u32plus)ptr[(n) * 4] | \
57
	((MD4_u32plus)ptr[(n) * 4 + 1] << 8) | \
58
	((MD4_u32plus)ptr[(n) * 4 + 2] << 16) | \
59
	((MD4_u32plus)ptr[(n) * 4 + 3] << 24))
60
#define GET(n) \
61
	(ctx->block[(n)])
62
#endif
63
64
/*
65
 * This processes one or more 64-byte data blocks, but does NOT update
66
 * the bit counters.  There're no alignment requirements.
67
 */
68
static void *body(MD4_CTX *ctx, void *data, unsigned long size)
69
{
70
	unsigned char *ptr;
71
	MD4_u32plus a, b, c, d;
72
	MD4_u32plus saved_a, saved_b, saved_c, saved_d;
73
74
	ptr = data;
75
76
	a = ctx->a;
77
	b = ctx->b;
78
	c = ctx->c;
79
	d = ctx->d;
80
81
	do {
82
		saved_a = a;
83
		saved_b = b;
84
		saved_c = c;
85
		saved_d = d;
86
87
/* Round 1 */
88
		STEP(F, a, b, c, d, SET(0), 3)
89
		STEP(F, d, a, b, c, SET(1), 7)
90
		STEP(F, c, d, a, b, SET(2), 11)
91
		STEP(F, b, c, d, a, SET(3), 19)
92
		STEP(F, a, b, c, d, SET(4), 3)
93
		STEP(F, d, a, b, c, SET(5), 7)
94
		STEP(F, c, d, a, b, SET(6), 11)
95
		STEP(F, b, c, d, a, SET(7), 19)
96
		STEP(F, a, b, c, d, SET(8), 3)
97
		STEP(F, d, a, b, c, SET(9), 7)
98
		STEP(F, c, d, a, b, SET(10), 11)
99
		STEP(F, b, c, d, a, SET(11), 19)
100
		STEP(F, a, b, c, d, SET(12), 3)
101
		STEP(F, d, a, b, c, SET(13), 7)
102
		STEP(F, c, d, a, b, SET(14), 11)
103
		STEP(F, b, c, d, a, SET(15), 19)
104
105
/* Round 2 */
106
		STEP(G, a, b, c, d, GET(0) + 0x5a827999, 3)
107
		STEP(G, d, a, b, c, GET(4) + 0x5a827999, 5)
108
		STEP(G, c, d, a, b, GET(8) + 0x5a827999, 9)
109
		STEP(G, b, c, d, a, GET(12) + 0x5a827999, 13)
110
		STEP(G, a, b, c, d, GET(1) + 0x5a827999, 3)
111
		STEP(G, d, a, b, c, GET(5) + 0x5a827999, 5)
112
		STEP(G, c, d, a, b, GET(9) + 0x5a827999, 9)
113
		STEP(G, b, c, d, a, GET(13) + 0x5a827999, 13)
114
		STEP(G, a, b, c, d, GET(2) + 0x5a827999, 3)
115
		STEP(G, d, a, b, c, GET(6) + 0x5a827999, 5)
116
		STEP(G, c, d, a, b, GET(10) + 0x5a827999, 9)
117
		STEP(G, b, c, d, a, GET(14) + 0x5a827999, 13)
118
		STEP(G, a, b, c, d, GET(3) + 0x5a827999, 3)
119
		STEP(G, d, a, b, c, GET(7) + 0x5a827999, 5)
120
		STEP(G, c, d, a, b, GET(11) + 0x5a827999, 9)
121
		STEP(G, b, c, d, a, GET(15) + 0x5a827999, 13)
122
123
/* Round 3 */
124
		STEP(H, a, b, c, d, GET(0) + 0x6ed9eba1, 3)
125
		STEP(H, d, a, b, c, GET(8) + 0x6ed9eba1, 9)
126
		STEP(H, c, d, a, b, GET(4) + 0x6ed9eba1, 11)
127
		STEP(H, b, c, d, a, GET(12) + 0x6ed9eba1, 15)
128
		STEP(H, a, b, c, d, GET(2) + 0x6ed9eba1, 3)
129
		STEP(H, d, a, b, c, GET(10) + 0x6ed9eba1, 9)
130
		STEP(H, c, d, a, b, GET(6) + 0x6ed9eba1, 11)
131
		STEP(H, b, c, d, a, GET(14) + 0x6ed9eba1, 15)
132
		STEP(H, a, b, c, d, GET(1) + 0x6ed9eba1, 3)
133
		STEP(H, d, a, b, c, GET(9) + 0x6ed9eba1, 9)
134
		STEP(H, c, d, a, b, GET(5) + 0x6ed9eba1, 11)
135
		STEP(H, b, c, d, a, GET(13) + 0x6ed9eba1, 15)
136
		STEP(H, a, b, c, d, GET(3) + 0x6ed9eba1, 3)
137
		STEP(H, d, a, b, c, GET(11) + 0x6ed9eba1, 9)
138
		STEP(H, c, d, a, b, GET(7) + 0x6ed9eba1, 11)
139
		STEP(H, b, c, d, a, GET(15) + 0x6ed9eba1, 15)
140
141
		a += saved_a;
142
		b += saved_b;
143
		c += saved_c;
144
		d += saved_d;
145
146
		ptr += 64;
147
	} while (size -= 64);
148
149
	ctx->a = a;
150
	ctx->b = b;
151
	ctx->c = c;
152
	ctx->d = d;
153
154
	return ptr;
155
}
156
157
void MD4_Init(MD4_CTX *ctx)
158
{
159
	ctx->a = 0x67452301;
160
	ctx->b = 0xefcdab89;
161
	ctx->c = 0x98badcfe;
162
	ctx->d = 0x10325476;
163
164
	ctx->lo = 0;
165
	ctx->hi = 0;
166
}
167
168
void MD4_Update(MD4_CTX *ctx, void *data, unsigned long size)
169
{
170
	MD4_u32plus saved_lo;
171
	unsigned long used, free;
172
173
	saved_lo = ctx->lo;
174
	if ((ctx->lo = (saved_lo + size) & 0x1fffffff) < saved_lo)
175
		ctx->hi++;
176
	ctx->hi += size >> 29;
177
178
	used = saved_lo & 0x3f;
179
180
	if (used) {
181
		free = 64 - used;
182
183
		if (size < free) {
184
			memcpy(&ctx->buffer[used], data, size);
185
			return;
186
		}
187
		
188
		memcpy(&ctx->buffer[used], data, free);
189
190
		data = (unsigned char *)data + free;
191
		size -= free;
192
		body(ctx, ctx->buffer, 64);
193
	}
194
195
	if (size >= 64) {
196
		data = body(ctx, data, size & ~(unsigned long)0x3f);
197
		size &= 0x3f;
198
	}
199
200
	memcpy(ctx->buffer, data, size);
201
}
202
203
void MD4_Final(unsigned char *result, MD4_CTX *ctx)
204
{
205
	unsigned long used, free;
206
207
	used = ctx->lo & 0x3f;
208
209
	ctx->buffer[used++] = 0x80;
210
211
	free = 64 - used;
212
213
	if (free < 8) {
214
		memset(&ctx->buffer[used], 0, free);
215
		body(ctx, ctx->buffer, 64);
216
		used = 0;
217
		free = 64;
218
	}
219
220
	memset(&ctx->buffer[used], 0, free - 8);
221
222
223
	ctx->lo <<= 3;
224
#ifndef ARCH_LITTLE_ENDIAN
225
	ctx->buffer[56] = ctx->lo;
226
	ctx->buffer[57] = ctx->lo >> 8;
227
	ctx->buffer[58] = ctx->lo >> 16;
228
	ctx->buffer[59] = ctx->lo >> 24;
229
	ctx->buffer[60] = ctx->hi;
230
	ctx->buffer[61] = ctx->hi >> 8;
231
	ctx->buffer[62] = ctx->hi >> 16;
232
	ctx->buffer[63] = ctx->hi >> 24;
233
#else
234
	((unsigned long *)ctx->buffer)[14] = ctx->lo;
235
	((unsigned long *)ctx->buffer)[15] = ctx->hi;
236
#endif
237
238
	body(ctx, ctx->buffer, 64);
239
240
#ifndef ARCH_LITTLE_ENDIAN
241
	result[0] = ctx->a;
242
	result[1] = ctx->a >> 8;
243
	result[2] = ctx->a >> 16;
244
	result[3] = ctx->a >> 24;
245
	result[4] = ctx->b;
246
	result[5] = ctx->b >> 8;
247
	result[6] = ctx->b >> 16;
248
	result[7] = ctx->b >> 24;
249
	result[8] = ctx->c;
250
	result[9] = ctx->c >> 8;
251
	result[10] = ctx->c >> 16;
252
	result[11] = ctx->c >> 24;
253
	result[12] = ctx->d;
254
	result[13] = ctx->d >> 8;
255
	result[14] = ctx->d >> 16;
256
	result[15] = ctx->d >> 24;
257
#else
258
	((unsigned long *)result)[0] = ctx->a;
259
	((unsigned long *)result)[1] = ctx->b;
260
	((unsigned long *)result)[2] = ctx->c;
261
	((unsigned long *)result)[3] = ctx->d;
262
#endif
263
264
	memset(ctx, 0, sizeof(*ctx));
265
}
266
267
//this function has been added by bartavelle at bandecon.com
268
void mdfour(unsigned char *out, unsigned char *in, int n)
269
{
270
	MD4_CTX ctx;
271
	MD4_Init(&ctx);
272
	MD4_Update(&ctx, in, n);
273
	MD4_Final(out, &ctx);
274
}
275
276
#endif
(-)john-1.7.0.1/src/md4.h (+39 lines)
Line 0 Link Here
1
/*
2
 * This is an OpenSSL-compatible implementation of the RSA Data Security,
3
 * Inc. MD4 Message-Digest Algorithm (RFC 1320).
4
 *
5
 * Written by Solar Designer <solar at openwall.com> in 2005, and placed
6
 * in the public domain.  See md4.c for more information.
7
 */
8
9
#ifdef HAVE_OPENSSL
10
#include <openssl/md4.h>
11
#elif !defined(_MD4_H)
12
#define _MD4_H
13
14
/* Any 32-bit or wider unsigned integer data type will do */
15
typedef unsigned long MD4_u32plus;
16
17
typedef struct {
18
	MD4_u32plus lo, hi;
19
	MD4_u32plus a, b, c, d;
20
	unsigned char buffer[64];
21
	MD4_u32plus block[16];
22
} MD4_CTX;
23
24
extern void MD4_Init(MD4_CTX *ctx);
25
extern void MD4_Update(MD4_CTX *ctx, void *data, unsigned long size);
26
extern void MD4_Final(unsigned char *result, MD4_CTX *ctx);
27
28
//added by bartavelle
29
extern void mdfour(unsigned char *out, unsigned char *in, int n);
30
31
#if (MMX_COEF == 2)
32
extern int mdfourmmx(unsigned char *out, unsigned char *in, int n) __attribute__((regparm(3)));
33
#endif
34
35
#if (MMX_COEF == 4)
36
extern int mdfoursse2(unsigned char *out, unsigned char *in, int n) __attribute__((regparm(3)));
37
#endif
38
39
#endif
(-)john-1.7.0.1/src/md5-mmx.S (+307 lines)
Line 0 Link Here
1
#include "arch.h"
2
3
// extern int mdfourmmx(unsigned char *out, unsigned char *in, int n) __attribute__((regparm(3)));
4
5
#ifdef UNDERSCORES
6
#define mdfivemmx	_mdfivemmx
7
#endif
8
.globl mdfivemmx
9
.globl mdfivemmx_noinit_sizeupdate
10
.globl mdfivemmx_noinit_uniformsizeupdate
11
.globl mdfivemmx_nosizeupdate
12
13
.data
14
.align(16)
15
#if (MMX_COEF == 2)
16
const_init_a: ; .long 0x67452301 ; .long 0x67452301
17
const_init_b: ; .long 0xefcdab89 ; .long 0xefcdab89
18
const_init_c: ; .long 0x98badcfe ; .long 0x98badcfe
19
const_init_d: ; .long 0x10325476 ; .long 0x10325476
20
storea: ; .long 0 ; .long 0
21
storeb: ; .long 0 ; .long 0
22
storec: ; .long 0 ; .long 0
23
stored: ; .long 0 ; .long 0
24
#define REGMM0 %mm0
25
#define REGMM1 %mm1
26
#define REGMM2 %mm2
27
#define REGMM3 %mm3
28
#define REGMM4 %mm4
29
#define REGMM5 %mm5
30
#define REGMM6 %mm6
31
#define REGMM7 %mm7
32
#define MMXMOVE movq
33
#include "stages_mmx_md5.S"
34
#else
35
const_init_a: ; .long 0x67452301 ; .long 0x67452301 ; .long 0x67452301 ; .long 0x67452301
36
const_init_b: ; .long 0xefcdab89 ; .long 0xefcdab89 ; .long 0xefcdab89 ; .long 0xefcdab89
37
const_init_c: ; .long 0x98badcfe ; .long 0x98badcfe ; .long 0x98badcfe ; .long 0x98badcfe
38
const_init_d: ; .long 0x10325476 ; .long 0x10325476 ; .long 0x10325476 ; .long 0x10325476
39
storea: ; .long 0 ; .long 0 ; .long 0 ; .long 0
40
storeb: ; .long 0 ; .long 0 ; .long 0 ; .long 0
41
storec: ; .long 0 ; .long 0 ; .long 0 ; .long 0
42
stored: ; .long 0 ; .long 0 ; .long 0 ; .long 0
43
#define REGMM0 %xmm0
44
#define REGMM1 %xmm1
45
#define REGMM2 %xmm2
46
#define REGMM3 %xmm3
47
#define REGMM4 %xmm4
48
#define REGMM5 %xmm5
49
#define REGMM6 %xmm6
50
#define REGMM7 %xmm7
51
#define MMXMOVE movapd
52
#include "stages_sse2_md5.S"
53
#endif
54
55
56
#define ctxa REGMM0
57
#define ctxb REGMM1
58
#define ctxc REGMM2
59
#define ctxd REGMM3
60
#define tmp1 REGMM4
61
#define tmp2 REGMM5
62
#define tmp3 REGMM6
63
#define tmp4 REGMM7
64
65
66
//#define F_MMX(x, y, z)			(z ^ (x & (y ^ z)))
67
68
#define F(x,y,z) \
69
	MMXMOVE y, tmp1; \
70
	pxor z, tmp1; \
71
	pand x, tmp1; \
72
	pxor z, tmp1
73
74
//#define G_MMX(x, y, z)			(y ^ (z & (x ^ y)))
75
76
#define G(x,y,z) \
77
	MMXMOVE y, tmp1; \
78
	pxor x, tmp1; \
79
	pand z, tmp1; \
80
	pxor y, tmp1
81
82
//#define H_MMX(x, y, z)			(x ^ y ^ z)
83
#define H(x,y,z) \
84
	MMXMOVE x, tmp1; \
85
	pxor y, tmp1; \
86
	pxor z, tmp1
87
88
//#define I(x, y, z)			(y ^ (x | ~z))
89
#define I(x, y, z) \
90
	MMXMOVE z, tmp1; \
91
	pandn tmp4, tmp1; \
92
	por x, tmp1; \
93
	pxor y, tmp1;
94
95
96
//#define STEP_MMX(f, a, b, c, d, x, s) \
97
//	(a) += f((b), (c), (d)) + (x); \
98
//	(a) = (((a) << (s)) | (((a) & 0xffffffff) >> (32 - (s))));
99
100
//#define STEP(f, a, b, c, d, x, t, s) \
101
//	(a) += f((b), (c), (d)) + (x) + (t); \
102
//	(a) = (((a) << (s)) | (((a) & 0xffffffff) >> (32 - (s)))); \
103
//	(a) += (b);
104
105
106
#define STEP(f, a, b, c, d, x, t, s) \
107
	f(b, c, d); \
108
	paddd (x*4*MMX_COEF)(%edx), tmp1; \
109
	paddd t, a; \
110
	paddd tmp1, a; \
111
	MMXMOVE a, tmp3; \
112
	psrld $(32-s), tmp3; \
113
	pslld $s, a; \
114
	por tmp3, a; \
115
	paddd b, a
116
117
#define STEPD(f, a, b, c, d, x, t, s) \
118
	f(b, c, d); \
119
	paddd (x*4*MMX_COEF)(%edx), tmp1; \
120
	paddd t, a; \
121
	paddd tmp1, a; \
122
	MMXMOVE a, tmp3; \
123
	psrld $(32-s), tmp3; \
124
	pslld $s, a; \
125
	por tmp3, a; \
126
	paddd b, a
127
128
129
.text
130
/*
131
 * Try to do some asm md4 w/ mmx
132
 * %eax ptr -> out
133
 * %edx ptr -> in
134
 * %ecx n
135
 */
136
137
init:
138
	MMXMOVE const_init_a, ctxa
139
	MMXMOVE const_init_b, ctxb
140
	MMXMOVE const_init_c, ctxc
141
	MMXMOVE const_init_d, ctxd
142
	ret;
143
144
sizeupdate:
145
#if (MMX_COEF == 2)
146
	shl $3, %ecx
147
	mov %ecx, %ebx
148
	and $0xffff, %ecx
149
	shrl $16,  %ebx
150
	mov %ecx, (14*4*MMX_COEF)(%edx)
151
	mov %ebx, (14*4*MMX_COEF+4)(%edx)
152
#else
153
	mov %ecx, %ebx
154
        shr $8, %ecx
155
        and $0xff, %ebx
156
        shl $3, %ebx
157
        mov %ebx, (14*16)(%edx)
158
        
159
        mov %ecx, %ebx
160
        shr $8, %ecx
161
        and $0xff, %ebx
162
        shl $3, %ebx
163
        mov %ebx, (14*16+4)(%edx)
164
165
        mov %ecx, %ebx
166
        shr $8, %ecx
167
        and $0xff, %ebx
168
        shl $3, %ebx
169
        mov %ebx, (14*16+8)(%edx)
170
171
        and $0xff, %ecx
172
        shl $3, %ecx
173
        mov %ecx, (14*16+12)(%edx)
174
#endif
175
	ret
176
177
uniformsizeupdate:
178
	shl $3, %ecx
179
	mov %ecx, (14*4*MMX_COEF)(%edx)
180
	mov %ecx, (14*4*MMX_COEF+4)(%edx)
181
#if (MMX_COEF == 4)
182
	mov %ecx, (14*4*MMX_COEF+8)(%edx)
183
	mov %ecx, (14*4*MMX_COEF+12)(%edx)
184
#endif
185
	ret
186
187
//entry points
188
mdfivemmx_noinit_sizeupdate:
189
	pusha
190
	call sizeupdate
191
	jmp mdfivemmx_noinit
192
193
mdfivemmx_noinit_uniformsizeupdate:
194
	pusha
195
	call uniformsizeupdate
196
	jmp mdfivemmx_noinit
197
198
mdfivemmx:
199
	pusha
200
	call sizeupdate
201
	call init
202
	jmp mdfivemmx_noinit
203
204
mdfivemmx_nosizeupdate:
205
	pusha
206
	call init
207
	jmp mdfivemmx_noinit
208
//end entry points
209
210
mdfivemmx_noinit:
211
	pcmpeqd tmp4, tmp4;
212
	MMXMOVE ctxa, storea
213
	MMXMOVE ctxb, storeb
214
	MMXMOVE ctxc, storec
215
	MMXMOVE ctxd, stored
216
217
	STEP(F, ctxa, ctxb, ctxc, ctxd, 0, const_stage_1, 7)
218
	STEP(F, ctxd, ctxa, ctxb, ctxc, 1, const_stage_2, 12)
219
	STEP(F, ctxc, ctxd, ctxa, ctxb, 2, const_stage_3, 17)
220
	STEP(F, ctxb, ctxc, ctxd, ctxa, 3, const_stage_4, 22)
221
	STEP(F, ctxa, ctxb, ctxc, ctxd, 4, const_stage_5, 7)
222
	STEP(F, ctxd, ctxa, ctxb, ctxc, 5, const_stage_6, 12)
223
	STEP(F, ctxc, ctxd, ctxa, ctxb, 6, const_stage_7, 17)
224
	STEP(F, ctxb, ctxc, ctxd, ctxa, 7, const_stage_8, 22)
225
	STEP(F, ctxa, ctxb, ctxc, ctxd, 8, const_stage_9, 7)
226
	STEP(F, ctxd, ctxa, ctxb, ctxc, 9, const_stage_10, 12)
227
	STEP(F, ctxc, ctxd, ctxa, ctxb, 10, const_stage_11, 17)
228
	STEP(F, ctxb, ctxc, ctxd, ctxa, 11, const_stage_12, 22)
229
	STEP(F, ctxa, ctxb, ctxc, ctxd, 12, const_stage_13, 7)
230
	STEP(F, ctxd, ctxa, ctxb, ctxc, 13, const_stage_14, 12)
231
	STEP(F, ctxc, ctxd, ctxa, ctxb, 14, const_stage_15, 17)
232
	STEP(F, ctxb, ctxc, ctxd, ctxa, 15, const_stage_16, 22)
233
234
	STEP(G, ctxa, ctxb, ctxc, ctxd, 1, const_stage_17, 5)
235
	STEP(G, ctxd, ctxa, ctxb, ctxc, 6, const_stage_18, 9)
236
	STEP(G, ctxc, ctxd, ctxa, ctxb, 11, const_stage_19, 14)
237
	STEP(G, ctxb, ctxc, ctxd, ctxa, 0, const_stage_20, 20)
238
	STEP(G, ctxa, ctxb, ctxc, ctxd, 5, const_stage_21, 5)
239
	STEP(G, ctxd, ctxa, ctxb, ctxc, 10, const_stage_22, 9)
240
	STEP(G, ctxc, ctxd, ctxa, ctxb, 15, const_stage_23, 14)
241
	STEP(G, ctxb, ctxc, ctxd, ctxa, 4, const_stage_24, 20)
242
	STEP(G, ctxa, ctxb, ctxc, ctxd, 9, const_stage_25, 5)
243
	STEP(G, ctxd, ctxa, ctxb, ctxc, 14, const_stage_26, 9)
244
	STEP(G, ctxc, ctxd, ctxa, ctxb, 3, const_stage_27, 14)
245
	STEP(G, ctxb, ctxc, ctxd, ctxa, 8, const_stage_28, 20)
246
	STEP(G, ctxa, ctxb, ctxc, ctxd, 13, const_stage_29, 5)
247
	STEP(G, ctxd, ctxa, ctxb, ctxc, 2, const_stage_30, 9)
248
	STEP(G, ctxc, ctxd, ctxa, ctxb, 7, const_stage_31, 14)
249
	STEP(G, ctxb, ctxc, ctxd, ctxa, 12, const_stage_32, 20)
250
251
	STEP(H, ctxa, ctxb, ctxc, ctxd, 5, const_stage_33, 4)
252
	STEP(H, ctxd, ctxa, ctxb, ctxc, 8, const_stage_34, 11)
253
	STEP(H, ctxc, ctxd, ctxa, ctxb, 11, const_stage_35, 16)
254
	STEP(H, ctxb, ctxc, ctxd, ctxa, 14, const_stage_36, 23)
255
	STEP(H, ctxa, ctxb, ctxc, ctxd, 1, const_stage_37, 4)
256
	STEP(H, ctxd, ctxa, ctxb, ctxc, 4, const_stage_38, 11)
257
	STEP(H, ctxc, ctxd, ctxa, ctxb, 7, const_stage_39, 16)
258
	STEP(H, ctxb, ctxc, ctxd, ctxa, 10, const_stage_40, 23)
259
	STEP(H, ctxa, ctxb, ctxc, ctxd, 13, const_stage_41, 4)
260
	STEP(H, ctxd, ctxa, ctxb, ctxc, 0, const_stage_42, 11)
261
	STEP(H, ctxc, ctxd, ctxa, ctxb, 3, const_stage_43, 16)
262
	STEP(H, ctxb, ctxc, ctxd, ctxa, 6, const_stage_44, 23)
263
	STEP(H, ctxa, ctxb, ctxc, ctxd, 9, const_stage_45, 4)
264
	STEP(H, ctxd, ctxa, ctxb, ctxc, 12, const_stage_46, 11)
265
	STEP(H, ctxc, ctxd, ctxa, ctxb, 15, const_stage_47, 16)
266
	STEP(H, ctxb, ctxc, ctxd, ctxa, 2, const_stage_48, 23)
267
268
	STEP(I, ctxa, ctxb, ctxc, ctxd, 0, const_stage_49, 6)
269
	STEP(I, ctxd, ctxa, ctxb, ctxc, 7, const_stage_50, 10)
270
	STEP(I, ctxc, ctxd, ctxa, ctxb, 14, const_stage_51, 15)
271
	STEP(I, ctxb, ctxc, ctxd, ctxa, 5, const_stage_52, 21)
272
	STEP(I, ctxa, ctxb, ctxc, ctxd, 12, const_stage_53, 6)
273
	STEP(I, ctxd, ctxa, ctxb, ctxc, 3, const_stage_54, 10)
274
	STEP(I, ctxc, ctxd, ctxa, ctxb, 10, const_stage_55, 15)
275
	STEP(I, ctxb, ctxc, ctxd, ctxa, 1, const_stage_56, 21)
276
	STEP(I, ctxa, ctxb, ctxc, ctxd, 8, const_stage_57, 6)
277
	STEP(I, ctxd, ctxa, ctxb, ctxc, 15, const_stage_58, 10)
278
	STEP(I, ctxc, ctxd, ctxa, ctxb, 6, const_stage_59, 15)
279
	STEP(I, ctxb, ctxc, ctxd, ctxa, 13, const_stage_60, 21)
280
	STEP(I, ctxa, ctxb, ctxc, ctxd, 4, const_stage_61, 6)
281
	STEP(I, ctxd, ctxa, ctxb, ctxc, 11, const_stage_62, 10)
282
	STEP(I, ctxc, ctxd, ctxa, ctxb, 2, const_stage_63, 15)
283
	STEP(I, ctxb, ctxc, ctxd, ctxa, 9, const_stage_64, 21)
284
285
	paddd storea, ctxa
286
	paddd storeb, ctxb
287
	paddd storec, ctxc
288
	paddd stored, ctxd
289
290
	MMXMOVE ctxa, 0(%eax)
291
	MMXMOVE ctxa, storea
292
	MMXMOVE ctxb, (4*MMX_COEF)(%eax)
293
	MMXMOVE ctxb, storeb
294
	MMXMOVE ctxc, (8*MMX_COEF)(%eax)
295
	MMXMOVE ctxc, storec
296
	MMXMOVE ctxd, (12*MMX_COEF)(%eax)
297
	MMXMOVE ctxd, stored
298
299
	popa
300
301
	emms
302
	
303
	ret
304
305
#ifdef __ELF__
306
.section .note.GNU-stack,"",@progbits
307
#endif
(-)john-1.7.0.1/src/md5.c (+274 lines)
Line 0 Link Here
1
/*
2
 * This is an OpenSSL-compatible implementation of the RSA Data Security,
3
 * Inc. MD5 Message-Digest Algorithm.
4
 *
5
 * Written by Solar Designer <solar@openwall.com> in 2001, and placed in
6
 * the public domain.  There's absolutely no warranty.
7
 *
8
 * This differs from Colin Plumb's older public domain implementation in
9
 * that no 32-bit integer data type is required, there's no compile-time
10
 * endianness configuration, and the function prototypes match OpenSSL's.
11
 * The primary goals are portability and ease of use.
12
 *
13
 * This implementation is meant to be fast, but not as fast as possible.
14
 * Some known optimizations are not included to reduce source code size
15
 * and avoid compile-time configuration.
16
 */
17
18
#ifndef HAVE_OPENSSL
19
20
#include <string.h>
21
22
#include "md5.h"
23
24
/*
25
 * The basic MD5 functions.
26
 *
27
 * F is optimized compared to its RFC 1321 definition just like in Colin
28
 * Plumb's implementation.
29
 */
30
#define F(x, y, z)			((z) ^ ((x) & ((y) ^ (z))))
31
#define G(x, y, z)			((y) ^ ((z) & ((x) ^ (y))))
32
#define H(x, y, z)			((x) ^ (y) ^ (z))
33
#define I(x, y, z)			((y) ^ ((x) | ~(z)))
34
35
/*
36
 * The MD5 transformation for all four rounds.
37
 */
38
#define STEP(f, a, b, c, d, x, t, s) \
39
	(a) += f((b), (c), (d)) + (x) + (t); \
40
	(a) = (((a) << (s)) | (((a) & 0xffffffff) >> (32 - (s)))); \
41
	(a) += (b);
42
43
/*
44
 * SET reads 4 input bytes in little-endian byte order and stores them
45
 * in a properly aligned word in host byte order.
46
 *
47
 * The check for little-endian architectures which tolerate unaligned
48
 * memory accesses is just an optimization.  Nothing will break if it
49
 * doesn't work.
50
 */
51
#if defined(__i386__) || defined(__vax__)
52
#define SET(n) \
53
	(*(MD5_u32plus *)&ptr[(n) * 4])
54
#define GET(n) \
55
	SET(n)
56
#else
57
#define SET(n) \
58
	(ctx->block[(n)] = \
59
	(MD5_u32plus)ptr[(n) * 4] | \
60
	((MD5_u32plus)ptr[(n) * 4 + 1] << 8) | \
61
	((MD5_u32plus)ptr[(n) * 4 + 2] << 16) | \
62
	((MD5_u32plus)ptr[(n) * 4 + 3] << 24))
63
#define GET(n) \
64
	(ctx->block[(n)])
65
#endif
66
67
/*
68
 * This processes one or more 64-byte data blocks, but does NOT update
69
 * the bit counters.  There're no alignment requirements.
70
 */
71
static void *body(MD5_CTX *ctx, void *data, unsigned long size)
72
{
73
	unsigned char *ptr;
74
	MD5_u32plus a, b, c, d;
75
	MD5_u32plus saved_a, saved_b, saved_c, saved_d;
76
77
	ptr = data;
78
79
	a = ctx->a;
80
	b = ctx->b;
81
	c = ctx->c;
82
	d = ctx->d;
83
84
	do {
85
		saved_a = a;
86
		saved_b = b;
87
		saved_c = c;
88
		saved_d = d;
89
90
/* Round 1 */
91
		STEP(F, a, b, c, d, SET(0), 0xd76aa478, 7)
92
		STEP(F, d, a, b, c, SET(1), 0xe8c7b756, 12)
93
		STEP(F, c, d, a, b, SET(2), 0x242070db, 17)
94
		STEP(F, b, c, d, a, SET(3), 0xc1bdceee, 22)
95
		STEP(F, a, b, c, d, SET(4), 0xf57c0faf, 7)
96
		STEP(F, d, a, b, c, SET(5), 0x4787c62a, 12)
97
		STEP(F, c, d, a, b, SET(6), 0xa8304613, 17)
98
		STEP(F, b, c, d, a, SET(7), 0xfd469501, 22)
99
		STEP(F, a, b, c, d, SET(8), 0x698098d8, 7)
100
		STEP(F, d, a, b, c, SET(9), 0x8b44f7af, 12)
101
		STEP(F, c, d, a, b, SET(10), 0xffff5bb1, 17)
102
		STEP(F, b, c, d, a, SET(11), 0x895cd7be, 22)
103
		STEP(F, a, b, c, d, SET(12), 0x6b901122, 7)
104
		STEP(F, d, a, b, c, SET(13), 0xfd987193, 12)
105
		STEP(F, c, d, a, b, SET(14), 0xa679438e, 17)
106
		STEP(F, b, c, d, a, SET(15), 0x49b40821, 22)
107
108
/* Round 2 */
109
		STEP(G, a, b, c, d, GET(1), 0xf61e2562, 5)
110
		STEP(G, d, a, b, c, GET(6), 0xc040b340, 9)
111
		STEP(G, c, d, a, b, GET(11), 0x265e5a51, 14)
112
		STEP(G, b, c, d, a, GET(0), 0xe9b6c7aa, 20)
113
		STEP(G, a, b, c, d, GET(5), 0xd62f105d, 5)
114
		STEP(G, d, a, b, c, GET(10), 0x02441453, 9)
115
		STEP(G, c, d, a, b, GET(15), 0xd8a1e681, 14)
116
		STEP(G, b, c, d, a, GET(4), 0xe7d3fbc8, 20)
117
		STEP(G, a, b, c, d, GET(9), 0x21e1cde6, 5)
118
		STEP(G, d, a, b, c, GET(14), 0xc33707d6, 9)
119
		STEP(G, c, d, a, b, GET(3), 0xf4d50d87, 14)
120
		STEP(G, b, c, d, a, GET(8), 0x455a14ed, 20)
121
		STEP(G, a, b, c, d, GET(13), 0xa9e3e905, 5)
122
		STEP(G, d, a, b, c, GET(2), 0xfcefa3f8, 9)
123
		STEP(G, c, d, a, b, GET(7), 0x676f02d9, 14)
124
		STEP(G, b, c, d, a, GET(12), 0x8d2a4c8a, 20)
125
126
/* Round 3 */
127
		STEP(H, a, b, c, d, GET(5), 0xfffa3942, 4)
128
		STEP(H, d, a, b, c, GET(8), 0x8771f681, 11)
129
		STEP(H, c, d, a, b, GET(11), 0x6d9d6122, 16)
130
		STEP(H, b, c, d, a, GET(14), 0xfde5380c, 23)
131
		STEP(H, a, b, c, d, GET(1), 0xa4beea44, 4)
132
		STEP(H, d, a, b, c, GET(4), 0x4bdecfa9, 11)
133
		STEP(H, c, d, a, b, GET(7), 0xf6bb4b60, 16)
134
		STEP(H, b, c, d, a, GET(10), 0xbebfbc70, 23)
135
		STEP(H, a, b, c, d, GET(13), 0x289b7ec6, 4)
136
		STEP(H, d, a, b, c, GET(0), 0xeaa127fa, 11)
137
		STEP(H, c, d, a, b, GET(3), 0xd4ef3085, 16)
138
		STEP(H, b, c, d, a, GET(6), 0x04881d05, 23)
139
		STEP(H, a, b, c, d, GET(9), 0xd9d4d039, 4)
140
		STEP(H, d, a, b, c, GET(12), 0xe6db99e5, 11)
141
		STEP(H, c, d, a, b, GET(15), 0x1fa27cf8, 16)
142
		STEP(H, b, c, d, a, GET(2), 0xc4ac5665, 23)
143
144
/* Round 4 */
145
		STEP(I, a, b, c, d, GET(0), 0xf4292244, 6)
146
		STEP(I, d, a, b, c, GET(7), 0x432aff97, 10)
147
		STEP(I, c, d, a, b, GET(14), 0xab9423a7, 15)
148
		STEP(I, b, c, d, a, GET(5), 0xfc93a039, 21)
149
		STEP(I, a, b, c, d, GET(12), 0x655b59c3, 6)
150
		STEP(I, d, a, b, c, GET(3), 0x8f0ccc92, 10)
151
		STEP(I, c, d, a, b, GET(10), 0xffeff47d, 15)
152
		STEP(I, b, c, d, a, GET(1), 0x85845dd1, 21)
153
		STEP(I, a, b, c, d, GET(8), 0x6fa87e4f, 6)
154
		STEP(I, d, a, b, c, GET(15), 0xfe2ce6e0, 10)
155
		STEP(I, c, d, a, b, GET(6), 0xa3014314, 15)
156
		STEP(I, b, c, d, a, GET(13), 0x4e0811a1, 21)
157
		STEP(I, a, b, c, d, GET(4), 0xf7537e82, 6)
158
		STEP(I, d, a, b, c, GET(11), 0xbd3af235, 10)
159
		STEP(I, c, d, a, b, GET(2), 0x2ad7d2bb, 15)
160
		STEP(I, b, c, d, a, GET(9), 0xeb86d391, 21)
161
162
		a += saved_a;
163
		b += saved_b;
164
		c += saved_c;
165
		d += saved_d;
166
167
		ptr += 64;
168
	} while (size -= 64);
169
170
	ctx->a = a;
171
	ctx->b = b;
172
	ctx->c = c;
173
	ctx->d = d;
174
175
	return ptr;
176
}
177
178
void MD5_Init(MD5_CTX *ctx)
179
{
180
	ctx->a = 0x67452301;
181
	ctx->b = 0xefcdab89;
182
	ctx->c = 0x98badcfe;
183
	ctx->d = 0x10325476;
184
185
	ctx->lo = 0;
186
	ctx->hi = 0;
187
}
188
189
void MD5_Update(MD5_CTX *ctx, void *data, unsigned long size)
190
{
191
	MD5_u32plus saved_lo;
192
	unsigned long used, free;
193
194
	saved_lo = ctx->lo;
195
	if ((ctx->lo = (saved_lo + size) & 0x1fffffff) < saved_lo)
196
		ctx->hi++;
197
	ctx->hi += size >> 29;
198
199
	used = saved_lo & 0x3f;
200
201
	if (used) {
202
		free = 64 - used;
203
204
		if (size < free) {
205
			memcpy(&ctx->buffer[used], data, size);
206
			return;
207
		}
208
209
		memcpy(&ctx->buffer[used], data, free);
210
		data = (unsigned char *)data + free;
211
		size -= free;
212
		body(ctx, ctx->buffer, 64);
213
	}
214
215
	if (size >= 64) {
216
		data = body(ctx, data, size & ~(unsigned long)0x3f);
217
		size &= 0x3f;
218
	}
219
220
	memcpy(ctx->buffer, data, size);
221
}
222
223
void MD5_Final(unsigned char *result, MD5_CTX *ctx)
224
{
225
	unsigned long used, free;
226
227
	used = ctx->lo & 0x3f;
228
229
	ctx->buffer[used++] = 0x80;
230
231
	free = 64 - used;
232
233
	if (free < 8) {
234
		memset(&ctx->buffer[used], 0, free);
235
		body(ctx, ctx->buffer, 64);
236
		used = 0;
237
		free = 64;
238
	}
239
240
	memset(&ctx->buffer[used], 0, free - 8);
241
242
	ctx->lo <<= 3;
243
	ctx->buffer[56] = ctx->lo;
244
	ctx->buffer[57] = ctx->lo >> 8;
245
	ctx->buffer[58] = ctx->lo >> 16;
246
	ctx->buffer[59] = ctx->lo >> 24;
247
	ctx->buffer[60] = ctx->hi;
248
	ctx->buffer[61] = ctx->hi >> 8;
249
	ctx->buffer[62] = ctx->hi >> 16;
250
	ctx->buffer[63] = ctx->hi >> 24;
251
252
	body(ctx, ctx->buffer, 64);
253
254
	result[0] = ctx->a;
255
	result[1] = ctx->a >> 8;
256
	result[2] = ctx->a >> 16;
257
	result[3] = ctx->a >> 24;
258
	result[4] = ctx->b;
259
	result[5] = ctx->b >> 8;
260
	result[6] = ctx->b >> 16;
261
	result[7] = ctx->b >> 24;
262
	result[8] = ctx->c;
263
	result[9] = ctx->c >> 8;
264
	result[10] = ctx->c >> 16;
265
	result[11] = ctx->c >> 24;
266
	result[12] = ctx->d;
267
	result[13] = ctx->d >> 8;
268
	result[14] = ctx->d >> 16;
269
	result[15] = ctx->d >> 24;
270
271
	memset(ctx, 0, sizeof(*ctx));
272
}
273
274
#endif
(-)john-1.7.0.1/src/md5.h (+35 lines)
Line 0 Link Here
1
/*
2
 * This is an OpenSSL-compatible implementation of the RSA Data Security,
3
 * Inc. MD5 Message-Digest Algorithm.
4
 *
5
 * Written by Solar Designer <solar@openwall.com> in 2001, and placed in
6
 * the public domain.  See md5.c for more information.
7
 */
8
9
#ifdef HAVE_OPENSSL
10
#include <openssl/md5.h>
11
#elif !defined(_MD5_H)
12
#define _MD5_H
13
14
/* Any 32-bit or wider unsigned integer data type will do */
15
typedef unsigned long MD5_u32plus;
16
17
typedef struct {
18
	MD5_u32plus lo, hi;
19
	MD5_u32plus a, b, c, d;
20
	unsigned char buffer[64];
21
	MD5_u32plus block[16];
22
} MD5_CTX;
23
24
extern void MD5_Init(MD5_CTX *ctx);
25
extern void MD5_Update(MD5_CTX *ctx, void *data, unsigned long size);
26
extern void MD5_Final(unsigned char *result, MD5_CTX *ctx);
27
28
#ifdef MMX_COEF
29
extern int mdfivemmx(unsigned char *out, unsigned char *in, int n) __attribute__((regparm(3)));
30
extern int mdfivemmx_nosizeupdate(unsigned char *out, unsigned char *in, int n) __attribute__((regparm(3)));
31
extern int mdfivemmx_noinit_sizeupdate(unsigned char *out, unsigned char *in, int n) __attribute__((regparm(3)));
32
extern int mdfivemmx_noinit_uniformsizeupdate(unsigned char *out, unsigned char *in, int n) __attribute__((regparm(3)));
33
#endif
34
35
#endif
(-)john-1.7.0.1/src/memory.c (+26 lines)
Lines 70-72 Link Here
70
	size = strlen(src) + 1;
70
	size = strlen(src) + 1;
71
	return (char *)memcpy(mem_alloc_tiny(size, MEM_ALIGN_NONE), src, size);
71
	return (char *)memcpy(mem_alloc_tiny(size, MEM_ALIGN_NONE), src, size);
72
}
72
}
73
74
void dump_stuff(unsigned char * x, unsigned int size)
75
{
76
	while(size--)
77
	{
78
		printf("%.2x", *x);
79
		x++;
80
	}
81
	printf("\n");
82
}
83
84
#ifdef MMX_COEF
85
#define GETPOS(i, index)		( (index)*4 + (i& (0xffffffff-3) )*MMX_COEF + ((i)&3) )
86
87
void dump_stuff_mmx(unsigned char * buf, unsigned int size, unsigned int index)
88
{
89
	int i;
90
	for(i=0;i<size;i++)
91
	{
92
		if(!(i%4))
93
			printf(" ");
94
		printf("%.2x", buf[GETPOS(i, index)]);
95
	}
96
	printf("\n");
97
}
98
#endif
(-)john-1.7.0.1/src/memory.h (+5 lines)
Lines 73-76 Link Here
73
 */
73
 */
74
extern char *str_alloc_copy(char *src);
74
extern char *str_alloc_copy(char *src);
75
75
76
void dump_stuff(unsigned char * x, unsigned int size);
77
#ifdef MMX_COEF
78
void dump_stuff_mmx(unsigned char * x, unsigned int size, unsigned int index);
79
#endif
80
76
#endif
81
#endif
(-)john-1.7.0.1/src/mscash_fmt.c (+213 lines)
Line 0 Link Here
1
/*
2
 * Copyright (c) 2004 Simon Marechal
3
 * bartavelle@bandecon.com
4
 *
5
 * This is a plugin that adds Microsoft credential's cache hashing algorithm,
6
 * MS Cache Hash, a.k.a. MS Cash. This patch is invasive because john doesn't
7
 * support the use of the username easily within the current framework.
8
 * In order to get those hashes, use the CacheDump utility :
9
 *
10
 * http://www.cr0.net:8040/misc/cachedump.html
11
 *
12
 * It uses 
13
 * - smbencrypt.c Copyright (C) Andrew Tridgell 1997-1998
14
 * - md4.c, md4.h by Solar Designer
15
 *  
16
 */
17
18
#include <string.h>
19
20
#include "arch.h"
21
#include "misc.h"
22
#include "common.h"
23
#include "formats.h"
24
#include "md4.h"
25
26
#define FORMAT_LABEL			"mscash"
27
#define FORMAT_NAME			"M$ Cache Hash"
28
#define ALGORITHM_NAME			"mscash"
29
30
#define BENCHMARK_COMMENT		""
31
#define BENCHMARK_LENGTH		-1
32
33
#define PLAINTEXT_LENGTH		32
34
35
#define BINARY_SIZE			16
36
//max username size is 64, double for unicode "optimization"
37
#define SALT_SIZE			(64*2)
38
#define CIPHERTEXT_LENGTH		(BINARY_SIZE*2 + SALT_SIZE)
39
40
#define MIN_KEYS_PER_CRYPT		1
41
#define MAX_KEYS_PER_CRYPT		1
42
43
static struct fmt_tests mscash_tests[] = {
44
	{"M$test1#64cd29e36a8431a2b111378564a10631", "test1" },
45
	{"M$test2#ab60bdb4493822b175486810ac2abe63", "test2" },
46
	{"M$test3#14dd041848e12fc48c0aa7a416a4a00c", "test3" },
47
	{"M$test4#b945d24866af4b01a6d89b9d932a153c", "test4" },
48
	{NULL}
49
};
50
51
static char saved_key[PLAINTEXT_LENGTH + 1];
52
//stores the ciphertext for value currently being tested
53
static char crypt_key[BINARY_SIZE+1];
54
55
static int salt_length; //the length of the current username
56
static unsigned short cur_salt[SALT_SIZE/2]; //current salt
57
58
extern void E_md4hash(unsigned char *passwd, unsigned char *p16);
59
60
static int valid(char *ciphertext)
61
{
62
	int i;
63
	int l;
64
65
	/*
66
	 * 2 cases
67
	 * 1 - it comes from the disk, and does not have M$ + salt
68
	 * 2 - it comes from memory, and has got M$ + salt + # + blah
69
	 */
70
71
	if (!memcmp(ciphertext, "M$", 2))
72
	{
73
		l = strlen(ciphertext) - PLAINTEXT_LENGTH;
74
		if(ciphertext[l-1]!='#')
75
			return 0;
76
	}
77
	else
78
	{
79
		if(strlen(ciphertext)!=PLAINTEXT_LENGTH)
80
			return 0;
81
		l = 0;
82
	}
83
	for (i = l; i < l + PLAINTEXT_LENGTH; i++){
84
		if (!(  (('0' <= ciphertext[i])&&(ciphertext[i] <= '9')) ||
85
					(('a' <= ciphertext[i])&&(ciphertext[i] <= 'f'))  
86
					|| (('A' <= ciphertext[i])&&(ciphertext[i] <= 'F'))))
87
			return 0;
88
	}
89
	
90
	return 1;
91
}
92
93
//salt is unicode, so let's say it's unsigned short
94
static void mscash_set_salt(void *salt) {
95
	salt_length = 0;
96
	while( ((unsigned char *)salt)[salt_length]!='#' )
97
	{
98
#if ARCH_LITTLE_ENDIAN
99
		cur_salt[salt_length] = ((unsigned char *)salt)[salt_length];
100
#else
101
		cur_salt[salt_length] = ((unsigned char *)salt)[salt_length] << 8;
102
#endif
103
		salt_length ++;
104
	}
105
	cur_salt[salt_length] = 0;
106
}
107
108
static void mscash_set_key(char *key, int index) {
109
	strnzcpy(saved_key, key, PLAINTEXT_LENGTH+1);
110
}
111
112
static char *mscash_get_key(int index) {
113
    return saved_key;
114
}
115
116
static int mscash_cmp_all(void *binary, int index) { 
117
	int i=0;
118
	while(i<BINARY_SIZE)
119
	{
120
		if(((char *)binary)[i]!=((char *)crypt_key)[i])
121
			return 0;
122
		i++;
123
	}
124
	return 1;
125
}
126
127
static void mscash_crypt_all(int count) {  
128
	unsigned char buffer[BINARY_SIZE+SALT_SIZE];
129
	// get plaintext input in saved_key put it into ciphertext crypt_key
130
	
131
	//stage 1 : build nt hash of password
132
	E_md4hash(saved_key, buffer);
133
134
	//stage 2 : append cleartext to buffer
135
	memcpy(buffer+BINARY_SIZE, cur_salt, salt_length*2);
136
137
	//stage 3 : generate final hash and put it in crypt_key
138
	mdfour(crypt_key, buffer, BINARY_SIZE+salt_length*2);
139
}
140
141
static void * mscash_binary(char *ciphertext) 
142
{
143
	static unsigned char realcipher[BINARY_SIZE];
144
	int i;
145
	
146
	int l = strlen(ciphertext);
147
	for(i=0; i<BINARY_SIZE ;i++)
148
	{
149
		realcipher[i] = atoi16[ARCH_INDEX(ciphertext[i*2+l-BINARY_SIZE*2])]*16 + atoi16[ARCH_INDEX(ciphertext[i*2+l-BINARY_SIZE*2+1])];
150
	}
151
	return (void *)realcipher;
152
}
153
154
static void * mscash_get_salt(char * ciphertext)
155
{
156
	static unsigned char out[SALT_SIZE];
157
	int l;
158
159
	l = strlen(ciphertext);
160
	strncpy(out, ciphertext + 2, l - PLAINTEXT_LENGTH + 1);
161
	return out;
162
}
163
164
static int mscash_cmp_one(void *binary, int count){
165
	return (1);
166
}
167
168
static int mscash_cmp_exact(char *source, int count){
169
	return 1;
170
	//return (!memcmp(mscash_binary(source), crypt_key, BINARY_SIZE));
171
}
172
173
struct fmt_main fmt_mscash = {
174
	{
175
		FORMAT_LABEL,
176
		FORMAT_NAME,
177
		ALGORITHM_NAME,
178
		BENCHMARK_COMMENT,
179
		BENCHMARK_LENGTH,
180
		PLAINTEXT_LENGTH,
181
		BINARY_SIZE,
182
		SALT_SIZE,
183
		MIN_KEYS_PER_CRYPT,
184
		MAX_KEYS_PER_CRYPT,
185
		FMT_CASE | FMT_8_BIT,
186
		mscash_tests
187
	}, {
188
		fmt_default_init,
189
		valid,
190
		fmt_default_split,
191
		mscash_binary,
192
		mscash_get_salt,
193
		{
194
			fmt_default_binary_hash,
195
			fmt_default_binary_hash,
196
			fmt_default_binary_hash
197
		},
198
		fmt_default_salt_hash,
199
		mscash_set_salt,
200
		mscash_set_key,
201
		mscash_get_key,
202
		fmt_default_clear_keys,
203
		mscash_crypt_all,
204
		{
205
			fmt_default_get_hash,
206
			fmt_default_get_hash,
207
			fmt_default_get_hash
208
		},
209
		mscash_cmp_all,
210
		mscash_cmp_one,
211
		mscash_cmp_exact
212
	}
213
};
(-)john-1.7.0.1/src/mscash_mmx.c (+234 lines)
Line 0 Link Here
1
/*
2
 * Copyright (c) 2004 Simon Marechal
3
 * bartavelle@bandecon.com
4
 *
5
 * This is a plugin that adds Microsoft credential's cache hashing algorithm,
6
 * MS Cache Hash, a.k.a. MS Cash. This patch is invasive because john doesn't
7
 * support the use of the username easily within the current framework.
8
 * In order to get those hashes, use the CacheDump utility :
9
 *
10
 * http://www.cr0.net:8040/misc/cachedump.html
11
 *
12
 * It uses 
13
 * - smbencrypt.c Copyright (C) Andrew Tridgell 1997-1998
14
 * - md4.c, md4.h by Solar Designer
15
 *  
16
 */
17
18
#include <string.h>
19
20
#include "arch.h"
21
#include "misc.h"
22
#include "common.h"
23
#include "formats.h"
24
#include "md4.h"
25
26
#define FORMAT_LABEL			"mscashmmx"
27
#define FORMAT_NAME			"M$ Cache Hash MMX"
28
#define ALGORITHM_NAME			"mscash"
29
30
#define BENCHMARK_COMMENT		MMX_TYPE
31
#define BENCHMARK_LENGTH		-1
32
33
#define PLAINTEXT_LENGTH		32
34
35
#define BINARY_SIZE			16
36
//max username size is 64, double for unicode "optimization"
37
#define SALT_SIZE			(64*2*MMX_COEF)
38
#define CIPHERTEXT_LENGTH		(BINARY_SIZE*2 + SALT_SIZE)
39
40
#define MIN_KEYS_PER_CRYPT		MMX_COEF
41
#define MAX_KEYS_PER_CRYPT		MMX_COEF
42
43
#define GETPOS(i,idx)	( ((i)&0xfffe)*MMX_COEF + ((i)&1) + ((idx)<<1) )
44
45
static struct fmt_tests mscash_tests[] = {
46
	{"M$test1#64cd29e36a8431a2b111378564a10631", "test1" },
47
	{"M$test2#ab60bdb4493822b175486810ac2abe63", "test2" },
48
	{"M$test3#14dd041848e12fc48c0aa7a416a4a00c", "test3" },
49
	{"M$test4#b945d24866af4b01a6d89b9d932a153c", "test4" },
50
	{NULL}
51
};
52
53
static char saved_key[PLAINTEXT_LENGTH*MMX_COEF + 1];
54
//stores the ciphertext for value currently being tested
55
static char crypt_key[BINARY_SIZE*MMX_COEF+1];
56
57
static int salt_length; //the length of the current username
58
static int total_len;
59
static unsigned short cur_salt[MMX_COEF*SALT_SIZE/2]; //current salt
60
61
//extern void E_md4hash(unsigned char *passwd, unsigned char *p16);
62
63
static int valid(char *ciphertext)
64
{
65
	int i;
66
	int l;
67
68
	/*
69
	 * 2 cases
70
	 * 1 - it comes from the disk, and does not have M$ + salt
71
	 * 2 - it comes from memory, and has got M$ + salt + # + blah
72
	 */
73
74
	if (!memcmp(ciphertext, "M$", 2))
75
	{
76
		l = strlen(ciphertext) - PLAINTEXT_LENGTH;
77
		if(ciphertext[l-1]!='#')
78
			return 0;
79
	}
80
	else
81
	{
82
		if(strlen(ciphertext)!=PLAINTEXT_LENGTH)
83
			return 0;
84
		l = 0;
85
	}
86
	for (i = l; i < l + PLAINTEXT_LENGTH; i++){
87
		if (!(  (('0' <= ciphertext[i])&&(ciphertext[i] <= '9')) ||
88
					(('a' <= ciphertext[i])&&(ciphertext[i] <= 'f'))  
89
					|| (('A' <= ciphertext[i])&&(ciphertext[i] <= 'F'))))
90
			return 0;
91
	}
92
	
93
	return 1;
94
}
95
96
//salt is unicode, so let's say it's unsigned short
97
static void mscash_set_salt(void *salt) {
98
	unsigned int curlen;
99
	salt_length = 0;
100
	while( ((unsigned char *)salt)[salt_length]!='#' )
101
	{
102
#if ARCH_LITTLE_ENDIAN
103
		cur_salt[salt_length] = ((unsigned char *)salt)[salt_length];
104
#else
105
		cur_salt[salt_length] = ((unsigned char *)salt)[salt_length] << 8;
106
#endif
107
		salt_length ++;
108
	}
109
	cur_salt[salt_length] = 0;
110
	salt_length = curlen;
111
}
112
113
static void mscash_set_key(char *key, int index) {
114
	int len;
115
	int i;
116
117
	if(index==0)
118
	{
119
		total_len = 0;
120
		memset(saved_key, 0, 64*MMX_COEF);
121
	}
122
	len = strlen(key);
123
	if(len > 32)
124
                len = 32;
125
126
	total_len += len << (1 + ( (32/MMX_COEF) * index ) );
127
128
	for(i=0;i<len;i++)
129
		((unsigned short *)saved_key)[ GETPOS(i, index) ] = key[i] ;
130
	((unsigned short *)saved_key)[ GETPOS(i, index) ] = 0x80;
131
}
132
133
static char *mscash_get_key(int index) {
134
    return saved_key;
135
}
136
137
static int mscash_cmp_all(void *binary, int index) { 
138
	int i=0;
139
	while(i<BINARY_SIZE)
140
	{
141
		if(((char *)binary)[i]!=((char *)crypt_key)[i])
142
			return 0;
143
		i++;
144
	}
145
	return 1;
146
}
147
148
static void mscash_crypt_all(int count) {  
149
	unsigned char buffer[BINARY_SIZE+SALT_SIZE];
150
	// get plaintext input in saved_key put it into ciphertext crypt_key
151
	
152
	//stage 1 : build nt hash of password
153
	//E_md4hash(saved_key, buffer);
154
155
	//stage 2 : append cleartext to buffer
156
	//memcpy(buffer+BINARY_SIZE, cur_salt, salt_length*2);
157
158
	//stage 3 : generate final hash and put it in crypt_key
159
	//mdfour(crypt_key, buffer, BINARY_SIZE+salt_length*2);
160
}
161
162
static void * mscash_binary(char *ciphertext) 
163
{
164
	static unsigned char realcipher[BINARY_SIZE];
165
	int i;
166
	
167
	int l = strlen(ciphertext);
168
	for(i=0; i<BINARY_SIZE ;i++)
169
	{
170
		realcipher[i] = atoi16[ARCH_INDEX(ciphertext[i*2+l-BINARY_SIZE*2])]*16 + atoi16[ARCH_INDEX(ciphertext[i*2+l-BINARY_SIZE*2+1])];
171
	}
172
	return (void *)realcipher;
173
}
174
175
static void * mscash_get_salt(char * ciphertext)
176
{
177
	static unsigned char out[SALT_SIZE];
178
	int l;
179
180
	l = strlen(ciphertext);
181
	strncpy(out, ciphertext + 2, l - PLAINTEXT_LENGTH + 1);
182
	return out;
183
}
184
185
static int mscash_cmp_one(void *binary, int count){
186
	return (1);
187
}
188
189
static int mscash_cmp_exact(char *source, int count){
190
	return 1;
191
	//return (!memcmp(mscash_binary(source), crypt_key, BINARY_SIZE));
192
}
193
194
struct fmt_main fmt_mscash_mmx = {
195
	{
196
		FORMAT_LABEL,
197
		FORMAT_NAME,
198
		ALGORITHM_NAME,
199
		BENCHMARK_COMMENT,
200
		BENCHMARK_LENGTH,
201
		PLAINTEXT_LENGTH,
202
		BINARY_SIZE,
203
		SALT_SIZE,
204
		MIN_KEYS_PER_CRYPT,
205
		MAX_KEYS_PER_CRYPT,
206
		FMT_CASE | FMT_8_BIT,
207
		mscash_tests
208
	}, {
209
		fmt_default_init,
210
		valid,
211
		fmt_default_split,
212
		mscash_binary,
213
		mscash_get_salt,
214
		{
215
			fmt_default_binary_hash,
216
			fmt_default_binary_hash,
217
			fmt_default_binary_hash
218
		},
219
		fmt_default_salt_hash,
220
		mscash_set_salt,
221
		mscash_set_key,
222
		mscash_get_key,
223
		fmt_default_clear_keys,
224
		mscash_crypt_all,
225
		{
226
			fmt_default_get_hash,
227
			fmt_default_get_hash,
228
			fmt_default_get_hash
229
		},
230
		mscash_cmp_all,
231
		mscash_cmp_one,
232
		mscash_cmp_exact
233
	}
234
};
(-)john-1.7.0.1/src/mssql_fmt.c (+326 lines)
Line 0 Link Here
1
/*
2
 * Copyright (c) 2004 bartavelle
3
 * bartavelle@bandecon.com
4
 *
5
 * microsoft MS SQL cracker
6
 * 
7
 */
8
9
#include <string.h>
10
11
#include "arch.h"
12
#include "misc.h"
13
#include "common.h"
14
#include "formats.h"
15
#include "sha.h"
16
17
//remove this line at your own risks!
18
//seems to work sometimes ...
19
#undef MMX_COEF
20
21
#define FORMAT_LABEL			"mssql"
22
#define FORMAT_NAME			"MS-SQL"
23
#ifdef MMX_COEF
24
#if (MMX_COEF == 2)
25
#define ALGORITHM_NAME			"ms-sql MMX"
26
#else
27
#define ALGORITHM_NAME			"ms-sql SSE2"
28
#endif
29
#else
30
#define ALGORITHM_NAME			"ms-sql"
31
#endif
32
33
#ifdef MMX_TYPE
34
#define BENCHMARK_COMMENT		MMX_TYPE
35
#else
36
#define BENCHMARK_COMMENT		""
37
#endif
38
#define BENCHMARK_LENGTH		-1
39
40
#define PLAINTEXT_LENGTH		20
41
#define CIPHERTEXT_LENGTH		94
42
43
#define BINARY_SIZE			20
44
#define SALT_SIZE			4
45
46
#ifdef MMX_COEF
47
#define MIN_KEYS_PER_CRYPT		MMX_COEF
48
#define MAX_KEYS_PER_CRYPT		MMX_COEF
49
//#define GETPOS(i, index)		( (index)*4 + (i& (0xffffffff-3) )*MMX_COEF + ((i)&3) ) //std getpos
50
#define GETPOS(i, index)		( (index)*4 + (i& (0xffffffff-3) )*MMX_COEF + (3-((i)&3)) ) //for endianity conversion
51
#else
52
#define MIN_KEYS_PER_CRYPT		1
53
#define MAX_KEYS_PER_CRYPT		1
54
#endif
55
56
//microsoft unicode ...
57
#if ARCH_BIG_ENDIAN
58
#define ENDIAN_SHIFT_L  << 8
59
#define ENDIAN_SHIFT_R  >> 8
60
#else
61
#define ENDIAN_SHIFT_L
62
#define ENDIAN_SHIFT_R
63
#endif
64
65
static struct fmt_tests mssql_tests[] = {
66
	{"0x0100A607BA7C54A24D17B565C59F1743776A10250F581D482DA8B6D6261460D3F53B279CC6913CE747006A2E3254", "FOO"},
67
	{"0x01000508513EADDF6DB7DDD270CCA288BF097F2FF69CC2DB74FBB9644D6901764F999BAB9ECB80DE578D92E3F80D", "BAR"},
68
	{"0x01008408C523CF06DCB237835D701C165E68F9460580132E28ED8BC558D22CEDF8801F4503468A80F9C52A12C0A3", "CANARD"},
69
	{"0x0100BF088517935FC9183FE39FDEC77539FD5CB52BA5F5761881E5B9638641A79DBF0F1501647EC941F3355440A2", "LAPIN"},
70
	{NULL}
71
};
72
73
static unsigned char cursalt[SALT_SIZE];
74
75
#ifdef MMX_COEF
76
static char saved_key[64*MMX_COEF*2 + 1] __attribute__ ((aligned(16)));
77
static char crypt_key[80*4*MMX_COEF+1] __attribute__ ((aligned(16))); //wtf
78
unsigned long total_len;
79
unsigned char out[PLAINTEXT_LENGTH];
80
#else
81
static unsigned char saved_key[PLAINTEXT_LENGTH*2 + 1];
82
static unsigned char crypt_key[BINARY_SIZE+1];
83
static SHA_CTX ctx;
84
unsigned int key_length;
85
#endif
86
87
static int valid(char *ciphertext)
88
{
89
	int i;
90
91
	if (strlen(ciphertext) != CIPHERTEXT_LENGTH) return 0;
92
	if(memcmp(ciphertext, "0x0100", 6))
93
		return 0;
94
	for (i = 6; i < CIPHERTEXT_LENGTH; i++){
95
		if (!(  (('0' <= ciphertext[i])&&(ciphertext[i] <= '9')) ||
96
					(('a' <= ciphertext[i])&&(ciphertext[i] <= 'f'))  
97
					|| (('A' <= ciphertext[i])&&(ciphertext[i] <= 'F'))))
98
			return 0;
99
	}
100
	return 1;
101
}
102
103
static void mssql_set_salt(void *salt)
104
{
105
	memcpy(cursalt, salt, SALT_SIZE);
106
}
107
108
static void * mssql_get_salt(char * ciphertext)
109
{
110
	static unsigned char out2[SALT_SIZE];
111
	int l;
112
113
	for(l=0;l<SALT_SIZE;l++)
114
	{
115
		out2[l] = atoi16[ARCH_INDEX(ciphertext[l*2+6])]*16 
116
			+ atoi16[ARCH_INDEX(ciphertext[l*2+7])];
117
	}
118
119
	return out2;
120
}
121
122
static inline unsigned char upper(unsigned char c)
123
{
124
	if( (c>='a') && (c<='z'))
125
		return c+'A'-'a';
126
	return c;
127
}
128
129
static void mssql_init(void)
130
{
131
#ifdef MMX_COEF
132
	memset(saved_key, 0, 64*MMX_COEF);
133
#endif
134
}
135
136
static void mssql_set_key(char *key, int index) {
137
#ifdef MMX_COEF
138
	int len;
139
	int i;
140
	
141
	if(index==0)
142
	{
143
		total_len = 0;
144
		memset(saved_key, 0, 64*MMX_COEF);
145
	}
146
	len = strlen(key);
147
	if(len>PLAINTEXT_LENGTH)
148
		len = PLAINTEXT_LENGTH;
149
150
	total_len += (len*2+SALT_SIZE ) << ( ( (32/MMX_COEF) * index ) );
151
	for(i=0;i<len;i++)
152
	{
153
		saved_key[GETPOS((i*2), index)] = upper(key[i]);
154
		saved_key[GETPOS((i*2+1), index)] = 0;
155
	}
156
	for(i=0;i<4;i++)
157
		saved_key[GETPOS( (len*2+i), index)] = cursalt[i];
158
	saved_key[GETPOS( (len*2+SALT_SIZE) , index)] = 0x80;
159
#else
160
	key_length = 0;
161
	while( (((unsigned short *)saved_key)[key_length] = upper(key[key_length]) ENDIAN_SHIFT_L ))
162
		key_length++;
163
#endif
164
}
165
166
static char *mssql_get_key(int index) {
167
#ifdef MMX_COEF
168
	unsigned int i,s;
169
	
170
	s = (total_len >> (((32/MMX_COEF)*(index)))) & 0xff;
171
	s = (s-4)/2;
172
	for(i=0;i<s;i++)
173
		out[i] = saved_key[ GETPOS(i*2, index) ];
174
	out[i] = 0;
175
	return out;
176
#else
177
	static unsigned char retkey[PLAINTEXT_LENGTH];
178
	int i;
179
	
180
	memset(retkey, 0, PLAINTEXT_LENGTH);
181
	for(i=0;i<key_length;i++)
182
		retkey[i] = ((unsigned short *)saved_key)[i];
183
	return retkey;
184
#endif
185
}
186
187
static int mssql_cmp_all(void *binary, int index) { 
188
	int i=0;
189
#ifdef MMX_COEF
190
	while(i< (BINARY_SIZE/4) )
191
	{
192
		if (
193
			( ((unsigned long *)binary)[i] != ((unsigned long *)crypt_key)[i*MMX_COEF])
194
			&& ( ((unsigned long *)binary)[i] != ((unsigned long *)crypt_key)[i*MMX_COEF+1])
195
#if (MMX_COEF > 3)
196
			&& ( ((unsigned long *)binary)[i] != ((unsigned long *)crypt_key)[i*MMX_COEF+2])
197
			&& ( ((unsigned long *)binary)[i] != ((unsigned long *)crypt_key)[i*MMX_COEF+3])
198
#endif
199
		)
200
			return 0;
201
		i++;
202
	}
203
#else
204
	while(i<BINARY_SIZE)
205
	{
206
		if(((char *)binary)[i]!=((char *)crypt_key)[i])
207
			return 0;
208
		i++;
209
	}
210
#endif
211
	return 1;
212
}
213
214
static int mssql_cmp_exact(char *source, int count){
215
  return (1);
216
}
217
218
static int mssql_cmp_one(void * binary, int index)
219
{
220
#ifdef MMX_COEF
221
	int i = 0;
222
	for(i=0;i<(BINARY_SIZE/4);i++)
223
		if ( ((unsigned long *)binary)[i] != ((unsigned long *)crypt_key)[i*MMX_COEF+index] )
224
			return 0;
225
	return 1;
226
#else
227
	return mssql_cmp_all(binary, index);
228
#endif
229
}
230
231
static void mssql_crypt_all(int count) {
232
  // get plaintext input in saved_key put it into ciphertext crypt_key
233
#ifdef MMX_COEF
234
	shammx(crypt_key, saved_key, total_len);
235
#else
236
	memcpy(saved_key+key_length*2, cursalt, SALT_SIZE);
237
	SHA1_Init( &ctx );
238
	SHA1_Update( &ctx, saved_key, key_length*2+SALT_SIZE );
239
	SHA1_Final( crypt_key, &ctx);
240
#endif
241
  
242
}
243
244
static void * mssql_binary(char *ciphertext) 
245
{
246
	static char realcipher[BINARY_SIZE];
247
	int i;
248
	
249
	for(i=0;i<BINARY_SIZE;i++)
250
	{
251
		realcipher[i] = atoi16[ARCH_INDEX(ciphertext[i*2+54])]*16 + atoi16[ARCH_INDEX(ciphertext[i*2+55])];
252
	}
253
	return (void *)realcipher;
254
}
255
256
static int binary_hash_0(void *binary)
257
{
258
  return ((unsigned int *)binary)[0] & 0xF;
259
}
260
261
static int binary_hash_1(void *binary)
262
{
263
  return ((unsigned int *)binary)[0] & 0xFF;
264
}
265
266
static int binary_hash_2(void *binary)
267
{
268
  return ((unsigned int *)binary)[0] & 0xFFF;
269
}
270
271
static int get_hash_0(int index)
272
{
273
  return ((unsigned long *)crypt_key)[index] & 0xF;
274
}
275
276
static int get_hash_1(int index)
277
{
278
  return ((unsigned long *)crypt_key)[index] & 0xFF;
279
}
280
281
static int get_hash_2(int index)
282
{
283
  return ((unsigned long *)crypt_key)[index] & 0xFFF;
284
}
285
286
struct fmt_main fmt_mssql = {
287
	{
288
		FORMAT_LABEL,
289
		FORMAT_NAME,
290
		ALGORITHM_NAME,
291
		BENCHMARK_COMMENT,
292
		BENCHMARK_LENGTH,
293
		PLAINTEXT_LENGTH,
294
		BINARY_SIZE,
295
		SALT_SIZE,
296
		MIN_KEYS_PER_CRYPT,
297
		MAX_KEYS_PER_CRYPT,
298
		FMT_8_BIT,
299
		mssql_tests
300
	}, {
301
		mssql_init,
302
		valid,
303
		fmt_default_split,
304
		mssql_binary,
305
		mssql_get_salt,
306
		{
307
			binary_hash_0,
308
			binary_hash_1,
309
			binary_hash_2
310
		},
311
		fmt_default_salt_hash,
312
		mssql_set_salt,
313
		mssql_set_key,
314
		mssql_get_key,
315
		fmt_default_clear_keys,
316
		mssql_crypt_all,
317
		{
318
			get_hash_0,
319
			get_hash_1,
320
			get_hash_2
321
		},
322
		mssql_cmp_all,
323
		mssql_cmp_one,
324
		mssql_cmp_exact
325
	}
326
};
(-)john-1.7.0.1/src/options.c (+4 lines)
Lines 102-107 Link Here
102
	"only\n" \
102
	"only\n" \
103
"--format=NAME              force ciphertext format NAME: " \
103
"--format=NAME              force ciphertext format NAME: " \
104
	"DES/BSDI/MD5/BF/AFS/LM\n" \
104
	"DES/BSDI/MD5/BF/AFS/LM\n" \
105
"                           raw-md5/MYSQL/NT/lotus5/mscash/md5a/nsldap\n" \
106
"                           bfegg/mssql/\n" \
107
"                           NTmmx (will not work for passwords more\n" \
108
"                           than 32 characters, use NT instead)\n" \
105
"--save-memory=LEVEL        enable memory saving, at LEVEL 1..3\n"
109
"--save-memory=LEVEL        enable memory saving, at LEVEL 1..3\n"
106
110
107
void opt_init(char *name, int argc, char **argv)
111
void opt_init(char *name, int argc, char **argv)
(-)john-1.7.0.1/src/oracle_fmt.c (+248 lines)
Line 0 Link Here
1
/*
2
 * Copyright (c) 2004 Simon Marechal
3
 * simon.marechal@thales-security.com
4
 */
5
6
#include <string.h>
7
8
#include "arch.h"
9
#include "misc.h"
10
#include "common.h"
11
#include "formats.h"
12
#include "des.h"
13
14
#define FORMAT_LABEL			"oracle"
15
#define FORMAT_NAME			"Oracle"
16
#define ALGORITHM_NAME			"oracle"
17
18
#define BENCHMARK_COMMENT		""
19
#define BENCHMARK_LENGTH		-1
20
21
#define PLAINTEXT_LENGTH		16
22
23
#define BINARY_SIZE			8
24
#define SALT_SIZE			32
25
#define CIPHERTEXT_LENGTH		(BINARY_SIZE + SALT_SIZE)
26
27
#define MIN_KEYS_PER_CRYPT		1
28
#define MAX_KEYS_PER_CRYPT		1
29
30
static struct fmt_tests oracle_tests[] = {
31
	{"O$SIMON#4F8BC1809CB2AF77", "A"},
32
	{"O$SIMON#183D72325548EF11", "THALES2" },
33
	{"O$SIMON#C4EB3152E17F24A4", "TST" },
34
	{"O$SYSTEM#9EEDFA0AD26C6D52", "THALES" },
35
	{NULL}
36
};
37
38
#if ARCH_LITTLE_ENDIAN
39
#define ENDIAN_SHIFT_L  << 8
40
#define ENDIAN_SHIFT_R  >> 8
41
#else
42
#define ENDIAN_SHIFT_L
43
#define ENDIAN_SHIFT_R
44
#endif
45
46
//stores the ciphertext for value currently being tested
47
static char crypt_key[BINARY_SIZE+1];
48
49
static unsigned char cur_salt[128 + 1]; //current salt
50
static unsigned char cur_key[128 + 1]; //current salt
51
52
static unsigned char deskey[8];
53
static unsigned char salt_iv[8];
54
static DES_key_schedule desschedule1;
55
static DES_key_schedule desschedule2;
56
57
static int salt_length;
58
static int key_length;
59
60
static int valid(char *ciphertext)
61
{
62
	int i;
63
	int l;
64
65
	/*
66
	 * 2 cases
67
	 * 1 - it comes from the disk, and does not have O$ + salt
68
	 * 2 - it comes from memory, and has got O$ + salt + # + blah
69
	 */
70
71
	if (!memcmp(ciphertext, "O$", 2))
72
	{
73
		l = strlen(ciphertext) - PLAINTEXT_LENGTH;
74
		if(ciphertext[l-1]!='#')
75
			return 0;
76
	}
77
	else
78
	{
79
		if(strlen(ciphertext)!=PLAINTEXT_LENGTH)
80
			return 0;
81
		l = 0;
82
	}
83
	for (i = l; i < l + PLAINTEXT_LENGTH; i++){
84
		if (!(  (('0' <= ciphertext[i])&&(ciphertext[i] <= '9')) ||
85
			(('a' <= ciphertext[i])&&(ciphertext[i] <= 'f'))  
86
			|| (('A' <= ciphertext[i])&&(ciphertext[i] <= 'F'))))
87
			return 0;
88
	}
89
	
90
	return 1;
91
}
92
93
static void oracle_init(void)
94
{
95
	deskey[0] = 0x01;
96
	deskey[1] = 0x23;
97
	deskey[2] = 0x45;
98
	deskey[3] = 0x67;
99
	deskey[4] = 0x89;
100
	deskey[5] = 0xab;
101
	deskey[6] = 0xcd;
102
	deskey[7] = 0xef;
103
104
	my_des_set_key(&deskey, &desschedule1);
105
}
106
107
static inline unsigned char upper(unsigned char c)
108
{
109
	if( (c>='a') && (c<='z'))
110
		return c+'A'-'a';
111
	return c;
112
}
113
114
static void oracle_set_salt(void *salt, int count) {
115
	salt_length = 0;
116
117
	memset(salt_iv, 0, 8);
118
	while ( (((unsigned short *)cur_salt)[salt_length] = upper(((unsigned char *)salt)[salt_length]) ENDIAN_SHIFT_L ))
119
		salt_length++;
120
}
121
122
static void oracle_set_key(char *key, int index) {
123
	key_length = 0;
124
	while( (((unsigned short *)cur_key)[key_length] = upper(key[key_length]) ENDIAN_SHIFT_L ))
125
		key_length++;
126
}
127
128
static char *oracle_get_key(int index) {
129
	static unsigned char out[PLAINTEXT_LENGTH];
130
	unsigned int i;
131
	for(i=0;i<key_length;i++)
132
		out[i] = ((unsigned short *)cur_key)[i] ENDIAN_SHIFT_R;
133
	out[i] = 0;
134
	return out;
135
}
136
137
static int oracle_cmp_all(void *binary, int index) { 
138
	int i=0;
139
	while(i<(BINARY_SIZE/sizeof(int)))
140
	{
141
		if(((int *)binary)[i]!=((int *)crypt_key)[i])
142
			return 0;
143
		i++;
144
	}
145
	return 1;
146
}
147
148
static void oracle_crypt_all(int count)  
149
{
150
	unsigned int l;
151
152
	
153
	l = (salt_length + key_length)*2;
154
	memcpy(crypt_key, salt_iv, 8);
155
	//that's the way john works ...
156
	memcpy(cur_salt + salt_length*2, cur_key, key_length * 2);
157
	my_des_ncbc_encrypt(cur_salt ,l , &desschedule1,(DES_cblock *) crypt_key);
158
	my_des_set_key((DES_cblock *)crypt_key, &desschedule2);
159
	memset(crypt_key, 0, 8);
160
	my_des_ncbc_encrypt(cur_salt, l , &desschedule2, (DES_cblock *)crypt_key);
161
}
162
163
static void * oracle_binary(char *ciphertext) 
164
{
165
	static unsigned char out3[BINARY_SIZE];
166
	int l;
167
	int i;
168
	l = strlen(ciphertext) - PLAINTEXT_LENGTH;
169
	for(i=0;i<BINARY_SIZE;i++) 
170
	{
171
		out3[i] = atoi16[ARCH_INDEX(ciphertext[i*2+l])]*16 
172
			+ atoi16[ARCH_INDEX(ciphertext[i*2+l+1])];
173
	}
174
	return out3;
175
}
176
177
static void * oracle_get_salt(char * ciphertext)
178
{
179
	static unsigned char out2[SALT_SIZE];
180
	int l;
181
182
	l = 2;
183
	while( ciphertext[l] && (ciphertext[l]!='#') )
184
	{
185
		out2[l-2] = ciphertext[l];
186
		l++;
187
	}
188
	out2[l-2] = 0;
189
	return out2;
190
}
191
192
static int oracle_cmp_one(void *binary, int count){
193
	return (1);
194
}
195
196
static int oracle_cmp_exact(char *source, int count){
197
	return 1;
198
}
199
200
static int binary_hash1(void * binary) { return (((unsigned int *)binary)[0] & 0xf); }
201
static int binary_hash2(void * binary) { return (((unsigned int *)binary)[0] & 0xff); }
202
static int binary_hash3(void * binary) { return (((unsigned int *)binary)[0] & 0xfff); }
203
204
static int get_hash1(int index) { return (((unsigned int *)crypt_key)[0] & 0xf); }
205
static int get_hash2(int index) { return (((unsigned int *)crypt_key)[0] & 0xff); }
206
static int get_hash3(int index) { return (((unsigned int *)crypt_key)[0] & 0xfff); }
207
208
struct fmt_main fmt_oracle = {
209
	{
210
		FORMAT_LABEL,
211
		FORMAT_NAME,
212
		ALGORITHM_NAME,
213
		BENCHMARK_COMMENT,
214
		BENCHMARK_LENGTH,
215
		PLAINTEXT_LENGTH,
216
		BINARY_SIZE,
217
		SALT_SIZE,
218
		MIN_KEYS_PER_CRYPT,
219
		MAX_KEYS_PER_CRYPT,
220
		FMT_8_BIT,
221
		oracle_tests
222
	}, {
223
		oracle_init,
224
		valid,
225
		fmt_default_split,
226
		oracle_binary,
227
		oracle_get_salt,
228
		{
229
			binary_hash1,
230
			binary_hash2,
231
			binary_hash3
232
		},
233
		fmt_default_salt_hash,
234
		oracle_set_salt,
235
		oracle_set_key,
236
		oracle_get_key,
237
		fmt_default_clear_keys,
238
		oracle_crypt_all,
239
		{
240
			get_hash1,
241
			get_hash2,
242
			get_hash3
243
		},
244
		oracle_cmp_all,
245
		oracle_cmp_one,
246
		oracle_cmp_exact
247
	}
248
};
(-)john-1.7.0.1/src/ppc-alti.c (+3 lines)
Lines 178-183 Link Here
178
	ARCH_WORD **k;
178
	ARCH_WORD **k;
179
#endif
179
#endif
180
	int iterations, rounds_and_swapped;
180
	int iterations, rounds_and_swapped;
181
#if DES_BS_VECTOR
182
	int depth;
183
#endif
181
184
182
	DES_bs_clear_block();
185
	DES_bs_clear_block();
183
186
(-)john-1.7.0.1/src/ppc.h (+47 lines)
Line 0 Link Here
1
/*
2
 * This file is part of John the Ripper password cracker,
3
 * Copyright (c) 1996-2000 by Solar Designer
4
 */
5
6
/*
7
 * Architecture specific parameters for PowerPC.
8
 */
9
10
#ifndef _JOHN_ARCH_H
11
#define _JOHN_ARCH_H
12
13
#define ARCH_WORD			long
14
#define ARCH_SIZE			4
15
#define ARCH_BITS			32
16
#define ARCH_BITS_LOG			5
17
#define ARCH_BITS_STR			"32"
18
#define ARCH_LITTLE_ENDIAN		0
19
#define ARCH_INT_GT_32			0
20
#define ARCH_ALLOWS_UNALIGNED		0
21
#define ARCH_INDEX(x)			((unsigned int)(unsigned char)(x))
22
23
#define OS_TIMER			1
24
#define OS_FLOCK			1
25
26
#define CPU_DETECT			0
27
28
#define DES_ASM				0
29
#define DES_128K			0
30
#define DES_X2				0
31
#define DES_MASK			1
32
#define DES_SCALE			0
33
#define DES_EXTB			1
34
#define DES_COPY			0
35
#define DES_BS_ASM			0
36
#define DES_BS				1
37
#define DES_BS_VECTOR			0
38
#define DES_BS_EXPAND			1
39
40
#define MD5_ASM				0
41
#define MD5_X2				1
42
#define MD5_IMM				0
43
44
#define BF_ASM				0
45
#define BF_SCALE			0
46
47
#endif
(-)john-1.7.0.1/src/ppc64.h (-1 / +1 lines)
Lines 10-16 Link Here
10
#ifndef _JOHN_ARCH_H
10
#ifndef _JOHN_ARCH_H
11
#define _JOHN_ARCH_H
11
#define _JOHN_ARCH_H
12
12
13
#define ARCH_WORD			long
13
#define ARCH_WORD			long long
14
#define ARCH_SIZE			8
14
#define ARCH_SIZE			8
15
#define ARCH_BITS			64
15
#define ARCH_BITS			64
16
#define ARCH_BITS_LOG			6
16
#define ARCH_BITS_LOG			6
(-)john-1.7.0.1/src/ppc64alt.h (-1 / +1 lines)
Lines 10-16 Link Here
10
#ifndef _JOHN_ARCH_H
10
#ifndef _JOHN_ARCH_H
11
#define _JOHN_ARCH_H
11
#define _JOHN_ARCH_H
12
12
13
#define ARCH_WORD			long
13
#define ARCH_WORD			long long
14
#define ARCH_SIZE			8
14
#define ARCH_SIZE			8
15
#define ARCH_BITS			64
15
#define ARCH_BITS			64
16
#define ARCH_BITS_LOG			6
16
#define ARCH_BITS_LOG			6
(-)john-1.7.0.1/src/rawMD5_fmt.c (+262 lines)
Line 0 Link Here
1
/*
2
 * Copyright (c) 2004 bartavelle
3
 * bartavelle@bandecon.com
4
 *
5
 * Simple MD5 hashes cracker
6
 * It uses the Solar Designer's md5 implementation
7
 * 
8
 */
9
10
#include <string.h>
11
12
#include "arch.h"
13
#include "misc.h"
14
#include "common.h"
15
#include "formats.h"
16
#include "md5.h"
17
18
#define FORMAT_LABEL			"raw-md5"
19
#define FORMAT_NAME			"Raw MD5"
20
#ifdef MMX_COEF
21
#if (MMX_COEF == 2)
22
#define ALGORITHM_NAME			"raw-md5 MMX"
23
#else
24
#define ALGORITHM_NAME			"raw-md5 SSE2"
25
#endif
26
#else
27
#define ALGORITHM_NAME			"raw-md5"
28
#endif
29
30
#ifdef MMX_TYPE
31
#define BENCHMARK_COMMENT		MMX_TYPE
32
#else
33
#define BENCHMARK_COMMENT		""
34
#endif
35
#define BENCHMARK_LENGTH		-1
36
37
#define PLAINTEXT_LENGTH		32
38
#define CIPHERTEXT_LENGTH		32
39
40
#define BINARY_SIZE			16
41
#define SALT_SIZE			0
42
43
#ifdef MMX_COEF
44
#define MIN_KEYS_PER_CRYPT		MMX_COEF
45
#define MAX_KEYS_PER_CRYPT		MMX_COEF
46
#define GETPOS(i, index)		( (index)*4 + (i& (0xffffffff-3) )*MMX_COEF + ((i)&3) )
47
#else
48
#define MIN_KEYS_PER_CRYPT		1
49
#define MAX_KEYS_PER_CRYPT		1
50
#endif
51
52
static struct fmt_tests rawmd5_tests[] = {
53
	{"5a105e8b9d40e1329780d62ea2265d8a", "test1"},
54
	{"ad0234829205b9033196ba818f7a872b", "test2"},
55
	{"8ad8757baa8564dc136c1e07507f4a98", "test3"},
56
	{"86985e105f79b95d6bc918fb45ec7727", "test4"},
57
	{NULL}
58
};
59
60
#ifdef MMX_COEF
61
static char saved_key[PLAINTEXT_LENGTH*MMX_COEF*2 + 1] __attribute__ ((aligned(16)));
62
static char crypt_key[BINARY_SIZE*MMX_COEF+1] __attribute__ ((aligned(16)));
63
unsigned long total_len;
64
unsigned char out[PLAINTEXT_LENGTH];
65
#else
66
static char saved_key[PLAINTEXT_LENGTH + 1];
67
static char crypt_key[BINARY_SIZE+1];
68
static MD5_CTX ctx;
69
#endif
70
71
static int valid(char *ciphertext)
72
{
73
	int i;
74
75
	if (strlen(ciphertext) != CIPHERTEXT_LENGTH) return 0;
76
	for (i = 0; i < CIPHERTEXT_LENGTH; i++){
77
		if (!(  (('0' <= ciphertext[i])&&(ciphertext[i] <= '9')) ||
78
					(('a' <= ciphertext[i])&&(ciphertext[i] <= 'f'))  
79
					|| (('A' <= ciphertext[i])&&(ciphertext[i] <= 'F'))))
80
			return 0;
81
	}
82
	return 1;
83
}
84
85
static void rawmd5_set_salt(void *salt) { }
86
87
static void rawmd5_set_key(char *key, int index) {
88
#ifdef MMX_COEF
89
	int len;
90
	int i;
91
	
92
	if(index==0)
93
	{
94
		total_len = 0;
95
		memset(saved_key, 0, PLAINTEXT_LENGTH*MMX_COEF);
96
	}
97
	len = strlen(key);
98
	if(len>PLAINTEXT_LENGTH)
99
		len = PLAINTEXT_LENGTH;
100
101
	total_len += len << ( ( (32/MMX_COEF) * index ) );
102
	for(i=0;i<len;i++)
103
		saved_key[GETPOS(i, index)] = key[i];
104
105
	saved_key[GETPOS(i, index)] = 0x80;
106
#else
107
	strnzcpy(saved_key, key, PLAINTEXT_LENGTH+1);
108
#endif
109
}
110
111
static char *rawmd5_get_key(int index) {
112
#ifdef MMX_COEF
113
	unsigned int i,s;
114
	
115
	s = (total_len >> (((32/MMX_COEF)*(index)))) & 0xff;
116
	for(i=0;i<s;i++)
117
		out[i] = saved_key[ GETPOS(i, index) ];
118
	out[i] = 0;
119
	return out;
120
#else
121
	return saved_key;
122
#endif
123
}
124
125
static int rawmd5_cmp_all(void *binary, int index) { 
126
	int i=0;
127
#ifdef MMX_COEF
128
	while(i< (BINARY_SIZE/4) )
129
	{
130
		if (
131
			( ((unsigned long *)binary)[i] != ((unsigned long *)crypt_key)[i*MMX_COEF])
132
			&& ( ((unsigned long *)binary)[i] != ((unsigned long *)crypt_key)[i*MMX_COEF+1])
133
#if (MMX_COEF > 3)
134
			&& ( ((unsigned long *)binary)[i] != ((unsigned long *)crypt_key)[i*MMX_COEF+2])
135
			&& ( ((unsigned long *)binary)[i] != ((unsigned long *)crypt_key)[i*MMX_COEF+3])
136
#endif
137
		)
138
			return 0;
139
		i++;
140
	}
141
#else
142
	while(i<BINARY_SIZE)
143
	{
144
		if(((char *)binary)[i]!=((char *)crypt_key)[i])
145
			return 0;
146
		i++;
147
	}
148
#endif
149
	return 1;
150
}
151
152
static int rawmd5_cmp_exact(char *source, int count){
153
  return (1);
154
}
155
156
static int rawmd5_cmp_one(void * binary, int index)
157
{
158
#ifdef MMX_COEF
159
	int i = 0;
160
	for(i=0;i<(BINARY_SIZE/4);i++)
161
		if ( ((unsigned long *)binary)[i] != ((unsigned long *)crypt_key)[i*MMX_COEF+index] )
162
			return 0;
163
	return 1;
164
#else
165
	return rawmd5_cmp_all(binary, index);
166
#endif
167
}
168
169
static void rawmd5_crypt_all(int count) {  
170
  // get plaintext input in saved_key put it into ciphertext crypt_key
171
#ifdef MMX_COEF
172
	mdfivemmx(crypt_key, saved_key, total_len);
173
#else
174
	MD5_Init( &ctx );
175
	MD5_Update( &ctx, saved_key, strlen( saved_key ) );
176
	MD5_Final( crypt_key, &ctx);
177
#endif
178
  
179
}
180
181
static void * rawmd5_binary(char *ciphertext) 
182
{
183
	static char realcipher[BINARY_SIZE];
184
	int i;
185
	
186
	for(i=0;i<BINARY_SIZE;i++)
187
	{
188
		realcipher[i] = atoi16[ARCH_INDEX(ciphertext[i*2])]*16 + atoi16[ARCH_INDEX(ciphertext[i*2+1])];
189
	}
190
	return (void *)realcipher;
191
}
192
193
static int get_hash1(int index)
194
{
195
#ifdef MMX_COEF
196
	return (((unsigned long *)crypt_key)[index] & 0xf);
197
#else
198
	return (((unsigned int *)crypt_key)[0] & 0xf);
199
#endif
200
}
201
static int get_hash2(int index)
202
{
203
#ifdef MMX_COEF
204
	return (((unsigned long *)crypt_key)[index] & 0xff);
205
#else
206
	return (((unsigned int *)crypt_key)[0] & 0xff);
207
#endif
208
}
209
static int get_hash3(int index)
210
{
211
#ifdef MMX_COEF
212
	return (((unsigned long *)crypt_key)[index] & 0xfff);
213
#else
214
	return (((unsigned int *)crypt_key)[0] & 0xfff);
215
#endif
216
}
217
218
static int binary_hash1(void * binary) { return (((unsigned int *)binary)[0] & 0xf); }
219
static int binary_hash2(void * binary) { return (((unsigned int *)binary)[0] & 0xff); }
220
static int binary_hash3(void * binary) { return (((unsigned int *)binary)[0] & 0xfff); }
221
222
struct fmt_main fmt_rawMD5 = {
223
	{
224
		FORMAT_LABEL,
225
		FORMAT_NAME,
226
		ALGORITHM_NAME,
227
		BENCHMARK_COMMENT,
228
		BENCHMARK_LENGTH,
229
		PLAINTEXT_LENGTH,
230
		BINARY_SIZE,
231
		SALT_SIZE,
232
		MIN_KEYS_PER_CRYPT,
233
		MAX_KEYS_PER_CRYPT,
234
		FMT_CASE | FMT_8_BIT,
235
		rawmd5_tests
236
	}, {
237
		fmt_default_init,
238
		valid,
239
		fmt_default_split,
240
		rawmd5_binary,
241
		fmt_default_salt,
242
		{
243
			binary_hash1,
244
			binary_hash2,
245
			binary_hash3
246
		},
247
		fmt_default_salt_hash,
248
		rawmd5_set_salt,
249
		rawmd5_set_key,
250
		rawmd5_get_key,
251
		fmt_default_clear_keys,
252
		rawmd5_crypt_all,
253
		{
254
			get_hash1,
255
			get_hash2,
256
			get_hash3
257
		},
258
		rawmd5_cmp_all,
259
		rawmd5_cmp_one,
260
		rawmd5_cmp_exact
261
	}
262
};
(-)john-1.7.0.1/src/rawSHA1_fmt.c (+271 lines)
Line 0 Link Here
1
/*
2
 * Copyright (c) 2004 bartavelle
3
 * bartavelle@bandecon.com
4
 *
5
 * Simple MD5 hashes cracker
6
 * It uses the Solar Designer's md5 implementation
7
 * 
8
 */
9
10
#include <string.h>
11
12
#include "arch.h"
13
#include "misc.h"
14
#include "common.h"
15
#include "formats.h"
16
#include "sha.h"
17
18
#define FORMAT_LABEL			"raw-sha1"
19
#define FORMAT_NAME			"Raw SHA1"
20
#ifdef MMX_COEF
21
#if (MMX_COEF == 2)
22
#define ALGORITHM_NAME			"raw-sha1 MMX"
23
#else
24
#define ALGORITHM_NAME			"raw-sha1 SSE2"
25
#endif
26
#else
27
#define ALGORITHM_NAME			"raw-sha1"
28
#endif
29
30
#ifdef MMX_TYPE
31
#define BENCHMARK_COMMENT		MMX_TYPE
32
#else
33
#define BENCHMARK_COMMENT		""
34
#endif
35
#define BENCHMARK_LENGTH		-1
36
37
#define PLAINTEXT_LENGTH		32
38
#define CIPHERTEXT_LENGTH		40
39
40
#define BINARY_SIZE			20
41
#define SALT_SIZE			0
42
43
#ifdef MMX_COEF
44
#define MIN_KEYS_PER_CRYPT		MMX_COEF
45
#define MAX_KEYS_PER_CRYPT		MMX_COEF
46
//#define GETPOS(i, index)		( (index)*4 + (i& (0xffffffff-3) )*MMX_COEF + ((i)&3) ) //std getpos
47
#define GETPOS(i, index)		( (index)*4 + (i& (0xffffffff-3) )*MMX_COEF + (3-((i)&3)) ) //for endianity conversion
48
#else
49
#define MIN_KEYS_PER_CRYPT		1
50
#define MAX_KEYS_PER_CRYPT		1
51
#endif
52
53
static struct fmt_tests rawsha1_tests[] = {
54
	{"A9993E364706816ABA3E25717850C26C9CD0D89D", "abc"},
55
	{"2fbf0eba37de1d1d633bc1ed943b907f9b360d4c", "azertyuiop1"},
56
	{"f879f8090e92232ed07092ebed6dc6170457a21d", "azertyuiop2"},
57
	{"1813c12f25e64931f3833b26e999e26e81f9ad24", "azertyuiop3"},
58
	{NULL}
59
};
60
61
#ifdef MMX_COEF
62
static char saved_key[PLAINTEXT_LENGTH*MMX_COEF*2 + 1] __attribute__ ((aligned(16)));
63
static char crypt_key[80*4*MMX_COEF+1] __attribute__ ((aligned(16)));
64
unsigned long total_len;
65
unsigned char out[PLAINTEXT_LENGTH];
66
#else
67
static char saved_key[PLAINTEXT_LENGTH + 1];
68
static char crypt_key[BINARY_SIZE+1];
69
static SHA_CTX ctx;
70
#endif
71
72
static int valid(char *ciphertext)
73
{
74
	int i;
75
76
	if (strlen(ciphertext) != CIPHERTEXT_LENGTH) return 0;
77
	for (i = 0; i < CIPHERTEXT_LENGTH; i++){
78
		if (!(  (('0' <= ciphertext[i])&&(ciphertext[i] <= '9')) ||
79
					(('a' <= ciphertext[i])&&(ciphertext[i] <= 'f'))  
80
					|| (('A' <= ciphertext[i])&&(ciphertext[i] <= 'F'))))
81
			return 0;
82
	}
83
	return 1;
84
}
85
86
static void rawsha1_set_salt(void *salt) { }
87
88
static void rawsha1_init(void)
89
{
90
#ifdef MMX_COEF
91
	memset(saved_key, 0, PLAINTEXT_LENGTH*MMX_COEF*2 + 1);
92
#endif
93
}
94
95
static void rawsha1_set_key(char *key, int index) {
96
#ifdef MMX_COEF
97
	int len;
98
	int i;
99
	
100
	if(index==0)
101
	{
102
		total_len = 0;
103
		memset(saved_key, 0, PLAINTEXT_LENGTH*MMX_COEF);
104
	}
105
	len = strlen(key);
106
	if(len>PLAINTEXT_LENGTH)
107
		len = PLAINTEXT_LENGTH;
108
109
	total_len += len << ( ( (32/MMX_COEF) * index ) );
110
	for(i=0;i<len;i++)
111
		saved_key[GETPOS(i, index)] = key[i];
112
113
	saved_key[GETPOS(i, index)] = 0x80;
114
#else
115
	strnzcpy(saved_key, key, PLAINTEXT_LENGTH+1);
116
#endif
117
}
118
119
static char *rawsha1_get_key(int index) {
120
#ifdef MMX_COEF
121
	unsigned int i,s;
122
	
123
	s = (total_len >> (((32/MMX_COEF)*(index)))) & 0xff;
124
	for(i=0;i<s;i++)
125
		out[i] = saved_key[ GETPOS(i, index) ];
126
	out[i] = 0;
127
	return out;
128
#else
129
	return saved_key;
130
#endif
131
}
132
133
static int rawsha1_cmp_all(void *binary, int index) { 
134
	int i=0;
135
#ifdef MMX_COEF
136
	while(i< (BINARY_SIZE/4) )
137
	{
138
		if (
139
			( ((unsigned long *)binary)[i] != ((unsigned long *)crypt_key)[i*MMX_COEF])
140
			&& ( ((unsigned long *)binary)[i] != ((unsigned long *)crypt_key)[i*MMX_COEF+1])
141
#if (MMX_COEF > 3)
142
			&& ( ((unsigned long *)binary)[i] != ((unsigned long *)crypt_key)[i*MMX_COEF+2])
143
			&& ( ((unsigned long *)binary)[i] != ((unsigned long *)crypt_key)[i*MMX_COEF+3])
144
#endif
145
		)
146
			return 0;
147
		i++;
148
	}
149
#else
150
	while(i<BINARY_SIZE)
151
	{
152
		if(((char *)binary)[i]!=((char *)crypt_key)[i])
153
			return 0;
154
		i++;
155
	}
156
#endif
157
	return 1;
158
}
159
160
static int rawsha1_cmp_exact(char *source, int count){
161
  return (1);
162
}
163
164
static int rawsha1_cmp_one(void * binary, int index)
165
{
166
#ifdef MMX_COEF
167
	int i = 0;
168
	for(i=0;i<(BINARY_SIZE/4);i++)
169
		if ( ((unsigned long *)binary)[i] != ((unsigned long *)crypt_key)[i*MMX_COEF+index] )
170
			return 0;
171
	return 1;
172
#else
173
	return rawsha1_cmp_all(binary, index);
174
#endif
175
}
176
177
static void rawsha1_crypt_all(int count) {  
178
  // get plaintext input in saved_key put it into ciphertext crypt_key
179
#ifdef MMX_COEF
180
	shammx(crypt_key, saved_key, total_len);
181
#else
182
	SHA1_Init( &ctx );
183
	SHA1_Update( &ctx, saved_key, strlen( saved_key ) );
184
	SHA1_Final( crypt_key, &ctx);
185
#endif
186
  
187
}
188
189
static void * rawsha1_binary(char *ciphertext) 
190
{
191
	static char realcipher[BINARY_SIZE];
192
	int i;
193
	
194
	for(i=0;i<BINARY_SIZE;i++)
195
	{
196
		realcipher[i] = atoi16[ARCH_INDEX(ciphertext[i*2])]*16 + atoi16[ARCH_INDEX(ciphertext[i*2+1])];
197
	}
198
	return (void *)realcipher;
199
}
200
201
static int binary_hash_0(void *binary)
202
{
203
  return ((unsigned int *)binary)[0] & 0xF;
204
}
205
206
static int binary_hash_1(void *binary)
207
{
208
  return ((unsigned int *)binary)[0] & 0xFF;
209
}
210
211
static int binary_hash_2(void *binary)
212
{
213
  return ((unsigned int *)binary)[0] & 0xFFF;
214
}
215
216
static int get_hash_0(int index)
217
{
218
  return ((unsigned long *)crypt_key)[index] & 0xF;
219
}
220
221
static int get_hash_1(int index)
222
{
223
  return ((unsigned long *)crypt_key)[index] & 0xFF;
224
}
225
226
static int get_hash_2(int index)
227
{
228
  return ((unsigned long *)crypt_key)[index] & 0xFFF;
229
}
230
231
struct fmt_main fmt_rawSHA1 = {
232
	{
233
		FORMAT_LABEL,
234
		FORMAT_NAME,
235
		ALGORITHM_NAME,
236
		BENCHMARK_COMMENT,
237
		BENCHMARK_LENGTH,
238
		PLAINTEXT_LENGTH,
239
		BINARY_SIZE,
240
		SALT_SIZE,
241
		MIN_KEYS_PER_CRYPT,
242
		MAX_KEYS_PER_CRYPT,
243
		FMT_CASE | FMT_8_BIT,
244
		rawsha1_tests
245
	}, {
246
		rawsha1_init,
247
		valid,
248
		fmt_default_split,
249
		rawsha1_binary,
250
		fmt_default_salt,
251
		{
252
			binary_hash_0,
253
			binary_hash_1,
254
			binary_hash_2
255
		},
256
		fmt_default_salt_hash,
257
		rawsha1_set_salt,
258
		rawsha1_set_key,
259
		rawsha1_get_key,
260
		fmt_default_clear_keys,
261
		rawsha1_crypt_all,
262
		{
263
			get_hash_0,
264
			get_hash_1,
265
			get_hash_2
266
		},
267
		rawsha1_cmp_all,
268
		rawsha1_cmp_one,
269
		rawsha1_cmp_exact
270
	}
271
};
(-)john-1.7.0.1/src/sha.h (+115 lines)
Line 0 Link Here
1
/* crypto/sha/sha.h */
2
/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
3
 * All rights reserved.
4
 *
5
 * This package is an SSL implementation written
6
 * by Eric Young (eay@cryptsoft.com).
7
 * The implementation was written so as to conform with Netscapes SSL.
8
 * 
9
 * This library is free for commercial and non-commercial use as long as
10
 * the following conditions are aheared to.  The following conditions
11
 * apply to all code found in this distribution, be it the RC4, RSA,
12
 * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
13
 * included with this distribution is covered by the same copyright terms
14
 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15
 * 
16
 * Copyright remains Eric Young's, and as such any Copyright notices in
17
 * the code are not to be removed.
18
 * If this package is used in a product, Eric Young should be given attribution
19
 * as the author of the parts of the library used.
20
 * This can be in the form of a textual message at program startup or
21
 * in documentation (online or textual) provided with the package.
22
 * 
23
 * Redistribution and use in source and binary forms, with or without
24
 * modification, are permitted provided that the following conditions
25
 * are met:
26
 * 1. Redistributions of source code must retain the copyright
27
 *    notice, this list of conditions and the following disclaimer.
28
 * 2. Redistributions in binary form must reproduce the above copyright
29
 *    notice, this list of conditions and the following disclaimer in the
30
 *    documentation and/or other materials provided with the distribution.
31
 * 3. All advertising materials mentioning features or use of this software
32
 *    must display the following acknowledgement:
33
 *    "This product includes cryptographic software written by
34
 *     Eric Young (eay@cryptsoft.com)"
35
 *    The word 'cryptographic' can be left out if the rouines from the library
36
 *    being used are not cryptographic related :-).
37
 * 4. If you include any Windows specific code (or a derivative thereof) from 
38
 *    the apps directory (application code) you must include an acknowledgement:
39
 *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40
 * 
41
 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51
 * SUCH DAMAGE.
52
 * 
53
 * The licence and distribution terms for any publically available version or
54
 * derivative of this code cannot be changed.  i.e. this code cannot simply be
55
 * copied and put under another distribution licence
56
 * [including the GNU Public Licence.]
57
 */
58
59
#ifndef HEADER_SHA_H
60
#define HEADER_SHA_H
61
62
#ifdef  __cplusplus
63
extern "C" {
64
#endif
65
66
#define SHA_CBLOCK	64
67
#define SHA_LBLOCK	16
68
#define SHA_BLOCK	16
69
#define SHA_LAST_BLOCK  56
70
#define SHA_LENGTH_BLOCK 8
71
#define SHA_DIGEST_LENGTH 20
72
73
typedef struct SHAstate_st
74
	{
75
	unsigned long h0,h1,h2,h3,h4;
76
	unsigned long Nl,Nh;
77
	unsigned long data[SHA_LBLOCK];
78
	int num;
79
	} SHA_CTX;
80
81
#ifndef NOPROTO
82
void SHA_Init(SHA_CTX *c);
83
void SHA_Update(SHA_CTX *c, unsigned char *data, unsigned long len);
84
void SHA_Final(unsigned char *md, SHA_CTX *c);
85
unsigned char *SHA(unsigned char *d, unsigned long n,unsigned char *md);
86
void SHA_Transform(SHA_CTX *c, unsigned char *data);
87
void SHA1_Init(SHA_CTX *c);
88
void SHA1_Update(SHA_CTX *c, unsigned char *data, unsigned long len);
89
void SHA1_Final(unsigned char *md, SHA_CTX *c);
90
unsigned char *SHA1(unsigned char *d, unsigned long n,unsigned char *md);
91
void SHA1_Transform(SHA_CTX *c, unsigned char *data);
92
#else
93
void SHA_Init();
94
void SHA_Update();
95
void SHA_Final();
96
unsigned char *SHA();
97
void SHA_Transform();
98
void SHA1_Init();
99
void SHA1_Update();
100
void SHA1_Final();
101
unsigned char *SHA1();
102
void SHA1_Transform();
103
#endif
104
105
#ifdef MMX_COEF
106
extern int shammx(unsigned char *out, unsigned char *in, int n) __attribute__((regparm(3)));
107
extern int shammx_nosizeupdate(unsigned char *out, unsigned char *in, int n) __attribute__((regparm(3)));
108
extern int shammx_noinit_uniformsizeupdate(unsigned char *out, unsigned char *in, int n) __attribute__((regparm(3)));
109
#endif
110
111
#ifdef  __cplusplus
112
}
113
#endif
114
115
#endif
(-)john-1.7.0.1/src/sha1-mmx.S (+561 lines)
Line 0 Link Here
1
2
// extern int mdfourmmx(unsigned char *out, unsigned char *in, int n) __attribute__((regparm(3)));
3
4
#include "arch.h"
5
#ifdef UNDERSCORES
6
#define shammx	_shammx
7
#endif
8
9
.globl shammx;
10
.globl shammx_nosizeupdate;
11
.globl shammx_noinit_uniformsizeupdate;
12
13
.data
14
.align(8*MMX_COEF)
15
const_init_a:
16
.long 0x67452301
17
.long 0x67452301
18
#if (MMX_COEF>=4)
19
.long 0x67452301
20
.long 0x67452301
21
#endif
22
const_init_b:
23
.long 0xefcdab89
24
.long 0xefcdab89
25
#if (MMX_COEF>=4)
26
.long 0xefcdab89
27
.long 0xefcdab89
28
#endif
29
const_init_c:
30
.long 0x98badcfe
31
.long 0x98badcfe
32
#if (MMX_COEF>=4)
33
.long 0x98badcfe
34
.long 0x98badcfe
35
#endif
36
const_init_d:
37
.long 0x10325476
38
.long 0x10325476
39
#if (MMX_COEF>=4)
40
.long 0x10325476
41
.long 0x10325476
42
#endif
43
const_init_e:
44
.long 0xc3d2e1f0
45
.long 0xc3d2e1f0
46
#if (MMX_COEF>=4)
47
.long 0xc3d2e1f0
48
.long 0xc3d2e1f0
49
#endif
50
51
.align(8*MMX_COEF)
52
const_stage0:
53
.long 0x5a827999
54
.long 0x5a827999
55
#if (MMX_COEF>=4)
56
.long 0x5a827999
57
.long 0x5a827999
58
#endif
59
const_stage1:
60
.long 0x6ed9eba1
61
.long 0x6ed9eba1
62
#if (MMX_COEF>=4)
63
.long 0x6ed9eba1
64
.long 0x6ed9eba1
65
#endif
66
const_stage2:
67
.long 0x8f1bbcdc
68
.long 0x8f1bbcdc
69
#if (MMX_COEF>=4)
70
.long 0x8f1bbcdc
71
.long 0x8f1bbcdc
72
#endif
73
const_stage3:
74
.long 0xca62c1d6
75
.long 0xca62c1d6
76
#if (MMX_COEF>=4)
77
.long 0xca62c1d6
78
.long 0xca62c1d6
79
#endif
80
81
.align(8*MMX_COEF)
82
mask0f0f:
83
.long 0x00ff00ff
84
.long 0x00ff00ff
85
#if (MMX_COEF>=4)
86
.long 0x00ff00ff
87
.long 0x00ff00ff
88
#endif
89
maskf0f0:
90
.long 0xff00ff00
91
.long 0xff00ff00
92
#if (MMX_COEF>=4)
93
.long 0xff00ff00
94
.long 0xff00ff00
95
#endif
96
97
#if (MMX_COEF == 2)
98
#define MMXMOVE movq
99
#define REGMM0 %mm0
100
#define REGMM1 %mm1
101
#define REGMM2 %mm2
102
#define REGMM3 %mm3
103
#define REGMM4 %mm4
104
#define REGMM5 %mm5
105
#define REGMM6 %mm6
106
#define REGMM7 %mm7
107
storea: ; .long 0 ; .long 0
108
storeb: ; .long 0 ; .long 0
109
storec: ; .long 0 ; .long 0
110
stored: ; .long 0 ; .long 0
111
storee: ; .long 0 ; .long 0
112
#else
113
#define MMXMOVE movapd
114
#define REGMM0 %xmm0
115
#define REGMM1 %xmm1
116
#define REGMM2 %xmm2
117
#define REGMM3 %xmm3
118
#define REGMM4 %xmm4
119
#define REGMM5 %xmm5
120
#define REGMM6 %xmm6
121
#define REGMM7 %xmm7
122
storea: ; .long 0 ; .long 0 ; .long 0 ; .long 0
123
storeb: ; .long 0 ; .long 0 ; .long 0 ; .long 0
124
storec: ; .long 0 ; .long 0 ; .long 0 ; .long 0
125
stored: ; .long 0 ; .long 0 ; .long 0 ; .long 0
126
storee: ; .long 0 ; .long 0 ; .long 0 ; .long 0
127
#endif
128
129
#define ctxa REGMM0
130
#define ctxb REGMM1
131
#define ctxc REGMM2
132
#define ctxd REGMM3
133
#define ctxe REGMM4
134
#define tmp1 REGMM5
135
#define tmp2 REGMM6
136
#define tmp3 REGMM7
137
138
//ft(x,y,z) = (x AND y) OR ((NOT x) AND z) ( 0 <= t <= 19) 
139
#define F0(x,y,z) \
140
	MMXMOVE x, tmp2; \
141
	MMXMOVE x, tmp1; \
142
	pand y, tmp2; \
143
	pandn z, tmp1; \
144
	por tmp2, tmp1; 
145
146
//ft(x,y,z) = x XOR y XOR z (20 <= t <= 39)
147
#define F1(x,y,z) \
148
	MMXMOVE z, tmp1; \
149
	pxor y, tmp1; \
150
	pxor x, tmp1
151
152
//ft(x,y,z) = (x AND y) OR (x AND z) OR (y AND z) (40 <= t <= 59)
153
//ft(x,y,z) = (x AND y) | ((x OR y) AND z) (40 <= t <= 59)
154
#define F2(x,y,z) \
155
	MMXMOVE x, tmp1; \
156
	MMXMOVE x, tmp2; \
157
	pand y, tmp1; \
158
	por y, tmp2; \
159
	pand z, tmp2; \
160
	por tmp2, tmp1;
161
	
162
//ft(x,y,z) = x XOR y XOR z (60 <= t <= 79).  = la seconde
163
164
165
#define expand(t) \
166
	MMXMOVE ((t-3)*4*MMX_COEF)(%edx), tmp1; \
167
	pxor ((t-8)*4*MMX_COEF)(%edx), tmp1; \
168
	pxor ((t-14)*4*MMX_COEF)(%edx), tmp1; \
169
	pxor ((t-16)*4*MMX_COEF)(%edx), tmp1; \
170
	MMXMOVE tmp1, tmp2; \
171
	pslld $1, tmp1; \
172
	psrld $31, tmp2; \
173
	por tmp2, tmp1; \
174
	MMXMOVE tmp1, (t*4*MMX_COEF)(%edx)
175
176
#define subRound(a, b, c, d, e, f, k, data) \
177
	f(b,c,d); \
178
	MMXMOVE a, tmp2; \
179
	MMXMOVE a, tmp3; \
180
	paddd tmp1, e; \
181
	pslld $5, tmp2; \
182
	psrld $27, tmp3; \
183
	por tmp3, tmp2; \
184
	paddd tmp2, e; \
185
	MMXMOVE b, tmp2; \
186
	pslld $30, b; \
187
	paddd k, e; \
188
	paddd (data*4*MMX_COEF)(%edx), e; \
189
	psrld $2, tmp2; \
190
	por tmp2, b;
191
192
#define subRoundu(a, b, c, d, e, f, k, data) \
193
	expand(data); \
194
	paddd tmp1, e; \
195
	f(b,c,d); \
196
	MMXMOVE a, tmp2; \
197
	MMXMOVE a, tmp3; \
198
	paddd tmp1, e; \
199
	pslld $5, tmp2; \
200
	psrld $27, tmp3; \
201
	por tmp3, tmp2; \
202
	paddd tmp2, e; \
203
	MMXMOVE b, tmp2; \
204
	pslld $30, b; \
205
	paddd k, e; \
206
	psrld $2, tmp2; \
207
	por tmp2, b;
208
209
.text
210
/*
211
 * Try to do some asm md4 w/ mmx
212
 * %eax ptr -> out
213
 * %edx ptr -> in (80*MMX_WIDTH mots)
214
 * %ecx n
215
 */
216
217
init_ctx:
218
	MMXMOVE const_init_a, ctxa
219
	MMXMOVE const_init_b, ctxb
220
	MMXMOVE const_init_c, ctxc
221
	MMXMOVE const_init_d, ctxd
222
	MMXMOVE const_init_e, ctxe
223
	ret
224
225
sizeupdate:
226
	 //MD4 Init
227
#if (MMX_COEF == 2)	
228
	shl $3, %ecx
229
	mov %ecx, %ebx
230
	and $0xffff, %ecx
231
	shrl $16,  %ebx
232
	// %ecx contient la taille du premier mdp
233
	// %edx celle du second
234
	mov %ecx, (15*4*MMX_COEF)(%edx)
235
	mov %ebx, (15*4*MMX_COEF+4)(%edx)
236
#else
237
	mov %ecx, %ebx
238
        shr $8, %ecx
239
        and $0xff, %ebx
240
        shl $3, %ebx
241
        mov %ebx, (15*16)(%edx)
242
        
243
        mov %ecx, %ebx
244
        shr $8, %ecx
245
        and $0xff, %ebx
246
        shl $3, %ebx
247
        mov %ebx, (15*16+4)(%edx)
248
249
        mov %ecx, %ebx
250
        shr $8, %ecx
251
        and $0xff, %ebx
252
        shl $3, %ebx
253
        mov %ebx, (15*16+8)(%edx)
254
255
        and $0xff, %ecx
256
        shl $3, %ecx
257
        mov %ecx, (15*16+12)(%edx)
258
#endif
259
	ret
260
261
262
uniformsizeupdate:
263
	shl $3, %ecx
264
	mov %ecx, (14*4*MMX_COEF)(%edx)
265
	mov %ecx, (14*4*MMX_COEF+4)(%edx)
266
#if (MMX_COEF == 4)
267
	mov %ecx, (14*4*MMX_COEF+8)(%edx)
268
	mov %ecx, (14*4*MMX_COEF+12)(%edx)
269
#endif
270
	ret
271
272
273
shammx_noinit_sizeupdate:
274
	pusha
275
	call sizeupdate
276
	jmp shammx_noinit
277
278
shammx_noinit_uniformsizeupdate:
279
	pusha
280
	call uniformsizeupdate
281
	jmp shammx_noinit
282
283
shammx:
284
	pusha
285
	call sizeupdate
286
	call init_ctx
287
	jmp shammx_noinit
288
289
shammx_nosizeupdate:
290
	pusha
291
	call init_ctx
292
	jmp shammx_noinit
293
294
shammx_noinit:
295
	MMXMOVE ctxa, storea
296
	MMXMOVE ctxb, storeb
297
	MMXMOVE ctxc, storec
298
	MMXMOVE ctxd, stored
299
	MMXMOVE ctxe, storee
300
301
round0:
302
	prefetchnta (%edx)
303
	subRound( ctxa, ctxb, ctxc, ctxd, ctxe, F0, const_stage0,  0 );
304
	subRound( ctxe, ctxa, ctxb, ctxc, ctxd, F0, const_stage0,  1 );
305
	subRound( ctxd, ctxe, ctxa, ctxb, ctxc, F0, const_stage0,  2 );
306
	subRound( ctxc, ctxd, ctxe, ctxa, ctxb, F0, const_stage0,  3 );
307
	subRound( ctxb, ctxc, ctxd, ctxe, ctxa, F0, const_stage0,  4 );
308
	subRound( ctxa, ctxb, ctxc, ctxd, ctxe, F0, const_stage0,  5 );
309
	subRound( ctxe, ctxa, ctxb, ctxc, ctxd, F0, const_stage0,  6 );
310
	subRound( ctxd, ctxe, ctxa, ctxb, ctxc, F0, const_stage0,  7 );
311
	subRound( ctxc, ctxd, ctxe, ctxa, ctxb, F0, const_stage0,  8 );
312
	subRound( ctxb, ctxc, ctxd, ctxe, ctxa, F0, const_stage0,  9 );
313
	subRound( ctxa, ctxb, ctxc, ctxd, ctxe, F0, const_stage0, 10 );
314
	subRound( ctxe, ctxa, ctxb, ctxc, ctxd, F0, const_stage0, 11 );
315
	subRound( ctxd, ctxe, ctxa, ctxb, ctxc, F0, const_stage0, 12 );
316
	subRound( ctxc, ctxd, ctxe, ctxa, ctxb, F0, const_stage0, 13 );
317
	subRound( ctxb, ctxc, ctxd, ctxe, ctxa, F0, const_stage0, 14 );
318
	subRound( ctxa, ctxb, ctxc, ctxd, ctxe, F0, const_stage0, 15 );
319
	subRoundu( ctxe, ctxa, ctxb, ctxc, ctxd, F0, const_stage0, 16 );
320
	subRoundu( ctxd, ctxe, ctxa, ctxb, ctxc, F0, const_stage0, 17 );
321
	subRoundu( ctxc, ctxd, ctxe, ctxa, ctxb, F0, const_stage0, 18 );
322
	subRoundu( ctxb, ctxc, ctxd, ctxe, ctxa, F0, const_stage0, 19 );
323
324
round1:
325
	subRoundu( ctxa, ctxb, ctxc, ctxd, ctxe, F1, const_stage1, 20 );
326
	subRoundu( ctxe, ctxa, ctxb, ctxc, ctxd, F1, const_stage1, 21 );
327
	subRoundu( ctxd, ctxe, ctxa, ctxb, ctxc, F1, const_stage1, 22 );
328
	subRoundu( ctxc, ctxd, ctxe, ctxa, ctxb, F1, const_stage1, 23 );
329
	subRoundu( ctxb, ctxc, ctxd, ctxe, ctxa, F1, const_stage1, 24 );
330
	subRoundu( ctxa, ctxb, ctxc, ctxd, ctxe, F1, const_stage1, 25 );
331
	subRoundu( ctxe, ctxa, ctxb, ctxc, ctxd, F1, const_stage1, 26 );
332
	subRoundu( ctxd, ctxe, ctxa, ctxb, ctxc, F1, const_stage1, 27 );
333
	subRoundu( ctxc, ctxd, ctxe, ctxa, ctxb, F1, const_stage1, 28 );
334
	subRoundu( ctxb, ctxc, ctxd, ctxe, ctxa, F1, const_stage1, 29 );
335
	subRoundu( ctxa, ctxb, ctxc, ctxd, ctxe, F1, const_stage1, 30 );
336
	subRoundu( ctxe, ctxa, ctxb, ctxc, ctxd, F1, const_stage1, 31 );
337
	subRoundu( ctxd, ctxe, ctxa, ctxb, ctxc, F1, const_stage1, 32 );
338
	subRoundu( ctxc, ctxd, ctxe, ctxa, ctxb, F1, const_stage1, 33 );
339
	subRoundu( ctxb, ctxc, ctxd, ctxe, ctxa, F1, const_stage1, 34 );
340
	subRoundu( ctxa, ctxb, ctxc, ctxd, ctxe, F1, const_stage1, 35 );
341
	subRoundu( ctxe, ctxa, ctxb, ctxc, ctxd, F1, const_stage1, 36 );
342
	subRoundu( ctxd, ctxe, ctxa, ctxb, ctxc, F1, const_stage1, 37 );
343
	subRoundu( ctxc, ctxd, ctxe, ctxa, ctxb, F1, const_stage1, 38 );
344
	subRoundu( ctxb, ctxc, ctxd, ctxe, ctxa, F1, const_stage1, 39 );
345
346
round2:
347
	subRoundu( ctxa, ctxb, ctxc, ctxd, ctxe, F2, const_stage2, 40 );
348
	subRoundu( ctxe, ctxa, ctxb, ctxc, ctxd, F2, const_stage2, 41 );
349
	subRoundu( ctxd, ctxe, ctxa, ctxb, ctxc, F2, const_stage2, 42 );
350
	subRoundu( ctxc, ctxd, ctxe, ctxa, ctxb, F2, const_stage2, 43 );
351
	subRoundu( ctxb, ctxc, ctxd, ctxe, ctxa, F2, const_stage2, 44 );
352
	subRoundu( ctxa, ctxb, ctxc, ctxd, ctxe, F2, const_stage2, 45 );
353
	subRoundu( ctxe, ctxa, ctxb, ctxc, ctxd, F2, const_stage2, 46 );
354
	subRoundu( ctxd, ctxe, ctxa, ctxb, ctxc, F2, const_stage2, 47 );
355
	subRoundu( ctxc, ctxd, ctxe, ctxa, ctxb, F2, const_stage2, 48 );
356
	subRoundu( ctxb, ctxc, ctxd, ctxe, ctxa, F2, const_stage2, 49 );
357
	subRoundu( ctxa, ctxb, ctxc, ctxd, ctxe, F2, const_stage2, 50 );
358
	subRoundu( ctxe, ctxa, ctxb, ctxc, ctxd, F2, const_stage2, 51 );
359
	subRoundu( ctxd, ctxe, ctxa, ctxb, ctxc, F2, const_stage2, 52 );
360
	subRoundu( ctxc, ctxd, ctxe, ctxa, ctxb, F2, const_stage2, 53 );
361
	subRoundu( ctxb, ctxc, ctxd, ctxe, ctxa, F2, const_stage2, 54 );
362
	subRoundu( ctxa, ctxb, ctxc, ctxd, ctxe, F2, const_stage2, 55 );
363
	subRoundu( ctxe, ctxa, ctxb, ctxc, ctxd, F2, const_stage2, 56 );
364
	subRoundu( ctxd, ctxe, ctxa, ctxb, ctxc, F2, const_stage2, 57 );
365
	subRoundu( ctxc, ctxd, ctxe, ctxa, ctxb, F2, const_stage2, 58 );
366
	subRoundu( ctxb, ctxc, ctxd, ctxe, ctxa, F2, const_stage2, 59 );
367
368
round3:
369
	subRoundu( ctxa, ctxb, ctxc, ctxd, ctxe, F1, const_stage3, 60 );
370
	subRoundu( ctxe, ctxa, ctxb, ctxc, ctxd, F1, const_stage3, 61 );
371
	subRoundu( ctxd, ctxe, ctxa, ctxb, ctxc, F1, const_stage3, 62 );
372
	subRoundu( ctxc, ctxd, ctxe, ctxa, ctxb, F1, const_stage3, 63 );
373
	subRoundu( ctxb, ctxc, ctxd, ctxe, ctxa, F1, const_stage3, 64 );
374
	subRoundu( ctxa, ctxb, ctxc, ctxd, ctxe, F1, const_stage3, 65 );
375
	subRoundu( ctxe, ctxa, ctxb, ctxc, ctxd, F1, const_stage3, 66 );
376
	subRoundu( ctxd, ctxe, ctxa, ctxb, ctxc, F1, const_stage3, 67 );
377
	subRoundu( ctxc, ctxd, ctxe, ctxa, ctxb, F1, const_stage3, 68 );
378
	subRoundu( ctxb, ctxc, ctxd, ctxe, ctxa, F1, const_stage3, 69 );
379
	subRoundu( ctxa, ctxb, ctxc, ctxd, ctxe, F1, const_stage3, 70 );
380
	subRoundu( ctxe, ctxa, ctxb, ctxc, ctxd, F1, const_stage3, 71 );
381
	subRoundu( ctxd, ctxe, ctxa, ctxb, ctxc, F1, const_stage3, 72 );
382
	subRoundu( ctxc, ctxd, ctxe, ctxa, ctxb, F1, const_stage3, 73 );
383
	subRoundu( ctxb, ctxc, ctxd, ctxe, ctxa, F1, const_stage3, 74 );
384
	subRoundu( ctxa, ctxb, ctxc, ctxd, ctxe, F1, const_stage3, 75 );
385
	subRoundu( ctxe, ctxa, ctxb, ctxc, ctxd, F1, const_stage3, 76 );
386
	subRoundu( ctxd, ctxe, ctxa, ctxb, ctxc, F1, const_stage3, 77 );
387
	subRoundu( ctxc, ctxd, ctxe, ctxa, ctxb, F1, const_stage3, 78 );
388
	subRoundu( ctxb, ctxc, ctxd, ctxe, ctxa, F1, const_stage3, 79 );
389
390
	paddd storea, ctxa
391
	paddd storeb, ctxb
392
	paddd storec, ctxc
393
	paddd stored, ctxd
394
	paddd storee, ctxe
395
	MMXMOVE ctxa, storea
396
	MMXMOVE ctxb, storeb
397
	MMXMOVE ctxc, storec
398
	MMXMOVE ctxd, stored
399
	MMXMOVE ctxe, storee
400
	jmp endianity
401
402
endianity:
403
404
//reverse indianity w/ rotate & and
405
//mmx has no rotate instructions ..
406
#define ENDIAN(a) \
407
	MMXMOVE a, tmp1; \
408
	MMXMOVE maskf0f0, tmp3; \
409
	pand tmp3, a; \
410
	MMXMOVE mask0f0f, tmp3; \
411
	pand tmp3, tmp1; \
412
	psrld $8, a; \
413
	pslld $8, tmp1; \
414
	por tmp1, a; \
415
	MMXMOVE a, tmp1; \
416
	psrld $16, a; \
417
	pslld $16, tmp1; \
418
	por tmp1, a
419
420
// why is this so slow ?
421
#define ENDIAN2(a) \
422
	pshuflw $177,a,a; \
423
	pshufhw $177,a,a; \
424
	movq a,tmp1; \
425
	pand maskf0f0, a; \
426
	pand mask0f0f, tmp1; \
427
	psrld $8, a; \
428
	pslld $8, tmp1; \
429
	por tmp1, a
430
431
//changes indianity ...
432
	MMXMOVE maskf0f0, tmp3
433
	MMXMOVE ctxa, tmp1
434
	MMXMOVE ctxb, tmp2
435
	pand tmp3, ctxa
436
	pand tmp3, ctxb
437
	MMXMOVE mask0f0f, tmp3
438
	pand tmp3, tmp1
439
	pand tmp3, tmp2
440
	psrld $8, ctxa
441
	psrld $8, ctxb
442
	pslld $8, tmp1
443
	pslld $8, tmp2
444
	por tmp1, ctxa
445
	por tmp2, ctxb
446
	MMXMOVE ctxa, tmp1
447
	MMXMOVE ctxb, tmp2
448
	psrld $16, ctxa
449
	psrld $16, ctxb
450
	pslld $16, tmp1
451
	pslld $16, tmp2
452
	por tmp1, ctxa
453
	por tmp2, ctxb 
454
	MMXMOVE ctxa, 0(%eax)
455
	MMXMOVE ctxb, 4*MMX_COEF(%eax)
456
457
458
//now 2 more register to play with ..
459
#define tmp4 ctxa
460
#define tmp5 ctxb
461
462
	MMXMOVE maskf0f0, tmp5
463
	MMXMOVE ctxc, tmp1
464
	MMXMOVE ctxd, tmp2
465
	MMXMOVE ctxe, tmp3
466
	pand tmp5, ctxc
467
	pand tmp5, ctxd
468
	pand tmp5, ctxe
469
	MMXMOVE mask0f0f, tmp5
470
	pand tmp5, tmp1
471
	pand tmp5, tmp2
472
	pand tmp5, tmp3
473
	psrld $8, ctxc
474
	psrld $8, ctxd
475
	psrld $8, ctxe
476
	pslld $8, tmp1
477
	pslld $8, tmp2
478
	pslld $8, tmp3
479
	por tmp1, ctxc
480
	por tmp2, ctxd
481
	por tmp3, ctxe
482
	MMXMOVE ctxc, tmp1
483
	MMXMOVE ctxd, tmp2
484
	MMXMOVE ctxe, tmp3
485
	psrld $16, ctxc
486
	psrld $16, ctxd
487
	psrld $16, ctxe
488
	pslld $16, tmp1
489
	pslld $16, tmp2
490
	pslld $16, tmp3
491
	por tmp1, ctxc
492
	por tmp2, ctxd
493
	por tmp3, ctxe
494
495
	MMXMOVE ctxc, 8*MMX_COEF(%eax)
496
	MMXMOVE ctxd, 12*MMX_COEF(%eax)
497
	MMXMOVE ctxe, 16*MMX_COEF(%eax)
498
499
	//mov %ecx, %eax
500
	//movd ctxe, %eax
501
	popa
502
	emms
503
	
504
	ret
505
506
/*
507
 alternate endianity conversion
508
 shouldn't be so slow ...
509
	pshuflw $177, ctxa, ctxa
510
	pshuflw $177, ctxb, ctxb
511
	pshuflw $177, ctxc, ctxc
512
	pshuflw $177, ctxd, ctxd
513
	pshuflw $177, ctxe, ctxe
514
	movq maskf0f0, tmp3
515
	pshufhw $177, ctxa, ctxa
516
	pshufhw $177, ctxb, ctxb
517
	pshufhw $177, ctxc, ctxc
518
	pshufhw $177, ctxd, ctxd
519
	pshufhw $177, ctxe, ctxe
520
	movq ctxa, tmp1
521
	movq ctxb, tmp2
522
	pand tmp3, ctxa
523
	pand tmp3, ctxb
524
	movq mask0f0f, tmp3
525
	pand tmp3, tmp1
526
	pand tmp3, tmp2
527
	psrld $8, ctxa
528
	psrld $8, ctxb
529
	pslld $8, tmp1
530
	pslld $8, tmp2
531
	por tmp1, ctxa
532
	por tmp2, ctxb
533
	MMXMOVE ctxa, 0(%eax)
534
	MMXMOVE ctxb, 4*MMX_COEF(%eax)
535
536
//now 2 more register to play with ..
537
#define tmp4 ctxa
538
#define tmp5 ctxb
539
	movq ctxc, tmp1
540
	movq ctxd, tmp2
541
	movq ctxe, tmp4
542
	pand tmp3, tmp1
543
	pand tmp3, tmp2
544
	pand tmp3, tmp4
545
	movq maskf0f0, tmp3
546
	pand tmp3, ctxc
547
	pand tmp3, ctxd
548
	pand tmp3, ctxe
549
	psrld $8, ctxc
550
	psrld $8, ctxd
551
	psrld $8, ctxe
552
	pslld $8, tmp1
553
	pslld $8, tmp2
554
	pslld $8, tmp4
555
	por tmp1, ctxc
556
	por tmp2, ctxd
557
	por tmp4, ctxe
558
*/
559
#ifdef __ELF__
560
.section .note.GNU-stack,"",@progbits
561
#endif
(-)john-1.7.0.1/src/sha1.c (+467 lines)
Line 0 Link Here
1
/* crypto/sha/sha1dgst.c */
2
/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
3
 * All rights reserved.
4
 *
5
 * This package is an SSL implementation written
6
 * by Eric Young (eay@cryptsoft.com).
7
 * The implementation was written so as to conform with Netscapes SSL.
8
 * 
9
 * This library is free for commercial and non-commercial use as long as
10
 * the following conditions are aheared to.  The following conditions
11
 * apply to all code found in this distribution, be it the RC4, RSA,
12
 * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
13
 * included with this distribution is covered by the same copyright terms
14
 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15
 * 
16
 * Copyright remains Eric Young's, and as such any Copyright notices in
17
 * the code are not to be removed.
18
 * If this package is used in a product, Eric Young should be given attribution
19
 * as the author of the parts of the library used.
20
 * This can be in the form of a textual message at program startup or
21
 * in documentation (online or textual) provided with the package.
22
 * 
23
 * Redistribution and use in source and binary forms, with or without
24
 * modification, are permitted provided that the following conditions
25
 * are met:
26
 * 1. Redistributions of source code must retain the copyright
27
 *    notice, this list of conditions and the following disclaimer.
28
 * 2. Redistributions in binary form must reproduce the above copyright
29
 *    notice, this list of conditions and the following disclaimer in the
30
 *    documentation and/or other materials provided with the distribution.
31
 * 3. All advertising materials mentioning features or use of this software
32
 *    must display the following acknowledgement:
33
 *    "This product includes cryptographic software written by
34
 *     Eric Young (eay@cryptsoft.com)"
35
 *    The word 'cryptographic' can be left out if the rouines from the library
36
 *    being used are not cryptographic related :-).
37
 * 4. If you include any Windows specific code (or a derivative thereof) from 
38
 *    the apps directory (application code) you must include an acknowledgement:
39
 *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40
 * 
41
 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51
 * SUCH DAMAGE.
52
 * 
53
 * The licence and distribution terms for any publically available version or
54
 * derivative of this code cannot be changed.  i.e. this code cannot simply be
55
 * copied and put under another distribution licence
56
 * [including the GNU Public Licence.]
57
 */
58
59
#include <stdio.h>
60
#include <string.h>
61
#undef  SHA_0
62
#define SHA_1
63
#include "sha.h"
64
#include "sha_locl.h"
65
66
char *SHA1_version="SHA1 part of SSLeay 0.8.2b 08-Jan-1998";
67
68
/* Implemented from SHA-1 document - The Secure Hash Algorithm
69
 */
70
71
#define INIT_DATA_h0 (unsigned long)0x67452301L
72
#define INIT_DATA_h1 (unsigned long)0xefcdab89L
73
#define INIT_DATA_h2 (unsigned long)0x98badcfeL
74
#define INIT_DATA_h3 (unsigned long)0x10325476L
75
#define INIT_DATA_h4 (unsigned long)0xc3d2e1f0L
76
77
#define K_00_19	0x5a827999L
78
#define K_20_39 0x6ed9eba1L
79
#define K_40_59 0x8f1bbcdcL
80
#define K_60_79 0xca62c1d6L
81
82
#ifndef NOPROTO
83
#  ifdef SHA1_ASM
84
     void sha1_block_x86(SHA_CTX *c, register unsigned long *p, int num);
85
#    define sha1_block sha1_block_x86
86
#  else
87
     void sha1_block(SHA_CTX *c, register unsigned long *p, int num);
88
#  endif
89
#else
90
#  ifdef SHA1_ASM
91
     void sha1_block_x86();
92
#    define sha1_block sha1_block_x86
93
#  else
94
     void sha1_block();
95
#  endif
96
#endif
97
98
#if defined(L_ENDIAN) && defined(SHA1_ASM)
99
#  define	M_c2nl 		c2l
100
#  define	M_p_c2nl 	p_c2l
101
#  define	M_c2nl_p	c2l_p
102
#  define	M_p_c2nl_p	p_c2l_p
103
#  define	M_nl2c		l2c
104
#else
105
#  define	M_c2nl 		c2nl
106
#  define	M_p_c2nl	p_c2nl
107
#  define	M_c2nl_p	c2nl_p
108
#  define	M_p_c2nl_p	p_c2nl_p
109
#  define	M_nl2c		nl2c
110
#endif
111
112
void SHA1_Init(c)
113
SHA_CTX *c;
114
	{
115
	c->h0=INIT_DATA_h0;
116
	c->h1=INIT_DATA_h1;
117
	c->h2=INIT_DATA_h2;
118
	c->h3=INIT_DATA_h3;
119
	c->h4=INIT_DATA_h4;
120
	c->Nl=0;
121
	c->Nh=0;
122
	c->num=0;
123
	}
124
125
void SHA1_Update(c, data, len)
126
SHA_CTX *c;
127
register unsigned char *data;
128
unsigned long len;
129
	{
130
	register unsigned long *p;
131
	int ew,ec,sw,sc;
132
	unsigned long l;
133
134
	if (len == 0) return;
135
136
	l=(c->Nl+(len<<3))&0xffffffffL;
137
	if (l < c->Nl) /* overflow */
138
		c->Nh++;
139
	c->Nh+=(len>>29);
140
	c->Nl=l;
141
142
	if (c->num != 0)
143
		{
144
		p=c->data;
145
		sw=c->num>>2;
146
		sc=c->num&0x03;
147
148
		if ((c->num+len) >= SHA_CBLOCK)
149
			{
150
			l= p[sw];
151
			M_p_c2nl(data,l,sc);
152
			p[sw++]=l;
153
			for (; sw<SHA_LBLOCK; sw++)
154
				{
155
				M_c2nl(data,l);
156
				p[sw]=l;
157
				}
158
			len-=(SHA_CBLOCK-c->num);
159
160
			sha1_block(c,p,64);
161
			c->num=0;
162
			/* drop through and do the rest */
163
			}
164
		else
165
			{
166
			c->num+=(int)len;
167
			if ((sc+len) < 4) /* ugly, add char's to a word */
168
				{
169
				l= p[sw];
170
				M_p_c2nl_p(data,l,sc,len);
171
				p[sw]=l;
172
				}
173
			else
174
				{
175
				ew=(c->num>>2);
176
				ec=(c->num&0x03);
177
				l= p[sw];
178
				M_p_c2nl(data,l,sc);
179
				p[sw++]=l;
180
				for (; sw < ew; sw++)
181
					{ M_c2nl(data,l); p[sw]=l; }
182
				if (ec)
183
					{
184
					M_c2nl_p(data,l,ec);
185
					p[sw]=l;
186
					}
187
				}
188
			return;
189
			}
190
		}
191
	/* We can only do the following code for assember, the reason
192
	 * being that the sha1_block 'C' version changes the values
193
	 * in the 'data' array.  The assember code avoids this and
194
	 * copies it to a local array.  I should be able to do this for
195
	 * the C version as well....
196
	 */
197
#if 1
198
#if defined(B_ENDIAN) || defined(SHA1_ASM)
199
	if ((((unsigned int)data)%sizeof(unsigned long)) == 0)
200
		{
201
		sw=len/SHA_CBLOCK;
202
		if (sw)
203
			{
204
			sw*=SHA_CBLOCK;
205
			sha1_block(c,(unsigned long *)data,sw);
206
			data+=sw;
207
			len-=sw;
208
			}
209
		}
210
#endif
211
#endif
212
	/* we now can process the input data in blocks of SHA_CBLOCK
213
	 * chars and save the leftovers to c->data. */
214
	p=c->data;
215
	while (len >= SHA_CBLOCK)
216
		{
217
#if defined(B_ENDIAN) || defined(L_ENDIAN)
218
		if (p != (unsigned long *)data)
219
			memcpy(p,data,SHA_CBLOCK);
220
		data+=SHA_CBLOCK;
221
#  ifdef L_ENDIAN
222
#    ifndef SHA1_ASM /* Will not happen */
223
		for (sw=(SHA_LBLOCK/4); sw; sw--)
224
			{
225
			Endian_Reverse32(p[0]);
226
			Endian_Reverse32(p[1]);
227
			Endian_Reverse32(p[2]);
228
			Endian_Reverse32(p[3]);
229
			p+=4;
230
			}
231
		p=c->data;
232
#    endif
233
#  endif
234
#else
235
		for (sw=(SHA_BLOCK/4); sw; sw--)
236
			{
237
			M_c2nl(data,l); *(p++)=l;
238
			M_c2nl(data,l); *(p++)=l;
239
			M_c2nl(data,l); *(p++)=l;
240
			M_c2nl(data,l); *(p++)=l;
241
			}
242
		p=c->data;
243
#endif
244
		sha1_block(c,p,64);
245
		len-=SHA_CBLOCK;
246
		}
247
	ec=(int)len;
248
	c->num=ec;
249
	ew=(ec>>2);
250
	ec&=0x03;
251
252
	for (sw=0; sw < ew; sw++)
253
		{ M_c2nl(data,l); p[sw]=l; }
254
	M_c2nl_p(data,l,ec);
255
	p[sw]=l;
256
	}
257
258
void SHA1_Transform(c,b)
259
SHA_CTX *c;
260
unsigned char *b;
261
	{
262
	unsigned long p[16];
263
#ifndef B_ENDIAN
264
	unsigned long *q;
265
	int i;
266
#endif
267
268
#if defined(B_ENDIAN) || defined(L_ENDIAN)
269
	memcpy(p,b,64);
270
#ifdef L_ENDIAN
271
	q=p;
272
	for (i=(SHA_LBLOCK/4); i; i--)
273
		{
274
		Endian_Reverse32(q[0]);
275
		Endian_Reverse32(q[1]);
276
		Endian_Reverse32(q[2]);
277
		Endian_Reverse32(q[3]);
278
		q+=4;
279
		}
280
#endif
281
#else
282
	q=p;
283
	for (i=(SHA_LBLOCK/4); i; i--)
284
		{
285
		unsigned long l;
286
		c2nl(b,l); *(q++)=l;
287
		c2nl(b,l); *(q++)=l;
288
		c2nl(b,l); *(q++)=l;
289
		c2nl(b,l); *(q++)=l; 
290
		} 
291
#endif
292
	sha1_block(c,p,64);
293
	}
294
295
#ifndef SHA1_ASM
296
297
void sha1_block(c, W, num)
298
SHA_CTX *c;
299
register unsigned long *W;
300
int num;
301
	{
302
	register unsigned long A,B,C,D,E,T;
303
	unsigned long X[16];
304
305
	A=c->h0;
306
	B=c->h1;
307
	C=c->h2;
308
	D=c->h3;
309
	E=c->h4;
310
311
	for (;;)
312
		{
313
	BODY_00_15( 0,A,B,C,D,E,T,W);
314
	BODY_00_15( 1,T,A,B,C,D,E,W);
315
	BODY_00_15( 2,E,T,A,B,C,D,W);
316
	BODY_00_15( 3,D,E,T,A,B,C,W);
317
	BODY_00_15( 4,C,D,E,T,A,B,W);
318
	BODY_00_15( 5,B,C,D,E,T,A,W);
319
	BODY_00_15( 6,A,B,C,D,E,T,W);
320
	BODY_00_15( 7,T,A,B,C,D,E,W);
321
	BODY_00_15( 8,E,T,A,B,C,D,W);
322
	BODY_00_15( 9,D,E,T,A,B,C,W);
323
	BODY_00_15(10,C,D,E,T,A,B,W);
324
	BODY_00_15(11,B,C,D,E,T,A,W);
325
	BODY_00_15(12,A,B,C,D,E,T,W);
326
	BODY_00_15(13,T,A,B,C,D,E,W);
327
	BODY_00_15(14,E,T,A,B,C,D,W);
328
	BODY_00_15(15,D,E,T,A,B,C,W);
329
	BODY_16_19(16,C,D,E,T,A,B,W,W,W,W);
330
	BODY_16_19(17,B,C,D,E,T,A,W,W,W,W);
331
	BODY_16_19(18,A,B,C,D,E,T,W,W,W,W);
332
	BODY_16_19(19,T,A,B,C,D,E,W,W,W,X);
333
334
	BODY_20_31(20,E,T,A,B,C,D,W,W,W,X);
335
	BODY_20_31(21,D,E,T,A,B,C,W,W,W,X);
336
	BODY_20_31(22,C,D,E,T,A,B,W,W,W,X);
337
	BODY_20_31(23,B,C,D,E,T,A,W,W,W,X);
338
	BODY_20_31(24,A,B,C,D,E,T,W,W,X,X);
339
	BODY_20_31(25,T,A,B,C,D,E,W,W,X,X);
340
	BODY_20_31(26,E,T,A,B,C,D,W,W,X,X);
341
	BODY_20_31(27,D,E,T,A,B,C,W,W,X,X);
342
	BODY_20_31(28,C,D,E,T,A,B,W,W,X,X);
343
	BODY_20_31(29,B,C,D,E,T,A,W,W,X,X);
344
	BODY_20_31(30,A,B,C,D,E,T,W,X,X,X);
345
	BODY_20_31(31,T,A,B,C,D,E,W,X,X,X);
346
	BODY_32_39(32,E,T,A,B,C,D,X);
347
	BODY_32_39(33,D,E,T,A,B,C,X);
348
	BODY_32_39(34,C,D,E,T,A,B,X);
349
	BODY_32_39(35,B,C,D,E,T,A,X);
350
	BODY_32_39(36,A,B,C,D,E,T,X);
351
	BODY_32_39(37,T,A,B,C,D,E,X);
352
	BODY_32_39(38,E,T,A,B,C,D,X);
353
	BODY_32_39(39,D,E,T,A,B,C,X);
354
355
	BODY_40_59(40,C,D,E,T,A,B,X);
356
	BODY_40_59(41,B,C,D,E,T,A,X);
357
	BODY_40_59(42,A,B,C,D,E,T,X);
358
	BODY_40_59(43,T,A,B,C,D,E,X);
359
	BODY_40_59(44,E,T,A,B,C,D,X);
360
	BODY_40_59(45,D,E,T,A,B,C,X);
361
	BODY_40_59(46,C,D,E,T,A,B,X);
362
	BODY_40_59(47,B,C,D,E,T,A,X);
363
	BODY_40_59(48,A,B,C,D,E,T,X);
364
	BODY_40_59(49,T,A,B,C,D,E,X);
365
	BODY_40_59(50,E,T,A,B,C,D,X);
366
	BODY_40_59(51,D,E,T,A,B,C,X);
367
	BODY_40_59(52,C,D,E,T,A,B,X);
368
	BODY_40_59(53,B,C,D,E,T,A,X);
369
	BODY_40_59(54,A,B,C,D,E,T,X);
370
	BODY_40_59(55,T,A,B,C,D,E,X);
371
	BODY_40_59(56,E,T,A,B,C,D,X);
372
	BODY_40_59(57,D,E,T,A,B,C,X);
373
	BODY_40_59(58,C,D,E,T,A,B,X);
374
	BODY_40_59(59,B,C,D,E,T,A,X);
375
376
	BODY_60_79(60,A,B,C,D,E,T,X);
377
	BODY_60_79(61,T,A,B,C,D,E,X);
378
	BODY_60_79(62,E,T,A,B,C,D,X);
379
	BODY_60_79(63,D,E,T,A,B,C,X);
380
	BODY_60_79(64,C,D,E,T,A,B,X);
381
	BODY_60_79(65,B,C,D,E,T,A,X);
382
	BODY_60_79(66,A,B,C,D,E,T,X);
383
	BODY_60_79(67,T,A,B,C,D,E,X);
384
	BODY_60_79(68,E,T,A,B,C,D,X);
385
	BODY_60_79(69,D,E,T,A,B,C,X);
386
	BODY_60_79(70,C,D,E,T,A,B,X);
387
	BODY_60_79(71,B,C,D,E,T,A,X);
388
	BODY_60_79(72,A,B,C,D,E,T,X);
389
	BODY_60_79(73,T,A,B,C,D,E,X);
390
	BODY_60_79(74,E,T,A,B,C,D,X);
391
	BODY_60_79(75,D,E,T,A,B,C,X);
392
	BODY_60_79(76,C,D,E,T,A,B,X);
393
	BODY_60_79(77,B,C,D,E,T,A,X);
394
	BODY_60_79(78,A,B,C,D,E,T,X);
395
	BODY_60_79(79,T,A,B,C,D,E,X);
396
	
397
	c->h0=(c->h0+E)&0xffffffffL; 
398
	c->h1=(c->h1+T)&0xffffffffL;
399
	c->h2=(c->h2+A)&0xffffffffL;
400
	c->h3=(c->h3+B)&0xffffffffL;
401
	c->h4=(c->h4+C)&0xffffffffL;
402
403
	num-=64;
404
	if (num <= 0) break;
405
406
	A=c->h0;
407
	B=c->h1;
408
	C=c->h2;
409
	D=c->h3;
410
	E=c->h4;
411
412
	W+=16;
413
		}
414
	}
415
#endif
416
417
void SHA1_Final(md, c)
418
unsigned char *md;
419
SHA_CTX *c;
420
	{
421
	register int i,j;
422
	register unsigned long l;
423
	register unsigned long *p;
424
	static unsigned char end[4]={0x80,0x00,0x00,0x00};
425
	unsigned char *cp=end;
426
427
	/* c->num should definitly have room for at least one more byte. */
428
	p=c->data;
429
	j=c->num;
430
	i=j>>2;
431
#ifdef PURIFY
432
	if ((j&0x03) == 0) p[i]=0;
433
#endif
434
	l=p[i];
435
	M_p_c2nl(cp,l,j&0x03);
436
	p[i]=l;
437
	i++;
438
	/* i is the next 'undefined word' */
439
	if (c->num >= SHA_LAST_BLOCK)
440
		{
441
		for (; i<SHA_LBLOCK; i++)
442
			p[i]=0;
443
		sha1_block(c,p,64);
444
		i=0;
445
		}
446
	for (; i<(SHA_LBLOCK-2); i++)
447
		p[i]=0;
448
	p[SHA_LBLOCK-2]=c->Nh;
449
	p[SHA_LBLOCK-1]=c->Nl;
450
#if defined(L_ENDIAN) && defined(SHA1_ASM)
451
	Endian_Reverse32(p[SHA_LBLOCK-2]);
452
	Endian_Reverse32(p[SHA_LBLOCK-1]);
453
#endif
454
	sha1_block(c,p,64);
455
	cp=md;
456
	l=c->h0; nl2c(l,cp);
457
	l=c->h1; nl2c(l,cp);
458
	l=c->h2; nl2c(l,cp);
459
	l=c->h3; nl2c(l,cp);
460
	l=c->h4; nl2c(l,cp);
461
462
	/* clear stuff, sha1_block may be leaving some stuff on the stack
463
	 * but I'm not worried :-) */
464
	c->num=0;
465
/*	memset((char *)&c,0,sizeof(c));*/
466
	}
467
(-)john-1.7.0.1/src/sha_locl.h (+241 lines)
Line 0 Link Here
1
/* crypto/sha/sha_locl.h */
2
/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
3
 * All rights reserved.
4
 *
5
 * This package is an SSL implementation written
6
 * by Eric Young (eay@cryptsoft.com).
7
 * The implementation was written so as to conform with Netscapes SSL.
8
 * 
9
 * This library is free for commercial and non-commercial use as long as
10
 * the following conditions are aheared to.  The following conditions
11
 * apply to all code found in this distribution, be it the RC4, RSA,
12
 * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
13
 * included with this distribution is covered by the same copyright terms
14
 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15
 * 
16
 * Copyright remains Eric Young's, and as such any Copyright notices in
17
 * the code are not to be removed.
18
 * If this package is used in a product, Eric Young should be given attribution
19
 * as the author of the parts of the library used.
20
 * This can be in the form of a textual message at program startup or
21
 * in documentation (online or textual) provided with the package.
22
 * 
23
 * Redistribution and use in source and binary forms, with or without
24
 * modification, are permitted provided that the following conditions
25
 * are met:
26
 * 1. Redistributions of source code must retain the copyright
27
 *    notice, this list of conditions and the following disclaimer.
28
 * 2. Redistributions in binary form must reproduce the above copyright
29
 *    notice, this list of conditions and the following disclaimer in the
30
 *    documentation and/or other materials provided with the distribution.
31
 * 3. All advertising materials mentioning features or use of this software
32
 *    must display the following acknowledgement:
33
 *    "This product includes cryptographic software written by
34
 *     Eric Young (eay@cryptsoft.com)"
35
 *    The word 'cryptographic' can be left out if the rouines from the library
36
 *    being used are not cryptographic related :-).
37
 * 4. If you include any Windows specific code (or a derivative thereof) from 
38
 *    the apps directory (application code) you must include an acknowledgement:
39
 *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40
 * 
41
 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51
 * SUCH DAMAGE.
52
 * 
53
 * The licence and distribution terms for any publically available version or
54
 * derivative of this code cannot be changed.  i.e. this code cannot simply be
55
 * copied and put under another distribution licence
56
 * [including the GNU Public Licence.]
57
 */
58
59
#include <stdlib.h>
60
#include <string.h>
61
62
#ifdef undef
63
/* one or the other needs to be defined */
64
#ifndef SHA_1 /* FIPE 180-1 */
65
#define SHA_0 /* FIPS 180   */
66
#endif
67
#endif
68
69
#ifdef NOCONST
70
#define const
71
#endif
72
73
#undef c2nl
74
#define c2nl(c,l)	(l =(((unsigned long)(*((c)++)))<<24), \
75
			 l|=(((unsigned long)(*((c)++)))<<16), \
76
			 l|=(((unsigned long)(*((c)++)))<< 8), \
77
			 l|=(((unsigned long)(*((c)++)))    ))
78
79
#undef p_c2nl
80
#define p_c2nl(c,l,n)	{ \
81
			switch (n) { \
82
			case 0: l =((unsigned long)(*((c)++)))<<24; \
83
			case 1: l|=((unsigned long)(*((c)++)))<<16; \
84
			case 2: l|=((unsigned long)(*((c)++)))<< 8; \
85
			case 3: l|=((unsigned long)(*((c)++))); \
86
				} \
87
			}
88
89
#undef c2nl_p
90
/* NOTE the pointer is not incremented at the end of this */
91
#define c2nl_p(c,l,n)	{ \
92
			l=0; \
93
			(c)+=n; \
94
			switch (n) { \
95
			case 3: l =((unsigned long)(*(--(c))))<< 8; \
96
			case 2: l|=((unsigned long)(*(--(c))))<<16; \
97
			case 1: l|=((unsigned long)(*(--(c))))<<24; \
98
				} \
99
			}
100
101
#undef p_c2nl_p
102
#define p_c2nl_p(c,l,sc,len) { \
103
			switch (sc) \
104
				{ \
105
			case 0: l =((unsigned long)(*((c)++)))<<24; \
106
				if (--len == 0) break; \
107
			case 1: l|=((unsigned long)(*((c)++)))<<16; \
108
				if (--len == 0) break; \
109
			case 2: l|=((unsigned long)(*((c)++)))<< 8; \
110
				} \
111
			}
112
113
#undef nl2c
114
#define nl2c(l,c)	(*((c)++)=(unsigned char)(((l)>>24)&0xff), \
115
			 *((c)++)=(unsigned char)(((l)>>16)&0xff), \
116
			 *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
117
			 *((c)++)=(unsigned char)(((l)    )&0xff))
118
119
#undef c2l
120
#define c2l(c,l)	(l =(((unsigned long)(*((c)++)))    ), \
121
			 l|=(((unsigned long)(*((c)++)))<< 8), \
122
			 l|=(((unsigned long)(*((c)++)))<<16), \
123
			 l|=(((unsigned long)(*((c)++)))<<24))
124
125
#undef p_c2l
126
#define p_c2l(c,l,n)	{ \
127
			switch (n) { \
128
			case 0: l =((unsigned long)(*((c)++))); \
129
			case 1: l|=((unsigned long)(*((c)++)))<< 8; \
130
			case 2: l|=((unsigned long)(*((c)++)))<<16; \
131
			case 3: l|=((unsigned long)(*((c)++)))<<24; \
132
				} \
133
			}
134
135
#undef c2l_p
136
/* NOTE the pointer is not incremented at the end of this */
137
#define c2l_p(c,l,n)	{ \
138
			l=0; \
139
			(c)+=n; \
140
			switch (n) { \
141
			case 3: l =((unsigned long)(*(--(c))))<<16; \
142
			case 2: l|=((unsigned long)(*(--(c))))<< 8; \
143
			case 1: l|=((unsigned long)(*(--(c)))); \
144
				} \
145
			}
146
147
#undef p_c2l_p
148
#define p_c2l_p(c,l,sc,len) { \
149
			switch (sc) \
150
				{ \
151
			case 0: l =((unsigned long)(*((c)++))); \
152
				if (--len == 0) break; \
153
			case 1: l|=((unsigned long)(*((c)++)))<< 8; \
154
				if (--len == 0) break; \
155
			case 2: l|=((unsigned long)(*((c)++)))<<16; \
156
				} \
157
			}
158
159
#undef l2c
160
#define l2c(l,c)	(*((c)++)=(unsigned char)(((l)    )&0xff), \
161
			 *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
162
			 *((c)++)=(unsigned char)(((l)>>16)&0xff), \
163
			 *((c)++)=(unsigned char)(((l)>>24)&0xff))
164
165
#undef ROTATE
166
#if defined(WIN32)
167
#define ROTATE(a,n)     _lrotl(a,n)
168
#else
169
#define ROTATE(a,n)     (((a)<<(n))|(((a)&0xffffffff)>>(32-(n))))
170
#endif
171
172
/* A nice byte order reversal from Wei Dai <weidai@eskimo.com> */
173
#if defined(WIN32)
174
/* 5 instructions with rotate instruction, else 9 */
175
#define Endian_Reverse32(a) \
176
	{ \
177
	unsigned long l=(a); \
178
	(a)=((ROTATE(l,8)&0x00FF00FF)|(ROTATE(l,24)&0xFF00FF00)); \
179
	}
180
#else
181
/* 6 instructions with rotate instruction, else 8 */
182
#define Endian_Reverse32(a) \
183
	{ \
184
	unsigned long l=(a); \
185
	l=(((l&0xFF00FF00)>>8L)|((l&0x00FF00FF)<<8L)); \
186
	(a)=ROTATE(l,16L); \
187
	}
188
#endif
189
190
/* As  pointed out by Wei Dai <weidai@eskimo.com>, F() below can be
191
 * simplified to the code in F_00_19.  Wei attributes these optimisations
192
 * to Peter Gutmann's SHS code, and he attributes it to Rich Schroeppel.
193
 * #define F(x,y,z) (((x) & (y))  |  ((~(x)) & (z)))
194
 * I've just become aware of another tweak to be made, again from Wei Dai,
195
 * in F_40_59, (x&a)|(y&a) -> (x|y)&a
196
 */
197
#define	F_00_19(b,c,d)	((((c) ^ (d)) & (b)) ^ (d)) 
198
#define	F_20_39(b,c,d)	((b) ^ (c) ^ (d))
199
#define F_40_59(b,c,d)	(((b) & (c)) | (((b)|(c)) & (d))) 
200
#define	F_60_79(b,c,d)	F_20_39(b,c,d)
201
202
#ifdef SHA_0
203
#undef Xupdate
204
#define Xupdate(a,i,ia,ib,ic,id) X[(i)&0x0f]=(a)=\
205
	(ia[(i)&0x0f]^ib[((i)+2)&0x0f]^ic[((i)+8)&0x0f]^id[((i)+13)&0x0f]);
206
#endif
207
#ifdef SHA_1
208
#undef Xupdate
209
#define Xupdate(a,i,ia,ib,ic,id) (a)=\
210
	(ia[(i)&0x0f]^ib[((i)+2)&0x0f]^ic[((i)+8)&0x0f]^id[((i)+13)&0x0f]);\
211
	X[(i)&0x0f]=(a)=ROTATE((a),1);
212
#endif
213
214
#define BODY_00_15(i,a,b,c,d,e,f,xa) \
215
	(f)=xa[i]+(e)+K_00_19+ROTATE((a),5)+F_00_19((b),(c),(d)); \
216
	(b)=ROTATE((b),30);
217
218
#define BODY_16_19(i,a,b,c,d,e,f,xa,xb,xc,xd) \
219
	Xupdate(f,i,xa,xb,xc,xd); \
220
	(f)+=(e)+K_00_19+ROTATE((a),5)+F_00_19((b),(c),(d)); \
221
	(b)=ROTATE((b),30);
222
223
#define BODY_20_31(i,a,b,c,d,e,f,xa,xb,xc,xd) \
224
	Xupdate(f,i,xa,xb,xc,xd); \
225
	(f)+=(e)+K_20_39+ROTATE((a),5)+F_20_39((b),(c),(d)); \
226
	(b)=ROTATE((b),30);
227
228
#define BODY_32_39(i,a,b,c,d,e,f,xa) \
229
	Xupdate(f,i,xa,xa,xa,xa); \
230
	(f)+=(e)+K_20_39+ROTATE((a),5)+F_20_39((b),(c),(d)); \
231
	(b)=ROTATE((b),30);
232
233
#define BODY_40_59(i,a,b,c,d,e,f,xa) \
234
	Xupdate(f,i,xa,xa,xa,xa); \
235
	(f)+=(e)+K_40_59+ROTATE((a),5)+F_40_59((b),(c),(d)); \
236
	(b)=ROTATE((b),30);
237
238
#define BODY_60_79(i,a,b,c,d,e,f,xa) \
239
	Xupdate(f,i,xa,xa,xa,xa); \
240
	(f)=X[(i)&0x0f]+(e)+K_60_79+ROTATE((a),5)+F_60_79((b),(c),(d)); \
241
	(b)=ROTATE((b),30);
(-)john-1.7.0.1/src/smbencrypt.c (+94 lines)
Line 0 Link Here
1
/* 
2
   Unix SMB/Netbios implementation.
3
   Version 1.9.
4
   SMB parameters and setup
5
   Copyright (C) Andrew Tridgell 1992-1998
6
   Modified by Jeremy Allison 1995.
7
   
8
   This program is free software; you can redistribute it and/or modify
9
   it under the terms of the GNU General Public License as published by
10
   the Free Software Foundation; either version 2 of the License, or
11
   (at your option) any later version.
12
   
13
   This program is distributed in the hope that it will be useful,
14
   but WITHOUT ANY WARRANTY; without even the implied warranty of
15
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
   GNU General Public License for more details.
17
   
18
   You should have received a copy of the GNU General Public License
19
   along with this program; if not, write to the Free Software
20
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21
*/
22
23
24
#include <sys/types.h>
25
#include <string.h>
26
#include "arch.h"
27
28
#ifndef uchar
29
#define uchar unsigned char
30
#endif
31
32
#if !defined(uint16) && !defined(HAVE_UINT16_FROM_RPC_RPC_H)
33
#if (SIZEOF_SHORT == 4)
34
#define uint16 __ERROR___CANNOT_DETERMINE_TYPE_FOR_INT16;
35
#else /* SIZEOF_SHORT != 4 */
36
#define uint16 unsigned short
37
#endif /* SIZEOF_SHORT != 4 */
38
#endif
39
40
#if !defined(int16) && !defined(HAVE_INT16_FROM_RPC_RPC_H)
41
#if (SIZEOF_SHORT == 4)
42
#define int16 __ERROR___CANNOT_DETERMINE_TYPE_FOR_INT16;
43
#else /* SIZEOF_SHORT != 4 */
44
#define int16 short
45
#endif /* SIZEOF_SHORT != 4 */
46
#endif
47
48
#include "byteorder.h"
49
50
extern void mdfour(unsigned char *out, unsigned char *in, int n);
51
52
/*
53
 * Convert a string into an NT UNICODE string.
54
 * Note that regardless of processor type 
55
 * this must be in intel (little-endian)
56
 * format.
57
 */
58
 
59
int _my_mbstowcs(int16 *dst, uchar *src, int len)
60
{
61
	int i;
62
 
63
	for(i = 0; i < len; i++) {
64
#if ARCH_LITTLE_ENDIAN
65
		dst[i] = src[i];
66
#else
67
		dst[i] = src[i] << 8;
68
#endif
69
	}
70
	return i;
71
}
72
73
/* 
74
 * Creates the MD4 Hash of the users password in NT UNICODE.
75
 */
76
 
77
void E_md4hash(uchar *passwd, uchar *p16)
78
{
79
	int len;
80
	int16 wpwd[129];
81
	
82
	/* Password cannot be longer than 128 characters */
83
	len = strlen((char *)passwd);
84
	if(len > 128)
85
		len = 128;
86
	/* Password must be converted to NT unicode */
87
	_my_mbstowcs(wpwd, passwd, len);
88
	wpwd[len] = 0; /* Ensure string is null terminated */
89
	/* Calculate length in bytes */
90
	//len = _my_wcslen(wpwd) * sizeof(int16);
91
92
	mdfour(p16, (unsigned char *)wpwd, len*2);
93
}
94
(-)john-1.7.0.1/src/sparc.S (+3 lines)
Lines 410-412 Link Here
410
.common DES_KS_table, (8 * 128 * 16 * 8), 32
410
.common DES_KS_table, (8 * 128 * 16 * 8), 32
411
411
412
#endif
412
#endif
413
#ifdef __ELF__
414
.section .note.GNU-stack,"",@progbits
415
#endif
(-)john-1.7.0.1/src/stages_mmx_md5.S (+192 lines)
Line 0 Link Here
1
const_stage_1:
2
.long 0xd76aa478
3
.long 0xd76aa478
4
const_stage_2:
5
.long 0xe8c7b756
6
.long 0xe8c7b756
7
const_stage_3:
8
.long 0x242070db
9
.long 0x242070db
10
const_stage_4:
11
.long 0xc1bdceee
12
.long 0xc1bdceee
13
const_stage_5:
14
.long 0xf57c0faf
15
.long 0xf57c0faf
16
const_stage_6:
17
.long 0x4787c62a
18
.long 0x4787c62a
19
const_stage_7:
20
.long 0xa8304613
21
.long 0xa8304613
22
const_stage_8:
23
.long 0xfd469501
24
.long 0xfd469501
25
const_stage_9:
26
.long 0x698098d8
27
.long 0x698098d8
28
const_stage_10:
29
.long 0x8b44f7af
30
.long 0x8b44f7af
31
const_stage_11:
32
.long 0xffff5bb1
33
.long 0xffff5bb1
34
const_stage_12:
35
.long 0x895cd7be
36
.long 0x895cd7be
37
const_stage_13:
38
.long 0x6b901122
39
.long 0x6b901122
40
const_stage_14:
41
.long 0xfd987193
42
.long 0xfd987193
43
const_stage_15:
44
.long 0xa679438e
45
.long 0xa679438e
46
const_stage_16:
47
.long 0x49b40821
48
.long 0x49b40821
49
const_stage_17:
50
.long 0xf61e2562
51
.long 0xf61e2562
52
const_stage_18:
53
.long 0xc040b340
54
.long 0xc040b340
55
const_stage_19:
56
.long 0x265e5a51
57
.long 0x265e5a51
58
const_stage_20:
59
.long 0xe9b6c7aa
60
.long 0xe9b6c7aa
61
const_stage_21:
62
.long 0xd62f105d
63
.long 0xd62f105d
64
const_stage_22:
65
.long 0x02441453
66
.long 0x02441453
67
const_stage_23:
68
.long 0xd8a1e681
69
.long 0xd8a1e681
70
const_stage_24:
71
.long 0xe7d3fbc8
72
.long 0xe7d3fbc8
73
const_stage_25:
74
.long 0x21e1cde6
75
.long 0x21e1cde6
76
const_stage_26:
77
.long 0xc33707d6
78
.long 0xc33707d6
79
const_stage_27:
80
.long 0xf4d50d87
81
.long 0xf4d50d87
82
const_stage_28:
83
.long 0x455a14ed
84
.long 0x455a14ed
85
const_stage_29:
86
.long 0xa9e3e905
87
.long 0xa9e3e905
88
const_stage_30:
89
.long 0xfcefa3f8
90
.long 0xfcefa3f8
91
const_stage_31:
92
.long 0x676f02d9
93
.long 0x676f02d9
94
const_stage_32:
95
.long 0x8d2a4c8a
96
.long 0x8d2a4c8a
97
const_stage_33:
98
.long 0xfffa3942
99
.long 0xfffa3942
100
const_stage_34:
101
.long 0x8771f681
102
.long 0x8771f681
103
const_stage_35:
104
.long 0x6d9d6122
105
.long 0x6d9d6122
106
const_stage_36:
107
.long 0xfde5380c
108
.long 0xfde5380c
109
const_stage_37:
110
.long 0xa4beea44
111
.long 0xa4beea44
112
const_stage_38:
113
.long 0x4bdecfa9
114
.long 0x4bdecfa9
115
const_stage_39:
116
.long 0xf6bb4b60
117
.long 0xf6bb4b60
118
const_stage_40:
119
.long 0xbebfbc70
120
.long 0xbebfbc70
121
const_stage_41:
122
.long 0x289b7ec6
123
.long 0x289b7ec6
124
const_stage_42:
125
.long 0xeaa127fa
126
.long 0xeaa127fa
127
const_stage_43:
128
.long 0xd4ef3085
129
.long 0xd4ef3085
130
const_stage_44:
131
.long 0x04881d05
132
.long 0x04881d05
133
const_stage_45:
134
.long 0xd9d4d039
135
.long 0xd9d4d039
136
const_stage_46:
137
.long 0xe6db99e5
138
.long 0xe6db99e5
139
const_stage_47:
140
.long 0x1fa27cf8
141
.long 0x1fa27cf8
142
const_stage_48:
143
.long 0xc4ac5665
144
.long 0xc4ac5665
145
const_stage_49:
146
.long 0xf4292244
147
.long 0xf4292244
148
const_stage_50:
149
.long 0x432aff97
150
.long 0x432aff97
151
const_stage_51:
152
.long 0xab9423a7
153
.long 0xab9423a7
154
const_stage_52:
155
.long 0xfc93a039
156
.long 0xfc93a039
157
const_stage_53:
158
.long 0x655b59c3
159
.long 0x655b59c3
160
const_stage_54:
161
.long 0x8f0ccc92
162
.long 0x8f0ccc92
163
const_stage_55:
164
.long 0xffeff47d
165
.long 0xffeff47d
166
const_stage_56:
167
.long 0x85845dd1
168
.long 0x85845dd1
169
const_stage_57:
170
.long 0x6fa87e4f
171
.long 0x6fa87e4f
172
const_stage_58:
173
.long 0xfe2ce6e0
174
.long 0xfe2ce6e0
175
const_stage_59:
176
.long 0xa3014314
177
.long 0xa3014314
178
const_stage_60:
179
.long 0x4e0811a1
180
.long 0x4e0811a1
181
const_stage_61:
182
.long 0xf7537e82
183
.long 0xf7537e82
184
const_stage_62:
185
.long 0xbd3af235
186
.long 0xbd3af235
187
const_stage_63:
188
.long 0x2ad7d2bb
189
.long 0x2ad7d2bb
190
const_stage_64:
191
.long 0xeb86d391
192
.long 0xeb86d391
(-)john-1.7.0.1/src/stages_sse2_md5.S (+320 lines)
Line 0 Link Here
1
const_stage_1:
2
.long 0xd76aa478
3
.long 0xd76aa478
4
.long 0xd76aa478
5
.long 0xd76aa478
6
const_stage_2:
7
.long 0xe8c7b756
8
.long 0xe8c7b756
9
.long 0xe8c7b756
10
.long 0xe8c7b756
11
const_stage_3:
12
.long 0x242070db
13
.long 0x242070db
14
.long 0x242070db
15
.long 0x242070db
16
const_stage_4:
17
.long 0xc1bdceee
18
.long 0xc1bdceee
19
.long 0xc1bdceee
20
.long 0xc1bdceee
21
const_stage_5:
22
.long 0xf57c0faf
23
.long 0xf57c0faf
24
.long 0xf57c0faf
25
.long 0xf57c0faf
26
const_stage_6:
27
.long 0x4787c62a
28
.long 0x4787c62a
29
.long 0x4787c62a
30
.long 0x4787c62a
31
const_stage_7:
32
.long 0xa8304613
33
.long 0xa8304613
34
.long 0xa8304613
35
.long 0xa8304613
36
const_stage_8:
37
.long 0xfd469501
38
.long 0xfd469501
39
.long 0xfd469501
40
.long 0xfd469501
41
const_stage_9:
42
.long 0x698098d8
43
.long 0x698098d8
44
.long 0x698098d8
45
.long 0x698098d8
46
const_stage_10:
47
.long 0x8b44f7af
48
.long 0x8b44f7af
49
.long 0x8b44f7af
50
.long 0x8b44f7af
51
const_stage_11:
52
.long 0xffff5bb1
53
.long 0xffff5bb1
54
.long 0xffff5bb1
55
.long 0xffff5bb1
56
const_stage_12:
57
.long 0x895cd7be
58
.long 0x895cd7be
59
.long 0x895cd7be
60
.long 0x895cd7be
61
const_stage_13:
62
.long 0x6b901122
63
.long 0x6b901122
64
.long 0x6b901122
65
.long 0x6b901122
66
const_stage_14:
67
.long 0xfd987193
68
.long 0xfd987193
69
.long 0xfd987193
70
.long 0xfd987193
71
const_stage_15:
72
.long 0xa679438e
73
.long 0xa679438e
74
.long 0xa679438e
75
.long 0xa679438e
76
const_stage_16:
77
.long 0x49b40821
78
.long 0x49b40821
79
.long 0x49b40821
80
.long 0x49b40821
81
const_stage_17:
82
.long 0xf61e2562
83
.long 0xf61e2562
84
.long 0xf61e2562
85
.long 0xf61e2562
86
const_stage_18:
87
.long 0xc040b340
88
.long 0xc040b340
89
.long 0xc040b340
90
.long 0xc040b340
91
const_stage_19:
92
.long 0x265e5a51
93
.long 0x265e5a51
94
.long 0x265e5a51
95
.long 0x265e5a51
96
const_stage_20:
97
.long 0xe9b6c7aa
98
.long 0xe9b6c7aa
99
.long 0xe9b6c7aa
100
.long 0xe9b6c7aa
101
const_stage_21:
102
.long 0xd62f105d
103
.long 0xd62f105d
104
.long 0xd62f105d
105
.long 0xd62f105d
106
const_stage_22:
107
.long 0x02441453
108
.long 0x02441453
109
.long 0x02441453
110
.long 0x02441453
111
const_stage_23:
112
.long 0xd8a1e681
113
.long 0xd8a1e681
114
.long 0xd8a1e681
115
.long 0xd8a1e681
116
const_stage_24:
117
.long 0xe7d3fbc8
118
.long 0xe7d3fbc8
119
.long 0xe7d3fbc8
120
.long 0xe7d3fbc8
121
const_stage_25:
122
.long 0x21e1cde6
123
.long 0x21e1cde6
124
.long 0x21e1cde6
125
.long 0x21e1cde6
126
const_stage_26:
127
.long 0xc33707d6
128
.long 0xc33707d6
129
.long 0xc33707d6
130
.long 0xc33707d6
131
const_stage_27:
132
.long 0xf4d50d87
133
.long 0xf4d50d87
134
.long 0xf4d50d87
135
.long 0xf4d50d87
136
const_stage_28:
137
.long 0x455a14ed
138
.long 0x455a14ed
139
.long 0x455a14ed
140
.long 0x455a14ed
141
const_stage_29:
142
.long 0xa9e3e905
143
.long 0xa9e3e905
144
.long 0xa9e3e905
145
.long 0xa9e3e905
146
const_stage_30:
147
.long 0xfcefa3f8
148
.long 0xfcefa3f8
149
.long 0xfcefa3f8
150
.long 0xfcefa3f8
151
const_stage_31:
152
.long 0x676f02d9
153
.long 0x676f02d9
154
.long 0x676f02d9
155
.long 0x676f02d9
156
const_stage_32:
157
.long 0x8d2a4c8a
158
.long 0x8d2a4c8a
159
.long 0x8d2a4c8a
160
.long 0x8d2a4c8a
161
const_stage_33:
162
.long 0xfffa3942
163
.long 0xfffa3942
164
.long 0xfffa3942
165
.long 0xfffa3942
166
const_stage_34:
167
.long 0x8771f681
168
.long 0x8771f681
169
.long 0x8771f681
170
.long 0x8771f681
171
const_stage_35:
172
.long 0x6d9d6122
173
.long 0x6d9d6122
174
.long 0x6d9d6122
175
.long 0x6d9d6122
176
const_stage_36:
177
.long 0xfde5380c
178
.long 0xfde5380c
179
.long 0xfde5380c
180
.long 0xfde5380c
181
const_stage_37:
182
.long 0xa4beea44
183
.long 0xa4beea44
184
.long 0xa4beea44
185
.long 0xa4beea44
186
const_stage_38:
187
.long 0x4bdecfa9
188
.long 0x4bdecfa9
189
.long 0x4bdecfa9
190
.long 0x4bdecfa9
191
const_stage_39:
192
.long 0xf6bb4b60
193
.long 0xf6bb4b60
194
.long 0xf6bb4b60
195
.long 0xf6bb4b60
196
const_stage_40:
197
.long 0xbebfbc70
198
.long 0xbebfbc70
199
.long 0xbebfbc70
200
.long 0xbebfbc70
201
const_stage_41:
202
.long 0x289b7ec6
203
.long 0x289b7ec6
204
.long 0x289b7ec6
205
.long 0x289b7ec6
206
const_stage_42:
207
.long 0xeaa127fa
208
.long 0xeaa127fa
209
.long 0xeaa127fa
210
.long 0xeaa127fa
211
const_stage_43:
212
.long 0xd4ef3085
213
.long 0xd4ef3085
214
.long 0xd4ef3085
215
.long 0xd4ef3085
216
const_stage_44:
217
.long 0x04881d05
218
.long 0x04881d05
219
.long 0x04881d05
220
.long 0x04881d05
221
const_stage_45:
222
.long 0xd9d4d039
223
.long 0xd9d4d039
224
.long 0xd9d4d039
225
.long 0xd9d4d039
226
const_stage_46:
227
.long 0xe6db99e5
228
.long 0xe6db99e5
229
.long 0xe6db99e5
230
.long 0xe6db99e5
231
const_stage_47:
232
.long 0x1fa27cf8
233
.long 0x1fa27cf8
234
.long 0x1fa27cf8
235
.long 0x1fa27cf8
236
const_stage_48:
237
.long 0xc4ac5665
238
.long 0xc4ac5665
239
.long 0xc4ac5665
240
.long 0xc4ac5665
241
const_stage_49:
242
.long 0xf4292244
243
.long 0xf4292244
244
.long 0xf4292244
245
.long 0xf4292244
246
const_stage_50:
247
.long 0x432aff97
248
.long 0x432aff97
249
.long 0x432aff97
250
.long 0x432aff97
251
const_stage_51:
252
.long 0xab9423a7
253
.long 0xab9423a7
254
.long 0xab9423a7
255
.long 0xab9423a7
256
const_stage_52:
257
.long 0xfc93a039
258
.long 0xfc93a039
259
.long 0xfc93a039
260
.long 0xfc93a039
261
const_stage_53:
262
.long 0x655b59c3
263
.long 0x655b59c3
264
.long 0x655b59c3
265
.long 0x655b59c3
266
const_stage_54:
267
.long 0x8f0ccc92
268
.long 0x8f0ccc92
269
.long 0x8f0ccc92
270
.long 0x8f0ccc92
271
const_stage_55:
272
.long 0xffeff47d
273
.long 0xffeff47d
274
.long 0xffeff47d
275
.long 0xffeff47d
276
const_stage_56:
277
.long 0x85845dd1
278
.long 0x85845dd1
279
.long 0x85845dd1
280
.long 0x85845dd1
281
const_stage_57:
282
.long 0x6fa87e4f
283
.long 0x6fa87e4f
284
.long 0x6fa87e4f
285
.long 0x6fa87e4f
286
const_stage_58:
287
.long 0xfe2ce6e0
288
.long 0xfe2ce6e0
289
.long 0xfe2ce6e0
290
.long 0xfe2ce6e0
291
const_stage_59:
292
.long 0xa3014314
293
.long 0xa3014314
294
.long 0xa3014314
295
.long 0xa3014314
296
const_stage_60:
297
.long 0x4e0811a1
298
.long 0x4e0811a1
299
.long 0x4e0811a1
300
.long 0x4e0811a1
301
const_stage_61:
302
.long 0xf7537e82
303
.long 0xf7537e82
304
.long 0xf7537e82
305
.long 0xf7537e82
306
const_stage_62:
307
.long 0xbd3af235
308
.long 0xbd3af235
309
.long 0xbd3af235
310
.long 0xbd3af235
311
const_stage_63:
312
.long 0x2ad7d2bb
313
.long 0x2ad7d2bb
314
.long 0x2ad7d2bb
315
.long 0x2ad7d2bb
316
const_stage_64:
317
.long 0xeb86d391
318
.long 0xeb86d391
319
.long 0xeb86d391
320
.long 0xeb86d391
(-)john-1.7.0.1/src/undrop.c (+73 lines)
Line 0 Link Here
1
/*	
2
 * Eggdrop userfile converter
3
 * Copyright (c) 2002 by Sun-Zero <sun-zero@freemail.hu>
4
 * This is a free software distributable under terms of the GNU GPL. 
5
 * See the file COPYING for details. 
6
 *
7
 * 2003-04-21
8
*/
9
10
#include <stdio.h>
11
#include <string.h>
12
#include <unistd.h>
13
14
15
#define USERFILE_HEADER "#4v:"
16
#define USERNAME_LENGTH 11
17
#define PASSWORD_LENGTH 13
18
#define MAX_FLAGS_LENGTH 32
19
#define BUFSIZE 512
20
21
int undrop(int argc, char *argv[]) {
22
23
    FILE *userfile;
24
    char username[USERNAME_LENGTH];
25
    char password[PASSWORD_LENGTH];
26
    char flags[MAX_FLAGS_LENGTH];
27
    char t_username[BUFSIZE];
28
    char t_flags[BUFSIZE];
29
    char t_line[BUFSIZE];
30
31
    if (argc != 2) {
32
	userfile = stdin;
33
	printf("# userfile reading from stdin\n");
34
    } else {
35
        if ((userfile = fopen(argv[1], "rt")) == NULL) {
36
    	        fprintf(stderr, "opening userfile\n");
37
	        userfile = stdin;
38
        }
39
    }
40
    
41
    
42
    if (fgets(t_line, sizeof(t_line) - 1, userfile) == NULL) 
43
	return 1;
44
45
    if (strncmp(t_line, USERFILE_HEADER, strlen(USERFILE_HEADER)) != 0) { 
46
	fprintf(stderr, "usefile format is wrong\n"); 
47
	return 1;
48
    } else {
49
	printf("# userfile format OK\n\n");
50
    }
51
    
52
    while (fgets(t_line, sizeof(t_line) - 1, userfile) != NULL) {
53
	if (sscanf(t_line, "%10s - %24s\n", t_username, t_flags)  == 2) {
54
	    if (strncmp(t_username, "! ", 2) != 0 &&
55
		strncmp(t_username, "--", 2) != 0 &&
56
		strncmp(t_username, "&&", 2) != 0 &&
57
		strncmp(t_username, "::", 2) != 0 &&
58
		strncmp(t_username, "$$", 2) != 0
59
	    ) {
60
		strncpy(username, t_username, USERNAME_LENGTH);
61
	        strncpy(flags, t_flags, MAX_FLAGS_LENGTH);
62
	    }
63
	}
64
65
	if (strncmp(t_line, "--PASS +", 8) == 0) {
66
	    sscanf(t_line, "--PASS %s", password);
67
	    printf("%s:%s:::%s:\n", username, password, flags);
68
	}
69
	fflush(stdout);
70
    }
71
    fclose(userfile);
72
    return 0;
73
}
(-)john-1.7.0.1/src/x86-mmx.S (-1 / +4 lines)
Lines 2-8 Link Here
2
 * This file is part of John the Ripper password cracker,
2
 * This file is part of John the Ripper password cracker,
3
 * Copyright (c) 2000-2001,2005 by Solar Designer and others:
3
 * Copyright (c) 2000-2001,2005 by Solar Designer and others:
4
 *
4
 *
5
 * The MMX DES S-box code is by Bruce Ford and Rémi Guyomarch, originally
5
 * The MMX DES S-box code is by Bruce Ford and R�i Guyomarch, originally
6
 * for use in the distributed.net clients, included here with permission.
6
 * for use in the distributed.net clients, included here with permission.
7
 * Only minor modifications have been made to their S-box code. Optimized
7
 * Only minor modifications have been made to their S-box code. Optimized
8
 * S-box expressions are based on work by Matthew Kwan (see nonstd.c).
8
 * S-box expressions are based on work by Matthew Kwan (see nonstd.c).
Lines 1309-1311 Link Here
1309
	emms
1309
	emms
1310
#endif
1310
#endif
1311
	ret
1311
	ret
1312
#ifdef __ELF__
1313
.section .note.GNU-stack,"",@progbits
1314
#endif
(-)john-1.7.0.1/src/x86-mmx.h (+3 lines)
Lines 58-61 Link Here
58
#define BF_ASM				1
58
#define BF_ASM				1
59
#define BF_SCALE			1
59
#define BF_SCALE			1
60
60
61
#define MMX_COEF			2
62
#define MMX_TYPE			"(MMX 2x)"
63
61
#endif
64
#endif
(-)john-1.7.0.1/src/x86-sse2.h (+64 lines)
Line 0 Link Here
1
/*
2
 * This file is part of John the Ripper password cracker,
3
 * Copyright (c) 1996-2002 by Solar Designer
4
 */
5
6
/*
7
 * Architecture specific parameters for x86 with MMX.
8
 */
9
10
#ifndef _JOHN_ARCH_H
11
#define _JOHN_ARCH_H
12
13
#define ARCH_WORD			long
14
#define ARCH_SIZE			4
15
#define ARCH_BITS			32
16
#define ARCH_BITS_LOG			5
17
#define ARCH_BITS_STR			"32"
18
#define ARCH_LITTLE_ENDIAN		1
19
#define ARCH_INT_GT_32			0
20
#define ARCH_ALLOWS_UNALIGNED		1
21
#define ARCH_INDEX(x)			((unsigned int)(unsigned char)(x))
22
23
#if defined(__CYGWIN32__) || defined(__BEOS__)
24
#define OS_TIMER			0
25
#else
26
#define OS_TIMER			1
27
#endif
28
#define OS_FLOCK			1
29
30
#define CPU_DETECT			1
31
#define CPU_REQ				1
32
#define CPU_NAME			"MMX"
33
#ifndef CPU_FALLBACK
34
#define CPU_FALLBACK			0
35
#endif
36
#if CPU_FALLBACK
37
#define CPU_FALLBACK_BINARY		"john-non-mmx"
38
#endif
39
40
#define DES_ASM				1
41
#define DES_128K			0
42
#define DES_X2				1
43
#define DES_MASK			1
44
#define DES_SCALE			0
45
#define DES_EXTB			0
46
#define DES_COPY			1
47
#define DES_STD_ALGORITHM_NAME		"48/64 4K MMX"
48
#define DES_BS_ASM			1
49
#define DES_BS				1
50
#define DES_BS_VECTOR			2
51
#define DES_BS_EXPAND			1
52
#define DES_BS_ALGORITHM_NAME		"64/64 BS MMX"
53
54
#define MD5_ASM				1
55
#define MD5_X2				0
56
#define MD5_IMM				1
57
58
#define BF_ASM				1
59
#define BF_SCALE			1
60
61
#define MMX_COEF			4
62
#define MMX_TYPE			" (SSE2 4x)"
63
64
#endif
(-)john-1.7.0.1/src/x86.S (+3 lines)
Lines 1355-1357 Link Here
1355
CPU_detect_ret:
1355
CPU_detect_ret:
1356
	popl %ebx
1356
	popl %ebx
1357
	ret
1357
	ret
1358
#ifdef __ELF__
1359
.section .note.GNU-stack,"",@progbits
1360
#endif

Return to bug 122435