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
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
|
.machine "any"
.abiversion 2
.text
.align 7
_vpaes_consts:
.Lk_mc_forward:
.byte 0x0e,0x0d,0x0c,0x0f,0x0a,0x09,0x08,0x0b,0x06,0x05,0x04,0x07,0x02,0x01,0x00,0x03
.byte 0x0a,0x09,0x08,0x0b,0x06,0x05,0x04,0x07,0x02,0x01,0x00,0x03,0x0e,0x0d,0x0c,0x0f
.byte 0x06,0x05,0x04,0x07,0x02,0x01,0x00,0x03,0x0e,0x0d,0x0c,0x0f,0x0a,0x09,0x08,0x0b
.byte 0x02,0x01,0x00,0x03,0x0e,0x0d,0x0c,0x0f,0x0a,0x09,0x08,0x0b,0x06,0x05,0x04,0x07
.Lk_mc_backward:
.byte 0x0c,0x0f,0x0e,0x0d,0x08,0x0b,0x0a,0x09,0x04,0x07,0x06,0x05,0x00,0x03,0x02,0x01
.byte 0x00,0x03,0x02,0x01,0x0c,0x0f,0x0e,0x0d,0x08,0x0b,0x0a,0x09,0x04,0x07,0x06,0x05
.byte 0x04,0x07,0x06,0x05,0x00,0x03,0x02,0x01,0x0c,0x0f,0x0e,0x0d,0x08,0x0b,0x0a,0x09
.byte 0x08,0x0b,0x0a,0x09,0x04,0x07,0x06,0x05,0x00,0x03,0x02,0x01,0x0c,0x0f,0x0e,0x0d
.Lk_sr:
.byte 0x0f,0x0e,0x0d,0x0c,0x0b,0x0a,0x09,0x08,0x07,0x06,0x05,0x04,0x03,0x02,0x01,0x00
.byte 0x0f,0x0a,0x05,0x00,0x0b,0x06,0x01,0x0c,0x07,0x02,0x0d,0x08,0x03,0x0e,0x09,0x04
.byte 0x0f,0x06,0x0d,0x04,0x0b,0x02,0x09,0x00,0x07,0x0e,0x05,0x0c,0x03,0x0a,0x01,0x08
.byte 0x0f,0x02,0x05,0x08,0x0b,0x0e,0x01,0x04,0x07,0x0a,0x0d,0x00,0x03,0x06,0x09,0x0c
.Lk_inv:
.byte 0x04,0x07,0x03,0x09,0x0a,0x0b,0x0c,0x02,0x0e,0x05,0x06,0x0f,0x0d,0x08,0x01,0xf0
.byte 0x03,0x0d,0x0e,0x0c,0x02,0x05,0x08,0x09,0x01,0x04,0x0a,0x06,0x0f,0x0b,0x07,0xf0
.Lk_ipt:
.byte 0xca,0xba,0xe0,0x90,0x52,0x22,0x78,0x08,0xc2,0xb2,0xe8,0x98,0x5a,0x2a,0x70,0x00
.byte 0xcd,0x80,0xb1,0xfc,0xb0,0xfd,0xcc,0x81,0x4c,0x01,0x30,0x7d,0x31,0x7c,0x4d,0x00
.Lk_sbo:
.byte 0x15,0xaa,0xbf,0x7a,0xc5,0x02,0xa8,0x78,0xd0,0xd2,0x6d,0x17,0x6f,0xbd,0xc7,0x00
.byte 0x8e,0x1e,0x90,0xd1,0x41,0x2b,0x35,0xfa,0xcf,0xe4,0x74,0xa5,0x5f,0xbb,0x6a,0x00
.Lk_sb1:
.byte 0x3b,0xf7,0xcc,0xc1,0x0d,0x2e,0xd9,0xef,0x36,0x18,0xd4,0x15,0xfa,0xe2,0x23,0x00
.byte 0xa5,0xdf,0x7a,0x6e,0x14,0x2a,0xf5,0x44,0xb1,0x9b,0xe1,0x8f,0xcb,0x50,0x3e,0x00
.Lk_sb2:
.byte 0xc2,0xa1,0x63,0xc8,0xab,0x82,0x23,0x4a,0x69,0xeb,0x88,0x40,0x0a,0xe1,0x29,0x00
.byte 0x5e,0xb7,0xe9,0x55,0xbc,0x98,0x2f,0xcd,0xe2,0x7a,0x93,0xc6,0x0b,0x71,0x24,0x00
.Lk_dipt:
.byte 0x15,0x4a,0x41,0x1e,0x11,0x4e,0x45,0x1a,0x0f,0x50,0x5b,0x04,0x0b,0x54,0x5f,0x00
.byte 0x12,0x77,0x17,0x72,0xf4,0x91,0xf1,0x94,0x86,0xe3,0x83,0xe6,0x60,0x05,0x65,0x00
.Lk_dsbo:
.byte 0xc7,0xaa,0x6d,0xb9,0xd4,0x94,0x3e,0x2d,0x13,0x87,0xea,0x53,0x7e,0xf9,0x40,0x00
.byte 0xca,0x4b,0x81,0x59,0xd8,0xc5,0x8e,0x9c,0x12,0xd7,0x56,0x0f,0x93,0x44,0x1d,0x00
.Lk_dsb9:
.byte 0xca,0xd5,0x1f,0x50,0x4f,0x99,0x4c,0xc9,0x85,0x1c,0x03,0x53,0x9a,0x86,0xd6,0x00
.byte 0x72,0x5e,0x2c,0x9e,0xb2,0xfb,0xa5,0x65,0xc0,0x3b,0x17,0x89,0xec,0xd7,0x49,0x00
.Lk_dsbd:
.byte 0xf5,0x6e,0x9b,0x13,0x88,0x2a,0x44,0x39,0x7d,0x57,0xcc,0xdf,0xe6,0xb1,0xa2,0x00
.byte 0x29,0x31,0x18,0x0d,0x15,0xde,0xef,0xd3,0x3c,0xe2,0xfa,0xf7,0x24,0xc6,0xcb,0x00
.Lk_dsbb:
.byte 0x60,0x26,0x46,0xf6,0xb0,0xf2,0xd4,0x04,0xd0,0x22,0x64,0x92,0x96,0xb4,0x42,0x00
.byte 0xf3,0xff,0x0c,0x3e,0x32,0x55,0xaa,0x6b,0xc1,0x94,0x98,0xa6,0xcd,0x59,0x67,0x00
.Lk_dsbe:
.byte 0x22,0x42,0x60,0x04,0x64,0xb4,0xf6,0xb0,0x46,0xf2,0x92,0x96,0x26,0xd4,0xd0,0x00
.byte 0x94,0x67,0xf3,0x6b,0x98,0x59,0x3e,0x32,0x0c,0x55,0xa6,0xcd,0xff,0xaa,0xc1,0x00
.Lk_dksd:
.byte 0x07,0x40,0xe3,0xa4,0x5a,0x1d,0xbe,0xf9,0xfe,0xb9,0x1a,0x5d,0xa3,0xe4,0x47,0x00
.byte 0x5f,0xdc,0x69,0xea,0xab,0x28,0x9d,0x1e,0x41,0xc2,0x77,0xf4,0xb5,0x36,0x83,0x00
.Lk_dksb:
.byte 0x03,0xd6,0x53,0x86,0x1c,0xc9,0x4c,0x99,0x9a,0x4f,0xca,0x1f,0x85,0x50,0xd5,0x00
.byte 0xd9,0x93,0x25,0x6f,0x7e,0x34,0x82,0xc8,0x11,0x5b,0xed,0xa7,0xb6,0xfc,0x4a,0x00
.Lk_dkse:
.byte 0x53,0x85,0x9a,0x4c,0x99,0x4f,0x50,0x86,0xd5,0x03,0x1c,0xca,0x1f,0xc9,0xd6,0x00
.byte 0xcd,0x5e,0xf9,0x6a,0x20,0xb3,0x14,0x87,0xa2,0x31,0x96,0x05,0x4f,0xdc,0x7b,0xe8
.Lk_dks9:
.byte 0x4a,0xed,0x93,0x34,0x82,0x25,0x5b,0xfc,0xb6,0x11,0x6f,0xc8,0x7e,0xd9,0xa7,0x00
.byte 0x8b,0xb8,0x9f,0xac,0xe9,0xda,0xfd,0xce,0x45,0x76,0x51,0x62,0x27,0x14,0x33,0x00
.Lk_rcon:
.byte 0xb6,0xee,0x9d,0xaf,0xb9,0x91,0x83,0x1f,0x81,0x7d,0x7c,0x4d,0x08,0x98,0x2a,0x70
.Lk_s63:
.byte 0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b
.Lk_opt:
.byte 0xf7,0x97,0x41,0x21,0xde,0xbe,0x68,0x08,0xff,0x9f,0x49,0x29,0xd6,0xb6,0x60,0x00
.byte 0xe1,0x0d,0x5d,0xb1,0xb0,0x5c,0x0c,0xe0,0x01,0xed,0xbd,0x51,0x50,0xbc,0xec,0x00
.Lk_deskew:
.byte 0x1d,0xfe,0xb9,0x5a,0x5d,0xbe,0xf9,0x1a,0x07,0xe4,0xa3,0x40,0x47,0xa4,0xe3,0x00
.byte 0x28,0x41,0xc2,0xab,0xf4,0x9d,0x1e,0x77,0x5f,0x36,0xb5,0xdc,0x83,0xea,0x69,0x00
.align 5
.Lconsts:
mflr 0
bcl 20,31,$+4
mflr 12
addi 12,12,-0x308
mtlr 0
blr
.long 0
.byte 0,12,0x14,0,0,0,0,0
.byte 86,101,99,116,111,114,32,80,101,114,109,117,116,97,116,105,111,110,32,65,69,83,32,102,111,114,32,65,108,116,105,86,101,99,44,77,105,107,101,32,72,97,109,98,117,114,103,32,40,83,116,97,110,102,111,114,100,32,85,110,105,118,101,114,115,105,116,121,41,0
.align 2
.align 6
.align 4
_vpaes_encrypt_preheat:
mflr 8
bl .Lconsts
mtlr 8
li 11, 0xc0
li 10, 0xd0
li 9, 0xe0
li 8, 0xf0
vxor 7, 7, 7
vspltisb 8,4
vspltisb 9,0x0f
lvx 10, 12, 11
li 11, 0x100
lvx 11, 12, 10
li 10, 0x110
lvx 12, 12, 9
li 9, 0x120
lvx 13, 12, 8
li 8, 0x130
lvx 14, 12, 11
li 11, 0x140
lvx 15, 12, 10
li 10, 0x150
lvx 16, 12, 9
lvx 17, 12, 8
lvx 18, 12, 11
lvx 19, 12, 10
blr
.long 0
.byte 0,12,0x14,0,0,0,0,0
.align 5
_vpaes_encrypt_core:
lwz 8, 240(5)
li 9, 16
lvx 5, 0, 5
li 11, 0x10
lvx 6, 9, 5
addi 9, 9, 16
vperm 5, 6, 5, 31
addi 10, 11, 0x40
vsrb 1, 0, 8
vperm 0, 12, 12, 0
vperm 1, 13, 13, 1
vxor 0, 0, 5
vxor 0, 0, 1
mtctr 8
b .Lenc_entry
.align 4
.Lenc_loop:
vperm 4, 17, 7, 2
lvx 1, 12, 11
addi 11, 11, 16
vperm 0, 16, 7, 3
vxor 4, 4, 5
andi. 11, 11, 0x30
vperm 5, 19, 7, 2
vxor 0, 0, 4
vperm 2, 18, 7, 3
lvx 4, 12, 10
addi 10, 11, 0x40
vperm 3, 0, 7, 1
vxor 2, 2, 5
vperm 0, 0, 7, 4
vxor 3, 3, 2
vperm 4, 3, 7, 1
vxor 0, 0, 3
vxor 0, 0, 4
.Lenc_entry:
vsrb 1, 0, 8
vperm 5, 11, 11, 0
vxor 0, 0, 1
vperm 3, 10, 10, 1
vperm 4, 10, 10, 0
vand 0, 0, 9
vxor 3, 3, 5
vxor 4, 4, 5
vperm 2, 10, 7, 3
vor 5,6,6
lvx 6, 9, 5
vperm 3, 10, 7, 4
addi 9, 9, 16
vxor 2, 2, 0
vperm 5, 6, 5, 31
vxor 3, 3, 1
bdnz .Lenc_loop
addi 10, 11, 0x80
vperm 4, 14, 7, 2
lvx 1, 12, 10
vperm 0, 15, 7, 3
vxor 4, 4, 5
vxor 0, 0, 4
vperm 0, 0, 7, 1
blr
.long 0
.byte 0,12,0x14,0,0,0,0,0
.globl vpaes_encrypt
.type vpaes_encrypt,@function
.align 5
vpaes_encrypt:
.localentry vpaes_encrypt,0
stdu 1,-256(1)
li 10,63
li 11,79
mflr 6
li 7,-1
stvx 20,10,1
addi 10,10,32
stvx 21,11,1
addi 11,11,32
stvx 22,10,1
addi 10,10,32
stvx 23,11,1
addi 11,11,32
stvx 24,10,1
addi 10,10,32
stvx 25,11,1
addi 11,11,32
stvx 26,10,1
addi 10,10,32
stvx 27,11,1
addi 11,11,32
stvx 28,10,1
addi 10,10,32
stvx 29,11,1
addi 11,11,32
stvx 30,10,1
stvx 31,11,1
stw 7,252(1)
li 0, -1
std 6,272(1)
or 0,0,0
bl _vpaes_encrypt_preheat
lvsr 27, 0, 3
lvx 0, 0, 3
addi 3, 3, 15
lvsl 29, 0, 4
lvsr 31, 0, 5
lvx 26, 0, 3
vperm 0, 26, 0, 27
bl _vpaes_encrypt_core
andi. 8, 4, 15
li 9, 16
beq .Lenc_out_aligned
vperm 0, 0, 0, 29
mtctr 9
.Lenc_out_unaligned:
stvebx 0, 0, 4
addi 4, 4, 1
bdnz .Lenc_out_unaligned
b .Lenc_done
.align 4
.Lenc_out_aligned:
stvx 0, 0, 4
.Lenc_done:
li 10,63
li 11,79
mtlr 6
or 7,7,7
lvx 20,10,1
addi 10,10,32
lvx 21,11,1
addi 11,11,32
lvx 22,10,1
addi 10,10,32
lvx 23,11,1
addi 11,11,32
lvx 24,10,1
addi 10,10,32
lvx 25,11,1
addi 11,11,32
lvx 26,10,1
addi 10,10,32
lvx 27,11,1
addi 11,11,32
lvx 28,10,1
addi 10,10,32
lvx 29,11,1
addi 11,11,32
lvx 30,10,1
lvx 31,11,1
addi 1,1,256
blr
.long 0
.byte 0,12,0x04,1,0x80,0,3,0
.long 0
.size vpaes_encrypt,.-vpaes_encrypt
.align 4
_vpaes_decrypt_preheat:
mflr 8
bl .Lconsts
mtlr 8
li 11, 0xc0
li 10, 0xd0
li 9, 0x160
li 8, 0x170
vxor 7, 7, 7
vspltisb 8,4
vspltisb 9,0x0f
lvx 10, 12, 11
li 11, 0x180
lvx 11, 12, 10
li 10, 0x190
lvx 12, 12, 9
li 9, 0x1a0
lvx 13, 12, 8
li 8, 0x1b0
lvx 14, 12, 11
li 11, 0x1c0
lvx 15, 12, 10
li 10, 0x1d0
lvx 16, 12, 9
li 9, 0x1e0
lvx 17, 12, 8
li 8, 0x1f0
lvx 18, 12, 11
li 11, 0x200
lvx 19, 12, 10
li 10, 0x210
lvx 20, 12, 9
lvx 21, 12, 8
lvx 22, 12, 11
lvx 23, 12, 10
blr
.long 0
.byte 0,12,0x14,0,0,0,0,0
.align 4
_vpaes_decrypt_core:
lwz 8, 240(5)
li 9, 16
lvx 5, 0, 5
li 11, 0x30
lvx 6, 9, 5
addi 9, 9, 16
vperm 5, 6, 5, 31
vsrb 1, 0, 8
vperm 0, 12, 12, 0
vperm 1, 13, 13, 1
vxor 0, 0, 5
vxor 0, 0, 1
mtctr 8
b .Ldec_entry
.align 4
.Ldec_loop:
lvx 0, 12, 11
vperm 4, 16, 7, 2
subi 11, 11, 16
vperm 1, 17, 7, 3
andi. 11, 11, 0x30
vxor 5, 5, 4
vxor 5, 5, 1
vperm 4, 18, 7, 2
vperm 5, 5, 7, 0
vperm 1, 19, 7, 3
vxor 5, 5, 4
vxor 5, 5, 1
vperm 4, 20, 7, 2
vperm 5, 5, 7, 0
vperm 1, 21, 7, 3
vxor 5, 5, 4
vxor 5, 5, 1
vperm 4, 22, 7, 2
vperm 5, 5, 7, 0
vperm 1, 23, 7, 3
vxor 0, 5, 4
vxor 0, 0, 1
.Ldec_entry:
vsrb 1, 0, 8
vperm 2, 11, 11, 0
vxor 0, 0, 1
vperm 3, 10, 10, 1
vperm 4, 10, 10, 0
vand 0, 0, 9
vxor 3, 3, 2
vxor 4, 4, 2
vperm 2, 10, 7, 3
vor 5,6,6
lvx 6, 9, 5
vperm 3, 10, 7, 4
addi 9, 9, 16
vxor 2, 2, 0
vperm 5, 6, 5, 31
vxor 3, 3, 1
bdnz .Ldec_loop
addi 10, 11, 0x80
vperm 4, 14, 7, 2
lvx 2, 12, 10
vperm 1, 15, 7, 3
vxor 4, 4, 5
vxor 0, 1, 4
vperm 0, 0, 7, 2
blr
.long 0
.byte 0,12,0x14,0,0,0,0,0
.globl vpaes_decrypt
.type vpaes_decrypt,@function
.align 5
vpaes_decrypt:
.localentry vpaes_decrypt,0
stdu 1,-256(1)
li 10,63
li 11,79
mflr 6
li 7,-1
stvx 20,10,1
addi 10,10,32
stvx 21,11,1
addi 11,11,32
stvx 22,10,1
addi 10,10,32
stvx 23,11,1
addi 11,11,32
stvx 24,10,1
addi 10,10,32
stvx 25,11,1
addi 11,11,32
stvx 26,10,1
addi 10,10,32
stvx 27,11,1
addi 11,11,32
stvx 28,10,1
addi 10,10,32
stvx 29,11,1
addi 11,11,32
stvx 30,10,1
stvx 31,11,1
stw 7,252(1)
li 0, -1
std 6,272(1)
or 0,0,0
bl _vpaes_decrypt_preheat
lvsr 27, 0, 3
lvx 0, 0, 3
addi 3, 3, 15
lvsl 29, 0, 4
lvsr 31, 0, 5
lvx 26, 0, 3
vperm 0, 26, 0, 27
bl _vpaes_decrypt_core
andi. 8, 4, 15
li 9, 16
beq .Ldec_out_aligned
vperm 0, 0, 0, 29
mtctr 9
.Ldec_out_unaligned:
stvebx 0, 0, 4
addi 4, 4, 1
bdnz .Ldec_out_unaligned
b .Ldec_done
.align 4
.Ldec_out_aligned:
stvx 0, 0, 4
.Ldec_done:
li 10,63
li 11,79
mtlr 6
or 7,7,7
lvx 20,10,1
addi 10,10,32
lvx 21,11,1
addi 11,11,32
lvx 22,10,1
addi 10,10,32
lvx 23,11,1
addi 11,11,32
lvx 24,10,1
addi 10,10,32
lvx 25,11,1
addi 11,11,32
lvx 26,10,1
addi 10,10,32
lvx 27,11,1
addi 11,11,32
lvx 28,10,1
addi 10,10,32
lvx 29,11,1
addi 11,11,32
lvx 30,10,1
lvx 31,11,1
addi 1,1,256
blr
.long 0
.byte 0,12,0x04,1,0x80,0,3,0
.long 0
.size vpaes_decrypt,.-vpaes_decrypt
.globl vpaes_cbc_encrypt
.type vpaes_cbc_encrypt,@function
.align 5
vpaes_cbc_encrypt:
.localentry vpaes_cbc_encrypt,0
cmpldi 5,16
.long 0x4dc00020
stdu 1,-272(1)
mflr 0
li 10,63
li 11,79
li 12,-1
stvx 20,10,1
addi 10,10,32
stvx 21,11,1
addi 11,11,32
stvx 22,10,1
addi 10,10,32
stvx 23,11,1
addi 11,11,32
stvx 24,10,1
addi 10,10,32
stvx 25,11,1
addi 11,11,32
stvx 26,10,1
addi 10,10,32
stvx 27,11,1
addi 11,11,32
stvx 28,10,1
addi 10,10,32
stvx 29,11,1
addi 11,11,32
stvx 30,10,1
stvx 31,11,1
stw 12,252(1)
std 30,256(1)
std 31,264(1)
li 9, -16
std 0, 288(1)
and 30, 5, 9
andi. 9, 4, 15
mr 5, 6
mr 31, 7
li 6, -1
mcrf 1, 0
mr 7, 12
or 6,6,6
lvx 24, 0, 31
li 9, 15
lvsr 27, 0, 31
lvx 25, 9, 31
vperm 24, 25, 24, 27
cmpwi 8, 0
neg 8, 3
vxor 7, 7, 7
lvsr 31, 0, 5
lvsl 29, 0, 4
lvsl 27, 0, 8
vnor 30, 7, 7
lvx 26, 0, 3
vperm 30, 30, 7, 29
addi 3, 3, 15
beq .Lcbc_decrypt
bl _vpaes_encrypt_preheat
li 0, 16
beq 1, .Lcbc_enc_loop
vor 0,26,26
lvx 26, 0, 3
addi 3, 3, 16
vperm 0, 26, 0, 27
vxor 0, 0, 24
bl _vpaes_encrypt_core
andi. 8, 4, 15
vor 24,0,0
sub 9, 4, 8
vperm 28, 0, 0, 29
.Lcbc_enc_head:
stvebx 28, 8, 9
cmpwi 8, 15
addi 8, 8, 1
bne .Lcbc_enc_head
sub. 30, 30, 0
addi 4, 4, 16
beq .Lcbc_unaligned_done
.Lcbc_enc_loop:
vor 0,26,26
lvx 26, 0, 3
addi 3, 3, 16
vperm 0, 26, 0, 27
vxor 0, 0, 24
bl _vpaes_encrypt_core
vor 24,0,0
sub. 30, 30, 0
vperm 0, 0, 0, 29
vsel 1, 28, 0, 30
vor 28,0,0
stvx 1, 0, 4
addi 4, 4, 16
bne .Lcbc_enc_loop
b .Lcbc_done
.align 5
.Lcbc_decrypt:
bl _vpaes_decrypt_preheat
li 0, 16
beq 1, .Lcbc_dec_loop
vor 0,26,26
lvx 26, 0, 3
addi 3, 3, 16
vperm 0, 26, 0, 27
vor 25,0,0
bl _vpaes_decrypt_core
andi. 8, 4, 15
vxor 0, 0, 24
vor 24,25,25
sub 9, 4, 8
vperm 28, 0, 0, 29
.Lcbc_dec_head:
stvebx 28, 8, 9
cmpwi 8, 15
addi 8, 8, 1
bne .Lcbc_dec_head
sub. 30, 30, 0
addi 4, 4, 16
beq .Lcbc_unaligned_done
.Lcbc_dec_loop:
vor 0,26,26
lvx 26, 0, 3
addi 3, 3, 16
vperm 0, 26, 0, 27
vor 25,0,0
bl _vpaes_decrypt_core
vxor 0, 0, 24
vor 24,25,25
sub. 30, 30, 0
vperm 0, 0, 0, 29
vsel 1, 28, 0, 30
vor 28,0,0
stvx 1, 0, 4
addi 4, 4, 16
bne .Lcbc_dec_loop
.Lcbc_done:
beq 1, .Lcbc_write_iv
.Lcbc_unaligned_done:
andi. 8, 4, 15
sub 4, 4, 8
li 9, 0
.Lcbc_tail:
stvebx 28, 9, 4
addi 9, 9, 1
cmpw 9, 8
bne .Lcbc_tail
.Lcbc_write_iv:
neg 8, 31
li 10, 4
lvsr 29, 0, 8
li 11, 8
li 12, 12
vperm 24, 24, 24, 29
stvewx 24, 0, 31
stvewx 24, 10, 31
stvewx 24, 11, 31
stvewx 24, 12, 31
or 7,7,7
li 10,63
li 11,79
lvx 20,10,1
addi 10,10,32
lvx 21,11,1
addi 11,11,32
lvx 22,10,1
addi 10,10,32
lvx 23,11,1
addi 11,11,32
lvx 24,10,1
addi 10,10,32
lvx 25,11,1
addi 11,11,32
lvx 26,10,1
addi 10,10,32
lvx 27,11,1
addi 11,11,32
lvx 28,10,1
addi 10,10,32
lvx 29,11,1
addi 11,11,32
lvx 30,10,1
lvx 31,11,1
.Lcbc_abort:
ld 0, 288(1)
ld 30,256(1)
ld 31,264(1)
mtlr 0
addi 1,1,272
blr
.long 0
.byte 0,12,0x04,1,0x80,2,6,0
.long 0
.size vpaes_cbc_encrypt,.-vpaes_cbc_encrypt
.align 4
_vpaes_key_preheat:
mflr 8
bl .Lconsts
mtlr 8
li 11, 0xc0
li 10, 0xd0
li 9, 0xe0
li 8, 0xf0
vspltisb 8,4
vxor 9,9,9
lvx 10, 12, 11
li 11, 0x120
lvx 11, 12, 10
li 10, 0x130
lvx 12, 12, 9
li 9, 0x220
lvx 13, 12, 8
li 8, 0x230
lvx 14, 12, 11
li 11, 0x240
lvx 15, 12, 10
li 10, 0x250
lvx 16, 12, 9
li 9, 0x260
lvx 17, 12, 8
li 8, 0x270
lvx 18, 12, 11
li 11, 0x280
lvx 19, 12, 10
li 10, 0x290
lvx 20, 12, 9
li 9, 0x2a0
lvx 21, 12, 8
li 8, 0x2b0
lvx 22, 12, 11
lvx 23, 12, 10
lvx 24, 12, 9
lvx 25, 0, 12
lvx 26, 12, 8
blr
.long 0
.byte 0,12,0x14,0,0,0,0,0
.align 4
_vpaes_schedule_core:
mflr 7
bl _vpaes_key_preheat
neg 8, 3
lvx 0, 0, 3
addi 3, 3, 15
lvsl 27, 0, 8
lvx 6, 0, 3
addi 3, 3, 8
vperm 0, 6, 0, 27
vor 3,0,0
bl _vpaes_schedule_transform
vor 7,0,0
bne 1, .Lschedule_am_decrypting
li 8, 0x30
li 9, 4
li 10, 8
li 11, 12
lvsl 29, 0, 5
vnor 30, 9, 9
vperm 30, 30, 9, 29
vperm 28, 0, 0, 29
stvewx 28, 0, 5
stvewx 28, 9, 5
stvewx 28, 10, 5
addi 10, 12, 0x80
stvewx 28, 11, 5
b .Lschedule_go
.Lschedule_am_decrypting:
srwi 8, 4, 1
andi. 8, 8, 32
xori 8, 8, 32
addi 10, 12, 0x80
lvx 1, 8, 10
li 9, 4
li 10, 8
li 11, 12
vperm 4, 3, 3, 1
neg 0, 5
lvsr 29, 0, 0
vnor 30, 9, 9
vperm 30, 9, 30, 29
vperm 28, 4, 4, 29
stvewx 28, 0, 5
stvewx 28, 9, 5
stvewx 28, 10, 5
addi 10, 12, 0x80
stvewx 28, 11, 5
addi 5, 5, 15
xori 8, 8, 0x30
.Lschedule_go:
cmplwi 4, 192
bgt .Lschedule_256
beq .Lschedule_192
.Lschedule_128:
li 0, 10
mtctr 0
.Loop_schedule_128:
bl _vpaes_schedule_round
bdz .Lschedule_mangle_last
bl _vpaes_schedule_mangle
b .Loop_schedule_128
.align 4
.Lschedule_192:
li 0, 4
lvx 0, 0, 3
vperm 0, 0, 6, 27
vsldoi 0, 0, 3, 16-8
bl _vpaes_schedule_transform
vsldoi 6, 9, 0, 16-8
vsldoi 6, 6, 9, 16-8
mtctr 0
.Loop_schedule_192:
bl _vpaes_schedule_round
vsldoi 0, 0, 6, 16-8
bl _vpaes_schedule_mangle
bl _vpaes_schedule_192_smear
bl _vpaes_schedule_mangle
bl _vpaes_schedule_round
bdz .Lschedule_mangle_last
bl _vpaes_schedule_mangle
bl _vpaes_schedule_192_smear
b .Loop_schedule_192
.align 4
.Lschedule_256:
li 0, 7
addi 3, 3, 8
lvx 0, 0, 3
vperm 0, 0, 6, 27
bl _vpaes_schedule_transform
mtctr 0
.Loop_schedule_256:
bl _vpaes_schedule_mangle
vor 6,0,0
bl _vpaes_schedule_round
bdz .Lschedule_mangle_last
bl _vpaes_schedule_mangle
vspltw 0, 0, 3-3
vor 5,7,7
vor 7,6,6
bl _vpaes_schedule_low_round
vor 7,5,5
b .Loop_schedule_256
.align 4
.Lschedule_mangle_last:
li 11, 0x2e0
li 9, 0x2f0
bne 1, .Lschedule_mangle_last_dec
lvx 1, 8, 10
li 11, 0x2c0
li 9, 0x2d0
vperm 0, 0, 0, 1
lvx 12, 11, 12
lvx 13, 9, 12
addi 5, 5, 16
vxor 0, 0, 26
bl _vpaes_schedule_transform
vperm 0, 0, 0, 29
li 10, 4
vsel 2, 28, 0, 30
li 11, 8
stvx 2, 0, 5
li 12, 12
stvewx 0, 0, 5
stvewx 0, 10, 5
stvewx 0, 11, 5
stvewx 0, 12, 5
b .Lschedule_mangle_done
.align 4
.Lschedule_mangle_last_dec:
lvx 12, 11, 12
lvx 13, 9, 12
addi 5, 5, -16
vxor 0, 0, 26
bl _vpaes_schedule_transform
addi 9, 5, -15
vperm 0, 0, 0, 29
li 10, 4
vsel 2, 28, 0, 30
li 11, 8
stvx 2, 0, 5
li 12, 12
stvewx 0, 0, 9
stvewx 0, 10, 9
stvewx 0, 11, 9
stvewx 0, 12, 9
.Lschedule_mangle_done:
mtlr 7
vxor 0, 0, 0
vxor 1, 1, 1
vxor 2, 2, 2
vxor 3, 3, 3
vxor 4, 4, 4
vxor 5, 5, 5
vxor 6, 6, 6
vxor 7, 7, 7
blr
.long 0
.byte 0,12,0x14,0,0,0,0,0
.align 4
_vpaes_schedule_192_smear:
vspltw 0, 7, 3-3
vsldoi 1, 6, 9, 16-12
vsldoi 0, 0, 7, 16-8
vxor 6, 6, 1
vxor 6, 6, 0
vor 0,6,6
vsldoi 6, 9, 6, 16-8
vsldoi 6, 6, 9, 16-8
blr
.long 0
.byte 0,12,0x14,0,0,0,0,0
.align 4
_vpaes_schedule_round:
vsldoi 1, 9, 24, 16-15
vsldoi 24, 24, 24, 16-15
vxor 7, 7, 1
vspltw 0, 0, 3-3
vsldoi 0, 0, 0, 16-1
_vpaes_schedule_low_round:
vsldoi 1, 7, 9, 16-12
vxor 7, 7, 1
vspltisb 1, 0x0f
vsldoi 4, 7, 9, 16-8
vand 1, 1, 0
vsrb 0, 0, 8
vxor 7, 7, 4
vperm 2, 11, 9, 1
vxor 1, 1, 0
vperm 3, 10, 9, 0
vxor 3, 3, 2
vperm 4, 10, 9, 1
vxor 7, 7, 26
vperm 3, 10, 9, 3
vxor 4, 4, 2
vperm 2, 10, 9, 4
vxor 3, 3, 1
vxor 2, 2, 0
vperm 4, 15, 9, 3
vperm 1, 14, 9, 2
vxor 1, 1, 4
vxor 0, 1, 7
vxor 7, 1, 7
blr
.long 0
.byte 0,12,0x14,0,0,0,0,0
.align 4
_vpaes_schedule_transform:
vsrb 2, 0, 8
vperm 0, 12, 12, 0
vperm 2, 13, 13, 2
vxor 0, 0, 2
blr
.long 0
.byte 0,12,0x14,0,0,0,0,0
.align 4
_vpaes_schedule_mangle:
bne 1, .Lschedule_mangle_dec
vxor 4, 0, 26
addi 5, 5, 16
vperm 4, 4, 4, 25
vperm 1, 4, 4, 25
vperm 3, 1, 1, 25
vxor 4, 4, 1
lvx 1, 8, 10
vxor 3, 3, 4
vperm 3, 3, 3, 1
addi 8, 8, -16
andi. 8, 8, 0x30
vperm 1, 3, 3, 29
vsel 2, 28, 1, 30
vor 28,1,1
stvx 2, 0, 5
blr
.align 4
.Lschedule_mangle_dec:
vsrb 1, 0, 8
vperm 2, 16, 16, 0
vperm 3, 17, 17, 1
vxor 3, 3, 2
vperm 3, 3, 9, 25
vperm 2, 18, 18, 0
vxor 2, 2, 3
vperm 3, 19, 19, 1
vxor 3, 3, 2
vperm 3, 3, 9, 25
vperm 2, 20, 20, 0
vxor 2, 2, 3
vperm 3, 21, 21, 1
vxor 3, 3, 2
vperm 2, 22, 22, 0
vperm 3, 3, 9, 25
vperm 4, 23, 23, 1
lvx 1, 8, 10
vxor 2, 2, 3
vxor 3, 4, 2
addi 5, 5, -16
vperm 3, 3, 3, 1
addi 8, 8, -16
andi. 8, 8, 0x30
vperm 1, 3, 3, 29
vsel 2, 28, 1, 30
vor 28,1,1
stvx 2, 0, 5
blr
.long 0
.byte 0,12,0x14,0,0,0,0,0
.globl vpaes_set_encrypt_key
.type vpaes_set_encrypt_key,@function
.align 5
vpaes_set_encrypt_key:
.localentry vpaes_set_encrypt_key,0
stdu 1,-256(1)
li 10,63
li 11,79
mflr 0
li 6,-1
stvx 20,10,1
addi 10,10,32
stvx 21,11,1
addi 11,11,32
stvx 22,10,1
addi 10,10,32
stvx 23,11,1
addi 11,11,32
stvx 24,10,1
addi 10,10,32
stvx 25,11,1
addi 11,11,32
stvx 26,10,1
addi 10,10,32
stvx 27,11,1
addi 11,11,32
stvx 28,10,1
addi 10,10,32
stvx 29,11,1
addi 11,11,32
stvx 30,10,1
stvx 31,11,1
stw 6,252(1)
li 7, -1
std 0, 272(1)
or 7,7,7
srwi 9, 4, 5
addi 9, 9, 6
stw 9, 240(5)
cmplw 1,4,4
li 8, 0x30
bl _vpaes_schedule_core
ld 0, 272(1)
li 10,63
li 11,79
or 6,6,6
mtlr 0
xor 3, 3, 3
lvx 20,10,1
addi 10,10,32
lvx 21,11,1
addi 11,11,32
lvx 22,10,1
addi 10,10,32
lvx 23,11,1
addi 11,11,32
lvx 24,10,1
addi 10,10,32
lvx 25,11,1
addi 11,11,32
lvx 26,10,1
addi 10,10,32
lvx 27,11,1
addi 11,11,32
lvx 28,10,1
addi 10,10,32
lvx 29,11,1
addi 11,11,32
lvx 30,10,1
lvx 31,11,1
addi 1,1,256
blr
.long 0
.byte 0,12,0x04,1,0x80,0,3,0
.long 0
.size vpaes_set_encrypt_key,.-vpaes_set_encrypt_key
.globl vpaes_set_decrypt_key
.type vpaes_set_decrypt_key,@function
.align 4
vpaes_set_decrypt_key:
.localentry vpaes_set_decrypt_key,0
stdu 1,-256(1)
li 10,63
li 11,79
mflr 0
li 6,-1
stvx 20,10,1
addi 10,10,32
stvx 21,11,1
addi 11,11,32
stvx 22,10,1
addi 10,10,32
stvx 23,11,1
addi 11,11,32
stvx 24,10,1
addi 10,10,32
stvx 25,11,1
addi 11,11,32
stvx 26,10,1
addi 10,10,32
stvx 27,11,1
addi 11,11,32
stvx 28,10,1
addi 10,10,32
stvx 29,11,1
addi 11,11,32
stvx 30,10,1
stvx 31,11,1
stw 6,252(1)
li 7, -1
std 0, 272(1)
or 7,7,7
srwi 9, 4, 5
addi 9, 9, 6
stw 9, 240(5)
slwi 9, 9, 4
add 5, 5, 9
cmplwi 1, 4, 0
srwi 8, 4, 1
andi. 8, 8, 32
xori 8, 8, 32
bl _vpaes_schedule_core
ld 0, 272(1)
li 10,63
li 11,79
or 6,6,6
mtlr 0
xor 3, 3, 3
lvx 20,10,1
addi 10,10,32
lvx 21,11,1
addi 11,11,32
lvx 22,10,1
addi 10,10,32
lvx 23,11,1
addi 11,11,32
lvx 24,10,1
addi 10,10,32
lvx 25,11,1
addi 11,11,32
lvx 26,10,1
addi 10,10,32
lvx 27,11,1
addi 11,11,32
lvx 28,10,1
addi 10,10,32
lvx 29,11,1
addi 11,11,32
lvx 30,10,1
lvx 31,11,1
addi 1,1,256
blr
.long 0
.byte 0,12,0x04,1,0x80,0,3,0
.long 0
.size vpaes_set_decrypt_key,.-vpaes_set_decrypt_key
|