]> git.pld-linux.org Git - packages/john.git/blob - john-1.6.34.patch
- updated to 1.6.37
[packages/john.git] / john-1.6.34.patch
1 diff -ruN john-1.6/doc/CHANGES john-1.6.34/doc/CHANGES
2 --- john-1.6/doc/CHANGES        1970-01-01 01:00:00.000000000 +0100
3 +++ john-1.6.34/doc/CHANGES     2003-01-24 04:55:37.000000000 +0100
4 @@ -0,0 +1,16 @@
5 +The following major changes have been done since John 1.6:
6 +
7 +* Two MD5 hashes at a time for extra ILP on RISC: up to +80% on Alpha EV5.
8 +* Significant improvements to the generic bitslice DES code: +20% on RISC.
9 +* Bitslice DES code for x86 with MMX: more than twice faster on Intel MMX.
10 +* Bitsliced the LM hash code as well: now several times faster.
11 +* Generic Blowfish x86 assembly code in addition to the original Pentium
12 +version: +15% on the Pentium Pro family (up to Pentium III), +20% on AMD.
13 +* First attempt at vectorization support for bitslice DES.
14 +* Better idle priority emulation with POSIX.1b (POSIX.4) scheduling calls.
15 +* System-wide installation support for *BSD ports and Linux distributions.
16 +* AIX, DU / Tru64 C2, HP-UX tcb files support in 'unshadow'.
17 +* New make targets for Linux/PowerPC, FreeBSD/Alpha, SCO, OpenBSD/SPARC,
18 +OpenBSD/VAX, NetBSD/VAX, Solaris/SPARC64, MacOS X, BeOS.
19 +* Bug and portability fixes, and new bugs.
20 +* Bonus: "Strip" cracker included in the default john.conf (john.ini).
21 diff -ruN john-1.6/doc/LICENSING john-1.6.34/doc/LICENSING
22 --- john-1.6/doc/LICENSING      1970-01-01 01:00:00.000000000 +0100
23 +++ john-1.6.34/doc/LICENSING   2002-05-08 20:05:53.000000000 +0200
24 @@ -0,0 +1,13 @@
25 +John the Ripper 1.7, when released, is going to be GPL'ed.  However,
26 +the licensing status of one source file -- x86-mmx.S -- is non-obvious
27 +to me.  I have explicit permission to use the S-box code found in this
28 +file in John, but I'm not sure whether this was meant to imply that I
29 +am free to put this code under a license of my choice.  I haven't got
30 +a reply regarding this so far.
31 +
32 +Portions of this code I've placed into the public domain as a separate
33 +package designed to provide modern password hashing for your software
34 +and your servers (where the GPL restrictions could be a problem).  The
35 +package can be found at:
36 +
37 +       http://www.openwall.com/crypt/
38 diff -ruN john-1.6/run/john.conf john-1.6.34/run/john.conf
39 --- john-1.6/run/john.conf      1970-01-01 01:00:00.000000000 +0100
40 +++ john-1.6.34/run/john.conf   2002-05-10 20:16:35.000000000 +0200
41 @@ -0,0 +1,576 @@
42 +#
43 +# This file is part of John the Ripper password cracker,
44 +# Copyright (c) 1996-2002 by Solar Designer
45 +#
46 +
47 +[Options]
48 +# Wordlist file name, to be used in batch mode
49 +Wordfile = $JOHN/password.lst
50 +# Use idle cycles only
51 +Idle = N
52 +# Crash recovery file saving delay in seconds
53 +Save = 600
54 +# Beep when a password is found (who needs this anyway?)
55 +Beep = N
56 +
57 +# "Single crack" mode rules
58 +[List.Rules:Single]
59 +# Simple rules come first...
60 +:
61 +-s x**
62 +-c (?acQ
63 +-c lQ
64 +-s-c x**MlQ
65 +# These were not included in crackers I've seen, but are pretty efficient,
66 +# so I include them near the beginning
67 +>6'6
68 +>7l'7
69 +>6/?ul'6
70 +>5'5
71 +# Weird order, eh? Can't do anything about it, the order is based on the
72 +# number of successful cracks...
73 +<*d
74 +rc
75 +<*dMcQ
76 +>5/?ul'5
77 +uQ
78 +r(?al
79 +<*!?A[lc]p
80 +<*cQd
81 +>7/?u'7
82 +>4l'4
83 +<+(?lcr
84 +<+r(?lcr
85 +>3'3
86 +>4/?u'4
87 +>3/?ul'3
88 +uQr
89 +<*lQf
90 +# About 50% of single-mode-crackable passwords get cracked by now...
91 +>2x12
92 +>3x13
93 +>4x14
94 +>5x15
95 +>6x16
96 +>7x17
97 +>8x18
98 +>3x22
99 +>4x23
100 +>5x24
101 +>6x25
102 +>7x26
103 +>8x27
104 +>9x28
105 +>4x32
106 +>5x33
107 +>6x34
108 +>7x35
109 +>8x36
110 +>9x37
111 +>2/?ulx12
112 +>3/?ulx13
113 +>4/?ulx14
114 +>5/?ulx15
115 +>6/?ulx16
116 +>7/?ulx17
117 +>8/?ulx18
118 +>3/?ulx22
119 +>4/?ulx23
120 +>5/?ulx24
121 +>6/?ulx25
122 +>7/?ulx26
123 +>8/?ulx27
124 +>9/?ulx28
125 +>4/?ulx32
126 +>5/?ulx33
127 +>6/?ulx34
128 +>7/?ulx35
129 +>8/?ulx36
130 +>9/?ulx37
131 +# Now to the suffix stuff...
132 +<*l$[1-9!0a-z"-/:-@\[-`{-~]
133 +<*(?ac$[1-9!0a-z"-/:-@\[-`{-~]
134 +<*lr$[1-9!]
135 +<*/?au$[1-9!]
136 +<-l$!$!
137 +<-(?ac$!$!
138 +l$!<-$!$!
139 +(?ac$!<-$!$!
140 +# Removing vowels...
141 +/?v@?v>2l
142 +/?v@?v>2(?ac
143 +/?v@?v>2<*d
144 +# crack -> cracked, crack -> cracking
145 +<*l[PI]
146 +<*l[PI](?ac
147 +# mary -> marie
148 +<*(?a[lc])yro0ir$e
149 +# marie -> mary
150 +<*(?a[lc])er=1iD0o0yr
151 +# The following 3l33t rules are based on original Crack's dicts.rules
152 +l/asa4[:c]
153 +l/ese3[:c]
154 +l/lsl1[:c]
155 +l/oso0[:c]
156 +l/sss$[:c]
157 +l/asa4/ese3[:c]
158 +l/asa4/lsl1[:c]
159 +l/asa4/oso0[:c]
160 +l/asa4/sss$[:c]
161 +l/ese3/lsl1[:c]
162 +l/ese3/oso0[:c]
163 +l/ese3/sss$[:c]
164 +l/lsl1/oso0[:c]
165 +l/lsl1/sss$[:c]
166 +l/oso0/sss$[:c]
167 +l/asa4/ese3/lsl1[:c]
168 +l/asa4/ese3/oso0[:c]
169 +l/asa4/ese3/sss$[:c]
170 +l/asa4/lsl1/oso0[:c]
171 +l/asa4/lsl1/sss$[:c]
172 +l/asa4/oso0/sss$[:c]
173 +l/ese3/lsl1/oso0[:c]
174 +l/ese3/lsl1/sss$[:c]
175 +l/ese3/oso0/sss$[:c]
176 +l/lsl1/oso0/sss$[:c]
177 +l/asa4/ese3/lsl1/oso0[:c]
178 +l/asa4/ese3/lsl1/sss$[:c]
179 +l/asa4/ese3/oso0/sss$[:c]
180 +l/asa4/lsl1/oso0/sss$[:c]
181 +l/ese3/lsl1/oso0/sss$[:c]
182 +l/asa4/ese3/lsl1/oso0/sss$[:c]
183 +# Now to the prefix stuff...
184 +l^[1a-z2-90]
185 +lQ^[A-Z]
186 +^[A-Z]
187 +l^["-/:-@\[-`{-~]
188 +<9(?a[lc]^e^h^[tT]
189 +<9(?a[lc]^y^m^[aA]
190 +<9(?a[lc]^r^[mdMD]
191 +<9(?a[lc]^.^r^[mdMD]
192 +<9(?a[lc]^_^_
193 +<-!?Alp^[240-9]
194 +# Some word pair rules...
195 +# johnsmith -> JohnSmith, johnSmith
196 +(?a2(?ac1[cl]
197 +# JohnSmith -> john smith, john_smith, john-smith
198 +1<-$[ _\-]+l
199 +# JohnSmith -> John smith, John_smith, John-smith
200 +1<-(?ac$[ _\-]2l
201 +# JohnSmith -> john Smith, john_Smith, john-Smith
202 +1<-l$[ _\-]2(?ac
203 +# johnsmith -> John Smith, John_Smith, John-Smith
204 +1<-(?ac$[ _\-]2(?ac
205 +# Applying different simple rules to each of the two words
206 +1[ur]2l
207 +2(?ac1[ur]
208 +1l2[ur]
209 +1(?ac2[ur]
210 +# jsmith -> smithj, etc...
211 +(?a[lc][{}]
212 +(?a[lc]}}
213 +(?a[lc]{{
214 +# Toggle case...
215 +T[1-7]Q
216 +lMT[1-7]Q
217 +>2[lu]MT0T2T4T6T8Q
218 +# Deleting chars...
219 +D[1-7]Q
220 +D[1-7]Q/?ul
221 +D[1-7]Q(?ac
222 +# Inserting a dot...
223 +>3(?a[lc]i[12].
224 +# More suffix stuff...
225 +<-l$[190]$[0-9]
226 +<-(?ac$[190]$[0-9]
227 +<-l$[782]$[0-9]
228 +<-(?ac$[782]$[0-9]
229 +<*(?a[lc]$[A-Z]
230 +# cracking -> CRACKiNG
231 +u/IsIi
232 +# Crack96 -> cRACK96
233 +CQ
234 +# Crack96 -> cRACK(^
235 +SQ
236 +# Crack96 -> CRaCK96
237 +/?vVQ
238 +# Really weird charset conversions, like "england" -> "rmh;smf"
239 +:[RL]Q
240 +lQ[RL]
241 +(?acQ[RL]
242 +RRQ
243 +LLQ
244 +# Both prefixing and suffixing...
245 +<-l^1$1
246 +<-l^!$!
247 +<-l^@$@
248 +<-l^#$#
249 +<-l^$$$
250 +<-l^%$%
251 +<-l^^$^
252 +<-l^&$&
253 +<-l^*$*
254 +<-l^($)
255 +<-l^-$-
256 +<-l^=$=
257 +<-l^_$_
258 +<-l^+$+
259 +<-l^.$.
260 +<-l^?$?
261 +<-l^{$}
262 +<-l^\[$]
263 +<-l^<$>
264 +<-l^|$|
265 +<-l^:$:
266 +<-l^'$'
267 +<-l^"$"
268 +# The rest of two-digit suffix stuff, less common numbers...
269 +<-l$[63-5]$[0-9]
270 +<-(?ac$[63-5]$[0-9]
271 +# Some three-digit numbers...
272 +(?a[lc]$0<-$0$7
273 +(?a[lc]$1<-$1$1
274 +(?a[lc]$1<-$2$3
275 +(?a[lc]$2<-$2$2
276 +(?a[lc]$3<-$3$3
277 +(?a[lc]$4<-$4$4
278 +(?a[lc]$5<-$5$5
279 +(?a[lc]$6<-$6$6
280 +(?a[lc]$7<-$7$7
281 +(?a[lc]$8<-$8$8
282 +(?a[lc]$9<-$9$9
283 +# Some [birth] years...
284 +l$1<-$9$[7-96-0]>-
285 +l$2<-$0$0>-
286 +l$1$9<-$[7-9]$[0-9]
287 +l$2$0<-$0$[0-9]
288 +l$1$9<-$[6-0]$[9-0]
289 +# Uncomment the following lines if you're really crazy
290 +;# Insert/overstrike some characters...
291 +;!?Ali[1-6][a-z]
292 +;!?Alo[0-7][a-z]
293 +;# Toggle case everywhere...
294 +;lMT[*7]T[*6]T[*5]T[*4]T[*3]T[*2]T[*1]T[*0]Q
295 +;# Very slow stuff...
296 +;l$[1-90]<-$[0-9]$[0-9]
297 +;(?ac$[1-90]<-$[0-9]$[0-9]
298 +;<-l$[a-z]$[a-z]
299 +;<9l^[a-z]^[a-z]
300 +;<-l^[a-z]$[a-z]
301 +
302 +# Wordlist mode rules
303 +[List.Rules:Wordlist]
304 +# Try words as they are
305 +:
306 +# Lowercase every pure alphanumeric word
307 +-c >3!?XlQ
308 +# Capitalize every pure alphanumeric word
309 +-c >2(?a!?XcQ
310 +# Lowercase and pluralize pure alphabetic words
311 +<*>2!?Alp
312 +# Lowercase pure alphabetic words and append '1'
313 +<*>2!?Al$1
314 +# Capitalize pure alphabetic words and append '1'
315 +-c <*>2!?Ac$1
316 +# Duplicate reasonably short pure alphabetic words (fred -> fredfred)
317 +<7>1!?Ald
318 +# Lowercase and reverse pure alphabetic words
319 +>3!?AlMrQ
320 +# Prefix pure alphabetic words with '1'
321 +>2!?Al^1
322 +# Uppercase pure alphanumeric words
323 +-c >2!?XuQ
324 +# Lowercase pure alphabetic words and append a digit or simple punctuation
325 +<*>2!?Al$[2!37954860.?]
326 +# Words containing punctuation, which is then squeezed out, lowercase
327 +/?p@?p>3l
328 +# Words with vowels removed, lowercase
329 +/?v@?v>3l
330 +# Words containing whitespace, which is then squeezed out, lowercase
331 +/?w@?w>3l
332 +# Capitalize and duplicate short pure alphabetic words (fred -> FredFred)
333 +-c <7>1!?Acd
334 +# Capitalize and reverse pure alphabetic words (fred -> derF)
335 +-c <+>2!?Acr
336 +# Reverse and capitalize pure alphabetic words (fred -> Derf)
337 +-c >2!?AMrQc
338 +# Lowercase and reflect pure alphabetic words (fred -> fredderf)
339 +<7>1!?AlMrQrf
340 +# Uppercase the last letter of pure alphabetic words (fred -> freD)
341 +-c <+>2!?AMrQcr
342 +# Prefix pure alphabetic words with '2' or '4'
343 +>2!?Al^[24]
344 +# Capitalize pure alphabetic words and append a digit or simple punctuation
345 +-c <*>2!?Ac$[2!3957468.?0]
346 +# Prefix pure alphabetic words with digits
347 +>2!?Al^[379568]
348 +# Capitalize and pluralize pure alphabetic words of reasonable length
349 +-c <*>2!?Acp
350 +# Lowercase/capitalize pure alphabetic words of reasonable length and convert:
351 +# crack -> cracked, crack -> cracking
352 +<*>2!?Al[PI]
353 +-c <*>2!?Ac[PI]
354 +# Try the second half of split passwords
355 +-s x**
356 +-s-c x**MlQ
357 +
358 +# Incremental modes
359 +[Incremental:All]
360 +File = $JOHN/all.chr
361 +MinLen = 0
362 +MaxLen = 8
363 +CharCount = 95
364 +
365 +[Incremental:Alpha]
366 +File = $JOHN/alpha.chr
367 +MinLen = 1
368 +MaxLen = 8
369 +CharCount = 26
370 +
371 +[Incremental:Digits]
372 +File = $JOHN/digits.chr
373 +MinLen = 1
374 +MaxLen = 8
375 +CharCount = 10
376 +
377 +[Incremental:LanMan]
378 +File = $JOHN/lanman.chr
379 +MinLen = 0
380 +MaxLen = 7
381 +CharCount = 69
382 +
383 +# Some pre-defined word filters
384 +[List.External:Filter_Alpha]
385 +void filter()
386 +{
387 +       int i, c;
388 +
389 +       i = 0;
390 +       while (c = word[i++])
391 +       if (c < 'a' || c > 'z') {
392 +               word = 0; return;
393 +       }
394 +}
395 +
396 +[List.External:Filter_Digits]
397 +void filter()
398 +{
399 +       int i, c;
400 +
401 +       i = 0;
402 +       while (c = word[i++])
403 +       if (c < '0' || c > '9') {
404 +               word = 0; return;
405 +       }
406 +}
407 +
408 +[List.External:Filter_LanMan]
409 +void filter()
410 +{
411 +       int i, c;
412 +
413 +       word[7] = 0;                    // Truncate at 7 characters
414 +
415 +       i = 0;                          // Convert to uppercase
416 +       while (c = word[i]) {
417 +               if (c >= 'a' && c <= 'z') word[i] &= 0xDF;
418 +               i++;
419 +       }
420 +}
421 +
422 +# A simple cracker for LM hashes
423 +[List.External:LanMan]
424 +int length;                            // Current length
425 +
426 +void init()
427 +{
428 +       word[0] = 'A' - 1;              // Start with "A"
429 +       word[length = 1] = 0;
430 +}
431 +
432 +void generate()
433 +{
434 +       int i;
435 +
436 +       i = length - 1;                 // Start from the last character
437 +       while (++word[i] > 'Z')         // Try to increase it
438 +       if (i)                          // Overflow here, any more positions?
439 +               word[i--] = 'A';        // Yes, move to the left, and repeat
440 +       else                            // No
441 +       if (length < 7) {
442 +               word[i = ++length] = 0; // Switch to the next length
443 +               while (i--)
444 +                       word[i] = 'A';
445 +               return;
446 +       } else {
447 +               word = 0; return;       // We're done
448 +       }
449 +}
450 +
451 +void restore()
452 +{
453 +       length = 0;                     // Calculate the length
454 +       while (word[length]) length++;
455 +}
456 +
457 +# Strip 0.5 ("Secure Tool for Recalling Important Passwords") cracker,
458 +# based on analysis done by Thomas Roessler and Ian Goldberg. This will
459 +# crack passwords you may have generated with Strip, other uses of Strip
460 +# are unaffected.
461 +# See http://www.zetetic.net/products.html for information on Strip.
462 +[List.External:Strip]
463 +int minlength, maxlength, mintype, maxtype;
464 +int crack_seed, length, type;
465 +int count, charset[128];
466 +
467 +void init()
468 +{
469 +       int c;
470 +
471 +/* Password lengths to try; Strip can generate passwords of 4 to 16
472 + * characters, but traditional crypt(3) hashes are limited to 8. */
473 +       minlength = 8;  // 4
474 +       maxlength = 8;  // 16
475 +
476 +/* Password types to try (Numeric, Alpha-Num, Alpha-Num w/ Meta). */
477 +       mintype = 1;    // 0
478 +       maxtype = 1;    // 2
479 +
480 +       crack_seed = 0x10000;
481 +       length = minlength - 1;
482 +       type = mintype;
483 +
484 +       count = 0;
485 +       c = '0'; while (c <= '9') charset[count++] = c++;
486 +}
487 +
488 +void generate()
489 +{
490 +       int seed, random;
491 +       int i, c;
492 +
493 +       if (crack_seed > 0xffff) {
494 +               crack_seed = 0;
495 +
496 +               if (++length > maxlength) {
497 +                       length = minlength;
498 +
499 +                       if (++type > maxtype) {
500 +                               word[0] = 0;
501 +                               return;
502 +                       }
503 +               }
504 +
505 +               count = 10;
506 +               if (type >= 1) {
507 +                       c = 'a'; while (c <= 'f') charset[count++] = c++;
508 +                       c = 'h'; while (c <= 'z') charset[count++] = c++;
509 +                       c = 'A'; while (c <= 'Z') charset[count++] = c++;
510 +               }
511 +               if (type == 2) {
512 +                       charset[count++] = '!';
513 +                       c = '#'; while (c <= '&') charset[count++] = c++;
514 +                       c = '('; while (c <= '/') charset[count++] = c++;
515 +                       c = '<'; while (c <= '>') charset[count++] = c++;
516 +                       charset[count++] = '?'; charset[count++] = '@';
517 +                       charset[count++] = '['; charset[count++] = ']';
518 +                       charset[count++] = '^'; charset[count++] = '_';
519 +                       c = '{'; while (c <= '~') charset[count++] = c++;
520 +               }
521 +       }
522 +
523 +       seed = (crack_seed++ << 16 >> 16) * 22695477 + 1;
524 +
525 +       i = 0;
526 +       while (i < length) {
527 +               random = ((seed = seed * 22695477 + 1) >> 16) & 0x7fff;
528 +               word[i++] = charset[random % count];
529 +       }
530 +
531 +       word[i] = 0;
532 +}
533 +
534 +# Useful external mode example
535 +[List.External:Double]
536 +/*
537 + * This cracking mode tries all the possible duplicated lowercase alphabetic
538 + * "words" of up to 8 characters long. Since word halves are the same, it
539 + * only has to try about 500,000 words.
540 + */
541 +
542 +/* Global variables: current length and word */
543 +int length, current[9];
544 +
545 +/* Called at startup to initialize the global variables */
546 +void init()
547 +{
548 +       int i;
549 +
550 +       i = length = 2;                 // Start with 4 character long words
551 +       while (i--) current[i] = 'a';   // Set our half-word to "aa"
552 +}
553 +
554 +/* Generates a new word */
555 +void generate()
556 +{
557 +       int i;
558 +
559 +/* Export last generated word, duplicating it at the same time; here "word"
560 + * is a pre-defined external variable. */
561 +       word[(i = length) << 1] = 0;
562 +       while (i--) word[length + i] = word[i] = current[i];
563 +
564 +/* Generate a new word */
565 +       i = length - 1;                 // Start from the last character
566 +       while (++current[i] > 'z')      // Try to increase it
567 +       if (i)                          // Overflow here, any more positions?
568 +               current[i--] = 'a';     // Yes, move to the left, and repeat
569 +       else {                          // No
570 +               current = 0;            // Request a length switch
571 +               break;                  // Break out of the loop
572 +       }
573 +
574 +/* Switch to the next length, unless we were generating 8 character long
575 + * words already. */
576 +       if (!current && length < 4) {
577 +               i = ++length;
578 +               while (i--) current[i] = 'a';
579 +       }
580 +}
581 +
582 +/* Called when restoring an interrupted session */
583 +void restore()
584 +{
585 +       int i;
586 +
587 +/* Import the word back */
588 +       i = 0;
589 +       while (current[i] = word[i]) i++;
590 +
591 +/* ...and calculate the half-word length */
592 +       length = i >> 1;
593 +}
594 +
595 +# Simple parallel processing example
596 +[List.External:Parallel]
597 +/*
598 + * This word filter makes John process some of the words only, for running
599 + * multiple instances on different CPUs. It can be used with any cracking
600 + * mode except for "single crack". Note: this is not a good solution, but
601 + * is just an example of what can be done with word filters.
602 + */
603 +
604 +int node, total;                       // This node's number, and node count
605 +int number;                            // Current word number
606 +
607 +void init()
608 +{
609 +       node = 1; total = 2;            // Node 1 of 2, change as appropriate
610 +       number = node - 1;              // Speedup the filter a bit
611 +}
612 +
613 +void filter()
614 +{
615 +       if (number++ % total)           // Word for a different node?
616 +               word = 0;               // Yes, skip it
617 +}
618 diff -ruN john-1.6/src/AFS_fmt.c john-1.6.34/src/AFS_fmt.c
619 --- john-1.6/src/AFS_fmt.c      1998-12-03 01:29:50.000000000 +0100
620 +++ john-1.6.34/src/AFS_fmt.c   2001-06-16 08:08:33.000000000 +0200
621 @@ -1,6 +1,6 @@
622  /*
623   * This file is part of John the Ripper password cracker,
624 - * Copyright (c) 1996-98 by Solar Designer
625 + * Copyright (c) 1996-2001 by Solar Designer
626   */
627  
628  #include <string.h>
629 @@ -90,7 +90,7 @@
630  } AFS_long_KS;
631  static DES_binary AFS_long_IV_binary;
632  
633 -static void init()
634 +static void init(void)
635  {
636         ARCH_WORD_32 block[2];
637  #if !ARCH_LITTLE_ENDIAN
638 @@ -121,12 +121,12 @@
639  
640         if (strncmp(ciphertext, "$K4$", 4)) return 0;
641  
642 -       for (pos = &ciphertext[4]; atoi16[(ARCH_INDEX)*pos] != 0x7F; pos++);
643 +       for (pos = &ciphertext[4]; atoi16[ARCH_INDEX(*pos)] != 0x7F; pos++);
644         if (*pos != ',' || pos - ciphertext != CIPHERTEXT_LENGTH) return 0;
645  
646         for (index = 0; index < 16; index += 2) {
647 -               value = (int)atoi16[(ARCH_INDEX)ciphertext[index + 4]] << 4;
648 -               value |= atoi16[(ARCH_INDEX)ciphertext[index + 5]];
649 +               value = (int)atoi16[ARCH_INDEX(ciphertext[index + 4])] << 4;
650 +               value |= atoi16[ARCH_INDEX(ciphertext[index + 5])];
651  
652                 count = 0;
653                 if (value)
654 @@ -153,8 +153,8 @@
655         known_long = 0;
656  
657         for (index = 0; index < 16; index += 2) {
658 -               value = (int)atoi16[(ARCH_INDEX)ciphertext[index + 4]] << 4;
659 -               value |= atoi16[(ARCH_INDEX)ciphertext[index + 5]];
660 +               value = (int)atoi16[ARCH_INDEX(ciphertext[index + 4])] << 4;
661 +               value |= atoi16[ARCH_INDEX(ciphertext[index + 5])];
662  
663                 out[index >> 3] |= (value | 1) << ((index << 2) & 0x18);
664  
665 @@ -458,6 +458,7 @@
666                 set_salt,
667                 set_key,
668                 get_key,
669 +               fmt_default_clear_keys,
670                 crypt_all,
671                 {
672                         get_hash_0,
673 diff -ruN john-1.6/src/alpha.h john-1.6.34/src/alpha.h
674 --- john-1.6/src/alpha.h        1998-12-03 01:29:50.000000000 +0100
675 +++ john-1.6.34/src/alpha.h     2000-05-08 09:05:05.000000000 +0200
676 @@ -1,6 +1,6 @@
677  /*
678   * This file is part of John the Ripper password cracker,
679 - * Copyright (c) 1996-98 by Solar Designer
680 + * Copyright (c) 1996-2000 by Solar Designer
681   */
682  
683  /*
684 @@ -10,15 +10,15 @@
685  #ifndef _JOHN_ARCH_H
686  #define _JOHN_ARCH_H
687  
688 -#define ARCH_GENERIC                   0
689  #define ARCH_WORD                      long
690  #define ARCH_SIZE                      8
691  #define ARCH_BITS                      64
692 +#define ARCH_BITS_LOG                  6
693  #define ARCH_BITS_STR                  "64"
694  #define ARCH_LITTLE_ENDIAN             1
695  #define ARCH_INT_GT_32                 0
696  #define ARCH_ALLOWS_UNALIGNED          0
697 -#define ARCH_INDEX                     unsigned long
698 +#define ARCH_INDEX(x)                  ((unsigned long)(unsigned char)(x))
699  
700  #define OS_TIMER                       1
701  #define OS_FLOCK                       1
702 @@ -32,9 +32,13 @@
703  #define DES_SCALE                      1
704  #define DES_EXTB                       1
705  #define DES_COPY                       0
706 +#define DES_BS_ASM                     0
707  #define DES_BS                         1
708 +#define DES_BS_VECTOR                  0
709 +#define DES_BS_EXPAND                  1
710  
711  #define MD5_ASM                                0
712 +#define MD5_X2                         1
713  #define MD5_IMM                                0
714  
715  #define BF_ASM                         0
716 diff -ruN john-1.6/src/alpha.S john-1.6.34/src/alpha.S
717 --- john-1.6/src/alpha.S        1998-12-03 01:29:50.000000000 +0100
718 +++ john-1.6.34/src/alpha.S     1999-09-22 05:25:30.000000000 +0200
719 @@ -1,6 +1,6 @@
720  /*
721   * This file is part of John the Ripper password cracker,
722 - * Copyright (c) 1996-98 by Solar Designer
723 + * Copyright (c) 1996-99 by Solar Designer
724   */
725  
726  /*
727 @@ -12,8 +12,7 @@
728   * affect EV4.
729   *
730   * In reality, bitslice DES turned out to be faster almost everywhere, so
731 - * these routines are now only used for BSDI setkey(), AFS and NT LM hash
732 - * by default.
733 + * these routines are now only used for BSDI setkey() and AFS by default.
734   *
735   * The following things were kept in mind while coding:
736   *
737 diff -ruN john-1.6/src/bench.c john-1.6.34/src/bench.c
738 --- john-1.6/src/bench.c        1998-12-03 01:29:50.000000000 +0100
739 +++ john-1.6.34/src/bench.c     2001-07-26 16:55:13.000000000 +0200
740 @@ -1,8 +1,16 @@
741  /*
742   * This file is part of John the Ripper password cracker,
743 - * Copyright (c) 1996-98 by Solar Designer
744 + * Copyright (c) 1996-2001 by Solar Designer
745   */
746  
747 +#ifdef __ultrix__
748 +#define __POSIX
749 +#define _POSIX_SOURCE
750 +#endif
751 +
752 +#ifdef _SCO_C_DIALECT
753 +#include <limits.h>
754 +#endif
755  #include <stdio.h>
756  #include <string.h>
757  #include <signal.h>
758 @@ -20,7 +28,7 @@
759  #include "formats.h"
760  #include "bench.h"
761  
762 -static int bench_running;
763 +static volatile int bench_running;
764  
765  static void bench_handle_timer(int signum)
766  {
767 @@ -28,18 +36,20 @@
768  }
769  
770  static void bench_set_keys(struct fmt_main *format,
771 -       struct fmt_tests **current, int cond)
772 +       struct fmt_tests *current, int cond)
773  {
774         char *plaintext;
775         int index, length;
776  
777 +       format->methods.clear_keys();
778 +
779         length = format->params.benchmark_length;
780         for (index = 0; index < format->params.max_keys_per_crypt; index++) {
781                 do {
782 -                       if (!(*current)->ciphertext)
783 -                               *current = format->params.tests;
784 -                       plaintext = (*current)->plaintext;
785 -                       (*current)++;
786 +                       if (!current->ciphertext)
787 +                               current = format->params.tests;
788 +                       plaintext = current->plaintext;
789 +                       current++;
790  
791                         if (cond > 0) {
792                                 if ((int)strlen(plaintext) > length) break;
793 @@ -54,9 +64,13 @@
794         }
795  }
796  
797 -int benchmark_format(struct fmt_main *format, int salts,
798 +char *benchmark_format(struct fmt_main *format, int salts,
799         struct bench_results *results)
800  {
801 +       static void *binary = NULL;
802 +       static int binary_size = 0;
803 +       static char s_error[64];
804 +       char *where;
805         struct fmt_tests *current;
806         int cond;
807  #if OS_TIMER
808 @@ -67,10 +81,19 @@
809         unsigned ARCH_WORD count;
810         char *ciphertext;
811         void *salt, *two_salts[2];
812 -       int index;
813 +       int index, max;
814  
815 -       if (!(current = format->params.tests)) return 1;
816 -       if (fmt_self_test(format)) return 1;
817 +       if (!(current = format->params.tests)) return "FAILED (no data)";
818 +       if ((where = fmt_self_test(format))) {
819 +               sprintf(s_error, "FAILED (%s)", where);
820 +               return s_error;
821 +       }
822 +
823 +       if (format->params.binary_size > binary_size) {
824 +               binary_size = format->params.binary_size;
825 +               binary = mem_alloc_tiny(binary_size, MEM_ALIGN_WORD);
826 +               memset(binary, 0x55, binary_size);
827 +       }
828  
829         for (index = 0; index < 2; index++) {
830                 two_salts[index] = mem_alloc(format->params.salt_size);
831 @@ -89,7 +112,7 @@
832         } else
833                 cond = 0;
834  
835 -       bench_set_keys(format, &current, cond);
836 +       bench_set_keys(format, current, cond);
837  
838  #if OS_TIMER
839         memset(&it, 0, sizeof(it));
840 @@ -111,14 +134,18 @@
841         count = 0;
842  
843         index = salts;
844 +       max = format->params.max_keys_per_crypt;
845         do {
846                 if (!--index) {
847                         index = salts;
848 -                       bench_set_keys(format, &current, cond);
849 +                       if (!(++current)->ciphertext)
850 +                               current = format->params.tests;
851 +                       bench_set_keys(format, current, cond);
852                 }
853  
854                 if (salts > 1) format->methods.set_salt(two_salts[index & 1]);
855 -               format->methods.crypt_all(format->params.max_keys_per_crypt);
856 +               format->methods.crypt_all(max);
857 +               format->methods.cmp_all(binary, max);
858  
859                 count++;
860  #if !OS_TIMER
861 @@ -137,7 +164,7 @@
862         for (index = 0; index < 2; index++)
863                 mem_free(&two_salts[index]);
864  
865 -       return event_abort ? -1 : 0;
866 +       return event_abort ? "" : NULL;
867  }
868  
869  void benchmark_cps(unsigned ARCH_WORD count, clock_t time, char *buffer)
870 @@ -150,13 +177,12 @@
871         sprintf(buffer, cps_hi < 100 ? "%lu.%lu" : "%lu", cps_hi, cps_lo);
872  }
873  
874 -void benchmark_all()
875 +void benchmark_all(void)
876  {
877         struct fmt_main *format;
878 -       char *msg_1, *msg_m;
879 +       char *result, *msg_1, *msg_m;
880         struct bench_results results_1, results_m;
881         char s_real[64], s_virtual[64];
882 -       int result;
883  
884         if ((format = fmt_list))
885         do {
886 @@ -182,15 +208,16 @@
887                         msg_1 = "Long";
888                 }
889  
890 -               if ((result = benchmark_format(format, BENCHMARK_MANY,
891 +               if ((result = benchmark_format(format,
892 +                   format->params.salt_size ? BENCHMARK_MANY : 1,
893                     &results_m))) {
894 -                       if (result > 0) puts("FAILED"); else putchar('\n');
895 +                       puts(result);
896                         continue;
897                 }
898  
899                 if (msg_1)
900                 if ((result = benchmark_format(format, 1, &results_1))) {
901 -                       if (result > 0) puts("FAILED"); else putchar('\n');
902 +                       puts(result);
903                         continue;
904                 }
905  
906 @@ -198,12 +225,11 @@
907  
908                 benchmark_cps(results_m.count, results_m.real, s_real);
909                 benchmark_cps(results_m.count, results_m.virtual, s_virtual);
910 -               printf("%s:\t%s c/s"
911 -#if !defined(__DJGPP__) && !defined(__CYGWIN32__)
912 -                       " real, %s c/s virtual\n",
913 +#if !defined(__DJGPP__) && !defined(__CYGWIN32__) && !defined(__BEOS__)
914 +               printf("%s:\t%s c/s real, %s c/s virtual\n",
915                         msg_m, s_real, s_virtual);
916  #else
917 -                       "\n",
918 +               printf("%s:\t%s c/s\n",
919                         msg_m, s_real);
920  #endif
921  
922 @@ -214,12 +240,11 @@
923  
924                 benchmark_cps(results_1.count, results_1.real, s_real);
925                 benchmark_cps(results_1.count, results_1.virtual, s_virtual);
926 -               printf("%s:\t%s c/s"
927 -#if !defined(__DJGPP__) && !defined(__CYGWIN32__)
928 -                       " real, %s c/s virtual\n\n",
929 +#if !defined(__DJGPP__) && !defined(__CYGWIN32__) && !defined(__BEOS__)
930 +               printf("%s:\t%s c/s real, %s c/s virtual\n\n",
931                         msg_1, s_real, s_virtual);
932  #else
933 -                       "\n\n",
934 +               printf("%s:\t%s c/s\n\n",
935                         msg_1, s_real);
936  #endif
937         } while ((format = format->next) && !event_abort);
938 diff -ruN john-1.6/src/bench.h john-1.6.34/src/bench.h
939 --- john-1.6/src/bench.h        1998-12-03 01:29:50.000000000 +0100
940 +++ john-1.6.34/src/bench.h     1999-10-16 15:52:31.000000000 +0200
941 @@ -1,6 +1,6 @@
942  /*
943   * This file is part of John the Ripper password cracker,
944 - * Copyright (c) 1996-98 by Solar Designer
945 + * Copyright (c) 1996-99 by Solar Designer
946   */
947  
948  /*
949 @@ -27,11 +27,11 @@
950  };
951  
952  /*
953 - * Benchmarks the supplied cracking algorithm. Returns zero on success, a
954 - * positive value if the self test fails or there's no self test for this
955 - * algorithm, or a negative value if aborted.
956 + * Benchmarks the supplied cracking algorithm. Returns NULL on success,
957 + * an error message if the self test fails or there're no test vectors
958 + * for this algorithm, or an empty string if aborted.
959   */
960 -extern int benchmark_format(struct fmt_main *format, int salts,
961 +extern char *benchmark_format(struct fmt_main *format, int salts,
962         struct bench_results *results);
963  
964  /*
965 @@ -44,6 +44,6 @@
966   * Benchmarks all the registered cracking algorithms and prints the results
967   * to stdout.
968   */
969 -extern void benchmark_all();
970 +extern void benchmark_all(void);
971  
972  #endif
973 diff -ruN john-1.6/src/best.c john-1.6.34/src/best.c
974 --- john-1.6/src/best.c 1998-12-03 01:29:50.000000000 +0100
975 +++ john-1.6.34/src/best.c      1999-06-08 05:33:20.000000000 +0200
976 @@ -1,12 +1,20 @@
977  /*
978   * This file is part of John the Ripper password cracker,
979 - * Copyright (c) 1996-98 by Solar Designer
980 + * Copyright (c) 1996-99 by Solar Designer
981   */
982  
983  /*
984   * Benchmark to detect the best algorithm for a particular architecture.
985   */
986  
987 +#ifdef __ultrix__
988 +#define __POSIX
989 +#define _POSIX_SOURCE
990 +#endif
991 +
992 +#ifdef _SCO_C_DIALECT
993 +#include <limits.h>
994 +#endif
995  #include <stdio.h>
996  #include <time.h>
997  
998 diff -ruN john-1.6/src/best.sh john-1.6.34/src/best.sh
999 --- john-1.6/src/best.sh        1998-12-03 01:29:50.000000000 +0100
1000 +++ john-1.6.34/src/best.sh     2000-06-25 07:07:28.000000000 +0200
1001 @@ -1,7 +1,7 @@
1002  #!/bin/sh
1003  #
1004  # This file is part of John the Ripper password cracker,
1005 -# Copyright (c) 1996-98 by Solar Designer
1006 +# Copyright (c) 1996-2000 by Solar Designer
1007  #
1008  
1009  [ $# -eq 4 ] || exit 1
1010 @@ -11,13 +11,13 @@
1011  MD5_DEPEND=$3
1012  BF_DEPEND=$4
1013  
1014 -# Detect the best standard DES algorithm
1015 +# Detect the best non-bitslice DES algorithm
1016  
1017  MAX=0
1018  DES_BEST=1
1019  
1020  for MODE in 1 2 3 4 5; do
1021 -       if ./detect $MODE 1 0 0 0 > arch.h; then
1022 +       if ./detect $MODE 1 0 0 0 0 > arch.h; then
1023                 rm -f $DES_DEPEND bench
1024                 echo "Compiling: DES benchmark (code version #$MODE)"
1025                 $MAKE bench || exit 1
1026 @@ -29,7 +29,7 @@
1027         fi
1028  done
1029  
1030 -./detect $DES_BEST 0 0 0 0 > arch.h
1031 +./detect $DES_BEST 0 0 0 0 0 > arch.h
1032  rm -f $DES_DEPEND bench
1033  
1034  echo "Compiling: DES benchmark (code version #$DES_BEST, no key copying)"
1035 @@ -43,7 +43,7 @@
1036  
1037  # Check if bitslice DES is faster
1038  
1039 -./detect $DES_BEST $DES_COPY 1 0 0 > arch.h
1040 +./detect $DES_BEST $DES_COPY 1 0 0 0 > arch.h
1041  rm -f $DES_DEPEND bench
1042  
1043  echo "Compiling: DES benchmark (bitslice)"
1044 @@ -59,7 +59,19 @@
1045  
1046  MAX=`./bench 2` || exit 1
1047  
1048 -./detect $DES_BEST $DES_COPY $DES_BS 1 0 > arch.h
1049 +./detect $DES_BEST $DES_COPY $DES_BS 1 0 0 > arch.h
1050 +rm -f $MD5_DEPEND bench
1051 +
1052 +echo "Compiling: MD5 benchmark (two hashes at a time)"
1053 +$MAKE bench || exit 1
1054 +RES=`./bench 2` || exit 1
1055 +if [ $RES -gt $MAX ]; then
1056 +       MD5_X2=1
1057 +else
1058 +       MD5_X2=0
1059 +fi
1060 +
1061 +./detect $DES_BEST $DES_COPY $DES_BS $MD5_X2 1 0 > arch.h
1062  rm -f $MD5_DEPEND bench
1063  
1064  echo "Compiling: MD5 benchmark (immediate values)"
1065 @@ -75,7 +87,7 @@
1066  
1067  MAX=`./bench 3` || exit 1
1068  
1069 -./detect $DES_BEST $DES_COPY $DES_BS $MD5_IMM 1 > arch.h
1070 +./detect $DES_BEST $DES_COPY $DES_BS $MD5_X2 $MD5_IMM 1 > arch.h
1071  rm -f $BF_DEPEND bench
1072  
1073  echo "Compiling: Blowfish benchmark (scale)"
1074 @@ -90,5 +102,5 @@
1075  # Produce generic.h, make sure everything is rebuilt with detected options,
1076  # and do some cleanup
1077  
1078 -./detect $DES_BEST $DES_COPY $DES_BS $MD5_IMM $BF_SCALE > generic.h
1079 +./detect $DES_BEST $DES_COPY $DES_BS $MD5_X2 $MD5_IMM $BF_SCALE > generic.h
1080  rm -f $DES_DEPEND $MD5_DEPEND $BF_DEPEND bench detect best.o detect.o arch.h
1081 diff -ruN john-1.6/src/BF_fmt.c john-1.6.34/src/BF_fmt.c
1082 --- john-1.6/src/BF_fmt.c       1998-12-03 01:29:50.000000000 +0100
1083 +++ john-1.6.34/src/BF_fmt.c    2001-06-16 08:08:58.000000000 +0200
1084 @@ -1,6 +1,6 @@
1085  /*
1086   * This file is part of John the Ripper password cracker,
1087 - * Copyright (c) 1996-98 by Solar Designer
1088 + * Copyright (c) 1996-2001 by Solar Designer
1089   */
1090  
1091  #include <stdlib.h>
1092 @@ -59,9 +59,12 @@
1093  
1094         if (ciphertext[6] != '$') return 0;
1095  
1096 -       for (pos = &ciphertext[7]; atoi64[(ARCH_INDEX)*pos] != 0x7F; pos++);
1097 +       for (pos = &ciphertext[7]; atoi64[ARCH_INDEX(*pos)] != 0x7F; pos++);
1098         if (*pos || pos - ciphertext != CIPHERTEXT_LENGTH) return 0;
1099  
1100 +       if (BF_atoi64[ARCH_INDEX(*(pos - 1))] & 3) return 0;
1101 +       if (BF_atoi64[ARCH_INDEX(ciphertext[28])] & 0xF) return 0;
1102 +
1103         return 1;
1104  }
1105  
1106 @@ -151,7 +154,7 @@
1107                 FMT_CASE | FMT_8_BIT,
1108                 tests
1109         }, {
1110 -               BF_std_init,
1111 +               fmt_default_init,
1112                 valid,
1113                 fmt_default_split,
1114                 (void *(*)(char *))BF_std_get_binary,
1115 @@ -165,6 +168,7 @@
1116                 set_salt,
1117                 set_key,
1118                 get_key,
1119 +               fmt_default_clear_keys,
1120                 crypt_all,
1121                 {
1122                         get_hash_0,
1123 diff -ruN john-1.6/src/BF_std.c john-1.6.34/src/BF_std.c
1124 --- john-1.6/src/BF_std.c       1998-12-03 01:29:50.000000000 +0100
1125 +++ john-1.6.34/src/BF_std.c    2001-04-29 07:06:12.000000000 +0200
1126 @@ -1,29 +1,36 @@
1127  /*
1128   * This file is part of John the Ripper password cracker,
1129 - * Copyright (c) 1996-98 by Solar Designer
1130 + * Copyright (c) 1996-2001 by Solar Designer
1131 + *
1132 + * A public domain version of this code, with reentrant and crypt(3)
1133 + * interfaces added, but optimizations specific to password cracking
1134 + * removed, is available at:
1135 + *
1136 + *     http://www.openwall.com/crypt/
1137   *
1138   * This implementation is compatible with OpenBSD bcrypt.c (version 2a)
1139   * by Niels Provos <provos@physnet.uni-hamburg.de>, and uses some of his
1140   * ideas. The password hashing algorithm was designed by David Mazieres
1141 - * <dm@lcs.mit.edu>. Some of the tricks in BF_ROUND might be inspired by
1142 - * Eric Young's Blowfish library (I can't be sure if I would think of
1143 - * something if I hadn't seen his code) -- SD.
1144 + * <dm@lcs.mit.edu>.
1145 + *
1146 + * There's a paper on the algorithm that explains its design decisions:
1147 + *
1148 + *     http://www.usenix.org/events/usenix99/provos.html
1149 + *
1150 + * Some of the tricks in BF_ROUND might be inspired by Eric Young's
1151 + * Blowfish library (I can't be sure if I would think of something if I
1152 + * hadn't seen his code).
1153   */
1154  
1155  #include <stdlib.h>
1156  #include <string.h>
1157  
1158  #include "arch.h"
1159 +#include "common.h"
1160  #include "BF_std.h"
1161  
1162  BF_binary BF_out;
1163  
1164 -/*
1165 - * Magic IV for 64 Blowfish encryptions that we do at the end.
1166 - */
1167 -static char BF_magic_b[24] = "OrpheanBeholderScryDoubt";
1168 -static BF_binary BF_magic_w;
1169 -
1170  /* Number of Blowfish rounds, this is also hardcoded into a few places */
1171  #define BF_N                           16
1172  
1173 @@ -34,21 +41,30 @@
1174         BF_key P;
1175  };
1176  
1177 -#if !BF_SCALE
1178 -#define BF_INDEX(S, i) \
1179 -       (*((BF_word *)(((unsigned char *)S) + (i))))
1180 -#endif
1181 -
1182  /* Current Blowfish context */
1183  #if BF_ASM
1184  extern
1185  #else
1186  static
1187  #endif
1188 -struct BF_ctx BF_current;
1189 +struct BF_ctx CC_CACHE_ALIGN BF_current;
1190  
1191  /* Current Blowfish key */
1192 -static BF_key BF_exp_key, BF_init_key;
1193 +static BF_key CC_CACHE_ALIGN BF_exp_key;
1194 +#if defined(__linux__) && defined(__sparc__)
1195 +static BF_key BF_init_key;
1196 +#else
1197 +static BF_key CC_CACHE_ALIGN BF_init_key;
1198 +#endif
1199 +
1200 +/*
1201 + * Magic IV for 64 Blowfish encryptions that we do at the end.
1202 + * The string is "OrpheanBeholderScryDoubt" on big-endian.
1203 + */
1204 +static BF_word BF_magic_w[6] = {
1205 +       0x4F727068, 0x65616E42, 0x65686F6C,
1206 +       0x64657253, 0x63727944, 0x6F756274
1207 +};
1208  
1209  /*
1210   * P-box and S-box tables initialized with digits of Pi.
1211 @@ -325,6 +341,20 @@
1212         }
1213  };
1214  
1215 +/*
1216 + * Same charset, different order -- can't use the common.c table here.
1217 + */
1218 +unsigned char BF_atoi64[0x80] = {
1219 +       64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
1220 +       64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
1221 +       64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 1,
1222 +       54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 64, 64, 64, 64, 64,
1223 +       64, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
1224 +       17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 64, 64, 64, 64, 64,
1225 +       64, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42,
1226 +       43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 64, 64, 64, 64, 64
1227 +};
1228 +
1229  #if ARCH_LITTLE_ENDIAN
1230  
1231  static void BF_swap(BF_word *x, int count)
1232 @@ -344,12 +374,6 @@
1233  
1234  #endif
1235  
1236 -void BF_std_init()
1237 -{
1238 -       memcpy(BF_magic_w, BF_magic_b, sizeof(BF_magic_w));
1239 -       BF_swap(BF_magic_w, 6);
1240 -}
1241 -
1242  #if BF_SCALE
1243  /* Architectures which can shift addresses left by 2 bits with no extra cost */
1244  #define BF_ROUND(L, R, N) \
1245 @@ -369,6 +393,8 @@
1246         R ^= tmp3;
1247  #else
1248  /* Architectures with no complicated addressing modes supported */
1249 +#define BF_INDEX(S, i) \
1250 +       (*((BF_word *)(((unsigned char *)S) + (i))))
1251  #define BF_ROUND(L, R, N) \
1252         tmp1 = L & 0xFF; \
1253         tmp1 <<= 2; \
1254 @@ -415,7 +441,7 @@
1255  
1256  #if BF_ASM
1257  
1258 -extern void BF_body();
1259 +extern void (*BF_body)(void);
1260  
1261  #else
1262  
1263 @@ -556,7 +582,7 @@
1264         BF_out[1] = R;
1265  }
1266  
1267 -void BF_std_crypt_exact()
1268 +void BF_std_crypt_exact(void)
1269  {
1270         BF_word L, R;
1271         BF_word tmp1, tmp2, tmp3, tmp4;
1272 @@ -580,60 +606,37 @@
1273  }
1274  
1275  /*
1276 - * Standard charset, but non-standard order, so we can't use the table
1277 - * generated in common.c here.
1278 - */
1279 -static unsigned char BF_atoi64[0x80] =
1280 -{
1281 -       0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1282 -       0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1283 -       0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1284 -       0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1285 -       0, 0, 0, 0, 0, 0, 0, 1, 54, 55,
1286 -       56, 57, 58, 59, 60, 61, 62, 63, 0, 0,
1287 -       0, 0, 0, 0, 0, 2, 3, 4, 5, 6,
1288 -       7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
1289 -       17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27,
1290 -       0, 0, 0, 0, 0, 0, 28, 29, 30,
1291 -       31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
1292 -       41, 42, 43, 44, 45, 46, 47, 48, 49, 50,
1293 -       51, 52, 53, 0, 0, 0, 0, 0
1294 -};
1295 -
1296 -/*
1297   * I'm not doing any error checking in the routines below since the
1298   * ciphertext should have already been checked to be fmt_BF.valid().
1299   */
1300  
1301 -static void BF_decode(void *buffer, int length, char *data)
1302 +static void BF_decode(BF_word *dst, char *src, int size)
1303  {
1304 -       unsigned char *dptr = (unsigned char *)buffer;
1305 -       unsigned char *end = (unsigned char *)buffer + length;
1306 -       char *sptr = data;
1307 -       unsigned char c1, c2, c3, c4;
1308 -
1309 -       while (dptr < end) {
1310 -               c1 = BF_atoi64[(ARCH_INDEX)*sptr++];
1311 -               c2 = BF_atoi64[(ARCH_INDEX)*sptr++];
1312 +       unsigned char *dptr = (unsigned char *)dst;
1313 +       unsigned char *end = dptr + size;
1314 +       unsigned char *sptr = (unsigned char *)src;
1315 +       unsigned int c1, c2, c3, c4;
1316  
1317 +       do {
1318 +               c1 = BF_atoi64[ARCH_INDEX(*sptr++)];
1319 +               c2 = BF_atoi64[ARCH_INDEX(*sptr++)];
1320                 *dptr++ = (c1 << 2) | ((c2 & 0x30) >> 4);
1321                 if (dptr >= end) break;
1322  
1323 -               c3 = BF_atoi64[(ARCH_INDEX)*sptr++];
1324 -
1325 +               c3 = BF_atoi64[ARCH_INDEX(*sptr++)];
1326                 *dptr++ = ((c2 & 0x0F) << 4) | ((c3 & 0x3C) >> 2);
1327                 if (dptr >= end) break;
1328  
1329 -               c4 = BF_atoi64[(ARCH_INDEX)*sptr++];
1330 +               c4 = BF_atoi64[ARCH_INDEX(*sptr++)];
1331                 *dptr++ = ((c3 & 0x03) << 6) | c4;
1332 -       }
1333 +       } while (dptr < end);
1334  }
1335  
1336  BF_word *BF_std_get_salt(char *ciphertext)
1337  {
1338         static BF_salt salt;
1339  
1340 -       BF_decode(salt, 16, &ciphertext[7]);
1341 +       BF_decode(salt, &ciphertext[7], 16);
1342         BF_swap(salt, 4);
1343  
1344         salt[4] = (BF_word)1 << atoi(&ciphertext[4]);
1345 @@ -645,9 +648,9 @@
1346  {
1347         static BF_binary binary;
1348  
1349 -       BF_decode(binary, 23, &ciphertext[29]);
1350 +       binary[5] = 0;
1351 +       BF_decode(binary, &ciphertext[29], 23);
1352         BF_swap(binary, 6);
1353 -
1354         binary[5] &= ~(BF_word)0xFF;
1355  
1356         return binary;
1357 diff -ruN john-1.6/src/BF_std.h john-1.6.34/src/BF_std.h
1358 --- john-1.6/src/BF_std.h       1998-12-03 01:29:50.000000000 +0100
1359 +++ john-1.6.34/src/BF_std.h    2001-04-29 06:29:40.000000000 +0200
1360 @@ -1,10 +1,10 @@
1361  /*
1362   * This file is part of John the Ripper password cracker,
1363 - * Copyright (c) 1996-98 by Solar Designer
1364 + * Copyright (c) 1996-2001 by Solar Designer
1365   */
1366  
1367  /*
1368 - * Standard OpenBSD Blowfish implementation.
1369 + * OpenBSD-style Blowfish-based password hash implementation.
1370   */
1371  
1372  #ifndef _JOHN_BF_STD_H
1373 @@ -30,12 +30,12 @@
1374   */
1375  extern BF_binary BF_out;
1376  
1377 -#define BF_ALGORITHM_NAME              "32/" ARCH_BITS_STR
1378 -
1379  /*
1380 - * Initializes the internal structures.
1381 + * ASCII to binary conversion table, for use in BF_fmt.valid().
1382   */
1383 -extern void BF_std_init();
1384 +extern unsigned char BF_atoi64[0x80];
1385 +
1386 +#define BF_ALGORITHM_NAME              "32/" ARCH_BITS_STR
1387  
1388  /*
1389   * Sets a key for BF_std_crypt().
1390 @@ -50,7 +50,7 @@
1391  /*
1392   * Calculates the rest of BF_out, for exact comparison.
1393   */
1394 -extern void BF_std_crypt_exact();
1395 +extern void BF_std_crypt_exact(void);
1396  
1397  /*
1398   * Returns the salt for BF_std_crypt().
1399 diff -ruN john-1.6/src/BSDI_fmt.c john-1.6.34/src/BSDI_fmt.c
1400 --- john-1.6/src/BSDI_fmt.c     1998-12-03 01:29:50.000000000 +0100
1401 +++ john-1.6.34/src/BSDI_fmt.c  2001-06-16 09:32:21.000000000 +0200
1402 @@ -1,6 +1,6 @@
1403  /*
1404   * This file is part of John the Ripper password cracker,
1405 - * Copyright (c) 1996-98 by Solar Designer
1406 + * Copyright (c) 1996-2001 by Solar Designer
1407   */
1408  
1409  #include <string.h>
1410 @@ -31,24 +31,22 @@
1411         {"_J9..SDizh.vll5VED9g", "ab1234567"},
1412         {"_J9..SDizRjWQ/zePPHc", "cr1234567"},
1413         {"_J9..SDizxmRI1GjnQuE", "zxyDPWgydbQjgq"},
1414 +       {"_K9..SaltNrQgIYUAeoY", "726 even"},
1415         {"_J9..SDSD5YGyRCr4W4c", ""},
1416         {NULL}
1417  };
1418  
1419  #if DES_BS
1420  
1421 -#include "memory.h"
1422  #include "DES_bs.h"
1423  
1424  #define ALGORITHM_NAME                 DES_BS_ALGORITHM_NAME
1425  
1426 -#define BINARY_BITS                    16
1427 -
1428 -#define BINARY_SIZE                    (BINARY_BITS * ARCH_SIZE)
1429 +#define BINARY_SIZE                    ARCH_SIZE
1430  #define SALT_SIZE                      (ARCH_SIZE * 2)
1431  
1432 -#define MIN_KEYS_PER_CRYPT             ARCH_BITS
1433 -#define MAX_KEYS_PER_CRYPT             ARCH_BITS
1434 +#define MIN_KEYS_PER_CRYPT             DES_BS_DEPTH
1435 +#define MAX_KEYS_PER_CRYPT             DES_BS_DEPTH
1436  
1437  #else
1438  
1439 @@ -64,12 +62,10 @@
1440  
1441  #endif
1442  
1443 -int saved_count;
1444 +static int saved_count;
1445  
1446  static struct {
1447 -#if DES_BS
1448 -       char final[8];
1449 -#else
1450 +#if !DES_BS
1451         union {
1452                 double dummy;
1453                 struct {
1454 @@ -81,26 +77,12 @@
1455         char key[PLAINTEXT_LENGTH];
1456  } buffer[MAX_KEYS_PER_CRYPT];
1457  
1458 -#if DES_BS
1459 -
1460 -struct fmt_main fmt_BSDI;
1461 -static int binary_bits = BINARY_BITS;
1462 -static int keys_changed;
1463 -
1464 -#endif
1465 -
1466 -static void init()
1467 +static void init(void)
1468  {
1469         DES_std_init();
1470  
1471  #if DES_BS
1472 -       if (mem_saving_level > 1) {
1473 -               DES_bs_mem_saving = 1;
1474 -               binary_bits = 32;
1475 -               fmt_BSDI.params.binary_size = ARCH_SIZE;
1476 -       }
1477 -
1478 -       DES_bs_init();
1479 +       DES_bs_init(0);
1480  
1481         DES_std_set_salt(0);
1482         DES_count = 1;
1483 @@ -118,9 +100,11 @@
1484         for (pos = &ciphertext[1]; pos < &ciphertext[9]; pos++)
1485         if (!*pos) return 0;
1486  
1487 -       for (pos = &ciphertext[9]; atoi64[(ARCH_INDEX)*pos] != 0x7F; pos++);
1488 +       for (pos = &ciphertext[9]; atoi64[ARCH_INDEX(*pos)] != 0x7F; pos++);
1489         if (*pos || pos - ciphertext != CIPHERTEXT_LENGTH) return 0;
1490  
1491 +       if (atoi64[ARCH_INDEX(*(pos - 1))] & 3) return 0;
1492 +
1493         return 1;
1494  }
1495  
1496 @@ -142,17 +126,17 @@
1497  
1498  static int binary_hash_0(void *binary)
1499  {
1500 -       return DES_bs_binary_hash((ARCH_WORD *)binary, 4);
1501 +       return *(ARCH_WORD *)binary & 0xF;
1502  }
1503  
1504  static int binary_hash_1(void *binary)
1505  {
1506 -       return DES_bs_binary_hash((ARCH_WORD *)binary, 8);
1507 +       return *(ARCH_WORD *)binary & 0xFF;
1508  }
1509  
1510  static int binary_hash_2(void *binary)
1511  {
1512 -       return DES_bs_binary_hash((ARCH_WORD *)binary, 12);
1513 +       return *(ARCH_WORD *)binary & 0xFFF;
1514  }
1515  
1516  static int get_hash_0(int index)
1517 @@ -283,8 +267,7 @@
1518         }
1519  
1520  #if DES_BS
1521 -       strnfcpy(buffer[index].final, final, 8);
1522 -       keys_changed = 1;
1523 +       DES_bs_set_key(final, index);
1524  #else
1525         memcpy(buffer[index].aligned.data.KS, DES_KS_current, sizeof(DES_KS));
1526  #endif
1527 @@ -302,26 +285,18 @@
1528  
1529  static void crypt_all(int count)
1530  {
1531 -       int index;
1532 -
1533 -       if (keys_changed) {
1534 -               DES_bs_clear_keys();
1535 -               for (index = 0; index < count; index++)
1536 -                       DES_bs_set_key(buffer[index].final, index);
1537 -               keys_changed = 0;
1538 -       }
1539 -
1540 +       DES_bs_expand_keys();
1541         DES_bs_crypt(saved_count);
1542  }
1543  
1544  static int cmp_all(void *binary, int count)
1545  {
1546 -       return DES_bs_cmp_all((ARCH_WORD *)binary, binary_bits);
1547 +       return DES_bs_cmp_all((ARCH_WORD *)binary);
1548  }
1549  
1550  static int cmp_one(void *binary, int index)
1551  {
1552 -       return DES_bs_cmp_one((ARCH_WORD *)binary, binary_bits, index);
1553 +       return DES_bs_cmp_one((ARCH_WORD *)binary, 32, index);
1554  }
1555  
1556  static int cmp_exact(char *source, int index)
1557 @@ -393,7 +368,11 @@
1558                 SALT_SIZE,
1559                 MIN_KEYS_PER_CRYPT,
1560                 MAX_KEYS_PER_CRYPT,
1561 +#if DES_BS
1562 +               FMT_CASE | FMT_BS,
1563 +#else
1564                 FMT_CASE,
1565 +#endif
1566                 tests
1567         }, {
1568                 init,
1569 @@ -415,6 +394,11 @@
1570                 set_salt,
1571                 set_key,
1572                 get_key,
1573 +#if DES_BS
1574 +               DES_bs_clear_keys,
1575 +#else
1576 +               fmt_default_clear_keys,
1577 +#endif
1578                 crypt_all,
1579                 {
1580                         get_hash_0,
1581 diff -ruN john-1.6/src/charset.c john-1.6.34/src/charset.c
1582 --- john-1.6/src/charset.c      1998-12-03 01:29:50.000000000 +0100
1583 +++ john-1.6.34/src/charset.c   1999-04-14 12:50:36.000000000 +0200
1584 @@ -1,6 +1,6 @@
1585  /*
1586   * This file is part of John the Ripper password cracker,
1587 - * Copyright (c) 1996-98 by Solar Designer
1588 + * Copyright (c) 1996-99 by Solar Designer
1589   */
1590  
1591  #include <stdio.h>
1592 @@ -123,7 +123,7 @@
1593         current = plaintexts;
1594         do {
1595                 for (ptr = (unsigned char *)current->data; *ptr; ptr++)
1596 -                       (*chars)[0][0][(ARCH_INDEX)(*ptr - CHARSET_MIN)]++;
1597 +                       (*chars)[0][0][ARCH_INDEX(*ptr - CHARSET_MIN)]++;
1598         } while ((current = current->next));
1599  
1600         count = 0;
1601 @@ -159,15 +159,15 @@
1602                         (*chars)
1603                                 [CHARSET_SIZE]
1604                                 [CHARSET_SIZE]
1605 -                               [(ARCH_INDEX)(ptr[pos] - CHARSET_MIN)]++;
1606 +                               [ARCH_INDEX(ptr[pos] - CHARSET_MIN)]++;
1607                         if (pos) (*chars)
1608                                 [CHARSET_SIZE]
1609 -                               [(ARCH_INDEX)(ptr[pos - 1] - CHARSET_MIN)]
1610 -                               [(ARCH_INDEX)(ptr[pos] - CHARSET_MIN)]++;
1611 +                               [ARCH_INDEX(ptr[pos - 1] - CHARSET_MIN)]
1612 +                               [ARCH_INDEX(ptr[pos] - CHARSET_MIN)]++;
1613                         if (pos > 1) (*chars)
1614 -                               [(ARCH_INDEX)(ptr[pos - 2] - CHARSET_MIN)]
1615 -                               [(ARCH_INDEX)(ptr[pos - 1] - CHARSET_MIN)]
1616 -                               [(ARCH_INDEX)(ptr[pos] - CHARSET_MIN)]++;
1617 +                               [ARCH_INDEX(ptr[pos - 2] - CHARSET_MIN)]
1618 +                               [ARCH_INDEX(ptr[pos - 1] - CHARSET_MIN)]
1619 +                               [ARCH_INDEX(ptr[pos] - CHARSET_MIN)]++;
1620                 } while ((current = current->next));
1621  
1622                 for (i = (pos > 1 ? 0 : CHARSET_SIZE); i <= CHARSET_SIZE; i++)
1623 diff -ruN john-1.6/src/charset.h john-1.6.34/src/charset.h
1624 --- john-1.6/src/charset.h      1998-12-03 01:29:50.000000000 +0100
1625 +++ john-1.6.34/src/charset.h   2001-02-16 06:52:01.000000000 +0100
1626 @@ -1,6 +1,6 @@
1627  /*
1628   * This file is part of John the Ripper password cracker,
1629 - * Copyright (c) 1996-98 by Solar Designer
1630 + * Copyright (c) 1996-2001 by Solar Designer
1631   */
1632  
1633  /*
1634 @@ -11,6 +11,7 @@
1635  #define _JOHN_CHARSET_H
1636  
1637  #include "params.h"
1638 +#include "common.h"
1639  #include "loader.h"
1640  
1641  /*
1642 @@ -26,19 +27,19 @@
1643   */
1644  struct charset_header {
1645  /* CHARSET_VERSION */
1646 -       char version[4];
1647 +       char version[4] CC_PACKED;
1648  
1649  /* CHARSET_MIN, CHARSET_MAX */
1650 -       unsigned char min, max;
1651 +       unsigned char min, max CC_PACKED;
1652  
1653  /* CHARSET_LENGTH */
1654 -       unsigned char length;
1655 +       unsigned char length CC_PACKED;
1656  
1657  /* Number of different characters, up to (max - min + 1) */
1658 -       unsigned char count;
1659 +       unsigned char count CC_PACKED;
1660  
1661 -/* File offsets for each length, 32 bit little endian */
1662 -       unsigned char offsets[CHARSET_LENGTH][4];
1663 +/* File offsets for each length, 32-bit little endian */
1664 +       unsigned char offsets[CHARSET_LENGTH][4] CC_PACKED;
1665  
1666  /*
1667   * Cracking order.
1668 @@ -51,13 +52,9 @@
1669   * up to CHARSET_SIZE characters large.
1670   */
1671         unsigned char order
1672 -               [CHARSET_LENGTH * (CHARSET_LENGTH + 1) / 2 * CHARSET_SIZE * 3];
1673 -}
1674 -#if ((__GNUC__ == 2) && (__GNUC_MINOR__ >= 7)) || (__GNUC__ > 2)
1675 -       __attribute__ ((packed));
1676 -#else
1677 -       ;
1678 -#endif
1679 +               [CHARSET_LENGTH * (CHARSET_LENGTH + 1) / 2 * CHARSET_SIZE * 3]
1680 +               CC_PACKED;
1681 +} CC_PACKED;
1682  
1683  /*
1684   * Reads a charset file header.
1685 diff -ruN john-1.6/src/common.c john-1.6.34/src/common.c
1686 --- john-1.6/src/common.c       1998-12-03 01:29:50.000000000 +0100
1687 +++ john-1.6.34/src/common.c    1999-09-22 05:48:17.000000000 +0200
1688 @@ -1,6 +1,6 @@
1689  /*
1690   * This file is part of John the Ripper password cracker,
1691 - * Copyright (c) 1996-98 by Solar Designer
1692 + * Copyright (c) 1996-99 by Solar Designer
1693   */
1694  
1695  #include <string.h>
1696 @@ -18,7 +18,7 @@
1697  
1698  static int initialized = 0;
1699  
1700 -void common_init()
1701 +void common_init(void)
1702  {
1703         char *pos;
1704  
1705 @@ -26,11 +26,11 @@
1706  
1707         memset(atoi64, 0x7F, sizeof(atoi64));
1708         for (pos = itoa64; pos <= &itoa64[63]; pos++)
1709 -               atoi64[(ARCH_INDEX)*pos] = pos - itoa64;
1710 +               atoi64[ARCH_INDEX(*pos)] = pos - itoa64;
1711  
1712         memset(atoi16, 0x7F, sizeof(atoi16));
1713         for (pos = itoa16; pos <= &itoa16[15]; pos++)
1714 -               atoi16[(ARCH_INDEX)*pos] = pos - itoa16;
1715 +               atoi16[ARCH_INDEX(*pos)] = pos - itoa16;
1716  
1717         atoi16['A'] = atoi16['a'];
1718         atoi16['B'] = atoi16['b'];
1719 diff -ruN john-1.6/src/common.h john-1.6.34/src/common.h
1720 --- john-1.6/src/common.h       1998-12-03 01:29:50.000000000 +0100
1721 +++ john-1.6.34/src/common.h    1999-09-22 05:39:10.000000000 +0200
1722 @@ -1,6 +1,6 @@
1723  /*
1724   * This file is part of John the Ripper password cracker,
1725 - * Copyright (c) 1996-98 by Solar Designer
1726 + * Copyright (c) 1996-99 by Solar Designer
1727   */
1728  
1729  /*
1730 @@ -11,6 +11,7 @@
1731  #define _JOHN_COMMON_H
1732  
1733  #include "arch.h"
1734 +#include "memory.h"
1735  
1736  #if ARCH_INT_GT_32
1737  typedef unsigned short ARCH_WORD_32;
1738 @@ -18,6 +19,19 @@
1739  typedef unsigned int ARCH_WORD_32;
1740  #endif
1741  
1742 +#if ((__GNUC__ == 2) && (__GNUC_MINOR__ >= 7)) || (__GNUC__ > 2)
1743 +#define CC_CACHE_ALIGN \
1744 +       __attribute__ ((aligned (MEM_ALIGN_CACHE)))
1745 +#else
1746 +#define CC_CACHE_ALIGN                 /* nothing */
1747 +#endif
1748 +
1749 +#if ((__GNUC__ == 2) && (__GNUC_MINOR__ >= 7)) || (__GNUC__ > 2)
1750 +#define CC_PACKED                      __attribute__ ((packed))
1751 +#else
1752 +#define CC_PACKED                      /* nothing */
1753 +#endif
1754 +
1755  /*
1756   * ASCII <-> binary conversion tables.
1757   */
1758 @@ -27,6 +41,6 @@
1759  /*
1760   * Initializes the tables.
1761   */
1762 -extern void common_init();
1763 +extern void common_init(void);
1764  
1765  #endif
1766 diff -ruN john-1.6/src/compiler.c john-1.6.34/src/compiler.c
1767 --- john-1.6/src/compiler.c     1998-12-03 01:29:50.000000000 +0100
1768 +++ john-1.6.34/src/compiler.c  2000-08-26 05:50:54.000000000 +0200
1769 @@ -1,11 +1,13 @@
1770  /*
1771   * This file is part of John the Ripper password cracker,
1772 - * Copyright (c) 1996-98 by Solar Designer
1773 + * Copyright (c) 1996-2000 by Solar Designer
1774   */
1775  
1776  #include <stdio.h>
1777 +#include <stdlib.h>
1778  #include <string.h>
1779  #include <ctype.h>
1780 +#include <errno.h>
1781  
1782  #include "arch.h"
1783  #include "params.h"
1784 @@ -21,6 +23,7 @@
1785         "Expression is too complex",
1786         "Invalid array size",
1787         "Data section is too large",
1788 +       "Integer constant out of range",
1789         "Duplicate identifier",
1790         "Keyword is used as an identifier",
1791         "Not in a function",
1792 @@ -34,7 +37,7 @@
1793  int c_errno;
1794  
1795  union c_insn {
1796 -       void (*op)();
1797 +       void (*op)(void);
1798         c_int *mem;
1799         c_int imm;
1800         union c_insn *pc;
1801 @@ -67,12 +70,12 @@
1802  
1803  static char c_isident[0x100];
1804  #define c_isstart(c) \
1805 -       (c_isident[(ARCH_INDEX)(c)] && ((c) < '0' || (c) > '9'))
1806 +       (c_isident[ARCH_INDEX(c)] && ((c) < '0' || (c) > '9'))
1807  
1808  static int c_EOF;
1809  
1810 -static int (*c_ext_getchar)();
1811 -static void (*c_ext_rewind)();
1812 +static int (*c_ext_getchar)(void);
1813 +static void (*c_ext_rewind)(void);
1814  
1815  static char *c_reserved[] = {
1816         "void",
1817 @@ -98,7 +101,7 @@
1818         int dir;
1819         int class;
1820         char *name;
1821 -       void (*op)();
1822 +       void (*op)(void);
1823  };
1824  
1825  #ifdef __GNUC__
1826 @@ -107,7 +110,7 @@
1827  static struct c_op c_ops[38];
1828  #endif
1829  
1830 -static void c_init()
1831 +static void c_init(void)
1832  {
1833         int c;
1834  
1835 @@ -141,7 +144,7 @@
1836                 c_unget_buffer[c_unget_count++] = c;
1837  }
1838  
1839 -static char c_buffer_getchar()
1840 +static char c_buffer_getchar(void)
1841  {
1842         int c;
1843  
1844 @@ -195,12 +198,12 @@
1845         return c;
1846  }
1847  
1848 -static char *c_gettoken()
1849 +static char *c_gettoken(void)
1850  {
1851         static char token[C_TOKEN_SIZE];
1852         int pos = 0;
1853  
1854 -       while (c_isident[(ARCH_INDEX)(token[pos++] = c_getchar(0))])
1855 +       while (c_isident[ARCH_INDEX(token[pos++] = c_getchar(0))])
1856         if (pos >= C_TOKEN_SIZE) {
1857                 c_errno = C_ERROR_TOOLONG;
1858                 break;
1859 @@ -215,7 +218,8 @@
1860  static int c_getint(char *token)
1861  {
1862         int value;
1863 -       char *format;
1864 +       long l_value;
1865 +       char *error;
1866  
1867         if (token[0] == '\'') {
1868                 if ((value = c_getchar(1)) == '\'')
1869 @@ -224,20 +228,20 @@
1870                         if (value == '\\') value = c_getchar(1);
1871                 if (c_getchar(1) != '\'') c_errno = C_ERROR_UNEXPECTED;
1872         } else {
1873 -               if (token[0] != '0') format = "%d"; else
1874 -               if (token[1] != 'x') format = "%o"; else {
1875 -                       format = "%x";
1876 -                       token += 2;
1877 -               }
1878 -
1879 -               if (sscanf((char *)token, format, &value) != 1)
1880 +               errno = 0;
1881 +               l_value = strtol(token, &error, 0);
1882 +               value = (int)l_value;
1883 +               if (errno == ERANGE || (long)value != l_value)
1884 +                       c_errno = C_ERROR_RANGE;
1885 +               else
1886 +               if (!*token || *error || errno)
1887                         c_errno = C_ERROR_UNEXPECTED;
1888         }
1889  
1890         return value;
1891  }
1892  
1893 -static char c_skip_space()
1894 +static char c_skip_space(void)
1895  {
1896         char c;
1897  
1898 @@ -337,19 +341,20 @@
1899         }
1900  }
1901  
1902 -static void (*c_op_return)();
1903 -static void (*c_op_bz)();
1904 -static void (*c_op_ba)();
1905 -static void (*c_op_push_imm)();
1906 -static void (*c_op_push_mem)();
1907 -static void (*c_op_pop)();
1908 -
1909 -static void (*c_op_push_imm_imm)();
1910 -static void (*c_op_push_imm_mem)();
1911 -static void (*c_op_push_mem_imm)();
1912 -static void (*c_op_push_mem_mem)();
1913 +static void (*c_op_return)(void);
1914 +static void (*c_op_bz)(void);
1915 +static void (*c_op_ba)(void);
1916 +static void (*c_op_push_imm)(void);
1917 +static void (*c_op_push_mem)(void);
1918 +static void (*c_op_pop)(void);
1919 +
1920 +static void (*c_op_push_imm_imm)(void);
1921 +static void (*c_op_push_imm_mem)(void);
1922 +static void (*c_op_push_mem_imm)(void);
1923 +static void (*c_op_push_mem_mem)(void);
1924  
1925 -static void (*c_push(void (*last)(), void (*op)(), union c_insn *value))()
1926 +static void (*c_push
1927 +       (void (*last)(void), void (*op)(void), union c_insn *value))(void)
1928  {
1929         if (last == c_op_push_imm || last == c_op_push_mem) {
1930                 if (last == c_op_push_imm) {
1931 @@ -454,7 +459,7 @@
1932         int sp = 0;
1933         int balance = -1;
1934         int left = 0;
1935 -       void (*last)() = (void (*)())0;
1936 +       void (*last)(void) = (void (*)(void))0;
1937  
1938         if (term == ')') stack[sp++] = -1;
1939         do {
1940 @@ -497,7 +502,7 @@
1941                         left = 0;
1942                 } else
1943                 if (c != ' ') {
1944 -                       if (c_isident[(ARCH_INDEX)c])
1945 +                       if (c_isident[ARCH_INDEX(c)])
1946                                 var = c_find_ident(vars, NULL, token);
1947                         else
1948                                 var = NULL;
1949 @@ -515,7 +520,7 @@
1950                                 }
1951  
1952                                 if ((op = c_find_op(token, left)) < 0) {
1953 -                                       if (c_isident[(ARCH_INDEX)c])
1954 +                                       if (c_isident[ARCH_INDEX(c)])
1955                                                 c_errno = C_ERROR_UNKNOWN;
1956                                         else
1957                                                 c_errno = C_ERROR_UNEXPECTED;
1958 @@ -648,7 +653,7 @@
1959         return c_errno;
1960  }
1961  
1962 -static int c_continue()
1963 +static int c_continue(void)
1964  {
1965         if (!c_loop_start) return c_errno = C_ERROR_NOTINLOOP;
1966  
1967 @@ -664,7 +669,7 @@
1968         return c_errno;
1969  }
1970  
1971 -static int c_break(char term, struct c_ident *vars)
1972 +static int c_break(void)
1973  {
1974         struct c_fixup *fixup;
1975  
1976 @@ -737,7 +742,7 @@
1977                 } else
1978  
1979                 if (!strcmp(token, "break")) {
1980 -                       if (c_break(term, locals)) break;
1981 +                       if (c_break()) break;
1982                 } else
1983  
1984                 if (!strcmp(token, "return")) {
1985 @@ -761,7 +766,7 @@
1986  static void c_direct(union c_insn *addr);
1987  #endif
1988  
1989 -int c_compile(int (*ext_getchar)(), void (*ext_rewind)(),
1990 +int c_compile(int (*ext_getchar)(void), void (*ext_rewind)(void),
1991         struct c_ident *externs)
1992  {
1993  #ifdef __GNUC__
1994 @@ -800,7 +805,7 @@
1995  void c_execute(struct c_ident *fn)
1996  {
1997  #ifndef __GNUC__
1998 -       register void (*op)();
1999 +       register void (*op)(void);
2000  #endif
2001  
2002         if (!fn) return;
2003 @@ -1127,12 +1132,12 @@
2004  
2005  #endif
2006  
2007 -static void c_f_op_return()
2008 +static void c_f_op_return(void)
2009  {
2010         c_pc = (c_sp -= 2)->pc;
2011  }
2012  
2013 -static void c_f_op_bz()
2014 +static void c_f_op_bz(void)
2015  {
2016         if ((c_sp -= 2)->imm)
2017                 c_pc++;
2018 @@ -1140,36 +1145,36 @@
2019                 c_pc = c_pc->pc;
2020  }
2021  
2022 -static void c_f_op_ba()
2023 +static void c_f_op_ba(void)
2024  {
2025         c_pc = c_pc->pc;
2026  }
2027  
2028 -static void c_f_op_push_imm()
2029 +static void c_f_op_push_imm(void)
2030  {
2031         c_sp->imm = (c_pc++)->imm;
2032         c_sp += 2;
2033  }
2034  
2035 -static void c_f_op_push_mem()
2036 +static void c_f_op_push_mem(void)
2037  {
2038         (c_sp++)->imm = *c_pc->mem;
2039         (c_sp++)->mem = (c_pc++)->mem;
2040  }
2041  
2042 -static void c_f_op_pop()
2043 +static void c_f_op_pop(void)
2044  {
2045         c_sp -= 2;
2046  }
2047  
2048 -static void c_f_op_push_imm_imm()
2049 +static void c_f_op_push_imm_imm(void)
2050  {
2051         c_sp->imm = (c_pc++)->imm;
2052         (c_sp + 2)->imm = (c_pc++)->imm;
2053         c_sp += 4;
2054  }
2055  
2056 -static void c_f_op_push_imm_mem()
2057 +static void c_f_op_push_imm_mem(void)
2058  {
2059         c_sp->imm = (c_pc++)->imm;
2060         (c_sp + 2)->imm = *c_pc->mem;
2061 @@ -1177,7 +1182,7 @@
2062         c_sp += 4;
2063  }
2064  
2065 -static void c_f_op_push_mem_imm()
2066 +static void c_f_op_push_mem_imm(void)
2067  {
2068         c_sp->imm = *c_pc->mem;
2069         (c_sp + 1)->mem = (c_pc++)->mem;
2070 @@ -1185,7 +1190,7 @@
2071         c_sp += 4;
2072  }
2073  
2074 -static void c_f_op_push_mem_mem()
2075 +static void c_f_op_push_mem_mem(void)
2076  {
2077         c_sp->imm = *c_pc->mem;
2078         (c_sp + 1)->mem = (c_pc++)->mem;
2079 @@ -1194,220 +1199,220 @@
2080         c_sp += 4;
2081  }
2082  
2083 -static void c_op_index()
2084 +static void c_op_index(void)
2085  {
2086         c_sp -= 2;
2087         (c_sp - 2)->imm = *((c_sp - 1)->mem += c_sp->imm);
2088  }
2089  
2090 -static void c_op_assign()
2091 +static void c_op_assign(void)
2092  {
2093         c_sp -= 2;
2094         (c_sp - 2)->imm = *(c_sp - 1)->mem = c_sp->imm;
2095  }
2096  
2097 -static void c_op_add_a()
2098 +static void c_op_add_a(void)
2099  {
2100         c_sp -= 2;
2101         (c_sp - 2)->imm = *(c_sp - 1)->mem += c_sp->imm;
2102  }
2103  
2104 -static void c_op_sub_a()
2105 +static void c_op_sub_a(void)
2106  {
2107         c_sp -= 2;
2108         (c_sp - 2)->imm = *(c_sp - 1)->mem -= c_sp->imm;
2109  }
2110  
2111 -static void c_op_mul_a()
2112 +static void c_op_mul_a(void)
2113  {
2114         c_sp -= 2;
2115         (c_sp - 2)->imm = *(c_sp - 1)->mem *= c_sp->imm;
2116  }
2117  
2118 -static void c_op_div_a()
2119 +static void c_op_div_a(void)
2120  {
2121         c_sp -= 2;
2122         (c_sp - 2)->imm = *(c_sp - 1)->mem /= c_sp->imm;
2123  }
2124  
2125 -static void c_op_mod_a()
2126 +static void c_op_mod_a(void)
2127  {
2128         c_sp -= 2;
2129         (c_sp - 2)->imm = *(c_sp - 1)->mem %= c_sp->imm;
2130  }
2131  
2132 -static void c_op_or_a()
2133 +static void c_op_or_a(void)
2134  {
2135         c_sp -= 2;
2136         (c_sp - 2)->imm = *(c_sp - 1)->mem |= c_sp->imm;
2137  }
2138  
2139 -static void c_op_xor_a()
2140 +static void c_op_xor_a(void)
2141  {
2142         c_sp -= 2;
2143         (c_sp - 2)->imm = *(c_sp - 1)->mem ^= c_sp->imm;
2144  }
2145  
2146 -static void c_op_and_a()
2147 +static void c_op_and_a(void)
2148  {
2149         c_sp -= 2;
2150         (c_sp - 2)->imm = *(c_sp - 1)->mem &= c_sp->imm;
2151  }
2152  
2153 -static void c_op_shl_a()
2154 +static void c_op_shl_a(void)
2155  {
2156         c_sp -= 2;
2157         (c_sp - 2)->imm = *(c_sp - 1)->mem <<= c_sp->imm;
2158  }
2159  
2160 -static void c_op_shr_a()
2161 +static void c_op_shr_a(void)
2162  {
2163         c_sp -= 2;
2164         (c_sp - 2)->imm = *(c_sp - 1)->mem >>= c_sp->imm;
2165  }
2166  
2167 -static void c_op_or_i()
2168 +static void c_op_or_i(void)
2169  {
2170         c_sp -= 2;
2171         (c_sp - 2)->imm |= c_sp->imm;
2172  }
2173  
2174 -static void c_op_and_b()
2175 +static void c_op_and_b(void)
2176  {
2177         c_sp -= 2;
2178         (c_sp - 2)->imm = (c_sp - 2)->imm && c_sp->imm;
2179  }
2180  
2181 -static void c_op_not_b()
2182 +static void c_op_not_b(void)
2183  {
2184         (c_sp - 2)->imm = !(c_sp - 2)->imm;
2185  }
2186  
2187 -static void c_op_eq()
2188 +static void c_op_eq(void)
2189  {
2190         c_sp -= 2;
2191         (c_sp - 2)->imm = (c_sp - 2)->imm == c_sp->imm;
2192  }
2193  
2194 -static void c_op_gt()
2195 +static void c_op_gt(void)
2196  {
2197         c_sp -= 2;
2198         (c_sp - 2)->imm = (c_sp - 2)->imm > c_sp->imm;
2199  }
2200  
2201 -static void c_op_lt()
2202 +static void c_op_lt(void)
2203  {
2204         c_sp -= 2;
2205         (c_sp - 2)->imm = (c_sp - 2)->imm < c_sp->imm;
2206  }
2207  
2208 -static void c_op_ge()
2209 +static void c_op_ge(void)
2210  {
2211         c_sp -= 2;
2212         (c_sp - 2)->imm = (c_sp - 2)->imm >= c_sp->imm;
2213  }
2214  
2215 -static void c_op_le()
2216 +static void c_op_le(void)
2217  {
2218         c_sp -= 2;
2219         (c_sp - 2)->imm = (c_sp - 2)->imm <= c_sp->imm;
2220  }
2221  
2222 -static void c_op_xor_i()
2223 +static void c_op_xor_i(void)
2224  {
2225         c_sp -= 2;
2226         (c_sp - 2)->imm ^= c_sp->imm;
2227  }
2228  
2229 -static void c_op_and_i()
2230 +static void c_op_and_i(void)
2231  {
2232         c_sp -= 2;
2233         (c_sp - 2)->imm &= c_sp->imm;
2234  }
2235  
2236 -static void c_op_shl()
2237 +static void c_op_shl(void)
2238  {
2239         c_sp -= 2;
2240         (c_sp - 2)->imm <<= c_sp->imm;
2241  }
2242  
2243 -static void c_op_shr()
2244 +static void c_op_shr(void)
2245  {
2246         c_sp -= 2;
2247         (c_sp - 2)->imm >>= c_sp->imm;
2248  }
2249  
2250 -static void c_op_add()
2251 +static void c_op_add(void)
2252  {
2253         c_sp -= 2;
2254         (c_sp - 2)->imm += c_sp->imm;
2255  }
2256  
2257 -static void c_op_sub()
2258 +static void c_op_sub(void)
2259  {
2260         c_sp -= 2;
2261         (c_sp - 2)->imm -= c_sp->imm;
2262  }
2263  
2264 -static void c_op_mul()
2265 +static void c_op_mul(void)
2266  {
2267         c_sp -= 2;
2268         (c_sp - 2)->imm *= c_sp->imm;
2269  }
2270  
2271 -static void c_op_div()
2272 +static void c_op_div(void)
2273  {
2274         c_sp -= 2;
2275         (c_sp - 2)->imm /= c_sp->imm;
2276  }
2277  
2278 -static void c_op_mod()
2279 +static void c_op_mod(void)
2280  {
2281         c_sp -= 2;
2282         (c_sp - 2)->imm %= c_sp->imm;
2283  }
2284  
2285 -static void c_op_not_i()
2286 +static void c_op_not_i(void)
2287  {
2288         (c_sp - 2)->imm = ~(c_sp - 2)->imm;
2289  }
2290  
2291 -static void c_op_neg()
2292 +static void c_op_neg(void)
2293  {
2294         (c_sp - 2)->imm = -(c_sp - 2)->imm;
2295  }
2296  
2297 -static void c_op_inc_l()
2298 +static void c_op_inc_l(void)
2299  {
2300         *(c_sp - 1)->mem = ++(c_sp - 2)->imm;
2301  }
2302  
2303 -static void c_op_dec_l()
2304 +static void c_op_dec_l(void)
2305  {
2306         *(c_sp - 1)->mem = --(c_sp - 2)->imm;
2307  }
2308  
2309 -static void c_op_inc_r()
2310 +static void c_op_inc_r(void)
2311  {
2312         *(c_sp - 1)->mem = (c_sp - 2)->imm + 1;
2313  }
2314  
2315 -static void c_op_dec_r()
2316 +static void c_op_dec_r(void)
2317  {
2318         *(c_sp - 1)->mem = (c_sp - 2)->imm - 1;
2319  }
2320  
2321 -static void (*c_op_return)() = c_f_op_return;
2322 -static void (*c_op_bz)() = c_f_op_bz;
2323 -static void (*c_op_ba)() = c_f_op_ba;
2324 -static void (*c_op_push_imm)() = c_f_op_push_imm;
2325 -static void (*c_op_push_mem)() = c_f_op_push_mem;
2326 -static void (*c_op_pop)() = c_f_op_pop;
2327 -
2328 -static void (*c_op_push_imm_imm)() = c_f_op_push_imm_imm;
2329 -static void (*c_op_push_imm_mem)() = c_f_op_push_imm_mem;
2330 -static void (*c_op_push_mem_imm)() = c_f_op_push_mem_imm;
2331 -static void (*c_op_push_mem_mem)() = c_f_op_push_mem_mem;
2332 +static void (*c_op_return)(void) = c_f_op_return;
2333 +static void (*c_op_bz)(void) = c_f_op_bz;
2334 +static void (*c_op_ba)(void) = c_f_op_ba;
2335 +static void (*c_op_push_imm)(void) = c_f_op_push_imm;
2336 +static void (*c_op_push_mem)(void) = c_f_op_push_mem;
2337 +static void (*c_op_pop)(void) = c_f_op_pop;
2338 +
2339 +static void (*c_op_push_imm_imm)(void) = c_f_op_push_imm_imm;
2340 +static void (*c_op_push_imm_mem)(void) = c_f_op_push_imm_mem;
2341 +static void (*c_op_push_mem_imm)(void) = c_f_op_push_mem_imm;
2342 +static void (*c_op_push_mem_mem)(void) = c_f_op_push_mem_mem;
2343  
2344  static struct c_op c_ops[] = {
2345         {1, C_LEFT_TO_RIGHT, C_CLASS_BINARY, "[", c_op_index},
2346 diff -ruN john-1.6/src/compiler.h john-1.6.34/src/compiler.h
2347 --- john-1.6/src/compiler.h     1998-12-03 01:29:50.000000000 +0100
2348 +++ john-1.6.34/src/compiler.h  2000-08-26 05:25:23.000000000 +0200
2349 @@ -1,6 +1,6 @@
2350  /*
2351   * This file is part of John the Ripper password cracker,
2352 - * Copyright (c) 1996-98 by Solar Designer
2353 + * Copyright (c) 1996-2000 by Solar Designer
2354   */
2355  
2356  /*
2357 @@ -21,14 +21,15 @@
2358  #define C_ERROR_TOOCOMPLEX             5
2359  #define C_ERROR_ARRAYSIZE              6
2360  #define C_ERROR_DATASIZE               7
2361 -#define C_ERROR_DUPE                   8
2362 -#define C_ERROR_RESERVED               9
2363 -#define C_ERROR_NOTINFUNC              10
2364 -#define C_ERROR_NESTEDFUNC             11
2365 -#define C_ERROR_NOTINIF                        12
2366 -#define C_ERROR_NOTINLOOP              13
2367 -#define C_ERROR_EOF                    14
2368 -#define C_ERROR_INTERNAL               15
2369 +#define C_ERROR_RANGE                  8
2370 +#define C_ERROR_DUPE                   9
2371 +#define C_ERROR_RESERVED               10
2372 +#define C_ERROR_NOTINFUNC              11
2373 +#define C_ERROR_NESTEDFUNC             12
2374 +#define C_ERROR_NOTINIF                        13
2375 +#define C_ERROR_NOTINLOOP              14
2376 +#define C_ERROR_EOF                    15
2377 +#define C_ERROR_INTERNAL               16
2378  
2379  /*
2380   * Error names.
2381 @@ -63,7 +64,7 @@
2382   * Runs the compiler, and allocates some memory for its output and the
2383   * program's data. Returns one of the error codes.
2384   */
2385 -extern int c_compile(int (*ext_getchar)(), void (*ext_rewind)(),
2386 +extern int c_compile(int (*ext_getchar)(void), void (*ext_rewind)(void),
2387         struct c_ident *externs);
2388  
2389  /*
2390 diff -ruN john-1.6/src/config.c john-1.6.34/src/config.c
2391 --- john-1.6/src/config.c       1998-12-03 01:29:50.000000000 +0100
2392 +++ john-1.6.34/src/config.c    2002-10-03 06:15:39.000000000 +0200
2393 @@ -1,12 +1,13 @@
2394  /*
2395   * This file is part of John the Ripper password cracker,
2396 - * Copyright (c) 1996-98 by Solar Designer
2397 + * Copyright (c) 1996-2002 by Solar Designer
2398   */
2399  
2400  #include <stdio.h>
2401  #include <stdlib.h>
2402  #include <string.h>
2403  #include <ctype.h>
2404 +#include <errno.h>
2405  
2406  #include "misc.h"
2407  #include "params.h"
2408 @@ -14,6 +15,7 @@
2409  #include "memory.h"
2410  #include "config.h"
2411  
2412 +char *cfg_name = NULL;
2413  static struct cfg_section *cfg_database = NULL;
2414  
2415  static char *trim(char *s)
2416 @@ -112,7 +114,7 @@
2417         error();
2418  }
2419  
2420 -void cfg_init(char *name)
2421 +void cfg_init(char *name, int allow_missing)
2422  {
2423         FILE *file;
2424         char line[LINE_BUFFER_SIZE];
2425 @@ -120,8 +122,10 @@
2426  
2427         if (cfg_database) return;
2428  
2429 -       if (!(file = fopen(path_expand(name), "r")))
2430 +       if (!(file = fopen(path_expand(name), "r"))) {
2431 +               if (allow_missing && errno == ENOENT) return;
2432                 pexit("fopen: %s", path_expand(name));
2433 +       }
2434  
2435         number = 0;
2436         while (fgetl(line, sizeof(line), file))
2437 @@ -130,6 +134,8 @@
2438         if (ferror(file)) pexit("fgets");
2439  
2440         if (fclose(file)) pexit("fclose");
2441 +
2442 +       cfg_name = str_alloc_copy(path_expand(name));
2443  }
2444  
2445  static struct cfg_section *cfg_get_section(char *section, char *subsection)
2446 @@ -191,10 +197,15 @@
2447  
2448  int cfg_get_int(char *section, char *subsection, char *param)
2449  {
2450 -       char *value;
2451 +       char *s_value, *error;
2452 +       long l_value;
2453  
2454 -       if ((value = cfg_get_param(section, subsection, param)))
2455 -               return atoi(value);
2456 +       if ((s_value = cfg_get_param(section, subsection, param))) {
2457 +               l_value = strtol(s_value, &error, 10);
2458 +               if (!*s_value || *error || (l_value & ~0x3FFFFFFFL))
2459 +                       return -1;
2460 +               return (int)l_value;
2461 +       }
2462  
2463         return -1;
2464  }
2465 @@ -209,10 +220,8 @@
2466         case 'Y':
2467         case 't':
2468         case 'T':
2469 +       case '1':
2470                 return 1;
2471 -
2472 -       default:
2473 -               return atoi(value);
2474         }
2475  
2476         return 0;
2477 diff -ruN john-1.6/src/config.h john-1.6.34/src/config.h
2478 --- john-1.6/src/config.h       1998-12-03 01:29:50.000000000 +0100
2479 +++ john-1.6.34/src/config.h    2000-03-15 00:23:25.000000000 +0100
2480 @@ -1,6 +1,6 @@
2481  /*
2482   * This file is part of John the Ripper password cracker,
2483 - * Copyright (c) 1996-98 by Solar Designer
2484 + * Copyright (c) 1996-2000 by Solar Designer
2485   */
2486  
2487  /*
2488 @@ -46,9 +46,14 @@
2489  };
2490  
2491  /*
2492 - * Loads a configuration file.
2493 + * Name of the currently loaded configuration file, or NULL for none.
2494   */
2495 -extern void cfg_init(char *name);
2496 +extern char *cfg_name;
2497 +
2498 +/*
2499 + * Loads a configuration file, or does nothing if one is already loaded.
2500 + */
2501 +extern void cfg_init(char *name, int allow_missing);
2502  
2503  /*
2504   * Searches for a section with the supplied name, and returns its line list
2505 diff -ruN john-1.6/src/cracker.c john-1.6.34/src/cracker.c
2506 --- john-1.6/src/cracker.c      1998-12-03 01:29:50.000000000 +0100
2507 +++ john-1.6.34/src/cracker.c   2002-09-05 07:56:20.000000000 +0200
2508 @@ -1,6 +1,6 @@
2509  /*
2510   * This file is part of John the Ripper password cracker,
2511 - * Copyright (c) 1996-98 by Solar Designer
2512 + * Copyright (c) 1996-2002 by Solar Designer
2513   */
2514  
2515  #include <string.h>
2516 @@ -27,7 +27,7 @@
2517  static struct fmt_methods crk_methods;
2518  static int crk_key_index, crk_last_key;
2519  static void *crk_last_salt;
2520 -static void (*crk_fix_state)();
2521 +static void (*crk_fix_state)(void);
2522  static struct db_keys *crk_guesses;
2523  static int64 *crk_timestamps;
2524  static char crk_stdout_key[PLAINTEXT_BUFFER_SIZE];
2525 @@ -36,11 +36,11 @@
2526  {
2527  }
2528  
2529 -static void crk_dummy_fix_state()
2530 +static void crk_dummy_fix_state(void)
2531  {
2532  }
2533  
2534 -static void crk_init_salt()
2535 +static void crk_init_salt(void)
2536  {
2537         if (!crk_db->salts->next) {
2538                 crk_methods.set_salt(crk_db->salts->salt);
2539 @@ -48,14 +48,15 @@
2540         }
2541  }
2542  
2543 -void crk_init(struct db_main *db, void (*fix_state)(),
2544 +void crk_init(struct db_main *db, void (*fix_state)(void),
2545         struct db_keys *guesses)
2546  {
2547 +       char *where;
2548         size_t size;
2549  
2550         if (db->loaded)
2551 -       if (fmt_self_test(db->format)) {
2552 -               fprintf(stderr, "Self test failed\n");
2553 +       if ((where = fmt_self_test(db->format))) {
2554 +               fprintf(stderr, "Self test failed (%s)\n", where);
2555                 error();
2556         }
2557  
2558 @@ -105,7 +106,7 @@
2559         crk_db->guess_count++;
2560         status.guess_count++;
2561  
2562 -       if (crk_guesses) {
2563 +       if (crk_guesses && !dupe) {
2564                 strnfcpy(crk_guesses->ptr, key, crk_params.plaintext_length);
2565                 crk_guesses->ptr += crk_params.plaintext_length;
2566                 crk_guesses->count++;
2567 @@ -142,7 +143,7 @@
2568         return 0;
2569  }
2570  
2571 -static int crk_process_event()
2572 +static int crk_process_event(void)
2573  {
2574         event_pending = 0;
2575  
2576 @@ -168,11 +169,11 @@
2577         sig_timer_emu_tick();
2578  #endif
2579  
2580 +       idle_yield();
2581 +
2582         if (event_pending)
2583         if (crk_process_event()) return 1;
2584  
2585 -       idle_yield(0);
2586 -
2587         crk_methods.crypt_all(crk_key_index);
2588  
2589         status_update_crypts(salt->count * crk_key_index);
2590 @@ -204,7 +205,7 @@
2591         return 0;
2592  }
2593  
2594 -static int crk_salt_loop()
2595 +static int crk_salt_loop(void)
2596  {
2597         struct db_salt *salt;
2598  
2599 @@ -218,6 +219,8 @@
2600         crk_last_salt = NULL;
2601         crk_fix_state();
2602  
2603 +       crk_methods.clear_keys();
2604 +
2605         return 0;
2606  }
2607  
2608 @@ -265,6 +268,8 @@
2609         count = salt->keys->count;
2610         index = 0;
2611  
2612 +       crk_methods.clear_keys();
2613 +
2614         while (count--) {
2615                 strnzcpy(key, ptr, crk_params.plaintext_length + 1);
2616                 ptr += crk_params.plaintext_length;
2617 @@ -281,7 +286,7 @@
2618         return 0;
2619  }
2620  
2621 -char *crk_get_key1()
2622 +char *crk_get_key1(void)
2623  {
2624         if (crk_db->loaded)
2625                 return crk_methods.get_key(0);
2626 @@ -289,7 +294,7 @@
2627                 return crk_stdout_key;
2628  }
2629  
2630 -char *crk_get_key2()
2631 +char *crk_get_key2(void)
2632  {
2633         if (crk_key_index > 1)
2634                 return crk_methods.get_key(crk_key_index - 1);
2635 @@ -300,7 +305,7 @@
2636                 return NULL;
2637  }
2638  
2639 -void crk_done()
2640 +void crk_done(void)
2641  {
2642         if (crk_db->loaded) {
2643                 if (crk_key_index && crk_db->salts && !event_abort)
2644 diff -ruN john-1.6/src/cracker.h john-1.6.34/src/cracker.h
2645 --- john-1.6/src/cracker.h      1998-12-03 01:29:50.000000000 +0100
2646 +++ john-1.6.34/src/cracker.h   1999-09-22 05:40:07.000000000 +0200
2647 @@ -1,6 +1,6 @@
2648  /*
2649   * This file is part of John the Ripper password cracker,
2650 - * Copyright (c) 1996-98 by Solar Designer
2651 + * Copyright (c) 1996-99 by Solar Designer
2652   */
2653  
2654  /*
2655 @@ -19,7 +19,7 @@
2656   * the future. If guesses is not NULL, the cracker will save guessed keys
2657   * in there (the caller must make sure there's room).
2658   */
2659 -extern void crk_init(struct db_main *db, void (*fix_state)(),
2660 +extern void crk_init(struct db_main *db, void (*fix_state)(void),
2661         struct db_keys *guesses);
2662  
2663  /*
2664 @@ -39,12 +39,12 @@
2665   * Return current keys range, crk_get_key2() may return NULL if there's only
2666   * one key. Note: these functions may share a static result buffer.
2667   */
2668 -extern char *crk_get_key1();
2669 -extern char *crk_get_key2();
2670 +extern char *crk_get_key1(void);
2671 +extern char *crk_get_key2(void);
2672  
2673  /*
2674   * Processes all the buffered keys (unless aborted).
2675   */
2676 -extern void crk_done();
2677 +extern void crk_done(void);
2678  
2679  #endif
2680 diff -ruN john-1.6/src/DES_bs_b.c john-1.6.34/src/DES_bs_b.c
2681 --- john-1.6/src/DES_bs_b.c     1998-12-03 01:29:50.000000000 +0100
2682 +++ john-1.6.34/src/DES_bs_b.c  2001-06-16 08:57:44.000000000 +0200
2683 @@ -1,77 +1,440 @@
2684  /*
2685   * This file is part of John the Ripper password cracker,
2686 - * Copyright (c) 1996-98 by Solar Designer
2687 - */
2688 -
2689 -/*
2690 - * Bitslice DES encryption.
2691 + * Copyright (c) 1996-2001 by Solar bdesigner
2692   */
2693  
2694  #include "arch.h"
2695 +
2696 +#if !DES_BS_ASM
2697  #include "DES_bs.h"
2698  
2699  /* Include the S-boxes here, so that the compiler can inline them */
2700  #include "DES_bs_s.c"
2701  
2702  #define b                              DES_bs_all.B
2703 -#define e                              DES_bs_all.E
2704 +#define e                              DES_bs_all.E.E
2705 +
2706 +#if DES_BS_VECTOR
2707 +#define kd                             [depth]
2708 +#define bd                             [depth]
2709 +#define ed                             [depth]
2710 +#define for_each_depth() \
2711 +       for (depth = 0; depth < DES_BS_VECTOR; depth++)
2712 +#else
2713 +#if DES_BS_EXPAND
2714 +#define kd
2715 +#else
2716 +#define kd                             [0]
2717 +#endif
2718 +#define bd
2719 +#define ed                             [0]
2720 +#define for_each_depth()
2721 +#endif
2722  
2723 -void DES_bs_body()
2724 +#define DES_bs_clear_block_8(i) \
2725 +       for_each_depth() { \
2726 +               b[i] bd = 0; \
2727 +               b[i + 1] bd = 0; \
2728 +               b[i + 2] bd = 0; \
2729 +               b[i + 3] bd = 0; \
2730 +               b[i + 4] bd = 0; \
2731 +               b[i + 5] bd = 0; \
2732 +               b[i + 6] bd = 0; \
2733 +               b[i + 7] bd = 0; \
2734 +       }
2735 +
2736 +#define DES_bs_clear_block() \
2737 +       DES_bs_clear_block_8(0); \
2738 +       DES_bs_clear_block_8(8); \
2739 +       DES_bs_clear_block_8(16); \
2740 +       DES_bs_clear_block_8(24); \
2741 +       DES_bs_clear_block_8(32); \
2742 +       DES_bs_clear_block_8(40); \
2743 +       DES_bs_clear_block_8(48); \
2744 +       DES_bs_clear_block_8(56);
2745 +
2746 +void DES_bs_crypt(int count)
2747  {
2748 -       ARCH_WORD **k = DES_bs_all.Kp;
2749 -       int count = 8;
2750 +#if DES_BS_EXPAND
2751 +       DES_bs_vector *k;
2752 +#else
2753 +       ARCH_WORD **k;
2754 +#endif
2755 +       int iterations, rounds_and_swapped;
2756 +#if DES_BS_VECTOR
2757 +       int depth;
2758 +#endif
2759 +
2760 +       DES_bs_clear_block();
2761 +
2762 +#if DES_BS_EXPAND
2763 +       k = DES_bs_all.KS.v;
2764 +#else
2765 +       k = DES_bs_all.KS.p;
2766 +#endif
2767 +       rounds_and_swapped = 8;
2768 +       iterations = count;
2769 +
2770 +start:
2771 +       for_each_depth()
2772 +       s1(e[0] ed ^ k[0] kd, e[1] ed ^ k[1] kd, e[2] ed ^ k[2] kd,
2773 +               e[3] ed ^ k[3] kd, e[4] ed ^ k[4] kd, e[5] ed ^ k[5] kd,
2774 +               &b[40] bd, &b[48] bd, &b[54] bd, &b[62] bd);
2775 +       for_each_depth()
2776 +       s2(e[6] ed ^ k[6] kd, e[7] ed ^ k[7] kd, e[8] ed ^ k[8] kd,
2777 +               e[9] ed ^ k[9] kd, e[10] ed ^ k[10] kd, e[11] ed ^ k[11] kd,
2778 +               &b[44] bd, &b[59] bd, &b[33] bd, &b[49] bd);
2779 +       for_each_depth()
2780 +       s3(e[12] ed ^ k[12] kd, e[13] ed ^ k[13] kd, e[14] ed ^ k[14] kd,
2781 +               e[15] ed ^ k[15] kd, e[16] ed ^ k[16] kd, e[17] ed ^ k[17] kd,
2782 +               &b[55] bd, &b[47] bd, &b[61] bd, &b[37] bd);
2783 +       for_each_depth()
2784 +       s4(e[18] ed ^ k[18] kd, e[19] ed ^ k[19] kd, e[20] ed ^ k[20] kd,
2785 +               e[21] ed ^ k[21] kd, e[22] ed ^ k[22] kd, e[23] ed ^ k[23] kd,
2786 +               &b[57] bd, &b[51] bd, &b[41] bd, &b[32] bd);
2787 +       for_each_depth()
2788 +       s5(e[24] ed ^ k[24] kd, e[25] ed ^ k[25] kd, e[26] ed ^ k[26] kd,
2789 +               e[27] ed ^ k[27] kd, e[28] ed ^ k[28] kd, e[29] ed ^ k[29] kd,
2790 +               &b[39] bd, &b[45] bd, &b[56] bd, &b[34] bd);
2791 +       for_each_depth()
2792 +       s6(e[30] ed ^ k[30] kd, e[31] ed ^ k[31] kd, e[32] ed ^ k[32] kd,
2793 +               e[33] ed ^ k[33] kd, e[34] ed ^ k[34] kd, e[35] ed ^ k[35] kd,
2794 +               &b[35] bd, &b[60] bd, &b[42] bd, &b[50] bd);
2795 +       for_each_depth()
2796 +       s7(e[36] ed ^ k[36] kd, e[37] ed ^ k[37] kd, e[38] ed ^ k[38] kd,
2797 +               e[39] ed ^ k[39] kd, e[40] ed ^ k[40] kd, e[41] ed ^ k[41] kd,
2798 +               &b[63] bd, &b[43] bd, &b[53] bd, &b[38] bd);
2799 +       for_each_depth()
2800 +       s8(e[42] ed ^ k[42] kd, e[43] ed ^ k[43] kd, e[44] ed ^ k[44] kd,
2801 +               e[45] ed ^ k[45] kd, e[46] ed ^ k[46] kd, e[47] ed ^ k[47] kd,
2802 +               &b[36] bd, &b[58] bd, &b[46] bd, &b[52] bd);
2803 +
2804 +       if (rounds_and_swapped == 0x100) goto next;
2805 +
2806 +swap:
2807 +       for_each_depth()
2808 +       s1(e[48] ed ^ k[48] kd, e[49] ed ^ k[49] kd, e[50] ed ^ k[50] kd,
2809 +               e[51] ed ^ k[51] kd, e[52] ed ^ k[52] kd, e[53] ed ^ k[53] kd,
2810 +               &b[8] bd, &b[16] bd, &b[22] bd, &b[30] bd);
2811 +       for_each_depth()
2812 +       s2(e[54] ed ^ k[54] kd, e[55] ed ^ k[55] kd, e[56] ed ^ k[56] kd,
2813 +               e[57] ed ^ k[57] kd, e[58] ed ^ k[58] kd, e[59] ed ^ k[59] kd,
2814 +               &b[12] bd, &b[27] bd, &b[1] bd, &b[17] bd);
2815 +       for_each_depth()
2816 +       s3(e[60] ed ^ k[60] kd, e[61] ed ^ k[61] kd, e[62] ed ^ k[62] kd,
2817 +               e[63] ed ^ k[63] kd, e[64] ed ^ k[64] kd, e[65] ed ^ k[65] kd,
2818 +               &b[23] bd, &b[15] bd, &b[29] bd, &b[5] bd);
2819 +       for_each_depth()
2820 +       s4(e[66] ed ^ k[66] kd, e[67] ed ^ k[67] kd, e[68] ed ^ k[68] kd,
2821 +               e[69] ed ^ k[69] kd, e[70] ed ^ k[70] kd, e[71] ed ^ k[71] kd,
2822 +               &b[25] bd, &b[19] bd, &b[9] bd, &b[0] bd);
2823 +       for_each_depth()
2824 +       s5(e[72] ed ^ k[72] kd, e[73] ed ^ k[73] kd, e[74] ed ^ k[74] kd,
2825 +               e[75] ed ^ k[75] kd, e[76] ed ^ k[76] kd, e[77] ed ^ k[77] kd,
2826 +               &b[7] bd, &b[13] bd, &b[24] bd, &b[2] bd);
2827 +       for_each_depth()
2828 +       s6(e[78] ed ^ k[78] kd, e[79] ed ^ k[79] kd, e[80] ed ^ k[80] kd,
2829 +               e[81] ed ^ k[81] kd, e[82] ed ^ k[82] kd, e[83] ed ^ k[83] kd,
2830 +               &b[3] bd, &b[28] bd, &b[10] bd, &b[18] bd);
2831 +       for_each_depth()
2832 +       s7(e[84] ed ^ k[84] kd, e[85] ed ^ k[85] kd, e[86] ed ^ k[86] kd,
2833 +               e[87] ed ^ k[87] kd, e[88] ed ^ k[88] kd, e[89] ed ^ k[89] kd,
2834 +               &b[31] bd, &b[11] bd, &b[21] bd, &b[6] bd);
2835 +       for_each_depth()
2836 +       s8(e[90] ed ^ k[90] kd, e[91] ed ^ k[91] kd, e[92] ed ^ k[92] kd,
2837 +               e[93] ed ^ k[93] kd, e[94] ed ^ k[94] kd, e[95] ed ^ k[95] kd,
2838 +               &b[4] bd, &b[26] bd, &b[14] bd, &b[20] bd);
2839 +
2840 +       k += 96;
2841 +
2842 +       if (--rounds_and_swapped) goto start;
2843 +       k -= (0x300 + 48);
2844 +       rounds_and_swapped = 0x108;
2845 +       if (--iterations) goto swap;
2846 +       return;
2847 +
2848 +next:
2849 +       k -= (0x300 - 48);
2850 +       rounds_and_swapped = 8;
2851 +       if (--iterations) goto start;
2852 +}
2853 +
2854 +void DES_bs_crypt_25(void)
2855 +{
2856 +#if DES_BS_EXPAND
2857 +       DES_bs_vector *k;
2858 +#else
2859 +       ARCH_WORD **k;
2860 +#endif
2861 +       int iterations, rounds_and_swapped;
2862 +#if DES_BS_VECTOR
2863 +       int depth;
2864 +#endif
2865 +
2866 +       DES_bs_clear_block();
2867 +
2868 +#if DES_BS_EXPAND
2869 +       k = DES_bs_all.KS.v;
2870 +#else
2871 +       k = DES_bs_all.KS.p;
2872 +#endif
2873 +       rounds_and_swapped = 8;
2874 +       iterations = 25;
2875 +
2876 +start:
2877 +       for_each_depth()
2878 +       s1(e[0] ed ^ k[0] kd, e[1] ed ^ k[1] kd, e[2] ed ^ k[2] kd,
2879 +               e[3] ed ^ k[3] kd, e[4] ed ^ k[4] kd, e[5] ed ^ k[5] kd,
2880 +               &b[40] bd, &b[48] bd, &b[54] bd, &b[62] bd);
2881 +       for_each_depth()
2882 +       s2(e[6] ed ^ k[6] kd, e[7] ed ^ k[7] kd, e[8] ed ^ k[8] kd,
2883 +               e[9] ed ^ k[9] kd, e[10] ed ^ k[10] kd, e[11] ed ^ k[11] kd,
2884 +               &b[44] bd, &b[59] bd, &b[33] bd, &b[49] bd);
2885 +       for_each_depth()
2886 +       s3(b[7] bd ^ k[12] kd, b[8] bd ^ k[13] kd, b[9] bd ^ k[14] kd,
2887 +               b[10] bd ^ k[15] kd, b[11] bd ^ k[16] kd, b[12] bd ^ k[17] kd,
2888 +               &b[55] bd, &b[47] bd, &b[61] bd, &b[37] bd);
2889 +       for_each_depth()
2890 +       s4(b[11] bd ^ k[18] kd, b[12] bd ^ k[19] kd, b[13] bd ^ k[20] kd,
2891 +               b[14] bd ^ k[21] kd, b[15] bd ^ k[22] kd, b[16] bd ^ k[23] kd,
2892 +               &b[57] bd, &b[51] bd, &b[41] bd, &b[32] bd);
2893 +       for_each_depth()
2894 +       s5(e[24] ed ^ k[24] kd, e[25] ed ^ k[25] kd, e[26] ed ^ k[26] kd,
2895 +               e[27] ed ^ k[27] kd, e[28] ed ^ k[28] kd, e[29] ed ^ k[29] kd,
2896 +               &b[39] bd, &b[45] bd, &b[56] bd, &b[34] bd);
2897 +       for_each_depth()
2898 +       s6(e[30] ed ^ k[30] kd, e[31] ed ^ k[31] kd, e[32] ed ^ k[32] kd,
2899 +               e[33] ed ^ k[33] kd, e[34] ed ^ k[34] kd, e[35] ed ^ k[35] kd,
2900 +               &b[35] bd, &b[60] bd, &b[42] bd, &b[50] bd);
2901 +       for_each_depth()
2902 +       s7(b[23] bd ^ k[36] kd, b[24] bd ^ k[37] kd, b[25] bd ^ k[38] kd,
2903 +               b[26] bd ^ k[39] kd, b[27] bd ^ k[40] kd, b[28] bd ^ k[41] kd,
2904 +               &b[63] bd, &b[43] bd, &b[53] bd, &b[38] bd);
2905 +       for_each_depth()
2906 +       s8(b[27] bd ^ k[42] kd, b[28] bd ^ k[43] kd, b[29] bd ^ k[44] kd,
2907 +               b[30] bd ^ k[45] kd, b[31] bd ^ k[46] kd, b[0] bd ^ k[47] kd,
2908 +               &b[36] bd, &b[58] bd, &b[46] bd, &b[52] bd);
2909 +
2910 +       if (rounds_and_swapped == 0x100) goto next;
2911 +
2912 +swap:
2913 +       for_each_depth()
2914 +       s1(e[48] ed ^ k[48] kd, e[49] ed ^ k[49] kd, e[50] ed ^ k[50] kd,
2915 +               e[51] ed ^ k[51] kd, e[52] ed ^ k[52] kd, e[53] ed ^ k[53] kd,
2916 +               &b[8] bd, &b[16] bd, &b[22] bd, &b[30] bd);
2917 +       for_each_depth()
2918 +       s2(e[54] ed ^ k[54] kd, e[55] ed ^ k[55] kd, e[56] ed ^ k[56] kd,
2919 +               e[57] ed ^ k[57] kd, e[58] ed ^ k[58] kd, e[59] ed ^ k[59] kd,
2920 +               &b[12] bd, &b[27] bd, &b[1] bd, &b[17] bd);
2921 +       for_each_depth()
2922 +       s3(b[39] bd ^ k[60] kd, b[40] bd ^ k[61] kd, b[41] bd ^ k[62] kd,
2923 +               b[42] bd ^ k[63] kd, b[43] bd ^ k[64] kd, b[44] bd ^ k[65] kd,
2924 +               &b[23] bd, &b[15] bd, &b[29] bd, &b[5] bd);
2925 +       for_each_depth()
2926 +       s4(b[43] bd ^ k[66] kd, b[44] bd ^ k[67] kd, b[45] bd ^ k[68] kd,
2927 +               b[46] bd ^ k[69] kd, b[47] bd ^ k[70] kd, b[48] bd ^ k[71] kd,
2928 +               &b[25] bd, &b[19] bd, &b[9] bd, &b[0] bd);
2929 +       for_each_depth()
2930 +       s5(e[72] ed ^ k[72] kd, e[73] ed ^ k[73] kd, e[74] ed ^ k[74] kd,
2931 +               e[75] ed ^ k[75] kd, e[76] ed ^ k[76] kd, e[77] ed ^ k[77] kd,
2932 +               &b[7] bd, &b[13] bd, &b[24] bd, &b[2] bd);
2933 +       for_each_depth()
2934 +       s6(e[78] ed ^ k[78] kd, e[79] ed ^ k[79] kd, e[80] ed ^ k[80] kd,
2935 +               e[81] ed ^ k[81] kd, e[82] ed ^ k[82] kd, e[83] ed ^ k[83] kd,
2936 +               &b[3] bd, &b[28] bd, &b[10] bd, &b[18] bd);
2937 +       for_each_depth()
2938 +       s7(b[55] bd ^ k[84] kd, b[56] bd ^ k[85] kd, b[57] bd ^ k[86] kd,
2939 +               b[58] bd ^ k[87] kd, b[59] bd ^ k[88] kd, b[60] bd ^ k[89] kd,
2940 +               &b[31] bd, &b[11] bd, &b[21] bd, &b[6] bd);
2941 +       for_each_depth()
2942 +       s8(b[59] bd ^ k[90] kd, b[60] bd ^ k[91] kd, b[61] bd ^ k[92] kd,
2943 +               b[62] bd ^ k[93] kd, b[63] bd ^ k[94] kd, b[32] bd ^ k[95] kd,
2944 +               &b[4] bd, &b[26] bd, &b[14] bd, &b[20] bd);
2945 +
2946 +       k += 96;
2947 +
2948 +       if (--rounds_and_swapped) goto start;
2949 +       k -= (0x300 + 48);
2950 +       rounds_and_swapped = 0x108;
2951 +       if (--iterations) goto swap;
2952 +       return;
2953 +
2954 +next:
2955 +       k -= (0x300 - 48);
2956 +       rounds_and_swapped = 8;
2957 +       iterations--;
2958 +       goto start;
2959 +}
2960 +
2961 +#undef kd
2962 +#if DES_BS_VECTOR
2963 +#define kd                             [depth]
2964 +#else
2965 +#define kd                             [0]
2966 +#endif
2967 +
2968 +void DES_bs_crypt_LM(void)
2969 +{
2970 +       ARCH_WORD **k;
2971 +       int rounds;
2972 +#if DES_BS_VECTOR
2973 +       int depth;
2974 +#endif
2975 +
2976 +       for_each_depth() {
2977 +               b[0] bd = 0;
2978 +               b[1] bd = 0;
2979 +               b[2] bd = 0;
2980 +               b[3] bd = 0;
2981 +               b[4] bd = 0;
2982 +               b[5] bd = 0;
2983 +               b[6] bd = 0;
2984 +               b[7] bd = 0;
2985 +               b[8] bd = ~(ARCH_WORD)0;
2986 +               b[9] bd = ~(ARCH_WORD)0;
2987 +               b[10] bd = ~(ARCH_WORD)0;
2988 +               b[11] bd = 0;
2989 +               b[12] bd = ~(ARCH_WORD)0;
2990 +               b[13] bd = 0;
2991 +               b[14] bd = 0;
2992 +               b[15] bd = 0;
2993 +               b[16] bd = 0;
2994 +               b[17] bd = 0;
2995 +               b[18] bd = 0;
2996 +               b[19] bd = 0;
2997 +               b[20] bd = 0;
2998 +               b[21] bd = 0;
2999 +               b[22] bd = 0;
3000 +               b[23] bd = ~(ARCH_WORD)0;
3001 +               b[24] bd = 0;
3002 +               b[25] bd = 0;
3003 +               b[26] bd = ~(ARCH_WORD)0;
3004 +               b[27] bd = 0;
3005 +               b[28] bd = 0;
3006 +               b[29] bd = ~(ARCH_WORD)0;
3007 +               b[30] bd = ~(ARCH_WORD)0;
3008 +               b[31] bd = ~(ARCH_WORD)0;
3009 +               b[32] bd = 0;
3010 +               b[33] bd = 0;
3011 +               b[34] bd = 0;
3012 +               b[35] bd = ~(ARCH_WORD)0;
3013 +               b[36] bd = 0;
3014 +               b[37] bd = ~(ARCH_WORD)0;
3015 +               b[38] bd = ~(ARCH_WORD)0;
3016 +               b[39] bd = ~(ARCH_WORD)0;
3017 +               b[40] bd = 0;
3018 +               b[41] bd = 0;
3019 +               b[42] bd = 0;
3020 +               b[43] bd = 0;
3021 +               b[44] bd = 0;
3022 +               b[45] bd = ~(ARCH_WORD)0;
3023 +               b[46] bd = 0;
3024 +               b[47] bd = 0;
3025 +               b[48] bd = ~(ARCH_WORD)0;
3026 +               b[49] bd = ~(ARCH_WORD)0;
3027 +               b[50] bd = 0;
3028 +               b[51] bd = 0;
3029 +               b[52] bd = 0;
3030 +               b[53] bd = 0;
3031 +               b[54] bd = ~(ARCH_WORD)0;
3032 +               b[55] bd = 0;
3033 +               b[56] bd = ~(ARCH_WORD)0;
3034 +               b[57] bd = 0;
3035 +               b[58] bd = ~(ARCH_WORD)0;
3036 +               b[59] bd = 0;
3037 +               b[60] bd = ~(ARCH_WORD)0;
3038 +               b[61] bd = ~(ARCH_WORD)0;
3039 +               b[62] bd = ~(ARCH_WORD)0;
3040 +               b[63] bd = ~(ARCH_WORD)0;
3041 +       }
3042 +
3043 +       k = DES_bs_all.KS.p;
3044 +       rounds = 8;
3045  
3046         do {
3047 -               s1(*e[0] ^ *k[0], *e[1] ^ *k[1], *e[2] ^ *k[2],
3048 -                       *e[3] ^ *k[3], *e[4] ^ *k[4], *e[5] ^ *k[5],
3049 -                       &b[40], &b[48], &b[54], &b[62]);
3050 -               s2(*e[6] ^ *k[6], *e[7] ^ *k[7], *e[8] ^ *k[8],
3051 -                       *e[9] ^ *k[9], *e[10] ^ *k[10], *e[11] ^ *k[11],
3052 -                       &b[44], &b[59], &b[33], &b[49]);
3053 -               s3(*e[12] ^ *k[12], *e[13] ^ *k[13], *e[14] ^ *k[14],
3054 -                       *e[15] ^ *k[15], *e[16] ^ *k[16], *e[17] ^ *k[17],
3055 -                       &b[55], &b[47], &b[61], &b[37]);
3056 -               s4(*e[18] ^ *k[18], *e[19] ^ *k[19], *e[20] ^ *k[20],
3057 -                       *e[21] ^ *k[21], *e[22] ^ *k[22], *e[23] ^ *k[23],
3058 -                       &b[57], &b[51], &b[41], &b[32]);
3059 -               s5(*e[24] ^ *k[24], *e[25] ^ *k[25], *e[26] ^ *k[26],
3060 -                       *e[27] ^ *k[27], *e[28] ^ *k[28], *e[29] ^ *k[29],
3061 -                       &b[39], &b[45], &b[56], &b[34]);
3062 -               s6(*e[30] ^ *k[30], *e[31] ^ *k[31], *e[32] ^ *k[32],
3063 -                       *e[33] ^ *k[33], *e[34] ^ *k[34], *e[35] ^ *k[35],
3064 -                       &b[35], &b[60], &b[42], &b[50]);
3065 -               s7(*e[36] ^ *k[36], *e[37] ^ *k[37], *e[38] ^ *k[38],
3066 -                       *e[39] ^ *k[39], *e[40] ^ *k[40], *e[41] ^ *k[41],
3067 -                       &b[63], &b[43], &b[53], &b[38]);
3068 -               s8(*e[42] ^ *k[42], *e[43] ^ *k[43], *e[44] ^ *k[44],
3069 -                       *e[45] ^ *k[45], *e[46] ^ *k[46], *e[47] ^ *k[47],
3070 -                       &b[36], &b[58], &b[46], &b[52]);
3071 -
3072 -               s1(*e[48] ^ *k[48], *e[49] ^ *k[49], *e[50] ^ *k[50],
3073 -                       *e[51] ^ *k[51], *e[52] ^ *k[52], *e[53] ^ *k[53],
3074 -                       &b[8], &b[16], &b[22], &b[30]);
3075 -               s2(*e[54] ^ *k[54], *e[55] ^ *k[55], *e[56] ^ *k[56],
3076 -                       *e[57] ^ *k[57], *e[58] ^ *k[58], *e[59] ^ *k[59],
3077 -                       &b[12], &b[27], &b[1], &b[17]);
3078 -               s3(*e[60] ^ *k[60], *e[61] ^ *k[61], *e[62] ^ *k[62],
3079 -                       *e[63] ^ *k[63], *e[64] ^ *k[64], *e[65] ^ *k[65],
3080 -                       &b[23], &b[15], &b[29], &b[5]);
3081 -               s4(*e[66] ^ *k[66], *e[67] ^ *k[67], *e[68] ^ *k[68],
3082 -                       *e[69] ^ *k[69], *e[70] ^ *k[70], *e[71] ^ *k[71],
3083 -                       &b[25], &b[19], &b[9], &b[0]);
3084 -               s5(*e[72] ^ *k[72], *e[73] ^ *k[73], *e[74] ^ *k[74],
3085 -                       *e[75] ^ *k[75], *e[76] ^ *k[76], *e[77] ^ *k[77],
3086 -                       &b[7], &b[13], &b[24], &b[2]);
3087 -               s6(*e[78] ^ *k[78], *e[79] ^ *k[79], *e[80] ^ *k[80],
3088 -                       *e[81] ^ *k[81], *e[82] ^ *k[82], *e[83] ^ *k[83],
3089 -                       &b[3], &b[28], &b[10], &b[18]);
3090 -               s7(*e[84] ^ *k[84], *e[85] ^ *k[85], *e[86] ^ *k[86],
3091 -                       *e[87] ^ *k[87], *e[88] ^ *k[88], *e[89] ^ *k[89],
3092 -                       &b[31], &b[11], &b[21], &b[6]);
3093 -               s8(*e[90] ^ *k[90], *e[91] ^ *k[91], *e[92] ^ *k[92],
3094 -                       *e[93] ^ *k[93], *e[94] ^ *k[94], *e[95] ^ *k[95],
3095 -                       &b[4], &b[26], &b[14], &b[20]);
3096 +               for_each_depth()
3097 +               s1(b[31] bd ^ k[0] kd, b[0] bd ^ k[1] kd,
3098 +                       b[1] bd ^ k[2] kd, b[2] bd ^ k[3] kd,
3099 +                       b[3] bd ^ k[4] kd, b[4] bd ^ k[5] kd,
3100 +                       &b[40] bd, &b[48] bd, &b[54] bd, &b[62] bd);
3101 +               for_each_depth()
3102 +               s2(b[3] bd ^ k[6] kd, b[4] bd ^ k[7] kd,
3103 +                       b[5] bd ^ k[8] kd, b[6] bd ^ k[9] kd,
3104 +                       b[7] bd ^ k[10] kd, b[8] bd ^ k[11] kd,
3105 +                       &b[44] bd, &b[59] bd, &b[33] bd, &b[49] bd);
3106 +               for_each_depth()
3107 +               s3(b[7] bd ^ k[12] kd, b[8] bd ^ k[13] kd,
3108 +                       b[9] bd ^ k[14] kd, b[10] bd ^ k[15] kd,
3109 +                       b[11] bd ^ k[16] kd, b[12] bd ^ k[17] kd,
3110 +                       &b[55] bd, &b[47] bd, &b[61] bd, &b[37] bd);
3111 +               for_each_depth()
3112 +               s4(b[11] bd ^ k[18] kd, b[12] bd ^ k[19] kd,
3113 +                       b[13] bd ^ k[20] kd, b[14] bd ^ k[21] kd,
3114 +                       b[15] bd ^ k[22] kd, b[16] bd ^ k[23] kd,
3115 +                       &b[57] bd, &b[51] bd, &b[41] bd, &b[32] bd);
3116 +               for_each_depth()
3117 +               s5(b[15] bd ^ k[24] kd, b[16] bd ^ k[25] kd,
3118 +                       b[17] bd ^ k[26] kd, b[18] bd ^ k[27] kd,
3119 +                       b[19] bd ^ k[28] kd, b[20] bd ^ k[29] kd,
3120 +                       &b[39] bd, &b[45] bd, &b[56] bd, &b[34] bd);
3121 +               for_each_depth()
3122 +               s6(b[19] bd ^ k[30] kd, b[20] bd ^ k[31] kd,
3123 +                       b[21] bd ^ k[32] kd, b[22] bd ^ k[33] kd,
3124 +                       b[23] bd ^ k[34] kd, b[24] bd ^ k[35] kd,
3125 +                       &b[35] bd, &b[60] bd, &b[42] bd, &b[50] bd);
3126 +               for_each_depth()
3127 +               s7(b[23] bd ^ k[36] kd, b[24] bd ^ k[37] kd,
3128 +                       b[25] bd ^ k[38] kd, b[26] bd ^ k[39] kd,
3129 +                       b[27] bd ^ k[40] kd, b[28] bd ^ k[41] kd,
3130 +                       &b[63] bd, &b[43] bd, &b[53] bd, &b[38] bd);
3131 +               for_each_depth()
3132 +               s8(b[27] bd ^ k[42] kd, b[28] bd ^ k[43] kd,
3133 +                       b[29] bd ^ k[44] kd, b[30] bd ^ k[45] kd,
3134 +                       b[31] bd ^ k[46] kd, b[0] bd ^ k[47] kd,
3135 +                       &b[36] bd, &b[58] bd, &b[46] bd, &b[52] bd);
3136 +
3137 +               for_each_depth()
3138 +               s1(b[63] bd ^ k[48] kd, b[32] bd ^ k[49] kd,
3139 +                       b[33] bd ^ k[50] kd, b[34] bd ^ k[51] kd,
3140 +                       b[35] bd ^ k[52] kd, b[36] bd ^ k[53] kd,
3141 +                       &b[8] bd, &b[16] bd, &b[22] bd, &b[30] bd);
3142 +               for_each_depth()
3143 +               s2(b[35] bd ^ k[54] kd, b[36] bd ^ k[55] kd,
3144 +                       b[37] bd ^ k[56] kd, b[38] bd ^ k[57] kd,
3145 +                       b[39] bd ^ k[58] kd, b[40] bd ^ k[59] kd,
3146 +                       &b[12] bd, &b[27] bd, &b[1] bd, &b[17] bd);
3147 +               for_each_depth()
3148 +               s3(b[39] bd ^ k[60] kd, b[40] bd ^ k[61] kd,
3149 +                       b[41] bd ^ k[62] kd, b[42] bd ^ k[63] kd,
3150 +                       b[43] bd ^ k[64] kd, b[44] bd ^ k[65] kd,
3151 +                       &b[23] bd, &b[15] bd, &b[29] bd, &b[5] bd);
3152 +               for_each_depth()
3153 +               s4(b[43] bd ^ k[66] kd, b[44] bd ^ k[67] kd,
3154 +                       b[45] bd ^ k[68] kd, b[46] bd ^ k[69] kd,
3155 +                       b[47] bd ^ k[70] kd, b[48] bd ^ k[71] kd,
3156 +                       &b[25] bd, &b[19] bd, &b[9] bd, &b[0] bd);
3157 +               for_each_depth()
3158 +               s5(b[47] bd ^ k[72] kd, b[48] bd ^ k[73] kd,
3159 +                       b[49] bd ^ k[74] kd, b[50] bd ^ k[75] kd,
3160 +                       b[51] bd ^ k[76] kd, b[52] bd ^ k[77] kd,
3161 +                       &b[7] bd, &b[13] bd, &b[24] bd, &b[2] bd);
3162 +               for_each_depth()
3163 +               s6(b[51] bd ^ k[78] kd, b[52] bd ^ k[79] kd,
3164 +                       b[53] bd ^ k[80] kd, b[54] bd ^ k[81] kd,
3165 +                       b[55] bd ^ k[82] kd, b[56] bd ^ k[83] kd,
3166 +                       &b[3] bd, &b[28] bd, &b[10] bd, &b[18] bd);
3167 +               for_each_depth()
3168 +               s7(b[55] bd ^ k[84] kd, b[56] bd ^ k[85] kd,
3169 +                       b[57] bd ^ k[86] kd, b[58] bd ^ k[87] kd,
3170 +                       b[59] bd ^ k[88] kd, b[60] bd ^ k[89] kd,
3171 +                       &b[31] bd, &b[11] bd, &b[21] bd, &b[6] bd);
3172 +               for_each_depth()
3173 +               s8(b[59] bd ^ k[90] kd, b[60] bd ^ k[91] kd,
3174 +                       b[61] bd ^ k[92] kd, b[62] bd ^ k[93] kd,
3175 +                       b[63] bd ^ k[94] kd, b[32] bd ^ k[95] kd,
3176 +                       &b[4] bd, &b[26] bd, &b[14] bd, &b[20] bd);
3177  
3178                 k += 96;
3179 -       } while (--count);
3180 +       } while (--rounds);
3181  }
3182 +#endif
3183 diff -ruN john-1.6/src/DES_bs.c john-1.6.34/src/DES_bs.c
3184 --- john-1.6/src/DES_bs.c       1998-12-03 01:29:50.000000000 +0100
3185 +++ john-1.6.34/src/DES_bs.c    2002-10-19 16:05:46.000000000 +0200
3186 @@ -1,34 +1,121 @@
3187  /*
3188   * This file is part of John the Ripper password cracker,
3189 - * Copyright (c) 1996-98 by Solar Designer
3190 + * Copyright (c) 1996-2002 by Solar Designer
3191   */
3192  
3193  #include <string.h>
3194  
3195  #include "arch.h"
3196 +#include "common.h"
3197  #include "DES_std.h"
3198  #include "DES_bs.h"
3199  
3200 -DES_bs_combined DES_bs_all;
3201 -int DES_bs_mem_saving = 0;
3202 +#if DES_BS_VECTOR
3203 +#define DEPTH                          [depth]
3204 +#define START                          [0]
3205 +#define init_depth() \
3206 +       register int depth; \
3207 +       depth = index >> ARCH_BITS_LOG; \
3208 +       index &= (ARCH_BITS - 1);
3209 +#define for_each_depth() \
3210 +       for (depth = 0; depth < DES_BS_VECTOR; depth++)
3211 +#else
3212 +#define DEPTH
3213 +#define START
3214 +#define init_depth()
3215 +#define for_each_depth()
3216 +#endif
3217 +
3218 +#if !DES_BS_ASM
3219 +DES_bs_combined CC_CACHE_ALIGN DES_bs_all;
3220 +#endif
3221 +
3222 +static unsigned char DES_LM_KP[56] = {
3223 +       1, 2, 3, 4, 5, 6, 7,
3224 +       10, 11, 12, 13, 14, 15, 0,
3225 +       19, 20, 21, 22, 23, 8, 9,
3226 +       28, 29, 30, 31, 16, 17, 18,
3227 +       37, 38, 39, 24, 25, 26, 27,
3228 +       46, 47, 32, 33, 34, 35, 36,
3229 +       55, 40, 41, 42, 43, 44, 45,
3230 +       48, 49, 50, 51, 52, 53, 54
3231 +};
3232 +
3233 +static unsigned char DES_LM_reverse[16] = {
3234 +       0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15
3235 +};
3236 +
3237 +#if DES_BS_ASM
3238 +extern void DES_bs_init_asm(void);
3239 +#endif
3240  
3241 -extern void DES_bs_body();
3242 -
3243 -void DES_bs_init()
3244 +void DES_bs_init(int LM)
3245  {
3246 -       int index, bit;
3247 +       ARCH_WORD **k;
3248 +       int round, index, bit;
3249 +       int p, q, s;
3250 +       int c;
3251 +
3252 +       DES_bs_all.KS_updates = 0;
3253 +       if (LM)
3254 +               DES_bs_clear_keys_LM();
3255 +       else
3256 +               DES_bs_clear_keys();
3257  
3258 -       for (index = 0; index < 0x300; index++) {
3259 -               bit = DES_K_bits[index];
3260 -               bit -= bit >> 3;
3261 -               DES_bs_all.Kp[index] = &DES_bs_all.K[55 - bit];
3262 +#if DES_BS_EXPAND
3263 +       if (LM)
3264 +               k = DES_bs_all.KS.p;
3265 +       else
3266 +               k = DES_bs_all.KSp;
3267 +#else
3268 +       k = DES_bs_all.KS.p;
3269 +#endif
3270 +
3271 +       s = 0;
3272 +       for (round = 0; round < 16; round++) {
3273 +               s += DES_ROT[round];
3274 +               for (index = 0; index < 48; index++) {
3275 +                       p = DES_PC2[index];
3276 +                       q = p < 28 ? 0 : 28;
3277 +                       p += s;
3278 +                       while (p >= 28) p -= 28;
3279 +                       bit = DES_PC1[p + q];
3280 +                       bit ^= 070;
3281 +                       bit -= bit >> 3;
3282 +                       bit = 55 - bit;
3283 +                       if (LM) bit = DES_LM_KP[bit];
3284 +                       *k++ = &DES_bs_all.K[bit] START;
3285 +               }
3286 +       }
3287 +
3288 +/* Initialize the array with right shifts needed to get past the first
3289 + * non-zero bit in the index. */
3290 +       for (bit = 0; bit <= 7; bit++)
3291 +       for (index = 1 << bit; index < 0x100; index += 2 << bit)
3292 +               DES_bs_all.s[index] = bit + 1;
3293 +
3294 +/* Special case: instead of doing an extra check in the loop below, we
3295 + * might instead overrun into DES_bs_all.B, which is harmless, as long
3296 + * as the order of fields is unchanged. */
3297 +       DES_bs_all.s[0] = 57;
3298 +
3299 +       if (LM) {
3300 +               for (c = 0; c < 0x100; c++)
3301 +               if (c >= 'a' && c <= 'z')
3302 +                       DES_bs_all.E.extras.u[c] = c & ~0x20;
3303 +               else
3304 +                       DES_bs_all.E.extras.u[c] = c;
3305         }
3306 +
3307 +#if DES_BS_ASM
3308 +       DES_bs_init_asm();
3309 +#endif
3310  }
3311  
3312  void DES_bs_set_salt(ARCH_WORD salt)
3313  {
3314 -       register int src, dst;
3315         register ARCH_WORD mask;
3316 +       register int src, dst;
3317  
3318         mask = 1;
3319         for (dst = 0; dst < 48; dst++) {
3320 @@ -38,158 +125,232 @@
3321                         if (dst < 24) src = dst + 24; else src = dst - 24;
3322                 } else src = dst;
3323  
3324 -               DES_bs_all.E[dst] = &DES_bs_all.B[DES_E[src]];
3325 -               DES_bs_all.E[dst + 48] = &DES_bs_all.B[DES_E[src] + 32];
3326 +               DES_bs_all.E.E[dst] = &DES_bs_all.B[DES_E[src]] START;
3327 +               DES_bs_all.E.E[dst + 48] = &DES_bs_all.B[DES_E[src] + 32] START;
3328  
3329                 mask <<= 1;
3330         }
3331  }
3332  
3333 -void DES_bs_clear_keys()
3334 +void DES_bs_clear_keys(void)
3335 +{
3336 +       if (DES_bs_all.KS_updates++ & 0xFFF) return;
3337 +       DES_bs_all.KS_updates = 1;
3338 +       memset(DES_bs_all.K, 0, sizeof(DES_bs_all.K));
3339 +       memset(DES_bs_all.keys, 0, sizeof(DES_bs_all.keys));
3340 +       DES_bs_all.keys_changed = 1;
3341 +}
3342 +
3343 +void DES_bs_clear_keys_LM(void)
3344  {
3345 +       if (DES_bs_all.KS_updates++ & 0xFFF) return;
3346 +       DES_bs_all.KS_updates = 1;
3347         memset(DES_bs_all.K, 0, sizeof(DES_bs_all.K));
3348 +#if !DES_BS_VECTOR && ARCH_BITS >= 64
3349 +       memset(DES_bs_all.E.extras.keys, 0, sizeof(DES_bs_all.E.extras.keys));
3350 +#else
3351 +       memset(DES_bs_all.keys, 0, sizeof(DES_bs_all.keys));
3352 +#endif
3353  }
3354  
3355  void DES_bs_set_key(char *key, int index)
3356  {
3357 -       register char *ptr;
3358 -       register int ofs, bit;
3359 -       register ARCH_WORD value;
3360 +       register unsigned char *new = (unsigned char *)key;
3361 +       register unsigned char *old = DES_bs_all.keys[index];
3362 +       register ARCH_WORD xor, mask;
3363 +       register int ofs, bit, shift;
3364 +
3365 +       init_depth();
3366  
3367 -       ofs = 56;
3368 -       for (ptr = key; *ptr && ofs; ptr++) {
3369 -               bit = (ofs -= 7);
3370 -               value = *ptr & 0x7F;
3371 +       mask = (ARCH_WORD)1 << index;
3372 +       ofs = -1;
3373 +       while ((*new || *old) && ofs < 55) {
3374 +               if ((xor = *new ^ *old)) {
3375 +                       xor &= 0x7F;
3376 +                       *old = *new;
3377 +                       bit = ofs;
3378 +                       do {
3379 +                               shift = DES_bs_all.s[xor];
3380 +                               DES_bs_all.K[bit += shift] DEPTH ^= mask;
3381 +                       } while (xor >>= shift);
3382 +               }
3383  
3384 -               do {
3385 -                       DES_bs_all.K[bit++] |= (value & 1) << index;
3386 -               } while (value >>= 1);
3387 +               if (*new) new++;
3388 +               old++;
3389 +               ofs += 7;
3390         }
3391 +
3392 +       DES_bs_all.keys_changed = 1;
3393  }
3394  
3395 -void DES_bs_crypt(int count)
3396 +void DES_bs_set_key_LM(char *key, int index)
3397  {
3398 -       register int bit;
3399 -       register ARCH_WORD R, L;
3400 +       register unsigned char *new = (unsigned char *)key;
3401 +#if !DES_BS_VECTOR && ARCH_BITS >= 64
3402 +       register unsigned char *old = DES_bs_all.E.extras.keys[index];
3403 +#else
3404 +       register unsigned char *old = DES_bs_all.keys[index];
3405 +#endif
3406 +       register unsigned char plain;
3407 +       register ARCH_WORD xor, mask;
3408 +       register int ofs, bit, shift;
3409  
3410 -       memset(DES_bs_all.B, 0, sizeof(DES_bs_all.B));
3411 +       init_depth();
3412  
3413 -       do {
3414 -               DES_bs_body();
3415 +       mask = (ARCH_WORD)1 << index;
3416 +       ofs = -1;
3417 +       while ((*new || *old) && ofs < 55) {
3418 +               plain = DES_bs_all.E.extras.u[ARCH_INDEX(*new)];
3419 +               if ((xor = plain ^ *old)) {
3420 +                       *old = plain;
3421 +                       bit = ofs;
3422 +                       do {
3423 +                               shift = DES_bs_all.s[xor];
3424 +                               DES_bs_all.K[bit += shift] DEPTH ^= mask;
3425 +                       } while (xor >>= shift);
3426 +               }
3427 +
3428 +               if (*new) new++;
3429 +               old++;
3430 +               ofs += 8;
3431 +       }
3432 +}
3433  
3434 -               if (!--count) break;
3435 +#if DES_BS_EXPAND
3436 +void DES_bs_expand_keys(void)
3437 +{
3438 +       register int index;
3439 +#if DES_BS_VECTOR
3440 +       register int depth;
3441 +#endif
3442 +
3443 +       if (!DES_bs_all.keys_changed) return;
3444 +
3445 +       for (index = 0; index < 0x300; index++)
3446 +       for_each_depth()
3447 +#if DES_BS_VECTOR
3448 +               DES_bs_all.KS.v[index] DEPTH = DES_bs_all.KSp[index] DEPTH;
3449 +#else
3450 +               DES_bs_all.KS.v[index] = *DES_bs_all.KSp[index];
3451 +#endif
3452  
3453 -               for (bit = 0; bit < 32; bit++) {
3454 -                       R = DES_bs_all.B[bit];
3455 -                       L = DES_bs_all.B[bit + 32];
3456 -                       DES_bs_all.B[bit + 32] = R;
3457 -                       DES_bs_all.B[bit] = L;
3458 -               }
3459 -       } while (1);
3460 +       DES_bs_all.keys_changed = 0;
3461  }
3462 +#endif
3463  
3464 -ARCH_WORD *DES_bs_get_binary(char *ciphertext)
3465 +static ARCH_WORD *DES_bs_get_binary_raw(ARCH_WORD *raw, int count)
3466  {
3467 -       static ARCH_WORD out[64];
3468 -       ARCH_WORD *raw;
3469 -       int bit;
3470 -       int index, shift;
3471 -       int value;
3472 -
3473 -       raw = DES_raw_get_binary(ciphertext);
3474 -
3475 -       out[1] = out[0] = 0;
3476 -       for (bit = 0; bit < 64; bit++) {
3477 -               index = bit >> 4;
3478 -
3479 -/* Swap L and R here instead of doing it one more time in DES_bs_crypt() */
3480 -               index ^= 2;
3481 -
3482 -/* Calculate the number of one of the 16 data bits in raw[index] */
3483 -               shift = ((bit & 0xC) << 1) + (bit & 3) + 1;
3484 -
3485 -/* Get the bit */
3486 -               value = (raw[index] >> shift) & 1;
3487 -
3488 -               if (DES_bs_mem_saving)
3489 -/* Memory saving: pack the bits into two words */
3490 -                       out[bit >> 5] |= value << (bit & 0x1F);
3491 -               else
3492 -/* We either set or clear all the bits in every word */
3493 -                       out[bit] = value ? ~(ARCH_WORD)0 : 0;
3494 -       }
3495 +       static ARCH_WORD out[2];
3496 +
3497 +/* For odd iteration counts, swap L and R here instead of doing it one
3498 + * more time in DES_bs_crypt(). */
3499 +       count &= 1;
3500 +       out[count] = raw[0];
3501 +       out[count ^ 1] = raw[1];
3502  
3503         return out;
3504  }
3505  
3506 -int DES_bs_binary_hash(ARCH_WORD *binary, int count)
3507 +ARCH_WORD *DES_bs_get_binary(char *ciphertext)
3508  {
3509 -       int bit, result;
3510 -
3511 -       if (DES_bs_mem_saving)
3512 -               return (int)*binary & ((1 << count) - 1);
3513 +       return DES_bs_get_binary_raw(
3514 +               DES_raw_get_binary(ciphertext),
3515 +               DES_raw_get_count(ciphertext));
3516 +}
3517  
3518 -       result = 0;
3519 -       for (bit = 0; bit < count; bit++)
3520 -               if (binary[bit]) result |= 1 << bit;
3521 +ARCH_WORD *DES_bs_get_binary_LM(char *ciphertext)
3522 +{
3523 +       ARCH_WORD block[2], value;
3524 +       int l, h;
3525 +       int index;
3526 +
3527 +       block[0] = block[1] = 0;
3528 +       for (index = 0; index < 16; index += 2) {
3529 +               l = atoi16[ARCH_INDEX(ciphertext[index])];
3530 +               h = atoi16[ARCH_INDEX(ciphertext[index + 1])];
3531 +               value = DES_LM_reverse[l] | (DES_LM_reverse[h] << 4);
3532 +               block[index >> 3] |= value << ((index << 2) & 0x18);
3533 +       }
3534  
3535 -       return result;
3536 +       return DES_bs_get_binary_raw(DES_do_IP(block), 1);
3537  }
3538  
3539  int DES_bs_get_hash(int index, int count)
3540  {
3541 -       register int bit, result;
3542 -       register ARCH_WORD mask;
3543 +       register int result;
3544  
3545 -       mask = (ARCH_WORD)1 << index;
3546 -       result = 0;
3547 -       for (bit = 0; bit < count; bit++)
3548 -               if (DES_bs_all.B[bit] & mask) result |= 1 << bit;
3549 +       init_depth();
3550 +
3551 +       result = (DES_bs_all.B[0] DEPTH >> index) & 1;
3552 +       result |= ((DES_bs_all.B[1] DEPTH >> index) & 1) << 1;
3553 +       result |= ((DES_bs_all.B[2] DEPTH >> index) & 1) << 2;
3554 +       result |= ((DES_bs_all.B[3] DEPTH >> index) & 1) << 3;
3555 +       if (count == 4) return result;
3556 +
3557 +       result |= ((DES_bs_all.B[4] DEPTH >> index) & 1) << 4;
3558 +       result |= ((DES_bs_all.B[5] DEPTH >> index) & 1) << 5;
3559 +       result |= ((DES_bs_all.B[6] DEPTH >> index) & 1) << 6;
3560 +       result |= ((DES_bs_all.B[7] DEPTH >> index) & 1) << 7;
3561 +       if (count == 8) return result;
3562 +
3563 +       result |= ((DES_bs_all.B[8] DEPTH >> index) & 1) << 8;
3564 +       result |= ((DES_bs_all.B[9] DEPTH >> index) & 1) << 9;
3565 +       result |= ((DES_bs_all.B[10] DEPTH >> index) & 1) << 10;
3566 +       result |= ((DES_bs_all.B[11] DEPTH >> index) & 1) << 11;
3567  
3568         return result;
3569  }
3570  
3571  /*
3572   * The trick I used here allows to compare one ciphertext against all the
3573 - * DES_bs_crypt() outputs in just O(log2(ARCH_BITS)) operations.
3574 + * DES_bs_crypt() outputs in just O(log2(ARCH_BITS)) operations, assuming
3575 + * that DES_BS_VECTOR is 0 or 1. This routine isn't vectorized, yet.
3576   */
3577 -int DES_bs_cmp_all(ARCH_WORD *binary, int count)
3578 +int DES_bs_cmp_all(ARCH_WORD *binary)
3579  {
3580 +       register ARCH_WORD value, mask;
3581         register int bit;
3582 -       register ARCH_WORD mask;
3583 +#if DES_BS_VECTOR
3584 +       register int depth;
3585 +#endif
3586 +
3587 +       for_each_depth() {
3588 +               value = binary[0];
3589 +
3590 +               mask = DES_bs_all.B[0] DEPTH ^ -(value & 1);
3591 +               mask |= DES_bs_all.B[1] DEPTH ^ -((value >> 1) & 1);
3592 +               if (mask == ~(ARCH_WORD)0) goto next_depth;
3593 +               mask |= DES_bs_all.B[2] DEPTH ^ -((value >> 2) & 1);
3594 +               mask |= DES_bs_all.B[3] DEPTH ^ -((value >> 3) & 1);
3595 +               if (mask == ~(ARCH_WORD)0) goto next_depth;
3596 +               value >>= 4;
3597 +               for (bit = 4; bit < 32; bit += 2) {
3598 +                       mask |= DES_bs_all.B[bit] DEPTH ^
3599 +                               -(value & 1);
3600 +                       if (mask == ~(ARCH_WORD)0) goto next_depth;
3601 +                       mask |= DES_bs_all.B[bit + 1] DEPTH ^
3602 +                               -((value >> 1) & 1);
3603 +                       if (mask == ~(ARCH_WORD)0) goto next_depth;
3604 +                       value >>= 2;
3605 +               }
3606  
3607 -       mask = 0;
3608 -       if (DES_bs_mem_saving)
3609 -       for (bit = 0; bit < ((count < 32) ? count : 32); bit++) {
3610 -               mask |= DES_bs_all.B[bit] ^
3611 -                       ((binary[0] & (1 << bit)) ? ~(ARCH_WORD)0 : 0);
3612 -               if (mask == ~(ARCH_WORD)0) return 0;
3613 -       }
3614 -       else
3615 -       for (bit = 0; bit < count; bit++) {
3616 -               mask |= DES_bs_all.B[bit] ^ binary[bit];
3617 -               if (mask == ~(ARCH_WORD)0) return 0;
3618 +               return 1;
3619 +next_depth:
3620 +               ;
3621         }
3622  
3623 -       return 1;
3624 +       return 0;
3625  }
3626  
3627  int DES_bs_cmp_one(ARCH_WORD *binary, int count, int index)
3628  {
3629         register int bit;
3630 -       register ARCH_WORD mask;
3631 -
3632 -       if (DES_bs_mem_saving) {
3633 -               for (bit = 0; bit < count; bit++)
3634 -               if (((DES_bs_all.B[bit] >> index) ^
3635 -                       (binary[bit >> 5] >> (bit & 0x1F))) & 1) return 0;
3636  
3637 -               return 1;
3638 -       }
3639 +       init_depth();
3640  
3641 -       mask = (ARCH_WORD)1 << index;
3642         for (bit = 0; bit < count; bit++)
3643 -               if ((DES_bs_all.B[bit] ^ binary[bit]) & mask) return 0;
3644 +       if (((DES_bs_all.B[bit] DEPTH >> index) ^
3645 +               (binary[bit >> 5] >> (bit & 0x1F))) & 1) return 0;
3646  
3647         return 1;
3648  }
3649 diff -ruN john-1.6/src/DES_bs.h john-1.6.34/src/DES_bs.h
3650 --- john-1.6/src/DES_bs.h       1998-12-03 01:29:50.000000000 +0100
3651 +++ john-1.6.34/src/DES_bs.h    2001-06-28 23:11:25.000000000 +0200
3652 @@ -1,6 +1,6 @@
3653  /*
3654   * This file is part of John the Ripper password cracker,
3655 - * Copyright (c) 1996-98 by Solar Designer
3656 + * Copyright (c) 1996-2001 by Solar Designer
3657   */
3658  
3659  /*
3660 @@ -12,23 +12,57 @@
3661  
3662  #include "arch.h"
3663  
3664 +#ifndef DES_BS_ALGORITHM_NAME
3665  #define DES_BS_ALGORITHM_NAME          ARCH_BITS_STR "/" ARCH_BITS_STR " BS"
3666 +#endif
3667  
3668 -/*
3669 - * Non-zero when memory saving is enabled, with a performance impact. This
3670 - * should be either set at the very beginning, or never set at all.
3671 - */
3672 -extern int DES_bs_mem_saving;
3673 +#if DES_BS_VECTOR
3674 +#define DES_BS_DEPTH                   (ARCH_BITS * DES_BS_VECTOR)
3675 +#else
3676 +#define DES_BS_DEPTH                   ARCH_BITS
3677 +#endif
3678 +
3679 +#if DES_BS_VECTOR
3680 +typedef ARCH_WORD DES_bs_vector[DES_BS_VECTOR];
3681 +#else
3682 +#define DES_bs_vector                  ARCH_WORD
3683 +#endif
3684  
3685  /*
3686   * All bitslice DES parameters combined into one struct for more efficient
3687 - * cache usage.
3688 + * cache usage. Don't re-order unless you know what you're doing, as there
3689 + * is an optimization that would produce undefined results if you did.
3690 + *
3691 + * This must match the definition in x86-mmx.S.
3692   */
3693  typedef struct {
3694 -       ARCH_WORD *Kp[0x300];   /* Key schedule (key bit pointers) */
3695 -       ARCH_WORD *E[96];       /* Expansion function (data bit pointers) */
3696 -       ARCH_WORD K[56];        /* Keys */
3697 -       ARCH_WORD B[64];        /* Data blocks */
3698 +#if DES_BS_EXPAND
3699 +       ARCH_WORD *KSp[0x300];  /* Initial key schedule (key bit pointers) */
3700 +#endif
3701 +       union {
3702 +               ARCH_WORD *p[0x300];    /* Key bit pointers */
3703 +#if DES_BS_EXPAND
3704 +               DES_bs_vector v[0x300]; /* Key bit values */
3705 +#endif
3706 +       } KS;                   /* Current key schedule */
3707 +       union {
3708 +               ARCH_WORD *E[96];       /* Expansion function (data bit ptrs) */
3709 +               struct {
3710 +#if !DES_BS_VECTOR && ARCH_BITS >= 64
3711 +                       unsigned char keys[DES_BS_DEPTH][8]; /* Current keys */
3712 +#endif
3713 +                       unsigned char u[0x100]; /* Uppercase */
3714 +               } extras;               /* Re-use the cache space for LM */
3715 +       } E;
3716 +       DES_bs_vector K[56];    /* Keys */
3717 +       DES_bs_vector B[64];    /* Data blocks */
3718 +#if DES_BS_ASM
3719 +       DES_bs_vector tmp[16];  /* Miscellaneous temporary storage */
3720 +#endif
3721 +       unsigned char s[0x100]; /* Shift counts, used internally */
3722 +       int KS_updates;         /* Key schedule updates counter */
3723 +       int keys_changed;       /* If keys have changed since last expand */
3724 +       unsigned char keys[DES_BS_DEPTH][8];    /* Current keys */
3725  } DES_bs_combined;
3726  
3727  extern DES_bs_combined DES_bs_all;
3728 @@ -36,7 +70,7 @@
3729  /*
3730   * Initializes the internal structures.
3731   */
3732 -extern void DES_bs_init();
3733 +extern void DES_bs_init(int LM);
3734  
3735  /*
3736   * Sets a salt for DES_bs_crypt().
3737 @@ -44,9 +78,12 @@
3738  extern void DES_bs_set_salt(ARCH_WORD salt);
3739  
3740  /*
3741 - * Clears the bitslice keys, should be done before DES_bs_set_key() calls.
3742 + * Clears the bitslice keys if the key schedule has been updated too
3743 + * many times without being fully regenerated. This should be called
3744 + * whenever possible to reduce the impact of hardware faults.
3745   */
3746 -extern void DES_bs_clear_keys();
3747 +extern void DES_bs_clear_keys(void);
3748 +extern void DES_bs_clear_keys_LM(void);
3749  
3750  /*
3751   * Sets a key for DES_bs_crypt().
3752 @@ -54,20 +91,44 @@
3753  extern void DES_bs_set_key(char *key, int index);
3754  
3755  /*
3756 - * Main encryption routine, accepts the iteration count.
3757 + * Initializes the key schedule with actual key bits. Not for LM.
3758 + */
3759 +#if DES_BS_EXPAND
3760 +extern void DES_bs_expand_keys(void);
3761 +#else
3762 +#define DES_bs_expand_keys()
3763 +#endif
3764 +
3765 +/*
3766 + * Sets a key for DES_bs_crypt_LM().
3767 + */
3768 +extern void DES_bs_set_key_LM(char *key, int index);
3769 +
3770 +/*
3771 + * Generic bitslice routine: 24 bit salts, variable iteration count.
3772   */
3773  extern void DES_bs_crypt(int count);
3774  
3775  /*
3776 + * A simplified special-case version: 12 bit salts, 25 iterations.
3777 + */
3778 +extern void DES_bs_crypt_25(void);
3779 +
3780 +/*
3781 + * Another special-case version: a non-zero IV, no salts, no iterations.
3782 + */
3783 +extern void DES_bs_crypt_LM(void);
3784 +
3785 +/*
3786   * Converts an ASCII ciphertext to binary to be used with one of the
3787   * comparison functions.
3788   */
3789  extern ARCH_WORD *DES_bs_get_binary(char *ciphertext);
3790  
3791  /*
3792 - * Calculates a hash for a ciphertext, for faster comparison.
3793 + * Similarly, for LM hashes.
3794   */
3795 -extern int DES_bs_binary_hash(ARCH_WORD *binary, int count);
3796 +extern ARCH_WORD *DES_bs_get_binary_LM(char *ciphertext);
3797  
3798  /*
3799   * Calculates a hash for a DES_bs_crypt() output.
3800 @@ -75,14 +136,13 @@
3801  extern int DES_bs_get_hash(int index, int count);
3802  
3803  /*
3804 - * Compares count bits of a given ciphertext against all the DES_bs_crypt()
3805 + * Compares 32 bits of a given ciphertext against all the DES_bs_crypt()
3806   * outputs and returns zero if no matches detected.
3807   */
3808 -extern int DES_bs_cmp_all(ARCH_WORD *binary, int count);
3809 +extern int DES_bs_cmp_all(ARCH_WORD *binary);
3810  
3811  /*
3812 - * Same as the above, except the comparison is done against only one of the
3813 - * DES_bs_crypt() outputs.
3814 + * Compares count bits of a given ciphertext against one of the outputs.
3815   */
3816  extern int DES_bs_cmp_one(ARCH_WORD *binary, int count, int index);
3817  
3818 diff -ruN john-1.6/src/DES_fmt.c john-1.6.34/src/DES_fmt.c
3819 --- john-1.6/src/DES_fmt.c      1998-12-03 01:29:50.000000000 +0100
3820 +++ john-1.6.34/src/DES_fmt.c   2001-06-19 10:34:09.000000000 +0200
3821 @@ -1,6 +1,6 @@
3822  /*
3823   * This file is part of John the Ripper password cracker,
3824 - * Copyright (c) 1996-98 by Solar Designer
3825 + * Copyright (c) 1996-2001 by Solar Designer
3826   */
3827  
3828  #include <string.h>
3829 @@ -11,7 +11,7 @@
3830  #include "formats.h"
3831  
3832  #define FORMAT_LABEL                   "des"
3833 -#define FORMAT_NAME                    "Standard DES"
3834 +#define FORMAT_NAME                    "Traditional DES"
3835  
3836  #define BENCHMARK_COMMENT              ""
3837  #define BENCHMARK_LENGTH               0
3838 @@ -31,18 +31,15 @@
3839  
3840  #if DES_BS
3841  
3842 -#include "memory.h"
3843  #include "DES_bs.h"
3844  
3845  #define ALGORITHM_NAME                 DES_BS_ALGORITHM_NAME
3846  
3847 -#define BINARY_BITS                    16
3848 -
3849 -#define BINARY_SIZE                    (BINARY_BITS * ARCH_SIZE)
3850 +#define BINARY_SIZE                    ARCH_SIZE
3851  #define SALT_SIZE                      ARCH_SIZE
3852  
3853 -#define MIN_KEYS_PER_CRYPT             ARCH_BITS
3854 -#define MAX_KEYS_PER_CRYPT             ARCH_BITS
3855 +#define MIN_KEYS_PER_CRYPT             DES_BS_DEPTH
3856 +#define MAX_KEYS_PER_CRYPT             DES_BS_DEPTH
3857  
3858  #else
3859  
3860 @@ -58,10 +55,7 @@
3861  #define MAX_KEYS_PER_CRYPT             0x80
3862  #endif
3863  
3864 -#endif
3865 -
3866  static struct {
3867 -#if !DES_BS
3868         union {
3869                 double dummy;
3870                 struct {
3871 @@ -69,25 +63,16 @@
3872                         DES_binary binary;
3873                 } data;
3874         } aligned;
3875 -#endif
3876         char key[PLAINTEXT_LENGTH];
3877  } buffer[MAX_KEYS_PER_CRYPT];
3878  
3879 -#if DES_BS
3880 +#endif
3881  
3882 -struct fmt_main fmt_DES;
3883 -static int binary_bits = BINARY_BITS;
3884 -static int keys_changed;
3885 -
3886 -static void init()
3887 -{
3888 -       if (mem_saving_level > 1) {
3889 -               DES_bs_mem_saving = 1;
3890 -               binary_bits = 32;
3891 -               fmt_DES.params.binary_size = ARCH_SIZE;
3892 -       }
3893 +#if DES_BS
3894  
3895 -       DES_bs_init();
3896 +static void init(void)
3897 +{
3898 +       DES_bs_init(0);
3899  }
3900  
3901  #endif
3902 @@ -98,14 +83,17 @@
3903  
3904         if (!ciphertext[0] || !ciphertext[1]) return 0;
3905  
3906 -       for (pos = &ciphertext[2]; atoi64[(ARCH_INDEX)*pos] != 0x7F; pos++);
3907 +       for (pos = &ciphertext[2]; atoi64[ARCH_INDEX(*pos)] != 0x7F; pos++);
3908         if (*pos && *pos != ',') return 0;
3909  
3910 +       if (atoi64[ARCH_INDEX(*(pos - 1))] & 3) return 0;
3911 +
3912         switch (pos - ciphertext) {
3913         case CIPHERTEXT_LENGTH_1:
3914                 return 1;
3915  
3916         case CIPHERTEXT_LENGTH_2:
3917 +               if (atoi64[ARCH_INDEX(ciphertext[12])] & 3) return 0;
3918                 return 2;
3919  
3920         default:
3921 @@ -144,17 +132,17 @@
3922  
3923  static int binary_hash_0(void *binary)
3924  {
3925 -       return DES_bs_binary_hash((ARCH_WORD *)binary, 4);
3926 +       return *(ARCH_WORD *)binary & 0xF;
3927  }
3928  
3929  static int binary_hash_1(void *binary)
3930  {
3931 -       return DES_bs_binary_hash((ARCH_WORD *)binary, 8);
3932 +       return *(ARCH_WORD *)binary & 0xFF;
3933  }
3934  
3935  static int binary_hash_2(void *binary)
3936  {
3937 -       return DES_bs_binary_hash((ARCH_WORD *)binary, 12);
3938 +       return *(ARCH_WORD *)binary & 0xFFF;
3939  }
3940  
3941  static int get_hash_0(int index)
3942 @@ -184,26 +172,18 @@
3943  
3944  static void crypt_all(int count)
3945  {
3946 -       int index;
3947 -
3948 -       if (keys_changed) {
3949 -               DES_bs_clear_keys();
3950 -               for (index = 0; index < count; index++)
3951 -                       DES_bs_set_key(buffer[index].key, index);
3952 -               keys_changed = 0;
3953 -       }
3954 -
3955 -       DES_bs_crypt(25);
3956 +       DES_bs_expand_keys();
3957 +       DES_bs_crypt_25();
3958  }
3959  
3960  static int cmp_all(void *binary, int count)
3961  {
3962 -       return DES_bs_cmp_all((ARCH_WORD *)binary, binary_bits);
3963 +       return DES_bs_cmp_all((ARCH_WORD *)binary);
3964  }
3965  
3966  static int cmp_one(void *binary, int index)
3967  {
3968 -       return DES_bs_cmp_one((ARCH_WORD *)binary, binary_bits, index);
3969 +       return DES_bs_cmp_one((ARCH_WORD *)binary, 32, index);
3970  }
3971  
3972  static int cmp_exact(char *source, int index)
3973 @@ -303,23 +283,24 @@
3974  
3975  #endif
3976  
3977 +#if !DES_BS
3978  static void set_key(char *key, int index)
3979  {
3980 -#if DES_BS
3981 -       keys_changed = 1;
3982 -#else
3983         DES_std_set_key(key);
3984         memcpy(buffer[index].aligned.data.KS, DES_KS_current, sizeof(DES_KS));
3985 -#endif
3986 -
3987         memcpy(buffer[index].key, key, PLAINTEXT_LENGTH);
3988  }
3989 +#endif
3990  
3991  static char *get_key(int index)
3992  {
3993         static char out[PLAINTEXT_LENGTH + 1];
3994  
3995 +#if DES_BS
3996 +       memcpy(out, DES_bs_all.keys[index], PLAINTEXT_LENGTH);
3997 +#else
3998         memcpy(out, buffer[index].key, PLAINTEXT_LENGTH);
3999 +#endif
4000         out[PLAINTEXT_LENGTH] = 0;
4001  
4002         return out;
4003 @@ -337,7 +318,11 @@
4004                 SALT_SIZE,
4005                 MIN_KEYS_PER_CRYPT,
4006                 MAX_KEYS_PER_CRYPT,
4007 +#if DES_BS
4008 +               FMT_CASE | FMT_BS,
4009 +#else
4010                 FMT_CASE,
4011 +#endif
4012                 tests
4013         }, {
4014  #if DES_BS
4015 @@ -361,8 +346,17 @@
4016                 },
4017                 salt_hash,
4018                 set_salt,
4019 +#if DES_BS
4020 +               DES_bs_set_key,
4021 +#else
4022                 set_key,
4023 +#endif
4024                 get_key,
4025 +#if DES_BS
4026 +               DES_bs_clear_keys,
4027 +#else
4028 +               fmt_default_clear_keys,
4029 +#endif
4030                 crypt_all,
4031                 {
4032                         get_hash_0,
4033 diff -ruN john-1.6/src/DES_std.c john-1.6.34/src/DES_std.c
4034 --- john-1.6/src/DES_std.c      1998-12-03 01:29:50.000000000 +0100
4035 +++ john-1.6.34/src/DES_std.c   2001-02-16 06:50:21.000000000 +0100
4036 @@ -1,26 +1,17 @@
4037  /*
4038   * This file is part of John the Ripper password cracker,
4039 - * Copyright (c) 1996-98 by Solar Designer
4040 + * Copyright (c) 1996-2001 by Solar Designer
4041   */
4042  
4043  #include <string.h>
4044  
4045  #include "arch.h"
4046 +#include "common.h"
4047  #include "DES_std.h"
4048  
4049 -#if ARCH_GENERIC
4050 -
4051 -#if ((__GNUC__ == 2) && (__GNUC_MINOR__ >= 7)) || (__GNUC__ > 2)
4052 -#define DES_ALIGN                      __attribute__ ((aligned (128)))
4053 -#else
4054 -#define DES_ALIGN                      /* nothing */
4055 -#endif
4056 -
4057 -#endif
4058 -
4059  #if ARCH_BITS >= 64
4060  
4061 -#if ARCH_GENERIC
4062 +#if !DES_ASM
4063  
4064  static union {
4065         double dummy;
4066 @@ -31,7 +22,7 @@
4067                 ARCH_WORD SPE_W[4][64 * 64];
4068  #endif
4069         } data;
4070 -} DES_ALIGN DES_all;
4071 +} CC_CACHE_ALIGN DES_all;
4072  
4073  #else
4074  
4075 @@ -46,7 +37,7 @@
4076  
4077  #else
4078  
4079 -#if ARCH_GENERIC
4080 +#if !DES_ASM
4081  
4082  static union {
4083         double dummy;
4084 @@ -60,7 +51,7 @@
4085                 ARCH_WORD SPE_W[4][64 * 64][2];
4086  #endif
4087         } data;
4088 -} DES_ALIGN DES_all;
4089 +} CC_CACHE_ALIGN DES_all;
4090  
4091  #else
4092  
4093 @@ -80,7 +71,7 @@
4094  
4095  #endif
4096  
4097 -#if ARCH_GENERIC
4098 +#if !DES_ASM
4099  
4100  #define DES_KS_copy                    DES_all.data.KS
4101  #define DES_SPE_F                      DES_all.data.SPE_F
4102 @@ -91,8 +82,8 @@
4103  DES_binary DES_IV;
4104  ARCH_WORD DES_count;
4105  
4106 -DES_KS DES_ALIGN DES_KS_current;
4107 -DES_KS DES_ALIGN DES_KS_table[8][128];
4108 +DES_KS CC_CACHE_ALIGN DES_KS_current;
4109 +DES_KS CC_CACHE_ALIGN DES_KS_table[8][128];
4110  
4111  #endif
4112  
4113 @@ -100,7 +91,7 @@
4114  static char DES_key[16];
4115  
4116  #if DES_COPY
4117 -#if !ARCH_GENERIC
4118 +#if DES_ASM
4119  extern DES_KS DES_KS_copy;
4120  #endif
4121  unsigned ARCH_WORD *DES_out;
4122 @@ -122,7 +113,7 @@
4123  #if (ARCH_BITS >= 64 && (DES_SCALE || !DES_MASK) || DES_128K) && \
4124         DES_SIZE_FIX == 2
4125  /*
4126 - * 64 bit architectures which can shift addresses left by 1 bit with no extra
4127 + * 64-bit architectures which can shift addresses left by 1 bit with no extra
4128   * time required (for example by adding a register to itself).
4129   */
4130  #define DES_INDEX(SPE, i) \
4131 @@ -130,7 +121,7 @@
4132  #else
4133  #if DES_SIZE_FIX == 0
4134  /*
4135 - * 64 bit architectures which can shift addresses left by 3 bits (but maybe
4136 + * 64-bit architectures which can shift addresses left by 3 bits (but maybe
4137   * not by 1) with no extra time required (for example by using the S8ADDQ
4138   * instruction on DEC Alphas; we would need an ADDQ anyway).
4139   */
4140 @@ -160,7 +151,7 @@
4141  #if DES_MASK
4142  #if ARCH_BITS >= 64 && !DES_SCALE && DES_SIZE_FIX == 2
4143  /*
4144 - * This method might be good for some 64 bit architectures with no complicated
4145 + * This method might be good for some 64-bit architectures with no complicated
4146   * addressing modes supported. It would be the best one for DEC Alphas if they
4147   * didn't have the S8ADDQ instruction.
4148   */
4149 @@ -192,12 +183,18 @@
4150  #endif
4151  #define DES_KS_INDEX(i)                        (DES_KS_copy + (i * (16 / DES_SIZE)))
4152  
4153 -#define DES_TO_6_BIT(x) \
4154 +#define DES_24_TO_32(x) \
4155         (((x) & 077) | \
4156         (((x) & 07700) << 2) | \
4157         (((x) & 0770000) << 4) | \
4158         (((x) & 077000000) << 6))
4159  
4160 +#define DES_16_TO_32(x) \
4161 +       ((((x) & 0xF) << 1) | \
4162 +       (((x) & 0xF0) << 5) | \
4163 +       (((x) & 0xF00) << 9) | \
4164 +       (((x) & 0xF000) << 13))
4165 +
4166  #if DES_128K
4167  #define DES_UNDO_SIZE_FIX(x) \
4168         ((((x) >> 1) & 0xFF00FF00) | (((x) & 0x00FF00FF) >> 3))
4169 @@ -294,58 +291,33 @@
4170         44, 45, 46, 47, 60, 61, 62, 63
4171  };
4172  
4173 -unsigned char DES_K_bits[0x300] = {
4174 -       9, 50, 33, 59, 48, 16, 32, 56, 1, 8, 18, 41, 2, 34, 25, 24,
4175 -       43, 57, 58, 0, 35, 26, 17, 40, 21, 27, 38, 53, 36, 3, 46, 29,
4176 -       4, 52, 22, 28, 60, 20, 37, 62, 14, 19, 44, 13, 12, 61, 54, 30,
4177 -       1, 42, 25, 51, 40, 8, 24, 48, 58, 0, 10, 33, 59, 26, 17, 16,
4178 -       35, 49, 50, 57, 56, 18, 9, 32, 13, 19, 30, 45, 28, 62, 38, 21,
4179 -       27, 44, 14, 20, 52, 12, 29, 54, 6, 11, 36, 5, 4, 53, 46, 22,
4180 -       50, 26, 9, 35, 24, 57, 8, 32, 42, 49, 59, 17, 43, 10, 1, 0,
4181 -       48, 33, 34, 41, 40, 2, 58, 16, 60, 3, 14, 29, 12, 46, 22, 5,
4182 -       11, 28, 61, 4, 36, 27, 13, 38, 53, 62, 20, 52, 19, 37, 30, 6,
4183 -       34, 10, 58, 48, 8, 41, 57, 16, 26, 33, 43, 1, 56, 59, 50, 49,
4184 -       32, 17, 18, 25, 24, 51, 42, 0, 44, 54, 61, 13, 27, 30, 6, 52,
4185 -       62, 12, 45, 19, 20, 11, 60, 22, 37, 46, 4, 36, 3, 21, 14, 53,
4186 -       18, 59, 42, 32, 57, 25, 41, 0, 10, 17, 56, 50, 40, 43, 34, 33,
4187 -       16, 1, 2, 9, 8, 35, 26, 49, 28, 38, 45, 60, 11, 14, 53, 36,
4188 -       46, 27, 29, 3, 4, 62, 44, 6, 21, 30, 19, 20, 54, 5, 61, 37,
4189 -       2, 43, 26, 16, 41, 9, 25, 49, 59, 1, 40, 34, 24, 56, 18, 17,
4190 -       0, 50, 51, 58, 57, 48, 10, 33, 12, 22, 29, 44, 62, 61, 37, 20,
4191 -       30, 11, 13, 54, 19, 46, 28, 53, 5, 14, 3, 4, 38, 52, 45, 21,
4192 -       51, 56, 10, 0, 25, 58, 9, 33, 43, 50, 24, 18, 8, 40, 2, 1,
4193 -       49, 34, 35, 42, 41, 32, 59, 17, 27, 6, 13, 28, 46, 45, 21, 4,
4194 -       14, 62, 60, 38, 3, 30, 12, 37, 52, 61, 54, 19, 22, 36, 29, 5,
4195 -       35, 40, 59, 49, 9, 42, 58, 17, 56, 34, 8, 2, 57, 24, 51, 50,
4196 -       33, 18, 48, 26, 25, 16, 43, 1, 11, 53, 60, 12, 30, 29, 5, 19,
4197 -       61, 46, 44, 22, 54, 14, 27, 21, 36, 45, 38, 3, 6, 20, 13, 52,
4198 -       56, 32, 51, 41, 1, 34, 50, 9, 48, 26, 0, 59, 49, 16, 43, 42,
4199 -       25, 10, 40, 18, 17, 8, 35, 58, 3, 45, 52, 4, 22, 21, 60, 11,
4200 -       53, 38, 36, 14, 46, 6, 19, 13, 28, 37, 30, 62, 61, 12, 5, 44,
4201 -       40, 16, 35, 25, 50, 18, 34, 58, 32, 10, 49, 43, 33, 0, 56, 26,
4202 -       9, 59, 24, 2, 1, 57, 48, 42, 54, 29, 36, 19, 6, 5, 44, 62,
4203 -       37, 22, 20, 61, 30, 53, 3, 60, 12, 21, 14, 46, 45, 27, 52, 28,
4204 -       24, 0, 48, 9, 34, 2, 18, 42, 16, 59, 33, 56, 17, 49, 40, 10,
4205 -       58, 43, 8, 51, 50, 41, 32, 26, 38, 13, 20, 3, 53, 52, 28, 46,
4206 -       21, 6, 4, 45, 14, 37, 54, 44, 27, 5, 61, 30, 29, 11, 36, 12,
4207 -       8, 49, 32, 58, 18, 51, 2, 26, 0, 43, 17, 40, 1, 33, 24, 59,
4208 -       42, 56, 57, 35, 34, 25, 16, 10, 22, 60, 4, 54, 37, 36, 12, 30,
4209 -       5, 53, 19, 29, 61, 21, 38, 28, 11, 52, 45, 14, 13, 62, 20, 27,
4210 -       57, 33, 16, 42, 2, 35, 51, 10, 49, 56, 1, 24, 50, 17, 8, 43,
4211 -       26, 40, 41, 48, 18, 9, 0, 59, 6, 44, 19, 38, 21, 20, 27, 14,
4212 -       52, 37, 3, 13, 45, 5, 22, 12, 62, 36, 29, 61, 60, 46, 4, 11,
4213 -       41, 17, 0, 26, 51, 48, 35, 59, 33, 40, 50, 8, 34, 1, 57, 56,
4214 -       10, 24, 25, 32, 2, 58, 49, 43, 53, 28, 3, 22, 5, 4, 11, 61,
4215 -       36, 21, 54, 60, 29, 52, 6, 27, 46, 20, 13, 45, 44, 30, 19, 62,
4216 -       25, 1, 49, 10, 35, 32, 48, 43, 17, 24, 34, 57, 18, 50, 41, 40,
4217 -       59, 8, 9, 16, 51, 42, 33, 56, 37, 12, 54, 6, 52, 19, 62, 45,
4218 -       20, 5, 38, 44, 13, 36, 53, 11, 30, 4, 60, 29, 28, 14, 3, 46,
4219 -       17, 58, 41, 2, 56, 24, 40, 35, 9, 16, 26, 49, 10, 42, 33, 32,
4220 -       51, 0, 1, 8, 43, 34, 25, 48, 29, 4, 46, 61, 44, 11, 54, 37,
4221 -       12, 60, 30, 36, 5, 28, 45, 3, 22, 27, 52, 21, 20, 6, 62, 38
4222 +unsigned char DES_PC1[56] = {
4223 +       56, 48, 40, 32, 24, 16, 8,
4224 +       0, 57, 49, 41, 33, 25, 17,
4225 +       9, 1, 58, 50, 42, 34, 26,
4226 +       18, 10, 2, 59, 51, 43, 35,
4227 +       62, 54, 46, 38, 30, 22, 14,
4228 +       6, 61, 53, 45, 37, 29, 21,
4229 +       13, 5, 60, 52, 44, 36, 28,
4230 +       20, 12, 4, 27, 19, 11, 3
4231 +};
4232 +
4233 +unsigned char DES_ROT[16] = {
4234 +       1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1
4235 +};
4236 +
4237 +unsigned char DES_PC2[48] = {
4238 +       13, 16, 10, 23, 0, 4,
4239 +       2, 27, 14, 5, 20, 9,
4240 +       22, 18, 11, 3, 25, 7,
4241 +       15, 6, 26, 19, 12, 1,
4242 +       40, 51, 30, 36, 46, 54,
4243 +       29, 39, 50, 44, 32, 47,
4244 +       43, 48, 38, 55, 33, 52,
4245 +       45, 41, 49, 35, 28, 31
4246  };
4247  
4248 -static void init_SPE()
4249 +static void init_SPE(void)
4250  {
4251         int box, index, row, column, bit;
4252         ARCH_WORD mask, l, h;
4253 @@ -366,14 +338,14 @@
4254                 h = l = 0;
4255                 for (bit = 0; bit < 24; bit++) {
4256                         if (((unsigned ARCH_WORD)0x80000000 >>
4257 -                           DES_P[DES_E[bit]]) & mask)
4258 +                           DES_P[ARCH_INDEX(DES_E[bit])]) & mask)
4259                                 l |= 1 << bit;
4260                         if (((unsigned ARCH_WORD)0x80000000 >>
4261 -                           DES_P[DES_E[bit + 24]]) & mask)
4262 +                           DES_P[ARCH_INDEX(DES_E[bit + 24])]) & mask)
4263                                 h |= 1 << bit;
4264                 }
4265  
4266 -               l = DES_TO_6_BIT(l); h = DES_TO_6_BIT(h);
4267 +               l = DES_24_TO_32(l); h = DES_24_TO_32(h);
4268  
4269  #if ARCH_BITS >= 64
4270                 DES_SPE[box][index] =
4271 @@ -386,7 +358,7 @@
4272         }
4273  }
4274  
4275 -static void init_IP_E()
4276 +static void init_IP_E(void)
4277  {
4278         int src, dst, dst1, dst2;
4279         int chunk, mask, value;
4280 @@ -396,7 +368,7 @@
4281         for (dst1 = 0; dst1 < 8; dst1++)
4282         for (dst2 = 0; dst2 < 6; dst2++) {
4283                 dst = (dst1 << 3) + dst2;
4284 -               src = DES_IP[DES_E[dst1 * 6 + dst2]];
4285 +               src = DES_IP[ARCH_INDEX(DES_E[dst1 * 6 + dst2])];
4286                 if (src >= 32) src -= 32; else src--;
4287                 src ^= 7;
4288  
4289 @@ -415,7 +387,7 @@
4290         }
4291  }
4292  
4293 -static void init_C_FP()
4294 +static void init_C_FP(void)
4295  {
4296         int src, dst;
4297         int chunk, mask, value;
4298 @@ -423,7 +395,7 @@
4299         memset(DES_C_FP, 0, sizeof(DES_C_FP));
4300  
4301         for (src = 0; src < 64; src++) {
4302 -               dst = DES_IP[DES_C[src]] ^ 7;
4303 +               dst = DES_IP[ARCH_INDEX(DES_C[src])] ^ 7;
4304  
4305                 chunk = src >> 2;
4306                 mask = 1 << (src & 3);
4307 @@ -440,12 +412,12 @@
4308         }
4309  }
4310  
4311 -static void init_KS()
4312 +static void init_KS(void)
4313  {
4314 -       int pos, chr, bit, ofs, index;
4315 +       int pos, chr, round, bit, ofs;
4316         unsigned char block[64];
4317 -       unsigned char *k;
4318 -       ARCH_WORD value;
4319 +       ARCH_WORD value[2];
4320 +       int k, p, q, r, s;
4321  
4322         memset(block, 0, sizeof(block));
4323  
4324 @@ -454,22 +426,31 @@
4325                 for (bit = 0; bit < 7; bit++)
4326                         block[(pos << 3) + bit] = (chr >> (6 - bit)) & 1;
4327  
4328 -               k = DES_K_bits;
4329 -               for (index = 0; index < 32; index++) {
4330 -                       value = 0;
4331 -                       for (ofs = 0; ofs < 32; ofs += 8)
4332 -                       for (bit = 0; bit < 6; bit++) value |=
4333 -                               (ARCH_WORD)block[*k++] << (ofs + bit);
4334 -
4335 -#if ARCH_BITS >= 64
4336 -                       if (index & 1)
4337 -                               DES_KS_table[pos][chr][index >> 1] |=
4338 -                                       DES_DO_SIZE_FIX(value) << 32;
4339 -                       else
4340 -                               DES_KS_table[pos][chr][index >> 1] =
4341 -                                       DES_DO_SIZE_FIX(value);
4342 -#else
4343 -                       DES_KS_table[pos][chr][index] = DES_DO_SIZE_FIX(value);
4344 +               s = 0;
4345 +               for (round = 0; round < 16; round++) {
4346 +                       s += DES_ROT[round];
4347 +                       value[0] = value[1] = 0;
4348 +                       k = 0;
4349 +                       for (ofs = 0; ofs < 64; ofs += 8)
4350 +                       for (bit = 0; bit < 6; bit++) {
4351 +                               p = DES_PC2[k++];
4352 +                               q = p < 28 ? 0 : 28;
4353 +                               p += s;
4354 +                               while (p >= 28) p -= 28;
4355 +                               r = DES_PC1[p + q];
4356 +                               value[ofs >> 5] |= (ARCH_WORD)block[r] <<
4357 +                                       ((ofs & 31) + bit);
4358 +                       }
4359 +
4360 +#if ARCH_BITS >= 64
4361 +                       DES_KS_table[pos][chr][round] =
4362 +                               DES_DO_SIZE_FIX(value[0]) |
4363 +                               (DES_DO_SIZE_FIX(value[1]) << 32);
4364 +#else
4365 +                       DES_KS_table[pos][chr][round << 1] =
4366 +                               DES_DO_SIZE_FIX(value[0]);
4367 +                       DES_KS_table[pos][chr][(round << 1) + 1] =
4368 +                               DES_DO_SIZE_FIX(value[1]);
4369  #endif
4370                 }
4371         }
4372 @@ -479,7 +460,7 @@
4373         memcpy(DES_KS_current, DES_KS_table, sizeof(DES_KS));
4374  }
4375  
4376 -void DES_std_init()
4377 +void DES_std_init(void)
4378  {
4379         init_SPE();
4380         init_IP_E();
4381 @@ -618,12 +599,12 @@
4382  #endif
4383  
4384         memcpy(DES_KS_current,
4385 -               DES_KS_table[0][(ARCH_INDEX)(DES_key[0] = key[0] & 0x7F)],
4386 +               DES_KS_table[0][ARCH_INDEX(DES_key[0] = key[0] & 0x7F)],
4387                 sizeof(DES_KS));
4388  
4389         pos = (DES_KS *)DES_KS_table[1][0];
4390         for (i = 1; i < 8; i++) {
4391 -               DES_xor_key1(pos[(ARCH_INDEX)(DES_key[i] = key[i] & 0x7F)]);
4392 +               DES_xor_key1(pos[ARCH_INDEX(DES_key[i] = key[i] & 0x7F)]);
4393                 pos += 128;
4394         }
4395  }
4396 @@ -635,7 +616,8 @@
4397         register ARCH_WORD *value1, *value2;
4398  #endif
4399  
4400 -       for (k = i = 0; (j = key[i]) && (l = DES_key[i]); i++)
4401 +       j = key[0];
4402 +       for (k = i = 0; (l = DES_key[i]) && (j = key[i]); i++)
4403         if (j != l) k += 3;
4404  
4405         if (j) {
4406 @@ -650,7 +632,7 @@
4407  
4408         if ((k < (j << 1)) && (++DES_KS_updates & 0xFFF)) {
4409                 j = 0; l = 1;
4410 -               for (i = 0; (k = key[i]) && i < 8; i++) {
4411 +               for (i = 0; i < 8 && (k = key[i]); i++) {
4412                         if (l)
4413                         if (k == (l = DES_key[j++])) continue;
4414  
4415 @@ -669,7 +651,7 @@
4416                         sizeof(DES_KS));
4417  
4418                 if (k)
4419 -               for (i = 1; (k = key[i]) && i < 8; i++)
4420 +               for (i = 1; i < 8 && (k = key[i]); i++)
4421                         DES_xor_key1(DES_KS_table[i][k & 0x7F]);
4422         }
4423  
4424 @@ -833,7 +815,7 @@
4425   */
4426  #if DES_MASK
4427  #if DES_SCALE
4428 -/* 64 bit, 4K, mask, scale */
4429 +/* 64-bit, 4K, mask, scale */
4430  #define DES_ROUND(L, H, B) \
4431         T = DES_INDEX(DES_SPE_F[0], DES_D & DES_MASK_6); \
4432         B ^= DES_INDEX(DES_SPE_F[1], (DES_D >> 8) & DES_MASK_6); \
4433 @@ -851,7 +833,7 @@
4434   * (which is done at compile time), I moved the extra shift out of the mask,
4435   * which allows doing this with special addressing modes, where possible.
4436   */
4437 -/* 64 bit, 4K, mask, no scale */
4438 +/* 64-bit, 4K, mask, no scale */
4439  #define DES_ROUND(L, H, B) \
4440         T = DES_INDEX(DES_SPE_F[0], (DES_D & (DES_MASK_6 >> 1)) << 1); \
4441         B ^= DES_INDEX(DES_SPE_F[1], (DES_D >> 7) & DES_MASK_6); \
4442 @@ -863,7 +845,7 @@
4443         B ^= T ^ DES_INDEX(DES_SPE_F[7], (DES_D >> 55) & DES_MASK_6);
4444  #endif
4445  #else
4446 -/* 64 bit, 4K, store/load, scale */
4447 +/* 64-bit, 4K, store/load, scale */
4448  #define DES_ROUND(L, H, B) \
4449         T = DES_INDEX(DES_SPE_F[0], DES_B0); \
4450         B ^= DES_INDEX(DES_SPE_F[1], DES_B1); \
4451 @@ -875,7 +857,7 @@
4452         B ^= T ^ DES_INDEX(DES_SPE_F[7], DES_B7);
4453  #endif
4454  #else
4455 -/* 64 bit, 128K, mask, no scale */
4456 +/* 64-bit, 128K, mask, no scale */
4457  #define DES_ROUND(L, H, B) \
4458         B ^= DES_INDEX(DES_SPE_W[0], DES_D & 0xFFFF); \
4459         B ^= DES_INDEX(DES_SPE_W[1], (DES_D >>= 16) & 0xFFFF); \
4460 @@ -885,7 +867,7 @@
4461  #else
4462  #if !DES_128K
4463  #if DES_MASK
4464 -/* 32 bit, 4K, mask */
4465 +/* 32-bit, 4K, mask */
4466  #define DES_ROUND(L, H, B) \
4467         L ^= DES_INDEX(DES_SPE_L[0], DES_Dl & DES_MASK_6); \
4468         H ^= DES_INDEX(DES_SPE_H[0], DES_Dl & DES_MASK_6); \
4469 @@ -904,7 +886,7 @@
4470         L ^= DES_INDEX(DES_SPE_L[7], (DES_Dh >>= 8) & DES_MASK_6); \
4471         H ^= DES_INDEX(DES_SPE_H[7], DES_Dh & DES_MASK_6);
4472  #else
4473 -/* 32 bit, 4K, store/load */
4474 +/* 32-bit, 4K, store/load */
4475  #define DES_ROUND(L, H, B) \
4476         L ^= DES_INDEX(DES_SPE_L[0], DES_B0); \
4477         H ^= DES_INDEX(DES_SPE_H[0], DES_B0); \
4478 @@ -924,7 +906,7 @@
4479         H ^= DES_INDEX(DES_SPE_H[7], DES_B7);
4480  #endif
4481  #else
4482 -/* 32 bit, 128K, mask */
4483 +/* 32-bit, 128K, mask */
4484  #define DES_ROUND(L, H, B) \
4485         L ^= DES_INDEX_L(DES_SPE_W[0], DES_Dl & 0xFFFF); \
4486         H ^= DES_INDEX_H(DES_SPE_W[0], DES_Dl & 0xFFFF); \
4487 @@ -954,7 +936,7 @@
4488  #endif
4489  
4490  #if DES_COPY
4491 -static void crypt_body()
4492 +static void crypt_body(void)
4493  #else
4494  void DES_std_crypt(DES_KS KS, DES_binary DES_out)
4495  #endif
4496 @@ -1064,12 +1046,12 @@
4497  
4498  ARCH_WORD DES_raw_get_salt(char *ciphertext)
4499  {
4500 -       if (ciphertext[13]) return DES_atoi64[(ARCH_INDEX)ciphertext[5]] |
4501 -               ((ARCH_WORD)DES_atoi64[(ARCH_INDEX)ciphertext[6]] << 6) |
4502 -               ((ARCH_WORD)DES_atoi64[(ARCH_INDEX)ciphertext[7]] << 12) |
4503 -               ((ARCH_WORD)DES_atoi64[(ARCH_INDEX)ciphertext[8]] << 18);
4504 -       else return DES_atoi64[(ARCH_INDEX)ciphertext[0]] |
4505 -               ((ARCH_WORD)DES_atoi64[(ARCH_INDEX)ciphertext[1]] << 6);
4506 +       if (ciphertext[13]) return DES_atoi64[ARCH_INDEX(ciphertext[5])] |
4507 +               ((ARCH_WORD)DES_atoi64[ARCH_INDEX(ciphertext[6])] << 6) |
4508 +               ((ARCH_WORD)DES_atoi64[ARCH_INDEX(ciphertext[7])] << 12) |
4509 +               ((ARCH_WORD)DES_atoi64[ARCH_INDEX(ciphertext[8])] << 18);
4510 +       else return DES_atoi64[ARCH_INDEX(ciphertext[0])] |
4511 +               ((ARCH_WORD)DES_atoi64[ARCH_INDEX(ciphertext[1])] << 6);
4512  }
4513  
4514  ARCH_WORD DES_std_get_salt(char *ciphertext)
4515 @@ -1077,75 +1059,72 @@
4516         ARCH_WORD salt;
4517  
4518         salt = DES_raw_get_salt(ciphertext);
4519 -       salt = DES_TO_6_BIT(salt);
4520 +       salt = DES_24_TO_32(salt);
4521         return DES_DO_SIZE_FIX(salt);
4522  }
4523  
4524  ARCH_WORD DES_raw_get_count(char *ciphertext)
4525  {
4526 -       if (ciphertext[13]) return DES_atoi64[(ARCH_INDEX)ciphertext[1]] |
4527 -               ((ARCH_WORD)DES_atoi64[(ARCH_INDEX)ciphertext[2]] << 6) |
4528 -               ((ARCH_WORD)DES_atoi64[(ARCH_INDEX)ciphertext[3]] << 12) |
4529 -               ((ARCH_WORD)DES_atoi64[(ARCH_INDEX)ciphertext[4]] << 18);
4530 +       if (ciphertext[13]) return DES_atoi64[ARCH_INDEX(ciphertext[1])] |
4531 +               ((ARCH_WORD)DES_atoi64[ARCH_INDEX(ciphertext[2])] << 6) |
4532 +               ((ARCH_WORD)DES_atoi64[ARCH_INDEX(ciphertext[3])] << 12) |
4533 +               ((ARCH_WORD)DES_atoi64[ARCH_INDEX(ciphertext[4])] << 18);
4534         else return 25;
4535  }
4536  
4537 -ARCH_WORD *DES_raw_get_binary(char *ciphertext)
4538 +ARCH_WORD *DES_do_IP(ARCH_WORD in[2])
4539  {
4540 -       static ARCH_WORD masks[8] = {
4541 -               0x1000, 0x0800, 0x0400, 0x0200, 0x0010, 0x0008, 0x0004, 0x0002
4542 -       };
4543 +       static ARCH_WORD out[2];
4544 +       int src, dst;
4545  
4546 -       static ARCH_WORD out[4];
4547 +       out[0] = out[1] = 0;
4548 +       for (dst = 0; dst < 64; dst++) {
4549 +               src = DES_IP[dst ^ 0x20];
4550 +
4551 +               if (in[src >> 5] & (1 << (src & 0x1F)))
4552 +                       out[dst >> 5] |= 1 << (dst & 0x1F);
4553 +       }
4554 +
4555 +       return out;
4556 +}
4557  
4558 -       int ofs, chr, bit, index, value;
4559 -       unsigned char block[66], *ptr;
4560 -       ARCH_WORD mask1, mask2;
4561 -       ARCH_WORD Rl, Rh, Ll, Lh;
4562 +ARCH_WORD *DES_raw_get_binary(char *ciphertext)
4563 +{
4564 +       ARCH_WORD block[3];
4565 +       ARCH_WORD mask;
4566 +       int ofs, chr, src, dst, value;
4567  
4568         if (ciphertext[13]) ofs = 9; else ofs = 2;
4569 -       ptr = block;
4570  
4571 +       block[0] = block[1] = 0;
4572 +       dst = 0;
4573         for (chr = 0; chr < 11; chr++) {
4574 -               value = DES_atoi64[(ARCH_INDEX)ciphertext[chr + ofs]];
4575 -               mask1 = 0x20;
4576 +               value = DES_atoi64[ARCH_INDEX(ciphertext[chr + ofs])];
4577 +               mask = 0x20;
4578  
4579 -               for (bit = 0; bit < 6; bit++) {
4580 -                       *ptr++ = value & mask1;
4581 -                       mask1 >>= 1;
4582 +               for (src = 0; src < 6; src++) {
4583 +                       if (value & mask)
4584 +                               block[dst >> 5] |= 1 << (dst & 0x1F);
4585 +                       mask >>= 1;
4586 +                       dst++;
4587                 }
4588         }
4589  
4590 -       Lh = Ll = Rh = Rl = 0;
4591 -       ptr = block;
4592 -
4593 -       for (index = 0; index < 8; index++) {
4594 -               mask2 = (mask1 = masks[index]) << 16;
4595 -
4596 -               if (*ptr++) Rl |= mask1;
4597 -               if (*ptr++) Ll |= mask1;
4598 -               if (*ptr++) Rl |= mask2;
4599 -               if (*ptr++) Ll |= mask2;
4600 -               if (*ptr++) Rh |= mask1;
4601 -               if (*ptr++) Lh |= mask1;
4602 -               if (*ptr++) Rh |= mask2;
4603 -               if (*ptr++) Lh |= mask2;
4604 -       }
4605 -
4606 -       out[0] = Rl;
4607 -       out[1] = Rh;
4608 -       out[2] = Ll;
4609 -       out[3] = Lh;
4610 -
4611 -       return out;
4612 +       return DES_do_IP(block);
4613  }
4614  
4615  ARCH_WORD *DES_std_get_binary(char *ciphertext)
4616  {
4617 -       ARCH_WORD *out;
4618 +       static ARCH_WORD out[4];
4619 +       ARCH_WORD *raw;
4620         ARCH_WORD salt, mask;
4621  
4622 -       out = DES_raw_get_binary(ciphertext);
4623 +       raw = DES_raw_get_binary(ciphertext);
4624 +
4625 +       out[0] = DES_16_TO_32(raw[0]);
4626 +       out[1] = DES_16_TO_32(raw[0] >> 16);
4627 +       out[2] = DES_16_TO_32(raw[1]);
4628 +       out[3] = DES_16_TO_32(raw[1] >> 16);
4629  
4630         out[0] = DES_DO_SIZE_FIX(out[0]);
4631         out[1] = DES_DO_SIZE_FIX(out[1]);
4632 diff -ruN john-1.6/src/DES_std.h john-1.6.34/src/DES_std.h
4633 --- john-1.6/src/DES_std.h      1998-12-03 01:29:50.000000000 +0100
4634 +++ john-1.6.34/src/DES_std.h   2000-03-24 22:22:20.000000000 +0100
4635 @@ -1,10 +1,10 @@
4636  /*
4637   * This file is part of John the Ripper password cracker,
4638 - * Copyright (c) 1996-98 by Solar Designer
4639 + * Copyright (c) 1996-2000 by Solar Designer
4640   */
4641  
4642  /*
4643 - * Standard DES implementation.
4644 + * "Standard" (non-bitslice) DES implementation.
4645   */
4646  
4647  #ifndef _JOHN_DES_STD_H
4648 @@ -19,14 +19,12 @@
4649  #endif
4650  
4651  /*
4652 - * Expansion table.
4653 + * Various DES tables exported for use by other implementations.
4654   */
4655  extern unsigned char DES_E[48];
4656 -
4657 -/*
4658 - * Key bits schedule.
4659 - */
4660 -extern unsigned char DES_K_bits[0x300];
4661 +extern unsigned char DES_PC1[56];
4662 +extern unsigned char DES_ROT[16];
4663 +extern unsigned char DES_PC2[48];
4664  
4665  /*
4666   * Current key schedule.
4667 @@ -108,10 +106,9 @@
4668         (DES_STD_HASH_1(x) | \
4669         (((x) >> (DES_SIZE_FIX + 9)) & 0xF00))
4670  
4671 +#ifndef DES_STD_ALGORITHM_NAME
4672  #if ARCH_BITS >= 64
4673  #define DES_STD_ALGORITHM_BITS         "48/" ARCH_BITS_STR
4674 -#elif DES_X2
4675 -#define DES_STD_ALGORITHM_BITS         "48/64"
4676  #else
4677  #define DES_STD_ALGORITHM_BITS         "24/32"
4678  #endif
4679 @@ -122,11 +119,12 @@
4680  #endif
4681  #define DES_STD_ALGORITHM_NAME \
4682         DES_STD_ALGORITHM_BITS " " DES_STD_ALGORITHM_SIZE
4683 +#endif
4684  
4685  /*
4686   * Initializes the internal structures.
4687   */
4688 -extern void DES_std_init();
4689 +extern void DES_std_init(void);
4690  
4691  /*
4692   * Sets a salt for DES_std_crypt().
4693 @@ -178,6 +176,13 @@
4694  extern ARCH_WORD DES_raw_get_count(char *ciphertext);
4695  
4696  /*
4697 + * Does the Initial Permutation; to be used at startup only (doesn't
4698 + * require that DES_std_init() has been called, is not as fast as it
4699 + * could be).
4700 + */
4701 +extern ARCH_WORD *DES_do_IP(ARCH_WORD in[2]);
4702 +
4703 +/*
4704   * Converts an ASCII ciphertext to binary.
4705   */
4706  extern ARCH_WORD *DES_raw_get_binary(char *ciphertext);
4707 diff -ruN john-1.6/src/detect.c john-1.6.34/src/detect.c
4708 --- john-1.6/src/detect.c       1998-12-03 01:29:50.000000000 +0100
4709 +++ john-1.6.34/src/detect.c    2000-05-08 09:04:46.000000000 +0200
4710 @@ -1,6 +1,6 @@
4711  /*
4712   * This file is part of John the Ripper password cracker,
4713 - * Copyright (c) 1996-98 by Solar Designer
4714 + * Copyright (c) 1996-2000 by Solar Designer
4715   */
4716  
4717  /*
4718 @@ -12,8 +12,12 @@
4719  int main(int argc, char **argv)
4720  {
4721         int value = 1;
4722 +       int size_log;
4723  
4724 -       if (argc != 6) return 1;
4725 +       if (argc != 7) return 1;
4726 +
4727 +       size_log = 0;
4728 +       while (sizeof(long) * 8 != 1 << size_log) size_log++;
4729  
4730         puts(
4731  "/*\n"
4732 @@ -24,18 +28,18 @@
4733  "#define _JOHN_ARCH_H\n");
4734  
4735         printf(
4736 -"#define ARCH_GENERIC\t\t\t%d\n"
4737  "#define ARCH_WORD\t\t\tlong\n"
4738  "#define ARCH_SIZE\t\t\t%d\n"
4739  "#define ARCH_BITS\t\t\t%d\n"
4740 +"#define ARCH_BITS_LOG\t\t\t%d\n"
4741  "#define ARCH_BITS_STR\t\t\t\"%d\"\n"
4742  "#define ARCH_LITTLE_ENDIAN\t\t%d\n"
4743  "#define ARCH_INT_GT_32\t\t\t%d\n"
4744  "#define ARCH_ALLOWS_UNALIGNED\t\t0\n"
4745  #ifdef __alpha__
4746 -"#define ARCH_INDEX\t\t\tunsigned long\n"
4747 +"#define ARCH_INDEX(x)\t\t\t((unsigned long)(unsigned char)(x))\n"
4748  #else
4749 -"#define ARCH_INDEX\t\t\tunsigned int\n"
4750 +"#define ARCH_INDEX(x)\t\t\t((unsigned int)(unsigned char)(x))\n"
4751  #endif
4752  "\n"
4753  #ifdef OS_TIMER
4754 @@ -49,13 +53,9 @@
4755  "#define OS_FLOCK\t\t\t0\n"
4756  #endif
4757  "\n",
4758 -#ifdef DES_ASM
4759 -               0,
4760 -#else
4761 -               1,
4762 -#endif
4763                 (int)sizeof(long),
4764                 (int)(sizeof(long) * 8),
4765 +               size_log,
4766                 (int)(sizeof(long) * 8),
4767                 (int)(*(char *)&value),
4768                 (sizeof(int) > 4) ? 1 : 0);
4769 @@ -125,9 +125,13 @@
4770  
4771         printf(
4772  "#define DES_COPY\t\t\t%c\n"
4773 +"#define DES_BS_ASM\t\t\t0\n"
4774  "#define DES_BS\t\t\t\t%c\n"
4775 +"#define DES_BS_VECTOR\t\t\t0\n"
4776 +"#define DES_BS_EXPAND\t\t\t1\n"
4777  "\n"
4778  "#define MD5_ASM\t\t\t\t0\n"
4779 +"#define MD5_X2\t\t\t\t%c\n"
4780  "#define MD5_IMM\t\t\t\t%c\n"
4781  "\n"
4782  "#define BF_ASM\t\t\t\t0\n"
4783 @@ -137,7 +141,8 @@
4784                 argv[2][0],
4785                 argv[3][0],
4786                 argv[4][0],
4787 -               argv[5][0]);
4788 +               argv[5][0],
4789 +               argv[6][0]);
4790  
4791         return 0;
4792  }
4793 diff -ruN john-1.6/src/external.c john-1.6.34/src/external.c
4794 --- john-1.6/src/external.c     1998-12-03 01:29:50.000000000 +0100
4795 +++ john-1.6.34/src/external.c  2001-06-16 09:46:21.000000000 +0200
4796 @@ -1,6 +1,6 @@
4797  /*
4798   * This file is part of John the Ripper password cracker,
4799 - * Copyright (c) 1996-98 by Solar Designer
4800 + * Copyright (c) 1996-2001 by Solar Designer
4801   */
4802  
4803  #include <stdio.h>
4804 @@ -8,7 +8,6 @@
4805  
4806  #include "misc.h"
4807  #include "params.h"
4808 -#include "path.h"
4809  #include "signals.h"
4810  #include "compiler.h"
4811  #include "loader.h"
4812 @@ -20,7 +19,7 @@
4813  static char int_word[PLAINTEXT_BUFFER_SIZE];
4814  static char rec_word[PLAINTEXT_BUFFER_SIZE];
4815  
4816 -static char *ext_mode = NULL;
4817 +char *ext_mode = NULL;
4818  
4819  static c_int ext_word[PLAINTEXT_BUFFER_SIZE];
4820  
4821 @@ -30,13 +29,14 @@
4822         ext_word
4823  };
4824  
4825 -static struct c_ident *f_generate, *f_filter;
4826 +static struct c_ident *f_generate;
4827 +struct c_ident *f_filter;
4828  
4829  static struct cfg_list *ext_source;
4830  static struct cfg_line *ext_line;
4831  static int ext_pos;
4832  
4833 -static int ext_getchar()
4834 +static int ext_getchar(void)
4835  {
4836         char c;
4837  
4838 @@ -49,7 +49,7 @@
4839         return '\n';
4840  }
4841  
4842 -static void ext_rewind()
4843 +static void ext_rewind(void)
4844  {
4845         ext_line = ext_source->head;
4846         ext_pos = 0;
4847 @@ -66,7 +66,7 @@
4848                 if (!ext_line) ext_line = ext_source->tail;
4849  
4850                 fprintf(stderr, "Compiler error in %s at line %d: %s\n",
4851 -                       path_expand(CFG_NAME), ext_line->number,
4852 +                       cfg_name, ext_line->number,
4853                         c_errors[c_errno]);
4854                 error();
4855         }
4856 @@ -80,14 +80,12 @@
4857         ext_mode = mode;
4858  }
4859  
4860 -int ext_filter(char *word)
4861 +int ext_filter_body(char *in, char *out)
4862  {
4863         unsigned char *internal;
4864         c_int *external;
4865  
4866 -       if (!ext_mode || !f_filter) return 1;
4867 -
4868 -       internal = (unsigned char *)word;
4869 +       internal = (unsigned char *)in;
4870         external = ext_word;
4871         while (*internal)
4872                 *external++ = *internal++;
4873 @@ -95,9 +93,9 @@
4874  
4875         c_execute(f_filter);
4876  
4877 -       if (word[0] && !ext_word[0]) return 0;
4878 +       if (in[0] && !ext_word[0]) return 0;
4879  
4880 -       internal = (unsigned char *)word;
4881 +       internal = (unsigned char *)out;
4882         external = ext_word;
4883         while (*external)
4884                 *internal++ = *external++;
4885 @@ -136,7 +134,7 @@
4886         return 0;
4887  }
4888  
4889 -static void fix_state()
4890 +static void fix_state(void)
4891  {
4892         strcpy(rec_word, int_word);
4893  }
4894 diff -ruN john-1.6/src/external.h john-1.6.34/src/external.h
4895 --- john-1.6/src/external.h     1998-12-03 01:29:50.000000000 +0100
4896 +++ john-1.6.34/src/external.h  2001-06-16 09:47:26.000000000 +0200
4897 @@ -1,6 +1,6 @@
4898  /*
4899   * This file is part of John the Ripper password cracker,
4900 - * Copyright (c) 1996-98 by Solar Designer
4901 + * Copyright (c) 1996-2001 by Solar Designer
4902   */
4903  
4904  /*
4905 @@ -13,6 +13,12 @@
4906  #include "loader.h"
4907  
4908  /*
4909 + * Defined for use in the ext_filter() macro, below.
4910 + */
4911 +extern char *ext_mode;
4912 +extern struct c_ident *f_filter;
4913 +
4914 +/*
4915   * Initializes an external mode.
4916   */
4917  extern void ext_init(char *mode);
4918 @@ -20,7 +26,13 @@
4919  /*
4920   * Calls an external word filter. Returns 0 if the word is rejected.
4921   */
4922 -extern int ext_filter(char *word);
4923 +#define ext_filter(word) \
4924 +       (!ext_mode || !f_filter || ext_filter_body(word, word))
4925 +
4926 +/*
4927 + * The actual implementation of ext_filter(); use the macro instead.
4928 + */
4929 +extern int ext_filter_body(char *in, char *out);
4930  
4931  /*
4932   * Runs the external mode cracker.
4933 diff -ruN john-1.6/src/formats.c john-1.6.34/src/formats.c
4934 --- john-1.6/src/formats.c      1998-12-03 01:29:50.000000000 +0100
4935 +++ john-1.6.34/src/formats.c   2001-06-16 08:07:01.000000000 +0200
4936 @@ -1,6 +1,6 @@
4937  /*
4938   * This file is part of John the Ripper password cracker,
4939 - * Copyright (c) 1996-98 by Solar Designer
4940 + * Copyright (c) 1996-2001 by Solar Designer
4941   */
4942  
4943  #include <stdio.h>
4944 @@ -28,24 +28,28 @@
4945         }
4946  }
4947  
4948 -int fmt_self_test(struct fmt_main *format)
4949 +char *fmt_self_test(struct fmt_main *format)
4950  {
4951 +       static char s_size[32];
4952         struct fmt_tests *current;
4953         char *ciphertext, *plaintext;
4954 -       int size;
4955 +       int index, max, size;
4956         void *binary, *salt;
4957  
4958         if (format->params.plaintext_length > PLAINTEXT_BUFFER_SIZE - 3)
4959 -               return 1;
4960 +               return "length";
4961  
4962 -       if (format->methods.valid("*")) return 1;
4963 +       if (format->methods.valid("*")) return "valid";
4964  
4965         fmt_init(format);
4966  
4967 -       if (!(current = format->params.tests)) return 0;
4968 +       if (!(current = format->params.tests)) return NULL;
4969  
4970 +       index = 0; max = format->params.max_keys_per_crypt;
4971 +       if (max > 2 && !(format->params.flags & FMT_BS)) max = 2;
4972         do {
4973 -               if (format->methods.valid(current->ciphertext) != 1) break;
4974 +               if (format->methods.valid(current->ciphertext) != 1)
4975 +                       return "valid";
4976                 ciphertext = format->methods.split(current->ciphertext, 0);
4977                 plaintext = current->plaintext;
4978  
4979 @@ -53,30 +57,40 @@
4980                 salt = format->methods.salt(ciphertext);
4981  
4982                 if ((unsigned int)format->methods.salt_hash(salt) >=
4983 -                       SALT_HASH_SIZE) break;
4984 +                   SALT_HASH_SIZE)
4985 +                       return "salt_hash";
4986  
4987                 format->methods.set_salt(salt);
4988 -               format->methods.set_key(current->plaintext, 0);
4989 +               format->methods.set_key(current->plaintext, index);
4990  
4991 -               format->methods.crypt_all(1);
4992 +               format->methods.crypt_all(index + 1);
4993  
4994                 for (size = 0; size < 3; size++)
4995 -               if (format->methods.get_hash[size](0) !=
4996 -                       format->methods.binary_hash[size](binary)) break;
4997 -               if (size < 3) break;
4998 -
4999 -               if (!format->methods.cmp_all(binary, 1)) break;
5000 -               if (!format->methods.cmp_one(binary, 0)) break;
5001 -               if (!format->methods.cmp_exact(ciphertext, 0)) break;
5002 +               if (format->methods.get_hash[size](index) !=
5003 +                   format->methods.binary_hash[size](binary)) {
5004 +                       sprintf(s_size, "get_hash[%d]", size);
5005 +                       return s_size;
5006 +               }
5007 +
5008 +               if (!format->methods.cmp_all(binary, index + 1))
5009 +                       return "cmp_all";
5010 +               if (!format->methods.cmp_one(binary, index))
5011 +                       return "cmp_one";
5012 +               if (!format->methods.cmp_exact(ciphertext, index))
5013 +                       return "cmp_exact";
5014 +
5015 +               if (strncmp(format->methods.get_key(index), plaintext,
5016 +                   format->params.plaintext_length))
5017 +                       return "get_key";
5018  
5019 -               if (strncmp(format->methods.get_key(0), plaintext,
5020 -                       format->params.plaintext_length)) break;
5021 +               index = (index << 1) + 1; /* 0, 1, 3, 7, 15, 31, 63, ... */
5022 +               if (index >= max) index = 0;
5023         } while ((++current)->ciphertext);
5024  
5025 -       return current->ciphertext != NULL;
5026 +       return NULL;
5027  }
5028  
5029 -void fmt_default_init()
5030 +void fmt_default_init(void)
5031  {
5032  }
5033  
5034 @@ -110,6 +124,10 @@
5035         return 0;
5036  }
5037  
5038 +void fmt_default_clear_keys(void)
5039 +{
5040 +}
5041 +
5042  int fmt_default_get_hash(int index)
5043  {
5044         return 0;
5045 diff -ruN john-1.6/src/formats.h john-1.6.34/src/formats.h
5046 --- john-1.6/src/formats.h      1998-12-03 01:29:50.000000000 +0100
5047 +++ john-1.6.34/src/formats.h   2001-06-16 09:45:42.000000000 +0200
5048 @@ -1,6 +1,6 @@
5049  /*
5050   * This file is part of John the Ripper password cracker,
5051 - * Copyright (c) 1996-98 by Solar Designer
5052 + * Copyright (c) 1996-2001 by Solar Designer
5053   */
5054  
5055  /*
5056 @@ -15,6 +15,7 @@
5057   */
5058  #define FMT_CASE                       0x00000001
5059  #define FMT_8_BIT                      0x00000002
5060 +#define FMT_BS                         0x00010000
5061  
5062  /*
5063   * A password to test the methods for correct operation.
5064 @@ -72,7 +73,7 @@
5065  struct fmt_methods {
5066  /* Initializes the algorithm's internal structures, valid() is the only
5067   * method that is allowed to be called before a call to init(). */
5068 -       void (*init)();
5069 +       void (*init)(void);
5070  
5071  /* Checks if an ASCII ciphertext is valid for this format. Returns zero for
5072   * invalid ciphertexts, or a number of parts the ciphertext should be split
5073 @@ -107,6 +108,11 @@
5074  /* Returns a plaintext previously set with set_key() */
5075         char *(*get_key)(int index);
5076  
5077 +/* Allow the previously set keys to be dropped if that would help improve
5078 + * performance and/or reduce the impact of certain hardware faults. After
5079 + * a call to clear_keys() the keys are undefined. */
5080 +       void (*clear_keys)(void);
5081 +
5082  /* Calculates the ciphertexts for given salt and plaintexts. This may
5083   * always calculate at least min_keys_per_crypt ciphertexts regardless of
5084   * the requested count, for some formats. */
5085 @@ -162,21 +168,22 @@
5086  extern void fmt_init(struct fmt_main *format);
5087  
5088  /*
5089 - * Tests the format's methods for correct operation. Returns a non-zero value
5090 - * on error.
5091 + * Tests the format's methods for correct operation. Returns NULL on
5092 + * success, method name on error.
5093   */
5094 -extern int fmt_self_test(struct fmt_main *format);
5095 +extern char *fmt_self_test(struct fmt_main *format);
5096  
5097  /*
5098   * Default methods.
5099   */
5100 -extern void fmt_default_init();
5101 +extern void fmt_default_init(void);
5102  extern int fmt_default_valid(char *ciphertext);
5103  extern char *fmt_default_split(char *ciphertext, int index);
5104  extern void *fmt_default_binary(char *ciphertext);
5105  extern void *fmt_default_salt(char *ciphertext);
5106  extern int fmt_default_binary_hash(void *binary);
5107  extern int fmt_default_salt_hash(void *salt);
5108 +extern void fmt_default_clear_keys(void);
5109  extern int fmt_default_get_hash(int index);
5110  
5111  /*
5112 diff -ruN john-1.6/src/getopt.c john-1.6.34/src/getopt.c
5113 --- john-1.6/src/getopt.c       1998-12-03 01:29:50.000000000 +0100
5114 +++ john-1.6.34/src/getopt.c    2000-08-26 05:52:13.000000000 +0200
5115 @@ -1,6 +1,6 @@
5116  /*
5117   * This file is part of John the Ripper password cracker,
5118 - * Copyright (c) 1996-98 by Solar Designer
5119 + * Copyright (c) 1996-2000 by Solar Designer
5120   */
5121  
5122  #include <stdio.h>
5123 @@ -105,10 +105,9 @@
5124  
5125  static int opt_check_one(struct opt_entry *list, opt_flags flg, char *opt)
5126  {
5127 -       char *param;
5128         struct opt_entry *entry;
5129  
5130 -       param = opt_find(list, opt, &entry);
5131 +       opt_find(list, opt, &entry);
5132         if (!entry) return OPT_ERROR_UNKNOWN;
5133  
5134         if ((flg & entry->req_set) != entry->req_set || (flg & entry->req_clr))
5135 diff -ruN john-1.6/src/idle.c john-1.6.34/src/idle.c
5136 --- john-1.6/src/idle.c 1998-12-03 01:29:50.000000000 +0100
5137 +++ john-1.6.34/src/idle.c      2001-07-26 16:56:25.000000000 +0200
5138 @@ -1,15 +1,15 @@
5139  /*
5140   * This file is part of John the Ripper password cracker,
5141 - * Copyright (c) 1996-98 by Solar Designer
5142 + * Copyright (c) 1996-2001 by Solar Designer
5143   */
5144  
5145  #include <unistd.h>
5146  
5147 -#ifdef __linux__
5148 +#ifdef _POSIX_PRIORITY_SCHEDULING
5149  #include <sched.h>
5150 -#ifndef SCHED_IDLE
5151 -#define SCHED_IDLE                     3
5152 -#endif
5153 +#include <time.h>
5154 +#include <sys/times.h>
5155 +
5156  static int use_yield = 0;
5157  #endif
5158  
5159 @@ -17,30 +17,68 @@
5160  extern int nice(int);
5161  #endif
5162  
5163 +#ifdef __BEOS__
5164 +#include <OS.h>
5165 +#endif
5166 +
5167  #include "params.h"
5168  #include "config.h"
5169  #include "options.h"
5170 +#include "signals.h"
5171  
5172 -void idle_init()
5173 +void idle_init(void)
5174  {
5175 -#ifdef __linux__
5176 +#if defined(_POSIX_PRIORITY_SCHEDULING) && defined(SCHED_IDLE)
5177         struct sched_param param = {0};
5178  #endif
5179  
5180         if (!cfg_get_bool(SECTION_OPTIONS, NULL, "Idle")) return;
5181         if (options.flags & FLG_STDOUT) return;
5182  
5183 +#ifndef __BEOS__
5184         nice(20);
5185 +#else
5186 +       set_thread_priority(getpid(), 1);
5187 +#endif
5188  
5189 -#ifdef __linux__
5190 -       use_yield = sched_setscheduler(getpid(), SCHED_IDLE, &param) ? 1 : 2;
5191 +#if defined(_POSIX_PRIORITY_SCHEDULING) && defined(SCHED_IDLE)
5192 +       use_yield = sched_setscheduler(getpid(), SCHED_IDLE, &param) != 0;
5193 +#elif defined(_POSIX_PRIORITY_SCHEDULING)
5194 +       use_yield = 1;
5195  #endif
5196  }
5197  
5198 -void idle_yield(int always)
5199 +void idle_yield(void)
5200  {
5201 -#ifdef __linux__
5202 -       if (use_yield)
5203 -       if (use_yield == 1 || always) sched_yield();
5204 +#ifdef _POSIX_PRIORITY_SCHEDULING
5205 +       static int calls_per_tick = 0;
5206 +       static int calls_since_tick = 0;
5207 +       static int calls_since_adj = 0;
5208 +       static clock_t last_adj = 0;
5209 +       clock_t last_check;
5210 +       clock_t current;
5211 +       struct tms buf;
5212 +
5213 +       if (!use_yield) return;
5214 +
5215 +       if (++calls_since_tick < calls_per_tick) return;
5216 +       calls_since_adj += calls_since_tick;
5217 +       calls_since_tick = 0;
5218 +
5219 +       current = times(&buf);
5220 +       if (!last_adj) last_adj = current;
5221 +
5222 +       if (current - last_adj >= CLK_TCK) {
5223 +               calls_per_tick = calls_since_adj / (current - last_adj);
5224 +               calls_since_adj = 0;
5225 +               last_adj = current;
5226 +       }
5227 +
5228 +       do {
5229 +               if (event_pending) break;
5230 +               last_check = current;
5231 +               sched_yield();
5232 +               current = times(&buf);
5233 +       } while (current - last_check > 1 && current - last_adj < CLK_TCK);
5234  #endif
5235  }
5236 diff -ruN john-1.6/src/idle.h john-1.6.34/src/idle.h
5237 --- john-1.6/src/idle.h 1998-12-03 01:29:50.000000000 +0100
5238 +++ john-1.6.34/src/idle.h      2001-05-08 22:37:37.000000000 +0200
5239 @@ -1,6 +1,6 @@
5240  /*
5241   * This file is part of John the Ripper password cracker,
5242 - * Copyright (c) 1996-98 by Solar Designer
5243 + * Copyright (c) 1996-2001 by Solar Designer
5244   */
5245  
5246  /*
5247 @@ -14,12 +14,12 @@
5248   * Sets this process to idle priority, if supported and enabled in the
5249   * configuration file.
5250   */
5251 -extern void idle_init();
5252 +extern void idle_init(void);
5253  
5254  /*
5255   * If the idle_init() call was unable to set the idle priority, this can
5256   * still be used to yield a timeslice if there's something else to do.
5257   */
5258 -extern void idle_yield(int always);
5259 +extern void idle_yield(void);
5260  
5261  #endif
5262 diff -ruN john-1.6/src/inc.c john-1.6.34/src/inc.c
5263 --- john-1.6/src/inc.c  1998-12-03 01:29:50.000000000 +0100
5264 +++ john-1.6.34/src/inc.c       2003-06-29 15:18:57.000000000 +0200
5265 @@ -1,6 +1,6 @@
5266  /*
5267   * This file is part of John the Ripper password cracker,
5268 - * Copyright (c) 1996-98 by Solar Designer
5269 + * Copyright (c) 1996-2003 by Solar Designer
5270   */
5271  
5272  #include <stdio.h>
5273 @@ -28,6 +28,7 @@
5274  typedef char (*chars_table)
5275         [CHARSET_SIZE + 1][CHARSET_SIZE + 1][CHARSET_SIZE + 1];
5276  
5277 +static int rec_compat;
5278  static int rec_entry;
5279  static int rec_numbers[CHARSET_LENGTH];
5280  
5281 @@ -38,17 +39,26 @@
5282  {
5283         int pos;
5284  
5285 -       fprintf(file, "%d\n", rec_entry);
5286 +       fprintf(file, "%d\n%d\n%d\n", rec_entry, rec_compat, CHARSET_LENGTH);
5287         for (pos = 0; pos < CHARSET_LENGTH; pos++)
5288                 fprintf(file, "%d\n", rec_numbers[pos]);
5289  }
5290  
5291  static int restore_state(FILE *file)
5292  {
5293 +       int length;
5294         int pos;
5295  
5296         if (fscanf(file, "%d\n", &rec_entry) != 1) return 1;
5297 -       for (pos = 0; pos < CHARSET_LENGTH; pos++) {
5298 +       rec_compat = 1;
5299 +       length = CHARSET_LENGTH;
5300 +       if (rec_version >= 2) {
5301 +               if (fscanf(file, "%d\n%d\n", &rec_compat, &length) != 2)
5302 +                       return 1;
5303 +               if ((unsigned int)rec_compat > 1) return 1;
5304 +               if ((unsigned int)length > CHARSET_LENGTH) return 1;
5305 +       }
5306 +       for (pos = 0; pos < length; pos++) {
5307                 if (fscanf(file, "%d\n", &rec_numbers[pos]) != 1) return 1;
5308                 if ((unsigned int)rec_numbers[pos] >= CHARSET_SIZE) return 1;
5309         }
5310 @@ -56,7 +66,7 @@
5311         return 0;
5312  }
5313  
5314 -static void fix_state()
5315 +static void fix_state(void)
5316  {
5317         rec_entry = entry;
5318         memcpy(rec_numbers, numbers, sizeof(rec_numbers));
5319 @@ -164,11 +174,11 @@
5320         memset(present, 0, sizeof(present));
5321         while (*dptr) {
5322                 if (--count <= 1) return;
5323 -               present[((ARCH_INDEX)*dptr++) - CHARSET_MIN] = 1;
5324 +               present[ARCH_INDEX(*dptr++) - CHARSET_MIN] = 1;
5325         }
5326  
5327         while (*sptr)
5328 -       if (!present[(ARCH_INDEX)*sptr - CHARSET_MIN]) {
5329 +       if (!present[ARCH_INDEX(*sptr) - CHARSET_MIN]) {
5330                 *dptr++ = *sptr++;
5331                 if (--count <= 1) break;
5332         } else
5333 @@ -208,36 +218,86 @@
5334  static int inc_key_loop(int length, int fixed, int count,
5335         char *char1, char2_table char2, chars_table *chars)
5336  {
5337 -       char key[PLAINTEXT_BUFFER_SIZE];
5338 +       char key_i[PLAINTEXT_BUFFER_SIZE];
5339 +       char key_e[PLAINTEXT_BUFFER_SIZE];
5340 +       char *key;
5341 +       char *chars_cache;
5342 +       int numbers_cache;
5343         int pos;
5344  
5345 -       key[length + 1] = 0;
5346 +       key_i[length + 1] = 0;
5347         numbers[fixed] = count;
5348  
5349 -       do {
5350 -               key[0] = char1[numbers[0]];
5351 +       chars_cache = NULL;
5352 +
5353 +update_all:
5354 +       pos = 0;
5355 +update_ending:
5356 +       if (pos < 2) {
5357 +               if (pos == 0)
5358 +                       key_i[0] = char1[numbers[0]];
5359                 if (length)
5360 -                       key[1] = (*char2)[key[0] - CHARSET_MIN][numbers[1]];
5361 -               for (pos = 2; pos <= length; pos++)
5362 -                       key[pos] = (*chars[pos - 2])
5363 -                               [(ARCH_INDEX)key[pos - 2] - CHARSET_MIN]
5364 -                               [(ARCH_INDEX)key[pos - 1] - CHARSET_MIN]
5365 -                               [numbers[pos]];
5366 -
5367 -               if (ext_filter(key))
5368 -               if (crk_process_key(key)) return 1;
5369 -
5370 -               if (length) {
5371 -                       pos = 0;
5372 -                       do {
5373 -                               if (pos == fixed) continue;
5374 -                               if (++numbers[pos] <= count -
5375 -                                       ((pos < fixed) ? 1 : 0)) break;
5376 -                               numbers[pos] = 0;
5377 -                       } while (++pos <= length);
5378 -               } else
5379 -                       if (++numbers[0] <= count) pos = 0; else break;
5380 -       } while (pos <= length);
5381 +                       key_i[1] = (*char2)[key_i[0] - CHARSET_MIN][numbers[1]];
5382 +               pos = 2;
5383 +       }
5384 +       while (pos < length) {
5385 +               key_i[pos] = (*chars[pos - 2])
5386 +                       [ARCH_INDEX(key_i[pos - 2]) - CHARSET_MIN]
5387 +                       [ARCH_INDEX(key_i[pos - 1]) - CHARSET_MIN]
5388 +                       [numbers[pos]];
5389 +               pos++;
5390 +       }
5391 +       numbers_cache = numbers[length];
5392 +       if (pos == length) {
5393 +               chars_cache = (*chars[pos - 2])
5394 +                       [ARCH_INDEX(key_i[pos - 2]) - CHARSET_MIN]
5395 +                       [ARCH_INDEX(key_i[pos - 1]) - CHARSET_MIN];
5396 +update_last:
5397 +               key_i[length] = chars_cache[numbers_cache];
5398 +       }
5399 +
5400 +       key = key_i;
5401 +       if (!ext_mode || !f_filter || ext_filter_body(key_i, key = key_e))
5402 +       if (crk_process_key(key)) return 1;
5403 +
5404 +       if (rec_compat) goto compat;
5405 +
5406 +       pos = length;
5407 +       if (fixed < length) {
5408 +               if (++numbers_cache <= count) {
5409 +                       if (length >= 2) goto update_last;
5410 +                       numbers[length] = numbers_cache;
5411 +                       goto update_ending;
5412 +               }
5413 +               numbers[pos--] = 0;
5414 +               while (pos > fixed) {
5415 +                       if (++numbers[pos] <= count) goto update_ending;
5416 +                       numbers[pos--] = 0;
5417 +               }
5418 +       }
5419 +       while (pos-- > 0) {
5420 +               if (++numbers[pos] < count) goto update_ending;
5421 +               numbers[pos] = 0;
5422 +       }
5423 +
5424 +       return 0;
5425 +
5426 +compat:
5427 +       pos = 0;
5428 +       if (fixed) {
5429 +               if (++numbers[0] < count) goto update_all;
5430 +               if (!length && numbers[0] <= count) goto update_all;
5431 +               numbers[0] = 0;
5432 +               pos = 1;
5433 +               while (pos < fixed) {
5434 +                       if (++numbers[pos] < count) goto update_all;
5435 +                       numbers[pos++] = 0;
5436 +               }
5437 +       }
5438 +       while (++pos <= length) {
5439 +               if (++numbers[pos] <= count) goto update_all;
5440 +               numbers[pos] = 0;
5441 +       }
5442  
5443         return 0;
5444  }
5445 @@ -279,6 +339,29 @@
5446                 max_length = CHARSET_LENGTH;
5447         max_count = cfg_get_int(SECTION_INC, mode, "CharCount");
5448  
5449 +       if (min_length > max_length) {
5450 +               fprintf(stderr, "MinLen = %d exceeds MaxLen = %d\n",
5451 +                       min_length, max_length);
5452 +               error();
5453 +       }
5454 +
5455 +       if (max_length > CHARSET_LENGTH) {
5456 +               fprintf(stderr,
5457 +                       "\n"
5458 +                       "MaxLen = %d exceeds the compile-time limit of %d\n\n"
5459 +                       "There're several good reasons why you probably don't "
5460 +                       "need to raise it:\n"
5461 +                       "- many hash types don't support passwords "
5462 +                       "(or password halves) longer than\n"
5463 +                       "7 or 8 characters;\n"
5464 +                       "- you probably don't have sufficient statistical "
5465 +                       "information to generate a\n"
5466 +                       "charset file for lengths beyond 8;\n"
5467 +                       "- the limitation applies to incremental mode only.\n",
5468 +                       max_length, CHARSET_LENGTH);
5469 +               error();
5470 +       }
5471 +
5472         if (!(file = fopen(path_expand(charset), "rb")))
5473                 pexit("fopen: %s", path_expand(charset));
5474  
5475 @@ -306,7 +389,7 @@
5476  
5477         if (max_count < 0) max_count = CHARSET_SIZE; else
5478         if ((unsigned int)max_count > real_count)
5479 -               fprintf(stderr,"Warning: only %d characters available\n",
5480 +               fprintf(stderr, "Warning: only %d characters available\n",
5481                         real_count);
5482  
5483         if (header->length >= 2)
5484 @@ -316,6 +399,7 @@
5485         for (pos = 0; pos < (int)header->length - 2; pos++)
5486                 chars[pos] = (chars_table)mem_alloc(sizeof(*chars[0]));
5487  
5488 +       rec_compat = 0;
5489         rec_entry = 0;
5490         memset(rec_numbers, 0, sizeof(rec_numbers));
5491  
5492 diff -ruN john-1.6/src/john.c john-1.6.34/src/john.c
5493 --- john-1.6/src/john.c 1998-12-03 01:29:50.000000000 +0100
5494 +++ john-1.6.34/src/john.c      2002-04-11 19:58:45.000000000 +0200
5495 @@ -1,9 +1,10 @@
5496  /*
5497   * This file is part of John the Ripper password cracker,
5498 - * Copyright (c) 1996-98 by Solar Designer
5499 + * Copyright (c) 1996-2002 by Solar Designer
5500   */
5501  
5502  #include <stdio.h>
5503 +#include <unistd.h>
5504  #include <string.h>
5505  #include <stdlib.h>
5506  #include <sys/stat.h>
5507 @@ -16,7 +17,6 @@
5508  #include "list.h"
5509  #include "tty.h"
5510  #include "signals.h"
5511 -#include "idle.h"
5512  #include "common.h"
5513  #include "formats.h"
5514  #include "loader.h"
5515 @@ -33,7 +33,7 @@
5516  #include "batch.h"
5517  
5518  #if CPU_DETECT
5519 -extern int CPU_detect();
5520 +extern int CPU_detect(void);
5521  #endif
5522  
5523  extern struct fmt_main fmt_DES, fmt_BSDI, fmt_MD5, fmt_BF;
5524 @@ -54,7 +54,7 @@
5525         fmt_register(format);
5526  }
5527  
5528 -static void john_register_all()
5529 +static void john_register_all(void)
5530  {
5531         if (options.format) strlwr(options.format);
5532  
5533 @@ -71,7 +71,7 @@
5534         }
5535  }
5536  
5537 -static void john_load()
5538 +static void john_load(void)
5539  {
5540         struct list_entry *current;
5541  
5542 @@ -172,6 +172,13 @@
5543  #if CPU_DETECT
5544         if (!CPU_detect()) {
5545  #if CPU_REQ
5546 +#if CPU_FALLBACK
5547 +#if defined(__DJGPP__) || defined(__CYGWIN32__)
5548 +#error CPU_FALLBACK is incompatible with the current DOS and Win32 code
5549 +#endif
5550 +               execv(JOHN_SYSTEMWIDE_EXEC "/" CPU_FALLBACK_BINARY, argv);
5551 +               perror("execv");
5552 +#endif
5553                 fprintf(stderr, "Sorry, %s is required\n", CPU_NAME);
5554                 error();
5555  #endif
5556 @@ -179,19 +186,26 @@
5557  #endif
5558  
5559         path_init(argv);
5560 -       cfg_init(CFG_NAME);
5561 +
5562 +#if JOHN_SYSTEMWIDE
5563 +       cfg_init(CFG_PRIVATE_FULL_NAME, 1);
5564 +       cfg_init(CFG_PRIVATE_ALT_NAME, 1);
5565 +#endif
5566 +       cfg_init(CFG_FULL_NAME, 1);
5567 +       cfg_init(CFG_ALT_NAME, 0);
5568 +
5569         status_init(NULL, 1);
5570         opt_init(argc, argv);
5571  
5572         john_register_all();
5573         common_init();
5574  
5575 -       sig_init(idle_yield);
5576 +       sig_init();
5577  
5578         john_load();
5579  }
5580  
5581 -static void john_run()
5582 +static void john_run(void)
5583  {
5584         if (options.flags & FLG_TEST_CHK)
5585                 benchmark_all();
5586 @@ -225,7 +239,7 @@
5587         }
5588  }
5589  
5590 -static void john_done()
5591 +static void john_done(void)
5592  {
5593         path_done();
5594  
5595 @@ -259,14 +273,6 @@
5596                 name[strlen(name) - 4] = 0;
5597  #endif
5598  
5599 -       if (!strcmp(name, "john")) {
5600 -               john_init(argc, argv);
5601 -               john_run();
5602 -               john_done();
5603 -
5604 -               return 0;
5605 -       }
5606 -
5607         if (!strcmp(name, "unshadow"))
5608                 return unshadow(argc, argv);
5609  
5610 @@ -276,6 +282,9 @@
5611         if (!strcmp(name, "unique"))
5612                 return unique(argc, argv);
5613  
5614 -       fprintf(stderr, "Sorry, I can't find myself\n");
5615 -       return 1;
5616 +       john_init(argc, argv);
5617 +       john_run();
5618 +       john_done();
5619 +
5620 +       return 0;
5621  }
5622 diff -ruN john-1.6/src/LM_fmt.c john-1.6.34/src/LM_fmt.c
5623 --- john-1.6/src/LM_fmt.c       1998-12-03 01:29:50.000000000 +0100
5624 +++ john-1.6.34/src/LM_fmt.c    2001-08-19 05:06:18.000000000 +0200
5625 @@ -1,12 +1,14 @@
5626  /*
5627   * This file is part of John the Ripper password cracker,
5628 - * Copyright (c) 1996-98 by Solar Designer
5629 + * Copyright (c) 1996-2001 by Solar Designer
5630   */
5631  
5632  #include <string.h>
5633  
5634  #include "arch.h"
5635 -#include "DES_std.h"
5636 +#include "misc.h"
5637 +#include "memory.h"
5638 +#include "DES_bs.h"
5639  #include "common.h"
5640  #include "formats.h"
5641  
5642 @@ -20,54 +22,44 @@
5643  #define CIPHERTEXT_LENGTH              32
5644  
5645  #define LM_EMPTY                       "AAD3B435B51404EE"
5646 +#define LM_EMPTY_LOWER                 "aad3b435b51404ee"
5647  
5648  static struct fmt_tests tests[] = {
5649 -       {"$LM$1C3A2B6D939A1021", "AAA"},
5650 +       {"$LM$A9C604D244C4E99D", "AAAAAA"},
5651         {"$LM$CBC501A4D2227783", "AAAAAAA"},
5652 -       {"$LM$CE045FF77F9D89E2", "ZZZZ"},
5653 +       {"$LM$3466C2B0487FE39A", "CRACKPO"},
5654 +       {"$LM$DBC5E5CBA8028091", "IMPUNIT"},
5655         {LM_EMPTY LM_EMPTY, ""},
5656 -       {"$LM$7584248B8D2C9F9E", "A"},
5657 +       {"$LM$73CC402BD3E79175", "SCLEROS"},
5658 +       {"$LM$5ECD9236D21095CE", "YOKOHAM"},
5659 +       {"$LM$A5E6066DE61C3E35", "ZZZZZZZ"},
5660 +       {"$LM$1FB363FEB834C12D", "ZZZZZZ"},
5661         {NULL}
5662  };
5663  
5664 -#define ALGORITHM_NAME                 DES_STD_ALGORITHM_NAME
5665 +#define ALGORITHM_NAME                 DES_BS_ALGORITHM_NAME
5666  
5667  #define BINARY_SIZE                    ARCH_SIZE
5668  #define SALT_SIZE                      0
5669  
5670 -#define MIN_KEYS_PER_CRYPT             0x40
5671 -#define MAX_KEYS_PER_CRYPT             0x40
5672 +#define MIN_KEYS_PER_CRYPT             DES_BS_DEPTH
5673 +#define MAX_KEYS_PER_CRYPT             DES_BS_DEPTH
5674  
5675 -#define LM_IV_0                                0x2153474B
5676 -#define LM_IV_1                                0x25242340
5677 -
5678 -static struct {
5679 -       union {
5680 -               double dummy;
5681 -               DES_binary binary;
5682 -       } aligned;
5683 -       char key[PLAINTEXT_LENGTH + 1];
5684 -} buffer[MAX_KEYS_PER_CRYPT];
5685 -
5686 -static DES_binary LM_IV;
5687 -
5688 -static void init()
5689 -{
5690 -       DES_std_init();
5691 -       DES_std_set_salt(0);
5692 -       DES_count = 1;
5693 -
5694 -       DES_std_set_block(LM_IV_0, LM_IV_1);
5695 -       memcpy(LM_IV, DES_IV, sizeof(DES_binary));
5696 +static void init(void)
5697 +{
5698 +       DES_bs_init(1);
5699  }
5700  
5701  static int valid(char *ciphertext)
5702  {
5703         char *pos;
5704 +       char lower[CIPHERTEXT_LENGTH - 16 + 1];
5705  
5706 -       for (pos = ciphertext; atoi16[(ARCH_INDEX)*pos] != 0x7F; pos++);
5707 +       for (pos = ciphertext; atoi16[ARCH_INDEX(*pos)] != 0x7F; pos++);
5708         if (!*pos && pos - ciphertext == CIPHERTEXT_LENGTH) {
5709 -               if (strcmp(&ciphertext[16], LM_EMPTY))
5710 +               strcpy(lower, &ciphertext[16]);
5711 +               strlwr(lower);
5712 +               if (strcmp(lower, LM_EMPTY_LOWER))
5713                         return 2;
5714                 else
5715                         return 1;
5716 @@ -75,7 +67,7 @@
5717  
5718         if (strncmp(ciphertext, "$LM$", 4)) return 0;
5719  
5720 -       for (pos = &ciphertext[4]; atoi16[(ARCH_INDEX)*pos] != 0x7F; pos++);
5721 +       for (pos = &ciphertext[4]; atoi16[ARCH_INDEX(*pos)] != 0x7F; pos++);
5722         if (*pos || pos - ciphertext != 20) return 0;
5723  
5724         return 1;
5725 @@ -103,149 +95,65 @@
5726  
5727  static void *get_binary(char *ciphertext)
5728  {
5729 -       static DES_binary out;
5730 -       ARCH_WORD_32 block[2];
5731 -       int index, value;
5732 -
5733 -       block[0] = block[1] = 0;
5734 -       for (index = 0; index < 16; index += 2) {
5735 -               value = (int)atoi16[(ARCH_INDEX)ciphertext[index + 4]] << 4;
5736 -               value |= atoi16[(ARCH_INDEX)ciphertext[index + 5]];
5737 -
5738 -               block[index >> 3] |= value << ((index << 2) & 0x18);
5739 -       }
5740 -
5741 -       DES_std_set_block(block[0], block[1]);
5742 -       memcpy(out, DES_IV, sizeof(DES_binary));
5743 -
5744 -       return out;
5745 +       return DES_bs_get_binary_LM(ciphertext + 4);
5746  }
5747  
5748  static int binary_hash_0(void *binary)
5749  {
5750 -       return DES_STD_HASH_0(*(ARCH_WORD *)binary);
5751 +       return *(ARCH_WORD *)binary & 0xF;
5752  }
5753  
5754  static int binary_hash_1(void *binary)
5755  {
5756 -       return DES_STD_HASH_1(*(ARCH_WORD *)binary);
5757 +       return *(ARCH_WORD *)binary & 0xFF;
5758  }
5759  
5760  static int binary_hash_2(void *binary)
5761  {
5762 -       return DES_STD_HASH_2(*(ARCH_WORD *)binary);
5763 +       return *(ARCH_WORD *)binary & 0xFFF;
5764  }
5765  
5766  static int get_hash_0(int index)
5767  {
5768 -       return DES_STD_HASH_0(buffer[index].aligned.binary[0]);
5769 +       return DES_bs_get_hash(index, 4);
5770  }
5771  
5772  static int get_hash_1(int index)
5773  {
5774 -       ARCH_WORD binary;
5775 -
5776 -       binary = buffer[index].aligned.binary[0];
5777 -       return DES_STD_HASH_1(binary);
5778 +       return DES_bs_get_hash(index, 8);
5779  }
5780  
5781  static int get_hash_2(int index)
5782  {
5783 -       ARCH_WORD binary;
5784 -
5785 -       binary = buffer[index].aligned.binary[0];
5786 -       return DES_STD_HASH_2(binary);
5787 +       return DES_bs_get_hash(index, 12);
5788  }
5789  
5790  static void set_salt(void *salt)
5791  {
5792  }
5793  
5794 -static void crypt_all(int count)
5795 -{
5796 -       int index;
5797 -       unsigned char *key7;
5798 -       union {
5799 -               char b[8];
5800 -               ARCH_WORD_32 w[2];
5801 -       } key8;
5802 -
5803 -       for (index = 0; index < count; index++) {
5804 -               key7 = (unsigned char *)buffer[index].key;
5805 -               key8.b[0] = key7[0] >> 1;
5806 -               key8.b[1] = ((key7[0] & 0x01) << 6) | (key7[1] >> 2);
5807 -               key8.b[2] = ((key7[1] & 0x03) << 5) | (key7[2] >> 3);
5808 -               key8.b[3] = ((key7[2] & 0x07) << 4) | (key7[3] >> 4);
5809 -               key8.b[4] = ((key7[3] & 0x0F) << 3) | (key7[4] >> 5);
5810 -               key8.b[5] = ((key7[4] & 0x1F) << 2) | (key7[5] >> 6);
5811 -               key8.b[6] = ((key7[5] & 0x3F) << 1) | (key7[6] >> 7);
5812 -               key8.b[7] = key7[6];
5813 -               key8.w[0] |= 0x80808080;
5814 -               key8.w[1] |= 0x80808080;
5815 -
5816 -               DES_std_set_key(key8.b);
5817 -
5818 -               DES_IV[0] = LM_IV[0];
5819 -               DES_IV[1] = LM_IV[1];
5820 -#if ARCH_BITS < 64
5821 -               DES_IV[2] = LM_IV[2];
5822 -               DES_IV[3] = LM_IV[3];
5823 -#endif
5824 -
5825 -               DES_std_crypt(DES_KS_current, buffer[index].aligned.binary);
5826 -       }
5827 -}
5828 -
5829  static int cmp_all(void *binary, int count)
5830  {
5831 -       int index;
5832 -
5833 -       for (index = 0; index < count; index++)
5834 -       if (*(unsigned ARCH_WORD *)binary == buffer[index].aligned.binary[0])
5835 -               return 1;
5836 -
5837 -       return 0;
5838 +       return DES_bs_cmp_all((ARCH_WORD *)binary);
5839  }
5840  
5841  static int cmp_one(void *binary, int index)
5842  {
5843 -       return *(unsigned ARCH_WORD *)binary ==
5844 -               buffer[index].aligned.binary[0];
5845 +       return DES_bs_cmp_one((ARCH_WORD *)binary, 32, index);
5846  }
5847  
5848  static int cmp_exact(char *source, int index)
5849  {
5850 -       ARCH_WORD *binary;
5851 -       int word;
5852 -
5853 -       binary = (ARCH_WORD *)get_binary(source);
5854 -
5855 -       for (word = 0; word < 16 / DES_SIZE; word++)
5856 -       if ((unsigned ARCH_WORD)binary[word] !=
5857 -           buffer[index].aligned.binary[word])
5858 -               return 0;
5859 -
5860 -       return 1;
5861 -}
5862 -
5863 -static void set_key(char *key, int index)
5864 -{
5865 -       char *dst = buffer[index].key;
5866 -       char *src = key;
5867 -       int count = PLAINTEXT_LENGTH;
5868 -
5869 -       do {
5870 -               if (*src >= 'a' && *src <= 'z')
5871 -                       *dst++ = *src++ & ~0x20;
5872 -               else
5873 -                       if ((*dst++ = *src)) src++;
5874 -       } while (--count);
5875 -       *dst = 0;
5876 +       return DES_bs_cmp_one(get_binary(source), 64, index);
5877  }
5878  
5879  static char *get_key(int index)
5880  {
5881 -       return buffer[index].key;
5882 +#if !DES_BS_VECTOR && ARCH_BITS >= 64
5883 +       return (char *)DES_bs_all.E.extras.keys[index];
5884 +#else
5885 +       return (char *)DES_bs_all.keys[index];
5886 +#endif
5887  }
5888  
5889  struct fmt_main fmt_LM = {
5890 @@ -260,7 +168,7 @@
5891                 SALT_SIZE,
5892                 MIN_KEYS_PER_CRYPT,
5893                 MAX_KEYS_PER_CRYPT,
5894 -               FMT_8_BIT,
5895 +               FMT_8_BIT | FMT_BS,
5896                 tests
5897         }, {
5898                 init,
5899 @@ -275,9 +183,10 @@
5900                 },
5901                 fmt_default_salt_hash,
5902                 set_salt,
5903 -               set_key,
5904 +               DES_bs_set_key_LM,
5905                 get_key,
5906 -               crypt_all,
5907 +               DES_bs_clear_keys_LM,
5908 +               (void (*)(int))DES_bs_crypt_LM,
5909                 {
5910                         get_hash_0,
5911                         get_hash_1,
5912 diff -ruN john-1.6/src/loader.c john-1.6.34/src/loader.c
5913 --- john-1.6/src/loader.c       1998-12-03 01:29:50.000000000 +0100
5914 +++ john-1.6.34/src/loader.c    2000-08-26 05:59:56.000000000 +0200
5915 @@ -1,6 +1,6 @@
5916  /*
5917   * This file is part of John the Ripper password cracker,
5918 - * Copyright (c) 1996-98 by Solar Designer
5919 + * Copyright (c) 1996-2000 by Solar Designer
5920   */
5921  
5922  #include <stdio.h>
5923 @@ -29,7 +29,7 @@
5924   * Word separator characters for ldr_split_words(), used on GECOS fields.
5925   */
5926  #define issep \
5927 -       "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~\177\377"
5928 +       "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~\177"
5929  
5930  static char issep_map[0x100];
5931  static int issep_initialized = 0;
5932 @@ -65,7 +65,7 @@
5933         if (fclose(file)) pexit("fclose");
5934  }
5935  
5936 -static void ldr_init_issep()
5937 +static void ldr_init_issep(void)
5938  {
5939         char *pos;
5940  
5941 @@ -75,7 +75,7 @@
5942  
5943         memset(issep_map, 1, 33);
5944         for (pos = issep; *pos; pos++)
5945 -               issep_map[(ARCH_INDEX)*pos] = 1;
5946 +               issep_map[ARCH_INDEX(*pos)] = 1;
5947  
5948         issep_initialized = 1;
5949  }
5950 @@ -246,11 +246,11 @@
5951         pos = src;
5952         do {
5953                 word = pos;
5954 -               while (*word && issep_map[(ARCH_INDEX)*word]) word++;
5955 +               while (*word && issep_map[ARCH_INDEX(*word)]) word++;
5956                 if (!*word) break;
5957  
5958                 pos = word;
5959 -               while (!issep_map[(ARCH_INDEX)*pos]) pos++;
5960 +               while (!issep_map[ARCH_INDEX(*pos)]) pos++;
5961                 if (*pos) *pos++ = 0;
5962  
5963                 list_add_unique(dst, word);
5964 @@ -340,8 +340,7 @@
5965                 if (!current_salt) {
5966                         last_salt = db->salt_hash[salt_hash];
5967                         current_salt = db->salt_hash[salt_hash] =
5968 -                               mem_alloc_tiny(sizeof(struct db_salt),
5969 -                               MEM_ALIGN_WORD);
5970 +                               mem_alloc_tiny(salt_size, MEM_ALIGN_WORD);
5971                         current_salt->next = last_salt;
5972  
5973                         current_salt->salt = mem_alloc_copy(
5974 @@ -541,6 +540,8 @@
5975                 for (size = 2; size >= 0; size--)
5976                 if (current->count >= password_hash_thresholds[size]) break;
5977  
5978 +               if ((db->format->params.flags & FMT_BS) && !size) size = -1;
5979 +
5980                 if (size >= 0 && mem_saving_level < 2) {
5981                         current->hash = mem_alloc_tiny(
5982                                 password_hash_sizes[size] *
5983 diff -ruN john-1.6/src/logger.c john-1.6.34/src/logger.c
5984 --- john-1.6/src/logger.c       1998-12-03 01:29:50.000000000 +0100
5985 +++ john-1.6.34/src/logger.c    1999-09-22 05:57:17.000000000 +0200
5986 @@ -1,6 +1,6 @@
5987  /*
5988   * This file is part of John the Ripper password cracker,
5989 - * Copyright (c) 1996-98 by Solar Designer
5990 + * Copyright (c) 1996-99 by Solar Designer
5991   */
5992  
5993  #include <stdio.h>
5994 @@ -41,7 +41,7 @@
5995         cfg_beep = cfg_get_bool(SECTION_OPTIONS, NULL, "Beep");
5996  }
5997  
5998 -static void log_write()
5999 +static void log_write(void)
6000  {
6001         int size;
6002  
6003 @@ -72,7 +72,7 @@
6004                 write_loop(fileno(stderr), "\007", 1);
6005  }
6006  
6007 -void log_flush()
6008 +void log_flush(void)
6009  {
6010         if (log_fd) {
6011                 if (log_bufptr != log_buffer) log_write();
6012 @@ -82,7 +82,7 @@
6013         }
6014  }
6015  
6016 -void log_done()
6017 +void log_done(void)
6018  {
6019         if (log_fd) {
6020                 log_flush();
6021 diff -ruN john-1.6/src/logger.h john-1.6.34/src/logger.h
6022 --- john-1.6/src/logger.h       1998-12-03 01:29:50.000000000 +0100
6023 +++ john-1.6.34/src/logger.h    1999-09-22 05:41:22.000000000 +0200
6024 @@ -1,6 +1,6 @@
6025  /*
6026   * This file is part of John the Ripper password cracker,
6027 - * Copyright (c) 1996-98 by Solar Designer
6028 + * Copyright (c) 1996-99 by Solar Designer
6029   */
6030  
6031  /*
6032 @@ -24,11 +24,11 @@
6033  /*
6034   * Writes the log file buffer to disk.
6035   */
6036 -extern void log_flush();
6037 +extern void log_flush(void);
6038  
6039  /*
6040   * Closes the log file.
6041   */
6042 -extern void log_done();
6043 +extern void log_done(void);
6044  
6045  #endif
6046 diff -ruN john-1.6/src/Makefile john-1.6.34/src/Makefile
6047 --- john-1.6/src/Makefile       1998-12-03 01:29:50.000000000 +0100
6048 +++ john-1.6.34/src/Makefile    2003-06-29 15:16:53.000000000 +0200
6049 @@ -1,6 +1,6 @@
6050  #
6051  # This file is part of John the Ripper password cracker,
6052 -# Copyright (c) 1996-98 by Solar Designer
6053 +# Copyright (c) 1996-2003 by Solar Designer
6054  #
6055  
6056  CPP = gcc
6057 @@ -10,6 +10,7 @@
6058  CP = cp
6059  LN = ln -sf
6060  RM = rm -f
6061 +TR = tr
6062  SED = sed
6063  NULL = /dev/null
6064  CPPFLAGS = -E
6065 @@ -19,18 +20,18 @@
6066  OPT_NORMAL = -funroll-loops
6067  OPT_INLINE = -finline-functions
6068  
6069 -JOHN_VERSION = 1.6
6070 +JOHN_VERSION = 1.6.34
6071  JOHN_ARCHIVE = john-$(JOHN_VERSION)
6072  
6073  JOHN_DIST = \
6074         $(JOHN_ARCHIVE)/src/*.{c,h,S,sh,asm,com,diff} \
6075         $(JOHN_ARCHIVE)/src/Makefile{,.dep} \
6076 -       $(JOHN_ARCHIVE)/run/{mailer,john.ini,*.chr,password.lst} \
6077 +       $(JOHN_ARCHIVE)/run/{mailer,john.conf,*.chr,password.lst} \
6078         $(JOHN_ARCHIVE)/doc/* \
6079         $(JOHN_ARCHIVE)/README
6080  
6081 -JOHN_OBJS_ORIG = \
6082 -       DES_fmt.o DES_std.o \
6083 +JOHN_OBJS_MINIMAL = \
6084 +       DES_fmt.o DES_std.o DES_bs.o \
6085         BSDI_fmt.o \
6086         MD5_fmt.o MD5_std.o \
6087         BF_fmt.o BF_std.o \
6088 @@ -44,12 +45,13 @@
6089         unafs.o \
6090         unique.o
6091  
6092 +JOHN_OBJS_ORIG = \
6093 +       $(JOHN_OBJS_MINIMAL) \
6094 +       DES_bs_b.o
6095 +
6096  JOHN_OBJS = \
6097         $(JOHN_OBJS_ORIG)
6098  
6099 -BITSLICE_OBJS = \
6100 -       DES_bs.o DES_bs_b.o
6101 -
6102  BENCH_DES_OBJS_ORIG = \
6103         DES_fmt.o DES_std.o
6104  
6105 @@ -57,15 +59,15 @@
6106         $(BENCH_DES_OBJS_ORIG)
6107  
6108  BENCH_MD5_OBJS_DEPEND = \
6109 -       MD5_std.o
6110 +       MD5_fmt.o MD5_std.o
6111  
6112  BENCH_BF_OBJS_DEPEND = \
6113         BF_std.o
6114  
6115  BENCH_OBJS = \
6116 -       $(BITSLICE_OBJS) \
6117         $(BENCH_DES_OBJS_DEPEND) \
6118 -       MD5_fmt.o $(BENCH_MD5_OBJS_DEPEND) \
6119 +       DES_bs.o DES_bs_b.o \
6120 +       $(BENCH_MD5_OBJS_DEPEND) \
6121         BF_fmt.o $(BENCH_BF_OBJS_DEPEND) \
6122         bench.o best.o common.o config.o formats.o memory.o misc.o params.o \
6123         path.o signals.o tty.o
6124 @@ -82,125 +84,135 @@
6125         @echo "where SYSTEM can be one of the following:"
6126         @echo "linux-x86-any-elf        Linux, x86, ELF binaries"
6127         @echo "linux-x86-mmx-elf        Linux, x86 with MMX, ELF binaries"
6128 -       @echo "linux-x86-k6-elf         Linux, AMD K6, ELF binaries"
6129         @echo "linux-x86-any-a.out      Linux, x86, a.out binaries"
6130         @echo "linux-alpha              Linux, Alpha"
6131 -       @echo "linux-sparc              Linux, SPARC"
6132 -       @echo "freebsd-x86-any-a.out    FreeBSD, x86, a.out binaries"
6133 -       @echo "freebsd-x86-k6-a.out     FreeBSD, AMD K6, a.out binaries"
6134 +       @echo "linux-sparc              Linux, SPARC 32-bit"
6135 +       @echo "linux-ppc                Linux, PowerPC"
6136         @echo "freebsd-x86-any-elf      FreeBSD, x86, ELF binaries"
6137         @echo "freebsd-x86-mmx-elf      FreeBSD, x86 with MMX, ELF binaries"
6138 -       @echo "freebsd-x86-k6-elf       FreeBSD, AMD K6, ELF binaries"
6139 +       @echo "freebsd-x86-any-a.out    FreeBSD, x86, a.out binaries"
6140 +       @echo "freebsd-alpha            FreeBSD, Alpha"
6141         @echo "openbsd-x86-any          OpenBSD, x86"
6142 -       @echo "openbsd-x86-k6           OpenBSD, AMD K6"
6143 -       @echo "solaris-sparc-gcc        Solaris, SPARC, gcc"
6144 -       @echo "solaris-sparc-v8-cc      Solaris, SPARC V8, cc"
6145 -       @echo "solaris-sparc-v9-cc      Solaris, SPARC V9, cc"
6146 +       @echo "openbsd-sparc            OpenBSD, SPARC 32-bit"
6147 +       @echo "openbsd-vax              OpenBSD, VAX"
6148 +       @echo "netbsd-vax               NetBSD, VAX"
6149 +       @echo "solaris-sparc-gcc        Solaris, SPARC 32-bit, gcc"
6150 +       @echo "solaris-sparc64-gcc      Solaris, SPARC V9 64-bit, gcc"
6151 +       @echo "solaris-sparc-v8-cc      Solaris, SPARC V8 32-bit, cc"
6152 +       @echo "solaris-sparc-v9-cc      Solaris, SPARC V9 32-bit, cc"
6153 +       @echo "solaris-sparc64-cc       Solaris, SPARC V9 64-bit, cc"
6154         @echo "solaris-x86-any          Solaris, x86, gcc"
6155 -       @echo "solaris-x86-k6           Solaris, AMD K6, gcc"
6156 -       @echo "digital-alpha-cc         Digital UNIX, Alpha, cc"
6157 +       @echo "sco-x86-any-gcc          SCO, x86, gcc, ELF binaries"
6158 +       @echo "sco-x86-any-cc           SCO, x86, cc, ELF binaries"
6159 +       @echo "tru64-alpha-cc           Tru64 (Digital UNIX, OSF/1), Alpha, cc"
6160         @echo "aix-ppc-cc               AIX, PowerPC, cc"
6161 +       @echo "macosx-ppc-cc            MacOS X, PowerPC, cc"
6162         @echo "hpux-pa-risc-gcc         HP-UX, PA-RISC, gcc"
6163 -       @echo "hpux-pa-risc-cc          HP-UX, PA-RISC, cc"
6164 +       @echo "hpux-pa-risc-cc          HP-UX, PA-RISC, ANSI cc"
6165         @echo "irix-mips32-cc           IRIX, MIPS 32-bit, cc"
6166         @echo "irix-mips64-cc           IRIX, MIPS 64-bit, cc"
6167 +       @echo "irix-mips64-r10k-cc      IRIX, MIPS 64-bit (R10K), cc"
6168         @echo "dos-djgpp-x86-any        DOS, DJGPP 2.x, x86"
6169         @echo "dos-djgpp-x86-mmx        DOS, DJGPP 2.x, x86 with MMX"
6170 -       @echo "dos-djgpp-x86-k6         DOS, DJGPP 2.x, AMD K6"
6171         @echo "win32-cygwin-x86-any     Win32, Cygwin, x86"
6172         @echo "win32-cygwin-x86-mmx     Win32, Cygwin, x86 with MMX"
6173 -       @echo "win32-cygwin-x86-k6      Win32, Cygwin, AMD K6"
6174 -       @echo "generic                  Any other UNIX system with gcc"
6175 +       @echo "beos-x86-any             BeOS, x86"
6176 +       @echo "beos-x86-mmx             BeOS, x86 with MMX"
6177 +       @echo "generic                  Any other Unix system with gcc"
6178  
6179  linux-x86-any-elf:
6180         $(LN) x86-any.h arch.h
6181         $(MAKE) $(PROJ) \
6182 -               JOHN_OBJS="$(JOHN_OBJS) x86.o" \
6183 -               CFLAGS="$(CFLAGS) -m486"
6184 +               JOHN_OBJS="$(JOHN_OBJS) x86.o"
6185  
6186  linux-x86-mmx-elf:
6187         $(LN) x86-mmx.h arch.h
6188         $(MAKE) $(PROJ) \
6189 -               JOHN_OBJS="$(JOHN_OBJS) x86.o" \
6190 -               CFLAGS="$(CFLAGS) -m486"
6191 -
6192 -linux-x86-k6-elf:
6193 -       $(LN) x86-k6.h arch.h
6194 -       $(MAKE) $(PROJ) \
6195 -               JOHN_OBJS="$(BITSLICE_OBJS) $(JOHN_OBJS) x86.o"
6196 +               JOHN_OBJS="$(JOHN_OBJS_MINIMAL) x86.o x86-mmx.o"
6197  
6198  linux-x86-any-a.out:
6199         $(LN) x86-any.h arch.h
6200         $(MAKE) $(PROJ) \
6201                 JOHN_OBJS="$(JOHN_OBJS) x86.o" \
6202 -               CFLAGS="$(CFLAGS) -m486" \
6203                 ASFLAGS="$(ASFLAGS) -DUNDERSCORES -DALIGN_LOG"
6204  
6205  linux-alpha:
6206         $(LN) alpha.h arch.h
6207         $(MAKE) $(PROJ) \
6208 -               JOHN_OBJS="$(BITSLICE_OBJS) $(JOHN_OBJS) alpha.o"
6209 +               JOHN_OBJS="$(JOHN_OBJS) alpha.o"
6210  
6211 -linux-alpha-very-slow-cache:
6212 -       $(LN) alpha-4k.h arch.h
6213 +# This target is currently "undocumented" as ccc generates much slower
6214 +# code for the large unrolled loops in John; let's hope it gets fixed.
6215 +linux-alpha-ccc:
6216 +       $(LN) alpha.h arch.h
6217         $(MAKE) $(PROJ) \
6218 +               CPP=ccc CC=ccc AS=ccc LD=ccc \
6219 +               CFLAGS="-c -Wf,-switch,noil_schedule" \
6220 +               OPT_NORMAL="-fast" \
6221 +               OPT_INLINE="-O2 -arch host" \
6222                 JOHN_OBJS="$(JOHN_OBJS) alpha.o"
6223  
6224  linux-sparc:
6225 -       $(MAKE) HAMMER=use-linux-sparc sparc.h
6226 -       ln -s sparc.h arch.h
6227 +       $(MAKE) use-linux-sparc HAMMER=use-linux-sparc NAIL=sparc.h
6228 +       $(LN) sparc.h arch.h
6229         $(MAKE) use-linux-sparc NAIL="$(PROJ)"
6230  
6231  use-linux-sparc:
6232         $(MAKE) $(NAIL) \
6233                 BENCH_DES_OBJS_DEPEND="$(BENCH_DES_OBJS_ORIG) sparc.o" \
6234 -               JOHN_OBJS="$(BITSLICE_OBJS) $(JOHN_OBJS_ORIG) sparc.o"
6235 -
6236 -freebsd-x86-any-a.out:
6237 -       $(LN) x86-any.h arch.h
6238 -       $(MAKE) $(PROJ) \
6239 -               JOHN_OBJS="$(JOHN_OBJS) x86.o" \
6240 -               CFLAGS="$(CFLAGS) -m486" \
6241 -               ASFLAGS="$(ASFLAGS) -DUNDERSCORES -DALIGN_LOG -DBSD"
6242 +               JOHN_OBJS="$(JOHN_OBJS_ORIG) sparc.o"
6243  
6244 -freebsd-x86-k6-a.out:
6245 -       $(LN) x86-k6.h arch.h
6246 -       $(MAKE) $(PROJ) \
6247 -               JOHN_OBJS="$(BITSLICE_OBJS) $(JOHN_OBJS) x86.o" \
6248 -               ASFLAGS="$(ASFLAGS) -DUNDERSCORES -DALIGN_LOG -DBSD"
6249 +linux-ppc:
6250 +       $(LN) ppc.h arch.h
6251 +       $(MAKE) $(PROJ)
6252  
6253  freebsd-x86-any-elf:
6254         $(LN) x86-any.h arch.h
6255         $(MAKE) $(PROJ) \
6256                 JOHN_OBJS="$(JOHN_OBJS) x86.o" \
6257 -               CFLAGS="$(CFLAGS) -m486" \
6258                 ASFLAGS="$(ASFLAGS) -DBSD"
6259  
6260  freebsd-x86-mmx-elf:
6261         $(LN) x86-mmx.h arch.h
6262         $(MAKE) $(PROJ) \
6263 -               JOHN_OBJS="$(JOHN_OBJS) x86.o" \
6264 -               CFLAGS="$(CFLAGS) -m486" \
6265 +               JOHN_OBJS="$(JOHN_OBJS_MINIMAL) x86.o x86-mmx.o" \
6266                 ASFLAGS="$(ASFLAGS) -DBSD"
6267  
6268 -freebsd-x86-k6-elf:
6269 -       $(LN) x86-k6.h arch.h
6270 +freebsd-x86-any-a.out:
6271 +       $(LN) x86-any.h arch.h
6272         $(MAKE) $(PROJ) \
6273 -               JOHN_OBJS="$(BITSLICE_OBJS) $(JOHN_OBJS) x86.o" \
6274 -               ASFLAGS="$(ASFLAGS) -DBSD"
6275 +               JOHN_OBJS="$(JOHN_OBJS) x86.o" \
6276 +               ASFLAGS="$(ASFLAGS) -DUNDERSCORES -DALIGN_LOG -DBSD"
6277 +
6278 +freebsd-alpha:
6279 +       $(LN) alpha.h arch.h
6280 +       $(MAKE) $(PROJ) \
6281 +               JOHN_OBJS="$(JOHN_OBJS) alpha.o"
6282  
6283  openbsd-x86-any:
6284         $(LN) x86-any.h arch.h
6285         $(MAKE) $(PROJ) \
6286                 JOHN_OBJS="$(JOHN_OBJS) x86.o" \
6287 -               CFLAGS="$(CFLAGS) -m486" \
6288                 ASFLAGS="$(ASFLAGS) -DUNDERSCORES -DALIGN_LOG -DBSD"
6289  
6290 -openbsd-x86-k6:
6291 -       $(LN) x86-k6.h arch.h
6292 -       $(MAKE) $(PROJ) \
6293 -               JOHN_OBJS="$(BITSLICE_OBJS) $(JOHN_OBJS) x86.o" \
6294 -               ASFLAGS="$(ASFLAGS) -DUNDERSCORES -DALIGN_LOG -DBSD"
6295 +openbsd-sparc:
6296 +       $(MAKE) use-openbsd-sparc HAMMER=use-openbsd-sparc NAIL=sparc.h
6297 +       $(LN) sparc.h arch.h
6298 +       $(MAKE) use-openbsd-sparc NAIL="$(PROJ)"
6299 +
6300 +use-openbsd-sparc:
6301 +       $(MAKE) $(NAIL) \
6302 +               BENCH_DES_OBJS_DEPEND="$(BENCH_DES_OBJS_ORIG) sparc.o" \
6303 +               JOHN_OBJS="$(JOHN_OBJS_ORIG) sparc.o" \
6304 +               ASFLAGS="-c -DUNDERSCORES -DBSD"
6305 +
6306 +openbsd-vax:
6307 +       $(LN) vax.h arch.h
6308 +       $(MAKE) $(PROJ)
6309 +
6310 +netbsd-vax:
6311 +       $(LN) vax.h arch.h
6312 +       $(MAKE) $(PROJ)
6313  
6314  solaris-sparc-any:
6315         $(MAKE) $(HAMMER) NAIL=sparc.h
6316 @@ -220,27 +232,28 @@
6317  use-solaris-sparc-gcc:
6318         $(MAKE) $(NAIL) \
6319                 BENCH_DES_OBJS_DEPEND="$(BENCH_DES_OBJS_ORIG) sparc.o" \
6320 -               JOHN_OBJS="$(BITSLICE_OBJS) $(JOHN_OBJS_ORIG) sparc.o"
6321 +               JOHN_OBJS="$(JOHN_OBJS_ORIG) sparc.o" \
6322 +               LDFLAGS="-s -lrt"
6323  
6324  use-solaris-sparc-v8-cc:
6325         $(MAKE) $(NAIL) \
6326                 BENCH_DES_OBJS_DEPEND="$(BENCH_DES_OBJS_ORIG) spro-sparc.o" \
6327 -               JOHN_OBJS="$(BITSLICE_OBJS) $(JOHN_OBJS_ORIG) spro-sparc.o" \
6328 +               JOHN_OBJS="$(JOHN_OBJS_ORIG) spro-sparc.o" \
6329                 CPP=cc CC=cc AS=cc LD=cc \
6330                 CFLAGS="-c -xO4 -xarch=v8" \
6331 -               LDFLAGS="-s -lc" \
6332 +               LDFLAGS="-s -lc -lrt" \
6333                 OPT_NORMAL="" \
6334 -               OPT_INLINE="-xinline=S1,S2,S3,S4,S5,S6,S7,S8"
6335 +               OPT_INLINE="-xinline=s1,s2,s3,s4,s5,s6,s7,s8"
6336  
6337  use-solaris-sparc-v9-cc:
6338         $(MAKE) $(NAIL) \
6339                 BENCH_DES_OBJS_DEPEND="$(BENCH_DES_OBJS_ORIG) spro-sparc.o" \
6340 -               JOHN_OBJS="$(BITSLICE_OBJS) $(JOHN_OBJS_ORIG) spro-sparc.o" \
6341 +               JOHN_OBJS="$(JOHN_OBJS_ORIG) spro-sparc.o" \
6342                 CPP=cc CC=cc AS=cc LD=cc \
6343                 CFLAGS="-c -xO4 -xarch=v8plusa -xchip=ultra" \
6344 -               LDFLAGS="-s -lc" \
6345 +               LDFLAGS="-s -lc -lrt" \
6346                 OPT_NORMAL="" \
6347 -               OPT_INLINE="-xinline=S1,S2,S3,S4,S5,S6,S7,S8"
6348 +               OPT_INLINE="-xinline=s1,s2,s3,s4,s5,s6,s7,s8"
6349  
6350  sparc.h:
6351         $(RM) arch.h
6352 @@ -250,66 +263,107 @@
6353  
6354  # Older versions of spro cc didn't support .S files directly
6355  spro-sparc.o: sparc.S
6356 -       $(CPP) $(CPPFLAGS) sparc.S > tmp.s
6357 +       $(CPP) $(CPPFLAGS) sparc.S | $(SED) 's/% /%/g' > tmp.s
6358         $(AS) $(ASFLAGS) tmp.s -o spro-sparc.o
6359         $(RM) tmp.s
6360  
6361 +solaris-sparc64-cc:
6362 +       $(LN) sparc64.h arch.h
6363 +       $(MAKE) $(PROJ) \
6364 +               CPP=cc CC=cc AS=cc LD=cc \
6365 +               CFLAGS="-c -fast -xarch=native64" \
6366 +               LDFLAGS="-xarch=native64 -s -lc -lrt" \
6367 +               OPT_NORMAL="" \
6368 +               OPT_INLINE="-xinline=s1,s2,s3,s4,s5,s6,s7,s8"
6369 +
6370 +solaris-sparc64-gcc:
6371 +       $(LN) sparc64.h arch.h
6372 +       $(MAKE) $(PROJ) \
6373 +               CFLAGS="$(CFLAGS) -m64 -mcpu=ultrasparc" \
6374 +               LDFLAGS="-m64 -s -lrt"
6375 +
6376  solaris-x86-any:
6377         $(RM) arch.h
6378         ln -s x86-any.h arch.h
6379         $(MAKE) $(PROJ) \
6380                 SHELL=/bin/sh \
6381                 JOHN_OBJS="$(JOHN_OBJS) solaris-x86.o" \
6382 -               CFLAGS="$(CFLAGS) -m486"
6383 -
6384 -solaris-x86-k6:
6385 -       $(RM) arch.h
6386 -       ln -s x86-k6.h arch.h
6387 -       $(MAKE) $(PROJ) \
6388 -               SHELL=/bin/sh \
6389 -               JOHN_OBJS="$(BITSLICE_OBJS) $(JOHN_OBJS) solaris-x86.o"
6390 +               LDFLAGS="-s -lc -lrt"
6391  
6392  # Solaris x86 got a broken assembler, with line length restriction (and some
6393  # other problems, that are worked around in x86.S)
6394  solaris-x86.o: x86.S
6395 -       $(CPP) $(CPPFLAGS) -P -DSOLARIS x86.S | tr \; \\n > tmp.s
6396 +       $(CPP) $(CPPFLAGS) -P -DDUMBAS x86.S | $(TR) \; \\n > tmp.s
6397         $(AS) $(ASFLAGS) tmp.s -o solaris-x86.o
6398         $(RM) tmp.s
6399  
6400 -digital-alpha-cc:
6401 +sco-x86-any-gcc:
6402 +       $(RM) arch.h
6403 +       ln -s x86-any.h arch.h
6404 +       $(MAKE) $(PROJ) \
6405 +               SHELL=/bin/sh \
6406 +               JOHN_OBJS="$(JOHN_OBJS) sco-x86.o"
6407 +
6408 +sco-x86-any-cc:
6409 +       $(RM) arch.h
6410 +       ln -s x86-any.h arch.h
6411 +       $(MAKE) $(PROJ) \
6412 +               SHELL=/bin/sh \
6413 +               JOHN_OBJS="$(JOHN_OBJS) sco-x86.o" \
6414 +               CPP=cc CC=cc AS=cc LD=cc \
6415 +               CFLAGS="-c -b elf -O3" \
6416 +               ASFLAGS="-c -b elf" \
6417 +               OPT_NORMAL="-K loop_unroll,no_inline" \
6418 +               OPT_INLINE="-K inline"
6419 +
6420 +# SCO is even worse than Solaris x86
6421 +sco-x86.o: x86.S
6422 +       $(CPP) $(CPPFLAGS) -DDUMBAS x86.S | \
6423 +               $(TR) \; \\n | $(SED) 's/\([%.]\) /\1/g' > tmp.s
6424 +       $(AS) $(ASFLAGS) tmp.s -o sco-x86.o
6425 +       $(RM) tmp.s
6426 +
6427 +tru64-alpha-cc:
6428         $(LN) alpha.h arch.h
6429         $(MAKE) $(PROJ) \
6430 -               JOHN_OBJS="$(BITSLICE_OBJS) $(JOHN_OBJS) digital-alpha.o" \
6431 +               JOHN_OBJS="$(JOHN_OBJS) digipaq-alpha.o" \
6432                 CPP=cc CC=cc AS=cc LD=cc \
6433 -               CFLAGS="-c -O5 -tune host" \
6434 +               CFLAGS="-c -O4 -arch host" \
6435                 OPT_NORMAL="" \
6436                 OPT_INLINE="-inline all"
6437  
6438 -# DEC's cc and make use the .S suffix for a different purpose...
6439 -digital-alpha.o: alpha.S
6440 +# Digital/Compaq's cc and make use the .S suffix for a different purpose...
6441 +digipaq-alpha.o: alpha.S
6442         $(CPP) $(CPPFLAGS) alpha.S > tmp.s
6443 -       $(AS) $(ASFLAGS) tmp.s -o digital-alpha.o
6444 +       $(AS) $(ASFLAGS) tmp.s -o digipaq-alpha.o
6445         $(RM) tmp.s
6446  
6447  aix-ppc-cc:
6448         $(LN) ppc.h arch.h
6449         $(MAKE) $(PROJ) \
6450 -               JOHN_OBJS="$(BITSLICE_OBJS) $(JOHN_OBJS)" \
6451                 CPP=cc CC=cc AS=cc LD=cc \
6452 -               CFLAGS="-c -qunroll -qarch=ppc -qtune=601 -qchars=signed" \
6453 +               CFLAGS="-c -qunroll -qarch=ppc -qchars=signed" \
6454                 LDFLAGS="-s -lbsd" \
6455                 OPT_NORMAL="-O2" \
6456                 OPT_INLINE="-O3 -Q=99 -w"
6457  
6458 +macosx-ppc-cc:
6459 +       $(LN) ppc.h arch.h
6460 +       $(MAKE) $(PROJ) \
6461 +               CPP=cc CC=cc AS=cc LD=cc \
6462 +               CFLAGS="-c -traditional-cpp" \
6463 +               LDFLAGS="" \
6464 +               OPT_NORMAL="-O2" \
6465 +               OPT_INLINE="-O3"
6466 +
6467  hpux-pa-risc-gcc:
6468         $(LN) pa-risc.h arch.h
6469         $(MAKE) $(PROJ) \
6470 -               JOHN_OBJS="$(BITSLICE_OBJS) $(JOHN_OBJS)"
6471 +               CFLAGS="-c -Wall -O3 -fomit-frame-pointer"
6472  
6473  hpux-pa-risc-cc:
6474         $(LN) pa-risc.h arch.h
6475         $(MAKE) $(PROJ) \
6476 -               JOHN_OBJS="$(BITSLICE_OBJS) $(JOHN_OBJS)" \
6477                 CPP=cc CC=cc AS=cc LD=cc \
6478                 CFLAGS="-c -Aa -D_HPUX_SOURCE -DANSI_CPP" \
6479                 LDFLAGS="-s" \
6480 @@ -319,7 +373,6 @@
6481  irix-mips32-cc:
6482         $(LN) mips32.h arch.h
6483         $(MAKE) $(PROJ) \
6484 -               JOHN_OBJS="$(BITSLICE_OBJS) $(JOHN_OBJS)" \
6485                 CPP=cc CC=cc AS=cc LD=cc \
6486                 CFLAGS="-c -O2 -32 -signed" \
6487                 LDFLAGS="-s -32" \
6488 @@ -329,7 +382,15 @@
6489  irix-mips64-cc:
6490         $(LN) mips64.h arch.h
6491         $(MAKE) $(PROJ) \
6492 -               JOHN_OBJS="$(BITSLICE_OBJS) $(JOHN_OBJS)" \
6493 +               CPP=cc CC=cc AS=cc LD=cc \
6494 +               CFLAGS="-c -O2 -64 -mips3 -signed" \
6495 +               LDFLAGS="-s -64 -mips3" \
6496 +               OPT_NORMAL="-LNO:opt=1 -OPT:Olimit=2194" \
6497 +               OPT_INLINE="-INLINE:all"
6498 +
6499 +irix-mips64-r10k-cc:
6500 +       $(LN) mips64.h arch.h
6501 +       $(MAKE) $(PROJ) \
6502                 CPP=cc CC=cc AS=cc LD=cc \
6503                 CFLAGS="-c -O2 -64 -mips4 -r10000 -signed" \
6504                 LDFLAGS="-s -64 -mips4 -r10000" \
6505 @@ -340,50 +401,40 @@
6506         copy x86-any.h arch.h
6507         $(MAKE) $(PROJ_DOS) \
6508                 JOHN_OBJS="$(JOHN_OBJS) x86.o" \
6509 -               CFLAGS="$(CFLAGS) -m486" \
6510                 ASFLAGS="$(ASFLAGS) -DUNDERSCORES -DALIGN_LOG"
6511  
6512  dos-djgpp-x86-mmx:
6513         copy x86-mmx.h arch.h
6514         $(MAKE) $(PROJ_DOS) \
6515 -               JOHN_OBJS="$(JOHN_OBJS) x86.o" \
6516 -               CFLAGS="$(CFLAGS) -m486" \
6517 -               ASFLAGS="$(ASFLAGS) -DUNDERSCORES -DALIGN_LOG"
6518 -
6519 -dos-djgpp-x86-k6:
6520 -       copy x86-k6.h arch.h
6521 -       copy nonstd.c DES_bs_s.c
6522 -       $(MAKE) $(PROJ_DOS) \
6523 -               JOHN_OBJS="$(BITSLICE_OBJS) $(JOHN_OBJS) x86.o" \
6524 +               JOHN_OBJS="$(JOHN_OBJS_MINIMAL) x86.o x86-mmx.o" \
6525                 ASFLAGS="$(ASFLAGS) -DUNDERSCORES -DALIGN_LOG"
6526  
6527  win32-cygwin-x86-any:
6528         $(CP) x86-any.h arch.h
6529         $(MAKE) $(PROJ_WIN32) \
6530                 JOHN_OBJS="$(JOHN_OBJS) x86.o" \
6531 -               CFLAGS="$(CFLAGS) -mpentium" \
6532                 ASFLAGS="$(ASFLAGS) -DUNDERSCORES"
6533  
6534  win32-cygwin-x86-mmx:
6535         $(CP) x86-mmx.h arch.h
6536         $(MAKE) $(PROJ_WIN32) \
6537 -               JOHN_OBJS="$(JOHN_OBJS) x86.o" \
6538 -               CFLAGS="$(CFLAGS) -mpentium" \
6539 +               JOHN_OBJS="$(JOHN_OBJS_MINIMAL) x86.o x86-mmx.o" \
6540                 ASFLAGS="$(ASFLAGS) -DUNDERSCORES"
6541  
6542 -win32-cygwin-x86-k6:
6543 -       $(CP) x86-k6.h arch.h
6544 -       $(CP) nonstd.c DES_bs_s.c
6545 -       $(MAKE) $(PROJ_WIN32) \
6546 -               JOHN_OBJS="$(BITSLICE_OBJS) $(JOHN_OBJS) x86.o" \
6547 -               CFLAGS="-c -Wall -O -fomit-frame-pointer" \
6548 -               ASFLAGS="$(ASFLAGS) -DUNDERSCORES"
6549 +beos-x86-any:
6550 +       $(LN) x86-any.h arch.h
6551 +       $(MAKE) $(PROJ) \
6552 +               JOHN_OBJS="$(JOHN_OBJS) x86.o"
6553 +
6554 +beos-x86-mmx:
6555 +       $(LN) x86-mmx.h arch.h
6556 +       $(MAKE) $(PROJ) \
6557 +               JOHN_OBJS="$(JOHN_OBJS_MINIMAL) x86.o x86-mmx.o"
6558  
6559  generic: generic.h
6560         $(RM) arch.h
6561         ln -s generic.h arch.h
6562 -       $(MAKE) $(PROJ) \
6563 -               JOHN_OBJS="$(BITSLICE_OBJS) $(JOHN_OBJS)"
6564 +       $(MAKE) $(PROJ)
6565  
6566  generic.h:
6567         $(RM) arch.h
6568 @@ -401,12 +452,15 @@
6569         $(LD) $(LDFLAGS) $(JOHN_OBJS) -o ../run/john
6570  
6571  ../run/unshadow: ../run/john
6572 +       $(RM) ../run/unshadow
6573         ln -s john ../run/unshadow
6574  
6575  ../run/unafs: ../run/john
6576 +       $(RM) ../run/unafs
6577         ln -s john ../run/unafs
6578  
6579  ../run/unique: ../run/john
6580 +       $(RM) ../run/unique
6581         ln -s john ../run/unique
6582  
6583  ../run/john.bin: $(JOHN_OBJS)
6584 @@ -446,7 +500,7 @@
6585         strip ../run/unique.exe
6586  
6587  # Inlining the S-boxes produces faster code, as long as they fit in the cache
6588 -# (that is, on RISC with at least 8 Kb of L1 code cache).
6589 +# (that is, on RISC with at least 8 KB of L1 code cache).
6590  DES_bs_b.o: DES_bs_b.c DES_bs_s.c
6591         $(CC) $(CFLAGS) $(OPT_INLINE) DES_bs_b.c
6592  
6593 diff -ruN john-1.6/src/math.h john-1.6.34/src/math.h
6594 --- john-1.6/src/math.h 1998-12-03 01:29:50.000000000 +0100
6595 +++ john-1.6.34/src/math.h      2001-02-16 06:48:37.000000000 +0100
6596 @@ -1,15 +1,18 @@
6597  /*
6598   * This file is part of John the Ripper password cracker,
6599 - * Copyright (c) 1996-98 by Solar Designer
6600 + * Copyright (c) 1996-2001 by Solar Designer
6601   */
6602  
6603  /*
6604 - * 64 bit integer math functions.
6605 + * 64-bit integer math functions.
6606   */
6607  
6608  #ifndef _JOHN_MATH_H
6609  #define _JOHN_MATH_H
6610  
6611 +#undef int64
6612 +#define int64 _john_int64_t
6613 +
6614  typedef struct {
6615         unsigned int lo, hi;
6616  } int64;
6617 diff -ruN john-1.6/src/MD5_fmt.c john-1.6.34/src/MD5_fmt.c
6618 --- john-1.6/src/MD5_fmt.c      1998-12-03 01:29:50.000000000 +0100
6619 +++ john-1.6.34/src/MD5_fmt.c   2001-11-13 12:34:32.000000000 +0100
6620 @@ -1,6 +1,6 @@
6621  /*
6622   * This file is part of John the Ripper password cracker,
6623 - * Copyright (c) 1996-98 by Solar Designer
6624 + * Copyright (c) 1996-2001 by Solar Designer
6625   */
6626  
6627  #include <string.h>
6628 @@ -23,8 +23,8 @@
6629  #define BINARY_SIZE                    4
6630  #define SALT_SIZE                      8
6631  
6632 -#define MIN_KEYS_PER_CRYPT             1
6633 -#define MAX_KEYS_PER_CRYPT             1
6634 +#define MIN_KEYS_PER_CRYPT             MD5_N
6635 +#define MAX_KEYS_PER_CRYPT             MD5_N
6636  
6637  static struct fmt_tests tests[] = {
6638         {"$1$12345678$aIccj83HRDBo6ux1bVx7D1", "0123456789ABCDE"},
6639 @@ -34,7 +34,7 @@
6640         {NULL}
6641  };
6642  
6643 -static char saved_key[PLAINTEXT_LENGTH + 1];
6644 +static char saved_key[MD5_N][PLAINTEXT_LENGTH + 1];
6645  
6646  static int valid(char *ciphertext)
6647  {
6648 @@ -43,12 +43,14 @@
6649         if (strncmp(ciphertext, "$1$", 3)) return 0;
6650  
6651         for (pos = &ciphertext[3]; *pos && *pos != '$'; pos++);
6652 -       if (!*pos || pos < &ciphertext[4] || pos > &ciphertext[11]) return 0;
6653 +       if (!*pos || pos < &ciphertext[3] || pos > &ciphertext[11]) return 0;
6654  
6655         start = ++pos;
6656 -       while (atoi64[(ARCH_INDEX)*pos] != 0x7F) pos++;
6657 +       while (atoi64[ARCH_INDEX(*pos)] != 0x7F) pos++;
6658         if (*pos || pos - start != CIPHERTEXT_LENGTH) return 0;
6659  
6660 +       if (atoi64[ARCH_INDEX(*(pos - 1))] & 0x3C) return 0;
6661 +
6662         return 1;
6663  }
6664  
6665 @@ -69,48 +71,53 @@
6666  
6667  static int get_hash_0(int index)
6668  {
6669 -       return MD5_out[0] & 0xF;
6670 +       return MD5_out[index][0] & 0xF;
6671  }
6672  
6673  static int get_hash_1(int index)
6674  {
6675 -       return MD5_out[0] & 0xFF;
6676 +       return MD5_out[index][0] & 0xFF;
6677  }
6678  
6679  static int get_hash_2(int index)
6680  {
6681 -       return MD5_out[0] & 0xFFF;
6682 +       return MD5_out[index][0] & 0xFFF;
6683  }
6684  
6685  static int salt_hash(void *salt)
6686  {
6687         return
6688 -               ((int)atoi64[(ARCH_INDEX)((char *)salt)[0]] | 
6689 -               ((int)atoi64[(ARCH_INDEX)((char *)salt)[1]] << 6)) & 0x3FF;
6690 +               ((int)atoi64[ARCH_INDEX(((char *)salt)[0])] | 
6691 +               ((int)atoi64[ARCH_INDEX(((char *)salt)[1])] << 6)) & 0x3FF;
6692  }
6693  
6694  static void set_key(char *key, int index)
6695  {
6696 -       MD5_std_set_key(key);
6697 +       MD5_std_set_key(key, index);
6698  
6699 -       strnfcpy(saved_key, key, PLAINTEXT_LENGTH);
6700 +       strnfcpy(saved_key[index], key, PLAINTEXT_LENGTH);
6701  }
6702  
6703  static char *get_key(int index)
6704  {
6705 -       saved_key[PLAINTEXT_LENGTH] = 0;
6706 +       saved_key[index][PLAINTEXT_LENGTH] = 0;
6707  
6708 -       return saved_key;
6709 +       return saved_key[index];
6710  }
6711  
6712  static int cmp_all(void *binary, int index)
6713  {
6714 -       return *(MD5_word *)binary == MD5_out[0];
6715 +#if MD5_X2
6716 +       return *(MD5_word *)binary == MD5_out[0][0] ||
6717 +               *(MD5_word *)binary == MD5_out[1][0];
6718 +#else
6719 +       return *(MD5_word *)binary == MD5_out[0][0];
6720 +#endif
6721  }
6722  
6723  static int cmp_exact(char *source, int index)
6724  {
6725 -       return !memcmp(MD5_std_get_binary(source), MD5_out,
6726 +       return !memcmp(MD5_std_get_binary(source), MD5_out[index],
6727                 sizeof(MD5_binary));
6728  }
6729  
6730 @@ -129,7 +136,7 @@
6731                 FMT_CASE | FMT_8_BIT,
6732                 tests
6733         }, {
6734 -               fmt_default_init,
6735 +               MD5_std_init,
6736                 valid,
6737                 fmt_default_split,
6738                 (void *(*)(char *))MD5_std_get_binary,
6739 @@ -143,6 +150,7 @@
6740                 (void (*)(void *))MD5_std_set_salt,
6741                 set_key,
6742                 get_key,
6743 +               fmt_default_clear_keys,
6744                 (void (*)(int))MD5_std_crypt,
6745                 {
6746                         get_hash_0,
6747 diff -ruN john-1.6/src/MD5_std.c john-1.6.34/src/MD5_std.c
6748 --- john-1.6/src/MD5_std.c      1998-12-03 01:29:50.000000000 +0100
6749 +++ john-1.6.34/src/MD5_std.c   2001-06-17 08:52:32.000000000 +0200
6750 @@ -1,6 +1,6 @@
6751  /*
6752   * This file is part of John the Ripper password cracker,
6753 - * Copyright (c) 1996-98 by Solar Designer
6754 + * Copyright (c) 1996-2001 by Solar Designer
6755   *
6756   * Based on the RSA Data Security, Inc. MD5 Message-Digest Algorithm and
6757   * FreeBSD MD5-based crypt(3) by Poul-Henning Kamp <phk@login.dknet.dk>.
6758 @@ -14,12 +14,34 @@
6759  #include "common.h"
6760  #include "MD5_std.h"
6761  
6762 -MD5_binary MD5_out;
6763 +MD5_std_combined CC_CACHE_ALIGN MD5_std_all;
6764  
6765 -typedef union {
6766 -       MD5_word w[15];
6767 -       char b[60];
6768 -} MD5_block;
6769 +#if !MD5_IMM
6770 +static MD5_data MD5_data_init = {
6771 +       {
6772 +               0xd76aa477, 0xf8fa0bcc, 0xbcdb4dd9, 0xb18b7a77,
6773 +               0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501,
6774 +               0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be,
6775 +               0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821,
6776 +               0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa,
6777 +               0xd62f105d, 0x02441453, 0xd8a1e681, 0xe7d3fbc8,
6778 +               0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed,
6779 +               0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a,
6780 +               0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c,
6781 +               0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70,
6782 +               0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x04881d05,
6783 +               0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665,
6784 +               0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039,
6785 +               0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1,
6786 +               0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1,
6787 +               0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391
6788 +       }, {
6789 +               0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476
6790 +       }, {
6791 +               0x77777777, 0x00ff00ff
6792 +       }
6793 +};
6794 +#endif
6795  
6796  #if !MD5_ASM
6797  
6798 @@ -40,11 +62,6 @@
6799  #define S43                            15
6800  #define S44                            21
6801  
6802 -#define Ca                             0x67452301
6803 -#define Cb                             0xefcdab89
6804 -#define Cc                             0x98badcfe
6805 -#define Cd                             0x10325476
6806 -
6807  #if MD5_IMM
6808  
6809  /*
6810 @@ -52,9 +69,9 @@
6811   */
6812  
6813  #define AC1                            0xd76aa477
6814 -#define AC2                            0xe8c7b756
6815 -#define AC3                            0x242070db
6816 -#define AC4                            0xc1bdceee
6817 +#define AC2pCd                         0xf8fa0bcc
6818 +#define AC3pCc                         0xbcdb4dd9
6819 +#define AC4pCb                         0xb18b7a77
6820  #define AC5                            0xf57c0faf
6821  #define AC6                            0x4787c62a
6822  #define AC7                            0xa8304613
6823 @@ -115,40 +132,28 @@
6824  #define AC62                           0xbd3af235
6825  #define AC63                           0x2ad7d2bb
6826  #define AC64                           0xeb86d391
6827 +
6828 +#define Ca                             0x67452301
6829 +#define Cb                             0xefcdab89
6830 +#define Cc                             0x98badcfe
6831 +#define Cd                             0x10325476
6832 +
6833  #define MASK1                          0x77777777
6834  
6835 +#define OOFFOOFF                       0x00ff00ff
6836 +
6837  #else
6838  
6839  /*
6840 - * If we used immediate values on RISC with 32 bit instruction size, it would
6841 - * take 130 instructions to load all the 65 values. Keeping the values in an
6842 - * array instead reduces the instruction count to 67.
6843 + * If we used immediate values on RISC with 32-bit instruction size, it would
6844 + * take about twice more instructions to load all the values.
6845   */
6846  
6847 -static MD5_word MD5_AC[65] = {
6848 -       0xd76aa477, 0xe8c7b756, 0x242070db, 0xc1bdceee,
6849 -       0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501,
6850 -       0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be,
6851 -       0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821,
6852 -       0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa,
6853 -       0xd62f105d, 0x02441453, 0xd8a1e681, 0xe7d3fbc8,
6854 -       0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed,
6855 -       0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a,
6856 -       0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c,
6857 -       0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70,
6858 -       0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x04881d05,
6859 -       0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665,
6860 -       0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039,
6861 -       0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1,
6862 -       0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1,
6863 -       0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391,
6864 -       0x77777777
6865 -};
6866 -
6867 +#define MD5_AC                         MD5_std_all.data.AC
6868  #define AC1                            MD5_AC[0]
6869 -#define AC2                            MD5_AC[1]
6870 -#define AC3                            MD5_AC[2]
6871 -#define AC4                            MD5_AC[3]
6872 +#define AC2pCd                         MD5_AC[1]
6873 +#define AC3pCc                         MD5_AC[2]
6874 +#define AC4pCb                         MD5_AC[3]
6875  #define AC5                            MD5_AC[4]
6876  #define AC6                            MD5_AC[5]
6877  #define AC7                            MD5_AC[6]
6878 @@ -209,7 +214,16 @@
6879  #define AC62                           MD5_AC[61]
6880  #define AC63                           MD5_AC[62]
6881  #define AC64                           MD5_AC[63]
6882 -#define MASK1                          MD5_AC[64]
6883 +
6884 +#define MD5_IV                         MD5_std_all.data.IV
6885 +#define Ca                             MD5_IV[0]
6886 +#define Cb                             MD5_IV[1]
6887 +#define Cc                             MD5_IV[2]
6888 +#define Cd                             MD5_IV[3]
6889 +
6890 +#define MASK1                          MD5_std_all.data.masks[0]
6891 +
6892 +#define OOFFOOFF                       MD5_std_all.data.masks[1]
6893  
6894  #endif
6895  
6896 @@ -225,7 +239,7 @@
6897   * ROTATE_LEFT rotates x left n bits.
6898   */
6899  #define ROTATE_LEFT(x, n) \
6900 -       (x) = (((x) << (n)) | ((x) >> (32 - (n))))
6901 +       (x) = (((x) << (n)) | ((MD5_word)(x) >> (32 - (n))))
6902  
6903  /*
6904   * FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
6905 @@ -252,16 +266,339 @@
6906         ROTATE_LEFT ((a), (s)); \
6907         (a) += (b);
6908  
6909 +#if MD5_X2
6910 +static void MD5_body(MD5_word x0[15], MD5_word x1[15],
6911 +       MD5_word out0[4], MD5_word out1[4]);
6912 +#else
6913 +static void MD5_body(MD5_word x[15], MD5_word out[4]);
6914 +#endif
6915 +
6916 +#else
6917 +
6918 +extern void MD5_body(MD5_word x[15], MD5_word out[4]);
6919 +
6920 +#endif
6921 +
6922 +static unsigned char PADDING[56] = {
6923 +       0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
6924 +       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
6925 +       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
6926 +};
6927 +
6928 +#if ARCH_LITTLE_ENDIAN
6929 +
6930 +#define MD5_swap(x, y, count)
6931 +
6932 +#else
6933 +
6934 +static void MD5_swap(MD5_word *x, MD5_word *y, int count)
6935 +{
6936 +       register MD5_word tmp, mask;
6937 +
6938 +       mask = OOFFOOFF;
6939 +       do {
6940 +               tmp = *x++;
6941 +               ROTATE_LEFT(tmp, 16);
6942 +               *y++ = ((tmp & mask) << 8) | ((tmp >> 8) & mask);
6943 +       } while (--count);
6944 +}
6945 +
6946 +#endif
6947 +
6948 +#define order                          MD5_std_all.order
6949 +#define pool                           MD5_std_all.pool
6950 +#define block                          MD5_std_all.block
6951 +
6952 +static void init_line(int line, int index, MD5_block *even, MD5_block *odd)
6953 +{
6954 +       order[line][index].even = even;
6955 +       order[line][index].odd = odd;
6956 +}
6957 +
6958 +void MD5_std_init(void)
6959 +{
6960 +       int index;
6961 +       MD5_pool *current;
6962 +
6963 +#if !MD5_IMM
6964 +       MD5_std_all.data = MD5_data_init;
6965 +#endif
6966 +
6967 +       for (index = 0, current = pool; index < MD5_N; index++, current++) {
6968 +               init_line(0, index, &current->e.p, &current->o.psp);
6969 +               init_line(1, index, &current->e.spp, &current->o.pp);
6970 +               init_line(2, index, &current->e.spp, &current->o.psp);
6971 +               init_line(3, index, &current->e.pp, &current->o.ps);
6972 +               init_line(4, index, &current->e.spp, &current->o.pp);
6973 +               init_line(5, index, &current->e.spp, &current->o.psp);
6974 +               init_line(6, index, &current->e.pp, &current->o.psp);
6975 +               init_line(7, index, &current->e.sp, &current->o.pp);
6976 +               init_line(8, index, &current->e.spp, &current->o.psp);
6977 +               init_line(9, index, &current->e.pp, &current->o.psp);
6978 +               init_line(10, index, &current->e.spp, &current->o.p);
6979 +               init_line(11, index, &current->e.spp, &current->o.psp);
6980 +               init_line(12, index, &current->e.pp, &current->o.psp);
6981 +               init_line(13, index, &current->e.spp, &current->o.pp);
6982 +               init_line(14, index, &current->e.sp, &current->o.psp);
6983 +               init_line(15, index, &current->e.pp, &current->o.psp);
6984 +               init_line(16, index, &current->e.spp, &current->o.pp);
6985 +               init_line(17, index, &current->e.spp, &current->o.ps);
6986 +               init_line(18, index, &current->e.pp, &current->o.psp);
6987 +               init_line(19, index, &current->e.spp, &current->o.pp);
6988 +               init_line(20, index, &current->e.spp, &current->o.psp);
6989 +       }
6990 +}
6991 +
6992 +void MD5_std_set_salt(char *salt)
6993 +{
6994 +       int length;
6995 +
6996 +       for (length = 0; length < 8 && salt[length]; length++);
6997 +
6998 +       memcpy(pool[0].s, salt, pool[0].l.s = length);
6999 +#if MD5_X2
7000 +       memcpy(pool[1].s, salt, pool[1].l.s = length);
7001 +#endif
7002 +}
7003 +
7004 +void MD5_std_set_key(char *key, int index)
7005 +{
7006 +       int length;
7007 +       MD5_pool *current;
7008 +
7009 +       for (length = 0; key[length] && length < 15; length++);
7010 +       current = &pool[index];
7011 +
7012 +       memcpy(current->o.p.b, key, current->l.p = length);
7013 +       memcpy(&current->o.p.b[length + 16], PADDING, 40 - length);
7014 +       current->o.p.w[14] = (length + 16) << 3;
7015 +
7016 +       memcpy(current->o.pp.b, key, length);
7017 +       memcpy(&current->o.pp.b[length], key, length);
7018 +       current->l.pp = length << 1;
7019 +       memcpy(&current->o.pp.b[current->l.pp + 16], PADDING,
7020 +               40 - current->l.pp);
7021 +       current->o.pp.w[14] = (current->l.pp + 16) << 3;
7022 +
7023 +       memcpy(&current->e.p.b[16], key, length);
7024 +       memcpy(&current->e.p.b[16 + length], PADDING, 40 - length);
7025 +       current->e.p.w[14] = (length + 16) << 3;
7026 +       MD5_swap(current->e.p.w, current->e.p.w, 14);
7027 +
7028 +       memcpy(&current->e.pp.b[16], current->o.pp.b, current->l.pp);
7029 +       memcpy(&current->e.pp.b[16 + current->l.pp], PADDING,
7030 +               40 - current->l.pp);
7031 +       current->e.pp.w[14] = (current->l.pp + 16) << 3;
7032 +       MD5_swap(current->e.pp.w, current->e.pp.w, 14);
7033 +
7034 +       order[1][index].length = current->l.pp;
7035 +       order[4][index].length = current->l.pp;
7036 +       order[7][index].length = current->l.pp;
7037 +       order[10][index].length = length;
7038 +       order[13][index].length = current->l.pp;
7039 +       order[16][index].length = current->l.pp;
7040 +       order[19][index].length = current->l.pp;
7041 +}
7042 +
7043 +void MD5_std_crypt(void)
7044 +{
7045 +       int length, index, mask;
7046 +       MD5_pattern *line;
7047 +#if ARCH_LITTLE_ENDIAN
7048 +       MD5_word *last0;
7049 +#endif
7050 +#if MD5_X2
7051 +       MD5_pool *key;
7052 +#if ARCH_LITTLE_ENDIAN
7053 +       MD5_word *last1;
7054 +#endif
7055 +#endif
7056 +
7057 +#if MD5_X2
7058 +       for (index = 0, key = pool; index < MD5_N; index++, key++) {
7059 +#else
7060 +#define index  0
7061 +#define key    pool
7062 +#endif
7063 +               memcpy(key->o.ps.b, key->o.p.b, key->l.p);
7064 +               memcpy(&key->o.ps.b[key->l.p], key->s, key->l.s);
7065 +               key->l.ps = key->l.p + key->l.s;
7066 +               memcpy(&key->o.ps.b[key->l.ps + 16], PADDING,
7067 +                       40 - key->l.ps);
7068 +               key->o.ps.w[14] = (key->l.ps + 16) << 3;
7069 +
7070 +               memcpy(key->o.psp.b, key->o.ps.b, key->l.ps);
7071 +               memcpy(&key->o.psp.b[key->l.ps], key->o.p.b, key->l.p);
7072 +               key->l.psp = key->l.ps + key->l.p;
7073 +               memcpy(&key->o.psp.b[key->l.psp + 16], PADDING,
7074 +                       40 - key->l.psp);
7075 +               key->o.psp.w[14] = (key->l.psp + 16) << 3;
7076 +
7077 +               memcpy(&key->e.sp.b[16], key->s, key->l.s);
7078 +               memcpy(&key->e.sp.b[16 + key->l.s], key->o.p.b,
7079 +                       key->l.p);
7080 +               memcpy(&key->e.sp.b[16 + key->l.ps], PADDING,
7081 +                       40 - key->l.ps);
7082 +               key->e.sp.w[14] = (key->l.ps + 16) << 3;
7083 +               MD5_swap(key->e.sp.w, key->e.sp.w, 14);
7084 +
7085 +               memcpy(&key->e.spp.b[16], key->s, key->l.s);
7086 +               memcpy(&key->e.spp.b[16 + key->l.s], key->o.pp.b,
7087 +                       key->l.pp);
7088 +               memcpy(&key->e.spp.b[16 + key->l.psp], PADDING,
7089 +                       40 - key->l.psp);
7090 +               key->e.spp.w[14] = (key->l.psp + 16) << 3;
7091 +               MD5_swap(key->e.spp.w, key->e.spp.w, 14);
7092 +
7093 +               order[0][index].length = key->l.psp;
7094 +               order[2][index].length = key->l.psp;
7095 +               order[3][index].length = key->l.ps;
7096 +               order[5][index].length = key->l.psp;
7097 +               order[6][index].length = key->l.psp;
7098 +               order[8][index].length = key->l.psp;
7099 +               order[9][index].length = key->l.psp;
7100 +               order[11][index].length = key->l.psp;
7101 +               order[12][index].length = key->l.psp;
7102 +               order[14][index].length = key->l.psp;
7103 +               order[15][index].length = key->l.psp;
7104 +               order[17][index].length = key->l.ps;
7105 +               order[18][index].length = key->l.psp;
7106 +               order[20][index].length = key->l.psp;
7107 +
7108 +               memcpy(&block[index], key->o.psp.b, key->l.psp);
7109 +               memcpy(&block[index].b[key->l.psp], PADDING, 56 - key->l.psp);
7110 +               block[index].w[14] = key->l.psp << 3;
7111 +               MD5_swap(block[index].w, block[index].w, 14);
7112 +#if MD5_X2
7113 +       }
7114 +
7115 +       MD5_body(block[0].w, block[1].w, MD5_out[0], MD5_out[1]);
7116 +       MD5_swap(MD5_out[0], MD5_out[0], 8);
7117 +#else
7118 +       MD5_body(block[0].w, MD5_out[0]);
7119 +       MD5_swap(MD5_out[0], MD5_out[0], 4);
7120 +#endif
7121 +
7122 +#if MD5_X2
7123 +       for (index = 0, key = pool; index < MD5_N; index++, key++) {
7124 +#endif
7125 +               memcpy(&block[index], key->o.p.b, key->l.p);
7126 +               memcpy(&block[index].b[key->l.p], "$1$", 3);
7127 +               memcpy(&block[index].b[key->l.p + 3], key->s, key->l.s);
7128 +               memcpy(&block[index].b[key->l.ps + 3],
7129 +                       MD5_out[index], key->l.p);
7130 +               length = key->l.psp + 3;
7131 +               if ((mask = key->l.p))
7132 +               do {
7133 +                       block[index].b[length++] =
7134 +                               (mask & 1) ? 0 : key->o.p.b[0];
7135 +               } while (mask >>= 1);
7136 +               memcpy(&block[index].b[length], PADDING, 56 - length);
7137 +               block[index].w[14] = length << 3;
7138 +               MD5_swap(block[index].w, block[index].w, 14);
7139 +#if MD5_X2
7140 +       }
7141 +#else
7142 +#undef index
7143 +#undef key
7144 +#endif
7145 +
7146 +#if MD5_X2
7147 +       MD5_body(block[0].w, block[1].w,
7148 +               order[0][0].even->w, order[0][1].even->w);
7149 +#else
7150 +       MD5_body(block[0].w, order[0][0].even->w);
7151 +#endif
7152 +
7153 +       index = 500; line = order[0];
7154 +       do {
7155 +#if ARCH_LITTLE_ENDIAN
7156 +#if ARCH_ALLOWS_UNALIGNED
7157 +#if MD5_X2
7158 +               MD5_body(line[0].even->w, line[1].even->w,
7159 +                       (MD5_word *)&line[0].odd->b[line[0].length],
7160 +                       (MD5_word *)&line[1].odd->b[line[1].length]);
7161 +#else
7162 +               MD5_body(line[0].even->w,
7163 +                       (MD5_word *)&line[0].odd->b[line[0].length]);
7164 +#endif
7165 +#else
7166 +#if MD5_X2
7167 +               MD5_body(line[0].even->w, line[1].even->w,
7168 +                       MD5_out[0], MD5_out[1]);
7169 +               memcpy(&line[0].odd->b[line[0].length], MD5_out[0], 16);
7170 +               memcpy(&line[1].odd->b[line[1].length], MD5_out[1], 16);
7171 +#else
7172 +               if (((ARCH_WORD)&line[0].odd->b[line[0].length]) & 3) {
7173 +                       MD5_body(line[0].even->w, MD5_out[0]);
7174 +                       memcpy(&line[0].odd->b[line[0].length],
7175 +                               MD5_out[0], 16);
7176 +               } else {
7177 +                       MD5_body(line[0].even->w,
7178 +                               (MD5_word *)&line[0].odd->b[line[0].length]);
7179 +               }
7180 +#endif
7181 +#endif
7182 +               last0 = line[0].odd->w;
7183 +#if MD5_X2
7184 +               last1 = line[1].odd->w;
7185 +               if ((line += 2) > &order[20][MD5_N - 1]) line = order[0];
7186 +               MD5_body(last0, last1, line[0].even->w, line[1].even->w);
7187 +#else
7188 +               if (++line > &order[20][0]) line = order[0];
7189 +               MD5_body(last0, line[0].even->w);
7190 +#endif
7191 +#else
7192 +#if MD5_X2
7193 +               MD5_body(line[0].even->w, line[1].even->w,
7194 +                       MD5_out[0], MD5_out[1]);
7195 +               MD5_swap(MD5_out[0], MD5_out[0], 8);
7196 +#else
7197 +               MD5_body(line[0].even->w, MD5_out[0]);
7198 +               MD5_swap(MD5_out[0], MD5_out[0], 4);
7199 +#endif
7200 +               memcpy(&line[0].odd->b[line[0].length], MD5_out[0], 16);
7201 +#if MD5_X2
7202 +               memcpy(&line[1].odd->b[line[1].length], MD5_out[1], 16);
7203 +#endif
7204 +               MD5_swap(line[0].odd->w, block[0].w, 14);
7205 +               block[0].w[14] = line[0].odd->w[14];
7206 +#if MD5_X2
7207 +               MD5_swap(line[1].odd->w, block[1].w, 14);
7208 +               block[1].w[14] = line[1].odd->w[14];
7209 +               if ((line += 2) > &order[20][MD5_N - 1]) line = order[0];
7210 +               MD5_body(block[0].w, block[1].w,
7211 +                       line[0].even->w, line[1].even->w);
7212 +#else
7213 +               if (++line > &order[20][0]) line = order[0];
7214 +               MD5_body(block[0].w, line[0].even->w);
7215 +#endif
7216 +#endif
7217 +       } while (--index);
7218 +
7219 +       memcpy(MD5_out[0], line[0].even, 16);
7220 +#if MD5_X2
7221 +       memcpy(MD5_out[1], line[1].even, 16);
7222 +#endif
7223 +}
7224 +
7225 +#if !MD5_ASM
7226 +
7227 +#if !MD5_X2
7228 +
7229  static void MD5_body(MD5_word x[15], MD5_word out[4])
7230  {
7231 -       register MD5_word a, b = Cb, c = Cc, d = Cd;
7232 +       register unsigned ARCH_WORD a, b = Cb, c = Cc, d;
7233  
7234  /* Round 1 */
7235 -       a = AC1 + x[0]; ROTATE_LEFT (a, S11); a += b;   /* 1 */
7236 -       d += (c ^ (a & MASK1)) + x[1] + AC2;
7237 +       a = AC1 + x[0];
7238 +       ROTATE_LEFT (a, S11); a += b;                   /* 1 */
7239 +       d = (c ^ (a & MASK1)) + x[1] + AC2pCd;
7240         ROTATE_LEFT (d, S12); d += a;                   /* 2 */
7241 -       FF (c, d, a, b, x[ 2], S13, AC3);               /* 3 */
7242 -       FF (b, c, d, a, x[ 3], S14, AC4);               /* 4 */
7243 +       c = F(d, a, b) + x[2] + AC3pCc;
7244 +       ROTATE_LEFT(c, S13); c += d;                    /* 3 */
7245 +       b = F(c, d, a) + x[3] + AC4pCb;
7246 +       ROTATE_LEFT(b, S14); b += c;                    /* 4 */
7247         FF (a, b, c, d, x[ 4], S11, AC5);               /* 5 */
7248         FF (d, a, b, c, x[ 5], S12, AC6);               /* 6 */
7249         FF (c, d, a, b, x[ 6], S13, AC7);               /* 7 */
7250 @@ -341,224 +678,180 @@
7251  
7252  #else
7253  
7254 -extern void MD5_body(MD5_word x[15], MD5_word out[4]);
7255 -
7256 -#endif
7257 -
7258 -#if ARCH_LITTLE_ENDIAN
7259 -
7260 -#define MD5_swap(x, y, count)
7261 -
7262 -#else
7263 -
7264 -static void MD5_swap(MD5_word *x, MD5_word *y, int count)
7265 +static void MD5_body(MD5_word x0[15], MD5_word x1[15],
7266 +       MD5_word out0[4], MD5_word out1[4])
7267  {
7268 -       MD5_word tmp;
7269 +       register unsigned ARCH_WORD a0, b0 = Cb, c0 = Cc, d0;
7270 +       register unsigned ARCH_WORD a1, b1, c1, d1;
7271 +       register unsigned ARCH_WORD u, v;
7272  
7273 -       do {
7274 -               tmp = *x++;
7275 -               ROTATE_LEFT(tmp, 16);
7276 -               *y++ = ((tmp & 0x00FF00FF) << 8) | ((tmp >> 8) & 0x00FF00FF);
7277 -       } while (--count);
7278 -}
7279 -
7280 -#endif
7281 -
7282 -static unsigned char PADDING[56] = {
7283 -       0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
7284 -       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
7285 -       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
7286 -};
7287 -
7288 -static struct {
7289 -       char s[8];
7290 -       struct {
7291 -               int p, s, ps, pp, psp;
7292 -       } l;
7293 -       struct {
7294 -               MD5_block p, sp, pp, spp;
7295 -       } e;
7296 -       struct {
7297 -               MD5_block p, ps, pp, psp;
7298 -       } o;
7299 -} patterns;
7300 -
7301 -struct pattern {
7302 -       int length;
7303 -       MD5_block *even, *odd;
7304 -};
7305 -
7306 -static struct pattern order[21] = {
7307 -       {0, &patterns.e.p, &patterns.o.psp},
7308 -       {0, &patterns.e.spp, &patterns.o.pp},
7309 -       {0, &patterns.e.spp, &patterns.o.psp},
7310 -       {0, &patterns.e.pp, &patterns.o.ps},
7311 -       {0, &patterns.e.spp, &patterns.o.pp},
7312 -       {0, &patterns.e.spp, &patterns.o.psp},
7313 -       {0, &patterns.e.pp, &patterns.o.psp},
7314 -       {0, &patterns.e.sp, &patterns.o.pp},
7315 -       {0, &patterns.e.spp, &patterns.o.psp},
7316 -       {0, &patterns.e.pp, &patterns.o.psp},
7317 -       {0, &patterns.e.spp, &patterns.o.p},
7318 -       {0, &patterns.e.spp, &patterns.o.psp},
7319 -       {0, &patterns.e.pp, &patterns.o.psp},
7320 -       {0, &patterns.e.spp, &patterns.o.pp},
7321 -       {0, &patterns.e.sp, &patterns.o.psp},
7322 -       {0, &patterns.e.pp, &patterns.o.psp},
7323 -       {0, &patterns.e.spp, &patterns.o.pp},
7324 -       {0, &patterns.e.spp, &patterns.o.ps},
7325 -       {0, &patterns.e.pp, &patterns.o.psp},
7326 -       {0, &patterns.e.spp, &patterns.o.pp},
7327 -       {0, &patterns.e.spp, &patterns.o.psp},
7328 -};
7329 -
7330 -void MD5_std_set_salt(char *salt)
7331 -{
7332 -       int length;
7333 -
7334 -       for (length = 0; salt[length] && length < 8; length++);
7335 -
7336 -       memcpy(patterns.s, salt, patterns.l.s = length);
7337 -}
7338 +/* Round 1 */
7339 +       a0 = (u = AC1) + x0[0];
7340 +       ROTATE_LEFT (a0, S11); a0 += b0;                /* 1 */
7341 +       a1 = u + x1[0];
7342 +       ROTATE_LEFT (a1, S11); a1 += b0;                /* 1 */
7343 +       d0 = (c0 ^ (a0 & (u = MASK1))) + x0[1] + (v = AC2pCd);
7344 +       ROTATE_LEFT (d0, S12); d0 += a0;                /* 2 */
7345 +       d1 = (c0 ^ (a1 & u)) + x1[1] + v;
7346 +       ROTATE_LEFT (d1, S12); d1 += a1;                /* 2 */
7347 +       c0 = F(d0, a0, b0) + x0[2] + (u = AC3pCc);
7348 +       ROTATE_LEFT(c0, S13); c0 += d0;                 /* 3 */
7349 +       c1 = F(d1, a1, b0) + x1[2] + u;
7350 +       ROTATE_LEFT(c1, S13); c1 += d1;                 /* 3 */
7351 +       b0 = F(c0, d0, a0) + x0[3] + (u = AC4pCb);
7352 +       ROTATE_LEFT(b0, S14); b0 += c0;                 /* 4 */
7353 +       b1 = F(c1, d1, a1) + x1[3] + u;
7354 +       ROTATE_LEFT(b1, S14); b1 += c1;                 /* 4 */
7355 +       FF (a0, b0, c0, d0, x0[ 4], S11, (u = AC5));    /* 5 */
7356 +       FF (a1, b1, c1, d1, x1[ 4], S11, u);            /* 5 */
7357 +       FF (d0, a0, b0, c0, x0[ 5], S12, (u = AC6));    /* 6 */
7358 +       FF (d1, a1, b1, c1, x1[ 5], S12, u);            /* 6 */
7359 +       FF (c0, d0, a0, b0, x0[ 6], S13, (u = AC7));    /* 7 */
7360 +       FF (c1, d1, a1, b1, x1[ 6], S13, u);            /* 7 */
7361 +       FF (b0, c0, d0, a0, x0[ 7], S14, (u = AC8));    /* 8 */
7362 +       FF (b1, c1, d1, a1, x1[ 7], S14, u);            /* 8 */
7363 +       FF (a0, b0, c0, d0, x0[ 8], S11, (u = AC9));    /* 9 */
7364 +       FF (a1, b1, c1, d1, x1[ 8], S11, u);            /* 9 */
7365 +       FF (d0, a0, b0, c0, x0[ 9], S12, (u = AC10));   /* 10 */
7366 +       FF (d1, a1, b1, c1, x1[ 9], S12, u);            /* 10 */
7367 +       FF (c0, d0, a0, b0, x0[10], S13, (u = AC11));   /* 11 */
7368 +       FF (c1, d1, a1, b1, x1[10], S13, u);            /* 11 */
7369 +       FF (b0, c0, d0, a0, x0[11], S14, (u = AC12));   /* 12 */
7370 +       FF (b1, c1, d1, a1, x1[11], S14, u);            /* 12 */
7371 +       FF (a0, b0, c0, d0, x0[12], S11, (u = AC13));   /* 13 */
7372 +       FF (a1, b1, c1, d1, x1[12], S11, u);            /* 13 */
7373 +       FF (d0, a0, b0, c0, x0[13], S12, (u = AC14));   /* 14 */
7374 +       FF (d1, a1, b1, c1, x1[13], S12, u);            /* 14 */
7375 +       FF (c0, d0, a0, b0, x0[14], S13, (u = AC15));   /* 15 */
7376 +       FF (c1, d1, a1, b1, x1[14], S13, u);            /* 15 */
7377 +       b0 += F (c0, d0, a0) + (u = AC16);
7378 +       ROTATE_LEFT (b0, S14); b0 += c0;                /* 16 */
7379 +       b1 += F (c1, d1, a1) + u;
7380 +       ROTATE_LEFT (b1, S14); b1 += c1;                /* 16 */
7381  
7382 -void MD5_std_set_key(char *key)
7383 -{
7384 -       int length;
7385 +/* Round 2 */
7386 +       GG (a0, b0, c0, d0, x0[ 1], S21, (u = AC17));   /* 17 */
7387 +       GG (a1, b1, c1, d1, x1[ 1], S21, u);            /* 17 */
7388 +       GG (d0, a0, b0, c0, x0[ 6], S22, (u = AC18));   /* 18 */
7389 +       GG (d1, a1, b1, c1, x1[ 6], S22, u);            /* 18 */
7390 +       GG (c0, d0, a0, b0, x0[11], S23, (u = AC19));   /* 19 */
7391 +       GG (c1, d1, a1, b1, x1[11], S23, u);            /* 19 */
7392 +       GG (b0, c0, d0, a0, x0[ 0], S24, (u = AC20));   /* 20 */
7393 +       GG (b1, c1, d1, a1, x1[ 0], S24, u);            /* 20 */
7394 +       GG (a0, b0, c0, d0, x0[ 5], S21, (u = AC21));   /* 21 */
7395 +       GG (a1, b1, c1, d1, x1[ 5], S21, u);            /* 21 */
7396 +       GG (d0, a0, b0, c0, x0[10], S22, (u = AC22));   /* 22 */
7397 +       GG (d1, a1, b1, c1, x1[10], S22, u);            /* 22 */
7398 +       c0 += G (d0, a0, b0) + (u = AC23);
7399 +       ROTATE_LEFT (c0, S23); c0 += d0;                /* 23 */
7400 +       c1 += G (d1, a1, b1) + u;
7401 +       ROTATE_LEFT (c1, S23); c1 += d1;                /* 23 */
7402 +       GG (b0, c0, d0, a0, x0[ 4], S24, (u = AC24));   /* 24 */
7403 +       GG (b1, c1, d1, a1, x1[ 4], S24, u);            /* 24 */
7404 +       GG (a0, b0, c0, d0, x0[ 9], S21, (u = AC25));   /* 25 */
7405 +       GG (a1, b1, c1, d1, x1[ 9], S21, u);            /* 25 */
7406 +       GG (d0, a0, b0, c0, x0[14], S22, (u = AC26));   /* 26 */
7407 +       GG (d1, a1, b1, c1, x1[14], S22, u);            /* 26 */
7408 +       GG (c0, d0, a0, b0, x0[ 3], S23, (u = AC27));   /* 27 */
7409 +       GG (c1, d1, a1, b1, x1[ 3], S23, u);            /* 27 */
7410 +       GG (b0, c0, d0, a0, x0[ 8], S24, (u = AC28));   /* 28 */
7411 +       GG (b1, c1, d1, a1, x1[ 8], S24, u);            /* 28 */
7412 +       GG (a0, b0, c0, d0, x0[13], S21, (u = AC29));   /* 29 */
7413 +       GG (a1, b1, c1, d1, x1[13], S21, u);            /* 29 */
7414 +       GG (d0, a0, b0, c0, x0[ 2], S22, (u = AC30));   /* 30 */
7415 +       GG (d1, a1, b1, c1, x1[ 2], S22, u);            /* 30 */
7416 +       GG (c0, d0, a0, b0, x0[ 7], S23, (u = AC31));   /* 31 */
7417 +       GG (c1, d1, a1, b1, x1[ 7], S23, u);            /* 31 */
7418 +       GG (b0, c0, d0, a0, x0[12], S24, (u = AC32));   /* 32 */
7419 +       GG (b1, c1, d1, a1, x1[12], S24, u);            /* 32 */
7420  
7421 -       for (length = 0; key[length] && length < 15; length++);
7422 +/* Round 3 */
7423 +       HH (a0, b0, c0, d0, x0[ 5], S31, (u = AC33));   /* 33 */
7424 +       HH (a1, b1, c1, d1, x1[ 5], S31, u);            /* 33 */
7425 +       HH (d0, a0, b0, c0, x0[ 8], S32, (u = AC34));   /* 34 */
7426 +       HH (d1, a1, b1, c1, x1[ 8], S32, u);            /* 34 */
7427 +       HH (c0, d0, a0, b0, x0[11], S33, (u = AC35));   /* 35 */
7428 +       HH (c1, d1, a1, b1, x1[11], S33, u);            /* 35 */
7429 +       HH (b0, c0, d0, a0, x0[14], S34, (u = AC36));   /* 36 */
7430 +       HH (b1, c1, d1, a1, x1[14], S34, u);            /* 36 */
7431 +       HH (a0, b0, c0, d0, x0[ 1], S31, (u = AC37));   /* 37 */
7432 +       HH (a1, b1, c1, d1, x1[ 1], S31, u);            /* 37 */
7433 +       HH (d0, a0, b0, c0, x0[ 4], S32, (u = AC38));   /* 38 */
7434 +       HH (d1, a1, b1, c1, x1[ 4], S32, u);            /* 38 */
7435 +       HH (c0, d0, a0, b0, x0[ 7], S33, (u = AC39));   /* 39 */
7436 +       HH (c1, d1, a1, b1, x1[ 7], S33, u);            /* 39 */
7437 +       HH (b0, c0, d0, a0, x0[10], S34, (u = AC40));   /* 40 */
7438 +       HH (b1, c1, d1, a1, x1[10], S34, u);            /* 40 */
7439 +       HH (a0, b0, c0, d0, x0[13], S31, (u = AC41));   /* 41 */
7440 +       HH (a1, b1, c1, d1, x1[13], S31, u);            /* 41 */
7441 +       HH (d0, a0, b0, c0, x0[ 0], S32, (u = AC42));   /* 42 */
7442 +       HH (d1, a1, b1, c1, x1[ 0], S32, u);            /* 42 */
7443 +       HH (c0, d0, a0, b0, x0[ 3], S33, (u = AC43));   /* 43 */
7444 +       HH (c1, d1, a1, b1, x1[ 3], S33, u);            /* 43 */
7445 +       HH (b0, c0, d0, a0, x0[ 6], S34, (u = AC44));   /* 44 */
7446 +       HH (b1, c1, d1, a1, x1[ 6], S34, u);            /* 44 */
7447 +       HH (a0, b0, c0, d0, x0[ 9], S31, (u = AC45));   /* 45 */
7448 +       HH (a1, b1, c1, d1, x1[ 9], S31, u);            /* 45 */
7449 +       HH (d0, a0, b0, c0, x0[12], S32, (u = AC46));   /* 46 */
7450 +       HH (d1, a1, b1, c1, x1[12], S32, u);            /* 46 */
7451 +       c0 += H (d0, a0, b0) + (u = AC47);
7452 +       ROTATE_LEFT (c0, S33); c0 += d0;                /* 47 */
7453 +       c1 += H (d1, a1, b1) + u;
7454 +       ROTATE_LEFT (c1, S33); c1 += d1;                /* 47 */
7455 +       HH (b0, c0, d0, a0, x0[ 2], S34, (u = AC48));   /* 48 */
7456 +       HH (b1, c1, d1, a1, x1[ 2], S34, u);            /* 48 */
7457  
7458 -       memcpy(patterns.o.p.b, key, patterns.l.p = length);
7459 -       memcpy(&patterns.o.p.b[length + 16], PADDING, 40 - length);
7460 -       patterns.o.p.w[14] = (length + 16) << 3;
7461 -
7462 -       memcpy(patterns.o.pp.b, key, length);
7463 -       memcpy(&patterns.o.pp.b[length], key, length);
7464 -       patterns.l.pp = length << 1;
7465 -       memcpy(&patterns.o.pp.b[patterns.l.pp + 16], PADDING,
7466 -               40 - patterns.l.pp);
7467 -       patterns.o.pp.w[14] = (patterns.l.pp + 16) << 3;
7468 -
7469 -       memcpy(&patterns.e.p.b[16], key, length);
7470 -       memcpy(&patterns.e.p.b[16 + length], PADDING, 40 - length);
7471 -       patterns.e.p.w[14] = (length + 16) << 3;
7472 -       MD5_swap(patterns.e.p.w, patterns.e.p.w, 14);
7473 -
7474 -       memcpy(&patterns.e.pp.b[16], patterns.o.pp.b, patterns.l.pp);
7475 -       memcpy(&patterns.e.pp.b[16 + patterns.l.pp], PADDING,
7476 -               40 - patterns.l.pp);
7477 -       patterns.e.pp.w[14] = (patterns.l.pp + 16) << 3;
7478 -       MD5_swap(patterns.e.pp.w, patterns.e.pp.w, 14);
7479 -
7480 -       order[1].length = patterns.l.pp;
7481 -       order[4].length = patterns.l.pp;
7482 -       order[7].length = patterns.l.pp;
7483 -       order[10].length = length;
7484 -       order[13].length = patterns.l.pp;
7485 -       order[16].length = patterns.l.pp;
7486 -       order[19].length = patterns.l.pp;
7487 +/* Round 4 */
7488 +       II (a0, b0, c0, d0, x0[ 0], S41, (u = AC49));   /* 49 */
7489 +       II (a1, b1, c1, d1, x1[ 0], S41, u);            /* 49 */
7490 +       II (d0, a0, b0, c0, x0[ 7], S42, (u = AC50));   /* 50 */
7491 +       II (d1, a1, b1, c1, x1[ 7], S42, u);            /* 50 */
7492 +       II (c0, d0, a0, b0, x0[14], S43, (u = AC51));   /* 51 */
7493 +       II (c1, d1, a1, b1, x1[14], S43, u);            /* 51 */
7494 +       II (b0, c0, d0, a0, x0[ 5], S44, (u = AC52));   /* 52 */
7495 +       II (b1, c1, d1, a1, x1[ 5], S44, u);            /* 52 */
7496 +       II (a0, b0, c0, d0, x0[12], S41, (u = AC53));   /* 53 */
7497 +       II (a1, b1, c1, d1, x1[12], S41, u);            /* 53 */
7498 +       II (d0, a0, b0, c0, x0[ 3], S42, (u = AC54));   /* 54 */
7499 +       II (d1, a1, b1, c1, x1[ 3], S42, u);            /* 54 */
7500 +       II (c0, d0, a0, b0, x0[10], S43, (u = AC55));   /* 55 */
7501 +       II (c1, d1, a1, b1, x1[10], S43, u);            /* 55 */
7502 +       II (b0, c0, d0, a0, x0[ 1], S44, (u = AC56));   /* 56 */
7503 +       II (b1, c1, d1, a1, x1[ 1], S44, u);            /* 56 */
7504 +       II (a0, b0, c0, d0, x0[ 8], S41, (u = AC57));   /* 57 */
7505 +       II (a1, b1, c1, d1, x1[ 8], S41, u);            /* 57 */
7506 +       d0 += I (a0, b0, c0) + (u = AC58);
7507 +       ROTATE_LEFT (d0, S42); d0 += a0;                /* 58 */
7508 +       d1 += I (a1, b1, c1) + u;
7509 +       ROTATE_LEFT (d1, S42); d1 += a1;                /* 58 */
7510 +       II (c0, d0, a0, b0, x0[ 6], S43, (u = AC59));   /* 59 */
7511 +       II (c1, d1, a1, b1, x1[ 6], S43, u);            /* 59 */
7512 +       II (b0, c0, d0, a0, x0[13], S44, (u = AC60));   /* 60 */
7513 +       II (b1, c1, d1, a1, x1[13], S44, u);            /* 60 */
7514 +       II (a0, b0, c0, d0, x0[ 4], S41, (u = AC61));   /* 61 */
7515 +       II (a1, b1, c1, d1, x1[ 4], S41, u);            /* 61 */
7516 +       II (d0, a0, b0, c0, x0[11], S42, (u = AC62));   /* 62 */
7517 +       II (d1, a1, b1, c1, x1[11], S42, u);            /* 62 */
7518 +       II (c0, d0, a0, b0, x0[ 2], S43, (u = AC63));   /* 63 */
7519 +       II (c1, d1, a1, b1, x1[ 2], S43, u);            /* 63 */
7520 +       II (b0, c0, d0, a0, x0[ 9], S44, (u = AC64));   /* 64 */
7521 +       II (b1, c1, d1, a1, x1[ 9], S44, u);            /* 64 */
7522 +
7523 +       out1[3] = Cd + d1;
7524 +
7525 +       out0[0] = Ca + a0;
7526 +       out0[1] = Cb + b0;
7527 +       out0[2] = Cc + c0;
7528 +       out0[3] = Cd + d0;
7529 +
7530 +       out1[0] = Ca + a1;
7531 +       out1[1] = Cb + b1;
7532 +       out1[2] = Cc + c1;
7533  }
7534  
7535 -void MD5_std_crypt()
7536 -{
7537 -       MD5_block block;
7538 -       int length, index;
7539 -       struct pattern *line;
7540 -#if ARCH_LITTLE_ENDIAN
7541 -       MD5_word *last;
7542  #endif
7543  
7544 -       memcpy(patterns.o.ps.b, patterns.o.p.b, patterns.l.p);
7545 -       memcpy(&patterns.o.ps.b[patterns.l.p], patterns.s, patterns.l.s);
7546 -       patterns.l.ps = patterns.l.p + patterns.l.s;
7547 -       memcpy(&patterns.o.ps.b[patterns.l.ps + 16], PADDING,
7548 -               40 - patterns.l.ps);
7549 -       patterns.o.ps.w[14] = (patterns.l.ps + 16) << 3;
7550 -
7551 -       memcpy(patterns.o.psp.b, patterns.o.ps.b, patterns.l.ps);
7552 -       memcpy(&patterns.o.psp.b[patterns.l.ps], patterns.o.p.b, patterns.l.p);
7553 -       patterns.l.psp = patterns.l.ps + patterns.l.p;
7554 -       memcpy(&patterns.o.psp.b[patterns.l.psp + 16], PADDING,
7555 -               40 - patterns.l.psp);
7556 -       patterns.o.psp.w[14] = (patterns.l.psp + 16) << 3;
7557 -
7558 -       memcpy(&patterns.e.sp.b[16], patterns.s, patterns.l.s);
7559 -       memcpy(&patterns.e.sp.b[16 + patterns.l.s], patterns.o.p.b,
7560 -               patterns.l.p);
7561 -       memcpy(&patterns.e.sp.b[16 + patterns.l.ps], PADDING,
7562 -               40 - patterns.l.ps);
7563 -       patterns.e.sp.w[14] = (patterns.l.ps + 16) << 3;
7564 -       MD5_swap(patterns.e.sp.w, patterns.e.sp.w, 14);
7565 -
7566 -       memcpy(&patterns.e.spp.b[16], patterns.s, patterns.l.s);
7567 -       memcpy(&patterns.e.spp.b[16 + patterns.l.s], patterns.o.pp.b,
7568 -               patterns.l.pp);
7569 -       memcpy(&patterns.e.spp.b[16 + patterns.l.psp], PADDING,
7570 -               40 - patterns.l.psp);
7571 -       patterns.e.spp.w[14] = (patterns.l.psp + 16) << 3;
7572 -       MD5_swap(patterns.e.spp.w, patterns.e.spp.w, 14);
7573 -
7574 -       order[0].length = patterns.l.psp;
7575 -       order[2].length = patterns.l.psp;
7576 -       order[3].length = patterns.l.ps;
7577 -       order[5].length = patterns.l.psp;
7578 -       order[6].length = patterns.l.psp;
7579 -       order[8].length = patterns.l.psp;
7580 -       order[9].length = patterns.l.psp;
7581 -       order[11].length = patterns.l.psp;
7582 -       order[12].length = patterns.l.psp;
7583 -       order[14].length = patterns.l.psp;
7584 -       order[15].length = patterns.l.psp;
7585 -       order[17].length = patterns.l.ps;
7586 -       order[18].length = patterns.l.psp;
7587 -       order[20].length = patterns.l.psp;
7588 -
7589 -       memcpy(&block, patterns.o.psp.b, patterns.l.psp);
7590 -       memcpy(&block.b[patterns.l.psp], PADDING, 56 - patterns.l.psp);
7591 -       block.w[14] = patterns.l.psp << 3;
7592 -       MD5_swap(block.w, block.w, 14);
7593 -       MD5_body(block.w, MD5_out);
7594 -       MD5_swap(MD5_out, MD5_out, 4);
7595 -
7596 -       memcpy(&block, patterns.o.p.b, patterns.l.p);
7597 -       memcpy(&block.b[patterns.l.p], "$1$", 3);
7598 -       memcpy(&block.b[patterns.l.p + 3], patterns.s, patterns.l.s);
7599 -       memcpy(&block.b[patterns.l.ps + 3], MD5_out, patterns.l.p);
7600 -       length = patterns.l.psp + 3;
7601 -       if ((index = patterns.l.p))
7602 -       do {
7603 -               block.b[length++] = (index & 1) ? 0 : patterns.o.p.b[0];
7604 -       } while (index >>= 1);
7605 -       memcpy(&block.b[length], PADDING, 56 - length);
7606 -       block.w[14] = length << 3;
7607 -       MD5_swap(block.w, block.w, 14);
7608 -       MD5_body(block.w, order[0].even->w);
7609 -
7610 -       index = 500; line = order;
7611 -       do {
7612 -#if ARCH_LITTLE_ENDIAN
7613 -#if ARCH_ALLOWS_UNALIGNED
7614 -               MD5_body(line->even->w,
7615 -                       (MD5_word *)&line->odd->b[line->length]);
7616 -#else
7617 -               MD5_body(line->even->w, MD5_out);
7618 -               memcpy(&line->odd->b[line->length], MD5_out, 16);
7619 -#endif
7620 -               last = line->odd->w;
7621 -               if (++line >= order + 21) line = order;
7622 -               MD5_body(last, line->even->w);
7623 -#else
7624 -               MD5_body(line->even->w, MD5_out);
7625 -               MD5_swap(MD5_out, MD5_out, 4);
7626 -               memcpy(&line->odd->b[line->length], MD5_out, 16);
7627 -               MD5_swap(line->odd->w, block.w, 14);
7628 -               block.w[14] = line->odd->w[14];
7629 -               if (++line >= order + 21) line = order;
7630 -               MD5_body(block.w, line->even->w);
7631  #endif
7632 -       } while (--index);
7633 -
7634 -       memcpy(MD5_out, line->even, 16);
7635 -}
7636  
7637  char *MD5_std_get_salt(char *ciphertext)
7638  {
7639 @@ -574,10 +867,10 @@
7640  
7641  #define TO_BINARY(b1, b2, b3) \
7642         value = \
7643 -               (MD5_word)atoi64[(ARCH_INDEX)pos[0]] | \
7644 -               ((MD5_word)atoi64[(ARCH_INDEX)pos[1]] << 6) | \
7645 -               ((MD5_word)atoi64[(ARCH_INDEX)pos[2]] << 12) | \
7646 -               ((MD5_word)atoi64[(ARCH_INDEX)pos[3]] << 18); \
7647 +               (MD5_word)atoi64[ARCH_INDEX(pos[0])] | \
7648 +               ((MD5_word)atoi64[ARCH_INDEX(pos[1])] << 6) | \
7649 +               ((MD5_word)atoi64[ARCH_INDEX(pos[2])] << 12) | \
7650 +               ((MD5_word)atoi64[ARCH_INDEX(pos[3])] << 18); \
7651         pos += 4; \
7652         out.b[b1] = value >> 16; \
7653         out.b[b2] = value >> 8; \
7654 @@ -600,8 +893,8 @@
7655         TO_BINARY(3, 9, 15);
7656         TO_BINARY(4, 10, 5);
7657         out.b[11] =
7658 -               (MD5_word)atoi64[(ARCH_INDEX)pos[0]] |
7659 -               ((MD5_word)atoi64[(ARCH_INDEX)pos[1]] << 6);
7660 +               (MD5_word)atoi64[ARCH_INDEX(pos[0])] |
7661 +               ((MD5_word)atoi64[ARCH_INDEX(pos[1])] << 6);
7662  
7663         MD5_swap(out.w, out.w, 4);
7664  
7665 diff -ruN john-1.6/src/MD5_std.h john-1.6.34/src/MD5_std.h
7666 --- john-1.6/src/MD5_std.h      1998-12-03 01:29:50.000000000 +0100
7667 +++ john-1.6.34/src/MD5_std.h   2000-06-25 07:06:03.000000000 +0200
7668 @@ -1,10 +1,10 @@
7669  /*
7670   * This file is part of John the Ripper password cracker,
7671 - * Copyright (c) 1996-98 by Solar Designer
7672 + * Copyright (c) 1996-2000 by Solar Designer
7673   */
7674  
7675  /*
7676 - * Standard FreeBSD MD5 implementation.
7677 + * FreeBSD-style MD5-based password hash implementation.
7678   */
7679  
7680  #ifndef _JOHN_MD5_STD_H
7681 @@ -21,11 +21,77 @@
7682  typedef MD5_word MD5_binary[4];
7683  
7684  /*
7685 + * Various structures for internal use.
7686 + */
7687 +
7688 +typedef union {
7689 +       double dummy;
7690 +       MD5_word w[15];
7691 +       char b[60];
7692 +} MD5_block;
7693 +
7694 +typedef struct {
7695 +       int length;
7696 +       MD5_block *even, *odd;
7697 +} MD5_pattern;
7698 +
7699 +typedef struct {
7700 +       char s[8];
7701 +       struct {
7702 +               int p, s, ps, pp, psp;
7703 +       } l;
7704 +       struct {
7705 +               MD5_block p, sp, pp, spp;
7706 +       } e;
7707 +       struct {
7708 +               MD5_block p, ps, pp, psp;
7709 +       } o;
7710 +} MD5_pool;
7711 +
7712 +#if !MD5_IMM
7713 +typedef struct {
7714 +       MD5_word AC[64];
7715 +       MD5_word IV[4];
7716 +       MD5_word masks[2];
7717 +} MD5_data;
7718 +#endif
7719 +
7720 +#if MD5_X2
7721 +#define MD5_N                          2
7722 +#else
7723 +#define MD5_N                          1
7724 +#endif
7725 +
7726 +typedef struct {
7727 +#if !MD5_IMM
7728 +       MD5_data data;
7729 +       double dummy;
7730 +#endif
7731 +
7732 +       MD5_binary out[MD5_N];
7733 +
7734 +       MD5_block block[MD5_N];
7735 +       MD5_pattern order[21][MD5_N];
7736 +       MD5_pool pool[MD5_N];
7737 +} MD5_std_combined;
7738 +
7739 +extern MD5_std_combined MD5_std_all;
7740 +
7741 +/*
7742   * MD5_std_crypt() output buffer.
7743   */
7744 -extern MD5_binary MD5_out;
7745 +#define MD5_out                                MD5_std_all.out
7746  
7747 +#if MD5_X2
7748 +#define MD5_ALGORITHM_NAME             "32/" ARCH_BITS_STR " X2"
7749 +#else
7750  #define MD5_ALGORITHM_NAME             "32/" ARCH_BITS_STR
7751 +#endif
7752 +
7753 +/*
7754 + * Initializes the internal structures.
7755 + */
7756 +extern void MD5_std_init(void);
7757  
7758  /*
7759   * Sets a salt for MD5_std_crypt().
7760 @@ -36,12 +102,12 @@
7761   * Sets a key for MD5_std_crypt().
7762   * Currently only supports keys up to 15 characters long.
7763   */
7764 -extern void MD5_std_set_key(char *key);
7765 +extern void MD5_std_set_key(char *key, int index);
7766  
7767  /*
7768   * Main encryption routine, sets MD5_out.
7769   */
7770 -extern void MD5_std_crypt();
7771 +extern void MD5_std_crypt(void);
7772  
7773  /*
7774   * Returns the salt for MD5_std_set_salt().
7775 diff -ruN john-1.6/src/memory.h john-1.6.34/src/memory.h
7776 --- john-1.6/src/memory.h       1998-12-03 01:29:50.000000000 +0100
7777 +++ john-1.6.34/src/memory.h    1999-06-19 05:34:13.000000000 +0200
7778 @@ -19,6 +19,7 @@
7779   */
7780  #define MEM_ALIGN_NONE                 1
7781  #define MEM_ALIGN_WORD                 ARCH_SIZE
7782 +#define MEM_ALIGN_CACHE                        (ARCH_SIZE * 8)
7783  
7784  /*
7785   * Block size used by mem_alloc_tiny().
7786 diff -ruN john-1.6/src/mips32.h john-1.6.34/src/mips32.h
7787 --- john-1.6/src/mips32.h       1998-12-03 01:29:50.000000000 +0100
7788 +++ john-1.6.34/src/mips32.h    2000-05-08 09:05:13.000000000 +0200
7789 @@ -1,6 +1,6 @@
7790  /*
7791   * This file is part of John the Ripper password cracker,
7792 - * Copyright (c) 1996-98 by Solar Designer
7793 + * Copyright (c) 1996-2000 by Solar Designer
7794   */
7795  
7796  /*
7797 @@ -10,15 +10,15 @@
7798  #ifndef _JOHN_ARCH_H
7799  #define _JOHN_ARCH_H
7800  
7801 -#define ARCH_GENERIC                   1
7802  #define ARCH_WORD                      long
7803  #define ARCH_SIZE                      4
7804  #define ARCH_BITS                      32
7805 +#define ARCH_BITS_LOG                  5
7806  #define ARCH_BITS_STR                  "32"
7807  #define ARCH_LITTLE_ENDIAN             0
7808  #define ARCH_INT_GT_32                 0
7809  #define ARCH_ALLOWS_UNALIGNED          0
7810 -#define ARCH_INDEX                     unsigned int
7811 +#define ARCH_INDEX(x)                  ((unsigned int)(unsigned char)(x))
7812  
7813  #define OS_TIMER                       1
7814  #define OS_FLOCK                       1
7815 @@ -32,10 +32,14 @@
7816  #define DES_SCALE                      1
7817  #define DES_EXTB                       0
7818  #define DES_COPY                       1
7819 +#define DES_BS_ASM                     0
7820  #define DES_BS                         1
7821 +#define DES_BS_VECTOR                  0
7822 +#define DES_BS_EXPAND                  1
7823  
7824  #define MD5_ASM                                0
7825 -#define MD5_IMM                                1
7826 +#define MD5_X2                         1
7827 +#define MD5_IMM                                0
7828  
7829  #define BF_ASM                         0
7830  #define BF_SCALE                       0
7831 diff -ruN john-1.6/src/mips64.h john-1.6.34/src/mips64.h
7832 --- john-1.6/src/mips64.h       1998-12-03 01:29:50.000000000 +0100
7833 +++ john-1.6.34/src/mips64.h    2000-05-08 09:05:18.000000000 +0200
7834 @@ -1,6 +1,6 @@
7835  /*
7836   * This file is part of John the Ripper password cracker,
7837 - * Copyright (c) 1996-98 by Solar Designer
7838 + * Copyright (c) 1996-2000 by Solar Designer
7839   */
7840  
7841  /*
7842 @@ -10,15 +10,15 @@
7843  #ifndef _JOHN_ARCH_H
7844  #define _JOHN_ARCH_H
7845  
7846 -#define ARCH_GENERIC                   1
7847  #define ARCH_WORD                      long
7848  #define ARCH_SIZE                      8
7849  #define ARCH_BITS                      64
7850 +#define ARCH_BITS_LOG                  6
7851  #define ARCH_BITS_STR                  "64"
7852  #define ARCH_LITTLE_ENDIAN             0
7853  #define ARCH_INT_GT_32                 0
7854  #define ARCH_ALLOWS_UNALIGNED          0
7855 -#define ARCH_INDEX                     unsigned int
7856 +#define ARCH_INDEX(x)                  ((unsigned int)(unsigned char)(x))
7857  
7858  #define OS_TIMER                       1
7859  #define OS_FLOCK                       1
7860 @@ -32,10 +32,14 @@
7861  #define DES_SCALE                      0
7862  #define DES_EXTB                       0
7863  #define DES_COPY                       0
7864 +#define DES_BS_ASM                     0
7865  #define DES_BS                         1
7866 +#define DES_BS_VECTOR                  0
7867 +#define DES_BS_EXPAND                  1
7868  
7869  #define MD5_ASM                                0
7870 -#define MD5_IMM                                1
7871 +#define MD5_X2                         1
7872 +#define MD5_IMM                                0
7873  
7874  #define BF_ASM                         0
7875  #define BF_SCALE                       0
7876 diff -ruN john-1.6/src/misc.c john-1.6.34/src/misc.c
7877 --- john-1.6/src/misc.c 1998-12-03 01:29:50.000000000 +0100
7878 +++ john-1.6.34/src/misc.c      1999-09-22 05:57:40.000000000 +0200
7879 @@ -1,6 +1,6 @@
7880  /*
7881   * This file is part of John the Ripper password cracker,
7882 - * Copyright (c) 1996-98 by Solar Designer
7883 + * Copyright (c) 1996-99 by Solar Designer
7884   */
7885  
7886  #include <stdio.h>
7887 @@ -10,7 +10,7 @@
7888  #include <stdarg.h>
7889  #include <errno.h>
7890  
7891 -void error()
7892 +void error(void)
7893  {
7894         exit(1);
7895  }
7896 diff -ruN john-1.6/src/misc.h john-1.6.34/src/misc.h
7897 --- john-1.6/src/misc.h 1998-12-03 01:29:50.000000000 +0100
7898 +++ john-1.6.34/src/misc.h      2001-10-22 06:46:52.000000000 +0200
7899 @@ -1,6 +1,6 @@
7900  /*
7901   * This file is part of John the Ripper password cracker,
7902 - * Copyright (c) 1996-98 by Solar Designer
7903 + * Copyright (c) 1996-99 by Solar Designer
7904   */
7905  
7906  /*
7907 @@ -15,7 +15,7 @@
7908  /*
7909   * Exit on error. Terminates the process with non-zero exit status.
7910   */
7911 -extern void error();
7912 +extern void error(void);
7913  
7914  /*
7915   * Similar to perror(), but supports formatted output, and calls error().
7916 @@ -35,24 +35,24 @@
7917  
7918  /*
7919   * Similar to fgets(), but doesn't leave the newline character in the buffer,
7920 - * and skips to the end of long lines. Handles both UNIX and DOS style text
7921 + * and skips to the end of long lines. Handles both Unix and DOS style text
7922   * files correctly.
7923   */
7924  extern char *fgetl(char *s, int size, FILE *stream);
7925  
7926  /*
7927 - * Similar to strncpy(), but terminates with only one null if there's room
7928 - * instead of null padding to the supplied size like strncpy() does.
7929 + * Similar to strncpy(), but terminates with only one NUL if there's room
7930 + * instead of padding to the supplied size like strncpy() does.
7931   */
7932  extern char *strnfcpy(char *dst, char *src, int size);
7933  
7934  /*
7935 - * Similar to the above, but always null terminates the string.
7936 + * Similar to the above, but always NUL terminates the string.
7937   */
7938  extern char *strnzcpy(char *dst, char *src, int size);
7939  
7940  /*
7941 - * Similar to strncat(), but total buffer size is supplied, and always null
7942 + * Similar to strncat(), but total buffer size is supplied, and always NUL
7943   * terminates the string.
7944   */
7945  extern char *strnzcat(char *dst, char *src, int size);
7946 diff -ruN john-1.6/src/options.c john-1.6.34/src/options.c
7947 --- john-1.6/src/options.c      1998-12-03 01:29:50.000000000 +0100
7948 +++ john-1.6.34/src/options.c   2003-01-15 03:59:01.000000000 +0100
7949 @@ -1,12 +1,13 @@
7950  /*
7951   * This file is part of John the Ripper password cracker,
7952 - * Copyright (c) 1996-98 by Solar Designer
7953 + * Copyright (c) 1996-2002 by Solar Designer
7954   */
7955  
7956  #include <stdio.h>
7957  #include <stdlib.h>
7958  #include <string.h>
7959  
7960 +#include "arch.h"
7961  #include "misc.h"
7962  #include "params.h"
7963  #include "memory.h"
7964 @@ -66,9 +67,18 @@
7965         {NULL}
7966  };
7967  
7968 +#if DES_BS
7969 +/* nonstd.c and parts of x86-mmx.S aren't mine */
7970 +#define JOHN_COPYRIGHT \
7971 +       "Solar Designer and others"
7972 +#else
7973 +#define JOHN_COPYRIGHT \
7974 +       "Solar Designer"
7975 +#endif
7976 +
7977  #define JOHN_USAGE \
7978 -"\nJohn the Ripper  Version " JOHN_VERSION \
7979 -"  Copyright (c) 1996-98 by Solar Designer\n" \
7980 +"John the Ripper password cracker, version " JOHN_VERSION "\n" \
7981 +"Copyright (c) 1996-2003 by " JOHN_COPYRIGHT "\n" \
7982  "\n" \
7983  "Usage: %s [OPTIONS] [PASSWORD-FILES]\n" \
7984  "-single                   \"single crack\" mode\n" \
7985 diff -ruN john-1.6/src/params.h john-1.6.34/src/params.h
7986 --- john-1.6/src/params.h       1998-12-03 01:29:50.000000000 +0100
7987 +++ john-1.6.34/src/params.h    2003-06-29 15:05:05.000000000 +0200
7988 @@ -1,6 +1,6 @@
7989  /*
7990   * This file is part of John the Ripper password cracker,
7991 - * Copyright (c) 1996-98 by Solar Designer
7992 + * Copyright (c) 1996-2003 by Solar Designer
7993   */
7994  
7995  /*
7996 @@ -15,17 +15,32 @@
7997  /*
7998   * John's version number.
7999   */
8000 -#define JOHN_VERSION                   "1.6"
8001 +#define JOHN_VERSION                   "1.6.34"
8002  
8003  /*
8004 - * Crash recovery file format version number.
8005 + * Is this a system-wide installation? *BSD ports and Linux distributions
8006 + * will probably want to set this to 1 for their builds of John.
8007 + */
8008 +#ifndef JOHN_SYSTEMWIDE
8009 +#define JOHN_SYSTEMWIDE                        0
8010 +#endif
8011 +
8012 +#if JOHN_SYSTEMWIDE
8013 +#define JOHN_SYSTEMWIDE_EXEC           "/usr/libexec/john"
8014 +#define JOHN_SYSTEMWIDE_HOME           "/usr/share/john"
8015 +#define JOHN_PRIVATE_HOME              "~/.john"
8016 +#endif
8017 +
8018 +/*
8019 + * Crash recovery file format version strings.
8020   */
8021  #define RECOVERY_VERSION_0             "REC0"
8022  #define RECOVERY_VERSION_1             "REC1"
8023 -#define RECOVERY_VERSION_CURRENT       RECOVERY_VERSION_1
8024 +#define RECOVERY_VERSION_2             "REC2"
8025 +#define RECOVERY_VERSION_CURRENT       RECOVERY_VERSION_2
8026  
8027  /*
8028 - * Charset file format version number.
8029 + * Charset file format version string.
8030   */
8031  #define CHARSET_VERSION                        "CHR1"
8032  
8033 @@ -52,10 +67,18 @@
8034  /*
8035   * File names.
8036   */
8037 -#define LOG_NAME                       "~/john.pot"
8038 -#define CFG_NAME                       "~/john.ini"
8039 -#define RECOVERY_NAME                  "~/restore"
8040 -#define WORDLIST_NAME                  "~/password.lst"
8041 +#define CFG_FULL_NAME                  "$JOHN/john.conf"
8042 +#define CFG_ALT_NAME                   "$JOHN/john.ini"
8043 +#if JOHN_SYSTEMWIDE
8044 +#define CFG_PRIVATE_FULL_NAME          JOHN_PRIVATE_HOME "/john.conf"
8045 +#define CFG_PRIVATE_ALT_NAME           JOHN_PRIVATE_HOME "/john.ini"
8046 +#define LOG_NAME                       JOHN_PRIVATE_HOME "/john.pot"
8047 +#define RECOVERY_NAME                  JOHN_PRIVATE_HOME "/restore"
8048 +#else
8049 +#define LOG_NAME                       "$JOHN/john.pot"
8050 +#define RECOVERY_NAME                  "$JOHN/restore"
8051 +#endif
8052 +#define WORDLIST_NAME                  "$JOHN/password.lst"
8053  
8054  /*
8055   * Configuration file section names.
8056 diff -ruN john-1.6/src/pa-risc.h john-1.6.34/src/pa-risc.h
8057 --- john-1.6/src/pa-risc.h      1998-12-03 01:29:50.000000000 +0100
8058 +++ john-1.6.34/src/pa-risc.h   2000-05-08 09:05:36.000000000 +0200
8059 @@ -1,6 +1,6 @@
8060  /*
8061   * This file is part of John the Ripper password cracker,
8062 - * Copyright (c) 1996-98 by Solar Designer
8063 + * Copyright (c) 1996-2000 by Solar Designer
8064   */
8065  
8066  /*
8067 @@ -10,15 +10,15 @@
8068  #ifndef _JOHN_ARCH_H
8069  #define _JOHN_ARCH_H
8070  
8071 -#define ARCH_GENERIC                   1
8072  #define ARCH_WORD                      long
8073  #define ARCH_SIZE                      4
8074  #define ARCH_BITS                      32
8075 +#define ARCH_BITS_LOG                  5
8076  #define ARCH_BITS_STR                  "32"
8077  #define ARCH_LITTLE_ENDIAN             0
8078  #define ARCH_INT_GT_32                 0
8079  #define ARCH_ALLOWS_UNALIGNED          0
8080 -#define ARCH_INDEX                     unsigned int
8081 +#define ARCH_INDEX(x)                  ((unsigned int)(unsigned char)(x))
8082  
8083  #define OS_TIMER                       0
8084  #define OS_FLOCK                       1
8085 @@ -32,9 +32,14 @@
8086  #define DES_SCALE                      1
8087  #define DES_EXTB                       1
8088  #define DES_COPY                       0
8089 +#define DES_BS_ASM                     0
8090  #define DES_BS                         1
8091 +#define DES_BS_VECTOR                  8
8092 +#define DES_BS_EXPAND                  0
8093 +#define DES_BS_ALGORITHM_NAME          "32/32x8V BS"
8094  
8095  #define MD5_ASM                                0
8096 +#define MD5_X2                         1
8097  #define MD5_IMM                                0
8098  
8099  #define BF_ASM                         0
8100 diff -ruN john-1.6/src/path.c john-1.6.34/src/path.c
8101 --- john-1.6/src/path.c 1998-12-03 01:29:50.000000000 +0100
8102 +++ john-1.6.34/src/path.c      2000-03-15 00:42:04.000000000 +0100
8103 @@ -1,50 +1,107 @@
8104  /*
8105   * This file is part of John the Ripper password cracker,
8106 - * Copyright (c) 1996-98 by Solar Designer
8107 + * Copyright (c) 1996-2000 by Solar Designer
8108   */
8109  
8110 -#include <stdio.h>
8111  #include <string.h>
8112  
8113  #include "misc.h"
8114  #include "params.h"
8115  #include "memory.h"
8116 +#include "path.h"
8117  
8118 -static char *home_path = NULL;
8119 -static size_t home_path_length;
8120 +static char *john_home_path = NULL;
8121 +static int john_home_length;
8122 +
8123 +#if JOHN_SYSTEMWIDE
8124 +#include <unistd.h>
8125 +#include <errno.h>
8126 +#include <pwd.h>
8127 +#include <sys/types.h>
8128 +#include <sys/stat.h>
8129 +
8130 +static char *user_home_path = NULL;
8131 +static int user_home_length;
8132 +#endif
8133  
8134  void path_init(char **argv)
8135  {
8136 +#if JOHN_SYSTEMWIDE
8137 +       struct passwd *pw;
8138 +#ifdef JOHN_PRIVATE_HOME
8139 +       char *private;
8140 +#endif
8141 +#else
8142         char *pos;
8143 +#endif
8144  
8145 -       if (!argv[0]) error();
8146 -
8147 -       if (!home_path && (pos = strrchr(argv[0], '/'))) {
8148 -               home_path_length = pos - argv[0] + 1;
8149 -               if (home_path_length >= PATH_BUFFER_SIZE)
8150 -                       home_path_length = PATH_BUFFER_SIZE - 1;
8151 -
8152 -               home_path = mem_alloc(PATH_BUFFER_SIZE);
8153 +#if JOHN_SYSTEMWIDE
8154 +       john_home_path = mem_alloc(PATH_BUFFER_SIZE);
8155 +       strnzcpy(john_home_path, JOHN_SYSTEMWIDE_HOME "/", PATH_BUFFER_SIZE);
8156 +       john_home_length = strlen(john_home_path);
8157 +
8158 +       if (user_home_path) return;
8159 +       pw = getpwuid(getuid());
8160 +       endpwent();
8161 +       if (!pw) return;
8162 +
8163 +       user_home_length = strlen(pw->pw_dir) + 1;
8164 +       if (user_home_length >= PATH_BUFFER_SIZE) return;
8165 +
8166 +       user_home_path = mem_alloc(PATH_BUFFER_SIZE);
8167 +       memcpy(user_home_path, pw->pw_dir, user_home_length - 1);
8168 +       user_home_path[user_home_length - 1] = '/';
8169 +
8170 +#ifdef JOHN_PRIVATE_HOME
8171 +       private = path_expand(JOHN_PRIVATE_HOME);
8172 +       if (mkdir(private, S_IRUSR | S_IWUSR | S_IXUSR)) {
8173 +               if (errno != EEXIST) pexit("mkdir: %s", private);
8174 +       } else
8175 +               fprintf(stderr, "Created directory: %s\n", private);
8176 +#endif
8177 +#else
8178 +       if (argv[0])
8179 +       if (!john_home_path && (pos = strrchr(argv[0], '/'))) {
8180 +               john_home_length = pos - argv[0] + 1;
8181 +               if (john_home_length >= PATH_BUFFER_SIZE) return;
8182  
8183 -               memcpy(home_path, argv[0], home_path_length);
8184 +               john_home_path = mem_alloc(PATH_BUFFER_SIZE);
8185 +               memcpy(john_home_path, argv[0], john_home_length);
8186         }
8187 +#endif
8188  }
8189  
8190  char *path_expand(char *name)
8191  {
8192 +       if (!strncmp(name, "$JOHN/", 6)) {
8193 +               if (john_home_path &&
8194 +                   john_home_length + strlen(name) - 6 < PATH_BUFFER_SIZE) {
8195 +                       strnzcpy(&john_home_path[john_home_length], &name[6],
8196 +                               PATH_BUFFER_SIZE - john_home_length);
8197 +                       return john_home_path;
8198 +               }
8199 +               return name + 6;
8200 +       }
8201 +
8202 +#if JOHN_SYSTEMWIDE
8203         if (!strncmp(name, "~/", 2)) {
8204 -               if (home_path) {
8205 -                       strnzcpy(&home_path[home_path_length], &name[2],
8206 -                               PATH_BUFFER_SIZE - home_path_length);
8207 -
8208 -                       return home_path;
8209 -               } else
8210 -                       return name + 2;
8211 -       } else
8212 -               return name;
8213 +               if (user_home_path &&
8214 +                   user_home_length + strlen(name) - 2 < PATH_BUFFER_SIZE) {
8215 +                       strnzcpy(&user_home_path[user_home_length], &name[2],
8216 +                               PATH_BUFFER_SIZE - user_home_length);
8217 +                       return user_home_path;
8218 +               }
8219 +               return name + 2;
8220 +       }
8221 +#endif
8222 +
8223 +       return name;
8224  }
8225  
8226 -void path_done()
8227 +void path_done(void)
8228  {
8229 -       mem_free((void **)&home_path);
8230 +       mem_free((void **)&john_home_path);
8231 +#if JOHN_SYSTEMWIDE
8232 +       mem_free((void **)&user_home_path);
8233 +#endif
8234  }
8235 diff -ruN john-1.6/src/path.h john-1.6.34/src/path.h
8236 --- john-1.6/src/path.h 1998-12-03 01:29:50.000000000 +0100
8237 +++ john-1.6.34/src/path.h      2000-03-14 23:12:53.000000000 +0100
8238 @@ -1,6 +1,6 @@
8239  /*
8240   * This file is part of John the Ripper password cracker,
8241 - * Copyright (c) 1996-98 by Solar Designer
8242 + * Copyright (c) 1996-2000 by Solar Designer
8243   */
8244  
8245  /*
8246 @@ -16,13 +16,13 @@
8247  extern void path_init(char **argv);
8248  
8249  /*
8250 - * Expands "~/" in a path name.
8251 + * Expands "$JOHN/" and "~/" in a path name.
8252   */
8253  extern char *path_expand(char *name);
8254  
8255  /*
8256   * Frees the memory allocated in path_init().
8257   */
8258 -extern void path_done();
8259 +extern void path_done(void);
8260  
8261  #endif
8262 diff -ruN john-1.6/src/ppc.h john-1.6.34/src/ppc.h
8263 --- john-1.6/src/ppc.h  1998-12-03 01:29:50.000000000 +0100
8264 +++ john-1.6.34/src/ppc.h       2000-05-08 09:05:39.000000000 +0200
8265 @@ -1,6 +1,6 @@
8266  /*
8267   * This file is part of John the Ripper password cracker,
8268 - * Copyright (c) 1996-98 by Solar Designer
8269 + * Copyright (c) 1996-2000 by Solar Designer
8270   */
8271  
8272  /*
8273 @@ -10,15 +10,15 @@
8274  #ifndef _JOHN_ARCH_H
8275  #define _JOHN_ARCH_H
8276  
8277 -#define ARCH_GENERIC                   1
8278  #define ARCH_WORD                      long
8279  #define ARCH_SIZE                      4
8280  #define ARCH_BITS                      32
8281 +#define ARCH_BITS_LOG                  5
8282  #define ARCH_BITS_STR                  "32"
8283  #define ARCH_LITTLE_ENDIAN             0
8284  #define ARCH_INT_GT_32                 0
8285  #define ARCH_ALLOWS_UNALIGNED          0
8286 -#define ARCH_INDEX                     unsigned int
8287 +#define ARCH_INDEX(x)                  ((unsigned int)(unsigned char)(x))
8288  
8289  #define OS_TIMER                       1
8290  #define OS_FLOCK                       1
8291 @@ -32,10 +32,14 @@
8292  #define DES_SCALE                      0
8293  #define DES_EXTB                       1
8294  #define DES_COPY                       0
8295 +#define DES_BS_ASM                     0
8296  #define DES_BS                         1
8297 +#define DES_BS_VECTOR                  0
8298 +#define DES_BS_EXPAND                  1
8299  
8300  #define MD5_ASM                                0
8301 -#define MD5_IMM                                1
8302 +#define MD5_X2                         1
8303 +#define MD5_IMM                                0
8304  
8305  #define BF_ASM                         0
8306  #define BF_SCALE                       0
8307 diff -ruN john-1.6/src/recovery.c john-1.6.34/src/recovery.c
8308 --- john-1.6/src/recovery.c     1998-12-03 01:29:50.000000000 +0100
8309 +++ john-1.6.34/src/recovery.c  2001-05-11 15:50:17.000000000 +0200
8310 @@ -1,6 +1,6 @@
8311  /*
8312   * This file is part of John the Ripper password cracker,
8313 - * Copyright (c) 1996-98 by Solar Designer
8314 + * Copyright (c) 1996-2001 by Solar Designer
8315   */
8316  
8317  #include <stdio.h>
8318 @@ -28,6 +28,7 @@
8319  #include "recovery.h"
8320  
8321  char *rec_name = RECOVERY_NAME;
8322 +int rec_version = 0;
8323  int rec_argc = 0;
8324  char **rec_argv;
8325  
8326 @@ -37,7 +38,7 @@
8327  static void (*rec_save_mode)(FILE *file);
8328  
8329  #if defined(LOCK_EX) && OS_FLOCK
8330 -static void rec_lock()
8331 +static void rec_lock(void)
8332  {
8333         if (flock(rec_fd, LOCK_EX | LOCK_NB)) {
8334                 if (errno == EWOULDBLOCK) {
8335 @@ -68,7 +69,7 @@
8336         rec_save_mode = save_mode;
8337  }
8338  
8339 -void rec_save()
8340 +void rec_save(void)
8341  {
8342         int save_format;
8343         long size;
8344 @@ -142,7 +143,6 @@
8345  void rec_restore_args(int lock)
8346  {
8347         char line[LINE_BUFFER_SIZE];
8348 -       int version;
8349         int index, argc;
8350         char **argv;
8351         char *save_rec_name;
8352 @@ -155,8 +155,9 @@
8353  
8354         if (!fgetl(line, sizeof(line), rec_file)) rec_format_error("fgets");
8355  
8356 -       version = 0;
8357 -       if (!strcmp(line, RECOVERY_VERSION_1)) version = 1; else
8358 +       rec_version = 0;
8359 +       if (!strcmp(line, RECOVERY_VERSION_2)) rec_version = 2; else
8360 +       if (!strcmp(line, RECOVERY_VERSION_1)) rec_version = 1; else
8361         if (strcmp(line, RECOVERY_VERSION_0)) rec_format_error("fgets");
8362  
8363         if (fscanf(rec_file, "%d\n", &argc) != 1) rec_format_error("fscanf");
8364 @@ -183,7 +184,7 @@
8365                 &status.crypts.hi) != 4) rec_format_error("fscanf");
8366         if (!status_restored_time) status_restored_time = 1;
8367  
8368 -       if (version == 0) {
8369 +       if (rec_version == 0) {
8370                 status.pass = 0;
8371                 status.progress = -1;
8372         } else
8373 diff -ruN john-1.6/src/recovery.h john-1.6.34/src/recovery.h
8374 --- john-1.6/src/recovery.h     1998-12-03 01:29:50.000000000 +0100
8375 +++ john-1.6.34/src/recovery.h  2001-05-11 15:51:13.000000000 +0200
8376 @@ -1,6 +1,6 @@
8377  /*
8378   * This file is part of John the Ripper password cracker,
8379 - * Copyright (c) 1996-98 by Solar Designer
8380 + * Copyright (c) 1996-2001 by Solar Designer
8381   */
8382  
8383  /*
8384 @@ -20,6 +20,11 @@
8385  extern char *rec_name;
8386  
8387  /*
8388 + * Crash recovery file format version number.
8389 + */
8390 +extern int rec_version;
8391 +
8392 +/*
8393   * Original command line arguments.
8394   */
8395  extern int rec_argc;
8396 @@ -34,7 +39,7 @@
8397  /*
8398   * Saves the command line arguments and cracking mode specific information.
8399   */
8400 -extern void rec_save();
8401 +extern void rec_save(void);
8402  
8403  /*
8404   * Closes the crash recovery file.
8405 diff -ruN john-1.6/src/rules.c john-1.6.34/src/rules.c
8406 --- john-1.6/src/rules.c        1998-12-03 01:29:50.000000000 +0100
8407 +++ john-1.6.34/src/rules.c     2002-05-08 20:07:17.000000000 +0200
8408 @@ -1,6 +1,6 @@
8409  /*
8410   * This file is part of John the Ripper password cracker,
8411 - * Copyright (c) 1996-98 by Solar Designer
8412 + * Copyright (c) 1996-99 by Solar Designer
8413   */
8414  
8415  #include <stdio.h>
8416 @@ -9,7 +9,6 @@
8417  #include "arch.h"
8418  #include "misc.h"
8419  #include "params.h"
8420 -#include "path.h"
8421  #include "memory.h"
8422  #include "formats.h"
8423  #include "loader.h"
8424 @@ -79,7 +78,7 @@
8425  }
8426  
8427  #define POSITION { \
8428 -       if ((pos = rules_length[(ARCH_INDEX)RULE]) == INVALID_LENGTH) { \
8429 +       if ((pos = rules_length[ARCH_INDEX(RULE)]) == INVALID_LENGTH) { \
8430                 if (LAST) \
8431                         rules_errno = RULES_ERROR_POSITION; \
8432                 else \
8433 @@ -90,15 +89,15 @@
8434  
8435  #define CLASS(start, true, false) { \
8436         if ((value = RULE) == '?') { \
8437 -               if (!(class = rules_classes[(ARCH_INDEX)RULE])) { \
8438 +               if (!(class = rules_classes[ARCH_INDEX(RULE)])) { \
8439                         if (LAST) \
8440                                 rules_errno = RULES_ERROR_CLASS; \
8441                         else \
8442                                 rules_errno = RULES_ERROR_END; \
8443                         return NULL; \
8444                 } \
8445 -               for (pos = (start); (ARCH_INDEX)in[pos]; pos++) \
8446 -               if (class[(ARCH_INDEX)in[pos]]) { \
8447 +               for (pos = (start); ARCH_INDEX(in[pos]); pos++) \
8448 +               if (class[ARCH_INDEX(in[pos])]) { \
8449                         true; \
8450                 } else { \
8451                         false; \
8452 @@ -108,7 +107,7 @@
8453                         rules_errno = RULES_ERROR_END; \
8454                         return NULL; \
8455                 } \
8456 -               for (pos = (start); (ARCH_INDEX)in[pos]; pos++) \
8457 +               for (pos = (start); ARCH_INDEX(in[pos]); pos++) \
8458                 if (in[pos] == value) { \
8459                         true; \
8460                 } else { \
8461 @@ -123,30 +122,30 @@
8462  }
8463  
8464  #define CONV(conv) { \
8465 -       for (pos = 0; (out[pos] = (conv)[(ARCH_INDEX)in[pos]]); pos++); \
8466 +       for (pos = 0; (out[pos] = (conv)[ARCH_INDEX(in[pos])]); pos++); \
8467  }
8468  
8469  static void rules_init_class(char name, char *valid)
8470  {
8471         char *pos, inv;
8472  
8473 -       rules_classes[(ARCH_INDEX)name] =
8474 +       rules_classes[ARCH_INDEX(name)] =
8475                 mem_alloc_tiny(0x100, MEM_ALIGN_NONE);
8476 -       memset(rules_classes[(ARCH_INDEX)name], 0, 0x100);
8477 -       for (pos = valid; (ARCH_INDEX)*pos; pos++)
8478 -               rules_classes[(ARCH_INDEX)name][(ARCH_INDEX)*pos] = 1;
8479 +       memset(rules_classes[ARCH_INDEX(name)], 0, 0x100);
8480 +       for (pos = valid; ARCH_INDEX(*pos); pos++)
8481 +               rules_classes[ARCH_INDEX(name)][ARCH_INDEX(*pos)] = 1;
8482  
8483         if (name >= 'a' && name <= 'z') {
8484                 inv = name & ~0x20;
8485 -               rules_classes[(ARCH_INDEX)inv] =
8486 +               rules_classes[ARCH_INDEX(inv)] =
8487                         mem_alloc_tiny(0x100, MEM_ALIGN_NONE);
8488 -               memset(rules_classes[(ARCH_INDEX)inv], 1, 0x100);
8489 -               for (pos = valid; (ARCH_INDEX)*pos; pos++)
8490 -                       rules_classes[(ARCH_INDEX)inv][(ARCH_INDEX)*pos] = 0;
8491 +               memset(rules_classes[ARCH_INDEX(inv)], 1, 0x100);
8492 +               for (pos = valid; ARCH_INDEX(*pos); pos++)
8493 +                       rules_classes[ARCH_INDEX(inv)][ARCH_INDEX(*pos)] = 0;
8494         }
8495  }
8496  
8497 -static void rules_init_classes()
8498 +static void rules_init_classes(void)
8499  {
8500         memset(rules_classes, 0, sizeof(rules_classes));
8501  
8502 @@ -172,12 +171,12 @@
8503         for (pos = 0; pos < 0x100; pos++) conv[pos] = pos;
8504  
8505         while (*src)
8506 -               conv[(ARCH_INDEX)*src++] = *dst++;
8507 +               conv[ARCH_INDEX(*src++)] = *dst++;
8508  
8509         return conv;
8510  }
8511  
8512 -static void rules_init_convs()
8513 +static void rules_init_convs(void)
8514  {
8515         conv_shift = rules_init_conv(conv_source, CONV_SHIFT);
8516         conv_invert = rules_init_conv(conv_source, CONV_INVERT);
8517 @@ -276,7 +275,7 @@
8518                 in[RULE_WORD_SIZE - 1] = 0;
8519  
8520                 switch (LAST) {
8521 -/* Crack v4.1 rules */
8522 +/* Crack 4.1 rules */
8523                 case ':':
8524                 case ' ':
8525                 case '\t':
8526 @@ -303,12 +302,12 @@
8527  
8528                 case 'c':
8529                         pos = 0;
8530 -                       if ((out[0] = conv_toupper[(ARCH_INDEX)in[0]]))
8531 +                       if ((out[0] = conv_toupper[ARCH_INDEX(in[0])]))
8532                         while (in[++pos])
8533 -                               out[pos] = conv_tolower[(ARCH_INDEX)in[pos]];
8534 +                               out[pos] = conv_tolower[ARCH_INDEX(in[pos])];
8535                         out[pos] = 0;
8536                         if (out[0] == 'M' && out[1] == 'c')
8537 -                               out[2] = conv_toupper[(ARCH_INDEX)out[2]];
8538 +                               out[2] = conv_toupper[ARCH_INDEX(out[2])];
8539                         break;
8540  
8541                 case 'r':
8542 @@ -426,7 +425,7 @@
8543                         out = in;
8544                         break;
8545  
8546 -/* Crack v5.0 rules */
8547 +/* Crack 5.0 rules */
8548                 case '[':
8549                         if (in[0]) strcpy(out, &in[1]); else out[0] = 0;
8550                         break;
8551 @@ -438,12 +437,12 @@
8552  
8553                 case 'C':
8554                         pos = 0;
8555 -                       if ((out[0] = conv_tolower[(ARCH_INDEX)in[0]]))
8556 +                       if ((out[0] = conv_tolower[ARCH_INDEX(in[0])]))
8557                         while (in[++pos])
8558 -                               out[pos] = conv_toupper[(ARCH_INDEX)in[pos]];
8559 +                               out[pos] = conv_toupper[ARCH_INDEX(in[pos])];
8560                         out[pos] = 0;
8561                         if (out[0] == 'm' && out[1] == 'C')
8562 -                               out[2] = conv_tolower[(ARCH_INDEX)out[2]];
8563 +                               out[2] = conv_tolower[ARCH_INDEX(out[2])];
8564                         break;
8565  
8566                 case 't':
8567 @@ -481,7 +480,7 @@
8568                 case 'T':
8569                         POSITION
8570                         out = in;
8571 -                       out[pos] = conv_invert[(ARCH_INDEX)out[pos]];
8572 +                       out[pos] = conv_invert[ARCH_INDEX(out[pos])];
8573                         break;
8574  
8575                 case 'D':
8576 @@ -677,7 +676,7 @@
8577  
8578         if (!(count = rules_check(start, split))) {
8579                 fprintf(stderr, "Invalid rule in %s at line %d: %s\n",
8580 -                       path_expand(CFG_NAME), rules_line,
8581 +                       cfg_name, rules_line,
8582                         rules_errors[rules_errno]);
8583                 error();
8584         }
8585 diff -ruN john-1.6/src/signals.c john-1.6.34/src/signals.c
8586 --- john-1.6/src/signals.c      1998-12-03 01:29:50.000000000 +0100
8587 +++ john-1.6.34/src/signals.c   2001-05-08 02:59:05.000000000 +0200
8588 @@ -1,8 +1,16 @@
8589  /*
8590   * This file is part of John the Ripper password cracker,
8591 - * Copyright (c) 1996-98 by Solar Designer
8592 + * Copyright (c) 1996-2001 by Solar Designer
8593   */
8594  
8595 +#ifdef __ultrix__
8596 +#define __POSIX
8597 +#define _POSIX_SOURCE
8598 +#endif
8599 +
8600 +#ifdef _SCO_C_DIALECT
8601 +#include <limits.h>
8602 +#endif
8603  #include <stdio.h>
8604  #include <stdlib.h>
8605  #include <string.h>
8606 @@ -24,12 +32,11 @@
8607  #include "tty.h"
8608  #include "config.h"
8609  
8610 -int event_pending = 0, event_abort = 0, event_save = 0, event_status = 0;
8611 +volatile int event_pending = 0;
8612 +volatile int event_abort = 0, event_save = 0, event_status = 0;
8613  
8614  static int timer_save_interval, timer_save_value;
8615  
8616 -static void (*sig_yield)(int always);
8617 -
8618  #if !OS_TIMER
8619  
8620  #include <time.h>
8621 @@ -44,7 +51,7 @@
8622         timer_emu_count = 0; timer_emu_max = 0;
8623  }
8624  
8625 -void sig_timer_emu_tick()
8626 +void sig_timer_emu_tick(void)
8627  {
8628         static clock_t last = 0;
8629         clock_t current;
8630 @@ -73,9 +80,9 @@
8631  
8632  #endif
8633  
8634 -static void sig_install_update();
8635 +static void sig_install_update(void);
8636  
8637 -static void sig_handle_update()
8638 +static void sig_handle_update(int signum)
8639  {
8640         event_save = event_pending = 1;
8641  
8642 @@ -84,7 +91,7 @@
8643  #endif
8644  }
8645  
8646 -static void sig_install_update()
8647 +static void sig_install_update(void)
8648  {
8649  #ifdef SA_RESTART
8650         struct sigaction sa;
8651 @@ -98,12 +105,12 @@
8652  #endif
8653  }
8654  
8655 -static void sig_remove_update()
8656 +static void sig_remove_update(void)
8657  {
8658         signal(SIGHUP, SIG_IGN);
8659  }
8660  
8661 -void check_abort()
8662 +void check_abort(void)
8663  {
8664         if (event_abort) {
8665                 fprintf(stderr, "Session aborted\n");
8666 @@ -111,7 +118,7 @@
8667         }
8668  }
8669  
8670 -static void sig_install_abort();
8671 +static void sig_install_abort(void);
8672  
8673  #ifdef __CYGWIN32__
8674  static BOOL sig_handle_abort(DWORD ctrltype)
8675 @@ -136,7 +143,7 @@
8676  #endif
8677  }
8678  
8679 -static void sig_install_abort()
8680 +static void sig_install_abort(void)
8681  {
8682  #ifdef __DJGPP__
8683         setcbrk(1);
8684 @@ -157,7 +164,7 @@
8685  #endif
8686  }
8687  
8688 -static void sig_remove_abort()
8689 +static void sig_remove_abort(void)
8690  {
8691         signal(SIGINT, SIG_DFL);
8692         signal(SIGTERM, SIG_DFL);
8693 @@ -165,7 +172,7 @@
8694  
8695  #ifdef __CYGWIN32__
8696  
8697 -static int sig_getchar()
8698 +static int sig_getchar(void)
8699  {
8700         int c;
8701  
8702 @@ -183,7 +190,7 @@
8703  
8704  #endif
8705  
8706 -static void sig_install_timer();
8707 +static void sig_install_timer(void);
8708  
8709  static void sig_handle_timer(int signum)
8710  {
8711 @@ -207,13 +214,10 @@
8712         sig_install_timer();
8713  #endif
8714  
8715 -       if (!event_pending && sig_yield)
8716 -               sig_yield(1);
8717 -
8718         errno = saved_errno;
8719  }
8720  
8721 -static void sig_install_timer()
8722 +static void sig_install_timer(void)
8723  {
8724  #if !OS_TIMER
8725         signal(SIGALRM, sig_handle_timer);
8726 @@ -243,7 +247,7 @@
8727  #endif
8728  }
8729  
8730 -static void sig_remove_timer()
8731 +static void sig_remove_timer(void)
8732  {
8733  #if OS_TIMER
8734         struct itimerval it;
8735 @@ -255,9 +259,9 @@
8736         signal(SIGALRM, SIG_DFL);
8737  }
8738  
8739 -static void sig_done();
8740 +static void sig_done(void);
8741  
8742 -void sig_init()
8743 +void sig_init(void)
8744  {
8745         timer_save_interval = cfg_get_int(SECTION_OPTIONS, NULL, "Save");
8746         if (timer_save_interval < 0)
8747 @@ -274,7 +278,7 @@
8748         sig_install_timer();
8749  }
8750  
8751 -static void sig_done()
8752 +static void sig_done(void)
8753  {
8754         sig_remove_update();
8755         sig_remove_abort();
8756 diff -ruN john-1.6/src/signals.h john-1.6.34/src/signals.h
8757 --- john-1.6/src/signals.h      1998-12-03 01:29:50.000000000 +0100
8758 +++ john-1.6.34/src/signals.h   2001-05-08 21:21:41.000000000 +0200
8759 @@ -1,6 +1,6 @@
8760  /*
8761   * This file is part of John the Ripper password cracker,
8762 - * Copyright (c) 1996-98 by Solar Designer
8763 + * Copyright (c) 1996-2001 by Solar Designer
8764   */
8765  
8766  /*
8767 @@ -19,28 +19,29 @@
8768   * to clear individual flags in a bitmask without a race condition on RISC,
8769   * or having to block the signals.
8770   */
8771 -extern int event_pending;      /* An event is pending */
8772 -extern int event_abort;                /* Abort requested */
8773 -extern int event_save;         /* Time to save the crash recovery file */
8774 -extern int event_status;       /* Status display requested */
8775 +extern volatile int event_pending;     /* An event is pending */
8776 +extern volatile int event_abort;       /* Abort requested */
8777 +extern volatile int event_save;                /* Save the crash recovery file */
8778 +extern volatile int event_status;      /* Status display requested */
8779  
8780  #if !OS_TIMER
8781  /*
8782   * Timer emulation for systems with no setitimer(2).
8783   */
8784  #include <sys/times.h>
8785 +
8786  extern void sig_timer_emu_init(clock_t interval);
8787 -extern void sig_timer_emu_tick();
8788 +extern void sig_timer_emu_tick(void);
8789  #endif
8790  
8791  /*
8792   * Installs the signal handlers.
8793   */
8794 -extern void sig_init(void (*yield)(int always));
8795 +extern void sig_init(void);
8796  
8797  /*
8798   * Terminates the process if event_abort is set.
8799   */
8800 -extern void check_abort();
8801 +extern void check_abort(void);
8802  
8803  #endif
8804 diff -ruN john-1.6/src/single.c john-1.6.34/src/single.c
8805 --- john-1.6/src/single.c       1998-12-03 01:29:50.000000000 +0100
8806 +++ john-1.6.34/src/single.c    2000-03-15 00:27:42.000000000 +0100
8807 @@ -1,6 +1,6 @@
8808  /*
8809   * This file is part of John the Ripper password cracker,
8810 - * Copyright (c) 1996-98 by Solar Designer
8811 + * Copyright (c) 1996-99 by Solar Designer
8812   */
8813  
8814  #include <stdio.h>
8815 @@ -8,7 +8,6 @@
8816  
8817  #include "misc.h"
8818  #include "params.h"
8819 -#include "path.h"
8820  #include "memory.h"
8821  #include "signals.h"
8822  #include "loader.h"
8823 @@ -33,7 +32,7 @@
8824         fprintf(file, "%d\n", rec_rule);
8825  }
8826  
8827 -static int restore_rule_number()
8828 +static int restore_rule_number(void)
8829  {
8830         if (rule_ctx)
8831         for (rule_number = 0; rule_number < rec_rule; rule_number++)
8832 @@ -49,7 +48,7 @@
8833         return restore_rule_number();
8834  }
8835  
8836 -static int get_progress()
8837 +static int get_progress(void)
8838  {
8839         if (progress) return progress;
8840  
8841 @@ -75,7 +74,7 @@
8842         memset((*keys)->hash, -1, hash_size);
8843  }
8844  
8845 -static void single_init()
8846 +static void single_init(void)
8847  {
8848         struct db_salt *salt;
8849  
8850 @@ -87,7 +86,7 @@
8851  
8852         if (rpp_init(rule_ctx, SUBSECTION_SINGLE)) {
8853                 fprintf(stderr, "No \"single crack\" mode rules found in %s\n",
8854 -                       path_expand(CFG_NAME));
8855 +                       cfg_name);
8856                 error();
8857         }
8858  
8859 @@ -289,7 +288,7 @@
8860         return 0;
8861  }
8862  
8863 -static void single_run()
8864 +static void single_run(void)
8865  {
8866         char *rule;
8867         struct db_salt *salt;
8868 @@ -315,7 +314,7 @@
8869         }
8870  }
8871  
8872 -static void single_done()
8873 +static void single_done(void)
8874  {
8875         struct db_salt *salt;
8876  
8877 diff -ruN john-1.6/src/sparc64.h john-1.6.34/src/sparc64.h
8878 --- john-1.6/src/sparc64.h      1970-01-01 01:00:00.000000000 +0100
8879 +++ john-1.6.34/src/sparc64.h   2003-01-24 04:41:40.000000000 +0100
8880 @@ -0,0 +1,47 @@
8881 +/*
8882 + * This file is part of John the Ripper password cracker,
8883 + * Copyright (c) 2003 by Solar Designer
8884 + */
8885 +
8886 +/*
8887 + * Architecture specific parameters for SPARC V9, 64-bit.
8888 + */
8889 +
8890 +#ifndef _JOHN_ARCH_H
8891 +#define _JOHN_ARCH_H
8892 +
8893 +#define ARCH_WORD                      long
8894 +#define ARCH_SIZE                      8
8895 +#define ARCH_BITS                      64
8896 +#define ARCH_BITS_LOG                  6
8897 +#define ARCH_BITS_STR                  "64"
8898 +#define ARCH_LITTLE_ENDIAN             0
8899 +#define ARCH_INT_GT_32                 0
8900 +#define ARCH_ALLOWS_UNALIGNED          0
8901 +#define ARCH_INDEX(x)                  ((unsigned int)(unsigned char)(x))
8902 +
8903 +#define OS_TIMER                       1
8904 +#define OS_FLOCK                       1
8905 +
8906 +#define CPU_DETECT                     0
8907 +
8908 +#define DES_ASM                                0
8909 +#define DES_128K                       0
8910 +#define DES_X2                         0
8911 +#define DES_MASK                       1
8912 +#define DES_SCALE                      0
8913 +#define DES_EXTB                       0
8914 +#define DES_COPY                       1
8915 +#define DES_BS_ASM                     0
8916 +#define DES_BS                         1
8917 +#define DES_BS_VECTOR                  0
8918 +#define DES_BS_EXPAND                  1
8919 +
8920 +#define MD5_ASM                                0
8921 +#define MD5_X2                         1
8922 +#define MD5_IMM                                0
8923 +
8924 +#define BF_ASM                         0
8925 +#define BF_SCALE                       0
8926 +
8927 +#endif
8928 diff -ruN john-1.6/src/sparc.S john-1.6.34/src/sparc.S
8929 --- john-1.6/src/sparc.S        1998-12-03 01:29:50.000000000 +0100
8930 +++ john-1.6.34/src/sparc.S     2001-01-24 20:24:09.000000000 +0100
8931 @@ -1,6 +1,6 @@
8932  /*
8933   * This file is part of John the Ripper password cracker,
8934 - * Copyright (c) 1996-98 by Solar Designer
8935 + * Copyright (c) 1996-2001 by Solar Designer
8936   */
8937  
8938  /*
8939 @@ -9,6 +9,29 @@
8940  
8941  #include "arch.h"
8942  
8943 +#ifdef UNDERSCORES
8944 +#define DES_IV                         _DES_IV
8945 +#define DES_count                      _DES_count
8946 +#define DES_KS_current                 _DES_KS_current
8947 +#define DES_KS_table                   _DES_KS_table
8948 +#define DES_SPE_L                      _DES_SPE_L
8949 +#define DES_SPE_H                      _DES_SPE_H
8950 +#define DES_SPE_W                      _DES_SPE_W
8951 +#define DES_std_crypt                  _DES_std_crypt
8952 +#define DES_xor_key1                   _DES_xor_key1
8953 +#define DES_xor_key2                   _DES_xor_key2
8954 +#endif
8955 +
8956 +/*
8957 + * Load an address assuming that it is 1024-byte aligned if the section
8958 + * alignment for this platform is large enough.
8959 + */
8960 +#ifdef BSD
8961 +#define LDAA(addr, reg)                        set (addr),reg
8962 +#else
8963 +#define LDAA(addr, reg)                        sethi %hi(addr),reg
8964 +#endif
8965 +
8966  /*
8967   * DES stuff.
8968   */
8969 @@ -202,17 +225,17 @@
8970  DES_std_crypt:
8971  #if DES_128K
8972         save %sp,-112,%sp
8973 -       sethi %hi(DES_SPE_L+0x400),SPE_L_4
8974 -       sethi %hi(DES_SPE_W),SPE_0
8975 -       sethi %hi(DES_SPE_W+0x8000),SPE_1
8976 -       sethi %hi(DES_SPE_W+0x10000),SPE_2
8977 -       sethi %hi(DES_SPE_W+0x18000),SPE_3
8978 +       LDAA (DES_SPE_L+0x400,SPE_L_4)
8979 +       LDAA (DES_SPE_W,SPE_0)
8980 +       LDAA (DES_SPE_W+0x8000,SPE_1)
8981 +       LDAA (DES_SPE_W+0x10000,SPE_2)
8982 +       LDAA (DES_SPE_W+0x18000,SPE_3)
8983         set 0xFFFF,FFFF
8984  #else
8985         save %sp,-120,%sp
8986         st %i7,[%fp-24]
8987 -       sethi %hi(DES_SPE_L),SPE_L_0
8988 -       sethi %hi(DES_SPE_L+0x400),SPE_L_4
8989 +       LDAA (DES_SPE_L,SPE_L_0)
8990 +       LDAA (DES_SPE_L+0x400,SPE_L_4)
8991         add SPE_L_0,0x808,SPE_H_0
8992         add SPE_L_0,0x100,SPE_L_1
8993         add SPE_L_0,0x200,SPE_L_2
8994 @@ -296,7 +319,7 @@
8995  .align 16
8996  .globl DES_xor_key1
8997  DES_xor_key1:
8998 -       sethi %hi(DES_KS_current),kp
8999 +       LDAA (DES_KS_current,kp)
9000         DES_xor1(0,)
9001         DES_xor1(16,)
9002         DES_xor1(32,)
9003 @@ -328,7 +351,7 @@
9004  .align 16
9005  .globl DES_xor_key2
9006  DES_xor_key2:
9007 -       sethi %hi(DES_KS_current),kp
9008 +       LDAA (DES_KS_current,kp)
9009         DES_xor2(0,)
9010         DES_xor2(16,)
9011         DES_xor2(32,)
9012 @@ -340,7 +363,12 @@
9013  
9014  .data
9015  
9016 +#ifdef BSD
9017 +.align 8
9018 +#else
9019  .align 1024
9020 +#endif
9021 +
9022  .globl DES_SPE_L
9023  DES_SPE_L:
9024  .skip 0x800
9025 @@ -363,9 +391,22 @@
9026  DES_count:
9027  .skip 4
9028  
9029 +#ifdef BSD
9030 +
9031 +#if DES_128K
9032 +.common DES_SPE_W, 0x20000, "bss"
9033 +#endif
9034 +
9035 +.common DES_KS_current, 128, "bss"
9036 +.common DES_KS_table, (8 * 128 * 16 * 8), "bss"
9037 +
9038 +#else
9039 +
9040  #if DES_128K
9041  .common DES_SPE_W, 0x20000, 1024
9042  #endif
9043  
9044  .common DES_KS_current, 128, 1024
9045  .common DES_KS_table, (8 * 128 * 16 * 8), 32
9046 +
9047 +#endif
9048 diff -ruN john-1.6/src/sparc.sh john-1.6.34/src/sparc.sh
9049 --- john-1.6/src/sparc.sh       1998-12-03 01:29:50.000000000 +0100
9050 +++ john-1.6.34/src/sparc.sh    2000-06-25 07:08:21.000000000 +0200
9051 @@ -1,7 +1,7 @@
9052  #!/bin/sh
9053  #
9054  # This file is part of John the Ripper password cracker,
9055 -# Copyright (c) 1996-98 by Solar Designer
9056 +# Copyright (c) 1996-2000 by Solar Designer
9057  #
9058  
9059  [ $# -eq 3 ] || exit 1
9060 @@ -10,13 +10,13 @@
9061  HAMMER=$2
9062  DES_DEPEND=$3
9063  
9064 -# Detect the best standard DES algorithm
9065 +# Detect the best non-bitslice DES algorithm
9066  
9067  MAX=0
9068  DES_BEST=1
9069  
9070  for MODE in 2 3; do
9071 -       if ./detect $MODE 0 0 0 0 > arch.h; then
9072 +       if ./detect $MODE 0 0 1 0 0 > arch.h; then
9073                 rm -f $DES_DEPEND bench
9074                 $MAKE $HAMMER NAIL=bench \
9075                         BENCH_DES_OBJS_DEPEND="$DES_DEPEND" || exit 1
9076 @@ -30,7 +30,7 @@
9077  
9078  # Check if bitslice DES is faster
9079  
9080 -./detect $DES_BEST 0 1 0 0 > arch.h
9081 +./detect $DES_BEST 0 1 1 0 0 > arch.h
9082  rm -f $DES_DEPEND bench
9083  
9084  $MAKE $HAMMER NAIL=bench BENCH_DES_OBJS_DEPEND="$DES_DEPEND" || exit 1
9085 @@ -44,5 +44,5 @@
9086  # Produce sparc.h, make sure everything is rebuilt with detected options,
9087  # and do some cleanup
9088  
9089 -./detect $DES_BEST 0 $DES_BS 0 0 > sparc.h
9090 +./detect $DES_BEST 0 $DES_BS 1 0 0 > sparc.h
9091  rm -f $DES_DEPEND bench detect best.o detect.o arch.h
9092 diff -ruN john-1.6/src/status.c john-1.6.34/src/status.c
9093 --- john-1.6/src/status.c       1998-12-03 01:29:50.000000000 +0100
9094 +++ john-1.6.34/src/status.c    2001-06-08 23:11:07.000000000 +0200
9095 @@ -1,8 +1,16 @@
9096  /*
9097   * This file is part of John the Ripper password cracker,
9098 - * Copyright (c) 1996-98 by Solar Designer
9099 + * Copyright (c) 1996-2001 by Solar Designer
9100   */
9101  
9102 +#ifdef __ultrix__
9103 +#define __POSIX
9104 +#define _POSIX_SOURCE
9105 +#endif
9106 +
9107 +#ifdef _SCO_C_DIALECT
9108 +#include <limits.h>
9109 +#endif
9110  #include <stdio.h>
9111  #include <string.h>
9112  #include <time.h>
9113 @@ -10,7 +18,6 @@
9114  
9115  #include "times.h"
9116  
9117 -#include "arch.h"
9118  #include "misc.h"
9119  #include "math.h"
9120  #include "params.h"
9121 @@ -20,22 +27,21 @@
9122  
9123  struct status_main status;
9124  unsigned int status_restored_time = 0;
9125 -int (*status_get_progress)() = NULL;
9126 +int (*status_get_progress)(void) = NULL;
9127  
9128 -static clock_t get_time()
9129 +static clock_t get_time(void)
9130  {
9131         struct tms buf;
9132  
9133         return times(&buf);
9134  }
9135  
9136 -void status_init(int (*get_progress)(), int start)
9137 +void status_init(int (*get_progress)(void), int start)
9138  {
9139         if (start) {
9140                 if (!status_restored_time)
9141                         memset(&status, 0, sizeof(status));
9142 -               status.start_time =
9143 -                       get_time() - status_restored_time * CLK_TCK;
9144 +               status.start_time = get_time();
9145         }
9146  
9147         status_get_progress = get_progress;
9148 @@ -43,24 +49,51 @@
9149  
9150  void status_update_crypts(unsigned int count)
9151  {
9152 +       unsigned int saved_hi, time;
9153 +       clock_t ticks;
9154 +
9155 +       saved_hi = status.crypts.hi;
9156         add32to64(&status.crypts, count);
9157 +
9158 +       if (status.crypts.hi != saved_hi) {
9159 +               ticks = get_time() - status.start_time;
9160 +               if (ticks > ((clock_t)1 << (sizeof(clock_t) * 8 - 2))) {
9161 +                       time = ticks / CLK_TCK;
9162 +                       status_restored_time += time;
9163 +                       status.start_time += (clock_t)time * CLK_TCK;
9164 +               }
9165 +       }
9166  }
9167  
9168 -unsigned int status_get_time()
9169 +unsigned int status_get_time(void)
9170  {
9171 -       return (get_time() - status.start_time) / CLK_TCK;
9172 +       return status_restored_time +
9173 +               (get_time() - status.start_time) / CLK_TCK;
9174  }
9175  
9176  static char *status_get_cps(char *buffer)
9177  {
9178 -       unsigned int time, cps_hi, cps_lo;
9179 +       int use_ticks;
9180 +       clock_t ticks;
9181 +       unsigned long time;
9182 +       unsigned int cps_hi, cps_lo;
9183         int64 tmp;
9184  
9185 -       if (!(time = status_get_time())) time = 1;
9186 +       use_ticks = !status.crypts.hi && !status_restored_time;
9187  
9188 -       cps_hi = div64by32lo(&status.crypts, time);
9189 +       ticks = get_time() - status.start_time;
9190 +       if (use_ticks)
9191 +               time = ticks;
9192 +       else
9193 +               time = status_restored_time + ticks / CLK_TCK;
9194 +       if (!time) time = 1;
9195 +
9196 +       tmp = status.crypts;
9197 +       if (use_ticks) mul64by32(&tmp, CLK_TCK);
9198 +       cps_hi = div64by32lo(&tmp, time);
9199  
9200         tmp = status.crypts;
9201 +       if (use_ticks) mul64by32(&tmp, CLK_TCK);
9202         mul64by32(&tmp, 100);
9203         cps_lo = div64by32lo(&tmp, time) % 100;
9204  
9205 @@ -77,8 +110,8 @@
9206         int64 current, next, rem;
9207         char *s_words_ptr;
9208  
9209 -       s_words_ptr = &s_words[sizeof(s_words)];
9210 -       *--s_words_ptr = 0;
9211 +       s_words_ptr = &s_words[sizeof(s_words) - 1];
9212 +       *s_words_ptr = 0;
9213  
9214         current = status.crypts;
9215         do {
9216 @@ -143,7 +176,7 @@
9217                         saved_key ? saved_key : "");
9218  }
9219  
9220 -void status_print()
9221 +void status_print(void)
9222  {
9223         int percent_value;
9224         char s_percent[32];
9225 diff -ruN john-1.6/src/status.h john-1.6.34/src/status.h
9226 --- john-1.6/src/status.h       1998-12-03 01:29:50.000000000 +0100
9227 +++ john-1.6.34/src/status.h    2001-06-02 20:09:05.000000000 +0200
9228 @@ -1,6 +1,6 @@
9229  /*
9230   * This file is part of John the Ripper password cracker,
9231 - * Copyright (c) 1996-98 by Solar Designer
9232 + * Copyright (c) 1996-2001 by Solar Designer
9233   */
9234  
9235  /*
9236 @@ -27,7 +27,7 @@
9237  
9238  extern struct status_main status;
9239  
9240 -extern int (*status_get_progress)();
9241 +extern int (*status_get_progress)(void);
9242  
9243  /*
9244   * Elapsed time of previous sessions, in seconds.
9245 @@ -35,11 +35,11 @@
9246  extern unsigned int status_restored_time;
9247  
9248  /*
9249 - * If start is non-zero, sets start_time to current time minus
9250 - * status_restored_time, and the rest of fields to zero. Always
9251 - * initializes the get_progress() handler (can be NULL).
9252 + * If start is non-zero, sets start_time to current time and the rest of
9253 + * fields to zero. Always initializes the get_progress() handler (can be
9254 + * NULL).
9255   */
9256 -extern void status_init(int (*get_progress)(), int start);
9257 +extern void status_init(int (*get_progress)(void), int start);
9258  
9259  /*
9260   * Updates the crypts count.
9261 @@ -48,16 +48,12 @@
9262  
9263  /*
9264   * Returns the elapsed time in seconds.
9265 - *
9266 - * Currently this does not support running for more than 248 days total
9267 - * (assuming CLK_TCK is 100). However, this should survive uptimes of the
9268 - * box we are running on of more than 248 days.
9269   */
9270 -extern unsigned int status_get_time();
9271 +extern unsigned int status_get_time(void);
9272  
9273  /*
9274   * Prints current status to stdout.
9275   */
9276 -extern void status_print();
9277 +extern void status_print(void);
9278  
9279  #endif
9280 diff -ruN john-1.6/src/tty.c john-1.6.34/src/tty.c
9281 --- john-1.6/src/tty.c  1998-12-03 01:29:50.000000000 +0100
9282 +++ john-1.6.34/src/tty.c       1999-09-22 06:01:15.000000000 +0200
9283 @@ -1,6 +1,6 @@
9284  /*
9285   * This file is part of John the Ripper password cracker,
9286 - * Copyright (c) 1996-98 by Solar Designer
9287 + * Copyright (c) 1996-99 by Solar Designer
9288   */
9289  
9290  #ifndef __DJGPP__
9291 @@ -34,7 +34,7 @@
9292  static struct termios saved_ti;
9293  #endif
9294  
9295 -void tty_init()
9296 +void tty_init(void)
9297  {
9298  #ifndef __DJGPP__
9299         int fd;
9300 @@ -63,7 +63,7 @@
9301  #endif
9302  }
9303  
9304 -int tty_getchar()
9305 +int tty_getchar(void)
9306  {
9307  #ifndef __DJGPP__
9308         int c;
9309 @@ -90,7 +90,7 @@
9310         return -1;
9311  }
9312  
9313 -void tty_done()
9314 +void tty_done(void)
9315  {
9316  #ifndef __DJGPP__
9317         int fd;
9318 diff -ruN john-1.6/src/tty.h john-1.6.34/src/tty.h
9319 --- john-1.6/src/tty.h  1998-12-03 01:29:50.000000000 +0100
9320 +++ john-1.6.34/src/tty.h       1999-09-22 05:44:00.000000000 +0200
9321 @@ -1,6 +1,6 @@
9322  /*
9323   * This file is part of John the Ripper password cracker,
9324 - * Copyright (c) 1996-98 by Solar Designer
9325 + * Copyright (c) 1996-99 by Solar Designer
9326   */
9327  
9328  /*
9329 @@ -14,16 +14,16 @@
9330   * Initializes the terminal for unbuffered non-blocking input. Also registers
9331   * tty_done() via atexit().
9332   */
9333 -extern void tty_init();
9334 +extern void tty_init(void);
9335  
9336  /*
9337   * Reads a character, returns -1 if no data available or on error.
9338   */
9339 -extern int tty_getchar();
9340 +extern int tty_getchar(void);
9341  
9342  /*
9343   * Restores the terminal parameters and closes the file descriptor.
9344   */
9345 -extern void tty_done();
9346 +extern void tty_done(void);
9347  
9348  #endif
9349 diff -ruN john-1.6/src/unique.c john-1.6.34/src/unique.c
9350 --- john-1.6/src/unique.c       1998-12-03 01:29:50.000000000 +0100
9351 +++ john-1.6.34/src/unique.c    2002-11-05 21:49:46.000000000 +0100
9352 @@ -1,6 +1,6 @@
9353  /*
9354   * This file is part of John the Ripper password cracker,
9355 - * Copyright (c) 1996-98 by Solar Designer
9356 + * Copyright (c) 1996-2002 by Solar Designer
9357   */
9358  
9359  #include <stdio.h>
9360 @@ -79,7 +79,7 @@
9361         return hash;
9362  }
9363  
9364 -static void init_hash()
9365 +static void init_hash(void)
9366  {
9367         int index;
9368  
9369 @@ -87,7 +87,7 @@
9370                 buffer.hash[index] = ENTRY_END_HASH;
9371  }
9372  
9373 -static void read_buffer()
9374 +static void read_buffer(void)
9375  {
9376         char line[LINE_BUFFER_SIZE];
9377         unsigned int ptr, current, *last;
9378 @@ -97,7 +97,7 @@
9379         ptr = 0;
9380         while (fgetl(line, sizeof(line), stdin)) {
9381                 last = &buffer.hash[line_hash(line)];
9382 -#if ARCH_LITTLE_ENDIAN
9383 +#if ARCH_LITTLE_ENDIAN && !ARCH_INT_GT_32
9384                 current = *last;
9385  #else
9386                 current = get_int(last);
9387 @@ -125,7 +125,7 @@
9388         put_data(ptr, ENTRY_END_LIST);
9389  }
9390  
9391 -static void write_buffer()
9392 +static void write_buffer(void)
9393  {
9394         unsigned int ptr, hash;
9395  
9396 @@ -140,7 +140,7 @@
9397         }
9398  }
9399  
9400 -static void clean_buffer()
9401 +static void clean_buffer(void)
9402  {
9403         char line[LINE_BUFFER_SIZE];
9404         unsigned int current, *last;
9405 @@ -149,7 +149,11 @@
9406  
9407         while (fgetl(line, sizeof(line), output)) {
9408                 last = &buffer.hash[line_hash(line)];
9409 +#if ARCH_LITTLE_ENDIAN && !ARCH_INT_GT_32
9410                 current = *last;
9411 +#else
9412 +               current = get_int(last);
9413 +#endif
9414                 while (current != ENTRY_END_HASH && current != ENTRY_DUPE) {
9415                         if (!strcmp(line, &buffer.data[current + 4])) {
9416                                 put_int(last, get_data(current));
9417 @@ -162,6 +166,9 @@
9418         }
9419  
9420         if (ferror(output)) pexit("fgets");
9421 +
9422 +/* Workaround a Solaris stdio bug. */
9423 +       if (fseek(output, 0, SEEK_END) < 0) pexit("fseek");
9424  }
9425  
9426  static void unique_init(char *name)
9427 @@ -176,7 +183,7 @@
9428         if (!(output = fdopen(fd, "w+"))) pexit("fdopen");
9429  }
9430  
9431 -static void unique_run()
9432 +static void unique_run(void)
9433  {
9434         read_buffer();
9435         write_buffer();
9436 @@ -188,7 +195,7 @@
9437         }
9438  }
9439  
9440 -static void unique_done()
9441 +static void unique_done(void)
9442  {
9443         if (fclose(output)) pexit("fclose");
9444  }
9445 diff -ruN john-1.6/src/unshadow.c john-1.6.34/src/unshadow.c
9446 --- john-1.6/src/unshadow.c     1998-12-03 01:29:50.000000000 +0100
9447 +++ john-1.6.34/src/unshadow.c  2001-10-19 14:52:19.000000000 +0200
9448 @@ -1,6 +1,6 @@
9449  /*
9450   * This file is part of John the Ripper password cracker,
9451 - * Copyright (c) 1996-98 by Solar Designer
9452 + * Copyright (c) 1996-2001 by Solar Designer
9453   */
9454  
9455  #include <stdio.h>
9456 @@ -51,23 +51,44 @@
9457  
9458  static void process_shadow_line(char *line)
9459  {
9460 -       char *pos1, *pos2;
9461 -       struct shadow_entry **entry, *last;
9462 +       static struct shadow_entry **entry = NULL;
9463 +       struct shadow_entry *last;
9464 +       char *login, *passwd, *tail;
9465 +
9466 +       if (!(passwd = strchr(line, ':'))) {
9467 +               while (*line == ' ' || *line == '\t') line++;
9468 +               /* AIX */
9469 +               if (!strncmp(line, "password = ", 11) && entry)
9470 +                       (*entry)->passwd = str_alloc_copy(line + 11);
9471 +               return;
9472 +       }
9473  
9474 -       if (!(pos1 = strchr(line, ':'))) return;
9475 -       *pos1++ = 0;
9476 +       login = line;
9477 +       *passwd++ = 0;
9478  
9479 -       if (!(pos2 = strchr(pos1, ':')))
9480 -               pos2 = pos1 + strlen(pos1);
9481 -       if (pos2 - pos1 < 1) return;
9482 -       *pos2 = 0;
9483 +       /* DU / Tru64 C2, HP-UX tcb */
9484 +       if (!strncmp(passwd, "u_name=", 7)) {
9485 +               if ((passwd = strstr(passwd, ":u_pwd=")))
9486 +                       passwd += 7;
9487 +       } else
9488 +       /* HP-UX tcb */
9489 +       if (!strncmp(passwd, "u_pwd=", 6) && entry) {
9490 +               passwd += 6;
9491 +               if ((tail = strchr(passwd, ':')))
9492 +                       *tail = 0;
9493 +               (*entry)->passwd = str_alloc_copy(passwd);
9494 +               return;
9495 +       }
9496 +
9497 +       if (passwd && (tail = strchr(passwd, ':')))
9498 +               *tail = 0;
9499  
9500 -       entry = &shadow_table[login_hash(line)];
9501 +       entry = &shadow_table[login_hash(login)];
9502         last = *entry;
9503         *entry = mem_alloc_tiny(sizeof(struct shadow_entry), MEM_ALIGN_WORD);
9504         (*entry)->next = last;
9505 -       (*entry)->login = str_alloc_copy(line);
9506 -       (*entry)->passwd = str_alloc_copy(pos1);
9507 +       (*entry)->login = str_alloc_copy(login);
9508 +       (*entry)->passwd = passwd ? str_alloc_copy(passwd) : "*";
9509  }
9510  
9511  static void process_passwd_line(char *line)
9512 @@ -81,7 +102,7 @@
9513         if (!(pos2 = strchr(pos1, ':')))
9514                 pos2 = pos1 + strlen(pos1);
9515  
9516 -       if ((current = shadow_table[login_hash(line)]))
9517 +       if (pos2 > pos1 && (current = shadow_table[login_hash(line)]))
9518         do {
9519                 if (!strcmp(current->login, line)) {
9520                         printf("%s:%s%s\n", line, current->passwd, pos2);
9521 diff -ruN john-1.6/src/vax.h john-1.6.34/src/vax.h
9522 --- john-1.6/src/vax.h  1970-01-01 01:00:00.000000000 +0100
9523 +++ john-1.6.34/src/vax.h       2000-08-24 00:16:43.000000000 +0200
9524 @@ -0,0 +1,47 @@
9525 +/*
9526 + * This file is part of John the Ripper password cracker,
9527 + * Copyright (c) 1996-2000 by Solar Designer
9528 + */
9529 +
9530 +/*
9531 + * Architecture specific parameters for VAX.
9532 + */
9533 +
9534 +#ifndef _JOHN_ARCH_H
9535 +#define _JOHN_ARCH_H
9536 +
9537 +#define ARCH_WORD                      long
9538 +#define ARCH_SIZE                      4
9539 +#define ARCH_BITS                      32
9540 +#define ARCH_BITS_LOG                  5
9541 +#define ARCH_BITS_STR                  "32"
9542 +#define ARCH_LITTLE_ENDIAN             1
9543 +#define ARCH_INT_GT_32                 0
9544 +#define ARCH_ALLOWS_UNALIGNED          1
9545 +#define ARCH_INDEX(x)                  ((unsigned int)(unsigned char)(x))
9546 +
9547 +#define OS_TIMER                       1
9548 +#define OS_FLOCK                       1
9549 +
9550 +#define CPU_DETECT                     0
9551 +
9552 +#define DES_ASM                                0
9553 +#define DES_128K                       1
9554 +#define DES_X2                         0
9555 +#define DES_MASK                       1
9556 +#define DES_SCALE                      1
9557 +#define DES_EXTB                       1
9558 +#define DES_COPY                       1
9559 +#define DES_BS_ASM                     0
9560 +#define DES_BS                         1
9561 +#define DES_BS_VECTOR                  0
9562 +#define DES_BS_EXPAND                  1
9563 +
9564 +#define MD5_ASM                                0
9565 +#define MD5_X2                         0
9566 +#define MD5_IMM                                1
9567 +
9568 +#define BF_ASM                         0
9569 +#define BF_SCALE                       0
9570 +
9571 +#endif
9572 diff -ruN john-1.6/src/wordlist.c john-1.6.34/src/wordlist.c
9573 --- john-1.6/src/wordlist.c     1998-12-03 01:29:50.000000000 +0100
9574 +++ john-1.6.34/src/wordlist.c  2000-03-15 00:27:57.000000000 +0100
9575 @@ -1,6 +1,6 @@
9576  /*
9577   * This file is part of John the Ripper password cracker,
9578 - * Copyright (c) 1996-98 by Solar Designer
9579 + * Copyright (c) 1996-99 by Solar Designer
9580   */
9581  
9582  #include <stdio.h>
9583 @@ -36,7 +36,7 @@
9584         fprintf(file, "%d\n%ld\n", rec_rule, rec_pos);
9585  }
9586  
9587 -static int restore_rule_number()
9588 +static int restore_rule_number(void)
9589  {
9590         if (rule_ctx)
9591         for (rule_number = 0; rule_number < rec_rule; rule_number++)
9592 @@ -45,7 +45,7 @@
9593         return 0;
9594  }
9595  
9596 -static void restore_line_number()
9597 +static void restore_line_number(void)
9598  {
9599         char line[LINE_BUFFER_SIZE];
9600  
9601 @@ -72,7 +72,7 @@
9602         return 0;
9603  }
9604  
9605 -static void fix_state()
9606 +static void fix_state(void)
9607  {
9608         rec_rule = rule_number;
9609  
9610 @@ -87,7 +87,7 @@
9611         }
9612  }
9613  
9614 -static int get_progress()
9615 +static int get_progress(void)
9616  {
9617         struct stat file_stat;
9618         long pos;
9619 @@ -138,7 +138,7 @@
9620         if (rules) {
9621                 if (rpp_init(rule_ctx = &ctx, SUBSECTION_WORDLIST)) {
9622                         fprintf(stderr, "No wordlist mode rules found in %s\n",
9623 -                               path_expand(CFG_NAME));
9624 +                               cfg_name);
9625                         error();
9626                 }
9627  
9628 diff -ruN john-1.6/src/x86-any.h john-1.6.34/src/x86-any.h
9629 --- john-1.6/src/x86-any.h      1998-12-03 01:29:50.000000000 +0100
9630 +++ john-1.6.34/src/x86-any.h   2001-07-26 17:00:00.000000000 +0200
9631 @@ -1,6 +1,6 @@
9632  /*
9633   * This file is part of John the Ripper password cracker,
9634 - * Copyright (c) 1996-98 by Solar Designer
9635 + * Copyright (c) 1996-2001 by Solar Designer
9636   */
9637  
9638  /*
9639 @@ -10,17 +10,17 @@
9640  #ifndef _JOHN_ARCH_H
9641  #define _JOHN_ARCH_H
9642  
9643 -#define ARCH_GENERIC                   0
9644  #define ARCH_WORD                      long
9645  #define ARCH_SIZE                      4
9646  #define ARCH_BITS                      32
9647 +#define ARCH_BITS_LOG                  5
9648  #define ARCH_BITS_STR                  "32"
9649  #define ARCH_LITTLE_ENDIAN             1
9650  #define ARCH_INT_GT_32                 0
9651  #define ARCH_ALLOWS_UNALIGNED          1
9652 -#define ARCH_INDEX                     unsigned int
9653 +#define ARCH_INDEX(x)                  ((unsigned int)(unsigned char)(x))
9654  
9655 -#ifdef __CYGWIN32__
9656 +#if defined(__CYGWIN32__) || defined(__BEOS__)
9657  #define OS_TIMER                       0
9658  #else
9659  #define OS_TIMER                       1
9660 @@ -37,9 +37,13 @@
9661  #define DES_SCALE                      0
9662  #define DES_EXTB                       0
9663  #define DES_COPY                       1
9664 +#define DES_BS_ASM                     0
9665  #define DES_BS                         0
9666 +#define DES_BS_VECTOR                  0
9667 +#define DES_BS_EXPAND                  0
9668  
9669  #define MD5_ASM                                1
9670 +#define MD5_X2                         0
9671  #define MD5_IMM                                1
9672  
9673  #define BF_ASM                         1
9674 diff -ruN john-1.6/src/x86-mmx.h john-1.6.34/src/x86-mmx.h
9675 --- john-1.6/src/x86-mmx.h      1998-12-03 01:29:50.000000000 +0100
9676 +++ john-1.6.34/src/x86-mmx.h   2002-04-11 19:55:55.000000000 +0200
9677 @@ -1,6 +1,6 @@
9678  /*
9679   * This file is part of John the Ripper password cracker,
9680 - * Copyright (c) 1996-98 by Solar Designer
9681 + * Copyright (c) 1996-2002 by Solar Designer
9682   */
9683  
9684  /*
9685 @@ -10,17 +10,17 @@
9686  #ifndef _JOHN_ARCH_H
9687  #define _JOHN_ARCH_H
9688  
9689 -#define ARCH_GENERIC                   0
9690  #define ARCH_WORD                      long
9691  #define ARCH_SIZE                      4
9692  #define ARCH_BITS                      32
9693 +#define ARCH_BITS_LOG                  5
9694  #define ARCH_BITS_STR                  "32"
9695  #define ARCH_LITTLE_ENDIAN             1
9696  #define ARCH_INT_GT_32                 0
9697  #define ARCH_ALLOWS_UNALIGNED          1
9698 -#define ARCH_INDEX                     unsigned int
9699 +#define ARCH_INDEX(x)                  ((unsigned int)(unsigned char)(x))
9700  
9701 -#ifdef __CYGWIN32__
9702 +#if defined(__CYGWIN32__) || defined(__BEOS__)
9703  #define OS_TIMER                       0
9704  #else
9705  #define OS_TIMER                       1
9706 @@ -30,6 +30,12 @@
9707  #define CPU_DETECT                     1
9708  #define CPU_REQ                                1
9709  #define CPU_NAME                       "MMX"
9710 +#ifndef CPU_FALLBACK
9711 +#define CPU_FALLBACK                   0
9712 +#endif
9713 +#if CPU_FALLBACK
9714 +#define CPU_FALLBACK_BINARY            "john-non-mmx"
9715 +#endif
9716  
9717  #define DES_ASM                                1
9718  #define DES_128K                       0
9719 @@ -38,9 +44,15 @@
9720  #define DES_SCALE                      0
9721  #define DES_EXTB                       0
9722  #define DES_COPY                       1
9723 -#define DES_BS                         0
9724 +#define DES_STD_ALGORITHM_NAME         "48/64 4K MMX"
9725 +#define DES_BS_ASM                     1
9726 +#define DES_BS                         1
9727 +#define DES_BS_VECTOR                  2
9728 +#define DES_BS_EXPAND                  1
9729 +#define DES_BS_ALGORITHM_NAME          "64/64 BS MMX"
9730  
9731  #define MD5_ASM                                1
9732 +#define MD5_X2                         0
9733  #define MD5_IMM                                1
9734  
9735  #define BF_ASM                         1
9736 diff -ruN john-1.6/src/x86-mmx.S john-1.6.34/src/x86-mmx.S
9737 --- john-1.6/src/x86-mmx.S      1970-01-01 01:00:00.000000000 +0100
9738 +++ john-1.6.34/src/x86-mmx.S   2001-06-28 23:15:03.000000000 +0200
9739 @@ -0,0 +1,1310 @@
9740 +/*
9741 + * This file is part of John the Ripper password cracker,
9742 + * Copyright (c) 2000-2001 by Solar Designer and others:
9743 + *
9744 + * The MMX DES S-box code is by Bruce Ford and Rémi Guyomarch, originally
9745 + * for use in the distributed.net clients, included here with permission.
9746 + * Only minor modifications have been made to their S-box code. Optimized
9747 + * S-box expressions are based on work by Matthew Kwan (see nonstd.c).
9748 + *
9749 + * Note: there's some MMX code in x86.S as well.
9750 + */
9751 +
9752 +#ifdef UNDERSCORES
9753 +#define DES_bs_all                     _DES_bs_all
9754 +#define DES_bs_init_asm                        _DES_bs_init_asm
9755 +#define DES_bs_crypt                   _DES_bs_crypt
9756 +#define DES_bs_crypt_25                        _DES_bs_crypt_25
9757 +#define DES_bs_crypt_LM                        _DES_bs_crypt_LM
9758 +#endif
9759 +
9760 +/*
9761 + * Some broken systems don't offer section alignments larger than 4 bytes,
9762 + * while for the MMX code we need at least an 8 byte alignment. ALIGN_FIX
9763 + * is here to work around this issue when we happen to get bad addresses.
9764 + */
9765 +#ifndef ALIGN_FIX
9766 +#ifdef ALIGN_LOG
9767 +#define DO_ALIGN(log)                  .align (log)
9768 +#else
9769 +#define DO_ALIGN(log)                  .align (1 << (log))
9770 +#endif
9771 +#else
9772 +#ifdef ALIGN_LOG
9773 +#define DO_ALIGN(log)                  .align (log); .space 4
9774 +#else
9775 +#define DO_ALIGN(log)                  .align (1 << (log)); .space 4
9776 +#endif
9777 +#endif
9778 +
9779 +#ifdef BSD
9780 +.data
9781 +#else
9782 +.bss
9783 +#endif
9784 +
9785 +.globl DES_bs_all
9786 +DO_ALIGN(5)
9787 +DES_bs_all:
9788 +DES_bs_all_KSp:
9789 +.space (0x300 * 4)
9790 +DES_bs_all_KS_p:
9791 +DES_bs_all_KS_v:
9792 +.space (0x300 * 8)
9793 +DES_bs_all_E:
9794 +.space (96 * 4)
9795 +DES_bs_all_K:
9796 +.space (56 * 8)
9797 +DES_bs_all_B:
9798 +.space (64 * 8)
9799 +DES_bs_all_tmp:
9800 +.space (16 * 8)
9801 +DES_bs_all_fields_not_used_here:
9802 +.space (0x100 + 4 + 4 + 64 * 8)
9803 +DES_bs_all_possible_alignment_gaps:
9804 +.space 0x100
9805 +
9806 +#define E(i)                           DES_bs_all_E+(i)*4
9807 +#define B(i)                           DES_bs_all_B+(i)*8
9808 +#define tmp_at(i)                      DES_bs_all_tmp+(i)*8
9809 +
9810 +#define pnot                           tmp_at(0)
9811 +
9812 +#define a1                             %mm0
9813 +#define a2                             %mm1
9814 +#define a3                             %mm2
9815 +#define a4                             %mm3
9816 +#define a5                             %mm4
9817 +#define a6                             %mm5
9818 +
9819 +#define S1_out1                                %mm5
9820 +#define S1_out2                                %mm7
9821 +#define S1_out3                                %mm2
9822 +#define S1_out4                                %mm0
9823 +
9824 +#define S1_a1                          tmp_at(1)
9825 +#define S1_a3                          tmp_at(2)
9826 +#define S1_a5                          tmp_at(3)
9827 +#define S1_x1                          tmp_at(4)
9828 +#define S1_x3                          tmp_at(5)
9829 +#define S1_x4                          tmp_at(6)
9830 +#define S1_x5                          tmp_at(7)
9831 +#define S1_x6                          tmp_at(8)
9832 +#define S1_x13                         tmp_at(9)
9833 +#define S1_x14                         tmp_at(10)
9834 +#define S1_x25                         tmp_at(11)
9835 +#define S1_x26                         tmp_at(12)
9836 +#define S1_x38                         tmp_at(13)
9837 +#define S1_x55                         tmp_at(14)
9838 +#define S1_x58                         tmp_at(15)
9839 +
9840 +#define S1(out1, out2, out3, out4, extra) \
9841 +       movq %mm0,S1_a1; \
9842 +       movq %mm3,%mm6; \
9843 +       pxor pnot,%mm0; \
9844 +       pxor %mm2,%mm3; \
9845 +       pxor pnot,%mm6; \
9846 +       movq %mm0,%mm7; \
9847 +       extra; \
9848 +       movq %mm4,S1_a5; \
9849 +       por %mm2,%mm7; \
9850 +       movq %mm3,S1_x3; \
9851 +       movq %mm5,%mm4; \
9852 +       movq %mm6,S1_x1; \
9853 +       pxor %mm0,%mm3; \
9854 +       movq %mm7,S1_x5; \
9855 +       por %mm6,%mm0; \
9856 +       movq %mm2,S1_a3; \
9857 +       pand %mm6,%mm7; \
9858 +       movq %mm3,S1_x4; \
9859 +       por %mm3,%mm2; \
9860 +       pxor pnot,%mm2; \
9861 +       pand %mm0,%mm4; \
9862 +       movq %mm7,%mm6; \
9863 +       por %mm5,%mm2; \
9864 +       movq %mm7,S1_x6; \
9865 +       por %mm5,%mm6; \
9866 +       pxor %mm2,%mm7; \
9867 +       pxor %mm6,%mm3; \
9868 +       movq %mm2,S1_x25; \
9869 +       pxor %mm4,%mm6; \
9870 +       pand S1_a3,%mm4; \
9871 +       movq %mm6,%mm2; \
9872 +       pxor S1_a3,%mm6; \
9873 +       por %mm1,%mm2; \
9874 +       pand S1_x5,%mm6; \
9875 +       pxor %mm3,%mm2; \
9876 +       movq %mm4,S1_x38; \
9877 +       pxor %mm2,%mm0; \
9878 +       movq %mm7,S1_x26; \
9879 +       movq %mm5,%mm4; \
9880 +       movq %mm2,S1_x13; \
9881 +       por %mm0,%mm4; \
9882 +       movq S1_x1,%mm7; \
9883 +       por %mm1,%mm6; \
9884 +       movq %mm0,S1_x14; \
9885 +       movq %mm3,%mm2; \
9886 +       pandn S1_x3,%mm0; \
9887 +       pxor %mm7,%mm4; \
9888 +       por S1_x4,%mm5; \
9889 +       por %mm1,%mm0; \
9890 +       pxor S1_x38,%mm5; \
9891 +       pxor %mm0,%mm4; \
9892 +       movq S1_a5,%mm0; \
9893 +       pand %mm7,%mm2; \
9894 +       movq %mm6,S1_x55; \
9895 +       por %mm1,%mm2; \
9896 +       movq S1_x14,%mm6; \
9897 +       por %mm4,%mm0; \
9898 +       pand S1_x5,%mm6; \
9899 +       por %mm3,%mm7; \
9900 +       movq %mm5,S1_x58; \
9901 +       pxor %mm3,%mm6; \
9902 +       pxor S1_x6,%mm7; \
9903 +       movq %mm1,%mm5; \
9904 +       pxor S1_x26,%mm2; \
9905 +       pand %mm6,%mm5; \
9906 +       pand S1_a3,%mm6; \
9907 +       pxor %mm7,%mm5; \
9908 +       por S1_a5,%mm5; \
9909 +       movq S1_a1,%mm7; \
9910 +       pxor %mm2,%mm5; \
9911 +       movq S1_x4,%mm2; \
9912 +       por %mm3,%mm7; \
9913 +       por S1_x38,%mm2; \
9914 +       pxor %mm6,%mm3; \
9915 +       pxor S1_x25,%mm6; \
9916 +       pxor %mm4,%mm7; \
9917 +       movq S1_a3,%mm4; \
9918 +       por %mm1,%mm7; \
9919 +       por S1_x26,%mm4; \
9920 +       por %mm1,%mm6; \
9921 +       pxor S1_x14,%mm4; \
9922 +       pxor %mm2,%mm6; \
9923 +       movq S1_x13,%mm2; \
9924 +       pxor %mm4,%mm7; \
9925 +       pxor S1_x55,%mm3; \
9926 +       pxor %mm2,%mm0; \
9927 +       pxor out1,%mm5; \
9928 +       pand %mm3,%mm2; \
9929 +       movq S1_a5,%mm4; \
9930 +       pand %mm1,%mm2; \
9931 +       movq %mm5,out1; \
9932 +       pxor S1_x58,%mm2; \
9933 +       pand %mm4,%mm7; \
9934 +       pxor out4,%mm0; \
9935 +       pand %mm4,%mm2; \
9936 +       pxor out2,%mm7; \
9937 +       movq %mm0,out4; \
9938 +       pxor out3,%mm2; \
9939 +       pxor %mm6,%mm7; \
9940 +       pxor %mm3,%mm2; \
9941 +       movq %mm7,out2; \
9942 +       movq %mm2,out3
9943 +
9944 +#define S2_out1                                %mm1
9945 +#undef S2_out2
9946 +#define S2_out3                                %mm7
9947 +#define S2_out4                                %mm2
9948 +
9949 +#define S2_a1                          tmp_at(1)
9950 +#define S2_a2                          tmp_at(2)
9951 +#define S2_a3                          tmp_at(3)
9952 +#define S2_a4                          tmp_at(4)
9953 +#define S2_x3                          tmp_at(5)
9954 +#define S2_x4                          tmp_at(6)
9955 +#define S2_x5                          tmp_at(7)
9956 +#define S2_x13                         tmp_at(8)
9957 +#define S2_x18                         tmp_at(9)
9958 +#define S2_x25                         tmp_at(10)
9959 +
9960 +#define S2(out1, out2, out3, out4, extra) \
9961 +       movq %mm3,S2_a4; \
9962 +       movq %mm4,%mm6; \
9963 +       extra; \
9964 +       movq %mm0,S2_a1; \
9965 +       movq %mm4,%mm7; \
9966 +       pxor pnot,%mm0; \
9967 +       pxor %mm5,%mm6; \
9968 +       pxor pnot,%mm7; \
9969 +       movq %mm0,%mm3; \
9970 +       movq %mm2,S2_a3; \
9971 +       por %mm5,%mm7; \
9972 +       movq %mm6,S2_x3; \
9973 +       por %mm7,%mm3; \
9974 +       pxor %mm4,%mm7; \
9975 +       pxor %mm0,%mm6; \
9976 +       pand %mm1,%mm3; \
9977 +       por %mm7,%mm2; \
9978 +       movq %mm1,S2_a2; \
9979 +       pxor %mm5,%mm3; \
9980 +       movq %mm6,S2_x4; \
9981 +       pxor %mm1,%mm6; \
9982 +       movq %mm7,S2_x13; \
9983 +       pand %mm3,%mm1; \
9984 +       pand S2_a3,%mm3; \
9985 +       pxor %mm2,%mm1; \
9986 +       movq S2_x4,%mm7; \
9987 +       movq %mm1,%mm2; \
9988 +       pand S2_a4,%mm2; \
9989 +       pxor %mm6,%mm3; \
9990 +       movq %mm6,S2_x5; \
9991 +       pxor %mm2,%mm3; \
9992 +       movq S2_a1,%mm2; \
9993 +       por %mm5,%mm7; \
9994 +       por %mm2,%mm1; \
9995 +       pand %mm3,%mm7; \
9996 +       pxor out2,%mm3; \
9997 +       por %mm4,%mm2; \
9998 +       por S2_a3,%mm7; \
9999 +       movq %mm2,%mm6; \
10000 +       pxor S2_x13,%mm1; \
10001 +       por %mm5,%mm6; \
10002 +       movq %mm3,out2; \
10003 +       pand %mm0,%mm4; \
10004 +       movq S2_x13,%mm3; \
10005 +       por %mm0,%mm5; \
10006 +       movq %mm2,S2_x18; \
10007 +       pxor %mm6,%mm3; \
10008 +       movq S2_a2,%mm2; \
10009 +       pxor %mm6,%mm0; \
10010 +       pxor %mm2,%mm3; \
10011 +       pand %mm2,%mm0; \
10012 +       pxor %mm3,%mm7; \
10013 +       por %mm4,%mm2; \
10014 +       pxor S2_x3,%mm4; \
10015 +       pand %mm3,%mm6; \
10016 +       pxor %mm0,%mm4; \
10017 +       pxor %mm5,%mm6; \
10018 +       movq %mm7,S2_x25; \
10019 +       pand %mm3,%mm0; \
10020 +       movq S2_a3,%mm7; \
10021 +       pxor %mm2,%mm5; \
10022 +       pxor S2_x5,%mm0; \
10023 +       pand %mm4,%mm7; \
10024 +       pand S2_a2,%mm4; \
10025 +       pxor %mm5,%mm7; \
10026 +       por S2_a4,%mm7; \
10027 +       movq %mm1,%mm5; \
10028 +       por S2_a3,%mm5; \
10029 +       por %mm2,%mm1; \
10030 +       pand S2_x18,%mm2; \
10031 +       pxor %mm3,%mm4; \
10032 +       movq S2_a4,%mm3; \
10033 +       pand %mm4,%mm2; \
10034 +       pand S2_a3,%mm4; \
10035 +       pxor %mm5,%mm0; \
10036 +       pxor S2_x25,%mm7; \
10037 +       pxor %mm6,%mm4; \
10038 +       pxor out3,%mm7; \
10039 +       pand %mm3,%mm1; \
10040 +       por %mm3,%mm2; \
10041 +       pxor out1,%mm1; \
10042 +       pxor %mm4,%mm2; \
10043 +       pxor %mm0,%mm1; \
10044 +       pxor out4,%mm2; \
10045 +       movq %mm1,out1; \
10046 +       movq %mm7,out3; \
10047 +       movq %mm2,out4
10048 +
10049 +#define S3_out1                                %mm2
10050 +#define S3_out2                                %mm6
10051 +#define S3_out3                                %mm3
10052 +#define S3_out4                                %mm7
10053 +
10054 +#define S3_a1                          tmp_at(1)
10055 +#define S3_x2                          tmp_at(2)
10056 +#define S3_x9                          tmp_at(3)
10057 +#define S3_a5                          tmp_at(4)
10058 +#define S3_x4                          tmp_at(5)
10059 +#define S3_a6                          tmp_at(6)
10060 +#define S3_x6                          tmp_at(7)
10061 +#define S3_x5                          tmp_at(8)
10062 +#define S3_x11                         tmp_at(9)
10063 +#define S3_x12                         tmp_at(10)
10064 +#define S3_x13                         tmp_at(11)
10065 +#define S3_x54                         tmp_at(12)
10066 +#define S3_x7                          tmp_at(13)
10067 +#define S3_a4                          tmp_at(14)
10068 +#define S3_a3                          S3_a5
10069 +#define S3_x38                         S3_x4
10070 +
10071 +#define S3(out1, out2, out3, out4, extra) \
10072 +       movq %mm0,S3_a1; \
10073 +       extra; \
10074 +       movq %mm4,%mm0; \
10075 +       movq %mm5,%mm6; \
10076 +       pxor pnot,%mm6; \
10077 +       movq %mm4,%mm7; \
10078 +       pxor %mm6,%mm7; \
10079 +       movq %mm6,S3_x2; \
10080 +       pand %mm2,%mm0; \
10081 +       movq %mm7,S3_x9; \
10082 +       pxor %mm5,%mm0; \
10083 +       movq %mm4,S3_a5; \
10084 +       pandn %mm3,%mm4; \
10085 +       movq %mm0,S3_x4; \
10086 +       por %mm3,%mm7; \
10087 +       movq S3_a5,%mm6; \
10088 +       pxor %mm4,%mm0; \
10089 +       movq %mm5,S3_a6; \
10090 +       pandn %mm2,%mm6; \
10091 +       movq %mm0,S3_x6; \
10092 +       pxor %mm6,%mm7; \
10093 +       movq S3_x2,%mm5; \
10094 +       pxor %mm1,%mm0; \
10095 +       movq %mm4,S3_x5; \
10096 +       movq %mm7,%mm4; \
10097 +       por S3_x4,%mm5; \
10098 +       pand %mm0,%mm4; \
10099 +       movq %mm7,S3_x11; \
10100 +       pxor %mm5,%mm6; \
10101 +       pxor S3_a5,%mm7; \
10102 +       por %mm1,%mm6; \
10103 +       movq %mm4,S3_x12; \
10104 +       pand %mm5,%mm4; \
10105 +       movq %mm7,S3_x13; \
10106 +       por %mm0,%mm7; \
10107 +       movq %mm4,S3_x54; \
10108 +       movq %mm2,%mm4; \
10109 +       pxor S3_x9,%mm4; \
10110 +       pand %mm3,%mm7; \
10111 +       movq %mm0,S3_x7; \
10112 +       pxor %mm3,%mm4; \
10113 +       pxor S3_a6,%mm5; \
10114 +       pxor %mm4,%mm6; \
10115 +       movq %mm3,S3_a4; \
10116 +       por %mm5,%mm3; \
10117 +       movq %mm2,S3_a3; \
10118 +       pxor %mm3,%mm5; \
10119 +       por %mm1,%mm5; \
10120 +       pxor %mm7,%mm2; \
10121 +       pxor S3_x12,%mm7; \
10122 +       movq %mm2,%mm4; \
10123 +       por S3_x5,%mm2; \
10124 +       pand %mm1,%mm7; \
10125 +       por S3_x4,%mm4; \
10126 +       por %mm1,%mm2; \
10127 +       pxor S3_x11,%mm7; \
10128 +       pxor %mm3,%mm2; \
10129 +       movq S3_a1,%mm3; \
10130 +       pxor S3_a4,%mm4; \
10131 +       pand %mm3,%mm7; \
10132 +       pxor S3_x7,%mm7; \
10133 +       por %mm3,%mm2; \
10134 +       movq %mm4,S3_x38; \
10135 +       pxor %mm6,%mm2; \
10136 +       pxor out4,%mm7; \
10137 +       por %mm1,%mm4; \
10138 +       movq S3_a3,%mm6; \
10139 +       movq %mm2,%mm3; \
10140 +       pxor S3_x9,%mm6; \
10141 +       por S3_x5,%mm6; \
10142 +       pxor S3_x38,%mm3; \
10143 +       pxor %mm6,%mm4; \
10144 +       movq S3_a6,%mm6; \
10145 +       pand S3_x11,%mm6; \
10146 +       movq %mm7,out4; \
10147 +       movq S3_x2,%mm0; \
10148 +       pxor %mm6,%mm3; \
10149 +       por S3_x6,%mm6; \
10150 +       pand %mm1,%mm3; \
10151 +       por S3_x38,%mm0; \
10152 +       pxor %mm6,%mm3; \
10153 +       pxor S3_x13,%mm0; \
10154 +       movq %mm5,%mm6; \
10155 +       por S3_a1,%mm3; \
10156 +       pxor %mm5,%mm0; \
10157 +       pand S3_x54,%mm6; \
10158 +       pxor %mm4,%mm3; \
10159 +       por S3_a1,%mm6; \
10160 +       pxor out3,%mm3; \
10161 +       pxor %mm0,%mm6; \
10162 +       pxor out1,%mm2; \
10163 +       movq %mm3,out3; \
10164 +       pxor out2,%mm6; \
10165 +       movq %mm2,out1; \
10166 +       movq %mm6,out2
10167 +
10168 +#define S4_out1                                %mm1
10169 +#define S4_out2                                %mm0
10170 +#define S4_out3                                %mm6
10171 +#define S4_out4                                %mm5
10172 +
10173 +#define S4_a2                          tmp_at(1)
10174 +#define S4_a3                          tmp_at(2)
10175 +#define S4_a4                          tmp_at(3)
10176 +#define S4_a6                          tmp_at(4)
10177 +
10178 +#define S4(out1, out2, out3, out4, extra) \
10179 +       movq %mm2,%mm6; \
10180 +       movq %mm3,S4_a4; \
10181 +       movq %mm0,%mm7; \
10182 +       movq %mm1,S4_a2; \
10183 +       por %mm0,%mm6; \
10184 +       extra; \
10185 +       pand %mm4,%mm7; \
10186 +       movq %mm1,%mm3; \
10187 +       movq %mm5,S4_a6; \
10188 +       movq %mm2,S4_a3; \
10189 +       movq %mm4,%mm5; \
10190 +       pand %mm6,%mm5; \
10191 +       por %mm2,%mm3; \
10192 +       pxor pnot,%mm2; \
10193 +       pxor %mm5,%mm0; \
10194 +       pxor pnot,%mm0; \
10195 +       pxor %mm7,%mm6; \
10196 +       pxor %mm0,%mm3; \
10197 +       movq %mm1,%mm7; \
10198 +       pand %mm6,%mm7; \
10199 +       pxor %mm2,%mm5; \
10200 +       pxor %mm4,%mm2; \
10201 +       pand %mm5,%mm0; \
10202 +       pxor %mm7,%mm4; \
10203 +       pand %mm1,%mm5; \
10204 +       por %mm1,%mm2; \
10205 +       pxor %mm6,%mm5; \
10206 +       movq S4_a4,%mm1; \
10207 +       movq %mm0,%mm6; \
10208 +       pand %mm4,%mm1; \
10209 +       pxor %mm2,%mm6; \
10210 +       por S4_a4,%mm6; \
10211 +       pxor %mm3,%mm1; \
10212 +       pand S4_a2,%mm4; \
10213 +       pxor %mm5,%mm6; \
10214 +       movq S4_a6,%mm3; \
10215 +       pxor %mm0,%mm4; \
10216 +       pxor S4_a3,%mm7; \
10217 +       movq %mm3,%mm0; \
10218 +       pxor %mm2,%mm7; \
10219 +       pand %mm6,%mm0; \
10220 +       movq S4_a4,%mm2; \
10221 +       por %mm3,%mm6; \
10222 +       pxor %mm1,%mm0; \
10223 +       pand %mm2,%mm7; \
10224 +       pxor pnot,%mm1; \
10225 +       pxor %mm7,%mm4; \
10226 +       movq %mm4,%mm5; \
10227 +       pxor %mm1,%mm4; \
10228 +       pxor out1,%mm1; \
10229 +       por %mm4,%mm2; \
10230 +       pand S4_a2,%mm4; \
10231 +       pxor %mm6,%mm1; \
10232 +       pxor %mm0,%mm4; \
10233 +       pxor out3,%mm6; \
10234 +       pxor %mm4,%mm2; \
10235 +       pxor out2,%mm0; \
10236 +       pand %mm2,%mm3; \
10237 +       pxor %mm2,%mm6; \
10238 +       pxor %mm3,%mm5; \
10239 +       movq %mm1,out1; \
10240 +       pxor %mm5,%mm6; \
10241 +       movq %mm0,out2; \
10242 +       pxor out4,%mm5; \
10243 +       movq %mm6,out3; \
10244 +       movq %mm5,out4
10245 +
10246 +#define S5_out1                                %mm5
10247 +#define S5_out2                                %mm7
10248 +#define S5_out3                                %mm6
10249 +#define S5_out4                                %mm4
10250 +
10251 +#define S5_a1                          tmp_at(1)
10252 +#define S5_a2                          tmp_at(2)
10253 +#define S5_a6                          tmp_at(3)
10254 +#define S5_x2                          tmp_at(4)
10255 +#define S5_x4                          tmp_at(5)
10256 +#define S5_x5                          tmp_at(6)
10257 +#define S5_x6                          tmp_at(7)
10258 +#define S5_x7                          tmp_at(8)
10259 +#define S5_x8                          tmp_at(9)
10260 +#define S5_x9                          tmp_at(10)
10261 +#define S5_x13                         tmp_at(11)
10262 +#define S5_x16                         tmp_at(12)
10263 +#define S5_x17                         S5_a6
10264 +#define S5_x21                         S5_x7
10265 +#define S5_x24                         S5_x8
10266 +#define S5_x28                         S5_x17
10267 +#define S5_x38                         S5_x9
10268 +
10269 +#define S5(out1, out2, out3, out4, extra) \
10270 +       movq %mm1,S5_a2; \
10271 +       movq %mm3,%mm6; \
10272 +       movq %mm2,%mm7; \
10273 +       pandn %mm2,%mm6; \
10274 +       pandn %mm0,%mm7; \
10275 +       movq %mm6,%mm1; \
10276 +       movq %mm0,S5_a1; \
10277 +       pxor %mm0,%mm1; \
10278 +       extra; \
10279 +       pxor %mm3,%mm0; \
10280 +       movq %mm1,S5_x2; \
10281 +       movq %mm5,S5_a6; \
10282 +       por %mm0,%mm6; \
10283 +       por %mm7,%mm5; \
10284 +       movq %mm6,S5_x7; \
10285 +       pxor %mm5,%mm1; \
10286 +       movq %mm5,S5_x4; \
10287 +       pand %mm2,%mm6; \
10288 +       movq S5_a6,%mm5; \
10289 +       pxor %mm3,%mm6; \
10290 +       pandn S5_x7,%mm5; \
10291 +       movq %mm0,S5_x6; \
10292 +       movq %mm7,%mm0; \
10293 +       movq %mm5,S5_x8; \
10294 +       pxor %mm2,%mm5; \
10295 +       movq %mm1,S5_x5; \
10296 +       pxor %mm3,%mm0; \
10297 +       movq %mm5,S5_x9; \
10298 +       pandn %mm6,%mm7; \
10299 +       por S5_a6,%mm0; \
10300 +       por %mm4,%mm5; \
10301 +       movq %mm6,S5_x13; \
10302 +       pxor %mm1,%mm5; \
10303 +       movq %mm0,S5_x16; \
10304 +       pxor %mm0,%mm7; \
10305 +       movq S5_a2,%mm0; \
10306 +       movq %mm4,%mm1; \
10307 +       movq %mm7,S5_x17; \
10308 +       por %mm7,%mm1; \
10309 +       pand S5_x5,%mm7; \
10310 +       pxor %mm6,%mm1; \
10311 +       pandn %mm1,%mm0; \
10312 +       movq %mm7,%mm6; \
10313 +       pandn S5_x7,%mm6; \
10314 +       pxor %mm0,%mm5; \
10315 +       pxor S5_x9,%mm7; \
10316 +       movq %mm3,%mm0; \
10317 +       movq %mm5,S5_x21; \
10318 +       movq %mm6,%mm5; \
10319 +       pandn S5_x8,%mm0; \
10320 +       pandn %mm1,%mm5; \
10321 +       pxor out3,%mm6; \
10322 +       pxor %mm2,%mm0; \
10323 +       movq S5_a1,%mm2; \
10324 +       movq %mm0,%mm1; \
10325 +       pxor S5_x9,%mm2; \
10326 +       pand %mm4,%mm1; \
10327 +       movq %mm7,S5_x38; \
10328 +       pxor %mm1,%mm6; \
10329 +       movq S5_x4,%mm1; \
10330 +       movq %mm2,%mm7; \
10331 +       pand S5_x2,%mm7; \
10332 +       pand %mm3,%mm1; \
10333 +       pxor S5_x17,%mm1; \
10334 +       pandn %mm4,%mm7; \
10335 +       movq %mm2,S5_x24; \
10336 +       pxor %mm7,%mm1; \
10337 +       movq out2,%mm7; \
10338 +       por %mm2,%mm3; \
10339 +       movq S5_a2,%mm2; \
10340 +       pxor %mm1,%mm7; \
10341 +       movq %mm3,S5_x28; \
10342 +       pandn %mm3,%mm2; \
10343 +       movq S5_x38,%mm3; \
10344 +       pxor %mm2,%mm7; \
10345 +       movq S5_x16,%mm2; \
10346 +       por %mm4,%mm3; \
10347 +       por S5_x13,%mm2; \
10348 +       por %mm5,%mm1; \
10349 +       pxor out1,%mm5; \
10350 +       pxor %mm3,%mm2; \
10351 +       por S5_a2,%mm2; \
10352 +       movq %mm7,out2; \
10353 +       pxor S5_x6,%mm1; \
10354 +       pxor %mm2,%mm6; \
10355 +       pandn %mm4,%mm1; \
10356 +       movq S5_x38,%mm2; \
10357 +       pxor S5_x24,%mm1; \
10358 +       movq %mm2,%mm3; \
10359 +       pxor S5_x21,%mm2; \
10360 +       pxor %mm1,%mm5; \
10361 +       pand S5_x6,%mm3; \
10362 +       pandn %mm4,%mm2; \
10363 +       pand S5_x28,%mm2; \
10364 +       pxor %mm0,%mm3; \
10365 +       pxor pnot,%mm6; \
10366 +       pxor %mm2,%mm3; \
10367 +       movq S5_x21,%mm4; \
10368 +       por S5_a2,%mm3; \
10369 +       movq %mm6,out3; \
10370 +       pxor out4,%mm4; \
10371 +       pxor %mm3,%mm5; \
10372 +       movq %mm4,out4; \
10373 +       movq %mm5,out1
10374 +
10375 +#define S6_out1                                %mm0
10376 +#undef S6_out2
10377 +#define S6_out3                                %mm2
10378 +#define S6_out4                                %mm4
10379 +
10380 +#define S6_a1                          tmp_at(1)
10381 +#define S6_a2                          tmp_at(2)
10382 +#define S6_a3                          tmp_at(3)
10383 +#define S6_a4                          tmp_at(4)
10384 +#define S6_x1                          tmp_at(5)
10385 +#define S6_x2                          tmp_at(6)
10386 +#define S6_x5                          tmp_at(7)
10387 +#define S6_x6                          tmp_at(8)
10388 +#define S6_x8                          tmp_at(9)
10389 +#define S6_x15                         tmp_at(10)
10390 +#define S6_x16                         tmp_at(11)
10391 +
10392 +#define S6(out1, out2, out3, out4, extra) \
10393 +       movq %mm2,S6_a3; \
10394 +       extra; \
10395 +       movq %mm4,%mm6; \
10396 +       pxor pnot,%mm6; \
10397 +       movq %mm5,%mm7; \
10398 +       movq %mm1,S6_a2; \
10399 +       movq %mm4,%mm2; \
10400 +       movq %mm3,S6_a4; \
10401 +       pxor %mm1,%mm7; \
10402 +       pxor pnot,%mm1; \
10403 +       pxor %mm6,%mm7; \
10404 +       movq %mm6,S6_x2; \
10405 +       pxor %mm0,%mm7; \
10406 +       pand %mm5,%mm2; \
10407 +       movq %mm4,%mm6; \
10408 +       movq %mm1,S6_x1; \
10409 +       movq %mm5,%mm3; \
10410 +       pand S6_a2,%mm3; \
10411 +       pand %mm7,%mm6; \
10412 +       movq %mm0,S6_a1; \
10413 +       por %mm2,%mm1; \
10414 +       movq %mm2,S6_x6; \
10415 +       pand %mm6,%mm0; \
10416 +       movq %mm3,S6_x15; \
10417 +       pxor %mm0,%mm1; \
10418 +       movq S6_a4,%mm0; \
10419 +       movq %mm4,%mm2; \
10420 +       movq %mm6,S6_x8; \
10421 +       pand %mm1,%mm0; \
10422 +       movq %mm7,S6_x5; \
10423 +       pxor %mm3,%mm2; \
10424 +       movq S6_x2,%mm6; \
10425 +       pxor %mm7,%mm0; \
10426 +       movq S6_a1,%mm7; \
10427 +       pxor %mm5,%mm1; \
10428 +       movq %mm2,S6_x16; \
10429 +       pand %mm7,%mm2; \
10430 +       movq S6_a4,%mm3; \
10431 +       pxor %mm2,%mm6; \
10432 +       pxor S6_a2,%mm2; \
10433 +       pand %mm7,%mm1; \
10434 +       por %mm6,%mm3; \
10435 +       pxor %mm5,%mm6; \
10436 +       pxor %mm3,%mm1; \
10437 +       pand %mm6,%mm7; \
10438 +       pand S6_a3,%mm1; \
10439 +       pand %mm4,%mm6; \
10440 +       movq S6_x6,%mm3; \
10441 +       pxor %mm1,%mm0; \
10442 +       pxor out2,%mm0; \
10443 +       por %mm2,%mm3; \
10444 +       pand S6_a4,%mm3; \
10445 +       pxor %mm7,%mm4; \
10446 +       movq S6_x5,%mm1; \
10447 +       pxor %mm3,%mm4; \
10448 +       pxor pnot,%mm2; \
10449 +       por %mm4,%mm5; \
10450 +       movq %mm0,out2; \
10451 +       movq %mm5,%mm3; \
10452 +       pandn S6_a4,%mm3; \
10453 +       pxor %mm6,%mm1; \
10454 +       movq S6_x6,%mm0; \
10455 +       pxor %mm2,%mm3; \
10456 +       por S6_a4,%mm1; \
10457 +       pxor %mm3,%mm0; \
10458 +       pand S6_a3,%mm3; \
10459 +       pxor %mm1,%mm0; \
10460 +       por S6_x5,%mm6; \
10461 +       movq %mm7,%mm1; \
10462 +       pxor S6_x15,%mm7; \
10463 +       pxor %mm3,%mm4; \
10464 +       movq S6_a4,%mm3; \
10465 +       pxor %mm5,%mm7; \
10466 +       pand S6_x8,%mm5; \
10467 +       por %mm3,%mm7; \
10468 +       pxor S6_x6,%mm6; \
10469 +       por %mm3,%mm5; \
10470 +       por S6_x16,%mm1; \
10471 +       pxor %mm6,%mm5; \
10472 +       pxor S6_x1,%mm1; \
10473 +       movq S6_a3,%mm3; \
10474 +       pxor %mm1,%mm7; \
10475 +       pxor out4,%mm4; \
10476 +       por %mm3,%mm7; \
10477 +       pand %mm1,%mm2; \
10478 +       pxor out1,%mm0; \
10479 +       por %mm3,%mm2; \
10480 +       pxor %mm7,%mm0; \
10481 +       pxor %mm5,%mm2; \
10482 +       movq %mm4,out4; \
10483 +       pxor out3,%mm2; \
10484 +       movq %mm0,out1; \
10485 +       movq %mm2,out3
10486 +
10487 +#define S7_out1                                %mm7
10488 +#define S7_out2                                %mm1
10489 +#define S7_out3                                %mm3
10490 +#define S7_out4                                %mm0
10491 +
10492 +#define S7_a1                          tmp_at(1)
10493 +#define S7_a2                          tmp_at(2)
10494 +#define S7_a4                          tmp_at(3)
10495 +#define S7_a6                          tmp_at(4)
10496 +#define S7_x6                          tmp_at(5)
10497 +#define S7_x7                          tmp_at(6)
10498 +#define S7_x8                          tmp_at(7)
10499 +#define S7_x11                         tmp_at(8)
10500 +#define S7_x13                         tmp_at(9)
10501 +#define S7_x15                         tmp_at(10)
10502 +#define S7_x25                         tmp_at(11)
10503 +#define S7_x26                         tmp_at(12)
10504 +
10505 +#define S7(out1, out2, out3, out4, extra) \
10506 +       movq %mm0,S7_a1; \
10507 +       movq %mm1,%mm6; \
10508 +       extra; \
10509 +       movq %mm1,S7_a2; \
10510 +       movq %mm3,%mm7; \
10511 +       movq %mm5,S7_a6; \
10512 +       pand %mm3,%mm6; \
10513 +       movq %mm3,S7_a4; \
10514 +       pxor %mm4,%mm6; \
10515 +       pxor pnot,%mm4; \
10516 +       pand %mm6,%mm7; \
10517 +       pand %mm4,%mm3; \
10518 +       movq %mm1,%mm5; \
10519 +       pxor %mm2,%mm6; \
10520 +       pxor %mm7,%mm5; \
10521 +       movq %mm7,S7_x6; \
10522 +       por %mm1,%mm4; \
10523 +       por %mm3,%mm1; \
10524 +       pxor %mm6,%mm7; \
10525 +       movq %mm5,S7_x7; \
10526 +       pand %mm2,%mm4; \
10527 +       pand %mm2,%mm5; \
10528 +       por %mm7,%mm3; \
10529 +       movq %mm1,S7_x13; \
10530 +       pxor %mm5,%mm0; \
10531 +       por S7_a6,%mm0; \
10532 +       pxor %mm4,%mm1; \
10533 +       movq %mm4,S7_x15; \
10534 +       pxor %mm6,%mm0; \
10535 +       movq %mm5,S7_x8; \
10536 +       movq %mm3,%mm4; \
10537 +       movq S7_a6,%mm6; \
10538 +       movq %mm0,%mm5; \
10539 +       pxor S7_x6,%mm5; \
10540 +       por %mm6,%mm4; \
10541 +       movq %mm7,S7_x25; \
10542 +       por %mm6,%mm5; \
10543 +       movq S7_a1,%mm7; \
10544 +       pxor %mm1,%mm5; \
10545 +       movq %mm3,S7_x26; \
10546 +       pand %mm5,%mm7; \
10547 +       movq %mm0,S7_x11; \
10548 +       pxor %mm0,%mm7; \
10549 +       movq S7_a4,%mm3; \
10550 +       movq %mm7,%mm0; \
10551 +       por S7_a2,%mm0; \
10552 +       pand %mm3,%mm1; \
10553 +       pand S7_x13,%mm3; \
10554 +       por S7_x7,%mm2; \
10555 +       pxor S7_x6,%mm0; \
10556 +       pxor %mm3,%mm2; \
10557 +       movq S7_a2,%mm3; \
10558 +       movq %mm0,%mm6; \
10559 +       pxor pnot,%mm3; \
10560 +       pxor S7_x15,%mm6; \
10561 +       por %mm3,%mm1; \
10562 +       pand S7_x26,%mm0; \
10563 +       pxor %mm6,%mm4; \
10564 +       pand S7_a6,%mm0; \
10565 +       por %mm3,%mm6; \
10566 +       por S7_a6,%mm6; \
10567 +       pand %mm5,%mm3; \
10568 +       pand S7_a6,%mm1; \
10569 +       pxor %mm3,%mm0; \
10570 +       por S7_a1,%mm0; \
10571 +       pxor %mm6,%mm2; \
10572 +       pxor S7_x11,%mm1; \
10573 +       pxor %mm4,%mm0; \
10574 +       movq S7_a1,%mm4; \
10575 +       pxor %mm2,%mm5; \
10576 +       movq S7_a4,%mm6; \
10577 +       por %mm2,%mm4; \
10578 +       pxor S7_x25,%mm6; \
10579 +       pxor %mm4,%mm1; \
10580 +       movq S7_a6,%mm4; \
10581 +       pand %mm1,%mm6; \
10582 +       movq S7_x6,%mm3; \
10583 +       pand %mm4,%mm6; \
10584 +       pxor S7_x15,%mm3; \
10585 +       pxor %mm5,%mm6; \
10586 +       pxor S7_x8,%mm2; \
10587 +       por %mm4,%mm3; \
10588 +       por S7_a1,%mm6; \
10589 +       pxor %mm2,%mm3; \
10590 +       pxor out1,%mm7; \
10591 +       pxor %mm6,%mm3; \
10592 +       pxor out2,%mm1; \
10593 +       movq %mm7,out1; \
10594 +       pxor out3,%mm3; \
10595 +       movq %mm1,out2; \
10596 +       pxor out4,%mm0; \
10597 +       movq %mm3,out3; \
10598 +       movq %mm0,out4
10599 +
10600 +#define S8_out1                                %mm6
10601 +#define S8_out2                                %mm2
10602 +#define S8_out3                                %mm5
10603 +#define S8_out4                                %mm1
10604 +
10605 +#define S8_a1                          tmp_at(1)
10606 +#define S8_a2                          tmp_at(2)
10607 +#define S8_a4                          tmp_at(3)
10608 +#define S8_a5                          tmp_at(4)
10609 +#define S8_a6                          tmp_at(5)
10610 +#define S8_x14                         tmp_at(6)
10611 +#define S8_x22                         tmp_at(7)
10612 +#define S8_x33                         tmp_at(8)
10613 +
10614 +#define S8(out1, out2, out3, out4, extra) \
10615 +       movq %mm0,S8_a1; \
10616 +       extra; \
10617 +       movq %mm2,%mm6; \
10618 +       pxor pnot,%mm0; \
10619 +       movq %mm2,%mm7; \
10620 +       movq %mm3,S8_a4; \
10621 +       por %mm0,%mm7; \
10622 +       pxor pnot,%mm3; \
10623 +       pxor %mm0,%mm6; \
10624 +       movq %mm5,S8_a6; \
10625 +       movq %mm4,%mm5; \
10626 +       movq %mm1,S8_a2; \
10627 +       movq %mm7,%mm1; \
10628 +       movq %mm4,S8_a5; \
10629 +       pxor %mm3,%mm7; \
10630 +       por %mm6,%mm5; \
10631 +       por %mm7,%mm0; \
10632 +       pand %mm4,%mm1; \
10633 +       pandn %mm0,%mm2; \
10634 +       por %mm7,%mm4; \
10635 +       pxor %mm1,%mm2; \
10636 +       movq %mm5,S8_x22; \
10637 +       pand %mm3,%mm5; \
10638 +       por S8_a2,%mm2; \
10639 +       pxor %mm4,%mm7; \
10640 +       pxor %mm0,%mm3; \
10641 +       movq %mm4,%mm1; \
10642 +       pxor S8_x22,%mm7; \
10643 +       pxor %mm3,%mm1; \
10644 +       pxor %mm6,%mm4; \
10645 +       pxor %mm5,%mm2; \
10646 +       pxor S8_a1,%mm5; \
10647 +       pand %mm3,%mm6; \
10648 +       movq %mm1,S8_x14; \
10649 +       pand %mm4,%mm5; \
10650 +       movq %mm7,S8_x33; \
10651 +       movq %mm0,%mm1; \
10652 +       pand S8_a5,%mm3; \
10653 +       movq %mm0,%mm7; \
10654 +       pand S8_a5,%mm1; \
10655 +       pxor %mm3,%mm7; \
10656 +       pand S8_a2,%mm7; \
10657 +       pxor %mm1,%mm6; \
10658 +       movq S8_a6,%mm1; \
10659 +       pxor %mm4,%mm7; \
10660 +       por S8_a2,%mm6; \
10661 +       pandn %mm0,%mm4; \
10662 +       pxor S8_x14,%mm6; \
10663 +       pand %mm2,%mm1; \
10664 +       pxor S8_a1,%mm3; \
10665 +       pxor %mm6,%mm2; \
10666 +       por S8_a6,%mm6; \
10667 +       pxor %mm7,%mm1; \
10668 +       pxor S8_x22,%mm3; \
10669 +       pxor %mm7,%mm6; \
10670 +       por S8_a2,%mm4; \
10671 +       pand S8_a2,%mm5; \
10672 +       pxor %mm4,%mm3; \
10673 +       movq S8_a1,%mm4; \
10674 +       pand S8_x33,%mm4; \
10675 +       por S8_a4,%mm7; \
10676 +       pxor %mm4,%mm0; \
10677 +       pand S8_a2,%mm7; \
10678 +       pxor %mm0,%mm5; \
10679 +       movq S8_a6,%mm4; \
10680 +       por %mm0,%mm2; \
10681 +       pxor S8_x33,%mm7; \
10682 +       por %mm4,%mm5; \
10683 +       pxor out1,%mm6; \
10684 +       pand %mm4,%mm2; \
10685 +       pxor out4,%mm1; \
10686 +       pxor %mm7,%mm5; \
10687 +       pxor %mm3,%mm2; \
10688 +       pxor out3,%mm5; \
10689 +       movq %mm6,out1; \
10690 +       pxor out2,%mm2; \
10691 +       movq %mm1,out4; \
10692 +       movq %mm5,out3; \
10693 +       movq %mm2,out2
10694 +
10695 +#define zero                           %mm0
10696 +
10697 +#define DES_bs_clear_block_8(i) \
10698 +       movq zero,B(i); \
10699 +       movq zero,B(i + 1); \
10700 +       movq zero,B(i + 2); \
10701 +       movq zero,B(i + 3); \
10702 +       movq zero,B(i + 4); \
10703 +       movq zero,B(i + 5); \
10704 +       movq zero,B(i + 6); \
10705 +       movq zero,B(i + 7)
10706 +
10707 +#define DES_bs_clear_block \
10708 +       DES_bs_clear_block_8(0); \
10709 +       DES_bs_clear_block_8(8); \
10710 +       DES_bs_clear_block_8(16); \
10711 +       DES_bs_clear_block_8(24); \
10712 +       DES_bs_clear_block_8(32); \
10713 +       DES_bs_clear_block_8(40); \
10714 +       DES_bs_clear_block_8(48); \
10715 +       DES_bs_clear_block_8(56)
10716 +
10717 +#define k_ptr                          %edx
10718 +#define K(i)                           (i)*8(k_ptr)
10719 +#define k(i)                           (i)*4(k_ptr)
10720 +
10721 +#define a6_xor_ptr                     %esi
10722 +#define a6_p                           pxor (a6_xor_ptr),a6
10723 +#define a6_v(i)                                pxor K(i),a6
10724 +
10725 +#define tmp1                           %ecx
10726 +#define tmp2                           a6_xor_ptr
10727 +
10728 +#define xor_E(i) \
10729 +       movl E(i),tmp1; \
10730 +       movq K(i),a1; \
10731 +       movl E(i + 1),tmp2; \
10732 +       movq K(i + 1),a2; \
10733 +       pxor (tmp1),a1; \
10734 +       pxor (tmp2),a2; \
10735 +       movl E(i + 2),tmp1; \
10736 +       movq K(i + 2),a3; \
10737 +       movl E(i + 3),tmp2; \
10738 +       movq K(i + 3),a4; \
10739 +       pxor (tmp1),a3; \
10740 +       pxor (tmp2),a4; \
10741 +       movl E(i + 4),tmp1; \
10742 +       movq K(i + 4),a5; \
10743 +       movl E(i + 5),a6_xor_ptr; \
10744 +       movq K(i + 5),a6; \
10745 +       pxor (tmp1),a5
10746 +
10747 +#define xor_B(b1, k1, b2, k2, b3, k3, b4, k4, b5, k5, b6) \
10748 +       movq B(b1),a1; \
10749 +       movq B(b2),a2; \
10750 +       pxor K(k1),a1; \
10751 +       movq B(b3),a3; \
10752 +       pxor K(k2),a2; \
10753 +       movq B(b4),a4; \
10754 +       pxor K(k3),a3; \
10755 +       movq B(b5),a5; \
10756 +       pxor K(k4),a4; \
10757 +       movq B(b6),a6; \
10758 +       pxor K(k5),a5
10759 +
10760 +#define xor_B_KS_p(b1, k1, b2, k2, b3, k3, b4, k4, b5, k5, b6, k6) \
10761 +       movl k(k1),tmp1; \
10762 +       movl k(k2),tmp2; \
10763 +       movq B(b1),a1; \
10764 +       movq B(b2),a2; \
10765 +       pxor (tmp1),a1; \
10766 +       movl k(k3),tmp1; \
10767 +       pxor (tmp2),a2; \
10768 +       movl k(k4),tmp2; \
10769 +       movq B(b3),a3; \
10770 +       movq B(b4),a4; \
10771 +       pxor (tmp1),a3; \
10772 +       movl k(k5),tmp1; \
10773 +       pxor (tmp2),a4; \
10774 +       movq B(b5),a5; \
10775 +       movl k(k6),a6_xor_ptr; \
10776 +       movq B(b6),a6; \
10777 +       pxor (tmp1),a5
10778 +
10779 +.data
10780 +
10781 +DO_ALIGN(3)
10782 +mm_ones:
10783 +.quad -1
10784 +
10785 +.text
10786 +
10787 +DO_ALIGN(5)
10788 +.globl DES_bs_init_asm
10789 +DES_bs_init_asm:
10790 +       movq mm_ones,%mm0
10791 +       movq %mm0,pnot
10792 +       ret
10793 +
10794 +#define rounds_and_swapped             %ebp
10795 +#define iterations                     %eax
10796 +
10797 +DO_ALIGN(5)
10798 +.globl DES_bs_crypt
10799 +DES_bs_crypt:
10800 +       movl 4(%esp),iterations
10801 +       pxor zero,zero
10802 +       pushl %ebp
10803 +       pushl %esi
10804 +       movl $DES_bs_all_KS_v,k_ptr
10805 +       DES_bs_clear_block
10806 +       movl $8,rounds_and_swapped
10807 +DES_bs_crypt_start:
10808 +       xor_E(0)
10809 +       S1(B(40), B(48), B(54), B(62), a6_p)
10810 +       xor_E(6)
10811 +       S2(B(44), B(59), B(33), B(49), a6_p)
10812 +       xor_E(12)
10813 +       S3(B(55), B(47), B(61), B(37), a6_p)
10814 +       xor_E(18)
10815 +       S4(B(57), B(51), B(41), B(32), a6_p)
10816 +       xor_E(24)
10817 +       S5(B(39), B(45), B(56), B(34), a6_p)
10818 +       xor_E(30)
10819 +       S6(B(35), B(60), B(42), B(50), a6_p)
10820 +       xor_E(36)
10821 +       S7(B(63), B(43), B(53), B(38), a6_p)
10822 +       xor_E(42)
10823 +       S8(B(36), B(58), B(46), B(52), a6_p)
10824 +       cmpl $0x100,rounds_and_swapped
10825 +       je DES_bs_crypt_next
10826 +DES_bs_crypt_swap:
10827 +       xor_E(48)
10828 +       S1(B(8), B(16), B(22), B(30), a6_p)
10829 +       xor_E(54)
10830 +       S2(B(12), B(27), B(1), B(17), a6_p)
10831 +       xor_E(60)
10832 +       S3(B(23), B(15), B(29), B(5), a6_p)
10833 +       xor_E(66)
10834 +       S4(B(25), B(19), B(9), B(0), a6_p)
10835 +       xor_E(72)
10836 +       S5(B(7), B(13), B(24), B(2), a6_p)
10837 +       xor_E(78)
10838 +       S6(B(3), B(28), B(10), B(18), a6_p)
10839 +       xor_E(84)
10840 +       S7(B(31), B(11), B(21), B(6), a6_p)
10841 +       xor_E(90)
10842 +       addl $96*8,k_ptr
10843 +       S8(B(4), B(26), B(14), B(20), a6_p)
10844 +       decl rounds_and_swapped
10845 +       jnz DES_bs_crypt_start
10846 +       subl $0x300*8+48*8,k_ptr
10847 +       movl $0x108,rounds_and_swapped
10848 +       decl iterations
10849 +       jnz DES_bs_crypt_swap
10850 +       popl %esi
10851 +       popl %ebp
10852 +#ifdef EMMS
10853 +       emms
10854 +#endif
10855 +       ret
10856 +DES_bs_crypt_next:
10857 +       subl $0x300*8-48*8,k_ptr
10858 +       movl $8,rounds_and_swapped
10859 +       decl iterations
10860 +       jnz DES_bs_crypt_start
10861 +       popl %esi
10862 +       popl %ebp
10863 +#ifdef EMMS
10864 +       emms
10865 +#endif
10866 +       ret
10867 +
10868 +DO_ALIGN(5)
10869 +.globl DES_bs_crypt_25
10870 +DES_bs_crypt_25:
10871 +       pxor zero,zero
10872 +       pushl %ebp
10873 +       pushl %esi
10874 +       movl $DES_bs_all_KS_v,k_ptr
10875 +       DES_bs_clear_block
10876 +       movl $8,rounds_and_swapped
10877 +       movl $25,iterations
10878 +DES_bs_crypt_25_start:
10879 +       xor_E(0)
10880 +       S1(B(40), B(48), B(54), B(62), a6_p)
10881 +       xor_E(6)
10882 +       S2(B(44), B(59), B(33), B(49), a6_p)
10883 +       xor_B(7, 12, 8, 13, 9, 14, 10, 15, 11, 16, 12)
10884 +       S3(B(55), B(47), B(61), B(37), a6_v(17))
10885 +       xor_B(11, 18, 12, 19, 13, 20, 14, 21, 15, 22, 16)
10886 +       S4(B(57), B(51), B(41), B(32), a6_v(23))
10887 +       xor_E(24)
10888 +       S5(B(39), B(45), B(56), B(34), a6_p)
10889 +       xor_E(30)
10890 +       S6(B(35), B(60), B(42), B(50), a6_p)
10891 +       xor_B(23, 36, 24, 37, 25, 38, 26, 39, 27, 40, 28)
10892 +       S7(B(63), B(43), B(53), B(38), a6_v(41))
10893 +       xor_B(27, 42, 28, 43, 29, 44, 30, 45, 31, 46, 0)
10894 +       S8(B(36), B(58), B(46), B(52), a6_v(47))
10895 +       cmpl $0x100,rounds_and_swapped
10896 +       je DES_bs_crypt_25_next
10897 +DES_bs_crypt_25_swap:
10898 +       xor_E(48)
10899 +       S1(B(8), B(16), B(22), B(30), a6_p)
10900 +       xor_E(54)
10901 +       S2(B(12), B(27), B(1), B(17), a6_p)
10902 +       xor_B(39, 60, 40, 61, 41, 62, 42, 63, 43, 64, 44)
10903 +       S3(B(23), B(15), B(29), B(5), a6_v(65))
10904 +       xor_B(43, 66, 44, 67, 45, 68, 46, 69, 47, 70, 48)
10905 +       S4(B(25), B(19), B(9), B(0), a6_v(71))
10906 +       xor_E(72)
10907 +       S5(B(7), B(13), B(24), B(2), a6_p)
10908 +       xor_E(78)
10909 +       S6(B(3), B(28), B(10), B(18), a6_p)
10910 +       xor_B(55, 84, 56, 85, 57, 86, 58, 87, 59, 88, 60)
10911 +       S7(B(31), B(11), B(21), B(6), a6_v(89))
10912 +       xor_B(59, 90, 60, 91, 61, 92, 62, 93, 63, 94, 32)
10913 +       S8(B(4), B(26), B(14), B(20), a6_v(95))
10914 +       addl $96*8,k_ptr
10915 +       decl rounds_and_swapped
10916 +       jnz DES_bs_crypt_25_start
10917 +       subl $0x300*8+48*8,k_ptr
10918 +       movl $0x108,rounds_and_swapped
10919 +       decl iterations
10920 +       jnz DES_bs_crypt_25_swap
10921 +       popl %esi
10922 +       popl %ebp
10923 +#ifdef EMMS
10924 +       emms
10925 +#endif
10926 +       ret
10927 +DES_bs_crypt_25_next:
10928 +       subl $0x300*8-48*8,k_ptr
10929 +       movl $8,rounds_and_swapped
10930 +       decl iterations
10931 +       jmp DES_bs_crypt_25_start
10932 +
10933 +#define ones                           %mm1
10934 +
10935 +#define rounds                         %eax
10936 +
10937 +DO_ALIGN(5)
10938 +.globl DES_bs_crypt_LM
10939 +DES_bs_crypt_LM:
10940 +       pxor zero,zero
10941 +       pushl %esi
10942 +       movq pnot,ones
10943 +       movl $DES_bs_all_KS_p,k_ptr
10944 +       movq zero,B(0)
10945 +       movq zero,B(1)
10946 +       movq zero,B(2)
10947 +       movq zero,B(3)
10948 +       movq zero,B(4)
10949 +       movq zero,B(5)
10950 +       movq zero,B(6)
10951 +       movq zero,B(7)
10952 +       movq ones,B(8)
10953 +       movq ones,B(9)
10954 +       movq ones,B(10)
10955 +       movq zero,B(11)
10956 +       movq ones,B(12)
10957 +       movq zero,B(13)
10958 +       movq zero,B(14)
10959 +       movq zero,B(15)
10960 +       movq zero,B(16)
10961 +       movq zero,B(17)
10962 +       movq zero,B(18)
10963 +       movq zero,B(19)
10964 +       movq zero,B(20)
10965 +       movq zero,B(21)
10966 +       movq zero,B(22)
10967 +       movq ones,B(23)
10968 +       movq zero,B(24)
10969 +       movq zero,B(25)
10970 +       movq ones,B(26)
10971 +       movq zero,B(27)
10972 +       movq zero,B(28)
10973 +       movq ones,B(29)
10974 +       movq ones,B(30)
10975 +       movq ones,B(31)
10976 +       movq zero,B(32)
10977 +       movq zero,B(33)
10978 +       movq zero,B(34)
10979 +       movq ones,B(35)
10980 +       movq zero,B(36)
10981 +       movq ones,B(37)
10982 +       movq ones,B(38)
10983 +       movq ones,B(39)
10984 +       movq zero,B(40)
10985 +       movq zero,B(41)
10986 +       movq zero,B(42)
10987 +       movq zero,B(43)
10988 +       movq zero,B(44)
10989 +       movq ones,B(45)
10990 +       movq zero,B(46)
10991 +       movq zero,B(47)
10992 +       movq ones,B(48)
10993 +       movq ones,B(49)
10994 +       movq zero,B(50)
10995 +       movq zero,B(51)
10996 +       movq zero,B(52)
10997 +       movq zero,B(53)
10998 +       movq ones,B(54)
10999 +       movq zero,B(55)
11000 +       movq ones,B(56)
11001 +       movq zero,B(57)
11002 +       movq ones,B(58)
11003 +       movq zero,B(59)
11004 +       movq ones,B(60)
11005 +       movq ones,B(61)
11006 +       movq ones,B(62)
11007 +       movq ones,B(63)
11008 +       movl $8,rounds
11009 +DES_bs_crypt_LM_loop:
11010 +       xor_B_KS_p(31, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5)
11011 +       S1(B(40), B(48), B(54), B(62), a6_p)
11012 +       xor_B_KS_p(3, 6, 4, 7, 5, 8, 6, 9, 7, 10, 8, 11)
11013 +       S2(B(44), B(59), B(33), B(49), a6_p)
11014 +       xor_B_KS_p(7, 12, 8, 13, 9, 14, 10, 15, 11, 16, 12, 17)
11015 +       S3(B(55), B(47), B(61), B(37), a6_p)
11016 +       xor_B_KS_p(11, 18, 12, 19, 13, 20, 14, 21, 15, 22, 16, 23)
11017 +       S4(B(57), B(51), B(41), B(32), a6_p)
11018 +       xor_B_KS_p(15, 24, 16, 25, 17, 26, 18, 27, 19, 28, 20, 29)
11019 +       S5(B(39), B(45), B(56), B(34), a6_p)
11020 +       xor_B_KS_p(19, 30, 20, 31, 21, 32, 22, 33, 23, 34, 24, 35)
11021 +       S6(B(35), B(60), B(42), B(50), a6_p)
11022 +       xor_B_KS_p(23, 36, 24, 37, 25, 38, 26, 39, 27, 40, 28, 41)
11023 +       S7(B(63), B(43), B(53), B(38), a6_p)
11024 +       xor_B_KS_p(27, 42, 28, 43, 29, 44, 30, 45, 31, 46, 0, 47)
11025 +       S8(B(36), B(58), B(46), B(52), a6_p)
11026 +       xor_B_KS_p(63, 48, 32, 49, 33, 50, 34, 51, 35, 52, 36, 53)
11027 +       S1(B(8), B(16), B(22), B(30), a6_p)
11028 +       xor_B_KS_p(35, 54, 36, 55, 37, 56, 38, 57, 39, 58, 40, 59)
11029 +       S2(B(12), B(27), B(1), B(17), a6_p)
11030 +       xor_B_KS_p(39, 60, 40, 61, 41, 62, 42, 63, 43, 64, 44, 65)
11031 +       S3(B(23), B(15), B(29), B(5), a6_p)
11032 +       xor_B_KS_p(43, 66, 44, 67, 45, 68, 46, 69, 47, 70, 48, 71)
11033 +       S4(B(25), B(19), B(9), B(0), a6_p)
11034 +       xor_B_KS_p(47, 72, 48, 73, 49, 74, 50, 75, 51, 76, 52, 77)
11035 +       S5(B(7), B(13), B(24), B(2), a6_p)
11036 +       xor_B_KS_p(51, 78, 52, 79, 53, 80, 54, 81, 55, 82, 56, 83)
11037 +       S6(B(3), B(28), B(10), B(18), a6_p)
11038 +       xor_B_KS_p(55, 84, 56, 85, 57, 86, 58, 87, 59, 88, 60, 89)
11039 +       S7(B(31), B(11), B(21), B(6), a6_p)
11040 +       xor_B_KS_p(59, 90, 60, 91, 61, 92, 62, 93, 63, 94, 32, 95)
11041 +       addl $96*4,k_ptr
11042 +       S8(B(4), B(26), B(14), B(20), a6_p)
11043 +       decl rounds
11044 +       jnz DES_bs_crypt_LM_loop
11045 +       popl %esi
11046 +#ifdef EMMS
11047 +       emms
11048 +#endif
11049 +       ret
11050 diff -ruN john-1.6/src/x86.S john-1.6.34/src/x86.S
11051 --- john-1.6/src/x86.S  1998-12-03 01:29:50.000000000 +0100
11052 +++ john-1.6.34/src/x86.S       2002-06-22 10:51:30.000000000 +0200
11053 @@ -1,6 +1,6 @@
11054  /*
11055   * This file is part of John the Ripper password cracker,
11056 - * Copyright (c) 1996-98 by Solar Designer
11057 + * Copyright (c) 1996-2001 by Solar Designer
11058   */
11059  
11060  /*
11061 @@ -35,7 +35,7 @@
11062  #ifndef ALIGN_FIX
11063  #ifdef ALIGN_LOG
11064  #define DO_ALIGN(log)                  .align (log)
11065 -#elif defined(SOLARIS)
11066 +#elif defined(DUMBAS)
11067  #define DO_ALIGN(log)                  .align 1 << log
11068  #else
11069  #define DO_ALIGN(log)                  .align (1 << (log))
11070 @@ -52,12 +52,15 @@
11071   * DES stuff.
11072   *
11073   * Included are versions for:
11074 - * 1. MMX (Pentium MMX, Pentium II, some clones);
11075 + * 1. MMX (Pentium MMX and newer Intel x86 CPUs, some clones);
11076   * 2. Intel Pentium without MMX;
11077   * 3. The rest (good for Pentium Pro, 486, clones).
11078   *
11079   * MMX has to be enabled at compile time (via DES_X2 in arch.h), while #2
11080   * or #3 is chosen based on CPUID info at runtime.
11081 + *
11082 + * Note: MMX code for the bitslice DES implementation is in x86-mmx.S, so
11083 + * you probably want to look in there instead.
11084   */
11085  
11086  .text
11087 @@ -498,9 +501,9 @@
11088         xorl DES_SPE_H+0x700(%edx),Rh
11089  
11090  DO_ALIGN(12)
11091 -DES_std_crypt_any:
11092 +DES_std_crypt_generic:
11093         DES_CRYPT_START
11094 -DES_loop_any:
11095 +DES_loop_generic:
11096         DES_2_ROUNDS_ANY(DES_KS_copy)
11097         DES_2_ROUNDS_ANY(DES_KS_copy+16)
11098         DES_2_ROUNDS_ANY(DES_KS_copy+32)
11099 @@ -521,7 +524,7 @@
11100         decl DES_count_tmp
11101         movl %eax,Rh
11102         movl DES_KS_copy,%eax
11103 -       jnz DES_loop_any
11104 +       jnz DES_loop_generic
11105         DES_CRYPT_END
11106  
11107  #define DES_xor1(ofs) \
11108 @@ -611,7 +614,7 @@
11109   * Weird alignments to make sure KS address's bits 5-11 never match current
11110   * instruction pointer's bits 5-11.
11111   */
11112 -#ifdef SOLARIS
11113 +#ifdef DUMBAS
11114  DO_ALIGN(12)
11115  .zero 0x1000 - 32 - 128
11116  #elif defined(__DJGPP__)
11117 @@ -629,7 +632,7 @@
11118   */
11119  .globl DES_std_crypt
11120  DES_std_crypt:
11121 -.long DES_std_crypt_any
11122 +.long DES_std_crypt_generic
11123  
11124  DES_SavedL:
11125  .long 0
11126 @@ -641,7 +644,7 @@
11127   */
11128  .globl DES_IV
11129  DES_IV:
11130 -#ifdef SOLARIS
11131 +#ifdef DUMBAS
11132  .zero 16
11133  #else
11134  .space 16
11135 @@ -657,7 +660,7 @@
11136  DO_ALIGN(5)
11137  .globl DES_KS_copy
11138  DES_KS_copy:
11139 -#ifdef SOLARIS
11140 +#ifdef DUMBAS
11141  .zero 128
11142  #else
11143  .space 128
11144 @@ -681,7 +684,7 @@
11145  
11146  .globl DES_SPE_L
11147  DES_SPE_L:
11148 -#ifdef SOLARIS
11149 +#ifdef DUMBAS
11150  .zero 0x800
11151  #else
11152  .space 0x800
11153 @@ -696,7 +699,7 @@
11154  
11155  .globl DES_SPE_H
11156  DES_SPE_H:
11157 -#ifdef SOLARIS
11158 +#ifdef DUMBAS
11159  .zero 0x800
11160  #else
11161  .space 0x800
11162 @@ -708,7 +711,7 @@
11163  
11164  .globl DES_KS_current
11165  DES_KS_current:
11166 -#ifdef SOLARIS
11167 +#ifdef DUMBAS
11168  .zero 128
11169  #else
11170  .space 128
11171 @@ -716,7 +719,7 @@
11172  
11173  .globl DES_KS_table
11174  DES_KS_table:
11175 -#ifdef SOLARIS
11176 +#ifdef DUMBAS
11177  .zero 0x20000
11178  #else
11179  .space (8 * 128 * 16 * 8)
11180 @@ -756,7 +759,7 @@
11181  #undef tmp2
11182  #define tmp1                           %eax
11183  #define tmp2                           %ecx
11184 -#ifdef SOLARIS
11185 +#ifdef DUMBAS
11186  #define x(i)                           i+i+i+i(%ebp)
11187  #else
11188  #define x(i)                           4*i(%ebp)
11189 @@ -813,22 +816,43 @@
11190  .globl MD5_body
11191  MD5_body:
11192         pushl %ebp
11193 +       movl 8(%esp),%ebp
11194         pushl %ebx
11195         pushl %esi
11196         pushl %edi
11197 -       movl 20(%esp),%ebp
11198  /* Round 1 */
11199 -       movl $0xd76aa477,a
11200 -       movl $Cb,b
11201 -       addl x(0),a
11202 -       movl $Cc,c
11203 +       movl x(0),a
11204 +       movl x(1),d
11205 +       addl $0xd76aa477,a
11206         roll $S11,a
11207 -       movl $Cd,d
11208 -       addl b,a
11209 -       movl $0x77777777,tmp1
11210 -       FF (d, a, b, c, x( 1), S12, 0xe8c7b756) /* 2 */
11211 -       FF (c, d, a, b, x( 2), S13, 0x242070db) /* 3 */
11212 -       FF (b, c, d, a, x( 3), S14, 0xc1bdceee) /* 4 */
11213 +       addl $0xf8fa0bcc,d
11214 +       addl $Cb,a
11215 +       movl x(2),c
11216 +       movl a,tmp1
11217 +       movl a,tmp2
11218 +       andl $0x77777777,tmp1
11219 +       xorl $Cb,tmp2
11220 +       xorl $Cc,tmp1
11221 +       addl $0xbcdb4dd9,c
11222 +       addl tmp1,d
11223 +       roll $S12,d
11224 +       addl a,d
11225 +       andl d,tmp2
11226 +       xorl $Cb,tmp2
11227 +       addl tmp2,c
11228 +       movl d,tmp1
11229 +       roll $S13,c
11230 +       xorl a,tmp1
11231 +       addl d,c
11232 +       andl c,tmp1
11233 +       movl x(3),b
11234 +       xorl a,tmp1
11235 +       addl $0xb18b7a77,b
11236 +       addl tmp1,b
11237 +       movl c,tmp1
11238 +       roll $S14,b
11239 +       xorl d,tmp1
11240 +       addl c,b
11241         FF (a, b, c, d, x( 4), S11, 0xf57c0faf) /* 5 */
11242         FF (d, a, b, c, x( 5), S12, 0x4787c62a) /* 6 */
11243         FF (c, d, a, b, x( 6), S13, 0xa8304613) /* 7 */
11244 @@ -953,118 +977,252 @@
11245   * Blowfish stuff.
11246   */
11247  
11248 +#ifdef DUMBAS
11249 +#define P(N)                           BF_current+0x1000+N+N+N+N
11250 +#else
11251 +#define P(N)                           BF_current+0x1000+4*N
11252 +#endif
11253 +
11254 +/*
11255 + * Intel Pentium optimized version, extra operations are used to avoid
11256 + * imperfect pairing.  Also used on the Pentium 4.
11257 + */
11258 +
11259  #undef L
11260  #undef R
11261  #undef tmp1
11262  #undef tmp2
11263  #define L                              %esi
11264  #define R                              %edi
11265 -#define tmp1                           %ecx
11266 -#define tmp1_lo                                %cl
11267 -#define tmp2                           %ebp
11268 -
11269 -#ifdef SOLARIS
11270 -#define P(N)                           BF_current+0x1000+N+N+N+N
11271 -#else
11272 -#define P(N)                           BF_current+0x1000+4*N
11273 -#endif
11274 +#define tmp1                           %eax
11275 +#define tmp1_lo                                %al
11276 +#define tmp2                           %ecx
11277 +#define tmp2_hi                                %ch
11278 +#define tmp3                           %edx
11279 +#define tmp3_lo                                %dl
11280 +#define tmp4                           %ebx
11281 +#define tmp4_hi                                %bh
11282 +#define tmp5                           %ebp
11283  
11284  .text
11285  
11286 -#define BF_ROUND(L, R, N) \
11287 -       xorl L,%eax; \
11288 +#define BF_ROUND_P5(L, R, N) \
11289 +       xorl L,tmp2; \
11290         xorl tmp1,tmp1; \
11291 -       movl %eax,L; \
11292 -       shrl $16,%eax; \
11293 -       movl L,%edx; \
11294 -       movb %ah,tmp1_lo; \
11295 -       andl $0xFF,%eax; \
11296 -       movb %dh,%bl; \
11297 -       andl $0xFF,%edx; \
11298 +       movl tmp2,L; \
11299 +       shrl $16,tmp2; \
11300 +       movl L,tmp4; \
11301 +       movb tmp2_hi,tmp1_lo; \
11302 +       andl $0xFF,tmp2; \
11303 +       movb tmp4_hi,tmp3_lo; \
11304 +       andl $0xFF,tmp4; \
11305         movl BF_current(,tmp1,4),tmp1; \
11306 -       movl BF_current+0x400(,%eax,4),tmp2; \
11307 -       addl tmp2,tmp1; \
11308 -       movl BF_current+0x800(,%ebx,4),tmp2; \
11309 -       xorl tmp2,tmp1; \
11310 -       movl BF_current+0xC00(,%edx,4),tmp2; \
11311 -       addl tmp1,tmp2; \
11312 -       movl P(N)+4,%eax; \
11313 -       xorl tmp2,R
11314 -
11315 -#define BF_ENCRYPT_START \
11316 -       BF_ROUND(L, R, 0); \
11317 -       BF_ROUND(R, L, 1); \
11318 -       BF_ROUND(L, R, 2); \
11319 -       BF_ROUND(R, L, 3); \
11320 -       BF_ROUND(L, R, 4); \
11321 -       BF_ROUND(R, L, 5); \
11322 -       BF_ROUND(L, R, 6); \
11323 -       BF_ROUND(R, L, 7); \
11324 -       BF_ROUND(L, R, 8); \
11325 -       BF_ROUND(R, L, 9); \
11326 -       BF_ROUND(L, R, 10); \
11327 -       BF_ROUND(R, L, 11); \
11328 -       BF_ROUND(L, R, 12); \
11329 -       BF_ROUND(R, L, 13); \
11330 -       BF_ROUND(L, R, 14); \
11331 -       BF_ROUND(R, L, 15); \
11332 -       movl BF_ptr,tmp2; \
11333 -       xorl L,%eax; \
11334 +       movl BF_current+0x400(,tmp2,4),tmp5; \
11335 +       addl tmp5,tmp1; \
11336 +       movl BF_current+0x800(,tmp3,4),tmp5; \
11337 +       xorl tmp5,tmp1; \
11338 +       movl BF_current+0xC00(,tmp4,4),tmp5; \
11339 +       addl tmp1,tmp5; \
11340 +       movl P(N)+4,tmp2; \
11341 +       xorl tmp5,R
11342 +
11343 +#define BF_ENCRYPT_START_P5 \
11344 +       BF_ROUND_P5(L, R, 0); \
11345 +       BF_ROUND_P5(R, L, 1); \
11346 +       BF_ROUND_P5(L, R, 2); \
11347 +       BF_ROUND_P5(R, L, 3); \
11348 +       BF_ROUND_P5(L, R, 4); \
11349 +       BF_ROUND_P5(R, L, 5); \
11350 +       BF_ROUND_P5(L, R, 6); \
11351 +       BF_ROUND_P5(R, L, 7); \
11352 +       BF_ROUND_P5(L, R, 8); \
11353 +       BF_ROUND_P5(R, L, 9); \
11354 +       BF_ROUND_P5(L, R, 10); \
11355 +       BF_ROUND_P5(R, L, 11); \
11356 +       BF_ROUND_P5(L, R, 12); \
11357 +       BF_ROUND_P5(R, L, 13); \
11358 +       BF_ROUND_P5(L, R, 14); \
11359 +       BF_ROUND_P5(R, L, 15); \
11360 +       movl BF_ptr,tmp5; \
11361 +       xorl L,tmp2; \
11362         movl P(17),L
11363  
11364 -#define BF_ENCRYPT_END \
11365 +#define BF_ENCRYPT_END_P5 \
11366         xorl R,L; \
11367 -       movl %eax,R
11368 +       movl tmp2,R
11369  
11370  DO_ALIGN(12)
11371 -.globl BF_body
11372 -BF_body:
11373 +.globl BF_body_P5
11374 +BF_body_P5:
11375         pushl %ebp
11376         pushl %ebx
11377         pushl %esi
11378         pushl %edi
11379         xorl L,L
11380         xorl R,R
11381 -       movl P(0),%eax
11382 -       xorl %ebx,%ebx
11383 +       movl P(0),tmp2
11384 +       xorl tmp3,tmp3
11385         movl $P(0),BF_ptr
11386 -BF_loop_P:
11387 +BF_loop_P_P5:
11388 +       BF_ENCRYPT_START_P5
11389 +       addl $8,tmp5
11390 +       BF_ENCRYPT_END_P5
11391 +       movl tmp5,BF_ptr
11392 +       cmpl $P(18),tmp5
11393 +       movl L,-8(tmp5)
11394 +       movl R,-4(tmp5)
11395 +       movl P(0),tmp2
11396 +       jb BF_loop_P_P5
11397 +#ifndef DONT_AVOID_PENTIUMPRO_FAMILY_PARTIAL_REGISTER_STALLS
11398 +       xorl tmp3,tmp3
11399 +#endif
11400 +       movl $BF_current,BF_ptr
11401 +BF_loop_S_P5:
11402 +       BF_ENCRYPT_START_P5
11403 +       BF_ENCRYPT_END_P5
11404 +       movl P(0),tmp2
11405 +       movl L,(tmp5)
11406 +       movl R,4(tmp5)
11407 +       BF_ENCRYPT_START_P5
11408 +       BF_ENCRYPT_END_P5
11409 +       movl P(0),tmp2
11410 +       movl L,8(tmp5)
11411 +       movl R,12(tmp5)
11412 +       BF_ENCRYPT_START_P5
11413 +       BF_ENCRYPT_END_P5
11414 +       movl P(0),tmp2
11415 +       movl L,16(tmp5)
11416 +       movl R,20(tmp5)
11417 +       BF_ENCRYPT_START_P5
11418 +       addl $32,tmp5
11419 +       BF_ENCRYPT_END_P5
11420 +       movl tmp5,BF_ptr
11421 +       cmpl $BF_current+0x1000,tmp5
11422 +       movl P(0),tmp2
11423 +       movl L,-8(tmp5)
11424 +       movl R,-4(tmp5)
11425 +       jb BF_loop_S_P5
11426 +       popl %edi
11427 +       popl %esi
11428 +       popl %ebx
11429 +       popl %ebp
11430 +       ret
11431 +
11432 +/*
11433 + * Generic x86 version.
11434 + */
11435 +
11436 +#undef L
11437 +#undef R
11438 +#undef tmp1
11439 +#undef tmp1_lo
11440 +#undef tmp2
11441 +#undef tmp2_hi
11442 +#undef tmp3
11443 +#undef tmp3_lo
11444 +#undef tmp4
11445 +#undef tmp4_hi
11446 +#undef tmp5
11447 +#define L                              %edx
11448 +#define L_lo                           %dl
11449 +#define L_hi                           %dh
11450 +#define R                              %ebx
11451 +#define R_lo                           %bl
11452 +#define R_hi                           %bh
11453 +#define tmp1                           %eax
11454 +#define tmp2                           %ecx
11455 +#define tmp2_hi                                %ch
11456 +#define tmp3                           %esi
11457 +#define tmp4                           %edi
11458 +#define ptr                            %ebp
11459 +
11460 +#define BF_ROUND_START(L, L_lo, L_hi) \
11461 +       shldl $16,L,tmp2; \
11462 +       movzbl L_hi,tmp3; \
11463 +       movzbl tmp2_hi,tmp1; \
11464 +       andl $0xFF,tmp2; \
11465 +       movzbl L_lo,tmp4; \
11466 +       movl BF_current(,tmp1,4),tmp1; \
11467 +       addl BF_current+0x400(,tmp2,4),tmp1
11468 +
11469 +#define BF_ROUND_END(R, N) \
11470 +       xorl BF_current+0x800(,tmp3,4),tmp1; \
11471 +       addl BF_current+0xC00(,tmp4,4),tmp1; \
11472 +       xorl P(N)+4,R; \
11473 +       xorl tmp1,R
11474 +
11475 +#define BF_ROUND(L, L_lo, L_hi, R, N) \
11476 +       BF_ROUND_START(L, L_lo, L_hi); \
11477 +       BF_ROUND_END(R, N)
11478 +
11479 +#define BF_ENCRYPT_START \
11480 +       xorl P(0),L; \
11481 +       BF_ROUND(L, L_lo, L_hi, R, 0); \
11482 +       BF_ROUND(R, R_lo, R_hi, L, 1); \
11483 +       BF_ROUND(L, L_lo, L_hi, R, 2); \
11484 +       BF_ROUND(R, R_lo, R_hi, L, 3); \
11485 +       BF_ROUND(L, L_lo, L_hi, R, 4); \
11486 +       BF_ROUND(R, R_lo, R_hi, L, 5); \
11487 +       BF_ROUND(L, L_lo, L_hi, R, 6); \
11488 +       BF_ROUND(R, R_lo, R_hi, L, 7); \
11489 +       BF_ROUND(L, L_lo, L_hi, R, 8); \
11490 +       BF_ROUND(R, R_lo, R_hi, L, 9); \
11491 +       BF_ROUND(L, L_lo, L_hi, R, 10); \
11492 +       BF_ROUND(R, R_lo, R_hi, L, 11); \
11493 +       BF_ROUND(L, L_lo, L_hi, R, 12); \
11494 +       BF_ROUND(R, R_lo, R_hi, L, 13); \
11495 +       BF_ROUND(L, L_lo, L_hi, R, 14); \
11496 +       BF_ROUND_START(R, R_lo, R_hi); \
11497 +       movl R,tmp2; \
11498 +       movl P(16),R; \
11499 +       xorl BF_current+0x800(,tmp3,4),tmp1; \
11500 +       xorl L,R; \
11501 +       addl BF_current+0xC00(,tmp4,4),tmp1; \
11502 +       movl P(17),L; \
11503 +       xorl tmp1,R; \
11504 +
11505 +#define BF_ENCRYPT_END \
11506 +       xorl tmp2,L
11507 +
11508 +DO_ALIGN(12)
11509 +.globl BF_body_generic
11510 +BF_body_generic:
11511 +       pushl %ebp
11512 +       pushl %ebx
11513 +       pushl %esi
11514 +       pushl %edi
11515 +       xorl L,L
11516 +       xorl R,R
11517 +       movl $P(0),ptr
11518 +BF_loop_P_generic:
11519         BF_ENCRYPT_START
11520 -       addl $8,tmp2
11521 +       addl $8,ptr
11522         BF_ENCRYPT_END
11523 -       movl tmp2,BF_ptr
11524 -       cmpl $P(18),tmp2
11525 -       movl L,-8(tmp2)
11526 -       movl R,-4(tmp2)
11527 -       movl P(0),%eax
11528 -       jb BF_loop_P
11529 -       xorl %ebx,%ebx
11530 -       movl $BF_current,BF_ptr
11531 -BF_loop_S:
11532 +       cmpl $P(18),ptr
11533 +       movl L,-8(ptr)
11534 +       movl R,-4(ptr)
11535 +       jb BF_loop_P_generic
11536 +       movl $BF_current,ptr
11537 +BF_loop_S_generic:
11538         BF_ENCRYPT_START
11539         BF_ENCRYPT_END
11540 -       movl P(0),%eax
11541 -       movl L,(tmp2)
11542 -       movl R,4(tmp2)
11543 +       movl L,(ptr)
11544 +       movl R,4(ptr)
11545         BF_ENCRYPT_START
11546         BF_ENCRYPT_END
11547 -       movl P(0),%eax
11548 -       movl L,8(tmp2)
11549 -       movl R,12(tmp2)
11550 +       movl L,8(ptr)
11551 +       movl R,12(ptr)
11552         BF_ENCRYPT_START
11553         BF_ENCRYPT_END
11554 -       movl P(0),%eax
11555 -       movl L,16(tmp2)
11556 -       movl R,20(tmp2)
11557 +       movl L,16(ptr)
11558 +       movl R,20(ptr)
11559         BF_ENCRYPT_START
11560 -       addl $32,tmp2
11561 +       addl $32,ptr
11562         BF_ENCRYPT_END
11563 -       movl tmp2,BF_ptr
11564 -       cmpl $BF_current+0x1000,tmp2
11565 -       movl P(0),%eax
11566 -       movl L,-8(tmp2)
11567 -       movl R,-4(tmp2)
11568 -       jb BF_loop_S
11569 +       cmpl $BF_current+0x1000,ptr
11570 +       movl L,-8(ptr)
11571 +       movl R,-4(ptr)
11572 +       jb BF_loop_S_generic
11573         popl %edi
11574         popl %esi
11575         popl %ebx
11576 @@ -1077,7 +1235,7 @@
11577  .bss
11578  #endif
11579  
11580 -#ifdef SOLARIS
11581 +#ifdef DUMBAS
11582  DO_ALIGN(12)
11583  .zero 0x1000 - 96
11584  #elif defined(__DJGPP__)
11585 @@ -1091,7 +1249,7 @@
11586  
11587  .globl BF_current
11588  BF_current:
11589 -#ifdef SOLARIS
11590 +#ifdef DUMBAS
11591  .zero 0x1000 + 72
11592  #else
11593  .space (0x1000 + 72)
11594 @@ -1100,6 +1258,13 @@
11595  BF_ptr:
11596  .long 0
11597  
11598 +/*
11599 + * The function pointer, set by CPU_detect().
11600 + */
11601 +.globl BF_body
11602 +BF_body:
11603 +.long 0
11604 +
11605  #ifdef __DJGPP__
11606  .space 32
11607  #endif
11608 @@ -1111,11 +1276,20 @@
11609  #define EF_ID                          $0x00200000
11610  #define CF_MMX                         $0x00800000
11611  #define CV_INTEL                       $0x6C65746E
11612 +#define CV_AMD                         $0x444D4163
11613  
11614  .text
11615  
11616 +#if !DES_X2
11617 +#define cpuid \
11618 +       .byte 0x0F; \
11619 +       .byte 0xA2
11620 +#endif
11621 +
11622  .globl CPU_detect
11623  CPU_detect:
11624 +       pushl %ebx
11625 +       movl $BF_body_generic,BF_body
11626         pushfl
11627         pushfl
11628         xorl EF_ID,(%esp)
11629 @@ -1125,30 +1299,51 @@
11630         xorl (%esp),%eax
11631         popfl
11632         andl EF_ID,%eax
11633 -       jz CPU_detect_ret
11634 +       jz CPU_detect_ret               /* 386/486 */
11635 +       xorl %eax,%eax
11636 +       cpuid
11637 +       testl %eax,%eax
11638 +       jz CPU_detect_ret               /* Newer 486's */
11639 +       pushl %ecx
11640         movl $1,%eax
11641 -       pushl %ebx
11642 -#if DES_X2
11643         cpuid
11644 -       popl %ebx
11645 +       popl %ecx
11646 +#if DES_X2
11647         xchgl %edx,%eax
11648         andl CF_MMX,%eax
11649 -#else
11650 -       .byte 0x0F
11651 -       .byte 0xA2
11652 -       popl %ebx
11653 +       jz CPU_detect_ret               /* No MMX */
11654 +       xchgl %edx,%eax
11655 +#endif
11656         andb $0x0F,%ah
11657 -       cmpb $5,%ah
11658 -       jne CPU_detect_ret
11659 -       xorl %eax,%eax
11660 -       pushl %ebx
11661 -       .byte 0x0F
11662 -       .byte 0xA2
11663 -       popl %ebx
11664 +       cmpl CV_AMD,%ecx
11665 +       je CPU_detect_AMD               /* Is an AMD processor */
11666         cmpl CV_INTEL,%ecx
11667 -       jne CPU_detect_ret
11668 -       movl $DES_std_crypt_P5,%eax
11669 -       movl %eax,DES_std_crypt
11670 +       jne CPU_detect_yes              /* Not an Intel or AMD */
11671 +       cmpb $5,%ah
11672 +       je CPU_detect_P5                /* Intel Pentium */
11673 +       cmpb $15,%ah
11674 +       je CPU_detect_P5                /* Intel Pentium 4 */
11675 +       jmp CPU_detect_yes              /* Not one of the above */
11676 +CPU_detect_AMD:
11677 +       cmpb $6,%ah
11678 +       jne CPU_detect_yes              /* Not an AMD Athlon */
11679 +CPU_detect_P5:
11680 +/*
11681 + * Enable Intel Pentium optimizations when running on one of:
11682 + *
11683 + * Intel Pentium
11684 + * Intel Pentium 4
11685 + * AMD Athlon
11686 + *
11687 + */
11688 +#if !DES_X2
11689 +       movl $DES_std_crypt_P5,DES_std_crypt
11690 +#endif
11691 +       movl $BF_body_P5,BF_body
11692 +CPU_detect_yes:
11693 +#if DES_X2
11694 +       movb $1,%al
11695  #endif
11696  CPU_detect_ret:
11697 +       popl %ebx
11698         ret
This page took 1.096243 seconds and 3 git commands to generate.