1
2
3
4
5#include <linux/linkage.h>
6
7.text
8
9
10ENTRY(salsa20_encrypt_bytes)
11 mov %esp,%eax
12 and $31,%eax
13 add $256,%eax
14 sub %eax,%esp
15
16 movl %eax,80(%esp)
17
18 movl %ebx,84(%esp)
19
20 movl %esi,88(%esp)
21
22 movl %edi,92(%esp)
23
24 movl %ebp,96(%esp)
25
26 movl 4(%esp,%eax),%edx
27
28 movl 8(%esp,%eax),%esi
29
30 movl 12(%esp,%eax),%edi
31
32 movl 16(%esp,%eax),%ebx
33
34 sub $0,%ebx
35
36 jbe ._done
37._start:
38
39 movl 0(%edx),%eax
40
41 movl 4(%edx),%ecx
42
43 movl 8(%edx),%ebp
44
45 movl %eax,164(%esp)
46
47 movl 12(%edx),%eax
48
49 movl %ecx,168(%esp)
50
51 movl 16(%edx),%ecx
52
53 movl %ebp,172(%esp)
54
55 movl 20(%edx),%ebp
56
57 movl %eax,176(%esp)
58
59 movl 24(%edx),%eax
60
61 movl %ecx,180(%esp)
62
63 movl 28(%edx),%ecx
64
65 movl %ebp,184(%esp)
66
67 movl 32(%edx),%ebp
68
69 movl %eax,188(%esp)
70
71 movl 36(%edx),%eax
72
73 movl %ecx,192(%esp)
74
75 movl 40(%edx),%ecx
76
77 movl %ebp,196(%esp)
78
79 movl 44(%edx),%ebp
80
81 movl %eax,200(%esp)
82
83 movl 48(%edx),%eax
84
85 movl %ecx,204(%esp)
86
87 movl 52(%edx),%ecx
88
89 movl %ebp,208(%esp)
90
91 movl 56(%edx),%ebp
92
93 movl %eax,212(%esp)
94
95 movl 60(%edx),%eax
96
97 movl %ecx,216(%esp)
98
99 movl %ebp,220(%esp)
100
101 movl %eax,224(%esp)
102
103 movl %edx,64(%esp)
104._bytesatleast1:
105
106 cmp $64,%ebx
107
108 jae ._nocopy
109
110 movl %edi,228(%esp)
111
112 leal 0(%esp),%edi
113
114 mov %ebx,%ecx
115
116 rep movsb
117
118 leal 0(%esp),%edi
119
120 leal 0(%esp),%esi
121._nocopy:
122
123 movl %edi,72(%esp)
124
125 movl %esi,68(%esp)
126
127 movl %ebx,76(%esp)
128
129 movl 164(%esp),%eax
130
131 movl 168(%esp),%ecx
132
133 movl 172(%esp),%edx
134
135 movl 176(%esp),%ebx
136
137 movl %eax,100(%esp)
138
139 movl %ecx,104(%esp)
140
141 movl %edx,108(%esp)
142
143 movl %ebx,112(%esp)
144
145 movl 180(%esp),%eax
146
147 movl 184(%esp),%ecx
148
149 movl 188(%esp),%edx
150
151 movl 192(%esp),%ebx
152
153 movl %eax,116(%esp)
154
155 movl %ecx,120(%esp)
156
157 movl %edx,124(%esp)
158
159 movl %ebx,128(%esp)
160
161 movl 196(%esp),%eax
162
163 movl 200(%esp),%ecx
164
165 movl 204(%esp),%edx
166
167 movl 208(%esp),%ebx
168
169 movl %eax,132(%esp)
170
171 movl %ecx,136(%esp)
172
173 movl %edx,140(%esp)
174
175 movl %ebx,144(%esp)
176
177 movl 212(%esp),%eax
178
179 movl 216(%esp),%ecx
180
181 movl 220(%esp),%edx
182
183 movl 224(%esp),%ebx
184
185 movl %eax,148(%esp)
186
187 movl %ecx,152(%esp)
188
189 movl %edx,156(%esp)
190
191 movl %ebx,160(%esp)
192
193 mov $20,%ebp
194
195 movl 100(%esp),%eax
196
197 movl 120(%esp),%ecx
198
199 movl 140(%esp),%edx
200
201 movl 160(%esp),%ebx
202._mainloop:
203
204 movl %eax,100(%esp)
205
206 movl %edx,140(%esp)
207
208 addl 148(%esp),%eax
209
210 movl %ecx,120(%esp)
211
212 addl 124(%esp),%edx
213
214 movl %ebx,160(%esp)
215
216 movl 104(%esp),%esi
217
218 add %ecx,%esi
219
220 movl 144(%esp),%edi
221
222 add %ebx,%edi
223
224 rol $7,%eax
225
226 xorl 116(%esp),%eax
227
228 rol $7,%edx
229
230 xorl 156(%esp),%edx
231
232 rol $7,%esi
233
234 xorl 136(%esp),%esi
235
236 rol $7,%edi
237
238 xorl 112(%esp),%edi
239
240 movl %eax,116(%esp)
241
242 movl %edx,156(%esp)
243
244 addl 100(%esp),%eax
245
246 movl %esi,136(%esp)
247
248 addl 140(%esp),%edx
249
250 movl %edi,112(%esp)
251
252 rol $9,%eax
253
254 xorl 132(%esp),%eax
255
256 rol $9,%edx
257
258 xorl 108(%esp),%edx
259
260 add %esi,%ecx
261
262 rol $9,%ecx
263
264 xorl 152(%esp),%ecx
265
266 add %edi,%ebx
267
268 rol $9,%ebx
269
270 xorl 128(%esp),%ebx
271
272 movl %eax,132(%esp)
273
274 movl %edx,108(%esp)
275
276 addl 116(%esp),%eax
277
278 movl %ecx,152(%esp)
279
280 addl 156(%esp),%edx
281
282 movl %ebx,128(%esp)
283
284 rol $13,%eax
285
286 xorl 148(%esp),%eax
287
288 rol $13,%edx
289
290 xorl 124(%esp),%edx
291
292 add %ecx,%esi
293
294 rol $13,%esi
295
296 xorl 104(%esp),%esi
297
298 add %ebx,%edi
299
300 rol $13,%edi
301
302 xorl 144(%esp),%edi
303
304 movl %eax,148(%esp)
305
306 movl %edx,124(%esp)
307
308 addl 132(%esp),%eax
309
310 movl %esi,104(%esp)
311
312 addl 108(%esp),%edx
313
314 movl %edi,144(%esp)
315
316 rol $18,%eax
317
318 xorl 100(%esp),%eax
319
320 rol $18,%edx
321
322 xorl 140(%esp),%edx
323
324 add %esi,%ecx
325
326 rol $18,%ecx
327
328 xorl 120(%esp),%ecx
329
330 add %edi,%ebx
331
332 rol $18,%ebx
333
334 xorl 160(%esp),%ebx
335
336 movl %eax,100(%esp)
337
338 movl %edx,140(%esp)
339
340 addl 112(%esp),%eax
341
342 rol $7,%eax
343
344 movl %ecx,120(%esp)
345
346 addl 136(%esp),%edx
347
348 movl %ebx,160(%esp)
349
350 movl 116(%esp),%esi
351
352 add %ecx,%esi
353
354 movl 156(%esp),%edi
355
356 add %ebx,%edi
357
358 xorl 104(%esp),%eax
359
360 rol $7,%edx
361
362 xorl 144(%esp),%edx
363
364 rol $7,%esi
365
366 xorl 124(%esp),%esi
367
368 rol $7,%edi
369
370 xorl 148(%esp),%edi
371
372 movl %eax,104(%esp)
373
374 movl %edx,144(%esp)
375
376 addl 100(%esp),%eax
377
378 movl %esi,124(%esp)
379
380 addl 140(%esp),%edx
381
382 movl %edi,148(%esp)
383
384 rol $9,%eax
385
386 xorl 108(%esp),%eax
387
388 rol $9,%edx
389
390 xorl 132(%esp),%edx
391
392 add %esi,%ecx
393
394 rol $9,%ecx
395
396 xorl 128(%esp),%ecx
397
398 add %edi,%ebx
399
400 rol $9,%ebx
401
402 xorl 152(%esp),%ebx
403
404 movl %eax,108(%esp)
405
406 movl %edx,132(%esp)
407
408 addl 104(%esp),%eax
409
410 movl %ecx,128(%esp)
411
412 addl 144(%esp),%edx
413
414 movl %ebx,152(%esp)
415
416 rol $13,%eax
417
418 xorl 112(%esp),%eax
419
420 rol $13,%edx
421
422 xorl 136(%esp),%edx
423
424 add %ecx,%esi
425
426 rol $13,%esi
427
428 xorl 116(%esp),%esi
429
430 add %ebx,%edi
431
432 rol $13,%edi
433
434 xorl 156(%esp),%edi
435
436 movl %eax,112(%esp)
437
438 movl %edx,136(%esp)
439
440 addl 108(%esp),%eax
441
442 movl %esi,116(%esp)
443
444 addl 132(%esp),%edx
445
446 movl %edi,156(%esp)
447
448 rol $18,%eax
449
450 xorl 100(%esp),%eax
451
452 rol $18,%edx
453
454 xorl 140(%esp),%edx
455
456 add %esi,%ecx
457
458 rol $18,%ecx
459
460 xorl 120(%esp),%ecx
461
462 add %edi,%ebx
463
464 rol $18,%ebx
465
466 xorl 160(%esp),%ebx
467
468 movl %eax,100(%esp)
469
470 movl %edx,140(%esp)
471
472 addl 148(%esp),%eax
473
474 movl %ecx,120(%esp)
475
476 addl 124(%esp),%edx
477
478 movl %ebx,160(%esp)
479
480 movl 104(%esp),%esi
481
482 add %ecx,%esi
483
484 movl 144(%esp),%edi
485
486 add %ebx,%edi
487
488 rol $7,%eax
489
490 xorl 116(%esp),%eax
491
492 rol $7,%edx
493
494 xorl 156(%esp),%edx
495
496 rol $7,%esi
497
498 xorl 136(%esp),%esi
499
500 rol $7,%edi
501
502 xorl 112(%esp),%edi
503
504 movl %eax,116(%esp)
505
506 movl %edx,156(%esp)
507
508 addl 100(%esp),%eax
509
510 movl %esi,136(%esp)
511
512 addl 140(%esp),%edx
513
514 movl %edi,112(%esp)
515
516 rol $9,%eax
517
518 xorl 132(%esp),%eax
519
520 rol $9,%edx
521
522 xorl 108(%esp),%edx
523
524 add %esi,%ecx
525
526 rol $9,%ecx
527
528 xorl 152(%esp),%ecx
529
530 add %edi,%ebx
531
532 rol $9,%ebx
533
534 xorl 128(%esp),%ebx
535
536 movl %eax,132(%esp)
537
538 movl %edx,108(%esp)
539
540 addl 116(%esp),%eax
541
542 movl %ecx,152(%esp)
543
544 addl 156(%esp),%edx
545
546 movl %ebx,128(%esp)
547
548 rol $13,%eax
549
550 xorl 148(%esp),%eax
551
552 rol $13,%edx
553
554 xorl 124(%esp),%edx
555
556 add %ecx,%esi
557
558 rol $13,%esi
559
560 xorl 104(%esp),%esi
561
562 add %ebx,%edi
563
564 rol $13,%edi
565
566 xorl 144(%esp),%edi
567
568 movl %eax,148(%esp)
569
570 movl %edx,124(%esp)
571
572 addl 132(%esp),%eax
573
574 movl %esi,104(%esp)
575
576 addl 108(%esp),%edx
577
578 movl %edi,144(%esp)
579
580 rol $18,%eax
581
582 xorl 100(%esp),%eax
583
584 rol $18,%edx
585
586 xorl 140(%esp),%edx
587
588 add %esi,%ecx
589
590 rol $18,%ecx
591
592 xorl 120(%esp),%ecx
593
594 add %edi,%ebx
595
596 rol $18,%ebx
597
598 xorl 160(%esp),%ebx
599
600 movl %eax,100(%esp)
601
602 movl %edx,140(%esp)
603
604 addl 112(%esp),%eax
605
606 rol $7,%eax
607
608 movl %ecx,120(%esp)
609
610 addl 136(%esp),%edx
611
612 movl %ebx,160(%esp)
613
614 movl 116(%esp),%esi
615
616 add %ecx,%esi
617
618 movl 156(%esp),%edi
619
620 add %ebx,%edi
621
622 xorl 104(%esp),%eax
623
624 rol $7,%edx
625
626 xorl 144(%esp),%edx
627
628 rol $7,%esi
629
630 xorl 124(%esp),%esi
631
632 rol $7,%edi
633
634 xorl 148(%esp),%edi
635
636 movl %eax,104(%esp)
637
638 movl %edx,144(%esp)
639
640 addl 100(%esp),%eax
641
642 movl %esi,124(%esp)
643
644 addl 140(%esp),%edx
645
646 movl %edi,148(%esp)
647
648 rol $9,%eax
649
650 xorl 108(%esp),%eax
651
652 rol $9,%edx
653
654 xorl 132(%esp),%edx
655
656 add %esi,%ecx
657
658 rol $9,%ecx
659
660 xorl 128(%esp),%ecx
661
662 add %edi,%ebx
663
664 rol $9,%ebx
665
666 xorl 152(%esp),%ebx
667
668 movl %eax,108(%esp)
669
670 movl %edx,132(%esp)
671
672 addl 104(%esp),%eax
673
674 movl %ecx,128(%esp)
675
676 addl 144(%esp),%edx
677
678 movl %ebx,152(%esp)
679
680 rol $13,%eax
681
682 xorl 112(%esp),%eax
683
684 rol $13,%edx
685
686 xorl 136(%esp),%edx
687
688 add %ecx,%esi
689
690 rol $13,%esi
691
692 xorl 116(%esp),%esi
693
694 add %ebx,%edi
695
696 rol $13,%edi
697
698 xorl 156(%esp),%edi
699
700 movl %eax,112(%esp)
701
702 movl %edx,136(%esp)
703
704 addl 108(%esp),%eax
705
706 movl %esi,116(%esp)
707
708 addl 132(%esp),%edx
709
710 movl %edi,156(%esp)
711
712 rol $18,%eax
713
714 xorl 100(%esp),%eax
715
716 rol $18,%edx
717
718 xorl 140(%esp),%edx
719
720 add %esi,%ecx
721
722 rol $18,%ecx
723
724 xorl 120(%esp),%ecx
725
726 add %edi,%ebx
727
728 rol $18,%ebx
729
730 xorl 160(%esp),%ebx
731
732 sub $4,%ebp
733
734 ja ._mainloop
735
736 movl %eax,100(%esp)
737
738 movl %ecx,120(%esp)
739
740 movl %edx,140(%esp)
741
742 movl %ebx,160(%esp)
743
744 movl 72(%esp),%edi
745
746 movl 68(%esp),%esi
747
748 movl 100(%esp),%eax
749
750 movl 104(%esp),%ecx
751
752 addl 164(%esp),%eax
753
754 addl 168(%esp),%ecx
755
756 xorl 0(%esi),%eax
757
758 xorl 4(%esi),%ecx
759
760 movl %eax,0(%edi)
761
762 movl %ecx,4(%edi)
763
764 movl 108(%esp),%eax
765
766 movl 112(%esp),%ecx
767
768 addl 172(%esp),%eax
769
770 addl 176(%esp),%ecx
771
772 xorl 8(%esi),%eax
773
774 xorl 12(%esi),%ecx
775
776 movl %eax,8(%edi)
777
778 movl %ecx,12(%edi)
779
780 movl 116(%esp),%eax
781
782 movl 120(%esp),%ecx
783
784 addl 180(%esp),%eax
785
786 addl 184(%esp),%ecx
787
788 xorl 16(%esi),%eax
789
790 xorl 20(%esi),%ecx
791
792 movl %eax,16(%edi)
793
794 movl %ecx,20(%edi)
795
796 movl 124(%esp),%eax
797
798 movl 128(%esp),%ecx
799
800 addl 188(%esp),%eax
801
802 addl 192(%esp),%ecx
803
804 xorl 24(%esi),%eax
805
806 xorl 28(%esi),%ecx
807
808 movl %eax,24(%edi)
809
810 movl %ecx,28(%edi)
811
812 movl 132(%esp),%eax
813
814 movl 136(%esp),%ecx
815
816 addl 196(%esp),%eax
817
818 addl 200(%esp),%ecx
819
820 xorl 32(%esi),%eax
821
822 xorl 36(%esi),%ecx
823
824 movl %eax,32(%edi)
825
826 movl %ecx,36(%edi)
827
828 movl 140(%esp),%eax
829
830 movl 144(%esp),%ecx
831
832 addl 204(%esp),%eax
833
834 addl 208(%esp),%ecx
835
836 xorl 40(%esi),%eax
837
838 xorl 44(%esi),%ecx
839
840 movl %eax,40(%edi)
841
842 movl %ecx,44(%edi)
843
844 movl 148(%esp),%eax
845
846 movl 152(%esp),%ecx
847
848 addl 212(%esp),%eax
849
850 addl 216(%esp),%ecx
851
852 xorl 48(%esi),%eax
853
854 xorl 52(%esi),%ecx
855
856 movl %eax,48(%edi)
857
858 movl %ecx,52(%edi)
859
860 movl 156(%esp),%eax
861
862 movl 160(%esp),%ecx
863
864 addl 220(%esp),%eax
865
866 addl 224(%esp),%ecx
867
868 xorl 56(%esi),%eax
869
870 xorl 60(%esi),%ecx
871
872 movl %eax,56(%edi)
873
874 movl %ecx,60(%edi)
875
876 movl 76(%esp),%ebx
877
878 movl 196(%esp),%eax
879
880 movl 200(%esp),%ecx
881
882 add $1,%eax
883
884 adc $0,%ecx
885
886 movl %eax,196(%esp)
887
888 movl %ecx,200(%esp)
889
890 cmp $64,%ebx
891
892 ja ._bytesatleast65
893
894 jae ._bytesatleast64
895
896 mov %edi,%esi
897
898 movl 228(%esp),%edi
899
900 mov %ebx,%ecx
901
902 rep movsb
903._bytesatleast64:
904
905 movl 64(%esp),%eax
906
907 movl 196(%esp),%ecx
908
909 movl 200(%esp),%edx
910
911 movl %ecx,32(%eax)
912
913 movl %edx,36(%eax)
914._done:
915
916 movl 80(%esp),%eax
917
918 movl 84(%esp),%ebx
919
920 movl 88(%esp),%esi
921
922 movl 92(%esp),%edi
923
924 movl 96(%esp),%ebp
925
926 add %eax,%esp
927 ret
928._bytesatleast65:
929
930 sub $64,%ebx
931
932 add $64,%edi
933
934 add $64,%esi
935
936 jmp ._bytesatleast1
937ENDPROC(salsa20_encrypt_bytes)
938
939
940ENTRY(salsa20_keysetup)
941 mov %esp,%eax
942 and $31,%eax
943 add $256,%eax
944 sub %eax,%esp
945
946 movl %eax,64(%esp)
947
948 movl %ebx,68(%esp)
949
950 movl %esi,72(%esp)
951
952 movl %edi,76(%esp)
953
954 movl %ebp,80(%esp)
955
956 movl 8(%esp,%eax),%ecx
957
958 movl 12(%esp,%eax),%edx
959
960 movl 4(%esp,%eax),%eax
961
962 movl 0(%ecx),%ebx
963
964 movl 4(%ecx),%esi
965
966 movl 8(%ecx),%edi
967
968 movl 12(%ecx),%ebp
969
970 movl %ebx,4(%eax)
971
972 movl %esi,8(%eax)
973
974 movl %edi,12(%eax)
975
976 movl %ebp,16(%eax)
977
978 cmp $256,%edx
979
980 jb ._kbits128
981._kbits256:
982
983 movl 16(%ecx),%edx
984
985 movl 20(%ecx),%ebx
986
987 movl 24(%ecx),%esi
988
989 movl 28(%ecx),%ecx
990
991 movl %edx,44(%eax)
992
993 movl %ebx,48(%eax)
994
995 movl %esi,52(%eax)
996
997 movl %ecx,56(%eax)
998
999 mov $1634760805,%ecx
1000
1001 mov $857760878,%edx
1002
1003 mov $2036477234,%ebx
1004
1005 mov $1797285236,%esi
1006
1007 movl %ecx,0(%eax)
1008
1009 movl %edx,20(%eax)
1010
1011 movl %ebx,40(%eax)
1012
1013 movl %esi,60(%eax)
1014
1015 jmp ._keysetupdone
1016._kbits128:
1017
1018 movl 0(%ecx),%edx
1019
1020 movl 4(%ecx),%ebx
1021
1022 movl 8(%ecx),%esi
1023
1024 movl 12(%ecx),%ecx
1025
1026 movl %edx,44(%eax)
1027
1028 movl %ebx,48(%eax)
1029
1030 movl %esi,52(%eax)
1031
1032 movl %ecx,56(%eax)
1033
1034 mov $1634760805,%ecx
1035
1036 mov $824206446,%edx
1037
1038 mov $2036477238,%ebx
1039
1040 mov $1797285236,%esi
1041
1042 movl %ecx,0(%eax)
1043
1044 movl %edx,20(%eax)
1045
1046 movl %ebx,40(%eax)
1047
1048 movl %esi,60(%eax)
1049._keysetupdone:
1050
1051 movl 64(%esp),%eax
1052
1053 movl 68(%esp),%ebx
1054
1055 movl 72(%esp),%esi
1056
1057 movl 76(%esp),%edi
1058
1059 movl 80(%esp),%ebp
1060
1061 add %eax,%esp
1062 ret
1063ENDPROC(salsa20_keysetup)
1064
1065
1066ENTRY(salsa20_ivsetup)
1067 mov %esp,%eax
1068 and $31,%eax
1069 add $256,%eax
1070 sub %eax,%esp
1071
1072 movl %eax,64(%esp)
1073
1074 movl %ebx,68(%esp)
1075
1076 movl %esi,72(%esp)
1077
1078 movl %edi,76(%esp)
1079
1080 movl %ebp,80(%esp)
1081
1082 movl 8(%esp,%eax),%ecx
1083
1084 movl 4(%esp,%eax),%eax
1085
1086 movl 0(%ecx),%edx
1087
1088 movl 4(%ecx),%ecx
1089
1090 mov $0,%ebx
1091
1092 mov $0,%esi
1093
1094 movl %edx,24(%eax)
1095
1096 movl %ecx,28(%eax)
1097
1098 movl %ebx,32(%eax)
1099
1100 movl %esi,36(%eax)
1101
1102 movl 64(%esp),%eax
1103
1104 movl 68(%esp),%ebx
1105
1106 movl 72(%esp),%esi
1107
1108 movl 76(%esp),%edi
1109
1110 movl 80(%esp),%ebp
1111
1112 add %eax,%esp
1113 ret
1114ENDPROC(salsa20_ivsetup)
1115