1 /*
2  * This file is part of John the Ripper password cracker,
3  * Copyright (c) 1996-2001,2003,2010-2013,2015,2019 by Solar Designer
4  *
5  * Addition of single DES encryption with no salt by
6  * Deepika Dutta Mishra <dipikadutta at gmail.com> in 2012, no
7  * rights reserved.
8  */
9 
10 #ifdef _MSC_VER
11 #undef _OPENMP
12 #endif
13 
14 #include "arch.h"
15 #include "common.h"
16 #include "DES_bs.h"
17 
18 #if DES_BS_ASM && defined(_OPENMP) && defined(__GNUC__)
19 #warning Assembly code and OpenMP are both requested - will provide the former, but not the latter (for DES-based hashes).  This may likely be corrected by enabling SIMD intrinsics with the C compiler (try adding -msse2 to OMPFLAGS).
20 #endif
21 
22 #if !DES_BS_ASM
23 
24 #define vzero (*(vtype *)&DES_bs_all.zero)
25 #if DES_bs_mt
26 #define vones (*(vtype *)&DES_bs_all_by_tnum(-1).ones)
27 #else
28 #define vones (*(vtype *)&DES_bs_all.ones)
29 #endif
30 
31 #define DES_BS_VECTOR_LOOPS 0
32 
33 #if (defined(__ARM_NEON) || defined(__aarch64__)) && DES_BS_DEPTH == 128
34 #include <arm_neon.h>
35 
36 typedef uint32x4_t vtype;
37 
38 #define vst(dst, ofs, src) \
39 	vst1q_u32((uint32_t *)((DES_bs_vector *)&(dst) + (ofs)), (src))
40 
41 #define vxorf(a, b) \
42 	veorq_u32((a), (b))
43 
44 #define vnot(dst, a) \
45 	(dst) = vmvnq_u32((a))
46 #define vand(dst, a, b) \
47 	(dst) = vandq_u32((a), (b))
48 #define vor(dst, a, b) \
49 	(dst) = vorrq_u32((a), (b))
50 #define vandn(dst, a, b) \
51 	(dst) = vbicq_u32((a), (b))
52 #define vsel(dst, a, b, c) \
53 	(dst) = vbslq_u32((c), (b), (a))
54 
55 #if 0
56 #define vshl1(dst, src) \
57 	(dst) = vaddq_u32((src), (src))
58 #endif
59 #define vshl(dst, src, shift) \
60 	(dst) = vshlq_n_u32((src), (shift))
61 #define vshr(dst, src, shift) \
62 	(dst) = vshrq_n_u32((src), (shift))
63 
64 #elif (defined(__ARM_NEON) || defined(__aarch64__)) && DES_BS_DEPTH == 64 && DES_BS_VECTOR > 0
65 #include <arm_neon.h>
66 
67 typedef uint32x2_t vtype;
68 
69 #define vst(dst, ofs, src) \
70 	vst1_u32((uint32_t *)((DES_bs_vector *)&(dst) + (ofs)), (src))
71 
72 #define vxorf(a, b) \
73 	veor_u32((a), (b))
74 
75 #define vnot(dst, a) \
76 	(dst) = vmvn_u32((a))
77 #define vand(dst, a, b) \
78 	(dst) = vand_u32((a), (b))
79 #define vor(dst, a, b) \
80 	(dst) = vorr_u32((a), (b))
81 #define vandn(dst, a, b) \
82 	(dst) = vbic_u32((a), (b))
83 #define vsel(dst, a, b, c) \
84 	(dst) = vbsl_u32((c), (b), (a))
85 
86 #if 0
87 #define vshl1(dst, src) \
88 	(dst) = vadd_u32((src), (src))
89 #endif
90 #define vshl(dst, src, shift) \
91 	(dst) = vshl_n_u32((src), (shift))
92 #define vshr(dst, src, shift) \
93 	(dst) = vshr_n_u32((src), (shift))
94 
95 #elif defined(__ALTIVEC__) && DES_BS_DEPTH == 128
96 #ifdef __linux__
97 #include <altivec.h>
98 #endif
99 
100 typedef vector signed int vtype;
101 
102 #define vst(dst, ofs, src) \
103 	vec_st((src), (ofs) * sizeof(DES_bs_vector), (vtype *)(dst))
104 
105 #define vxorf(a, b) \
106 	vec_xor((a), (b))
107 
108 #define vnot(dst, a) \
109 	(dst) = vec_nor((a), (a))
110 #define vand(dst, a, b) \
111 	(dst) = vec_and((a), (b))
112 #define vor(dst, a, b) \
113 	(dst) = vec_or((a), (b))
114 #define vandn(dst, a, b) \
115 	(dst) = vec_andc((a), (b))
116 #define vsel(dst, a, b, c) \
117 	(dst) = vec_sel((a), (b), (vector bool int)(c))
118 
119 #elif (defined(__MIC__) || defined(__AVX512F__)) && DES_BS_DEPTH == 512
120 #include <immintrin.h>
121 
122 typedef __m512i vtype;
123 
124 #define vst(dst, ofs, src) \
125 	_mm512_store_epi32((vtype *)((DES_bs_vector *)&(dst) + (ofs)), (src))
126 
127 #define vxorf(a, b) \
128 	_mm512_xor_epi32((a), (b))
129 
130 #define vand(dst, a, b) \
131 	(dst) = _mm512_and_epi32((a), (b))
132 #define vor(dst, a, b) \
133 	(dst) = _mm512_or_epi32((a), (b))
134 #define vandn(dst, a, b) \
135 	(dst) = _mm512_andnot_epi32((b), (a))
136 
137 #define vshl1(dst, src) \
138 	(dst) = _mm512_add_epi32((src), (src))
139 #define vshl(dst, src, shift) \
140 	(dst) = _mm512_slli_epi32((src), (shift))
141 #define vshr(dst, src, shift) \
142 	(dst) = _mm512_srli_epi32((src), (shift))
143 
144 #ifdef __AVX512F__
145 #define vsel(dst, a, b, c) \
146 	(dst) = _mm512_ternarylogic_epi32((b), (a), (c), 0xE4)
147 #define vlut3(a, b, c, d) \
148 	_mm512_ternarylogic_epi32((a), (b), (c), (d))
149 #endif
150 
151 #elif defined(__AVX2__) && DES_BS_DEPTH == 256
152 #include <immintrin.h>
153 
154 typedef __m256i vtype;
155 
156 #define vst(dst, ofs, src) \
157 	_mm256_store_si256((vtype *)((DES_bs_vector *)&(dst) + (ofs)), (src))
158 
159 #define vxorf(a, b) \
160 	_mm256_xor_si256((a), (b))
161 
162 #define vand(dst, a, b) \
163 	(dst) = _mm256_and_si256((a), (b))
164 #define vor(dst, a, b) \
165 	(dst) = _mm256_or_si256((a), (b))
166 #define vandn(dst, a, b) \
167 	(dst) = _mm256_andnot_si256((b), (a))
168 
169 #define vshl1(dst, src) \
170 	(dst) = _mm256_add_epi8((src), (src))
171 #define vshl(dst, src, shift) \
172 	(dst) = _mm256_slli_epi64((src), (shift))
173 #define vshr(dst, src, shift) \
174 	(dst) = _mm256_srli_epi64((src), (shift))
175 
176 #elif defined(__SSE2__) && DES_BS_DEPTH == 128
177 #ifdef __AVX__
178 #include <immintrin.h>
179 #ifdef __XOP__
180 #include <x86intrin.h>
181 #endif
182 #else
183 #include <emmintrin.h>
184 #endif
185 
186 typedef __m128i vtype;
187 
188 #define vst(dst, ofs, src) \
189 	_mm_store_si128((vtype *)((DES_bs_vector *)&(dst) + (ofs)), (src))
190 
191 #define vxorf(a, b) \
192 	_mm_xor_si128((a), (b))
193 
194 #define vand(dst, a, b) \
195 	(dst) = _mm_and_si128((a), (b))
196 #define vor(dst, a, b) \
197 	(dst) = _mm_or_si128((a), (b))
198 #define vandn(dst, a, b) \
199 	(dst) = _mm_andnot_si128((b), (a))
200 
201 #ifdef __XOP__
202 #define vsel(dst, a, b, c) \
203 	(dst) = _mm_cmov_si128((b), (a), (c))
204 #else
205 #define vsel(dst, a, b, c) \
206 	(dst) = _mm_xor_si128(_mm_andnot_si128((c), (a)), \
207 	    _mm_and_si128((c), (b)))
208 #endif
209 
210 #define vshl1(dst, src) \
211 	(dst) = _mm_add_epi8((src), (src))
212 #define vshl(dst, src, shift) \
213 	(dst) = _mm_slli_epi64((src), (shift))
214 #define vshr(dst, src, shift) \
215 	(dst) = _mm_srli_epi64((src), (shift))
216 
217 #elif defined(__MMX__) && ARCH_BITS != 64 && DES_BS_DEPTH == 64
218 #include <mmintrin.h>
219 
220 typedef __m64 vtype;
221 
222 #define vxorf(a, b) \
223 	_mm_xor_si64((a), (b))
224 
225 #define vand(dst, a, b) \
226 	(dst) = _mm_and_si64((a), (b))
227 #define vor(dst, a, b) \
228 	(dst) = _mm_or_si64((a), (b))
229 #define vandn(dst, a, b) \
230 	(dst) = _mm_andnot_si64((b), (a))
231 
232 #define vshl1(dst, src) \
233 	(dst) = _mm_add_pi8((src), (src))
234 #define vshl(dst, src, shift) \
235 	(dst) = _mm_slli_si64((src), (shift))
236 #define vshr(dst, src, shift) \
237 	(dst) = _mm_srli_si64((src), (shift))
238 
239 #else
240 
241 #if DES_BS_VECTOR
242 #undef DES_BS_VECTOR_LOOPS
243 #define DES_BS_VECTOR_LOOPS 1
244 #endif
245 
246 typedef unsigned ARCH_WORD vtype;
247 
248 #define vxorf(a, b) \
249 	((a) ^ (b))
250 
251 #define vnot(dst, a) \
252 	(dst) = ~(a)
253 #define vand(dst, a, b) \
254 	(dst) = (a) & (b)
255 #define vor(dst, a, b) \
256 	(dst) = (a) | (b)
257 #define vandn(dst, a, b) \
258 	(dst) = (a) & ~(b)
259 #define vsel(dst, a, b, c) \
260 	(dst) = (((a) & ~(c)) ^ ((b) & (c)))
261 
262 #define vshl(dst, src, shift) \
263 	(dst) = (src) << (shift)
264 #define vshr(dst, src, shift) \
265 	(dst) = (src) >> (shift)
266 
267 /* Assume that 0 always fits in one load immediate instruction */
268 #undef vzero
269 #define vzero 0
270 
271 /* Archs friendly to use of immediate values */
272 #if defined(__x86_64__) || defined(__i386__)
273 #undef vones
274 #define vones (~(vtype)0)
275 #endif
276 
277 #endif
278 
279 #ifndef vst
280 #define vst(dst, ofs, src) \
281 	*((vtype *)((DES_bs_vector *)&(dst) + (ofs))) = (src)
282 #endif
283 
284 #if !defined(vxor) && defined(vxorf)
285 #define vxor(dst, a, b) \
286 	(dst) = vxorf((a), (b))
287 #endif
288 #if !defined(vxorf) && defined(vxor)
289 /*
290  * This requires gcc's "Statement Exprs" extension (also supported by a number
291  * of other C compilers).
292  */
293 #define vxorf(a, b) \
294 	({ vtype tmp; vxor(tmp, (a), (b)); tmp; })
295 #endif
296 
297 #ifndef vnot
298 #define vnot(dst, a) \
299 	vxor((dst), (a), vones)
300 #endif
301 
302 #ifndef vshl1
303 #define vshl1(dst, src) \
304 	vshl((dst), (src), 1)
305 #endif
306 
307 #if !DES_BS_VECTOR_LOOPS && defined(vshl) && defined(vshr)
308 #define DES_BS_VECTOR_LOOPS_K 0
309 #define DEPTH_K
310 #define for_each_depth_k()
311 
312 #define kvtype vtype
313 #define kvand vand
314 #define kvor vor
315 #define kvshl1 vshl1
316 #define kvshl vshl
317 #define kvshr vshr
318 #else
319 #if DES_BS_VECTOR
320 #define DES_BS_VECTOR_LOOPS_K 1
321 #define DEPTH_K				[depth]
322 #define for_each_depth_k() \
323 	for (depth = 0; depth < DES_BS_VECTOR; depth++)
324 #else
325 #define DES_BS_VECTOR_LOOPS_K 0
326 #endif
327 
328 typedef unsigned ARCH_WORD kvtype;
329 #define kvand(dst, a, b) \
330 	(dst) = (a) & (b)
331 #define kvor(dst, a, b) \
332 	(dst) = (a) | (b)
333 #define kvshl1(dst, src) \
334 	(dst) = (src) << 1
335 #define kvshl(dst, src, shift) \
336 	(dst) = (src) << (shift)
337 #define kvshr(dst, src, shift) \
338 	(dst) = (src) >> (shift)
339 #endif
340 
341 #if !DES_BS_VECTOR || DES_BS_VECTOR_LOOPS_K
342 #ifdef __x86_64__
343 #define mask01 0x0101010101010101UL
344 #elif __i386__
345 #define mask01 0x01010101UL
346 #else
347 #undef mask01
348 #endif
349 #ifdef mask01
350 #define mask02 (mask01 << 1)
351 #define mask04 (mask01 << 2)
352 #define mask08 (mask01 << 3)
353 #define mask10 (mask01 << 4)
354 #define mask20 (mask01 << 5)
355 #define mask40 (mask01 << 6)
356 #define mask80 (mask01 << 7)
357 #endif
358 #endif
359 
360 #ifndef mask01
361 #define mask01 (*(kvtype *)&DES_bs_all.masks[0])
362 #define mask02 (*(kvtype *)&DES_bs_all.masks[1])
363 #define mask04 (*(kvtype *)&DES_bs_all.masks[2])
364 #define mask08 (*(kvtype *)&DES_bs_all.masks[3])
365 #define mask10 (*(kvtype *)&DES_bs_all.masks[4])
366 #define mask20 (*(kvtype *)&DES_bs_all.masks[5])
367 #define mask40 (*(kvtype *)&DES_bs_all.masks[6])
368 #define mask80 (*(kvtype *)&DES_bs_all.masks[7])
369 #endif
370 
371 #ifdef __i386__
372 /* register-starved */
373 #define LOAD_V \
374 	kvtype v0 = *(kvtype *)&vp[0]; \
375 	kvtype v4 = *(kvtype *)&vp[4];
376 #define v1 *(kvtype *)&vp[1]
377 #define v2 *(kvtype *)&vp[2]
378 #define v3 *(kvtype *)&vp[3]
379 #define v5 *(kvtype *)&vp[5]
380 #define v6 *(kvtype *)&vp[6]
381 #define v7 *(kvtype *)&vp[7]
382 #else
383 #define LOAD_V \
384 	kvtype v0 = *(kvtype *)&vp[0]; \
385 	kvtype v1 = *(kvtype *)&vp[1]; \
386 	kvtype v2 = *(kvtype *)&vp[2]; \
387 	kvtype v3 = *(kvtype *)&vp[3]; \
388 	kvtype v4 = *(kvtype *)&vp[4]; \
389 	kvtype v5 = *(kvtype *)&vp[5]; \
390 	kvtype v6 = *(kvtype *)&vp[6]; \
391 	kvtype v7 = *(kvtype *)&vp[7];
392 #endif
393 
394 #define kvand_shl1_or(dst, src, mask) \
395 	kvand(tmp, src, mask); \
396 	kvshl1(tmp, tmp); \
397 	kvor(dst, dst, tmp)
398 
399 #define kvand_shl_or(dst, src, mask, shift) \
400 	kvand(tmp, src, mask); \
401 	kvshl(tmp, tmp, shift); \
402 	kvor(dst, dst, tmp)
403 
404 #define kvand_shl1(dst, src, mask) \
405 	kvand(tmp, src, mask); \
406 	kvshl1(dst, tmp)
407 
408 #define kvand_or(dst, src, mask) \
409 	kvand(tmp, src, mask); \
410 	kvor(dst, dst, tmp)
411 
412 #define kvand_shr_or(dst, src, mask, shift) \
413 	kvand(tmp, src, mask); \
414 	kvshr(tmp, tmp, shift); \
415 	kvor(dst, dst, tmp)
416 
417 #define kvand_shr(dst, src, mask, shift) \
418 	kvand(tmp, src, mask); \
419 	kvshr(dst, tmp, shift)
420 
421 #define FINALIZE_NEXT_KEY_BIT_0 { \
422 	kvtype m = mask01, va, vb, tmp; \
423 	kvand(va, v0, m); \
424 	kvand_shl1(vb, v1, m); \
425 	kvand_shl_or(va, v2, m, 2); \
426 	kvand_shl_or(vb, v3, m, 3); \
427 	kvand_shl_or(va, v4, m, 4); \
428 	kvand_shl_or(vb, v5, m, 5); \
429 	kvand_shl_or(va, v6, m, 6); \
430 	kvand_shl_or(vb, v7, m, 7); \
431 	kvor(*(kvtype *)kp, va, vb); \
432 	kp++; \
433 }
434 
435 #define FINALIZE_NEXT_KEY_BIT_1 { \
436 	kvtype m = mask02, va, vb, tmp; \
437 	kvand_shr(va, v0, m, 1); \
438 	kvand(vb, v1, m); \
439 	kvand_shl1_or(va, v2, m); \
440 	kvand_shl_or(vb, v3, m, 2); \
441 	kvand_shl_or(va, v4, m, 3); \
442 	kvand_shl_or(vb, v5, m, 4); \
443 	kvand_shl_or(va, v6, m, 5); \
444 	kvand_shl_or(vb, v7, m, 6); \
445 	kvor(*(kvtype *)kp, va, vb); \
446 	kp++; \
447 }
448 
449 #define FINALIZE_NEXT_KEY_BIT_2 { \
450 	kvtype m = mask04, va, vb, tmp; \
451 	kvand_shr(va, v0, m, 2); \
452 	kvand_shr(vb, v1, m, 1); \
453 	kvand_or(va, v2, m); \
454 	kvand_shl1_or(vb, v3, m); \
455 	kvand_shl_or(va, v4, m, 2); \
456 	kvand_shl_or(vb, v5, m, 3); \
457 	kvand_shl_or(va, v6, m, 4); \
458 	kvand_shl_or(vb, v7, m, 5); \
459 	kvor(*(kvtype *)kp, va, vb); \
460 	kp++; \
461 }
462 
463 #define FINALIZE_NEXT_KEY_BIT_3 { \
464 	kvtype m = mask08, va, vb, tmp; \
465 	kvand_shr(va, v0, m, 3); \
466 	kvand_shr(vb, v1, m, 2); \
467 	kvand_shr_or(va, v2, m, 1); \
468 	kvand_or(vb, v3, m); \
469 	kvand_shl1_or(va, v4, m); \
470 	kvand_shl_or(vb, v5, m, 2); \
471 	kvand_shl_or(va, v6, m, 3); \
472 	kvand_shl_or(vb, v7, m, 4); \
473 	kvor(*(kvtype *)kp, va, vb); \
474 	kp++; \
475 }
476 
477 #define FINALIZE_NEXT_KEY_BIT_4 { \
478 	kvtype m = mask10, va, vb, tmp; \
479 	kvand_shr(va, v0, m, 4); \
480 	kvand_shr(vb, v1, m, 3); \
481 	kvand_shr_or(va, v2, m, 2); \
482 	kvand_shr_or(vb, v3, m, 1); \
483 	kvand_or(va, v4, m); \
484 	kvand_shl1_or(vb, v5, m); \
485 	kvand_shl_or(va, v6, m, 2); \
486 	kvand_shl_or(vb, v7, m, 3); \
487 	kvor(*(kvtype *)kp, va, vb); \
488 	kp++; \
489 }
490 
491 #define FINALIZE_NEXT_KEY_BIT_5 { \
492 	kvtype m = mask20, va, vb, tmp; \
493 	kvand_shr(va, v0, m, 5); \
494 	kvand_shr(vb, v1, m, 4); \
495 	kvand_shr_or(va, v2, m, 3); \
496 	kvand_shr_or(vb, v3, m, 2); \
497 	kvand_shr_or(va, v4, m, 1); \
498 	kvand_or(vb, v5, m); \
499 	kvand_shl1_or(va, v6, m); \
500 	kvand_shl_or(vb, v7, m, 2); \
501 	kvor(*(kvtype *)kp, va, vb); \
502 	kp++; \
503 }
504 
505 #define FINALIZE_NEXT_KEY_BIT_6 { \
506 	kvtype m = mask40, va, vb, tmp; \
507 	kvand_shr(va, v0, m, 6); \
508 	kvand_shr(vb, v1, m, 5); \
509 	kvand_shr_or(va, v2, m, 4); \
510 	kvand_shr_or(vb, v3, m, 3); \
511 	kvand_shr_or(va, v4, m, 2); \
512 	kvand_shr_or(vb, v5, m, 1); \
513 	kvand_or(va, v6, m); \
514 	kvand_shl1_or(vb, v7, m); \
515 	kvor(*(kvtype *)kp, va, vb); \
516 	kp++; \
517 }
518 
519 #define FINALIZE_NEXT_KEY_BIT_7 { \
520 	kvtype m = mask80, va, vb, tmp; \
521 	kvand_shr(va, v0, m, 7); \
522 	kvand_shr(vb, v1, m, 6); \
523 	kvand_shr_or(va, v2, m, 5); \
524 	kvand_shr_or(vb, v3, m, 4); \
525 	kvand_shr_or(va, v4, m, 3); \
526 	kvand_shr_or(vb, v5, m, 2); \
527 	kvand_shr_or(va, v6, m, 1); \
528 	kvand_or(vb, v7, m); \
529 	kvor(*(kvtype *)kp, va, vb); \
530 	kp++; \
531 }
532 
533 #if DES_bs_mt
DES_bs_finalize_keys(int t)534 static MAYBE_INLINE void DES_bs_finalize_keys(int t)
535 #else
536 static MAYBE_INLINE void DES_bs_finalize_keys(void)
537 #endif
538 {
539 #if DES_BS_VECTOR_LOOPS_K
540 	int depth;
541 #endif
542 
543 	for_each_depth_k() {
544 		DES_bs_vector *kp = (DES_bs_vector *)&DES_bs_all.K[0] DEPTH_K;
545 		int ic;
546 		for (ic = 0; ic < 8; ic++) {
547 			DES_bs_vector *vp =
548 			    (DES_bs_vector *)&DES_bs_all.xkeys.v[ic][0] DEPTH_K;
549 			LOAD_V
550 			FINALIZE_NEXT_KEY_BIT_0
551 			FINALIZE_NEXT_KEY_BIT_1
552 			FINALIZE_NEXT_KEY_BIT_2
553 			FINALIZE_NEXT_KEY_BIT_3
554 			FINALIZE_NEXT_KEY_BIT_4
555 			FINALIZE_NEXT_KEY_BIT_5
556 			FINALIZE_NEXT_KEY_BIT_6
557 		}
558 	}
559 
560 #if DES_BS_EXPAND
561 	{
562 		int index;
563 		for (index = 0; index < 0x300; index++)
564 		for_each_depth_k() {
565 #if DES_BS_VECTOR_LOOPS_K
566 			DES_bs_all.KS.v[index] DEPTH_K =
567 			    DES_bs_all.KSp[index] DEPTH_K;
568 #else
569 			vst(*(kvtype *)&DES_bs_all.KS.v[index], 0,
570 			    *(kvtype *)DES_bs_all.KSp[index]);
571 #endif
572 		}
573 	}
574 #endif
575 }
576 
577 #endif
578 
579 #if DES_bs_mt
DES_bs_set_salt_for_thread(int t,unsigned int salt)580 MAYBE_INLINE void DES_bs_set_salt_for_thread(int t, unsigned int salt)
581 #else
582 void DES_bs_set_salt(ARCH_WORD salt)
583 #endif
584 {
585 	unsigned int new = salt;
586 	unsigned int old = DES_bs_all.salt;
587 	int dst;
588 
589 	DES_bs_all.salt = new;
590 
591 	for (dst = 0; dst < 24; dst++) {
592 		if ((new ^ old) & 1) {
593 			DES_bs_vector *sp1, *sp2;
594 			int src1 = dst;
595 			int src2 = dst + 24;
596 			if (new & 1) {
597 				src1 = src2;
598 				src2 = dst;
599 			}
600 			sp1 = DES_bs_all.Ens[src1];
601 			sp2 = DES_bs_all.Ens[src2];
602 			DES_bs_all.E.E[dst] = (ARCH_WORD *)sp1;
603 			DES_bs_all.E.E[dst + 24] = (ARCH_WORD *)sp2;
604 			DES_bs_all.E.E[dst + 48] = (ARCH_WORD *)(sp1 + 32);
605 			DES_bs_all.E.E[dst + 72] = (ARCH_WORD *)(sp2 + 32);
606 		}
607 		new >>= 1;
608 		old >>= 1;
609 		if (new == old)
610 			break;
611 	}
612 }
613 
614 #if !DES_BS_ASM
615 
616 /* Include the S-boxes here so that the compiler can inline them */
617 #if DES_BS == 4
618 #include "sboxes-t.c"
619 #elif DES_BS == 3
620 #include "sboxes-s.c"
621 #elif DES_BS == 2
622 #include "sboxes.c"
623 #else
624 #undef andn
625 #include "nonstd.c"
626 #endif
627 
628 #define b				DES_bs_all.B
629 #define e				DES_bs_all.E.E
630 
631 #if DES_BS_VECTOR_LOOPS
632 #define kd				[depth]
633 #define bd				[depth]
634 #define ed				[depth]
635 #define DEPTH				[depth]
636 #define for_each_depth() \
637 	for (depth = 0; depth < DES_BS_VECTOR; depth++)
638 #else
639 #if DES_BS_EXPAND
640 #define kd
641 #else
642 #define kd				[0]
643 #endif
644 #define bd
645 #define ed				[0]
646 #define DEPTH
647 #define for_each_depth()
648 #endif
649 
650 #define DES_bs_clear_block_8(i) \
651 	for_each_depth() { \
652 		vst(b[i] bd, 0, zero); \
653 		vst(b[i] bd, 1, zero); \
654 		vst(b[i] bd, 2, zero); \
655 		vst(b[i] bd, 3, zero); \
656 		vst(b[i] bd, 4, zero); \
657 		vst(b[i] bd, 5, zero); \
658 		vst(b[i] bd, 6, zero); \
659 		vst(b[i] bd, 7, zero); \
660 	}
661 
662 #define DES_bs_clear_block \
663 	DES_bs_clear_block_8(0); \
664 	DES_bs_clear_block_8(8); \
665 	DES_bs_clear_block_8(16); \
666 	DES_bs_clear_block_8(24); \
667 	DES_bs_clear_block_8(32); \
668 	DES_bs_clear_block_8(40); \
669 	DES_bs_clear_block_8(48); \
670 	DES_bs_clear_block_8(56);
671 
672 #define DES_bs_set_block_8(i, v0, v1, v2, v3, v4, v5, v6, v7) \
673 	for_each_depth() { \
674 		vst(b[i] bd, 0, v0); \
675 		vst(b[i] bd, 1, v1); \
676 		vst(b[i] bd, 2, v2); \
677 		vst(b[i] bd, 3, v3); \
678 		vst(b[i] bd, 4, v4); \
679 		vst(b[i] bd, 5, v5); \
680 		vst(b[i] bd, 6, v6); \
681 		vst(b[i] bd, 7, v7); \
682 	}
683 
684 #define x(p) vxorf(*(vtype *)&e[p] ed, *(vtype *)&k[p] kd)
685 #define y(p, q) vxorf(*(vtype *)&b[p] bd, *(vtype *)&k[q] kd)
686 #define z(r) ((vtype *)&b[r] bd)
687 
DES_bs_crypt_25(int keys_count)688 void DES_bs_crypt_25(int keys_count)
689 {
690 #if DES_bs_mt
691 	int t, n = (keys_count + (DES_BS_DEPTH - 1)) / DES_BS_DEPTH;
692 #endif
693 
694 #ifdef _OPENMP
695 #pragma omp parallel for default(none) private(t) shared(n, DES_bs_all_p, keys_count)
696 #endif
697 	for_each_t(n) {
698 #if DES_BS_EXPAND
699 		DES_bs_vector *k;
700 #else
701 		ARCH_WORD **k;
702 #endif
703 		int iterations, rounds_and_swapped;
704 #if DES_BS_VECTOR_LOOPS
705 		int depth;
706 #endif
707 
708 		if (DES_bs_all.keys_changed)
709 			goto finalize_keys;
710 
711 body:
712 #if DES_bs_mt
713 		DES_bs_set_salt_for_thread(t, DES_bs_all_by_tnum(-1).salt);
714 #endif
715 
716 		{
717 			vtype zero = vzero;
718 			DES_bs_clear_block
719 		}
720 
721 #if DES_BS_EXPAND
722 		k = DES_bs_all.KS.v;
723 #else
724 		k = DES_bs_all.KS.p;
725 #endif
726 		rounds_and_swapped = 8;
727 		iterations = 25;
728 
729 start:
730 		for_each_depth()
731 		s1(x(0), x(1), x(2), x(3), x(4), x(5),
732 			z(40), z(48), z(54), z(62));
733 		for_each_depth()
734 		s2(x(6), x(7), x(8), x(9), x(10), x(11),
735 			z(44), z(59), z(33), z(49));
736 		for_each_depth()
737 		s3(y(7, 12), y(8, 13), y(9, 14),
738 			y(10, 15), y(11, 16), y(12, 17),
739 			z(55), z(47), z(61), z(37));
740 		for_each_depth()
741 		s4(y(11, 18), y(12, 19), y(13, 20),
742 			y(14, 21), y(15, 22), y(16, 23),
743 			z(57), z(51), z(41), z(32));
744 		for_each_depth()
745 		s5(x(24), x(25), x(26), x(27), x(28), x(29),
746 			z(39), z(45), z(56), z(34));
747 		for_each_depth()
748 		s6(x(30), x(31), x(32), x(33), x(34), x(35),
749 			z(35), z(60), z(42), z(50));
750 		for_each_depth()
751 		s7(y(23, 36), y(24, 37), y(25, 38),
752 			y(26, 39), y(27, 40), y(28, 41),
753 			z(63), z(43), z(53), z(38));
754 		for_each_depth()
755 		s8(y(27, 42), y(28, 43), y(29, 44),
756 			y(30, 45), y(31, 46), y(0, 47),
757 			z(36), z(58), z(46), z(52));
758 
759 		if (rounds_and_swapped == 0x100) goto next;
760 
761 swap:
762 		for_each_depth()
763 		s1(x(48), x(49), x(50), x(51), x(52), x(53),
764 			z(8), z(16), z(22), z(30));
765 		for_each_depth()
766 		s2(x(54), x(55), x(56), x(57), x(58), x(59),
767 			z(12), z(27), z(1), z(17));
768 		for_each_depth()
769 		s3(y(39, 60), y(40, 61), y(41, 62),
770 			y(42, 63), y(43, 64), y(44, 65),
771 			z(23), z(15), z(29), z(5));
772 		for_each_depth()
773 		s4(y(43, 66), y(44, 67), y(45, 68),
774 			y(46, 69), y(47, 70), y(48, 71),
775 			z(25), z(19), z(9), z(0));
776 		for_each_depth()
777 		s5(x(72), x(73), x(74), x(75), x(76), x(77),
778 			z(7), z(13), z(24), z(2));
779 		for_each_depth()
780 		s6(x(78), x(79), x(80), x(81), x(82), x(83),
781 			z(3), z(28), z(10), z(18));
782 		for_each_depth()
783 		s7(y(55, 84), y(56, 85), y(57, 86),
784 			y(58, 87), y(59, 88), y(60, 89),
785 			z(31), z(11), z(21), z(6));
786 		for_each_depth()
787 		s8(y(59, 90), y(60, 91), y(61, 92),
788 			y(62, 93), y(63, 94), y(32, 95),
789 			z(4), z(26), z(14), z(20));
790 
791 		k += 96;
792 
793 		if (--rounds_and_swapped) goto start;
794 		k -= (0x300 + 48);
795 		rounds_and_swapped = 0x108;
796 		if (--iterations) goto swap;
797 #if DES_bs_mt
798 		continue;
799 #else
800 		return;
801 #endif
802 
803 next:
804 		k -= (0x300 - 48);
805 		rounds_and_swapped = 8;
806 		iterations--;
807 		goto start;
808 
809 finalize_keys:
810 		DES_bs_all.keys_changed = 0;
811 #if DES_bs_mt
812 		DES_bs_finalize_keys(t);
813 #else
814 		DES_bs_finalize_keys();
815 #endif
816 		goto body;
817 	}
818 }
819 
DES_bs_crypt(int count,int keys_count)820 void DES_bs_crypt(int count, int keys_count)
821 {
822 #if DES_bs_mt
823 	int t, n = (keys_count + (DES_BS_DEPTH - 1)) / DES_BS_DEPTH;
824 #endif
825 
826 #ifdef _OPENMP
827 #pragma omp parallel for default(none) private(t) shared(n, DES_bs_all_p, count, keys_count)
828 #endif
829 	for_each_t(n) {
830 #if DES_BS_EXPAND
831 		DES_bs_vector *k;
832 #else
833 		ARCH_WORD **k;
834 #endif
835 		int iterations, rounds_and_swapped;
836 #if DES_BS_VECTOR_LOOPS
837 		int depth;
838 #endif
839 
840 		if (DES_bs_all.keys_changed)
841 			goto finalize_keys;
842 
843 body:
844 #if DES_bs_mt
845 		DES_bs_set_salt_for_thread(t, DES_bs_all_by_tnum(-1).salt);
846 #endif
847 
848 		{
849 			vtype zero = vzero;
850 			DES_bs_clear_block
851 		}
852 
853 #if DES_BS_EXPAND
854 		k = DES_bs_all.KS.v;
855 #else
856 		k = DES_bs_all.KS.p;
857 #endif
858 		rounds_and_swapped = 8;
859 		iterations = count;
860 
861 start:
862 		for_each_depth()
863 		s1(x(0), x(1), x(2), x(3), x(4), x(5),
864 			z(40), z(48), z(54), z(62));
865 		for_each_depth()
866 		s2(x(6), x(7), x(8), x(9), x(10), x(11),
867 			z(44), z(59), z(33), z(49));
868 		for_each_depth()
869 		s3(x(12), x(13), x(14), x(15), x(16), x(17),
870 			z(55), z(47), z(61), z(37));
871 		for_each_depth()
872 		s4(x(18), x(19), x(20), x(21), x(22), x(23),
873 			z(57), z(51), z(41), z(32));
874 		for_each_depth()
875 		s5(x(24), x(25), x(26), x(27), x(28), x(29),
876 			z(39), z(45), z(56), z(34));
877 		for_each_depth()
878 		s6(x(30), x(31), x(32), x(33), x(34), x(35),
879 			z(35), z(60), z(42), z(50));
880 		for_each_depth()
881 		s7(x(36), x(37), x(38), x(39), x(40), x(41),
882 			z(63), z(43), z(53), z(38));
883 		for_each_depth()
884 		s8(x(42), x(43), x(44), x(45), x(46), x(47),
885 			z(36), z(58), z(46), z(52));
886 
887 		if (rounds_and_swapped == 0x100) goto next;
888 
889 swap:
890 		for_each_depth()
891 		s1(x(48), x(49), x(50), x(51), x(52), x(53),
892 			z(8), z(16), z(22), z(30));
893 		for_each_depth()
894 		s2(x(54), x(55), x(56), x(57), x(58), x(59),
895 			z(12), z(27), z(1), z(17));
896 		for_each_depth()
897 		s3(x(60), x(61), x(62), x(63), x(64), x(65),
898 			z(23), z(15), z(29), z(5));
899 		for_each_depth()
900 		s4(x(66), x(67), x(68), x(69), x(70), x(71),
901 			z(25), z(19), z(9), z(0));
902 		for_each_depth()
903 		s5(x(72), x(73), x(74), x(75), x(76), x(77),
904 			z(7), z(13), z(24), z(2));
905 		for_each_depth()
906 		s6(x(78), x(79), x(80), x(81), x(82), x(83),
907 			z(3), z(28), z(10), z(18));
908 		for_each_depth()
909 		s7(x(84), x(85), x(86), x(87), x(88), x(89),
910 			z(31), z(11), z(21), z(6));
911 		for_each_depth()
912 		s8(x(90), x(91), x(92), x(93), x(94), x(95),
913 			z(4), z(26), z(14), z(20));
914 
915 		k += 96;
916 
917 		if (--rounds_and_swapped) goto start;
918 		k -= (0x300 + 48);
919 		rounds_and_swapped = 0x108;
920 		if (--iterations) goto swap;
921 #if DES_bs_mt
922 		continue;
923 #else
924 		return;
925 #endif
926 
927 next:
928 		k -= (0x300 - 48);
929 		rounds_and_swapped = 8;
930 		if (--iterations) goto start;
931 #if DES_bs_mt
932 		continue;
933 #else
934 		return;
935 #endif
936 
937 finalize_keys:
938 		DES_bs_all.keys_changed = 0;
939 #if DES_bs_mt
940 		DES_bs_finalize_keys(t);
941 #else
942 		DES_bs_finalize_keys();
943 #endif
944 		goto body;
945 	}
946 }
947 
948 #undef x
949 
950 #if DES_bs_mt
DES_bs_finalize_keys_LM(int t)951 static MAYBE_INLINE void DES_bs_finalize_keys_LM(int t)
952 #else
953 static MAYBE_INLINE void DES_bs_finalize_keys_LM(void)
954 #endif
955 {
956 #if DES_BS_VECTOR_LOOPS_K
957 	int depth;
958 #endif
959 
960 	for_each_depth_k() {
961 		DES_bs_vector *kp = (DES_bs_vector *)&DES_bs_all.K[0] DEPTH_K;
962 		int ic;
963 		for (ic = 0; ic < 7; ic++) {
964 			DES_bs_vector *vp =
965 			    (DES_bs_vector *)&DES_bs_all.xkeys.v[ic][0] DEPTH_K;
966 			LOAD_V
967 			FINALIZE_NEXT_KEY_BIT_0
968 			FINALIZE_NEXT_KEY_BIT_1
969 			FINALIZE_NEXT_KEY_BIT_2
970 			FINALIZE_NEXT_KEY_BIT_3
971 			FINALIZE_NEXT_KEY_BIT_4
972 			FINALIZE_NEXT_KEY_BIT_5
973 			FINALIZE_NEXT_KEY_BIT_6
974 			FINALIZE_NEXT_KEY_BIT_7
975 		}
976 	}
977 }
978 
979 #undef kd
980 #if DES_BS_VECTOR_LOOPS
981 #define kd				[depth]
982 #else
983 #define kd				[0]
984 #endif
985 
DES_bs_crypt_LM(int * pcount,struct db_salt * salt)986 int DES_bs_crypt_LM(int *pcount, struct db_salt *salt)
987 {
988 	int keys_count = *pcount;
989 #if DES_bs_mt
990 	int t, n = (keys_count + (DES_BS_DEPTH - 1)) / DES_BS_DEPTH;
991 #endif
992 
993 #ifdef _OPENMP
994 #pragma omp parallel for default(none) private(t) shared(n, DES_bs_all_p, keys_count)
995 #endif
996 	for_each_t(n) {
997 		ARCH_WORD **k;
998 		int rounds;
999 #if DES_BS_VECTOR_LOOPS
1000 		int depth;
1001 #endif
1002 
1003 		{
1004 			vtype z = vzero, o = vones;
1005 			DES_bs_set_block_8(0, z, z, z, z, z, z, z, z);
1006 			DES_bs_set_block_8(8, o, o, o, z, o, z, z, z);
1007 			DES_bs_set_block_8(16, z, z, z, z, z, z, z, o);
1008 			DES_bs_set_block_8(24, z, z, o, z, z, o, o, o);
1009 			DES_bs_set_block_8(32, z, z, z, o, z, o, o, o);
1010 			DES_bs_set_block_8(40, z, z, z, z, z, o, z, z);
1011 			DES_bs_set_block_8(48, o, o, z, z, z, z, o, z);
1012 			DES_bs_set_block_8(56, o, z, o, z, o, o, o, o);
1013 		}
1014 
1015 #if DES_bs_mt
1016 		DES_bs_finalize_keys_LM(t);
1017 #else
1018 		DES_bs_finalize_keys_LM();
1019 #endif
1020 
1021 		k = DES_bs_all.KS.p;
1022 		rounds = 8;
1023 
1024 		do {
1025 			for_each_depth()
1026 			s1(y(31, 0), y(0, 1), y(1, 2),
1027 				y(2, 3), y(3, 4), y(4, 5),
1028 				z(40), z(48), z(54), z(62));
1029 			for_each_depth()
1030 			s2(y(3, 6), y(4, 7), y(5, 8),
1031 				y(6, 9), y(7, 10), y(8, 11),
1032 				z(44), z(59), z(33), z(49));
1033 			for_each_depth()
1034 			s3(y(7, 12), y(8, 13), y(9, 14),
1035 				y(10, 15), y(11, 16), y(12, 17),
1036 				z(55), z(47), z(61), z(37));
1037 			for_each_depth()
1038 			s4(y(11, 18), y(12, 19), y(13, 20),
1039 				y(14, 21), y(15, 22), y(16, 23),
1040 				z(57), z(51), z(41), z(32));
1041 			for_each_depth()
1042 			s5(y(15, 24), y(16, 25), y(17, 26),
1043 				y(18, 27), y(19, 28), y(20, 29),
1044 				z(39), z(45), z(56), z(34));
1045 			for_each_depth()
1046 			s6(y(19, 30), y(20, 31), y(21, 32),
1047 				y(22, 33), y(23, 34), y(24, 35),
1048 				z(35), z(60), z(42), z(50));
1049 			for_each_depth()
1050 			s7(y(23, 36), y(24, 37), y(25, 38),
1051 				y(26, 39), y(27, 40), y(28, 41),
1052 				z(63), z(43), z(53), z(38));
1053 			for_each_depth()
1054 			s8(y(27, 42), y(28, 43), y(29, 44),
1055 				y(30, 45), y(31, 46), y(0, 47),
1056 				z(36), z(58), z(46), z(52));
1057 
1058 			for_each_depth()
1059 			s1(y(63, 48), y(32, 49), y(33, 50),
1060 				y(34, 51), y(35, 52), y(36, 53),
1061 				z(8), z(16), z(22), z(30));
1062 			for_each_depth()
1063 			s2(y(35, 54), y(36, 55), y(37, 56),
1064 				y(38, 57), y(39, 58), y(40, 59),
1065 				z(12), z(27), z(1), z(17));
1066 			for_each_depth()
1067 			s3(y(39, 60), y(40, 61), y(41, 62),
1068 				y(42, 63), y(43, 64), y(44, 65),
1069 				z(23), z(15), z(29), z(5));
1070 			for_each_depth()
1071 			s4(y(43, 66), y(44, 67), y(45, 68),
1072 				y(46, 69), y(47, 70), y(48, 71),
1073 				z(25), z(19), z(9), z(0));
1074 			for_each_depth()
1075 			s5(y(47, 72), y(48, 73), y(49, 74),
1076 				y(50, 75), y(51, 76), y(52, 77),
1077 				z(7), z(13), z(24), z(2));
1078 			for_each_depth()
1079 			s6(y(51, 78), y(52, 79), y(53, 80),
1080 				y(54, 81), y(55, 82), y(56, 83),
1081 				z(3), z(28), z(10), z(18));
1082 			for_each_depth()
1083 			s7(y(55, 84), y(56, 85), y(57, 86),
1084 				y(58, 87), y(59, 88), y(60, 89),
1085 				z(31), z(11), z(21), z(6));
1086 			for_each_depth()
1087 			s8(y(59, 90), y(60, 91), y(61, 92),
1088 				y(62, 93), y(63, 94), y(32, 95),
1089 				z(4), z(26), z(14), z(20));
1090 
1091 			k += 96;
1092 		} while (--rounds);
1093 	}
1094 
1095 	return keys_count;
1096 }
1097 
1098 
1099 #if DES_bs_mt
DES_bs_finalize_keys_plain(int t)1100 static MAYBE_INLINE void DES_bs_finalize_keys_plain(int t)
1101 #else
1102 static MAYBE_INLINE void DES_bs_finalize_keys_plain(void)
1103 #endif
1104 {
1105 #if DES_BS_VECTOR_LOOPS_K
1106 	int depth;
1107 #endif
1108 
1109 	for_each_depth_k() {
1110       DES_bs_vector *kp = (DES_bs_vector *)&DES_bs_all.K[0] DEPTH_K;
1111       int ic;
1112       for (ic = 0; ic < 8; ic++) {
1113                DES_bs_vector *vp =
1114                (DES_bs_vector *)&DES_bs_all.xkeys.v[ic][0] DEPTH_K;
1115                LOAD_V
1116                FINALIZE_NEXT_KEY_BIT_0
1117                FINALIZE_NEXT_KEY_BIT_1
1118                FINALIZE_NEXT_KEY_BIT_2
1119                FINALIZE_NEXT_KEY_BIT_3
1120                FINALIZE_NEXT_KEY_BIT_4
1121                FINALIZE_NEXT_KEY_BIT_5
1122                FINALIZE_NEXT_KEY_BIT_6
1123               }
1124 	}
1125 }
1126 
1127 #undef v1
1128 #undef v2
1129 #undef v3
1130 #undef v5
1131 #undef v6
1132 #undef v7
1133 
1134 
1135 /* Single Des Encryption with no salt */
1136 #undef kd
1137 #if DES_BS_VECTOR_LOOPS
1138 #define kd				[depth]
1139 #else
1140 #define kd				[0]
1141 #endif
1142 
1143 #if DES_BS_VECTOR
1144 #define INDX [index]
1145 #else
1146 #define INDX
1147 #endif
1148 
DES_bs_crypt_plain(int keys_count)1149 void DES_bs_crypt_plain(int keys_count)
1150 {
1151 #if DES_bs_mt
1152 	int t, n = (keys_count + (DES_BS_DEPTH - 1)) / DES_BS_DEPTH;
1153 #endif
1154 
1155 
1156 #ifdef _OPENMP
1157 #pragma omp parallel for default(none) private(t) shared(n, DES_bs_all_p, keys_count, DES_bs_P)
1158 #endif
1159 	for_each_t(n) {
1160 			ARCH_WORD **k;
1161 			int rounds;
1162 	#if DES_BS_VECTOR_LOOPS
1163 			int depth;
1164 	#endif
1165 			int i;
1166 	#if DES_BS_VECTOR
1167 		int index;
1168 	#endif
1169 
1170 	for (i=0; i<64; i++)
1171 	{
1172 	#if DES_BS_VECTOR
1173                 for (index=0; index<DES_BS_VECTOR_SIZE; index++)
1174 	#endif
1175 			DES_bs_all.B[i]INDX = DES_bs_P[i]INDX;
1176 	}
1177 
1178 #if DES_bs_mt
1179 		DES_bs_finalize_keys_plain(t);
1180 #else
1181 		DES_bs_finalize_keys_plain();
1182 #endif
1183 
1184 	k = DES_bs_all.KS.p;
1185 	rounds = 8;
1186 
1187 	do {
1188 		for_each_depth()
1189 		s1(y(31, 0), y(0, 1), y(1, 2),
1190 			y(2, 3), y(3, 4), y(4, 5),
1191 			z(40), z(48), z(54), z(62));
1192 		for_each_depth()
1193 		s2(y(3, 6), y(4, 7), y(5, 8),
1194 			y(6, 9), y(7, 10), y(8, 11),
1195 			z(44), z(59), z(33), z(49));
1196 		for_each_depth()
1197 		s3(y(7, 12), y(8, 13), y(9, 14),
1198 			y(10, 15), y(11, 16), y(12, 17),
1199 			z(55), z(47), z(61), z(37));
1200 		for_each_depth()
1201 		s4(y(11, 18), y(12, 19), y(13, 20),
1202 			y(14, 21), y(15, 22), y(16, 23),
1203 			z(57), z(51), z(41), z(32));
1204 		for_each_depth()
1205 		s5(y(15, 24), y(16, 25), y(17, 26),
1206 			y(18, 27), y(19, 28), y(20, 29),
1207 			z(39), z(45), z(56), z(34));
1208 		for_each_depth()
1209 		s6(y(19, 30), y(20, 31), y(21, 32),
1210 			y(22, 33), y(23, 34), y(24, 35),
1211 			z(35), z(60), z(42), z(50));
1212 		for_each_depth()
1213 		s7(y(23, 36), y(24, 37), y(25, 38),
1214 			y(26, 39), y(27, 40), y(28, 41),
1215 			z(63), z(43), z(53), z(38));
1216 		for_each_depth()
1217 		s8(y(27, 42), y(28, 43), y(29, 44),
1218 			y(30, 45), y(31, 46), y(0, 47),
1219 			z(36), z(58), z(46), z(52));
1220 
1221 		for_each_depth()
1222 		s1(y(63, 48), y(32, 49), y(33, 50),
1223 			y(34, 51), y(35, 52), y(36, 53),
1224 			z(8), z(16), z(22), z(30));
1225 		for_each_depth()
1226 		s2(y(35, 54), y(36, 55), y(37, 56),
1227 			y(38, 57), y(39, 58), y(40, 59),
1228 			z(12), z(27), z(1), z(17));
1229 		for_each_depth()
1230 		s3(y(39, 60), y(40, 61), y(41, 62),
1231 			y(42, 63), y(43, 64), y(44, 65),
1232 			z(23), z(15), z(29), z(5));
1233 		for_each_depth()
1234 		s4(y(43, 66), y(44, 67), y(45, 68),
1235 			y(46, 69), y(47, 70), y(48, 71),
1236 			z(25), z(19), z(9), z(0));
1237 		for_each_depth()
1238 		s5(y(47, 72), y(48, 73), y(49, 74),
1239 			y(50, 75), y(51, 76), y(52, 77),
1240 			z(7), z(13), z(24), z(2));
1241 		for_each_depth()
1242 		s6(y(51, 78), y(52, 79), y(53, 80),
1243 			y(54, 81), y(55, 82), y(56, 83),
1244 			z(3), z(28), z(10), z(18));
1245 		for_each_depth()
1246 		s7(y(55, 84), y(56, 85), y(57, 86),
1247 			y(58, 87), y(59, 88), y(60, 89),
1248 			z(31), z(11), z(21), z(6));
1249 		for_each_depth()
1250 		s8(y(59, 90), y(60, 91), y(61, 92),
1251 			y(62, 93), y(63, 94), y(32, 95),
1252 			z(4), z(26), z(14), z(20));
1253 
1254 		k += 96;
1255 	} while (--rounds);
1256 }}
1257 #endif
1258 
1259 #ifdef INDX
1260 #undef INDX
1261 #endif
1262 
1263 #if DES_BS_VECTOR
1264 #define INDX [k]
1265 #else
1266 #define INDX
1267 #endif
1268 
DES_bs_generate_plaintext(unsigned char * plaintext)1269 void DES_bs_generate_plaintext(unsigned char *plaintext)
1270 {
1271 	int i, j;
1272 #if DES_BS_VECTOR
1273 	int k;
1274 #endif
1275 
1276 	/* Set same plaintext for all bit layers */
1277 	for (i = 0; i < 64; i++) {
1278 		j = (int) (plaintext[i/8] >> (7-(i%8))) & 0x01;
1279 		if (j==1)
1280 				j = -1;
1281 #if DES_BS_VECTOR
1282 		for (k=0; k<DES_BS_VECTOR_SIZE; k++)
1283 #endif
1284 			DES_bs_P[i]INDX = j;
1285 		}
1286 }
1287