aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/openssl/asm/windows/crypto/aes/vpaes-x86_64.masm
blob: 51dc1e955de534c1f4b8a9aa4428c38b0dddf2af (plain) (blame)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
OPTION	DOTNAME
.text$	SEGMENT ALIGN(256) 'CODE'

















ALIGN	16
_vpaes_encrypt_core	PROC PRIVATE

	mov	r9,rdx
	mov	r11,16
	mov	eax,DWORD PTR[240+rdx]
	movdqa	xmm1,xmm9
	movdqa	xmm2,XMMWORD PTR[$L$k_ipt]
	pandn	xmm1,xmm0
	movdqu	xmm5,XMMWORD PTR[r9]
	psrld	xmm1,4
	pand	xmm0,xmm9
DB	102,15,56,0,208
	movdqa	xmm0,XMMWORD PTR[(($L$k_ipt+16))]
DB	102,15,56,0,193
	pxor	xmm2,xmm5
	add	r9,16
	pxor	xmm0,xmm2
	lea	r10,QWORD PTR[$L$k_mc_backward]
	jmp	$L$enc_entry

ALIGN	16
$L$enc_loop::

	movdqa	xmm4,xmm13
	movdqa	xmm0,xmm12
DB	102,15,56,0,226
DB	102,15,56,0,195
	pxor	xmm4,xmm5
	movdqa	xmm5,xmm15
	pxor	xmm0,xmm4
	movdqa	xmm1,XMMWORD PTR[((-64))+r10*1+r11]
DB	102,15,56,0,234
	movdqa	xmm4,XMMWORD PTR[r10*1+r11]
	movdqa	xmm2,xmm14
DB	102,15,56,0,211
	movdqa	xmm3,xmm0
	pxor	xmm2,xmm5
DB	102,15,56,0,193
	add	r9,16
	pxor	xmm0,xmm2
DB	102,15,56,0,220
	add	r11,16
	pxor	xmm3,xmm0
DB	102,15,56,0,193
	and	r11,030h
	sub	rax,1
	pxor	xmm0,xmm3

$L$enc_entry::

	movdqa	xmm1,xmm9
	movdqa	xmm5,xmm11
	pandn	xmm1,xmm0
	psrld	xmm1,4
	pand	xmm0,xmm9
DB	102,15,56,0,232
	movdqa	xmm3,xmm10
	pxor	xmm0,xmm1
DB	102,15,56,0,217
	movdqa	xmm4,xmm10
	pxor	xmm3,xmm5
DB	102,15,56,0,224
	movdqa	xmm2,xmm10
	pxor	xmm4,xmm5
DB	102,15,56,0,211
	movdqa	xmm3,xmm10
	pxor	xmm2,xmm0
DB	102,15,56,0,220
	movdqu	xmm5,XMMWORD PTR[r9]
	pxor	xmm3,xmm1
	jnz	$L$enc_loop


	movdqa	xmm4,XMMWORD PTR[((-96))+r10]
	movdqa	xmm0,XMMWORD PTR[((-80))+r10]
DB	102,15,56,0,226
	pxor	xmm4,xmm5
DB	102,15,56,0,195
	movdqa	xmm1,XMMWORD PTR[64+r10*1+r11]
	pxor	xmm0,xmm4
DB	102,15,56,0,193
	DB	0F3h,0C3h		;repret

_vpaes_encrypt_core	ENDP







ALIGN	16
_vpaes_decrypt_core	PROC PRIVATE

	mov	r9,rdx
	mov	eax,DWORD PTR[240+rdx]
	movdqa	xmm1,xmm9
	movdqa	xmm2,XMMWORD PTR[$L$k_dipt]
	pandn	xmm1,xmm0
	mov	r11,rax
	psrld	xmm1,4
	movdqu	xmm5,XMMWORD PTR[r9]
	shl	r11,4
	pand	xmm0,xmm9
DB	102,15,56,0,208
	movdqa	xmm0,XMMWORD PTR[(($L$k_dipt+16))]
	xor	r11,030h
	lea	r10,QWORD PTR[$L$k_dsbd]
DB	102,15,56,0,193
	and	r11,030h
	pxor	xmm2,xmm5
	movdqa	xmm5,XMMWORD PTR[(($L$k_mc_forward+48))]
	pxor	xmm0,xmm2
	add	r9,16
	add	r11,r10
	jmp	$L$dec_entry

ALIGN	16
$L$dec_loop::



	movdqa	xmm4,XMMWORD PTR[((-32))+r10]
	movdqa	xmm1,XMMWORD PTR[((-16))+r10]
DB	102,15,56,0,226
DB	102,15,56,0,203
	pxor	xmm0,xmm4
	movdqa	xmm4,XMMWORD PTR[r10]
	pxor	xmm0,xmm1
	movdqa	xmm1,XMMWORD PTR[16+r10]

DB	102,15,56,0,226
DB	102,15,56,0,197
DB	102,15,56,0,203
	pxor	xmm0,xmm4
	movdqa	xmm4,XMMWORD PTR[32+r10]
	pxor	xmm0,xmm1
	movdqa	xmm1,XMMWORD PTR[48+r10]

DB	102,15,56,0,226
DB	102,15,56,0,197
DB	102,15,56,0,203
	pxor	xmm0,xmm4
	movdqa	xmm4,XMMWORD PTR[64+r10]
	pxor	xmm0,xmm1
	movdqa	xmm1,XMMWORD PTR[80+r10]

DB	102,15,56,0,226
DB	102,15,56,0,197
DB	102,15,56,0,203
	pxor	xmm0,xmm4
	add	r9,16
DB	102,15,58,15,237,12
	pxor	xmm0,xmm1
	sub	rax,1

$L$dec_entry::

	movdqa	xmm1,xmm9
	pandn	xmm1,xmm0
	movdqa	xmm2,xmm11
	psrld	xmm1,4
	pand	xmm0,xmm9
DB	102,15,56,0,208
	movdqa	xmm3,xmm10
	pxor	xmm0,xmm1
DB	102,15,56,0,217
	movdqa	xmm4,xmm10
	pxor	xmm3,xmm2
DB	102,15,56,0,224
	pxor	xmm4,xmm2
	movdqa	xmm2,xmm10
DB	102,15,56,0,211
	movdqa	xmm3,xmm10
	pxor	xmm2,xmm0
DB	102,15,56,0,220
	movdqu	xmm0,XMMWORD PTR[r9]
	pxor	xmm3,xmm1
	jnz	$L$dec_loop


	movdqa	xmm4,XMMWORD PTR[96+r10]
DB	102,15,56,0,226
	pxor	xmm4,xmm0
	movdqa	xmm0,XMMWORD PTR[112+r10]
	movdqa	xmm2,XMMWORD PTR[((-352))+r11]
DB	102,15,56,0,195
	pxor	xmm0,xmm4
DB	102,15,56,0,194
	DB	0F3h,0C3h		;repret

_vpaes_decrypt_core	ENDP







ALIGN	16
_vpaes_schedule_core	PROC PRIVATE






	call	_vpaes_preheat
	movdqa	xmm8,XMMWORD PTR[$L$k_rcon]
	movdqu	xmm0,XMMWORD PTR[rdi]


	movdqa	xmm3,xmm0
	lea	r11,QWORD PTR[$L$k_ipt]
	call	_vpaes_schedule_transform
	movdqa	xmm7,xmm0

	lea	r10,QWORD PTR[$L$k_sr]
	test	rcx,rcx
	jnz	$L$schedule_am_decrypting


	movdqu	XMMWORD PTR[rdx],xmm0
	jmp	$L$schedule_go

$L$schedule_am_decrypting::

	movdqa	xmm1,XMMWORD PTR[r10*1+r8]
DB	102,15,56,0,217
	movdqu	XMMWORD PTR[rdx],xmm3
	xor	r8,030h

$L$schedule_go::
	cmp	esi,192
	ja	$L$schedule_256
	je	$L$schedule_192










$L$schedule_128::
	mov	esi,10

$L$oop_schedule_128::
	call	_vpaes_schedule_round
	dec	rsi
	jz	$L$schedule_mangle_last
	call	_vpaes_schedule_mangle
	jmp	$L$oop_schedule_128
















ALIGN	16
$L$schedule_192::
	movdqu	xmm0,XMMWORD PTR[8+rdi]
	call	_vpaes_schedule_transform
	movdqa	xmm6,xmm0
	pxor	xmm4,xmm4
	movhlps	xmm6,xmm4
	mov	esi,4

$L$oop_schedule_192::
	call	_vpaes_schedule_round
DB	102,15,58,15,198,8
	call	_vpaes_schedule_mangle
	call	_vpaes_schedule_192_smear
	call	_vpaes_schedule_mangle
	call	_vpaes_schedule_round
	dec	rsi
	jz	$L$schedule_mangle_last
	call	_vpaes_schedule_mangle
	call	_vpaes_schedule_192_smear
	jmp	$L$oop_schedule_192











ALIGN	16
$L$schedule_256::
	movdqu	xmm0,XMMWORD PTR[16+rdi]
	call	_vpaes_schedule_transform
	mov	esi,7

$L$oop_schedule_256::
	call	_vpaes_schedule_mangle
	movdqa	xmm6,xmm0


	call	_vpaes_schedule_round
	dec	rsi
	jz	$L$schedule_mangle_last
	call	_vpaes_schedule_mangle


	pshufd	xmm0,xmm0,0FFh
	movdqa	xmm5,xmm7
	movdqa	xmm7,xmm6
	call	_vpaes_schedule_low_round
	movdqa	xmm7,xmm5

	jmp	$L$oop_schedule_256












ALIGN	16
$L$schedule_mangle_last::

	lea	r11,QWORD PTR[$L$k_deskew]
	test	rcx,rcx
	jnz	$L$schedule_mangle_last_dec


	movdqa	xmm1,XMMWORD PTR[r10*1+r8]
DB	102,15,56,0,193
	lea	r11,QWORD PTR[$L$k_opt]
	add	rdx,32

$L$schedule_mangle_last_dec::
	add	rdx,-16
	pxor	xmm0,XMMWORD PTR[$L$k_s63]
	call	_vpaes_schedule_transform
	movdqu	XMMWORD PTR[rdx],xmm0


	pxor	xmm0,xmm0
	pxor	xmm1,xmm1
	pxor	xmm2,xmm2
	pxor	xmm3,xmm3
	pxor	xmm4,xmm4
	pxor	xmm5,xmm5
	pxor	xmm6,xmm6
	pxor	xmm7,xmm7
	DB	0F3h,0C3h		;repret

_vpaes_schedule_core	ENDP
















ALIGN	16
_vpaes_schedule_192_smear	PROC PRIVATE

	pshufd	xmm1,xmm6,080h
	pshufd	xmm0,xmm7,0FEh
	pxor	xmm6,xmm1
	pxor	xmm1,xmm1
	pxor	xmm6,xmm0
	movdqa	xmm0,xmm6
	movhlps	xmm6,xmm1
	DB	0F3h,0C3h		;repret

_vpaes_schedule_192_smear	ENDP




















ALIGN	16
_vpaes_schedule_round	PROC PRIVATE


	pxor	xmm1,xmm1
DB	102,65,15,58,15,200,15
DB	102,69,15,58,15,192,15
	pxor	xmm7,xmm1


	pshufd	xmm0,xmm0,0FFh
DB	102,15,58,15,192,1




_vpaes_schedule_low_round::

	movdqa	xmm1,xmm7
	pslldq	xmm7,4
	pxor	xmm7,xmm1
	movdqa	xmm1,xmm7
	pslldq	xmm7,8
	pxor	xmm7,xmm1
	pxor	xmm7,XMMWORD PTR[$L$k_s63]


	movdqa	xmm1,xmm9
	pandn	xmm1,xmm0
	psrld	xmm1,4
	pand	xmm0,xmm9
	movdqa	xmm2,xmm11
DB	102,15,56,0,208
	pxor	xmm0,xmm1
	movdqa	xmm3,xmm10
DB	102,15,56,0,217
	pxor	xmm3,xmm2
	movdqa	xmm4,xmm10
DB	102,15,56,0,224
	pxor	xmm4,xmm2
	movdqa	xmm2,xmm10
DB	102,15,56,0,211
	pxor	xmm2,xmm0
	movdqa	xmm3,xmm10
DB	102,15,56,0,220
	pxor	xmm3,xmm1
	movdqa	xmm4,xmm13
DB	102,15,56,0,226
	movdqa	xmm0,xmm12
DB	102,15,56,0,195
	pxor	xmm0,xmm4


	pxor	xmm0,xmm7
	movdqa	xmm7,xmm0
	DB	0F3h,0C3h		;repret

_vpaes_schedule_round	ENDP











ALIGN	16
_vpaes_schedule_transform	PROC PRIVATE

	movdqa	xmm1,xmm9
	pandn	xmm1,xmm0
	psrld	xmm1,4
	pand	xmm0,xmm9
	movdqa	xmm2,XMMWORD PTR[r11]
DB	102,15,56,0,208
	movdqa	xmm0,XMMWORD PTR[16+r11]
DB	102,15,56,0,193
	pxor	xmm0,xmm2
	DB	0F3h,0C3h		;repret

_vpaes_schedule_transform	ENDP

























ALIGN	16
_vpaes_schedule_mangle	PROC PRIVATE

	movdqa	xmm4,xmm0
	movdqa	xmm5,XMMWORD PTR[$L$k_mc_forward]
	test	rcx,rcx
	jnz	$L$schedule_mangle_dec


	add	rdx,16
	pxor	xmm4,XMMWORD PTR[$L$k_s63]
DB	102,15,56,0,229
	movdqa	xmm3,xmm4
DB	102,15,56,0,229
	pxor	xmm3,xmm4
DB	102,15,56,0,229
	pxor	xmm3,xmm4

	jmp	$L$schedule_mangle_both
ALIGN	16
$L$schedule_mangle_dec::

	lea	r11,QWORD PTR[$L$k_dksd]
	movdqa	xmm1,xmm9
	pandn	xmm1,xmm4
	psrld	xmm1,4
	pand	xmm4,xmm9

	movdqa	xmm2,XMMWORD PTR[r11]
DB	102,15,56,0,212
	movdqa	xmm3,XMMWORD PTR[16+r11]
DB	102,15,56,0,217
	pxor	xmm3,xmm2
DB	102,15,56,0,221

	movdqa	xmm2,XMMWORD PTR[32+r11]
DB	102,15,56,0,212
	pxor	xmm2,xmm3
	movdqa	xmm3,XMMWORD PTR[48+r11]
DB	102,15,56,0,217
	pxor	xmm3,xmm2
DB	102,15,56,0,221

	movdqa	xmm2,XMMWORD PTR[64+r11]
DB	102,15,56,0,212
	pxor	xmm2,xmm3
	movdqa	xmm3,XMMWORD PTR[80+r11]
DB	102,15,56,0,217
	pxor	xmm3,xmm2
DB	102,15,56,0,221

	movdqa	xmm2,XMMWORD PTR[96+r11]
DB	102,15,56,0,212
	pxor	xmm2,xmm3
	movdqa	xmm3,XMMWORD PTR[112+r11]
DB	102,15,56,0,217
	pxor	xmm3,xmm2

	add	rdx,-16

$L$schedule_mangle_both::
	movdqa	xmm1,XMMWORD PTR[r10*1+r8]
DB	102,15,56,0,217
	add	r8,-16
	and	r8,030h
	movdqu	XMMWORD PTR[rdx],xmm3
	DB	0F3h,0C3h		;repret

_vpaes_schedule_mangle	ENDP




PUBLIC	vpaes_set_encrypt_key

ALIGN	16
vpaes_set_encrypt_key	PROC PUBLIC
	mov	QWORD PTR[8+rsp],rdi	;WIN64 prologue
	mov	QWORD PTR[16+rsp],rsi
	mov	rax,rsp
$L$SEH_begin_vpaes_set_encrypt_key::
	mov	rdi,rcx
	mov	rsi,rdx
	mov	rdx,r8



	lea	rsp,QWORD PTR[((-184))+rsp]
	movaps	XMMWORD PTR[16+rsp],xmm6
	movaps	XMMWORD PTR[32+rsp],xmm7
	movaps	XMMWORD PTR[48+rsp],xmm8
	movaps	XMMWORD PTR[64+rsp],xmm9
	movaps	XMMWORD PTR[80+rsp],xmm10
	movaps	XMMWORD PTR[96+rsp],xmm11
	movaps	XMMWORD PTR[112+rsp],xmm12
	movaps	XMMWORD PTR[128+rsp],xmm13
	movaps	XMMWORD PTR[144+rsp],xmm14
	movaps	XMMWORD PTR[160+rsp],xmm15
$L$enc_key_body::
	mov	eax,esi
	shr	eax,5
	add	eax,5
	mov	DWORD PTR[240+rdx],eax

	mov	ecx,0
	mov	r8d,030h
	call	_vpaes_schedule_core
	movaps	xmm6,XMMWORD PTR[16+rsp]
	movaps	xmm7,XMMWORD PTR[32+rsp]
	movaps	xmm8,XMMWORD PTR[48+rsp]
	movaps	xmm9,XMMWORD PTR[64+rsp]
	movaps	xmm10,XMMWORD PTR[80+rsp]
	movaps	xmm11,XMMWORD PTR[96+rsp]
	movaps	xmm12,XMMWORD PTR[112+rsp]
	movaps	xmm13,XMMWORD PTR[128+rsp]
	movaps	xmm14,XMMWORD PTR[144+rsp]
	movaps	xmm15,XMMWORD PTR[160+rsp]
	lea	rsp,QWORD PTR[184+rsp]
$L$enc_key_epilogue::
	xor	eax,eax
	mov	rdi,QWORD PTR[8+rsp]	;WIN64 epilogue
	mov	rsi,QWORD PTR[16+rsp]
	DB	0F3h,0C3h		;repret

$L$SEH_end_vpaes_set_encrypt_key::
vpaes_set_encrypt_key	ENDP

PUBLIC	vpaes_set_decrypt_key

ALIGN	16
vpaes_set_decrypt_key	PROC PUBLIC
	mov	QWORD PTR[8+rsp],rdi	;WIN64 prologue
	mov	QWORD PTR[16+rsp],rsi
	mov	rax,rsp
$L$SEH_begin_vpaes_set_decrypt_key::
	mov	rdi,rcx
	mov	rsi,rdx
	mov	rdx,r8



	lea	rsp,QWORD PTR[((-184))+rsp]
	movaps	XMMWORD PTR[16+rsp],xmm6
	movaps	XMMWORD PTR[32+rsp],xmm7
	movaps	XMMWORD PTR[48+rsp],xmm8
	movaps	XMMWORD PTR[64+rsp],xmm9
	movaps	XMMWORD PTR[80+rsp],xmm10
	movaps	XMMWORD PTR[96+rsp],xmm11
	movaps	XMMWORD PTR[112+rsp],xmm12
	movaps	XMMWORD PTR[128+rsp],xmm13
	movaps	XMMWORD PTR[144+rsp],xmm14
	movaps	XMMWORD PTR[160+rsp],xmm15
$L$dec_key_body::
	mov	eax,esi
	shr	eax,5
	add	eax,5
	mov	DWORD PTR[240+rdx],eax
	shl	eax,4
	lea	rdx,QWORD PTR[16+rax*1+rdx]

	mov	ecx,1
	mov	r8d,esi
	shr	r8d,1
	and	r8d,32
	xor	r8d,32
	call	_vpaes_schedule_core
	movaps	xmm6,XMMWORD PTR[16+rsp]
	movaps	xmm7,XMMWORD PTR[32+rsp]
	movaps	xmm8,XMMWORD PTR[48+rsp]
	movaps	xmm9,XMMWORD PTR[64+rsp]
	movaps	xmm10,XMMWORD PTR[80+rsp]
	movaps	xmm11,XMMWORD PTR[96+rsp]
	movaps	xmm12,XMMWORD PTR[112+rsp]
	movaps	xmm13,XMMWORD PTR[128+rsp]
	movaps	xmm14,XMMWORD PTR[144+rsp]
	movaps	xmm15,XMMWORD PTR[160+rsp]
	lea	rsp,QWORD PTR[184+rsp]
$L$dec_key_epilogue::
	xor	eax,eax
	mov	rdi,QWORD PTR[8+rsp]	;WIN64 epilogue
	mov	rsi,QWORD PTR[16+rsp]
	DB	0F3h,0C3h		;repret

$L$SEH_end_vpaes_set_decrypt_key::
vpaes_set_decrypt_key	ENDP

PUBLIC	vpaes_encrypt

ALIGN	16
vpaes_encrypt	PROC PUBLIC
	mov	QWORD PTR[8+rsp],rdi	;WIN64 prologue
	mov	QWORD PTR[16+rsp],rsi
	mov	rax,rsp
$L$SEH_begin_vpaes_encrypt::
	mov	rdi,rcx
	mov	rsi,rdx
	mov	rdx,r8



	lea	rsp,QWORD PTR[((-184))+rsp]
	movaps	XMMWORD PTR[16+rsp],xmm6
	movaps	XMMWORD PTR[32+rsp],xmm7
	movaps	XMMWORD PTR[48+rsp],xmm8
	movaps	XMMWORD PTR[64+rsp],xmm9
	movaps	XMMWORD PTR[80+rsp],xmm10
	movaps	XMMWORD PTR[96+rsp],xmm11
	movaps	XMMWORD PTR[112+rsp],xmm12
	movaps	XMMWORD PTR[128+rsp],xmm13
	movaps	XMMWORD PTR[144+rsp],xmm14
	movaps	XMMWORD PTR[160+rsp],xmm15
$L$enc_body::
	movdqu	xmm0,XMMWORD PTR[rdi]
	call	_vpaes_preheat
	call	_vpaes_encrypt_core
	movdqu	XMMWORD PTR[rsi],xmm0
	movaps	xmm6,XMMWORD PTR[16+rsp]
	movaps	xmm7,XMMWORD PTR[32+rsp]
	movaps	xmm8,XMMWORD PTR[48+rsp]
	movaps	xmm9,XMMWORD PTR[64+rsp]
	movaps	xmm10,XMMWORD PTR[80+rsp]
	movaps	xmm11,XMMWORD PTR[96+rsp]
	movaps	xmm12,XMMWORD PTR[112+rsp]
	movaps	xmm13,XMMWORD PTR[128+rsp]
	movaps	xmm14,XMMWORD PTR[144+rsp]
	movaps	xmm15,XMMWORD PTR[160+rsp]
	lea	rsp,QWORD PTR[184+rsp]
$L$enc_epilogue::
	mov	rdi,QWORD PTR[8+rsp]	;WIN64 epilogue
	mov	rsi,QWORD PTR[16+rsp]
	DB	0F3h,0C3h		;repret

$L$SEH_end_vpaes_encrypt::
vpaes_encrypt	ENDP

PUBLIC	vpaes_decrypt

ALIGN	16
vpaes_decrypt	PROC PUBLIC
	mov	QWORD PTR[8+rsp],rdi	;WIN64 prologue
	mov	QWORD PTR[16+rsp],rsi
	mov	rax,rsp
$L$SEH_begin_vpaes_decrypt::
	mov	rdi,rcx
	mov	rsi,rdx
	mov	rdx,r8



	lea	rsp,QWORD PTR[((-184))+rsp]
	movaps	XMMWORD PTR[16+rsp],xmm6
	movaps	XMMWORD PTR[32+rsp],xmm7
	movaps	XMMWORD PTR[48+rsp],xmm8
	movaps	XMMWORD PTR[64+rsp],xmm9
	movaps	XMMWORD PTR[80+rsp],xmm10
	movaps	XMMWORD PTR[96+rsp],xmm11
	movaps	XMMWORD PTR[112+rsp],xmm12
	movaps	XMMWORD PTR[128+rsp],xmm13
	movaps	XMMWORD PTR[144+rsp],xmm14
	movaps	XMMWORD PTR[160+rsp],xmm15
$L$dec_body::
	movdqu	xmm0,XMMWORD PTR[rdi]
	call	_vpaes_preheat
	call	_vpaes_decrypt_core
	movdqu	XMMWORD PTR[rsi],xmm0
	movaps	xmm6,XMMWORD PTR[16+rsp]
	movaps	xmm7,XMMWORD PTR[32+rsp]
	movaps	xmm8,XMMWORD PTR[48+rsp]
	movaps	xmm9,XMMWORD PTR[64+rsp]
	movaps	xmm10,XMMWORD PTR[80+rsp]
	movaps	xmm11,XMMWORD PTR[96+rsp]
	movaps	xmm12,XMMWORD PTR[112+rsp]
	movaps	xmm13,XMMWORD PTR[128+rsp]
	movaps	xmm14,XMMWORD PTR[144+rsp]
	movaps	xmm15,XMMWORD PTR[160+rsp]
	lea	rsp,QWORD PTR[184+rsp]
$L$dec_epilogue::
	mov	rdi,QWORD PTR[8+rsp]	;WIN64 epilogue
	mov	rsi,QWORD PTR[16+rsp]
	DB	0F3h,0C3h		;repret

$L$SEH_end_vpaes_decrypt::
vpaes_decrypt	ENDP
PUBLIC	vpaes_cbc_encrypt

ALIGN	16
vpaes_cbc_encrypt	PROC PUBLIC
	mov	QWORD PTR[8+rsp],rdi	;WIN64 prologue
	mov	QWORD PTR[16+rsp],rsi
	mov	rax,rsp
$L$SEH_begin_vpaes_cbc_encrypt::
	mov	rdi,rcx
	mov	rsi,rdx
	mov	rdx,r8
	mov	rcx,r9
	mov	r8,QWORD PTR[40+rsp]
	mov	r9,QWORD PTR[48+rsp]



	xchg	rdx,rcx
	sub	rcx,16
	jc	$L$cbc_abort
	lea	rsp,QWORD PTR[((-184))+rsp]
	movaps	XMMWORD PTR[16+rsp],xmm6
	movaps	XMMWORD PTR[32+rsp],xmm7
	movaps	XMMWORD PTR[48+rsp],xmm8
	movaps	XMMWORD PTR[64+rsp],xmm9
	movaps	XMMWORD PTR[80+rsp],xmm10
	movaps	XMMWORD PTR[96+rsp],xmm11
	movaps	XMMWORD PTR[112+rsp],xmm12
	movaps	XMMWORD PTR[128+rsp],xmm13
	movaps	XMMWORD PTR[144+rsp],xmm14
	movaps	XMMWORD PTR[160+rsp],xmm15
$L$cbc_body::
	movdqu	xmm6,XMMWORD PTR[r8]
	sub	rsi,rdi
	call	_vpaes_preheat
	cmp	r9d,0
	je	$L$cbc_dec_loop
	jmp	$L$cbc_enc_loop
ALIGN	16
$L$cbc_enc_loop::
	movdqu	xmm0,XMMWORD PTR[rdi]
	pxor	xmm0,xmm6
	call	_vpaes_encrypt_core
	movdqa	xmm6,xmm0
	movdqu	XMMWORD PTR[rdi*1+rsi],xmm0
	lea	rdi,QWORD PTR[16+rdi]
	sub	rcx,16
	jnc	$L$cbc_enc_loop
	jmp	$L$cbc_done
ALIGN	16
$L$cbc_dec_loop::
	movdqu	xmm0,XMMWORD PTR[rdi]
	movdqa	xmm7,xmm0
	call	_vpaes_decrypt_core
	pxor	xmm0,xmm6
	movdqa	xmm6,xmm7
	movdqu	XMMWORD PTR[rdi*1+rsi],xmm0
	lea	rdi,QWORD PTR[16+rdi]
	sub	rcx,16
	jnc	$L$cbc_dec_loop
$L$cbc_done::
	movdqu	XMMWORD PTR[r8],xmm6
	movaps	xmm6,XMMWORD PTR[16+rsp]
	movaps	xmm7,XMMWORD PTR[32+rsp]
	movaps	xmm8,XMMWORD PTR[48+rsp]
	movaps	xmm9,XMMWORD PTR[64+rsp]
	movaps	xmm10,XMMWORD PTR[80+rsp]
	movaps	xmm11,XMMWORD PTR[96+rsp]
	movaps	xmm12,XMMWORD PTR[112+rsp]
	movaps	xmm13,XMMWORD PTR[128+rsp]
	movaps	xmm14,XMMWORD PTR[144+rsp]
	movaps	xmm15,XMMWORD PTR[160+rsp]
	lea	rsp,QWORD PTR[184+rsp]
$L$cbc_epilogue::
$L$cbc_abort::
	mov	rdi,QWORD PTR[8+rsp]	;WIN64 epilogue
	mov	rsi,QWORD PTR[16+rsp]
	DB	0F3h,0C3h		;repret

$L$SEH_end_vpaes_cbc_encrypt::
vpaes_cbc_encrypt	ENDP







ALIGN	16
_vpaes_preheat	PROC PRIVATE

	lea	r10,QWORD PTR[$L$k_s0F]
	movdqa	xmm10,XMMWORD PTR[((-32))+r10]
	movdqa	xmm11,XMMWORD PTR[((-16))+r10]
	movdqa	xmm9,XMMWORD PTR[r10]
	movdqa	xmm13,XMMWORD PTR[48+r10]
	movdqa	xmm12,XMMWORD PTR[64+r10]
	movdqa	xmm15,XMMWORD PTR[80+r10]
	movdqa	xmm14,XMMWORD PTR[96+r10]
	DB	0F3h,0C3h		;repret

_vpaes_preheat	ENDP






ALIGN	64
_vpaes_consts::
$L$k_inv::
	DQ	00E05060F0D080180h,0040703090A0B0C02h
	DQ	001040A060F0B0780h,0030D0E0C02050809h

$L$k_s0F::
	DQ	00F0F0F0F0F0F0F0Fh,00F0F0F0F0F0F0F0Fh

$L$k_ipt::
	DQ	0C2B2E8985A2A7000h,0CABAE09052227808h
	DQ	04C01307D317C4D00h,0CD80B1FCB0FDCC81h

$L$k_sb1::
	DQ	0B19BE18FCB503E00h,0A5DF7A6E142AF544h
	DQ	03618D415FAE22300h,03BF7CCC10D2ED9EFh
$L$k_sb2::
	DQ	0E27A93C60B712400h,05EB7E955BC982FCDh
	DQ	069EB88400AE12900h,0C2A163C8AB82234Ah
$L$k_sbo::
	DQ	0D0D26D176FBDC700h,015AABF7AC502A878h
	DQ	0CFE474A55FBB6A00h,08E1E90D1412B35FAh

$L$k_mc_forward::
	DQ	00407060500030201h,00C0F0E0D080B0A09h
	DQ	0080B0A0904070605h,0000302010C0F0E0Dh
	DQ	00C0F0E0D080B0A09h,00407060500030201h
	DQ	0000302010C0F0E0Dh,0080B0A0904070605h

$L$k_mc_backward::
	DQ	00605040702010003h,00E0D0C0F0A09080Bh
	DQ	0020100030E0D0C0Fh,00A09080B06050407h
	DQ	00E0D0C0F0A09080Bh,00605040702010003h
	DQ	00A09080B06050407h,0020100030E0D0C0Fh

$L$k_sr::
	DQ	00706050403020100h,00F0E0D0C0B0A0908h
	DQ	0030E09040F0A0500h,00B06010C07020D08h
	DQ	00F060D040B020900h,0070E050C030A0108h
	DQ	00B0E0104070A0D00h,00306090C0F020508h

$L$k_rcon::
	DQ	01F8391B9AF9DEEB6h,0702A98084D7C7D81h

$L$k_s63::
	DQ	05B5B5B5B5B5B5B5Bh,05B5B5B5B5B5B5B5Bh

$L$k_opt::
	DQ	0FF9F4929D6B66000h,0F7974121DEBE6808h
	DQ	001EDBD5150BCEC00h,0E10D5DB1B05C0CE0h

$L$k_deskew::
	DQ	007E4A34047A4E300h,01DFEB95A5DBEF91Ah
	DQ	05F36B5DC83EA6900h,02841C2ABF49D1E77h





$L$k_dksd::
	DQ	0FEB91A5DA3E44700h,00740E3A45A1DBEF9h
	DQ	041C277F4B5368300h,05FDC69EAAB289D1Eh
$L$k_dksb::
	DQ	09A4FCA1F8550D500h,003D653861CC94C99h
	DQ	0115BEDA7B6FC4A00h,0D993256F7E3482C8h
$L$k_dkse::
	DQ	0D5031CCA1FC9D600h,053859A4C994F5086h
	DQ	0A23196054FDC7BE8h,0CD5EF96A20B31487h
$L$k_dks9::
	DQ	0B6116FC87ED9A700h,04AED933482255BFCh
	DQ	04576516227143300h,08BB89FACE9DAFDCEh





$L$k_dipt::
	DQ	00F505B040B545F00h,0154A411E114E451Ah
	DQ	086E383E660056500h,012771772F491F194h

$L$k_dsb9::
	DQ	0851C03539A86D600h,0CAD51F504F994CC9h
	DQ	0C03B1789ECD74900h,0725E2C9EB2FBA565h
$L$k_dsbd::
	DQ	07D57CCDFE6B1A200h,0F56E9B13882A4439h
	DQ	03CE2FAF724C6CB00h,02931180D15DEEFD3h
$L$k_dsbb::
	DQ	0D022649296B44200h,0602646F6B0F2D404h
	DQ	0C19498A6CD596700h,0F3FF0C3E3255AA6Bh
$L$k_dsbe::
	DQ	046F2929626D4D000h,02242600464B4F6B0h
	DQ	00C55A6CDFFAAC100h,09467F36B98593E32h
$L$k_dsbo::
	DQ	01387EA537EF94000h,0C7AA6DB9D4943E2Dh
	DQ	012D7560F93441D00h,0CA4B8159D8C58E9Ch
DB	86,101,99,116,111,114,32,80,101,114,109,117,116,97,116,105
DB	111,110,32,65,69,83,32,102,111,114,32,120,56,54,95,54
DB	52,47,83,83,83,69,51,44,32,77,105,107,101,32,72,97
DB	109,98,117,114,103,32,40,83,116,97,110,102,111,114,100,32
DB	85,110,105,118,101,114,115,105,116,121,41,0
ALIGN	64

EXTERN	__imp_RtlVirtualUnwind:NEAR

ALIGN	16
se_handler	PROC PRIVATE
	push	rsi
	push	rdi
	push	rbx
	push	rbp
	push	r12
	push	r13
	push	r14
	push	r15
	pushfq
	sub	rsp,64

	mov	rax,QWORD PTR[120+r8]
	mov	rbx,QWORD PTR[248+r8]

	mov	rsi,QWORD PTR[8+r9]
	mov	r11,QWORD PTR[56+r9]

	mov	r10d,DWORD PTR[r11]
	lea	r10,QWORD PTR[r10*1+rsi]
	cmp	rbx,r10
	jb	$L$in_prologue

	mov	rax,QWORD PTR[152+r8]

	mov	r10d,DWORD PTR[4+r11]
	lea	r10,QWORD PTR[r10*1+rsi]
	cmp	rbx,r10
	jae	$L$in_prologue

	lea	rsi,QWORD PTR[16+rax]
	lea	rdi,QWORD PTR[512+r8]
	mov	ecx,20
	DD	0a548f3fch
	lea	rax,QWORD PTR[184+rax]

$L$in_prologue::
	mov	rdi,QWORD PTR[8+rax]
	mov	rsi,QWORD PTR[16+rax]
	mov	QWORD PTR[152+r8],rax
	mov	QWORD PTR[168+r8],rsi
	mov	QWORD PTR[176+r8],rdi

	mov	rdi,QWORD PTR[40+r9]
	mov	rsi,r8
	mov	ecx,154
	DD	0a548f3fch

	mov	rsi,r9
	xor	rcx,rcx
	mov	rdx,QWORD PTR[8+rsi]
	mov	r8,QWORD PTR[rsi]
	mov	r9,QWORD PTR[16+rsi]
	mov	r10,QWORD PTR[40+rsi]
	lea	r11,QWORD PTR[56+rsi]
	lea	r12,QWORD PTR[24+rsi]
	mov	QWORD PTR[32+rsp],r10
	mov	QWORD PTR[40+rsp],r11
	mov	QWORD PTR[48+rsp],r12
	mov	QWORD PTR[56+rsp],rcx
	call	QWORD PTR[__imp_RtlVirtualUnwind]

	mov	eax,1
	add	rsp,64
	popfq
	pop	r15
	pop	r14
	pop	r13
	pop	r12
	pop	rbp
	pop	rbx
	pop	rdi
	pop	rsi
	DB	0F3h,0C3h		;repret
se_handler	ENDP

.text$	ENDS
.pdata	SEGMENT READONLY ALIGN(4)
ALIGN	4
	DD	imagerel $L$SEH_begin_vpaes_set_encrypt_key
	DD	imagerel $L$SEH_end_vpaes_set_encrypt_key
	DD	imagerel $L$SEH_info_vpaes_set_encrypt_key

	DD	imagerel $L$SEH_begin_vpaes_set_decrypt_key
	DD	imagerel $L$SEH_end_vpaes_set_decrypt_key
	DD	imagerel $L$SEH_info_vpaes_set_decrypt_key

	DD	imagerel $L$SEH_begin_vpaes_encrypt
	DD	imagerel $L$SEH_end_vpaes_encrypt
	DD	imagerel $L$SEH_info_vpaes_encrypt

	DD	imagerel $L$SEH_begin_vpaes_decrypt
	DD	imagerel $L$SEH_end_vpaes_decrypt
	DD	imagerel $L$SEH_info_vpaes_decrypt

	DD	imagerel $L$SEH_begin_vpaes_cbc_encrypt
	DD	imagerel $L$SEH_end_vpaes_cbc_encrypt
	DD	imagerel $L$SEH_info_vpaes_cbc_encrypt

.pdata	ENDS
.xdata	SEGMENT READONLY ALIGN(8)
ALIGN	8
$L$SEH_info_vpaes_set_encrypt_key::
DB	9,0,0,0
	DD	imagerel se_handler
	DD	imagerel $L$enc_key_body,imagerel $L$enc_key_epilogue
$L$SEH_info_vpaes_set_decrypt_key::
DB	9,0,0,0
	DD	imagerel se_handler
	DD	imagerel $L$dec_key_body,imagerel $L$dec_key_epilogue
$L$SEH_info_vpaes_encrypt::
DB	9,0,0,0
	DD	imagerel se_handler
	DD	imagerel $L$enc_body,imagerel $L$enc_epilogue
$L$SEH_info_vpaes_decrypt::
DB	9,0,0,0
	DD	imagerel se_handler
	DD	imagerel $L$dec_body,imagerel $L$dec_epilogue
$L$SEH_info_vpaes_cbc_encrypt::
DB	9,0,0,0
	DD	imagerel se_handler
	DD	imagerel $L$cbc_body,imagerel $L$cbc_epilogue

.xdata	ENDS
END