-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathx86.S
1450 lines (1351 loc) · 27.9 KB
/
x86.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 is part of John the Ripper password cracker,
* Copyright (c) 1996-2003,2006,2011,2019 by Solar Designer
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted.
*
* There's ABSOLUTELY NO WARRANTY, express or implied.
*/
/*
* x86 assembly routines.
*/
#include "arch.h"
#ifdef UNDERSCORES
#define DES_IV _DES_IV
#define DES_count _DES_count
#define DES_KS_current _DES_KS_current
#define DES_KS_copy _DES_KS_copy
#define DES_KS_table _DES_KS_table
#define DES_SPE_L _DES_SPE_L
#define DES_SPE_H _DES_SPE_H
#define DES_SPE_F _DES_SPE_F
#define DES_std_crypt _DES_std_crypt
#define DES_xor_key1 _DES_xor_key1
#define DES_xor_key2 _DES_xor_key2
#define MD5_body _MD5_body
#define BF_body _BF_body
#define BF_current _BF_current
#define CPU_detect _CPU_detect
#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)
#elif defined(DUMBAS)
#define DO_ALIGN(log) .align 1 << 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
/*
* DES stuff.
*
* Included are versions for:
* 1. MMX (Pentium MMX and newer Intel x86 CPUs, some clones);
* 2. Intel Pentium without MMX;
* 3. The rest (good for Pentium Pro, 486, clones).
*
* MMX has to be enabled at compile time (via DES_X2 in arch.h), while #2
* or #3 is chosen based on CPUID info at runtime.
*
* Note: MMX code for the bitslice DES implementation is in x86-mmx.S, so
* you probably want to look in there instead.
*/
.text
#if DES_X2
/*
* DES MMX routines.
*/
#define R %mm0
#define L %mm1
#define tmp1 %mm2
#define tmp2 %mm3
#define K1 %mm4
#define K2 %mm5
#define K3 %mm6
#define K4 %mm7
#define DES_copy(ofs1, ofs2) \
movq ofs1(%edx),%mm0; \
movq ofs2(%edx),%mm1; \
movq %mm0,DES_KS_copy+ofs1; \
movq %mm1,DES_KS_copy+ofs2
#define DES_2_ROUNDS_START(K) \
pxor R,tmp1; \
movd tmp1,%eax; \
movb %al,%bl; \
movb %ah,%dl; \
shrl $16,%eax; \
psrlq $32,tmp1; \
pxor DES_SPE_F(%ebx,%ebx),L; \
pxor DES_SPE_F+0x200(%edx,%edx),L; \
movb %al,%bl; \
movb %ah,%dl; \
movd tmp1,%eax; \
pxor DES_SPE_F+0x400(%ebx,%ebx),L; \
pxor DES_SPE_F+0x600(%edx,%edx),L; \
movb %al,%bl; \
movb %ah,%dl; \
shrl $16,%eax; \
pxor DES_SPE_F+0x800(%ebx,%ebx),L; \
pxor DES_SPE_F+0xA00(%edx,%edx),L; \
movb %al,%bl; \
movb %ah,%dl; \
movq K,tmp1; \
pxor DES_SPE_F+0xC00(%ebx,%ebx),L; \
pxor DES_SPE_F+0xE00(%edx,%edx),L; \
pxor L,tmp1; \
movd tmp1,%eax; \
movb %al,%bl; \
movb %ah,%dl; \
shrl $16,%eax; \
psrlq $32,tmp1; \
pxor DES_SPE_F(%ebx,%ebx),R; \
pxor DES_SPE_F+0x200(%edx,%edx),R; \
movb %al,%bl; \
movb %ah,%dl; \
movd tmp1,%eax; \
pxor DES_SPE_F+0x400(%ebx,%ebx),R; \
pxor DES_SPE_F+0x600(%edx,%edx),R; \
movb %al,%bl; \
movb %ah,%dl; \
shrl $16,%eax; \
pxor DES_SPE_F+0x800(%ebx,%ebx),R; \
pxor DES_SPE_F+0xA00(%edx,%edx),R; \
movb %al,%bl; \
movb %ah,%dl
#define DES_2_ROUNDS(K1, K2) \
DES_2_ROUNDS_START(K1); \
movq K2,tmp1; \
pxor DES_SPE_F+0xC00(%ebx,%ebx),R; \
pxor DES_SPE_F+0xE00(%edx,%edx),R
DO_ALIGN(12)
.globl DES_std_crypt
DES_std_crypt:
movl 4(%esp),%edx
pushl %ebx
movl DES_count,%ecx
xorl %ebx,%ebx
movq (%edx),K1
movq 32(%edx),K2
movq K1,tmp1
movq 8(%edx),K3
movq 16(%edx),K4
DES_copy(24, 40)
DES_copy(48, 56)
DES_copy(64, 96)
DES_copy(72, 80)
DES_copy(88, 104)
DES_copy(112, 120)
movq DES_IV,R
xorl %edx,%edx
movq DES_IV+8,L
DES_loop:
DES_2_ROUNDS(K3, K4)
DES_2_ROUNDS(DES_KS_copy+24, K2)
DES_2_ROUNDS(DES_KS_copy+40, DES_KS_copy+48)
DES_2_ROUNDS(DES_KS_copy+56, DES_KS_copy+64)
DES_2_ROUNDS(DES_KS_copy+72, DES_KS_copy+80)
DES_2_ROUNDS(DES_KS_copy+88, DES_KS_copy+96)
DES_2_ROUNDS(DES_KS_copy+104, DES_KS_copy+112)
DES_2_ROUNDS_START(DES_KS_copy+120)
movq K1,tmp1
pxor DES_SPE_F+0xC00(%ebx,%ebx),R
movq L,tmp2
pxor DES_SPE_F+0xE00(%edx,%edx),R
decl %ecx
movq R,L
movq tmp2,R
jnz DES_loop
movl 12(%esp),%edx
popl %ebx
movq R,(%edx)
movq L,8(%edx)
#ifdef EMMS
emms
#endif
ret
#define DES_xor1(ofs1, ofs2) \
movq DES_KS_current+ofs1,%mm0; \
movq DES_KS_current+ofs2,%mm1; \
pxor ofs1(%edx),%mm0; \
pxor ofs2(%edx),%mm1; \
movq %mm0,DES_KS_current+ofs1; \
movq %mm1,DES_KS_current+ofs2
DO_ALIGN(4)
.globl DES_xor_key1
DES_xor_key1:
movl 4(%esp),%edx
DES_xor1(0, 32)
DES_xor1(8, 16)
DES_xor1(24, 40)
DES_xor1(48, 56)
DES_xor1(64, 96)
DES_xor1(72, 80)
DES_xor1(88, 104)
DES_xor1(112, 120)
#ifdef EMMS
emms
#endif
ret
#define DES_xor2(ofs1, ofs2) \
movq DES_KS_current+ofs1,%mm0; \
movq DES_KS_current+ofs2,%mm1; \
pxor ofs1(%edx),%mm0; \
pxor ofs2(%edx),%mm1; \
pxor ofs1(%ecx),%mm0; \
pxor ofs2(%ecx),%mm1; \
movq %mm0,DES_KS_current+ofs1; \
movq %mm1,DES_KS_current+ofs2
DO_ALIGN(4)
.globl DES_xor_key2
DES_xor_key2:
movl 4(%esp),%edx
movl 8(%esp),%ecx
DES_xor2(0, 32)
DES_xor2(8, 16)
DES_xor2(24, 40)
DES_xor2(48, 56)
DES_xor2(64, 96)
DES_xor2(72, 80)
DES_xor2(88, 104)
DES_xor2(112, 120)
#ifdef EMMS
emms
#endif
ret
#else
/*
* DES non-MMX routines.
*/
#define Rl %ecx
#define Rh %ebp
#define Ll %esi
#define Lh %edi
#define DES_copy(ofs) \
movl ofs(%edx),%esi; \
movl ofs+4(%edx),%edi; \
movl %esi,DES_KS_copy+ofs; \
movl %edi,DES_KS_copy+ofs+4
#define DES_CRYPT_START \
movl 4(%esp),%edx; \
pushl %ebp; \
pushl %esi; \
pushl %edi; \
pushl %ebx; \
movl (%edx),%eax; \
movl 4(%edx),%edi; \
movl %eax,DES_KS_copy; \
movl %edi,DES_KS_copy+4; \
DES_copy(32); \
DES_copy(8); \
DES_copy(16); \
DES_copy(24); \
DES_copy(40); \
DES_copy(48); \
DES_copy(56); \
DES_copy(64); \
DES_copy(96); \
DES_copy(72); \
DES_copy(80); \
DES_copy(88); \
DES_copy(104); \
DES_copy(112); \
DES_copy(120); \
movl DES_IV,Rl; \
movl DES_IV+4,Rh; \
movl DES_IV+8,Ll; \
movl DES_IV+12,Lh; \
movl DES_count,%edx; \
xorl %ebx,%ebx; \
movl %edx,DES_count_tmp; \
xorl %edx,%edx
#define DES_CRYPT_END \
movl 24(%esp),%edx; \
popl %ebx; \
movl Rl,(%edx); \
movl Rh,4(%edx); \
movl Ll,8(%edx); \
movl Lh,12(%edx); \
popl %edi; \
popl %esi; \
popl %ebp; \
ret
/*
* Intel Pentium optimized version, extra operations are used to avoid
* imperfect pairing.
*/
#define DES_2_ROUNDS_START_P1(K) \
xorl Rl,%eax; \
movb %al,%bl; \
movb %ah,%dl; \
movl Rl,DES_SavedL; \
shrl $16,%eax; \
movl DES_SPE_L(%ebx),Rl; \
xorl Rl,Ll; \
movl DES_SPE_H(%ebx),Rl; \
xorl Rl,Lh; \
movl DES_SPE_L+0x100(%edx),Rl; \
xorl Rl,Ll; \
movl DES_SPE_H+0x100(%edx),Rl; \
movb %al,%bl; \
xorl Rl,Lh; \
movb %ah,%dl; \
movl K+4,%eax; \
movl DES_SPE_L+0x200(%ebx),Rl; \
xorl Rh,%eax; \
xorl Rl,Ll; \
movl DES_SPE_H+0x200(%ebx),Rl; \
xorl Rl,Lh; \
movl DES_SPE_L+0x300(%edx),Rl; \
xorl Rl,Ll; \
movb %al,%bl; \
movl DES_SPE_H+0x300(%edx),Rl; \
movb %ah,%dl; \
shrl $16,%eax; \
xorl Rl,Lh; \
movl DES_SPE_L+0x400(%ebx),Rl; \
xorl Rl,Ll; \
movl DES_SPE_H+0x400(%ebx),Rl; \
xorl Rl,Lh; \
movl DES_SPE_L+0x500(%edx),Rl; \
xorl Rl,Ll; \
movb %al,%bl; \
movl DES_SPE_H+0x500(%edx),Rl; \
movb %ah,%dl; \
xorl Rl,Lh; \
movl DES_SPE_L+0x600(%ebx),Rl; \
xorl Rl,Ll; \
movl DES_SPE_H+0x600(%ebx),Rl; \
xorl Rl,Lh; \
movl DES_SPE_L+0x700(%edx),Rl; \
xorl Rl,Ll; \
movl K+8,%eax; \
movl DES_SPE_H+0x700(%edx),Rl; \
xorl Ll,%eax; \
xorl Rl,Lh; \
movb %al,%bl; \
movl DES_SavedL,Rl; \
movb %ah,%dl; \
movl Ll,DES_SavedL; \
shrl $16,%eax; \
movl DES_SPE_L(%ebx),Ll; \
xorl Ll,Rl; \
movl DES_SPE_H(%ebx),Ll; \
xorl Ll,Rh; \
movl DES_SPE_L+0x100(%edx),Ll; \
xorl Ll,Rl; \
movl DES_SPE_H+0x100(%edx),Ll; \
movb %al,%bl; \
xorl Ll,Rh; \
movb %ah,%dl; \
movl K+12,%eax; \
movl DES_SPE_L+0x200(%ebx),Ll; \
xorl Lh,%eax; \
xorl Ll,Rl; \
movl DES_SPE_H+0x200(%ebx),Ll; \
xorl Ll,Rh; \
movl DES_SPE_L+0x300(%edx),Ll; \
xorl Ll,Rl; \
movb %al,%bl; \
movl DES_SPE_H+0x300(%edx),Ll; \
movb %ah,%dl; \
shrl $16,%eax; \
xorl Ll,Rh; \
movl DES_SPE_L+0x400(%ebx),Ll; \
xorl Ll,Rl; \
movl DES_SPE_H+0x400(%ebx),Ll; \
xorl Ll,Rh; \
movl DES_SPE_L+0x500(%edx),Ll; \
xorl Ll,Rl; \
movb %al,%bl; \
movl DES_SPE_H+0x500(%edx),Ll; \
movb %ah,%dl; \
xorl Ll,Rh; \
movl DES_SPE_L+0x600(%ebx),Ll; \
xorl Ll,Rl; \
movl DES_SPE_H+0x600(%ebx),Ll; \
xorl Ll,Rh; \
movl DES_SPE_L+0x700(%edx),Ll
#define DES_2_ROUNDS_P1(K) \
DES_2_ROUNDS_START_P1(K); \
xorl Ll,Rl; \
movl DES_SPE_H+0x700(%edx),Ll; \
xorl Ll,Rh; \
movl K+16,%eax; \
movl DES_SavedL,Ll
DO_ALIGN(12)
DES_std_crypt_P1:
DES_CRYPT_START
DES_loop_P1:
DES_2_ROUNDS_P1(DES_KS_copy)
DES_2_ROUNDS_P1(DES_KS_copy+16)
DES_2_ROUNDS_P1(DES_KS_copy+32)
DES_2_ROUNDS_P1(DES_KS_copy+48)
DES_2_ROUNDS_P1(DES_KS_copy+64)
DES_2_ROUNDS_P1(DES_KS_copy+80)
DES_2_ROUNDS_P1(DES_KS_copy+96)
DES_2_ROUNDS_START_P1(DES_KS_copy+112)
xorl Rl,Ll
movl DES_SPE_H+0x700(%edx),%eax
xorl Rh,%eax
movl Lh,Rh
movl %eax,Lh
movl DES_count_tmp,%eax
movl DES_SavedL,Rl
decl %eax
movl %eax,DES_count_tmp
movl DES_KS_copy,%eax
jnz DES_loop_P1
DES_CRYPT_END
/*
* Generic x86 version.
*/
#define DES_2_ROUNDS_START_ANY(K) \
xorl Rl,%eax; \
movb %al,%bl; \
movb %ah,%dl; \
shrl $16,%eax; \
xorl DES_SPE_L(%ebx),Ll; \
xorl DES_SPE_H(%ebx),Lh; \
movb %al,%bl; \
xorl DES_SPE_L+0x100(%edx),Ll; \
xorl DES_SPE_H+0x100(%edx),Lh; \
movb %ah,%dl; \
movl K+4,%eax; \
xorl DES_SPE_L+0x200(%ebx),Ll; \
xorl Rh,%eax; \
xorl DES_SPE_H+0x200(%ebx),Lh; \
movb %al,%bl; \
xorl DES_SPE_L+0x300(%edx),Ll; \
xorl DES_SPE_H+0x300(%edx),Lh; \
movb %ah,%dl; \
xorl DES_SPE_L+0x400(%ebx),Ll; \
shrl $16,%eax; \
xorl DES_SPE_H+0x400(%ebx),Lh; \
movb %al,%bl; \
xorl DES_SPE_L+0x500(%edx),Ll; \
xorl DES_SPE_H+0x500(%edx),Lh; \
movb %ah,%dl; \
xorl DES_SPE_L+0x600(%ebx),Ll; \
xorl DES_SPE_H+0x600(%ebx),Lh; \
xorl DES_SPE_L+0x700(%edx),Ll; \
movl K+8,%eax; \
xorl Ll,%eax; \
movb %al,%bl; \
xorl DES_SPE_H+0x700(%edx),Lh; \
movb %ah,%dl; \
shrl $16,%eax; \
xorl DES_SPE_L(%ebx),Rl; \
xorl DES_SPE_H(%ebx),Rh; \
movb %al,%bl; \
xorl DES_SPE_L+0x100(%edx),Rl; \
xorl DES_SPE_H+0x100(%edx),Rh; \
movb %ah,%dl; \
movl K+12,%eax; \
xorl DES_SPE_L+0x200(%ebx),Rl; \
xorl Lh,%eax; \
xorl DES_SPE_H+0x200(%ebx),Rh; \
movb %al,%bl; \
xorl DES_SPE_L+0x300(%edx),Rl; \
xorl DES_SPE_H+0x300(%edx),Rh; \
movb %ah,%dl; \
shrl $16,%eax; \
xorl DES_SPE_L+0x400(%ebx),Rl; \
xorl DES_SPE_H+0x400(%ebx),Rh; \
movb %al,%bl; \
xorl DES_SPE_L+0x500(%edx),Rl; \
xorl DES_SPE_H+0x500(%edx),Rh; \
movb %ah,%dl
#define DES_2_ROUNDS_ANY(K) \
DES_2_ROUNDS_START_ANY(K); \
xorl DES_SPE_L+0x600(%ebx),Rl; \
xorl DES_SPE_H+0x600(%ebx),Rh; \
movl K+16,%eax; \
xorl DES_SPE_L+0x700(%edx),Rl; \
xorl DES_SPE_H+0x700(%edx),Rh
DO_ALIGN(12)
DES_std_crypt_generic:
DES_CRYPT_START
DES_loop_generic:
DES_2_ROUNDS_ANY(DES_KS_copy)
DES_2_ROUNDS_ANY(DES_KS_copy+16)
DES_2_ROUNDS_ANY(DES_KS_copy+32)
DES_2_ROUNDS_ANY(DES_KS_copy+48)
DES_2_ROUNDS_ANY(DES_KS_copy+64)
DES_2_ROUNDS_ANY(DES_KS_copy+80)
DES_2_ROUNDS_ANY(DES_KS_copy+96)
DES_2_ROUNDS_START_ANY(DES_KS_copy+112)
movl Ll,%eax
xorl DES_SPE_L+0x600(%ebx),Rl
xorl DES_SPE_H+0x600(%ebx),Rh
movl DES_SPE_L+0x700(%edx),Ll
xorl Rl,Ll
movl %eax,Rl
movl Lh,%eax
movl DES_SPE_H+0x700(%edx),Lh
xorl Rh,Lh
decl DES_count_tmp
movl %eax,Rh
movl DES_KS_copy,%eax
jnz DES_loop_generic
DES_CRYPT_END
#define DES_xor1(ofs) \
movl DES_KS_current+ofs,%esi; \
movl DES_KS_current+ofs+4,%edi; \
movl ofs(%edx),%eax; \
movl ofs+4(%edx),%ecx; \
xorl %esi,%eax; \
xorl %edi,%ecx; \
movl %eax,DES_KS_current+ofs; \
movl %ecx,DES_KS_current+ofs+4
DO_ALIGN(4)
.globl DES_xor_key1
DES_xor_key1:
movl 4(%esp),%edx
pushl %esi
pushl %edi
DES_xor1(0)
DES_xor1(32)
DES_xor1(8)
DES_xor1(16)
DES_xor1(24)
DES_xor1(40)
DES_xor1(48)
DES_xor1(56)
DES_xor1(64)
DES_xor1(96)
DES_xor1(72)
DES_xor1(80)
DES_xor1(88)
DES_xor1(104)
DES_xor1(112)
DES_xor1(120)
popl %edi
popl %esi
ret
#define DES_xor2(ofs) \
movl ofs(%edx),%eax; \
movl ofs+4(%edx),%ecx; \
movl ofs(%ebx),%esi; \
movl ofs+4(%ebx),%edi; \
xorl %esi,%eax; \
xorl %edi,%ecx; \
movl DES_KS_current+ofs,%esi; \
movl DES_KS_current+ofs+4,%edi; \
xorl %esi,%eax; \
xorl %edi,%ecx; \
movl %eax,DES_KS_current+ofs; \
movl %ecx,DES_KS_current+ofs+4
DO_ALIGN(4)
.globl DES_xor_key2
DES_xor_key2:
pushl %ebx
movl 8(%esp),%edx
movl 12(%esp),%ebx
pushl %esi
pushl %edi
DES_xor2(0)
DES_xor2(32)
DES_xor2(8)
DES_xor2(16)
DES_xor2(24)
DES_xor2(40)
DES_xor2(48)
DES_xor2(56)
DES_xor2(64)
DES_xor2(96)
DES_xor2(72)
DES_xor2(80)
DES_xor2(88)
DES_xor2(104)
DES_xor2(112)
DES_xor2(120)
popl %edi
popl %esi
popl %ebx
ret
#endif
.data
/*
* Weird alignments to make sure KS address's bits 5-11 never match current
* instruction pointer's bits 5-11.
*/
#ifdef DUMBAS
DO_ALIGN(12)
.zero 0x1000 - 32 - 128
#elif defined(__DJGPP__)
.text
DO_ALIGN(12)
.space (0x1000 - 32 - 128 - 0xE0)
#else
DO_ALIGN(12)
.space (0x1000 - 32 - 128)
#endif
#if !DES_X2
/*
* The function pointer, set by CPU_detect().
*/
.globl DES_std_crypt
DES_std_crypt:
.long DES_std_crypt_generic
DES_SavedL:
.long 0
#endif
/*
* These are in .data, not .bss, to get them in a cache line that has to be
* already loaded at DES_std_crypt() startup.
*/
.globl DES_IV
DES_IV:
#ifdef DUMBAS
.zero 16
#else
.space 16
#endif
.globl DES_count
DES_count:
.long 0
DES_count_tmp:
.long 0
DO_ALIGN(5)
.globl DES_KS_copy
DES_KS_copy:
#ifdef DUMBAS
.zero 128
#else
.space 128
#endif
#ifdef __DJGPP__
.space 32
#endif
#ifndef BSD
.bss
DO_ALIGN(5)
#endif
#if DES_X2
.globl DES_SPE_F
DES_SPE_F:
#ifdef DUMBAS
.zero 0x1000
#else
.space 0x1000
#endif
#else
.globl DES_SPE_L
DES_SPE_L:
#ifdef DUMBAS
.zero 0x800
#else
.space 0x800
#endif
/*
* Cache bank shift. This should be at least as large as the word size, but
* smaller than the cache line size. (At least on Intel Pentium, two loads
* can't dual issue if accessing the same cache bank.)
*/
.long 0
.globl DES_SPE_H
DES_SPE_H:
#ifdef DUMBAS
.zero 0x800
#else
.space 0x800
#endif
#endif
DO_ALIGN(5)
.globl DES_KS_current
DES_KS_current:
#ifdef DUMBAS
.zero 128
#else
.space 128
#endif
.globl DES_KS_table
DES_KS_table:
#ifdef DUMBAS
.zero 0x20000
#else
.space (8 * 128 * 16 * 8)
#endif
/*
* MD5 stuff, optimized for Intel Pentium only right now.
*/
#define S11 7
#define S12 12
#define S13 17
#define S14 22
#define S21 5
#define S22 9
#define S23 14
#define S24 20
#define S31 4
#define S32 11
#define S33 16
#define S34 23
#define S41 6
#define S42 10
#define S43 15
#define S44 21
#define Ca 0x67452301
#define Cb 0xefcdab89
#define Cc 0x98badcfe
#define Cd 0x10325476
#define a %esi
#define b %edi
#define c %edx
#define d %ebx
#undef tmp1
#undef tmp2
#define tmp1 %eax
#define tmp2 %ecx
#ifdef DUMBAS
#define x(i) i+i+i+i(%ebp)
#else
#define x(i) 4*i(%ebp)
#endif
.text
#define FF(a, b, c, d, x, s, ac) \
andl b,tmp1; \
addl x,a; \
xorl d,tmp1; \
addl $ac,a; \
addl tmp1,a; \
movl b,tmp1; \
roll $s,a; \
xorl c,tmp1; \
addl b,a
#define GG(a, b, c, d, x, s, ac) \
movl x,tmp2; \
xorl b,tmp1; \
addl tmp2,a; \
andl d,tmp1; \
addl $ac,a; \
xorl c,tmp1; \
addl tmp1,a; \
roll $s,a; \
movl b,tmp1; \
addl b,a
#define HH(a, b, c, d, x, s, ac) \
movl c,tmp1; \
addl tmp2,a; \
xorl d,tmp1; \
addl $ac,a; \
xorl b,tmp1; \
movl x,tmp2; \
addl tmp1,a; \
roll $s,a; \
addl b,a
#define II(a, b, c, d, x, s, ac) \
xorl d,tmp2; \
addl x,a; \
orl b,tmp2; \
addl $ac,a; \
xorl c,tmp2; \
addl tmp2,a; \
movl $-1,tmp2; \
roll $s,a; \
addl b,a
DO_ALIGN(5)
.globl MD5_body
MD5_body:
pushl %ebp
movl 8(%esp),%ebp
pushl %ebx
pushl %esi
pushl %edi
/* Round 1 */
movl x(0),a
movl x(1),d
addl $0xd76aa477,a
roll $S11,a
addl $0xf8fa0bcc,d
addl $Cb,a
movl x(2),c
movl a,tmp1
movl a,tmp2
andl $0x77777777,tmp1
xorl $Cb,tmp2
xorl $Cc,tmp1
addl $0xbcdb4dd9,c
addl tmp1,d
roll $S12,d
addl a,d
andl d,tmp2
xorl $Cb,tmp2
addl tmp2,c
movl d,tmp1
roll $S13,c
xorl a,tmp1
addl d,c
andl c,tmp1
movl x(3),b
xorl a,tmp1
addl $0xb18b7a77,b
addl tmp1,b
movl c,tmp1
roll $S14,b
xorl d,tmp1
addl c,b
FF (a, b, c, d, x( 4), S11, 0xf57c0faf) /* 5 */
FF (d, a, b, c, x( 5), S12, 0x4787c62a) /* 6 */
FF (c, d, a, b, x( 6), S13, 0xa8304613) /* 7 */
FF (b, c, d, a, x( 7), S14, 0xfd469501) /* 8 */
FF (a, b, c, d, x( 8), S11, 0x698098d8) /* 9 */
FF (d, a, b, c, x( 9), S12, 0x8b44f7af) /* 10 */
FF (c, d, a, b, x(10), S13, 0xffff5bb1) /* 11 */
FF (b, c, d, a, x(11), S14, 0x895cd7be) /* 12 */
FF (a, b, c, d, x(12), S11, 0x6b901122) /* 13 */
FF (d, a, b, c, x(13), S12, 0xfd987193) /* 14 */
FF (c, d, a, b, x(14), S13, 0xa679438e) /* 15 */
andl c,tmp1
addl $0x49b40821,b
xorl a,tmp1
addl tmp1,b
roll $S14,b
movl c,tmp1
addl c,b
/* Round 2 */
GG (a, b, c, d, x( 1), S21, 0xf61e2562) /* 17 */
GG (d, a, b, c, x( 6), S22, 0xc040b340) /* 18 */
GG (c, d, a, b, x(11), S23, 0x265e5a51) /* 19 */
GG (b, c, d, a, x( 0), S24, 0xe9b6c7aa) /* 20 */
GG (a, b, c, d, x( 5), S21, 0xd62f105d) /* 21 */
GG (d, a, b, c, x(10), S22, 0x2441453) /* 22 */
xorl d,tmp1
andl b,tmp1
addl $0xd8a1e681,c
xorl a,tmp1
addl tmp1,c
roll $S23,c
movl d,tmp1
addl d,c
GG (b, c, d, a, x( 4), S24, 0xe7d3fbc8) /* 24 */
GG (a, b, c, d, x( 9), S21, 0x21e1cde6) /* 25 */
GG (d, a, b, c, x(14), S22, 0xc33707d6) /* 26 */
GG (c, d, a, b, x( 3), S23, 0xf4d50d87) /* 27 */
GG (b, c, d, a, x( 8), S24, 0x455a14ed) /* 28 */
GG (a, b, c, d, x(13), S21, 0xa9e3e905) /* 29 */
GG (d, a, b, c, x( 2), S22, 0xfcefa3f8) /* 30 */
GG (c, d, a, b, x( 7), S23, 0x676f02d9) /* 31 */
movl x(12),tmp2
xorl c,tmp1
addl tmp2,b
andl a,tmp1
addl $0x8d2a4c8a,b
xorl d,tmp1
movl x(5),tmp2
addl tmp1,b
roll $S24,b
addl c,b
/* Round 3 */
HH (a, b, c, d, x( 8), S31, 0xfffa3942) /* 33 */
HH (d, a, b, c, x(11), S32, 0x8771f681) /* 34 */
HH (c, d, a, b, x(14), S33, 0x6d9d6122) /* 35 */
HH (b, c, d, a, x( 1), S34, 0xfde5380c) /* 36 */
HH (a, b, c, d, x( 4), S31, 0xa4beea44) /* 37 */
HH (d, a, b, c, x( 7), S32, 0x4bdecfa9) /* 38 */
HH (c, d, a, b, x(10), S33, 0xf6bb4b60) /* 39 */
HH (b, c, d, a, x(13), S34, 0xbebfbc70) /* 40 */
HH (a, b, c, d, x( 0), S31, 0x289b7ec6) /* 41 */
HH (d, a, b, c, x( 3), S32, 0xeaa127fa) /* 42 */
HH (c, d, a, b, x( 6), S33, 0xd4ef3085) /* 43 */
HH (b, c, d, a, x( 9), S34, 0x4881d05) /* 44 */
HH (a, b, c, d, x(12), S31, 0xd9d4d039) /* 45 */
HH (d, a, b, c, x( 2), S32, 0xe6db99e5) /* 46 */
movl a,tmp1
xorl b,tmp1
addl $0x1fa27cf8,c
xorl d,tmp1
addl tmp1,c
roll $S33,c
addl d,c
HH (b, c, d, a, $-1, S34, 0xc4ac5665) /* 48 */
/* Round 4 */
II (a, b, c, d, x( 0), S41, 0xf4292244) /* 49 */
II (d, a, b, c, x( 7), S42, 0x432aff97) /* 50 */
II (c, d, a, b, x(14), S43, 0xab9423a7) /* 51 */
II (b, c, d, a, x( 5), S44, 0xfc93a039) /* 52 */
II (a, b, c, d, x(12), S41, 0x655b59c3) /* 53 */
II (d, a, b, c, x( 3), S42, 0x8f0ccc92) /* 54 */
II (c, d, a, b, x(10), S43, 0xffeff47d) /* 55 */
II (b, c, d, a, x( 1), S44, 0x85845dd1) /* 56 */
II (a, b, c, d, x( 8), S41, 0x6fa87e4f) /* 57 */
xorl c,tmp2
orl a,tmp2
addl $0xfe2ce6e0,d
xorl b,tmp2
addl tmp2,d
movl $-1,tmp2
roll $S42,d
addl a,d
II (c, d, a, b, x( 6), S43, 0xa3014314) /* 59 */
II (b, c, d, a, x(13), S44, 0x4e0811a1) /* 60 */
II (a, b, c, d, x( 4), S41, 0xf7537e82) /* 61 */
II (d, a, b, c, x(11), S42, 0xbd3af235) /* 62 */
II (c, d, a, b, x( 2), S43, 0x2ad7d2bb) /* 63 */
xorl a,tmp2
addl x(9),b
orl c,tmp2
addl $0xeb86d391,b
xorl d,tmp2
addl tmp2,b
movl 24(%esp),tmp1
roll $S44,b
/* Update the state and return */
addl $Ca,a
addl $Cd,d
movl a,(tmp1)
leal Cb(b,c),b
addl $Cc,c
movl b,4(tmp1)
movl c,8(tmp1)
movl d,12(tmp1)
popl %edi
popl %esi
popl %ebx
popl %ebp
ret
#if BF_ASM
/*
* Blowfish stuff.
*/
#ifdef DUMBAS
#define P(N) BF_current+0x1000+N+N+N+N
#else
#define P(N) BF_current+0x1000+4*N
#endif
/*
* Intel Pentium optimized version, extra operations are used to avoid
* imperfect pairing. Also used on the Pentium 4.
*/