3 # ====================================================================
4 # Written by David S. Miller <davem@devemloft.net> and Andy Polyakov
5 # <appro@openssl.org>. The module is licensed under 2-clause BSD
6 # license. October 2012. All rights reserved.
7 # ====================================================================
9 ######################################################################
12 # AES round instructions complete in 3 cycles and can be issued every
13 # cycle. It means that round calculations should take 4*rounds cycles,
14 # because any given round instruction depends on result of *both*
15 # previous instructions:
23 # Provided that fxor [with IV] takes 3 cycles to complete, critical
24 # path length for CBC encrypt would be 3+4*rounds, or in other words
25 # it should process one byte in at least (3+4*rounds)/16 cycles. This
26 # estimate doesn't account for "collateral" instructions, such as
27 # fetching input from memory, xor-ing it with zero-round key and
28 # storing the result. Yet, *measured* performance [for data aligned
29 # at 64-bit boundary!] deviates from this equation by less than 0.5%:
31 # 128-bit key 192- 256-
32 # CBC encrypt 2.70/2.90(*) 3.20/3.40 3.70/3.90
33 # (*) numbers after slash are for
36 # Out-of-order execution logic managed to fully overlap "collateral"
37 # instructions with those on critical path. Amazing!
39 # As with Intel AES-NI, question is if it's possible to improve
40 # performance of parallelizeable modes by interleaving round
41 # instructions. Provided round instruction latency and throughput
42 # optimal interleave factor is 2. But can we expect 2x performance
43 # improvement? Well, as round instructions can be issued one per
44 # cycle, they don't saturate the 2-way issue pipeline and therefore
45 # there is room for "collateral" calculations... Yet, 2x speed-up
46 # over CBC encrypt remains unattaintable:
48 # 128-bit key 192- 256-
49 # CBC decrypt 1.64/2.11 1.89/2.37 2.23/2.61
50 # CTR 1.64/2.08(*) 1.89/2.33 2.23/2.61
51 # (*) numbers after slash are for
54 # Estimates based on amount of instructions under assumption that
55 # round instructions are not pairable with any other instruction
56 # suggest that latter is the actual case and pipeline runs
57 # underutilized. It should be noted that T4 out-of-order execution
58 # logic is so capable that performance gain from 2x interleave is
59 # not even impressive, ~7-13% over non-interleaved code, largest
62 # To anchor to something else, software implementation processes
63 # one byte in 29 cycles with 128-bit key on same processor. Intel
64 # Sandy Bridge encrypts byte in 5.07 cycles in CBC mode and decrypts
65 # in 0.93, naturally with AES-NI.
67 $0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
68 push(@INC,"${dir}","${dir}../../perlasm");
69 require "sparcv9_modes.pl";
72 for (@ARGV) { $bits=64 if (/\-m64/ || /\-xarch\=v9/); }
73 if ($bits==64) { $::bias=2047; $::frame=192; }
74 else { $::bias=0; $::frame=112; }
76 $::evp=1; # if $evp is set to 0, script generates module with
77 # AES_[en|de]crypt, AES_set_[en|de]crypt_key and AES_cbc_encrypt entry
78 # points. These however are not fully compatible with openssl/aes.h,
79 # because they expect AES_KEY to be aligned at 64-bit boundary. When
80 # used through EVP, alignment is arranged at EVP layer. Second thing
81 # that is arranged by EVP is at least 32-bit alignment of IV.
83 ######################################################################
84 # single-round subroutines
87 my ($inp,$out,$key,$rounds,$tmp,$mask)=map("%o$_",(0..5));
95 andcc $inp, 7, %g1 ! is input aligned?
104 ldx [$inp + 16], $inp
114 ld [$key + 240], $rounds
115 ldd [$key + 16], %f12
116 ldd [$key + 24], %f14
121 srl $rounds, 1, $rounds
122 ldd [$key + 32], %f16
123 sub $rounds, 1, $rounds
124 ldd [$key + 40], %f18
128 aes_eround01 %f12, %f0, %f2, %f4
129 aes_eround23 %f14, %f0, %f2, %f2
132 sub $rounds,1,$rounds
133 aes_eround01 %f16, %f4, %f2, %f0
134 aes_eround23 %f18, %f4, %f2, %f2
135 ldd [$key + 16], %f16
136 ldd [$key + 24], %f18
137 brnz,pt $rounds, .Lenc
140 andcc $out, 7, $tmp ! is output aligned?
141 aes_eround01 %f12, %f0, %f2, %f4
142 aes_eround23 %f14, %f0, %f2, %f2
143 aes_eround01_l %f16, %f4, %f2, %f0
144 aes_eround23_l %f18, %f4, %f2, %f2
153 2: alignaddrl $out, %g0, $out
155 srl $mask, $tmp, $mask
157 faligndata %f0, %f0, %f4
158 faligndata %f0, %f2, %f6
159 faligndata %f2, %f2, %f8
161 stda %f4, [$out + $mask]0xc0 ! partial store
164 orn %g0, $mask, $mask
166 stda %f8, [$out + $mask]0xc0 ! partial store
167 .type aes_t4_encrypt,#function
168 .size aes_t4_encrypt,.-aes_t4_encrypt
170 .globl aes_t4_decrypt
173 andcc $inp, 7, %g1 ! is input aligned?
182 ldx [$inp + 16], $inp
192 ld [$key + 240], $rounds
193 ldd [$key + 16], %f12
194 ldd [$key + 24], %f14
199 srl $rounds, 1, $rounds
200 ldd [$key + 32], %f16
201 sub $rounds, 1, $rounds
202 ldd [$key + 40], %f18
206 aes_dround01 %f12, %f0, %f2, %f4
207 aes_dround23 %f14, %f0, %f2, %f2
210 sub $rounds,1,$rounds
211 aes_dround01 %f16, %f4, %f2, %f0
212 aes_dround23 %f18, %f4, %f2, %f2
213 ldd [$key + 16], %f16
214 ldd [$key + 24], %f18
215 brnz,pt $rounds, .Ldec
218 andcc $out, 7, $tmp ! is output aligned?
219 aes_dround01 %f12, %f0, %f2, %f4
220 aes_dround23 %f14, %f0, %f2, %f2
221 aes_dround01_l %f16, %f4, %f2, %f0
222 aes_dround23_l %f18, %f4, %f2, %f2
231 2: alignaddrl $out, %g0, $out
233 srl $mask, $tmp, $mask
235 faligndata %f0, %f0, %f4
236 faligndata %f0, %f2, %f6
237 faligndata %f2, %f2, %f8
239 stda %f4, [$out + $mask]0xc0 ! partial store
242 orn %g0, $mask, $mask
244 stda %f8, [$out + $mask]0xc0 ! partial store
245 .type aes_t4_decrypt,#function
246 .size aes_t4_decrypt,.-aes_t4_decrypt
250 ######################################################################
251 # key setup subroutines
254 my ($inp,$bits,$out,$tmp)=map("%o$_",(0..5));
256 .globl aes_t4_set_encrypt_key
258 aes_t4_set_encrypt_key:
261 alignaddr $inp, %g0, $inp
269 brz,pt $tmp, .L256aligned
273 faligndata %f0, %f2, %f0
274 faligndata %f2, %f4, %f2
275 faligndata %f4, %f6, %f4
276 faligndata %f6, %f8, %f6
279 for ($i=0; $i<6; $i++) {
281 std %f0, [$out + `32*$i+0`]
282 aes_kexpand1 %f0, %f6, $i, %f0
283 std %f2, [$out + `32*$i+8`]
284 aes_kexpand2 %f2, %f0, %f2
285 std %f4, [$out + `32*$i+16`]
286 aes_kexpand0 %f4, %f2, %f4
287 std %f6, [$out + `32*$i+24`]
288 aes_kexpand2 %f6, %f4, %f6
292 std %f0, [$out + `32*$i+0`]
293 aes_kexpand1 %f0, %f6, $i, %f0
294 std %f2, [$out + `32*$i+8`]
295 aes_kexpand2 %f2, %f0, %f2
296 std %f4, [$out + `32*$i+16`]
297 std %f6, [$out + `32*$i+24`]
298 std %f0, [$out + `32*$i+32`]
299 std %f2, [$out + `32*$i+40`]
302 st $tmp, [$out + 240]
308 brz,pt $tmp, .L192aligned
312 faligndata %f0, %f2, %f0
313 faligndata %f2, %f4, %f2
314 faligndata %f4, %f6, %f4
317 for ($i=0; $i<7; $i++) {
319 std %f0, [$out + `24*$i+0`]
320 aes_kexpand1 %f0, %f4, $i, %f0
321 std %f2, [$out + `24*$i+8`]
322 aes_kexpand2 %f2, %f0, %f2
323 std %f4, [$out + `24*$i+16`]
324 aes_kexpand2 %f4, %f2, %f4
328 std %f0, [$out + `24*$i+0`]
329 aes_kexpand1 %f0, %f4, $i, %f0
330 std %f2, [$out + `24*$i+8`]
331 aes_kexpand2 %f2, %f0, %f2
332 std %f4, [$out + `24*$i+16`]
333 std %f0, [$out + `24*$i+24`]
334 std %f2, [$out + `24*$i+32`]
337 st $tmp, [$out + 240]
343 brz,pt $tmp, .L128aligned
347 faligndata %f0, %f2, %f0
348 faligndata %f2, %f4, %f2
351 for ($i=0; $i<10; $i++) {
353 std %f0, [$out + `16*$i+0`]
354 aes_kexpand1 %f0, %f2, $i, %f0
355 std %f2, [$out + `16*$i+8`]
356 aes_kexpand2 %f2, %f0, %f2
360 std %f0, [$out + `16*$i+0`]
361 std %f2, [$out + `16*$i+8`]
364 st $tmp, [$out + 240]
367 .type aes_t4_set_encrypt_key,#function
368 .size aes_t4_set_encrypt_key,.-aes_t4_set_encrypt_key
370 .globl aes_t4_set_decrypt_key
372 aes_t4_set_decrypt_key:
374 call .Lset_encrypt_key
378 sll $tmp, 4, $inp ! $tmp is number of rounds
380 add $out, $inp, $inp ! $inp=$out+16*rounds
381 srl $tmp, 2, $tmp ! $tmp=(rounds+2)/4
390 ldd [$inp - 16], %f12
399 std %f12, [$out + 16]
400 std %f14, [$out + 24]
402 brnz $tmp, .Lkey_flip
407 .type aes_t4_set_decrypt_key,#function
408 .size aes_t4_set_decrypt_key,.-aes_t4_set_decrypt_key
413 my ($inp,$out,$len,$key,$ivec,$enc)=map("%i$_",(0..5));
414 my ($ileft,$iright,$ooff,$omask,$ivoff)=map("%l$_",(1..7));
422 for ($i=2; $i<22;$i++) { # load key schedule
424 ldd [$key + `8*$i`], %f`12+2*$i`
430 .type _aes128_loadkey,#function
431 .size _aes128_loadkey,.-_aes128_loadkey
432 _aes128_load_enckey=_aes128_loadkey
433 _aes128_load_deckey=_aes128_loadkey
438 for ($i=0; $i<4; $i++) {
440 aes_eround01 %f`16+8*$i+0`, %f0, %f2, %f4
441 aes_eround23 %f`16+8*$i+2`, %f0, %f2, %f2
442 aes_eround01 %f`16+8*$i+4`, %f4, %f2, %f0
443 aes_eround23 %f`16+8*$i+6`, %f4, %f2, %f2
447 aes_eround01 %f48, %f0, %f2, %f4
448 aes_eround23 %f50, %f0, %f2, %f2
449 aes_eround01_l %f52, %f4, %f2, %f0
451 aes_eround23_l %f54, %f4, %f2, %f2
452 .type _aes128_encrypt_1x,#function
453 .size _aes128_encrypt_1x,.-_aes128_encrypt_1x
458 for ($i=0; $i<4; $i++) {
460 aes_eround01 %f`16+8*$i+0`, %f0, %f2, %f8
461 aes_eround23 %f`16+8*$i+2`, %f0, %f2, %f2
462 aes_eround01 %f`16+8*$i+0`, %f4, %f6, %f10
463 aes_eround23 %f`16+8*$i+2`, %f4, %f6, %f6
464 aes_eround01 %f`16+8*$i+4`, %f8, %f2, %f0
465 aes_eround23 %f`16+8*$i+6`, %f8, %f2, %f2
466 aes_eround01 %f`16+8*$i+4`, %f10, %f6, %f4
467 aes_eround23 %f`16+8*$i+6`, %f10, %f6, %f6
471 aes_eround01 %f48, %f0, %f2, %f8
472 aes_eround23 %f50, %f0, %f2, %f2
473 aes_eround01 %f48, %f4, %f6, %f10
474 aes_eround23 %f50, %f4, %f6, %f6
475 aes_eround01_l %f52, %f8, %f2, %f0
476 aes_eround23_l %f54, %f8, %f2, %f2
477 aes_eround01_l %f52, %f10, %f6, %f4
479 aes_eround23_l %f54, %f10, %f6, %f6
480 .type _aes128_encrypt_2x,#function
481 .size _aes128_encrypt_2x,.-_aes128_encrypt_2x
486 for ($i=0; $i<4; $i++) {
488 aes_dround01 %f`16+8*$i+0`, %f0, %f2, %f4
489 aes_dround23 %f`16+8*$i+2`, %f0, %f2, %f2
490 aes_dround01 %f`16+8*$i+4`, %f4, %f2, %f0
491 aes_dround23 %f`16+8*$i+6`, %f4, %f2, %f2
495 aes_dround01 %f48, %f0, %f2, %f4
496 aes_dround23 %f50, %f0, %f2, %f2
497 aes_dround01_l %f52, %f4, %f2, %f0
499 aes_dround23_l %f54, %f4, %f2, %f2
500 .type _aes128_decrypt_1x,#function
501 .size _aes128_decrypt_1x,.-_aes128_decrypt_1x
506 for ($i=0; $i<4; $i++) {
508 aes_dround01 %f`16+8*$i+0`, %f0, %f2, %f8
509 aes_dround23 %f`16+8*$i+2`, %f0, %f2, %f2
510 aes_dround01 %f`16+8*$i+0`, %f4, %f6, %f10
511 aes_dround23 %f`16+8*$i+2`, %f4, %f6, %f6
512 aes_dround01 %f`16+8*$i+4`, %f8, %f2, %f0
513 aes_dround23 %f`16+8*$i+6`, %f8, %f2, %f2
514 aes_dround01 %f`16+8*$i+4`, %f10, %f6, %f4
515 aes_dround23 %f`16+8*$i+6`, %f10, %f6, %f6
519 aes_dround01 %f48, %f0, %f2, %f8
520 aes_dround23 %f50, %f0, %f2, %f2
521 aes_dround01 %f48, %f4, %f6, %f10
522 aes_dround23 %f50, %f4, %f6, %f6
523 aes_dround01_l %f52, %f8, %f2, %f0
524 aes_dround23_l %f54, %f8, %f2, %f2
525 aes_dround01_l %f52, %f10, %f6, %f4
527 aes_dround23_l %f54, %f10, %f6, %f6
528 .type _aes128_decrypt_2x,#function
529 .size _aes128_decrypt_2x,.-_aes128_decrypt_2x
537 for ($i=2; $i<26;$i++) { # load key schedule
539 ldd [$key + `8*$i`], %f`12+2*$i`
545 .type _aes192_loadkey,#function
546 .size _aes192_loadkey,.-_aes192_loadkey
547 _aes192_load_enckey=_aes192_loadkey
548 _aes192_load_deckey=_aes192_loadkey
549 _aes256_load_enckey=_aes192_loadkey
550 _aes256_load_deckey=_aes192_loadkey
555 for ($i=0; $i<5; $i++) {
557 aes_eround01 %f`16+8*$i+0`, %f0, %f2, %f4
558 aes_eround23 %f`16+8*$i+2`, %f0, %f2, %f2
559 aes_eround01 %f`16+8*$i+4`, %f4, %f2, %f0
560 aes_eround23 %f`16+8*$i+6`, %f4, %f2, %f2
564 aes_eround01 %f56, %f0, %f2, %f4
565 aes_eround23 %f58, %f0, %f2, %f2
566 aes_eround01_l %f60, %f4, %f2, %f0
568 aes_eround23_l %f62, %f4, %f2, %f2
569 .type _aes192_encrypt_1x,#function
570 .size _aes192_encrypt_1x,.-_aes192_encrypt_1x
575 for ($i=0; $i<5; $i++) {
577 aes_eround01 %f`16+8*$i+0`, %f0, %f2, %f8
578 aes_eround23 %f`16+8*$i+2`, %f0, %f2, %f2
579 aes_eround01 %f`16+8*$i+0`, %f4, %f6, %f10
580 aes_eround23 %f`16+8*$i+2`, %f4, %f6, %f6
581 aes_eround01 %f`16+8*$i+4`, %f8, %f2, %f0
582 aes_eround23 %f`16+8*$i+6`, %f8, %f2, %f2
583 aes_eround01 %f`16+8*$i+4`, %f10, %f6, %f4
584 aes_eround23 %f`16+8*$i+6`, %f10, %f6, %f6
588 aes_eround01 %f56, %f0, %f2, %f8
589 aes_eround23 %f58, %f0, %f2, %f2
590 aes_eround01 %f56, %f4, %f6, %f10
591 aes_eround23 %f58, %f4, %f6, %f6
592 aes_eround01_l %f60, %f8, %f2, %f0
593 aes_eround23_l %f62, %f8, %f2, %f2
594 aes_eround01_l %f60, %f10, %f6, %f4
596 aes_eround23_l %f62, %f10, %f6, %f6
597 .type _aes192_encrypt_2x,#function
598 .size _aes192_encrypt_2x,.-_aes192_encrypt_2x
603 for ($i=0; $i<5; $i++) {
605 aes_dround01 %f`16+8*$i+0`, %f0, %f2, %f4
606 aes_dround23 %f`16+8*$i+2`, %f0, %f2, %f2
607 aes_dround01 %f`16+8*$i+4`, %f4, %f2, %f0
608 aes_dround23 %f`16+8*$i+6`, %f4, %f2, %f2
612 aes_dround01 %f56, %f0, %f2, %f4
613 aes_dround23 %f58, %f0, %f2, %f2
614 aes_dround01_l %f60, %f4, %f2, %f0
616 aes_dround23_l %f62, %f4, %f2, %f2
617 .type _aes192_decrypt_1x,#function
618 .size _aes192_decrypt_1x,.-_aes192_decrypt_1x
623 for ($i=0; $i<5; $i++) {
625 aes_dround01 %f`16+8*$i+0`, %f0, %f2, %f8
626 aes_dround23 %f`16+8*$i+2`, %f0, %f2, %f2
627 aes_dround01 %f`16+8*$i+0`, %f4, %f6, %f10
628 aes_dround23 %f`16+8*$i+2`, %f4, %f6, %f6
629 aes_dround01 %f`16+8*$i+4`, %f8, %f2, %f0
630 aes_dround23 %f`16+8*$i+6`, %f8, %f2, %f2
631 aes_dround01 %f`16+8*$i+4`, %f10, %f6, %f4
632 aes_dround23 %f`16+8*$i+6`, %f10, %f6, %f6
636 aes_dround01 %f56, %f0, %f2, %f8
637 aes_dround23 %f58, %f0, %f2, %f2
638 aes_dround01 %f56, %f4, %f6, %f10
639 aes_dround23 %f58, %f4, %f6, %f6
640 aes_dround01_l %f60, %f8, %f2, %f0
641 aes_dround23_l %f62, %f8, %f2, %f2
642 aes_dround01_l %f60, %f10, %f6, %f4
644 aes_dround23_l %f62, %f10, %f6, %f6
645 .type _aes192_decrypt_2x,#function
646 .size _aes192_decrypt_2x,.-_aes192_decrypt_2x
650 aes_eround01 %f16, %f0, %f2, %f4
651 aes_eround23 %f18, %f0, %f2, %f2
652 ldd [$key + 208], %f16
653 ldd [$key + 216], %f18
654 aes_eround01 %f20, %f4, %f2, %f0
655 aes_eround23 %f22, %f4, %f2, %f2
656 ldd [$key + 224], %f20
657 ldd [$key + 232], %f22
659 for ($i=1; $i<6; $i++) {
661 aes_eround01 %f`16+8*$i+0`, %f0, %f2, %f4
662 aes_eround23 %f`16+8*$i+2`, %f0, %f2, %f2
663 aes_eround01 %f`16+8*$i+4`, %f4, %f2, %f0
664 aes_eround23 %f`16+8*$i+6`, %f4, %f2, %f2
668 aes_eround01 %f16, %f0, %f2, %f4
669 aes_eround23 %f18, %f0, %f2, %f2
670 ldd [$key + 16], %f16
671 ldd [$key + 24], %f18
672 aes_eround01_l %f20, %f4, %f2, %f0
673 aes_eround23_l %f22, %f4, %f2, %f2
674 ldd [$key + 32], %f20
676 ldd [$key + 40], %f22
677 .type _aes256_encrypt_1x,#function
678 .size _aes256_encrypt_1x,.-_aes256_encrypt_1x
682 aes_eround01 %f16, %f0, %f2, %f8
683 aes_eround23 %f18, %f0, %f2, %f2
684 aes_eround01 %f16, %f4, %f6, %f10
685 aes_eround23 %f18, %f4, %f6, %f6
686 ldd [$key + 208], %f16
687 ldd [$key + 216], %f18
688 aes_eround01 %f20, %f8, %f2, %f0
689 aes_eround23 %f22, %f8, %f2, %f2
690 aes_eround01 %f20, %f10, %f6, %f4
691 aes_eround23 %f22, %f10, %f6, %f6
692 ldd [$key + 224], %f20
693 ldd [$key + 232], %f22
695 for ($i=1; $i<6; $i++) {
697 aes_eround01 %f`16+8*$i+0`, %f0, %f2, %f8
698 aes_eround23 %f`16+8*$i+2`, %f0, %f2, %f2
699 aes_eround01 %f`16+8*$i+0`, %f4, %f6, %f10
700 aes_eround23 %f`16+8*$i+2`, %f4, %f6, %f6
701 aes_eround01 %f`16+8*$i+4`, %f8, %f2, %f0
702 aes_eround23 %f`16+8*$i+6`, %f8, %f2, %f2
703 aes_eround01 %f`16+8*$i+4`, %f10, %f6, %f4
704 aes_eround23 %f`16+8*$i+6`, %f10, %f6, %f6
708 aes_eround01 %f16, %f0, %f2, %f8
709 aes_eround23 %f18, %f0, %f2, %f2
710 aes_eround01 %f16, %f4, %f6, %f10
711 aes_eround23 %f18, %f4, %f6, %f6
712 ldd [$key + 16], %f16
713 ldd [$key + 24], %f18
714 aes_eround01_l %f20, %f8, %f2, %f0
715 aes_eround23_l %f22, %f8, %f2, %f2
716 aes_eround01_l %f20, %f10, %f6, %f4
717 aes_eround23_l %f22, %f10, %f6, %f6
718 ldd [$key + 32], %f20
720 ldd [$key + 40], %f22
721 .type _aes256_encrypt_2x,#function
722 .size _aes256_encrypt_2x,.-_aes256_encrypt_2x
726 aes_dround01 %f16, %f0, %f2, %f4
727 aes_dround23 %f18, %f0, %f2, %f2
728 ldd [$key + 208], %f16
729 ldd [$key + 216], %f18
730 aes_dround01 %f20, %f4, %f2, %f0
731 aes_dround23 %f22, %f4, %f2, %f2
732 ldd [$key + 224], %f20
733 ldd [$key + 232], %f22
735 for ($i=1; $i<6; $i++) {
737 aes_dround01 %f`16+8*$i+0`, %f0, %f2, %f4
738 aes_dround23 %f`16+8*$i+2`, %f0, %f2, %f2
739 aes_dround01 %f`16+8*$i+4`, %f4, %f2, %f0
740 aes_dround23 %f`16+8*$i+6`, %f4, %f2, %f2
744 aes_dround01 %f16, %f0, %f2, %f4
745 aes_dround23 %f18, %f0, %f2, %f2
746 ldd [$key + 16], %f16
747 ldd [$key + 24], %f18
748 aes_dround01_l %f20, %f4, %f2, %f0
749 aes_dround23_l %f22, %f4, %f2, %f2
750 ldd [$key + 32], %f20
752 ldd [$key + 40], %f22
753 .type _aes256_decrypt_1x,#function
754 .size _aes256_decrypt_1x,.-_aes256_decrypt_1x
758 aes_dround01 %f16, %f0, %f2, %f8
759 aes_dround23 %f18, %f0, %f2, %f2
760 aes_dround01 %f16, %f4, %f6, %f10
761 aes_dround23 %f18, %f4, %f6, %f6
762 ldd [$key + 208], %f16
763 ldd [$key + 216], %f18
764 aes_dround01 %f20, %f8, %f2, %f0
765 aes_dround23 %f22, %f8, %f2, %f2
766 aes_dround01 %f20, %f10, %f6, %f4
767 aes_dround23 %f22, %f10, %f6, %f6
768 ldd [$key + 224], %f20
769 ldd [$key + 232], %f22
771 for ($i=1; $i<6; $i++) {
773 aes_dround01 %f`16+8*$i+0`, %f0, %f2, %f8
774 aes_dround23 %f`16+8*$i+2`, %f0, %f2, %f2
775 aes_dround01 %f`16+8*$i+0`, %f4, %f6, %f10
776 aes_dround23 %f`16+8*$i+2`, %f4, %f6, %f6
777 aes_dround01 %f`16+8*$i+4`, %f8, %f2, %f0
778 aes_dround23 %f`16+8*$i+6`, %f8, %f2, %f2
779 aes_dround01 %f`16+8*$i+4`, %f10, %f6, %f4
780 aes_dround23 %f`16+8*$i+6`, %f10, %f6, %f6
784 aes_dround01 %f16, %f0, %f2, %f8
785 aes_dround23 %f18, %f0, %f2, %f2
786 aes_dround01 %f16, %f4, %f6, %f10
787 aes_dround23 %f18, %f4, %f6, %f6
788 ldd [$key + 16], %f16
789 ldd [$key + 24], %f18
790 aes_dround01_l %f20, %f8, %f2, %f0
791 aes_dround23_l %f22, %f8, %f2, %f2
792 aes_dround01_l %f20, %f10, %f6, %f4
793 aes_dround23_l %f22, %f10, %f6, %f6
794 ldd [$key + 32], %f20
796 ldd [$key + 40], %f22
797 .type _aes256_decrypt_2x,#function
798 .size _aes256_decrypt_2x,.-_aes256_decrypt_2x
801 &alg_cbc_encrypt_implement("aes",128);
802 &alg_cbc_encrypt_implement("aes",192);
803 &alg_cbc_encrypt_implement("aes",256);
805 &alg_cbc_decrypt_implement("aes",128);
806 &alg_cbc_decrypt_implement("aes",192);
807 &alg_cbc_decrypt_implement("aes",256);
810 &alg_ctr32_implement("aes",128);
811 &alg_ctr32_implement("aes",192);
812 &alg_ctr32_implement("aes",256);
819 AES_encrypt=aes_t4_encrypt
821 AES_decrypt=aes_t4_decrypt
822 .global AES_set_encrypt_key
825 andcc %o2, 7, %g0 ! check alignment
832 andncc %o1, 0x1c0, %g0
838 b aes_t4_set_encrypt_key
842 .type AES_set_encrypt_key,#function
843 .size AES_set_encrypt_key,.-AES_set_encrypt_key
845 .global AES_set_decrypt_key
848 andcc %o2, 7, %g0 ! check alignment
855 andncc %o1, 0x1c0, %g0
861 b aes_t4_set_decrypt_key
865 .type AES_set_decrypt_key,#function
866 .size AES_set_decrypt_key,.-AES_set_decrypt_key
869 my ($inp,$out,$len,$key,$ivec,$enc)=map("%o$_",(0..5));
872 .globl AES_cbc_encrypt
877 brz $enc, .Lcbc_decrypt
880 bl,pt %icc, aes128_t4_cbc_encrypt
882 be,pn %icc, aes192_t4_cbc_encrypt
884 ba aes256_t4_cbc_encrypt
888 bl,pt %icc, aes128_t4_cbc_decrypt
890 be,pn %icc, aes192_t4_cbc_decrypt
892 ba aes256_t4_cbc_decrypt
894 .type AES_cbc_encrypt,#function
895 .size AES_cbc_encrypt,.-AES_cbc_encrypt
899 .asciz "AES for SPARC T4, David S. Miller, Andy Polyakov"