-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathx86-mmx.S
1410 lines (1364 loc) · 28.9 KB
/
x86-mmx.S
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* This file contains the core of a bitslice DES implementation for x86/MMX.
* It is part of John the Ripper password cracker,
* Copyright (c) 2000-2001,2005,2006,2008,2011,2012,2015 by Solar Designer
* Redistribution and use in source and binary forms, with or without
* modification, are permitted. (This is a heavily cut-down "BSD license".)
*
* Gate counts per S-box: 49 44 46 33 48 46 46 41
* Average: 44.125
*
* The Boolean expressions corresponding to DES S-boxes have been generated
* by Roman Rusakov <roman_rus at openwall.com> for use in Openwall's
* John the Ripper password cracker: http://www.openwall.com/john/
* Being mathematical formulas, they are not copyrighted and are free for reuse
* by anyone.
*
* The x86/MMX code for the S-boxes was generated by Solar Designer using a
* Perl script, hand-optimized, and then had its instruction scheduling tuned
* on a Pentium 3 using a brute-force instruction scheduling program running
* the individual S-boxes in a context similar to that of this file.
*
* The effort has been sponsored by Rapid7: http://www.rapid7.com
*
* Note: there's some MMX code in x86.S as well (just not for bitslice DES).
*/
#include "arch.h"
#if DES_BS_ASM
#ifdef UNDERSCORES
#define DES_bs_all _DES_bs_all
#define DES_bs_init_asm _DES_bs_init_asm
#define DES_bs_crypt _DES_bs_crypt
#define DES_bs_crypt_25 _DES_bs_crypt_25
#define DES_bs_crypt_LM _DES_bs_crypt_LM
#endif
/*
* Some broken systems don't offer section alignments larger than 4 bytes,
* while for the MMX code we need at least an 8 byte alignment. ALIGN_FIX
* is here to work around this issue when we happen to get bad addresses.
*/
#ifndef ALIGN_FIX
#ifdef ALIGN_LOG
#define DO_ALIGN(log) .align log
#else
#define DO_ALIGN(log) .align 1 << log
#endif
#else
#ifdef ALIGN_LOG
#define DO_ALIGN(log) .align log; .space 4
#else
#define DO_ALIGN(log) .align 1 << log; .space 4
#endif
#endif
#ifdef __sun
/* Sun's assembler doesn't recognize .space */
#define DO_SPACE(size) .zero size
#else
/* Mac OS X assembler doesn't recognize .zero */
#define DO_SPACE(size) .space size
#endif
/* Sun's assembler can't multiply, but at least it can add... */
#define nptr(n) n+n+n+n
#define nvec(n) n+n+n+n+n+n+n+n
#ifdef BSD
.data
#else
.bss
#endif
.globl DES_bs_all
DO_ALIGN(5)
DES_bs_all:
DES_bs_all_KSp:
DO_SPACE(nptr(0x300))
DES_bs_all_KS_p:
DES_bs_all_KS_v:
DO_SPACE(nvec(0x300))
DES_bs_all_E:
DO_SPACE(nptr(96))
DES_bs_all_K:
DO_SPACE(nvec(56))
DES_bs_all_B:
DO_SPACE(nvec(64))
DES_bs_all_tmp:
DO_SPACE(nvec(16))
DES_bs_all_xkeys:
DO_SPACE(nvec(64))
DES_bs_all_pxkeys:
DO_SPACE(nptr(64))
DES_bs_all_keys_changed:
DO_SPACE(4)
DES_bs_all_salt:
DO_SPACE(4)
DES_bs_all_Ens:
DO_SPACE(nptr(48))
#define E(i) DES_bs_all_E+nptr(i)
#define B(i) DES_bs_all_B+nvec(i)
#define tmp_at(i) DES_bs_all_tmp+nvec(i)
#define pnot tmp_at(0)
#define S1(out1, out2, out3, out4) \
movq %mm0,tmp_at(1); \
movq %mm5,%mm7; \
movq %mm4,tmp_at(4); \
movq %mm2,%mm6; \
movq %mm1,tmp_at(2); \
por %mm2,%mm7; \
movq %mm3,tmp_at(3); \
pxor %mm0,%mm6; \
movq %mm7,tmp_at(5); \
movq %mm6,%mm1; \
pandn %mm0,%mm4; \
pand %mm7,%mm1; \
movq %mm1,%mm7; \
por %mm5,%mm7; \
pxor %mm3,%mm1; \
pxor %mm4,%mm3; \
movq %mm1,tmp_at(6); \
movq %mm3,%mm1; \
pandn tmp_at(6),%mm3; \
movq %mm3,tmp_at(7); \
movq %mm5,%mm3; \
por %mm0,%mm5; \
pxor tmp_at(4),%mm3; \
movq %mm3,tmp_at(8); \
movq %mm5,%mm0; \
pandn %mm3,%mm6; \
pxor %mm2,%mm3; \
pandn %mm2,%mm4; \
pandn %mm1,%mm3; \
pxor %mm3,%mm7; \
movq tmp_at(7),%mm3; \
pandn tmp_at(3),%mm5; \
por %mm7,%mm0; \
pandn %mm7,%mm3; \
movq %mm3,tmp_at(9); \
pand tmp_at(5),%mm7; \
movq tmp_at(6),%mm3; \
movq %mm0,%mm2; \
pxor %mm1,%mm2; \
pandn tmp_at(4),%mm3; \
pandn %mm2,%mm4; \
movq tmp_at(2),%mm2; \
pxor %mm4,%mm7; \
pxor tmp_at(8),%mm4; \
pxor %mm3,%mm5; \
por %mm3,%mm4; \
pxor tmp_at(1),%mm4; \
pxor %mm0,%mm3; \
pandn %mm3,%mm2; \
pxor tmp_at(5),%mm0; \
movq tmp_at(7),%mm3; \
por tmp_at(2),%mm3; \
pxor pnot,%mm7; \
pxor out1,%mm3; \
pxor %mm7,%mm2; \
pxor tmp_at(5),%mm4; \
pxor out3,%mm2; \
pxor %mm4,%mm7; \
pxor %mm7,%mm3; \
movq %mm3,out1; \
por %mm6,%mm5; \
por tmp_at(8),%mm7; \
por %mm5,%mm0; \
pxor out2,%mm7; \
pxor %mm4,%mm0; \
pxor %mm0,%mm7; \
por tmp_at(4),%mm1; \
movq tmp_at(2),%mm3; \
pand tmp_at(9),%mm4; \
pandn %mm1,%mm0; \
pxor %mm0,%mm4; \
por tmp_at(9),%mm3; \
por tmp_at(2),%mm4; \
movq %mm2,out3; \
pxor %mm3,%mm7; \
pxor %mm5,%mm4; \
pxor out4,%mm4; \
movq %mm7,out2; \
movq %mm4,out4
#define S2(out1, out2, out3, out4) \
movq %mm2,tmp_at(2); \
movq %mm1,tmp_at(1); \
movq %mm5,%mm2; \
movq %mm4,tmp_at(4); \
pandn %mm0,%mm2; \
movq %mm3,tmp_at(3); \
pandn %mm4,%mm2; \
movq %mm0,%mm6; \
movq %mm2,%mm7; \
pxor pnot,%mm0; \
por %mm1,%mm7; \
pxor %mm4,%mm1; \
movq %mm7,tmp_at(5); \
pand %mm1,%mm6; \
movq %mm5,%mm7; \
pxor %mm4,%mm6; \
pandn %mm1,%mm7; \
movq %mm3,%mm4; \
pxor %mm7,%mm2; \
pandn %mm6,%mm7; \
pxor %mm5,%mm1; \
movq %mm7,tmp_at(7); \
movq %mm5,%mm7; \
pand tmp_at(2),%mm5; \
pand tmp_at(5),%mm2; \
movq %mm5,tmp_at(8); \
pandn %mm2,%mm5; \
pand tmp_at(2),%mm2; \
movq tmp_at(8),%mm7; \
pandn tmp_at(3),%mm5; \
pandn %mm1,%mm7; \
pxor %mm2,%mm0; \
movq %mm7,%mm3; \
pxor %mm0,%mm3; \
pxor out2,%mm5; \
pandn tmp_at(1),%mm7; \
pxor %mm6,%mm7; \
pxor %mm3,%mm5; \
movq %mm7,%mm6; \
movq %mm5,out2; \
movq tmp_at(7),%mm5; \
pandn tmp_at(5),%mm4; \
pandn %mm0,%mm6; \
pxor tmp_at(5),%mm3; \
movq %mm1,%mm0; \
pxor %mm4,%mm6; \
pxor tmp_at(2),%mm0; \
pxor %mm0,%mm6; \
movq %mm0,%mm4; \
pxor out1,%mm6; \
pandn tmp_at(1),%mm0; \
pxor tmp_at(4),%mm2; \
pxor %mm3,%mm0; \
movq %mm6,out1; \
por %mm1,%mm3; \
por tmp_at(8),%mm0; \
pxor %mm4,%mm0; \
movq %mm0,%mm4; \
pandn tmp_at(2),%mm0; \
movq tmp_at(3),%mm6; \
pxor tmp_at(7),%mm0; \
por %mm7,%mm0; \
por %mm6,%mm5; \
pxor %mm0,%mm2; \
pandn %mm2,%mm7; \
por %mm2,%mm6; \
pxor out4,%mm7; \
pxor %mm4,%mm6; \
pxor out3,%mm6; \
pxor %mm5,%mm7; \
pxor %mm3,%mm7; \
movq %mm6,out3; \
movq %mm7,out4
#define S3(out1, out2, out3, out4) \
movq %mm0,tmp_at(1); \
movq %mm1,tmp_at(2); \
movq %mm0,%mm7; \
pandn %mm0,%mm1; \
movq %mm2,tmp_at(3); \
movq %mm5,%mm0; \
pxor %mm2,%mm0; \
movq %mm4,tmp_at(4); \
movq %mm5,%mm2; \
por %mm0,%mm1; \
pxor %mm3,%mm2; \
movq %mm0,%mm4; \
movq %mm5,%mm6; \
pandn %mm2,%mm7; \
pxor tmp_at(2),%mm4; \
movq %mm7,tmp_at(5); \
pxor %mm1,%mm7; \
pandn %mm4,%mm6; \
movq %mm7,tmp_at(6); \
pxor %mm6,%mm1; \
pand %mm0,%mm2; \
movq %mm1,%mm6; \
movq %mm3,%mm0; \
pandn %mm7,%mm6; \
pand %mm5,%mm7; \
pand %mm3,%mm5; \
por %mm3,%mm7; \
pand tmp_at(1),%mm7; \
movq tmp_at(4),%mm3; \
pandn tmp_at(6),%mm3; \
pxor %mm4,%mm7; \
pxor tmp_at(1),%mm0; \
movq %mm7,tmp_at(7); \
pxor %mm3,%mm7; \
movq tmp_at(2),%mm3; \
pxor out4,%mm7; \
pxor %mm0,%mm1; \
movq %mm7,out4; \
movq tmp_at(3),%mm7; \
por tmp_at(3),%mm1; \
pandn %mm1,%mm2; \
por tmp_at(5),%mm0; \
movq %mm0,%mm1; \
pandn %mm5,%mm3; \
pandn tmp_at(7),%mm1; \
por %mm4,%mm5; \
pxor %mm3,%mm1; \
por tmp_at(2),%mm7; \
movq tmp_at(3),%mm3; \
pandn %mm1,%mm3; \
pxor %mm4,%mm0; \
pandn %mm5,%mm3; \
movq tmp_at(4),%mm5; \
pxor tmp_at(1),%mm3; \
pand %mm2,%mm5; \
pxor pnot,%mm0; \
pxor %mm5,%mm3; \
movq %mm7,%mm5; \
pxor out2,%mm3; \
pandn tmp_at(4),%mm6; \
pandn tmp_at(6),%mm7; \
pxor %mm0,%mm6; \
movq %mm3,out2; \
pxor tmp_at(1),%mm2; \
por tmp_at(4),%mm1; \
por %mm2,%mm0; \
pxor tmp_at(6),%mm5; \
pxor %mm1,%mm0; \
pxor out1,%mm6; \
pxor out3,%mm5; \
pxor tmp_at(7),%mm0; \
pxor %mm7,%mm6; \
pxor %mm5,%mm0; \
movq %mm6,out1; \
movq %mm0,out3
#define S4(out1, out2, out3, out4) \
movq %mm1,%mm7; \
pxor %mm2,%mm0; \
por %mm3,%mm1; \
pxor %mm4,%mm2; \
movq %mm5,tmp_at(2); \
pxor %mm4,%mm1; \
movq %mm7,%mm6; \
movq %mm7,%mm5; \
pandn %mm2,%mm7; \
pandn %mm2,%mm1; \
por %mm7,%mm4; \
pxor %mm3,%mm7; \
movq %mm7,%mm6; \
por %mm0,%mm7; \
pxor %mm5,%mm3; \
movq %mm1,tmp_at(3); \
pandn %mm7,%mm1; \
movq %mm1,%mm7; \
pxor %mm5,%mm1; \
pand %mm1,%mm6; \
movq %mm6,%mm5; \
pxor %mm1,%mm0; \
pandn %mm2,%mm6; \
pandn %mm0,%mm6; \
pxor %mm0,%mm4; \
movq %mm3,%mm0; \
pandn %mm4,%mm3; \
movq tmp_at(2),%mm2; \
pxor %mm7,%mm3; \
pxor tmp_at(3),%mm6; \
movq %mm6,%mm7; \
pandn %mm2,%mm6; \
pxor out1,%mm6; \
pandn %mm7,%mm2; \
pxor out2,%mm2; \
pxor %mm3,%mm6; \
pxor pnot,%mm3; \
pxor %mm3,%mm2; \
pxor %mm7,%mm3; \
movq %mm6,out1; \
pandn %mm3,%mm0; \
por %mm5,%mm0; \
movq %mm2,out2; \
movq tmp_at(2),%mm3; \
por %mm1,%mm3; \
pand tmp_at(2),%mm1; \
pxor %mm4,%mm0; \
pxor %mm0,%mm3; \
pxor out3,%mm3; \
pxor %mm1,%mm0; \
movq %mm3,out3; \
pxor out4,%mm0; \
movq %mm0,out4
#define S5(out1, out2, out3, out4) \
movq %mm2,tmp_at(3); \
movq %mm0,tmp_at(1); \
por %mm0,%mm2; \
movq %mm5,%mm6; \
movq %mm2,tmp_at(4); \
pandn %mm2,%mm5; \
movq %mm2,%mm7; \
movq %mm5,%mm2; \
pxor %mm0,%mm5; \
movq %mm3,%mm7; \
movq %mm5,tmp_at(5); \
pxor tmp_at(3),%mm5; \
movq %mm1,tmp_at(2); \
por %mm5,%mm0; \
por %mm3,%mm5; \
pandn %mm2,%mm3; \
pxor tmp_at(3),%mm3; \
movq %mm3,tmp_at(6); \
movq %mm0,%mm1; \
pand %mm4,%mm3; \
pxor %mm0,%mm3; \
pand %mm7,%mm0; \
pxor %mm7,%mm3; \
movq %mm3,tmp_at(3); \
pxor %mm3,%mm6; \
movq %mm6,%mm2; \
por tmp_at(5),%mm6; \
movq %mm6,%mm3; \
pand %mm4,%mm6; \
movq %mm6,tmp_at(7); \
pxor tmp_at(5),%mm6; \
pxor %mm6,%mm0; \
movq tmp_at(1),%mm6; \
movq %mm0,tmp_at(8); \
pandn %mm3,%mm6; \
movq tmp_at(2),%mm0; \
movq %mm6,%mm3; \
pxor tmp_at(6),%mm6; \
pxor %mm5,%mm4; \
pandn %mm4,%mm6; \
pxor pnot,%mm6; \
pandn %mm6,%mm0; \
pxor tmp_at(3),%mm0; \
movq tmp_at(7),%mm6; \
pandn tmp_at(6),%mm6; \
pxor out3,%mm0; \
pxor %mm4,%mm3; \
movq %mm0,out3; \
por tmp_at(8),%mm3; \
movq tmp_at(6),%mm0; \
pandn %mm3,%mm6; \
pand tmp_at(6),%mm1; \
pand %mm6,%mm2; \
movq %mm6,%mm3; \
pandn %mm5,%mm6; \
pxor %mm4,%mm2; \
por %mm2,%mm1; \
pxor tmp_at(4),%mm3; \
pxor tmp_at(7),%mm1; \
pand %mm2,%mm7; \
pand tmp_at(2),%mm1; \
pxor tmp_at(1),%mm7; \
pxor tmp_at(8),%mm1; \
pxor %mm7,%mm3; \
por tmp_at(2),%mm6; \
pxor out4,%mm1; \
movq %mm1,out4; \
pxor %mm5,%mm0; \
pxor tmp_at(5),%mm2; \
pxor %mm3,%mm6; \
pandn %mm0,%mm3; \
pand tmp_at(2),%mm5; \
pxor %mm2,%mm3; \
pxor out2,%mm5; \
pxor %mm5,%mm3; \
pxor out1,%mm6; \
movq %mm3,out2; \
movq %mm6,out1
#define S6(out1, out2, out3, out4) \
movq %mm4,tmp_at(2); \
pxor %mm1,%mm4; \
movq %mm5,tmp_at(3); \
por %mm1,%mm5; \
movq %mm2,%mm7; \
pand %mm0,%mm5; \
pxor %mm0,%mm2; \
movq %mm0,tmp_at(1); \
pxor %mm5,%mm4; \
movq %mm4,tmp_at(4); \
pxor tmp_at(3),%mm4; \
movq %mm4,%mm6; \
pandn tmp_at(2),%mm4; \
pand %mm0,%mm6; \
movq %mm6,tmp_at(5); \
pxor %mm1,%mm6; \
movq %mm6,tmp_at(6); \
por %mm2,%mm6; \
movq %mm6,tmp_at(7); \
pxor tmp_at(4),%mm6; \
movq %mm6,%mm0; \
pand %mm7,%mm6; \
movq %mm6,tmp_at(8); \
movq tmp_at(3),%mm6; \
por %mm1,%mm2; \
pandn tmp_at(8),%mm6; \
movq %mm6,tmp_at(9); \
movq tmp_at(6),%mm6; \
por %mm4,%mm6; \
movq %mm6,tmp_at(6); \
pxor tmp_at(9),%mm6; \
movq %mm6,tmp_at(10); \
pand %mm3,%mm6; \
pxor out4,%mm6; \
pxor %mm0,%mm6; \
por tmp_at(1),%mm0; \
movq %mm6,out4; \
movq tmp_at(7),%mm6; \
pxor %mm1,%mm6; \
movq %mm3,%mm1; \
movq %mm6,tmp_at(7); \
pandn tmp_at(3),%mm6; \
pxor %mm7,%mm6; \
movq tmp_at(8),%mm7; \
movq %mm6,tmp_at(12); \
pandn tmp_at(2),%mm7; \
pand tmp_at(6),%mm0; \
por %mm6,%mm7; \
pxor %mm6,%mm0; \
movq tmp_at(9),%mm6; \
por %mm3,%mm4; \
pandn %mm0,%mm6; \
por %mm7,%mm5; \
pxor %mm4,%mm6; \
pxor tmp_at(4),%mm0; \
pxor out3,%mm6; \
pxor %mm2,%mm5; \
movq %mm6,out3; \
movq tmp_at(5),%mm6; \
pandn tmp_at(2),%mm0; \
pxor pnot,%mm2; \
pxor tmp_at(7),%mm2; \
pxor tmp_at(3),%mm6; \
pxor out2,%mm5; \
movq tmp_at(12),%mm4; \
pxor %mm2,%mm0; \
pxor tmp_at(1),%mm4; \
pxor tmp_at(10),%mm5; \
pand %mm6,%mm4; \
pandn %mm0,%mm3; \
pxor out1,%mm4; \
pandn %mm7,%mm1; \
pxor tmp_at(8),%mm4; \
pxor %mm2,%mm1; \
pxor %mm3,%mm5; \
movq %mm5,out2; \
pxor %mm1,%mm4; \
movq %mm4,out1
#define S7(out1, out2, out3, out4) \
movq %mm0,tmp_at(1); \
movq %mm4,tmp_at(3); \
movq %mm4,%mm0; \
pxor %mm3,%mm4; \
movq %mm5,tmp_at(4); \
movq %mm4,%mm7; \
movq %mm3,tmp_at(2); \
pxor %mm2,%mm4; \
movq %mm4,tmp_at(5); \
pand %mm5,%mm4; \
movq %mm7,%mm5; \
pxor tmp_at(4),%mm5; \
pand %mm3,%mm7; \
movq %mm7,tmp_at(6); \
movq %mm7,%mm6; \
pxor %mm1,%mm7; \
pand tmp_at(4),%mm6; \
pxor %mm2,%mm6; \
movq %mm7,tmp_at(7); \
movq tmp_at(1),%mm3; \
movq %mm6,%mm0; \
por %mm7,%mm6; \
pand %mm4,%mm7; \
pxor %mm5,%mm6; \
pandn %mm3,%mm7; \
pxor %mm4,%mm0; \
pxor out4,%mm7; \
pxor %mm5,%mm4; \
pxor %mm6,%mm7; \
movq %mm7,out4; \
pandn tmp_at(2),%mm4; \
por tmp_at(6),%mm6; \
movq tmp_at(5),%mm7; \
pandn tmp_at(3),%mm7; \
pandn tmp_at(7),%mm4; \
movq %mm7,tmp_at(9); \
por tmp_at(7),%mm7; \
pandn tmp_at(5),%mm5; \
pxor %mm0,%mm7; \
pxor tmp_at(3),%mm0; \
pxor %mm4,%mm0; \
movq tmp_at(1),%mm4; \
pand %mm0,%mm2; \
por %mm2,%mm6; \
pxor %mm5,%mm6; \
pandn %mm6,%mm3; \
movq %mm6,%mm5; \
pxor %mm7,%mm3; \
pxor %mm6,%mm7; \
por %mm0,%mm6; \
pxor out1,%mm3; \
pand tmp_at(4),%mm6; \
pxor pnot,%mm5; \
pand %mm6,%mm1; \
pxor out3,%mm0; \
pxor %mm7,%mm1; \
movq %mm3,out1; \
movq %mm4,%mm3; \
pxor tmp_at(3),%mm7; \
por %mm1,%mm2; \
pxor %mm6,%mm2; \
por %mm2,%mm7; \
pand %mm7,%mm4; \
pxor %mm6,%mm7; \
por tmp_at(9),%mm7; \
pxor %mm5,%mm7; \
pxor out2,%mm1; \
pandn %mm7,%mm3; \
pxor %mm4,%mm0; \
movq %mm0,out3; \
pxor %mm3,%mm1; \
movq %mm1,out2
#define S8(out1, out2, out3, out4) \
movq %mm2,%mm7; \
movq %mm1,tmp_at(1); \
pandn %mm2,%mm1; \
movq %mm2,tmp_at(2); \
pandn %mm4,%mm2; \
movq %mm3,tmp_at(3); \
pxor %mm3,%mm2; \
movq %mm4,tmp_at(4); \
movq %mm1,%mm3; \
movq %mm5,tmp_at(5); \
movq %mm2,%mm4; \
movq %mm2,%mm5; \
pandn tmp_at(1),%mm4; \
pand %mm0,%mm2; \
pandn tmp_at(1),%mm7; \
pandn %mm2,%mm1; \
pxor tmp_at(4),%mm7; \
movq %mm4,%mm6; \
por %mm0,%mm4; \
movq %mm7,tmp_at(6); \
pand %mm4,%mm7; \
pxor pnot,%mm5; \
por %mm7,%mm2; \
pxor %mm7,%mm5; \
pandn tmp_at(2),%mm4; \
movq tmp_at(5),%mm7; \
pxor %mm4,%mm5; \
por %mm1,%mm7; \
pxor %mm5,%mm3; \
pxor %mm3,%mm7; \
pxor %mm0,%mm3; \
pxor out2,%mm7; \
movq %mm7,out2; \
pxor tmp_at(1),%mm5; \
movq %mm3,%mm4; \
pand tmp_at(4),%mm3; \
pxor %mm5,%mm3; \
por tmp_at(3),%mm5; \
pxor %mm3,%mm6; \
pxor tmp_at(6),%mm5; \
pxor %mm2,%mm3; \
pxor %mm6,%mm5; \
por tmp_at(1),%mm3; \
pxor %mm5,%mm0; \
pxor %mm4,%mm3; \
por tmp_at(3),%mm4; \
pxor tmp_at(4),%mm3; \
pand tmp_at(5),%mm2; \
pandn %mm3,%mm4; \
pand tmp_at(5),%mm0; \
pxor %mm6,%mm0; \
por %mm1,%mm4; \
pxor out4,%mm0; \
pxor %mm4,%mm5; \
pxor out3,%mm2; \
por tmp_at(5),%mm5; \
pxor out1,%mm5; \
pxor %mm3,%mm2; \
pxor %mm6,%mm5; \
movq %mm0,out4; \
movq %mm2,out3; \
movq %mm5,out1
#define zero %mm5
#define DES_bs_clear_block_8(i) \
movq zero,B(i); \
movq zero,B(i + 1); \
movq zero,B(i + 2); \
movq zero,B(i + 3); \
movq zero,B(i + 4); \
movq zero,B(i + 5); \
movq zero,B(i + 6); \
movq zero,B(i + 7)
#define DES_bs_clear_block \
DES_bs_clear_block_8(0); \
DES_bs_clear_block_8(8); \
DES_bs_clear_block_8(16); \
DES_bs_clear_block_8(24); \
DES_bs_clear_block_8(32); \
DES_bs_clear_block_8(40); \
DES_bs_clear_block_8(48); \
DES_bs_clear_block_8(56)
#define k_ptr %edx
#define K(i) nvec(i)(k_ptr)
#define k(i) nptr(i)(k_ptr)
#define a1 %mm0
#define a2 %mm1
#define a3 %mm2
#define a4 %mm3
#define a5 %mm4
#define a6 %mm5
#define tmp1 %ecx
#define tmp2 %esi
#define xor_E(i) \
movl E(i),tmp1; \
movq K(i),a1; \
movl E(i + 1),tmp2; \
movq K(i + 1),a2; \
pxor (tmp1),a1; \
pxor (tmp2),a2; \
movl E(i + 2),tmp1; \
movq K(i + 2),a3; \
movl E(i + 3),tmp2; \
movq K(i + 3),a4; \
pxor (tmp1),a3; \
pxor (tmp2),a4; \
movl E(i + 4),tmp1; \
movq K(i + 4),a5; \
movl E(i + 5),tmp2; \
movq K(i + 5),a6; \
pxor (tmp1),a5; \
pxor (tmp2),a6
#define xor_B(b1, k1, b2, k2, b3, k3, b4, k4, b5, k5, b6, k6) \
movq B(b1),a1; \
movq B(b2),a2; \
pxor K(k1),a1; \
movq B(b3),a3; \
pxor K(k2),a2; \
movq B(b4),a4; \
pxor K(k3),a3; \
movq B(b5),a5; \
pxor K(k4),a4; \
movq B(b6),a6; \
pxor K(k5),a5; \
pxor K(k6),a6
#define xor_B_KS_p_prefix(b1, k1, b2, k2, b3, k3, b4, k4, k6) \
movl k(k1),tmp1; \
movl k(k2),tmp2; \
movq B(b1),a1; \
movq B(b2),a2; \
pxor (tmp1),a1; \
movl k(k3),tmp1; \
pxor (tmp2),a2; \
movl k(k4),tmp2; \
movq B(b3),a3; \
movq B(b4),a4; \
pxor (tmp1),a3; \
movl k(k6),tmp1; \
pxor (tmp2),a4
#define xor_B_KS_p_suffix(b5, k5) \
movl k(k5),tmp2; \
movq B(b5),a5; \
pxor (tmp1),a6; \
pxor (tmp2),a5
#define xor_B_KS_p(b1, k1, b2, k2, b3, k3, b4, k4, b5, k5, b6, k6) \
xor_B_KS_p_prefix(b1, k1, b2, k2, b3, k3, b4, k4, k6); \
movq B(b6),a6; \
xor_B_KS_p_suffix(b5, k5)
#define xor_B_KS_p_special(b1, k1, b2, k2, b3, k3, b4, k4, b5, k5, k6) \
xor_B_KS_p_prefix(b1, k1, b2, k2, b3, k3, b4, k4, k6); \
xor_B_KS_p_suffix(b5, k5)
#define mask01 tmp_at(15)
#define v_ptr %eax
#define V(i) nvec(i)(v_ptr)
#if 1
#define SHLB1(reg) paddb reg,reg
#else
#define SHLB1(reg) psllq $1,reg
#endif
#define FINALIZE_NEXT_KEY_BITS_0_6 \
movq mask01,%mm7; \
\
movq V(0),%mm0; \
movq V(1),%mm1; \
movq V(2),%mm2; \
movq V(3),%mm3; \
pand %mm7,%mm0; \
pand %mm7,%mm1; \
pand %mm7,%mm2; \
pand %mm7,%mm3; \
SHLB1(%mm1); \
psllq $2,%mm2; \
psllq $3,%mm3; \
por %mm0,%mm1; \
por %mm2,%mm3; \
movq V(4),%mm4; \
movq V(5),%mm5; \
por %mm1,%mm3; \
pand %mm7,%mm4; \
pand %mm7,%mm5; \
movq V(6),%mm6; \
movq V(7),%mm0; \
psllq $4,%mm4; \
pand %mm7,%mm6; \
pand %mm7,%mm0; \
psllq $5,%mm5; \
psllq $6,%mm6; \
psllq $7,%mm0; \
por %mm4,%mm5; \
por %mm6,%mm3; \
por %mm5,%mm0; \
movq V(1),%mm1; \
por %mm3,%mm0; \
SHLB1(%mm7); \
movq %mm0,K(0); \
\
movq V(0),%mm0; \
movq V(2),%mm2; \
movq V(3),%mm3; \
pand %mm7,%mm0; \
pand %mm7,%mm1; \
pand %mm7,%mm2; \
pand %mm7,%mm3; \
psrlq $1,%mm0; \
SHLB1(%mm2); \
psllq $2,%mm3; \
por %mm0,%mm1; \
por %mm2,%mm3; \
movq V(4),%mm4; \
movq V(5),%mm5; \
por %mm1,%mm3; \
pand %mm7,%mm4; \
pand %mm7,%mm5; \
movq V(6),%mm6; \
movq V(7),%mm0; \
psllq $3,%mm4; \
pand %mm7,%mm6; \
pand %mm7,%mm0; \
psllq $4,%mm5; \
psllq $5,%mm6; \
psllq $6,%mm0; \
por %mm4,%mm5; \
por %mm6,%mm3; \
por %mm5,%mm0; \
movq V(1),%mm1; \
por %mm3,%mm0; \
SHLB1(%mm7); \
movq %mm0,K(1); \
\
movq V(0),%mm0; \
movq V(2),%mm2; \
movq V(3),%mm3; \
pand %mm7,%mm0; \
pand %mm7,%mm1; \
pand %mm7,%mm2; \
pand %mm7,%mm3; \
psrlq $2,%mm0; \
psrlq $1,%mm1; \
SHLB1(%mm3); \
por %mm0,%mm1; \
por %mm2,%mm3; \
movq V(4),%mm4; \
movq V(5),%mm5; \
por %mm1,%mm3; \
pand %mm7,%mm4; \
pand %mm7,%mm5; \
movq V(6),%mm6; \
movq V(7),%mm0; \
psllq $2,%mm4; \
pand %mm7,%mm6; \
pand %mm7,%mm0; \
psllq $3,%mm5; \
psllq $4,%mm6; \
psllq $5,%mm0; \
por %mm4,%mm5; \
por %mm6,%mm3; \
por %mm5,%mm0; \
movq V(1),%mm1; \
por %mm3,%mm0; \
SHLB1(%mm7); \
movq %mm0,K(2); \
\
movq V(0),%mm0; \
movq V(2),%mm2; \
movq V(3),%mm3; \
pand %mm7,%mm0; \
pand %mm7,%mm1; \
pand %mm7,%mm2; \
pand %mm7,%mm3; \
psrlq $3,%mm0; \
psrlq $2,%mm1; \
psrlq $1,%mm2; \
por %mm0,%mm1; \
por %mm2,%mm3; \
movq V(4),%mm4; \
movq V(5),%mm5; \
por %mm1,%mm3; \
pand %mm7,%mm4; \
pand %mm7,%mm5; \
movq V(6),%mm6; \
movq V(7),%mm0; \
SHLB1(%mm4); \
pand %mm7,%mm6; \
pand %mm7,%mm0; \
psllq $2,%mm5; \
psllq $3,%mm6; \
psllq $4,%mm0; \
por %mm4,%mm5; \
por %mm6,%mm3; \
por %mm5,%mm0; \
movq V(1),%mm1; \
por %mm3,%mm0; \
SHLB1(%mm7); \
movq %mm0,K(3); \
\
movq V(0),%mm0; \
movq V(2),%mm2; \
movq V(3),%mm3; \
pand %mm7,%mm0; \
pand %mm7,%mm1; \
pand %mm7,%mm2; \
pand %mm7,%mm3; \
psrlq $4,%mm0; \
psrlq $3,%mm1; \
psrlq $2,%mm2; \
psrlq $1,%mm3; \
por %mm0,%mm1; \
por %mm2,%mm3; \
movq V(4),%mm4; \
movq V(5),%mm5; \
por %mm1,%mm3; \
pand %mm7,%mm4; \
pand %mm7,%mm5; \
movq V(6),%mm6; \
movq V(7),%mm0; \
pand %mm7,%mm6; \
pand %mm7,%mm0; \
SHLB1(%mm5); \
psllq $2,%mm6; \
psllq $3,%mm0; \
por %mm4,%mm5; \
por %mm6,%mm3; \
por %mm5,%mm0; \
movq V(1),%mm1; \
por %mm3,%mm0; \
SHLB1(%mm7); \
movq %mm0,K(4); \
\
movq V(0),%mm0; \
movq V(2),%mm2; \
movq V(3),%mm3; \
pand %mm7,%mm0; \
pand %mm7,%mm1; \
pand %mm7,%mm2; \
pand %mm7,%mm3; \
psrlq $5,%mm0; \
psrlq $4,%mm1; \
psrlq $3,%mm2; \
psrlq $2,%mm3; \
por %mm0,%mm1; \
por %mm2,%mm3; \
movq V(4),%mm4; \
movq V(5),%mm5; \
por %mm1,%mm3; \
pand %mm7,%mm4; \
pand %mm7,%mm5; \
movq V(6),%mm6; \
movq V(7),%mm0; \
psrlq $1,%mm4; \
pand %mm7,%mm6; \
pand %mm7,%mm0; \
SHLB1(%mm6); \
psllq $2,%mm0; \
por %mm4,%mm5; \