11cb0ef41Sopenharmony_ci#! /usr/bin/env perl
21cb0ef41Sopenharmony_ci# Copyright 2012-2021 The OpenSSL Project Authors. All Rights Reserved.
31cb0ef41Sopenharmony_ci#
41cb0ef41Sopenharmony_ci# Licensed under the Apache License 2.0 (the "License").  You may not use
51cb0ef41Sopenharmony_ci# this file except in compliance with the License.  You can obtain a copy
61cb0ef41Sopenharmony_ci# in the file LICENSE in the source distribution or at
71cb0ef41Sopenharmony_ci# https://www.openssl.org/source/license.html
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ci# ====================================================================
111cb0ef41Sopenharmony_ci# Written by David S. Miller and Andy Polyakov.
121cb0ef41Sopenharmony_ci# The module is licensed under 2-clause BSD license. October 2012.
131cb0ef41Sopenharmony_ci# All rights reserved.
141cb0ef41Sopenharmony_ci# ====================================================================
151cb0ef41Sopenharmony_ci
161cb0ef41Sopenharmony_ci######################################################################
171cb0ef41Sopenharmony_ci# AES for SPARC T4.
181cb0ef41Sopenharmony_ci#
191cb0ef41Sopenharmony_ci# AES round instructions complete in 3 cycles and can be issued every
201cb0ef41Sopenharmony_ci# cycle. It means that round calculations should take 4*rounds cycles,
211cb0ef41Sopenharmony_ci# because any given round instruction depends on result of *both*
221cb0ef41Sopenharmony_ci# previous instructions:
231cb0ef41Sopenharmony_ci#
241cb0ef41Sopenharmony_ci#	|0 |1 |2 |3 |4
251cb0ef41Sopenharmony_ci#	|01|01|01|
261cb0ef41Sopenharmony_ci#	   |23|23|23|
271cb0ef41Sopenharmony_ci#	            |01|01|...
281cb0ef41Sopenharmony_ci#	               |23|...
291cb0ef41Sopenharmony_ci#
301cb0ef41Sopenharmony_ci# Provided that fxor [with IV] takes 3 cycles to complete, critical
311cb0ef41Sopenharmony_ci# path length for CBC encrypt would be 3+4*rounds, or in other words
321cb0ef41Sopenharmony_ci# it should process one byte in at least (3+4*rounds)/16 cycles. This
331cb0ef41Sopenharmony_ci# estimate doesn't account for "collateral" instructions, such as
341cb0ef41Sopenharmony_ci# fetching input from memory, xor-ing it with zero-round key and
351cb0ef41Sopenharmony_ci# storing the result. Yet, *measured* performance [for data aligned
361cb0ef41Sopenharmony_ci# at 64-bit boundary!] deviates from this equation by less than 0.5%:
371cb0ef41Sopenharmony_ci#
381cb0ef41Sopenharmony_ci#		128-bit key	192-		256-
391cb0ef41Sopenharmony_ci# CBC encrypt	2.70/2.90(*)	3.20/3.40	3.70/3.90
401cb0ef41Sopenharmony_ci#			 (*) numbers after slash are for
411cb0ef41Sopenharmony_ci#			     misaligned data.
421cb0ef41Sopenharmony_ci#
431cb0ef41Sopenharmony_ci# Out-of-order execution logic managed to fully overlap "collateral"
441cb0ef41Sopenharmony_ci# instructions with those on critical path. Amazing!
451cb0ef41Sopenharmony_ci#
461cb0ef41Sopenharmony_ci# As with Intel AES-NI, question is if it's possible to improve
471cb0ef41Sopenharmony_ci# performance of parallelizable modes by interleaving round
481cb0ef41Sopenharmony_ci# instructions. Provided round instruction latency and throughput
491cb0ef41Sopenharmony_ci# optimal interleave factor is 2. But can we expect 2x performance
501cb0ef41Sopenharmony_ci# improvement? Well, as round instructions can be issued one per
511cb0ef41Sopenharmony_ci# cycle, they don't saturate the 2-way issue pipeline and therefore
521cb0ef41Sopenharmony_ci# there is room for "collateral" calculations... Yet, 2x speed-up
531cb0ef41Sopenharmony_ci# over CBC encrypt remains unattaintable:
541cb0ef41Sopenharmony_ci#
551cb0ef41Sopenharmony_ci#		128-bit key	192-		256-
561cb0ef41Sopenharmony_ci# CBC decrypt	1.64/2.11	1.89/2.37	2.23/2.61
571cb0ef41Sopenharmony_ci# CTR		1.64/2.08(*)	1.89/2.33	2.23/2.61
581cb0ef41Sopenharmony_ci#			 (*) numbers after slash are for
591cb0ef41Sopenharmony_ci#			     misaligned data.
601cb0ef41Sopenharmony_ci#
611cb0ef41Sopenharmony_ci# Estimates based on amount of instructions under assumption that
621cb0ef41Sopenharmony_ci# round instructions are not pairable with any other instruction
631cb0ef41Sopenharmony_ci# suggest that latter is the actual case and pipeline runs
641cb0ef41Sopenharmony_ci# underutilized. It should be noted that T4 out-of-order execution
651cb0ef41Sopenharmony_ci# logic is so capable that performance gain from 2x interleave is
661cb0ef41Sopenharmony_ci# not even impressive, ~7-13% over non-interleaved code, largest
671cb0ef41Sopenharmony_ci# for 256-bit keys.
681cb0ef41Sopenharmony_ci
691cb0ef41Sopenharmony_ci# To anchor to something else, software implementation processes
701cb0ef41Sopenharmony_ci# one byte in 29 cycles with 128-bit key on same processor. Intel
711cb0ef41Sopenharmony_ci# Sandy Bridge encrypts byte in 5.07 cycles in CBC mode and decrypts
721cb0ef41Sopenharmony_ci# in 0.93, naturally with AES-NI.
731cb0ef41Sopenharmony_ci
741cb0ef41Sopenharmony_ci$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
751cb0ef41Sopenharmony_cipush(@INC,"${dir}","${dir}../../perlasm");
761cb0ef41Sopenharmony_cirequire "sparcv9_modes.pl";
771cb0ef41Sopenharmony_ci
781cb0ef41Sopenharmony_ci$output = pop and open STDOUT,">$output";
791cb0ef41Sopenharmony_ci
801cb0ef41Sopenharmony_ci$::evp=1;	# if $evp is set to 0, script generates module with
811cb0ef41Sopenharmony_ci# AES_[en|de]crypt, AES_set_[en|de]crypt_key and AES_cbc_encrypt entry
821cb0ef41Sopenharmony_ci# points. These however are not fully compatible with openssl/aes.h,
831cb0ef41Sopenharmony_ci# because they expect AES_KEY to be aligned at 64-bit boundary. When
841cb0ef41Sopenharmony_ci# used through EVP, alignment is arranged at EVP layer. Second thing
851cb0ef41Sopenharmony_ci# that is arranged by EVP is at least 32-bit alignment of IV.
861cb0ef41Sopenharmony_ci
871cb0ef41Sopenharmony_ci######################################################################
881cb0ef41Sopenharmony_ci# single-round subroutines
891cb0ef41Sopenharmony_ci#
901cb0ef41Sopenharmony_ci{
911cb0ef41Sopenharmony_cimy ($inp,$out,$key,$rounds,$tmp,$mask)=map("%o$_",(0..5));
921cb0ef41Sopenharmony_ci
931cb0ef41Sopenharmony_ci$code.=<<___;
941cb0ef41Sopenharmony_ci#ifndef __ASSEMBLER__
951cb0ef41Sopenharmony_ci# define __ASSEMBLER__ 1
961cb0ef41Sopenharmony_ci#endif
971cb0ef41Sopenharmony_ci#include "crypto/sparc_arch.h"
981cb0ef41Sopenharmony_ci
991cb0ef41Sopenharmony_ci#ifdef	__arch64__
1001cb0ef41Sopenharmony_ci.register	%g2,#scratch
1011cb0ef41Sopenharmony_ci.register	%g3,#scratch
1021cb0ef41Sopenharmony_ci#endif
1031cb0ef41Sopenharmony_ci
1041cb0ef41Sopenharmony_ci.text
1051cb0ef41Sopenharmony_ci
1061cb0ef41Sopenharmony_ci.globl	aes_t4_encrypt
1071cb0ef41Sopenharmony_ci.align	32
1081cb0ef41Sopenharmony_ciaes_t4_encrypt:
1091cb0ef41Sopenharmony_ci	andcc		$inp, 7, %g1		! is input aligned?
1101cb0ef41Sopenharmony_ci	andn		$inp, 7, $inp
1111cb0ef41Sopenharmony_ci
1121cb0ef41Sopenharmony_ci	ldx		[$key + 0], %g4
1131cb0ef41Sopenharmony_ci	ldx		[$key + 8], %g5
1141cb0ef41Sopenharmony_ci
1151cb0ef41Sopenharmony_ci	ldx		[$inp + 0], %o4
1161cb0ef41Sopenharmony_ci	bz,pt		%icc, 1f
1171cb0ef41Sopenharmony_ci	ldx		[$inp + 8], %o5
1181cb0ef41Sopenharmony_ci	ldx		[$inp + 16], $inp
1191cb0ef41Sopenharmony_ci	sll		%g1, 3, %g1
1201cb0ef41Sopenharmony_ci	sub		%g0, %g1, %o3
1211cb0ef41Sopenharmony_ci	sllx		%o4, %g1, %o4
1221cb0ef41Sopenharmony_ci	sllx		%o5, %g1, %g1
1231cb0ef41Sopenharmony_ci	srlx		%o5, %o3, %o5
1241cb0ef41Sopenharmony_ci	srlx		$inp, %o3, %o3
1251cb0ef41Sopenharmony_ci	or		%o5, %o4, %o4
1261cb0ef41Sopenharmony_ci	or		%o3, %g1, %o5
1271cb0ef41Sopenharmony_ci1:
1281cb0ef41Sopenharmony_ci	ld		[$key + 240], $rounds
1291cb0ef41Sopenharmony_ci	ldd		[$key + 16], %f12
1301cb0ef41Sopenharmony_ci	ldd		[$key + 24], %f14
1311cb0ef41Sopenharmony_ci	xor		%g4, %o4, %o4
1321cb0ef41Sopenharmony_ci	xor		%g5, %o5, %o5
1331cb0ef41Sopenharmony_ci	movxtod		%o4, %f0
1341cb0ef41Sopenharmony_ci	movxtod		%o5, %f2
1351cb0ef41Sopenharmony_ci	srl		$rounds, 1, $rounds
1361cb0ef41Sopenharmony_ci	ldd		[$key + 32], %f16
1371cb0ef41Sopenharmony_ci	sub		$rounds, 1, $rounds
1381cb0ef41Sopenharmony_ci	ldd		[$key + 40], %f18
1391cb0ef41Sopenharmony_ci	add		$key, 48, $key
1401cb0ef41Sopenharmony_ci
1411cb0ef41Sopenharmony_ci.Lenc:
1421cb0ef41Sopenharmony_ci	aes_eround01	%f12, %f0, %f2, %f4
1431cb0ef41Sopenharmony_ci	aes_eround23	%f14, %f0, %f2, %f2
1441cb0ef41Sopenharmony_ci	ldd		[$key + 0], %f12
1451cb0ef41Sopenharmony_ci	ldd		[$key + 8], %f14
1461cb0ef41Sopenharmony_ci	sub		$rounds,1,$rounds
1471cb0ef41Sopenharmony_ci	aes_eround01	%f16, %f4, %f2, %f0
1481cb0ef41Sopenharmony_ci	aes_eround23	%f18, %f4, %f2, %f2
1491cb0ef41Sopenharmony_ci	ldd		[$key + 16], %f16
1501cb0ef41Sopenharmony_ci	ldd		[$key + 24], %f18
1511cb0ef41Sopenharmony_ci	brnz,pt		$rounds, .Lenc
1521cb0ef41Sopenharmony_ci	add		$key, 32, $key
1531cb0ef41Sopenharmony_ci
1541cb0ef41Sopenharmony_ci	andcc		$out, 7, $tmp		! is output aligned?
1551cb0ef41Sopenharmony_ci	aes_eround01	%f12, %f0, %f2, %f4
1561cb0ef41Sopenharmony_ci	aes_eround23	%f14, %f0, %f2, %f2
1571cb0ef41Sopenharmony_ci	aes_eround01_l	%f16, %f4, %f2, %f0
1581cb0ef41Sopenharmony_ci	aes_eround23_l	%f18, %f4, %f2, %f2
1591cb0ef41Sopenharmony_ci
1601cb0ef41Sopenharmony_ci	bnz,pn		%icc, 2f
1611cb0ef41Sopenharmony_ci	nop
1621cb0ef41Sopenharmony_ci
1631cb0ef41Sopenharmony_ci	std		%f0, [$out + 0]
1641cb0ef41Sopenharmony_ci	retl
1651cb0ef41Sopenharmony_ci	std		%f2, [$out + 8]
1661cb0ef41Sopenharmony_ci
1671cb0ef41Sopenharmony_ci2:	alignaddrl	$out, %g0, $out
1681cb0ef41Sopenharmony_ci	mov		0xff, $mask
1691cb0ef41Sopenharmony_ci	srl		$mask, $tmp, $mask
1701cb0ef41Sopenharmony_ci
1711cb0ef41Sopenharmony_ci	faligndata	%f0, %f0, %f4
1721cb0ef41Sopenharmony_ci	faligndata	%f0, %f2, %f6
1731cb0ef41Sopenharmony_ci	faligndata	%f2, %f2, %f8
1741cb0ef41Sopenharmony_ci
1751cb0ef41Sopenharmony_ci	stda		%f4, [$out + $mask]0xc0	! partial store
1761cb0ef41Sopenharmony_ci	std		%f6, [$out + 8]
1771cb0ef41Sopenharmony_ci	add		$out, 16, $out
1781cb0ef41Sopenharmony_ci	orn		%g0, $mask, $mask
1791cb0ef41Sopenharmony_ci	retl
1801cb0ef41Sopenharmony_ci	stda		%f8, [$out + $mask]0xc0	! partial store
1811cb0ef41Sopenharmony_ci.type	aes_t4_encrypt,#function
1821cb0ef41Sopenharmony_ci.size	aes_t4_encrypt,.-aes_t4_encrypt
1831cb0ef41Sopenharmony_ci
1841cb0ef41Sopenharmony_ci.globl	aes_t4_decrypt
1851cb0ef41Sopenharmony_ci.align	32
1861cb0ef41Sopenharmony_ciaes_t4_decrypt:
1871cb0ef41Sopenharmony_ci	andcc		$inp, 7, %g1		! is input aligned?
1881cb0ef41Sopenharmony_ci	andn		$inp, 7, $inp
1891cb0ef41Sopenharmony_ci
1901cb0ef41Sopenharmony_ci	ldx		[$key + 0], %g4
1911cb0ef41Sopenharmony_ci	ldx		[$key + 8], %g5
1921cb0ef41Sopenharmony_ci
1931cb0ef41Sopenharmony_ci	ldx		[$inp + 0], %o4
1941cb0ef41Sopenharmony_ci	bz,pt		%icc, 1f
1951cb0ef41Sopenharmony_ci	ldx		[$inp + 8], %o5
1961cb0ef41Sopenharmony_ci	ldx		[$inp + 16], $inp
1971cb0ef41Sopenharmony_ci	sll		%g1, 3, %g1
1981cb0ef41Sopenharmony_ci	sub		%g0, %g1, %o3
1991cb0ef41Sopenharmony_ci	sllx		%o4, %g1, %o4
2001cb0ef41Sopenharmony_ci	sllx		%o5, %g1, %g1
2011cb0ef41Sopenharmony_ci	srlx		%o5, %o3, %o5
2021cb0ef41Sopenharmony_ci	srlx		$inp, %o3, %o3
2031cb0ef41Sopenharmony_ci	or		%o5, %o4, %o4
2041cb0ef41Sopenharmony_ci	or		%o3, %g1, %o5
2051cb0ef41Sopenharmony_ci1:
2061cb0ef41Sopenharmony_ci	ld		[$key + 240], $rounds
2071cb0ef41Sopenharmony_ci	ldd		[$key + 16], %f12
2081cb0ef41Sopenharmony_ci	ldd		[$key + 24], %f14
2091cb0ef41Sopenharmony_ci	xor		%g4, %o4, %o4
2101cb0ef41Sopenharmony_ci	xor		%g5, %o5, %o5
2111cb0ef41Sopenharmony_ci	movxtod		%o4, %f0
2121cb0ef41Sopenharmony_ci	movxtod		%o5, %f2
2131cb0ef41Sopenharmony_ci	srl		$rounds, 1, $rounds
2141cb0ef41Sopenharmony_ci	ldd		[$key + 32], %f16
2151cb0ef41Sopenharmony_ci	sub		$rounds, 1, $rounds
2161cb0ef41Sopenharmony_ci	ldd		[$key + 40], %f18
2171cb0ef41Sopenharmony_ci	add		$key, 48, $key
2181cb0ef41Sopenharmony_ci
2191cb0ef41Sopenharmony_ci.Ldec:
2201cb0ef41Sopenharmony_ci	aes_dround01	%f12, %f0, %f2, %f4
2211cb0ef41Sopenharmony_ci	aes_dround23	%f14, %f0, %f2, %f2
2221cb0ef41Sopenharmony_ci	ldd		[$key + 0], %f12
2231cb0ef41Sopenharmony_ci	ldd		[$key + 8], %f14
2241cb0ef41Sopenharmony_ci	sub		$rounds,1,$rounds
2251cb0ef41Sopenharmony_ci	aes_dround01	%f16, %f4, %f2, %f0
2261cb0ef41Sopenharmony_ci	aes_dround23	%f18, %f4, %f2, %f2
2271cb0ef41Sopenharmony_ci	ldd		[$key + 16], %f16
2281cb0ef41Sopenharmony_ci	ldd		[$key + 24], %f18
2291cb0ef41Sopenharmony_ci	brnz,pt		$rounds, .Ldec
2301cb0ef41Sopenharmony_ci	add		$key, 32, $key
2311cb0ef41Sopenharmony_ci
2321cb0ef41Sopenharmony_ci	andcc		$out, 7, $tmp		! is output aligned?
2331cb0ef41Sopenharmony_ci	aes_dround01	%f12, %f0, %f2, %f4
2341cb0ef41Sopenharmony_ci	aes_dround23	%f14, %f0, %f2, %f2
2351cb0ef41Sopenharmony_ci	aes_dround01_l	%f16, %f4, %f2, %f0
2361cb0ef41Sopenharmony_ci	aes_dround23_l	%f18, %f4, %f2, %f2
2371cb0ef41Sopenharmony_ci
2381cb0ef41Sopenharmony_ci	bnz,pn		%icc, 2f
2391cb0ef41Sopenharmony_ci	nop
2401cb0ef41Sopenharmony_ci
2411cb0ef41Sopenharmony_ci	std		%f0, [$out + 0]
2421cb0ef41Sopenharmony_ci	retl
2431cb0ef41Sopenharmony_ci	std		%f2, [$out + 8]
2441cb0ef41Sopenharmony_ci
2451cb0ef41Sopenharmony_ci2:	alignaddrl	$out, %g0, $out
2461cb0ef41Sopenharmony_ci	mov		0xff, $mask
2471cb0ef41Sopenharmony_ci	srl		$mask, $tmp, $mask
2481cb0ef41Sopenharmony_ci
2491cb0ef41Sopenharmony_ci	faligndata	%f0, %f0, %f4
2501cb0ef41Sopenharmony_ci	faligndata	%f0, %f2, %f6
2511cb0ef41Sopenharmony_ci	faligndata	%f2, %f2, %f8
2521cb0ef41Sopenharmony_ci
2531cb0ef41Sopenharmony_ci	stda		%f4, [$out + $mask]0xc0	! partial store
2541cb0ef41Sopenharmony_ci	std		%f6, [$out + 8]
2551cb0ef41Sopenharmony_ci	add		$out, 16, $out
2561cb0ef41Sopenharmony_ci	orn		%g0, $mask, $mask
2571cb0ef41Sopenharmony_ci	retl
2581cb0ef41Sopenharmony_ci	stda		%f8, [$out + $mask]0xc0	! partial store
2591cb0ef41Sopenharmony_ci.type	aes_t4_decrypt,#function
2601cb0ef41Sopenharmony_ci.size	aes_t4_decrypt,.-aes_t4_decrypt
2611cb0ef41Sopenharmony_ci___
2621cb0ef41Sopenharmony_ci}
2631cb0ef41Sopenharmony_ci
2641cb0ef41Sopenharmony_ci######################################################################
2651cb0ef41Sopenharmony_ci# key setup subroutines
2661cb0ef41Sopenharmony_ci#
2671cb0ef41Sopenharmony_ci{
2681cb0ef41Sopenharmony_cimy ($inp,$bits,$out,$tmp)=map("%o$_",(0..5));
2691cb0ef41Sopenharmony_ci$code.=<<___;
2701cb0ef41Sopenharmony_ci.globl	aes_t4_set_encrypt_key
2711cb0ef41Sopenharmony_ci.align	32
2721cb0ef41Sopenharmony_ciaes_t4_set_encrypt_key:
2731cb0ef41Sopenharmony_ci.Lset_encrypt_key:
2741cb0ef41Sopenharmony_ci	and		$inp, 7, $tmp
2751cb0ef41Sopenharmony_ci	alignaddr	$inp, %g0, $inp
2761cb0ef41Sopenharmony_ci	cmp		$bits, 192
2771cb0ef41Sopenharmony_ci	ldd		[$inp + 0], %f0
2781cb0ef41Sopenharmony_ci	bl,pt		%icc,.L128
2791cb0ef41Sopenharmony_ci	ldd		[$inp + 8], %f2
2801cb0ef41Sopenharmony_ci
2811cb0ef41Sopenharmony_ci	be,pt		%icc,.L192
2821cb0ef41Sopenharmony_ci	ldd		[$inp + 16], %f4
2831cb0ef41Sopenharmony_ci	brz,pt		$tmp, .L256aligned
2841cb0ef41Sopenharmony_ci	ldd		[$inp + 24], %f6
2851cb0ef41Sopenharmony_ci
2861cb0ef41Sopenharmony_ci	ldd		[$inp + 32], %f8
2871cb0ef41Sopenharmony_ci	faligndata	%f0, %f2, %f0
2881cb0ef41Sopenharmony_ci	faligndata	%f2, %f4, %f2
2891cb0ef41Sopenharmony_ci	faligndata	%f4, %f6, %f4
2901cb0ef41Sopenharmony_ci	faligndata	%f6, %f8, %f6
2911cb0ef41Sopenharmony_ci.L256aligned:
2921cb0ef41Sopenharmony_ci___
2931cb0ef41Sopenharmony_cifor ($i=0; $i<6; $i++) {
2941cb0ef41Sopenharmony_ci    $code.=<<___;
2951cb0ef41Sopenharmony_ci	std		%f0, [$out + `32*$i+0`]
2961cb0ef41Sopenharmony_ci	aes_kexpand1	%f0, %f6, $i, %f0
2971cb0ef41Sopenharmony_ci	std		%f2, [$out + `32*$i+8`]
2981cb0ef41Sopenharmony_ci	aes_kexpand2	%f2, %f0, %f2
2991cb0ef41Sopenharmony_ci	std		%f4, [$out + `32*$i+16`]
3001cb0ef41Sopenharmony_ci	aes_kexpand0	%f4, %f2, %f4
3011cb0ef41Sopenharmony_ci	std		%f6, [$out + `32*$i+24`]
3021cb0ef41Sopenharmony_ci	aes_kexpand2	%f6, %f4, %f6
3031cb0ef41Sopenharmony_ci___
3041cb0ef41Sopenharmony_ci}
3051cb0ef41Sopenharmony_ci$code.=<<___;
3061cb0ef41Sopenharmony_ci	std		%f0, [$out + `32*$i+0`]
3071cb0ef41Sopenharmony_ci	aes_kexpand1	%f0, %f6, $i, %f0
3081cb0ef41Sopenharmony_ci	std		%f2, [$out + `32*$i+8`]
3091cb0ef41Sopenharmony_ci	aes_kexpand2	%f2, %f0, %f2
3101cb0ef41Sopenharmony_ci	std		%f4, [$out + `32*$i+16`]
3111cb0ef41Sopenharmony_ci	std		%f6, [$out + `32*$i+24`]
3121cb0ef41Sopenharmony_ci	std		%f0, [$out + `32*$i+32`]
3131cb0ef41Sopenharmony_ci	std		%f2, [$out + `32*$i+40`]
3141cb0ef41Sopenharmony_ci
3151cb0ef41Sopenharmony_ci	mov		14, $tmp
3161cb0ef41Sopenharmony_ci	st		$tmp, [$out + 240]
3171cb0ef41Sopenharmony_ci	retl
3181cb0ef41Sopenharmony_ci	xor		%o0, %o0, %o0
3191cb0ef41Sopenharmony_ci
3201cb0ef41Sopenharmony_ci.align	16
3211cb0ef41Sopenharmony_ci.L192:
3221cb0ef41Sopenharmony_ci	brz,pt		$tmp, .L192aligned
3231cb0ef41Sopenharmony_ci	nop
3241cb0ef41Sopenharmony_ci
3251cb0ef41Sopenharmony_ci	ldd		[$inp + 24], %f6
3261cb0ef41Sopenharmony_ci	faligndata	%f0, %f2, %f0
3271cb0ef41Sopenharmony_ci	faligndata	%f2, %f4, %f2
3281cb0ef41Sopenharmony_ci	faligndata	%f4, %f6, %f4
3291cb0ef41Sopenharmony_ci.L192aligned:
3301cb0ef41Sopenharmony_ci___
3311cb0ef41Sopenharmony_cifor ($i=0; $i<7; $i++) {
3321cb0ef41Sopenharmony_ci    $code.=<<___;
3331cb0ef41Sopenharmony_ci	std		%f0, [$out + `24*$i+0`]
3341cb0ef41Sopenharmony_ci	aes_kexpand1	%f0, %f4, $i, %f0
3351cb0ef41Sopenharmony_ci	std		%f2, [$out + `24*$i+8`]
3361cb0ef41Sopenharmony_ci	aes_kexpand2	%f2, %f0, %f2
3371cb0ef41Sopenharmony_ci	std		%f4, [$out + `24*$i+16`]
3381cb0ef41Sopenharmony_ci	aes_kexpand2	%f4, %f2, %f4
3391cb0ef41Sopenharmony_ci___
3401cb0ef41Sopenharmony_ci}
3411cb0ef41Sopenharmony_ci$code.=<<___;
3421cb0ef41Sopenharmony_ci	std		%f0, [$out + `24*$i+0`]
3431cb0ef41Sopenharmony_ci	aes_kexpand1	%f0, %f4, $i, %f0
3441cb0ef41Sopenharmony_ci	std		%f2, [$out + `24*$i+8`]
3451cb0ef41Sopenharmony_ci	aes_kexpand2	%f2, %f0, %f2
3461cb0ef41Sopenharmony_ci	std		%f4, [$out + `24*$i+16`]
3471cb0ef41Sopenharmony_ci	std		%f0, [$out + `24*$i+24`]
3481cb0ef41Sopenharmony_ci	std		%f2, [$out + `24*$i+32`]
3491cb0ef41Sopenharmony_ci
3501cb0ef41Sopenharmony_ci	mov		12, $tmp
3511cb0ef41Sopenharmony_ci	st		$tmp, [$out + 240]
3521cb0ef41Sopenharmony_ci	retl
3531cb0ef41Sopenharmony_ci	xor		%o0, %o0, %o0
3541cb0ef41Sopenharmony_ci
3551cb0ef41Sopenharmony_ci.align	16
3561cb0ef41Sopenharmony_ci.L128:
3571cb0ef41Sopenharmony_ci	brz,pt		$tmp, .L128aligned
3581cb0ef41Sopenharmony_ci	nop
3591cb0ef41Sopenharmony_ci
3601cb0ef41Sopenharmony_ci	ldd		[$inp + 16], %f4
3611cb0ef41Sopenharmony_ci	faligndata	%f0, %f2, %f0
3621cb0ef41Sopenharmony_ci	faligndata	%f2, %f4, %f2
3631cb0ef41Sopenharmony_ci.L128aligned:
3641cb0ef41Sopenharmony_ci___
3651cb0ef41Sopenharmony_cifor ($i=0; $i<10; $i++) {
3661cb0ef41Sopenharmony_ci    $code.=<<___;
3671cb0ef41Sopenharmony_ci	std		%f0, [$out + `16*$i+0`]
3681cb0ef41Sopenharmony_ci	aes_kexpand1	%f0, %f2, $i, %f0
3691cb0ef41Sopenharmony_ci	std		%f2, [$out + `16*$i+8`]
3701cb0ef41Sopenharmony_ci	aes_kexpand2	%f2, %f0, %f2
3711cb0ef41Sopenharmony_ci___
3721cb0ef41Sopenharmony_ci}
3731cb0ef41Sopenharmony_ci$code.=<<___;
3741cb0ef41Sopenharmony_ci	std		%f0, [$out + `16*$i+0`]
3751cb0ef41Sopenharmony_ci	std		%f2, [$out + `16*$i+8`]
3761cb0ef41Sopenharmony_ci
3771cb0ef41Sopenharmony_ci	mov		10, $tmp
3781cb0ef41Sopenharmony_ci	st		$tmp, [$out + 240]
3791cb0ef41Sopenharmony_ci	retl
3801cb0ef41Sopenharmony_ci	xor		%o0, %o0, %o0
3811cb0ef41Sopenharmony_ci.type	aes_t4_set_encrypt_key,#function
3821cb0ef41Sopenharmony_ci.size	aes_t4_set_encrypt_key,.-aes_t4_set_encrypt_key
3831cb0ef41Sopenharmony_ci
3841cb0ef41Sopenharmony_ci.globl	aes_t4_set_decrypt_key
3851cb0ef41Sopenharmony_ci.align	32
3861cb0ef41Sopenharmony_ciaes_t4_set_decrypt_key:
3871cb0ef41Sopenharmony_ci	mov		%o7, %o5
3881cb0ef41Sopenharmony_ci	call		.Lset_encrypt_key
3891cb0ef41Sopenharmony_ci	nop
3901cb0ef41Sopenharmony_ci
3911cb0ef41Sopenharmony_ci	mov		%o5, %o7
3921cb0ef41Sopenharmony_ci	sll		$tmp, 4, $inp		! $tmp is number of rounds
3931cb0ef41Sopenharmony_ci	add		$tmp, 2, $tmp
3941cb0ef41Sopenharmony_ci	add		$out, $inp, $inp	! $inp=$out+16*rounds
3951cb0ef41Sopenharmony_ci	srl		$tmp, 2, $tmp		! $tmp=(rounds+2)/4
3961cb0ef41Sopenharmony_ci
3971cb0ef41Sopenharmony_ci.Lkey_flip:
3981cb0ef41Sopenharmony_ci	ldd		[$out + 0],  %f0
3991cb0ef41Sopenharmony_ci	ldd		[$out + 8],  %f2
4001cb0ef41Sopenharmony_ci	ldd		[$out + 16], %f4
4011cb0ef41Sopenharmony_ci	ldd		[$out + 24], %f6
4021cb0ef41Sopenharmony_ci	ldd		[$inp + 0],  %f8
4031cb0ef41Sopenharmony_ci	ldd		[$inp + 8],  %f10
4041cb0ef41Sopenharmony_ci	ldd		[$inp - 16], %f12
4051cb0ef41Sopenharmony_ci	ldd		[$inp - 8],  %f14
4061cb0ef41Sopenharmony_ci	sub		$tmp, 1, $tmp
4071cb0ef41Sopenharmony_ci	std		%f0, [$inp + 0]
4081cb0ef41Sopenharmony_ci	std		%f2, [$inp + 8]
4091cb0ef41Sopenharmony_ci	std		%f4, [$inp - 16]
4101cb0ef41Sopenharmony_ci	std		%f6, [$inp - 8]
4111cb0ef41Sopenharmony_ci	std		%f8, [$out + 0]
4121cb0ef41Sopenharmony_ci	std		%f10, [$out + 8]
4131cb0ef41Sopenharmony_ci	std		%f12, [$out + 16]
4141cb0ef41Sopenharmony_ci	std		%f14, [$out + 24]
4151cb0ef41Sopenharmony_ci	add		$out, 32, $out
4161cb0ef41Sopenharmony_ci	brnz		$tmp, .Lkey_flip
4171cb0ef41Sopenharmony_ci	sub		$inp, 32, $inp
4181cb0ef41Sopenharmony_ci
4191cb0ef41Sopenharmony_ci	retl
4201cb0ef41Sopenharmony_ci	xor		%o0, %o0, %o0
4211cb0ef41Sopenharmony_ci.type	aes_t4_set_decrypt_key,#function
4221cb0ef41Sopenharmony_ci.size	aes_t4_set_decrypt_key,.-aes_t4_set_decrypt_key
4231cb0ef41Sopenharmony_ci___
4241cb0ef41Sopenharmony_ci}
4251cb0ef41Sopenharmony_ci
4261cb0ef41Sopenharmony_ci{{{
4271cb0ef41Sopenharmony_cimy ($inp,$out,$len,$key,$ivec,$enc)=map("%i$_",(0..5));
4281cb0ef41Sopenharmony_cimy ($ileft,$iright,$ooff,$omask,$ivoff)=map("%l$_",(1..7));
4291cb0ef41Sopenharmony_ci
4301cb0ef41Sopenharmony_ci$code.=<<___;
4311cb0ef41Sopenharmony_ci.align	32
4321cb0ef41Sopenharmony_ci_aes128_encrypt_1x:
4331cb0ef41Sopenharmony_ci___
4341cb0ef41Sopenharmony_cifor ($i=0; $i<4; $i++) {
4351cb0ef41Sopenharmony_ci    $code.=<<___;
4361cb0ef41Sopenharmony_ci	aes_eround01	%f`16+8*$i+0`, %f0, %f2, %f4
4371cb0ef41Sopenharmony_ci	aes_eround23	%f`16+8*$i+2`, %f0, %f2, %f2
4381cb0ef41Sopenharmony_ci	aes_eround01	%f`16+8*$i+4`, %f4, %f2, %f0
4391cb0ef41Sopenharmony_ci	aes_eround23	%f`16+8*$i+6`, %f4, %f2, %f2
4401cb0ef41Sopenharmony_ci___
4411cb0ef41Sopenharmony_ci}
4421cb0ef41Sopenharmony_ci$code.=<<___;
4431cb0ef41Sopenharmony_ci	aes_eround01	%f48, %f0, %f2, %f4
4441cb0ef41Sopenharmony_ci	aes_eround23	%f50, %f0, %f2, %f2
4451cb0ef41Sopenharmony_ci	aes_eround01_l	%f52, %f4, %f2, %f0
4461cb0ef41Sopenharmony_ci	retl
4471cb0ef41Sopenharmony_ci	aes_eround23_l	%f54, %f4, %f2, %f2
4481cb0ef41Sopenharmony_ci.type	_aes128_encrypt_1x,#function
4491cb0ef41Sopenharmony_ci.size	_aes128_encrypt_1x,.-_aes128_encrypt_1x
4501cb0ef41Sopenharmony_ci
4511cb0ef41Sopenharmony_ci.align	32
4521cb0ef41Sopenharmony_ci_aes128_encrypt_2x:
4531cb0ef41Sopenharmony_ci___
4541cb0ef41Sopenharmony_cifor ($i=0; $i<4; $i++) {
4551cb0ef41Sopenharmony_ci    $code.=<<___;
4561cb0ef41Sopenharmony_ci	aes_eround01	%f`16+8*$i+0`, %f0, %f2, %f8
4571cb0ef41Sopenharmony_ci	aes_eround23	%f`16+8*$i+2`, %f0, %f2, %f2
4581cb0ef41Sopenharmony_ci	aes_eround01	%f`16+8*$i+0`, %f4, %f6, %f10
4591cb0ef41Sopenharmony_ci	aes_eround23	%f`16+8*$i+2`, %f4, %f6, %f6
4601cb0ef41Sopenharmony_ci	aes_eround01	%f`16+8*$i+4`, %f8, %f2, %f0
4611cb0ef41Sopenharmony_ci	aes_eround23	%f`16+8*$i+6`, %f8, %f2, %f2
4621cb0ef41Sopenharmony_ci	aes_eround01	%f`16+8*$i+4`, %f10, %f6, %f4
4631cb0ef41Sopenharmony_ci	aes_eround23	%f`16+8*$i+6`, %f10, %f6, %f6
4641cb0ef41Sopenharmony_ci___
4651cb0ef41Sopenharmony_ci}
4661cb0ef41Sopenharmony_ci$code.=<<___;
4671cb0ef41Sopenharmony_ci	aes_eround01	%f48, %f0, %f2, %f8
4681cb0ef41Sopenharmony_ci	aes_eround23	%f50, %f0, %f2, %f2
4691cb0ef41Sopenharmony_ci	aes_eround01	%f48, %f4, %f6, %f10
4701cb0ef41Sopenharmony_ci	aes_eround23	%f50, %f4, %f6, %f6
4711cb0ef41Sopenharmony_ci	aes_eround01_l	%f52, %f8, %f2, %f0
4721cb0ef41Sopenharmony_ci	aes_eround23_l	%f54, %f8, %f2, %f2
4731cb0ef41Sopenharmony_ci	aes_eround01_l	%f52, %f10, %f6, %f4
4741cb0ef41Sopenharmony_ci	retl
4751cb0ef41Sopenharmony_ci	aes_eround23_l	%f54, %f10, %f6, %f6
4761cb0ef41Sopenharmony_ci.type	_aes128_encrypt_2x,#function
4771cb0ef41Sopenharmony_ci.size	_aes128_encrypt_2x,.-_aes128_encrypt_2x
4781cb0ef41Sopenharmony_ci
4791cb0ef41Sopenharmony_ci.align	32
4801cb0ef41Sopenharmony_ci_aes128_loadkey:
4811cb0ef41Sopenharmony_ci	ldx		[$key + 0], %g4
4821cb0ef41Sopenharmony_ci	ldx		[$key + 8], %g5
4831cb0ef41Sopenharmony_ci___
4841cb0ef41Sopenharmony_cifor ($i=2; $i<22;$i++) {			# load key schedule
4851cb0ef41Sopenharmony_ci    $code.=<<___;
4861cb0ef41Sopenharmony_ci	ldd		[$key + `8*$i`], %f`12+2*$i`
4871cb0ef41Sopenharmony_ci___
4881cb0ef41Sopenharmony_ci}
4891cb0ef41Sopenharmony_ci$code.=<<___;
4901cb0ef41Sopenharmony_ci	retl
4911cb0ef41Sopenharmony_ci	nop
4921cb0ef41Sopenharmony_ci.type	_aes128_loadkey,#function
4931cb0ef41Sopenharmony_ci.size	_aes128_loadkey,.-_aes128_loadkey
4941cb0ef41Sopenharmony_ci_aes128_load_enckey=_aes128_loadkey
4951cb0ef41Sopenharmony_ci_aes128_load_deckey=_aes128_loadkey
4961cb0ef41Sopenharmony_ci
4971cb0ef41Sopenharmony_ci___
4981cb0ef41Sopenharmony_ci
4991cb0ef41Sopenharmony_ci&alg_cbc_encrypt_implement("aes",128);
5001cb0ef41Sopenharmony_ciif ($::evp) {
5011cb0ef41Sopenharmony_ci    &alg_ctr32_implement("aes",128);
5021cb0ef41Sopenharmony_ci    &alg_xts_implement("aes",128,"en");
5031cb0ef41Sopenharmony_ci    &alg_xts_implement("aes",128,"de");
5041cb0ef41Sopenharmony_ci}
5051cb0ef41Sopenharmony_ci&alg_cbc_decrypt_implement("aes",128);
5061cb0ef41Sopenharmony_ci
5071cb0ef41Sopenharmony_ci$code.=<<___;
5081cb0ef41Sopenharmony_ci.align	32
5091cb0ef41Sopenharmony_ci_aes128_decrypt_1x:
5101cb0ef41Sopenharmony_ci___
5111cb0ef41Sopenharmony_cifor ($i=0; $i<4; $i++) {
5121cb0ef41Sopenharmony_ci    $code.=<<___;
5131cb0ef41Sopenharmony_ci	aes_dround01	%f`16+8*$i+0`, %f0, %f2, %f4
5141cb0ef41Sopenharmony_ci	aes_dround23	%f`16+8*$i+2`, %f0, %f2, %f2
5151cb0ef41Sopenharmony_ci	aes_dround01	%f`16+8*$i+4`, %f4, %f2, %f0
5161cb0ef41Sopenharmony_ci	aes_dround23	%f`16+8*$i+6`, %f4, %f2, %f2
5171cb0ef41Sopenharmony_ci___
5181cb0ef41Sopenharmony_ci}
5191cb0ef41Sopenharmony_ci$code.=<<___;
5201cb0ef41Sopenharmony_ci	aes_dround01	%f48, %f0, %f2, %f4
5211cb0ef41Sopenharmony_ci	aes_dround23	%f50, %f0, %f2, %f2
5221cb0ef41Sopenharmony_ci	aes_dround01_l	%f52, %f4, %f2, %f0
5231cb0ef41Sopenharmony_ci	retl
5241cb0ef41Sopenharmony_ci	aes_dround23_l	%f54, %f4, %f2, %f2
5251cb0ef41Sopenharmony_ci.type	_aes128_decrypt_1x,#function
5261cb0ef41Sopenharmony_ci.size	_aes128_decrypt_1x,.-_aes128_decrypt_1x
5271cb0ef41Sopenharmony_ci
5281cb0ef41Sopenharmony_ci.align	32
5291cb0ef41Sopenharmony_ci_aes128_decrypt_2x:
5301cb0ef41Sopenharmony_ci___
5311cb0ef41Sopenharmony_cifor ($i=0; $i<4; $i++) {
5321cb0ef41Sopenharmony_ci    $code.=<<___;
5331cb0ef41Sopenharmony_ci	aes_dround01	%f`16+8*$i+0`, %f0, %f2, %f8
5341cb0ef41Sopenharmony_ci	aes_dround23	%f`16+8*$i+2`, %f0, %f2, %f2
5351cb0ef41Sopenharmony_ci	aes_dround01	%f`16+8*$i+0`, %f4, %f6, %f10
5361cb0ef41Sopenharmony_ci	aes_dround23	%f`16+8*$i+2`, %f4, %f6, %f6
5371cb0ef41Sopenharmony_ci	aes_dround01	%f`16+8*$i+4`, %f8, %f2, %f0
5381cb0ef41Sopenharmony_ci	aes_dround23	%f`16+8*$i+6`, %f8, %f2, %f2
5391cb0ef41Sopenharmony_ci	aes_dround01	%f`16+8*$i+4`, %f10, %f6, %f4
5401cb0ef41Sopenharmony_ci	aes_dround23	%f`16+8*$i+6`, %f10, %f6, %f6
5411cb0ef41Sopenharmony_ci___
5421cb0ef41Sopenharmony_ci}
5431cb0ef41Sopenharmony_ci$code.=<<___;
5441cb0ef41Sopenharmony_ci	aes_dround01	%f48, %f0, %f2, %f8
5451cb0ef41Sopenharmony_ci	aes_dround23	%f50, %f0, %f2, %f2
5461cb0ef41Sopenharmony_ci	aes_dround01	%f48, %f4, %f6, %f10
5471cb0ef41Sopenharmony_ci	aes_dround23	%f50, %f4, %f6, %f6
5481cb0ef41Sopenharmony_ci	aes_dround01_l	%f52, %f8, %f2, %f0
5491cb0ef41Sopenharmony_ci	aes_dround23_l	%f54, %f8, %f2, %f2
5501cb0ef41Sopenharmony_ci	aes_dround01_l	%f52, %f10, %f6, %f4
5511cb0ef41Sopenharmony_ci	retl
5521cb0ef41Sopenharmony_ci	aes_dround23_l	%f54, %f10, %f6, %f6
5531cb0ef41Sopenharmony_ci.type	_aes128_decrypt_2x,#function
5541cb0ef41Sopenharmony_ci.size	_aes128_decrypt_2x,.-_aes128_decrypt_2x
5551cb0ef41Sopenharmony_ci___
5561cb0ef41Sopenharmony_ci
5571cb0ef41Sopenharmony_ci$code.=<<___;
5581cb0ef41Sopenharmony_ci.align	32
5591cb0ef41Sopenharmony_ci_aes192_encrypt_1x:
5601cb0ef41Sopenharmony_ci___
5611cb0ef41Sopenharmony_cifor ($i=0; $i<5; $i++) {
5621cb0ef41Sopenharmony_ci    $code.=<<___;
5631cb0ef41Sopenharmony_ci	aes_eround01	%f`16+8*$i+0`, %f0, %f2, %f4
5641cb0ef41Sopenharmony_ci	aes_eround23	%f`16+8*$i+2`, %f0, %f2, %f2
5651cb0ef41Sopenharmony_ci	aes_eround01	%f`16+8*$i+4`, %f4, %f2, %f0
5661cb0ef41Sopenharmony_ci	aes_eround23	%f`16+8*$i+6`, %f4, %f2, %f2
5671cb0ef41Sopenharmony_ci___
5681cb0ef41Sopenharmony_ci}
5691cb0ef41Sopenharmony_ci$code.=<<___;
5701cb0ef41Sopenharmony_ci	aes_eround01	%f56, %f0, %f2, %f4
5711cb0ef41Sopenharmony_ci	aes_eround23	%f58, %f0, %f2, %f2
5721cb0ef41Sopenharmony_ci	aes_eround01_l	%f60, %f4, %f2, %f0
5731cb0ef41Sopenharmony_ci	retl
5741cb0ef41Sopenharmony_ci	aes_eround23_l	%f62, %f4, %f2, %f2
5751cb0ef41Sopenharmony_ci.type	_aes192_encrypt_1x,#function
5761cb0ef41Sopenharmony_ci.size	_aes192_encrypt_1x,.-_aes192_encrypt_1x
5771cb0ef41Sopenharmony_ci
5781cb0ef41Sopenharmony_ci.align	32
5791cb0ef41Sopenharmony_ci_aes192_encrypt_2x:
5801cb0ef41Sopenharmony_ci___
5811cb0ef41Sopenharmony_cifor ($i=0; $i<5; $i++) {
5821cb0ef41Sopenharmony_ci    $code.=<<___;
5831cb0ef41Sopenharmony_ci	aes_eround01	%f`16+8*$i+0`, %f0, %f2, %f8
5841cb0ef41Sopenharmony_ci	aes_eround23	%f`16+8*$i+2`, %f0, %f2, %f2
5851cb0ef41Sopenharmony_ci	aes_eround01	%f`16+8*$i+0`, %f4, %f6, %f10
5861cb0ef41Sopenharmony_ci	aes_eround23	%f`16+8*$i+2`, %f4, %f6, %f6
5871cb0ef41Sopenharmony_ci	aes_eround01	%f`16+8*$i+4`, %f8, %f2, %f0
5881cb0ef41Sopenharmony_ci	aes_eround23	%f`16+8*$i+6`, %f8, %f2, %f2
5891cb0ef41Sopenharmony_ci	aes_eround01	%f`16+8*$i+4`, %f10, %f6, %f4
5901cb0ef41Sopenharmony_ci	aes_eround23	%f`16+8*$i+6`, %f10, %f6, %f6
5911cb0ef41Sopenharmony_ci___
5921cb0ef41Sopenharmony_ci}
5931cb0ef41Sopenharmony_ci$code.=<<___;
5941cb0ef41Sopenharmony_ci	aes_eround01	%f56, %f0, %f2, %f8
5951cb0ef41Sopenharmony_ci	aes_eround23	%f58, %f0, %f2, %f2
5961cb0ef41Sopenharmony_ci	aes_eround01	%f56, %f4, %f6, %f10
5971cb0ef41Sopenharmony_ci	aes_eround23	%f58, %f4, %f6, %f6
5981cb0ef41Sopenharmony_ci	aes_eround01_l	%f60, %f8, %f2, %f0
5991cb0ef41Sopenharmony_ci	aes_eround23_l	%f62, %f8, %f2, %f2
6001cb0ef41Sopenharmony_ci	aes_eround01_l	%f60, %f10, %f6, %f4
6011cb0ef41Sopenharmony_ci	retl
6021cb0ef41Sopenharmony_ci	aes_eround23_l	%f62, %f10, %f6, %f6
6031cb0ef41Sopenharmony_ci.type	_aes192_encrypt_2x,#function
6041cb0ef41Sopenharmony_ci.size	_aes192_encrypt_2x,.-_aes192_encrypt_2x
6051cb0ef41Sopenharmony_ci
6061cb0ef41Sopenharmony_ci.align	32
6071cb0ef41Sopenharmony_ci_aes256_encrypt_1x:
6081cb0ef41Sopenharmony_ci	aes_eround01	%f16, %f0, %f2, %f4
6091cb0ef41Sopenharmony_ci	aes_eround23	%f18, %f0, %f2, %f2
6101cb0ef41Sopenharmony_ci	ldd		[$key + 208], %f16
6111cb0ef41Sopenharmony_ci	ldd		[$key + 216], %f18
6121cb0ef41Sopenharmony_ci	aes_eround01	%f20, %f4, %f2, %f0
6131cb0ef41Sopenharmony_ci	aes_eround23	%f22, %f4, %f2, %f2
6141cb0ef41Sopenharmony_ci	ldd		[$key + 224], %f20
6151cb0ef41Sopenharmony_ci	ldd		[$key + 232], %f22
6161cb0ef41Sopenharmony_ci___
6171cb0ef41Sopenharmony_cifor ($i=1; $i<6; $i++) {
6181cb0ef41Sopenharmony_ci    $code.=<<___;
6191cb0ef41Sopenharmony_ci	aes_eround01	%f`16+8*$i+0`, %f0, %f2, %f4
6201cb0ef41Sopenharmony_ci	aes_eround23	%f`16+8*$i+2`, %f0, %f2, %f2
6211cb0ef41Sopenharmony_ci	aes_eround01	%f`16+8*$i+4`, %f4, %f2, %f0
6221cb0ef41Sopenharmony_ci	aes_eround23	%f`16+8*$i+6`, %f4, %f2, %f2
6231cb0ef41Sopenharmony_ci___
6241cb0ef41Sopenharmony_ci}
6251cb0ef41Sopenharmony_ci$code.=<<___;
6261cb0ef41Sopenharmony_ci	aes_eround01	%f16, %f0, %f2, %f4
6271cb0ef41Sopenharmony_ci	aes_eround23	%f18, %f0, %f2, %f2
6281cb0ef41Sopenharmony_ci	ldd		[$key + 16], %f16
6291cb0ef41Sopenharmony_ci	ldd		[$key + 24], %f18
6301cb0ef41Sopenharmony_ci	aes_eround01_l	%f20, %f4, %f2, %f0
6311cb0ef41Sopenharmony_ci	aes_eround23_l	%f22, %f4, %f2, %f2
6321cb0ef41Sopenharmony_ci	ldd		[$key + 32], %f20
6331cb0ef41Sopenharmony_ci	retl
6341cb0ef41Sopenharmony_ci	ldd		[$key + 40], %f22
6351cb0ef41Sopenharmony_ci.type	_aes256_encrypt_1x,#function
6361cb0ef41Sopenharmony_ci.size	_aes256_encrypt_1x,.-_aes256_encrypt_1x
6371cb0ef41Sopenharmony_ci
6381cb0ef41Sopenharmony_ci.align	32
6391cb0ef41Sopenharmony_ci_aes256_encrypt_2x:
6401cb0ef41Sopenharmony_ci	aes_eround01	%f16, %f0, %f2, %f8
6411cb0ef41Sopenharmony_ci	aes_eround23	%f18, %f0, %f2, %f2
6421cb0ef41Sopenharmony_ci	aes_eround01	%f16, %f4, %f6, %f10
6431cb0ef41Sopenharmony_ci	aes_eround23	%f18, %f4, %f6, %f6
6441cb0ef41Sopenharmony_ci	ldd		[$key + 208], %f16
6451cb0ef41Sopenharmony_ci	ldd		[$key + 216], %f18
6461cb0ef41Sopenharmony_ci	aes_eround01	%f20, %f8, %f2, %f0
6471cb0ef41Sopenharmony_ci	aes_eround23	%f22, %f8, %f2, %f2
6481cb0ef41Sopenharmony_ci	aes_eround01	%f20, %f10, %f6, %f4
6491cb0ef41Sopenharmony_ci	aes_eround23	%f22, %f10, %f6, %f6
6501cb0ef41Sopenharmony_ci	ldd		[$key + 224], %f20
6511cb0ef41Sopenharmony_ci	ldd		[$key + 232], %f22
6521cb0ef41Sopenharmony_ci___
6531cb0ef41Sopenharmony_cifor ($i=1; $i<6; $i++) {
6541cb0ef41Sopenharmony_ci    $code.=<<___;
6551cb0ef41Sopenharmony_ci	aes_eround01	%f`16+8*$i+0`, %f0, %f2, %f8
6561cb0ef41Sopenharmony_ci	aes_eround23	%f`16+8*$i+2`, %f0, %f2, %f2
6571cb0ef41Sopenharmony_ci	aes_eround01	%f`16+8*$i+0`, %f4, %f6, %f10
6581cb0ef41Sopenharmony_ci	aes_eround23	%f`16+8*$i+2`, %f4, %f6, %f6
6591cb0ef41Sopenharmony_ci	aes_eround01	%f`16+8*$i+4`, %f8, %f2, %f0
6601cb0ef41Sopenharmony_ci	aes_eround23	%f`16+8*$i+6`, %f8, %f2, %f2
6611cb0ef41Sopenharmony_ci	aes_eround01	%f`16+8*$i+4`, %f10, %f6, %f4
6621cb0ef41Sopenharmony_ci	aes_eround23	%f`16+8*$i+6`, %f10, %f6, %f6
6631cb0ef41Sopenharmony_ci___
6641cb0ef41Sopenharmony_ci}
6651cb0ef41Sopenharmony_ci$code.=<<___;
6661cb0ef41Sopenharmony_ci	aes_eround01	%f16, %f0, %f2, %f8
6671cb0ef41Sopenharmony_ci	aes_eround23	%f18, %f0, %f2, %f2
6681cb0ef41Sopenharmony_ci	aes_eround01	%f16, %f4, %f6, %f10
6691cb0ef41Sopenharmony_ci	aes_eround23	%f18, %f4, %f6, %f6
6701cb0ef41Sopenharmony_ci	ldd		[$key + 16], %f16
6711cb0ef41Sopenharmony_ci	ldd		[$key + 24], %f18
6721cb0ef41Sopenharmony_ci	aes_eround01_l	%f20, %f8, %f2, %f0
6731cb0ef41Sopenharmony_ci	aes_eround23_l	%f22, %f8, %f2, %f2
6741cb0ef41Sopenharmony_ci	aes_eround01_l	%f20, %f10, %f6, %f4
6751cb0ef41Sopenharmony_ci	aes_eround23_l	%f22, %f10, %f6, %f6
6761cb0ef41Sopenharmony_ci	ldd		[$key + 32], %f20
6771cb0ef41Sopenharmony_ci	retl
6781cb0ef41Sopenharmony_ci	ldd		[$key + 40], %f22
6791cb0ef41Sopenharmony_ci.type	_aes256_encrypt_2x,#function
6801cb0ef41Sopenharmony_ci.size	_aes256_encrypt_2x,.-_aes256_encrypt_2x
6811cb0ef41Sopenharmony_ci
6821cb0ef41Sopenharmony_ci.align	32
6831cb0ef41Sopenharmony_ci_aes192_loadkey:
6841cb0ef41Sopenharmony_ci	ldx		[$key + 0], %g4
6851cb0ef41Sopenharmony_ci	ldx		[$key + 8], %g5
6861cb0ef41Sopenharmony_ci___
6871cb0ef41Sopenharmony_cifor ($i=2; $i<26;$i++) {			# load key schedule
6881cb0ef41Sopenharmony_ci    $code.=<<___;
6891cb0ef41Sopenharmony_ci	ldd		[$key + `8*$i`], %f`12+2*$i`
6901cb0ef41Sopenharmony_ci___
6911cb0ef41Sopenharmony_ci}
6921cb0ef41Sopenharmony_ci$code.=<<___;
6931cb0ef41Sopenharmony_ci	retl
6941cb0ef41Sopenharmony_ci	nop
6951cb0ef41Sopenharmony_ci.type	_aes192_loadkey,#function
6961cb0ef41Sopenharmony_ci.size	_aes192_loadkey,.-_aes192_loadkey
6971cb0ef41Sopenharmony_ci_aes256_loadkey=_aes192_loadkey
6981cb0ef41Sopenharmony_ci_aes192_load_enckey=_aes192_loadkey
6991cb0ef41Sopenharmony_ci_aes192_load_deckey=_aes192_loadkey
7001cb0ef41Sopenharmony_ci_aes256_load_enckey=_aes192_loadkey
7011cb0ef41Sopenharmony_ci_aes256_load_deckey=_aes192_loadkey
7021cb0ef41Sopenharmony_ci___
7031cb0ef41Sopenharmony_ci
7041cb0ef41Sopenharmony_ci&alg_cbc_encrypt_implement("aes",256);
7051cb0ef41Sopenharmony_ci&alg_cbc_encrypt_implement("aes",192);
7061cb0ef41Sopenharmony_ciif ($::evp) {
7071cb0ef41Sopenharmony_ci    &alg_ctr32_implement("aes",256);
7081cb0ef41Sopenharmony_ci    &alg_xts_implement("aes",256,"en");
7091cb0ef41Sopenharmony_ci    &alg_xts_implement("aes",256,"de");
7101cb0ef41Sopenharmony_ci    &alg_ctr32_implement("aes",192);
7111cb0ef41Sopenharmony_ci}
7121cb0ef41Sopenharmony_ci&alg_cbc_decrypt_implement("aes",192);
7131cb0ef41Sopenharmony_ci&alg_cbc_decrypt_implement("aes",256);
7141cb0ef41Sopenharmony_ci
7151cb0ef41Sopenharmony_ci$code.=<<___;
7161cb0ef41Sopenharmony_ci.align	32
7171cb0ef41Sopenharmony_ci_aes256_decrypt_1x:
7181cb0ef41Sopenharmony_ci	aes_dround01	%f16, %f0, %f2, %f4
7191cb0ef41Sopenharmony_ci	aes_dround23	%f18, %f0, %f2, %f2
7201cb0ef41Sopenharmony_ci	ldd		[$key + 208], %f16
7211cb0ef41Sopenharmony_ci	ldd		[$key + 216], %f18
7221cb0ef41Sopenharmony_ci	aes_dround01	%f20, %f4, %f2, %f0
7231cb0ef41Sopenharmony_ci	aes_dround23	%f22, %f4, %f2, %f2
7241cb0ef41Sopenharmony_ci	ldd		[$key + 224], %f20
7251cb0ef41Sopenharmony_ci	ldd		[$key + 232], %f22
7261cb0ef41Sopenharmony_ci___
7271cb0ef41Sopenharmony_cifor ($i=1; $i<6; $i++) {
7281cb0ef41Sopenharmony_ci    $code.=<<___;
7291cb0ef41Sopenharmony_ci	aes_dround01	%f`16+8*$i+0`, %f0, %f2, %f4
7301cb0ef41Sopenharmony_ci	aes_dround23	%f`16+8*$i+2`, %f0, %f2, %f2
7311cb0ef41Sopenharmony_ci	aes_dround01	%f`16+8*$i+4`, %f4, %f2, %f0
7321cb0ef41Sopenharmony_ci	aes_dround23	%f`16+8*$i+6`, %f4, %f2, %f2
7331cb0ef41Sopenharmony_ci___
7341cb0ef41Sopenharmony_ci}
7351cb0ef41Sopenharmony_ci$code.=<<___;
7361cb0ef41Sopenharmony_ci	aes_dround01	%f16, %f0, %f2, %f4
7371cb0ef41Sopenharmony_ci	aes_dround23	%f18, %f0, %f2, %f2
7381cb0ef41Sopenharmony_ci	ldd		[$key + 16], %f16
7391cb0ef41Sopenharmony_ci	ldd		[$key + 24], %f18
7401cb0ef41Sopenharmony_ci	aes_dround01_l	%f20, %f4, %f2, %f0
7411cb0ef41Sopenharmony_ci	aes_dround23_l	%f22, %f4, %f2, %f2
7421cb0ef41Sopenharmony_ci	ldd		[$key + 32], %f20
7431cb0ef41Sopenharmony_ci	retl
7441cb0ef41Sopenharmony_ci	ldd		[$key + 40], %f22
7451cb0ef41Sopenharmony_ci.type	_aes256_decrypt_1x,#function
7461cb0ef41Sopenharmony_ci.size	_aes256_decrypt_1x,.-_aes256_decrypt_1x
7471cb0ef41Sopenharmony_ci
7481cb0ef41Sopenharmony_ci.align	32
7491cb0ef41Sopenharmony_ci_aes256_decrypt_2x:
7501cb0ef41Sopenharmony_ci	aes_dround01	%f16, %f0, %f2, %f8
7511cb0ef41Sopenharmony_ci	aes_dround23	%f18, %f0, %f2, %f2
7521cb0ef41Sopenharmony_ci	aes_dround01	%f16, %f4, %f6, %f10
7531cb0ef41Sopenharmony_ci	aes_dround23	%f18, %f4, %f6, %f6
7541cb0ef41Sopenharmony_ci	ldd		[$key + 208], %f16
7551cb0ef41Sopenharmony_ci	ldd		[$key + 216], %f18
7561cb0ef41Sopenharmony_ci	aes_dround01	%f20, %f8, %f2, %f0
7571cb0ef41Sopenharmony_ci	aes_dround23	%f22, %f8, %f2, %f2
7581cb0ef41Sopenharmony_ci	aes_dround01	%f20, %f10, %f6, %f4
7591cb0ef41Sopenharmony_ci	aes_dround23	%f22, %f10, %f6, %f6
7601cb0ef41Sopenharmony_ci	ldd		[$key + 224], %f20
7611cb0ef41Sopenharmony_ci	ldd		[$key + 232], %f22
7621cb0ef41Sopenharmony_ci___
7631cb0ef41Sopenharmony_cifor ($i=1; $i<6; $i++) {
7641cb0ef41Sopenharmony_ci    $code.=<<___;
7651cb0ef41Sopenharmony_ci	aes_dround01	%f`16+8*$i+0`, %f0, %f2, %f8
7661cb0ef41Sopenharmony_ci	aes_dround23	%f`16+8*$i+2`, %f0, %f2, %f2
7671cb0ef41Sopenharmony_ci	aes_dround01	%f`16+8*$i+0`, %f4, %f6, %f10
7681cb0ef41Sopenharmony_ci	aes_dround23	%f`16+8*$i+2`, %f4, %f6, %f6
7691cb0ef41Sopenharmony_ci	aes_dround01	%f`16+8*$i+4`, %f8, %f2, %f0
7701cb0ef41Sopenharmony_ci	aes_dround23	%f`16+8*$i+6`, %f8, %f2, %f2
7711cb0ef41Sopenharmony_ci	aes_dround01	%f`16+8*$i+4`, %f10, %f6, %f4
7721cb0ef41Sopenharmony_ci	aes_dround23	%f`16+8*$i+6`, %f10, %f6, %f6
7731cb0ef41Sopenharmony_ci___
7741cb0ef41Sopenharmony_ci}
7751cb0ef41Sopenharmony_ci$code.=<<___;
7761cb0ef41Sopenharmony_ci	aes_dround01	%f16, %f0, %f2, %f8
7771cb0ef41Sopenharmony_ci	aes_dround23	%f18, %f0, %f2, %f2
7781cb0ef41Sopenharmony_ci	aes_dround01	%f16, %f4, %f6, %f10
7791cb0ef41Sopenharmony_ci	aes_dround23	%f18, %f4, %f6, %f6
7801cb0ef41Sopenharmony_ci	ldd		[$key + 16], %f16
7811cb0ef41Sopenharmony_ci	ldd		[$key + 24], %f18
7821cb0ef41Sopenharmony_ci	aes_dround01_l	%f20, %f8, %f2, %f0
7831cb0ef41Sopenharmony_ci	aes_dround23_l	%f22, %f8, %f2, %f2
7841cb0ef41Sopenharmony_ci	aes_dround01_l	%f20, %f10, %f6, %f4
7851cb0ef41Sopenharmony_ci	aes_dround23_l	%f22, %f10, %f6, %f6
7861cb0ef41Sopenharmony_ci	ldd		[$key + 32], %f20
7871cb0ef41Sopenharmony_ci	retl
7881cb0ef41Sopenharmony_ci	ldd		[$key + 40], %f22
7891cb0ef41Sopenharmony_ci.type	_aes256_decrypt_2x,#function
7901cb0ef41Sopenharmony_ci.size	_aes256_decrypt_2x,.-_aes256_decrypt_2x
7911cb0ef41Sopenharmony_ci
7921cb0ef41Sopenharmony_ci.align	32
7931cb0ef41Sopenharmony_ci_aes192_decrypt_1x:
7941cb0ef41Sopenharmony_ci___
7951cb0ef41Sopenharmony_cifor ($i=0; $i<5; $i++) {
7961cb0ef41Sopenharmony_ci    $code.=<<___;
7971cb0ef41Sopenharmony_ci	aes_dround01	%f`16+8*$i+0`, %f0, %f2, %f4
7981cb0ef41Sopenharmony_ci	aes_dround23	%f`16+8*$i+2`, %f0, %f2, %f2
7991cb0ef41Sopenharmony_ci	aes_dround01	%f`16+8*$i+4`, %f4, %f2, %f0
8001cb0ef41Sopenharmony_ci	aes_dround23	%f`16+8*$i+6`, %f4, %f2, %f2
8011cb0ef41Sopenharmony_ci___
8021cb0ef41Sopenharmony_ci}
8031cb0ef41Sopenharmony_ci$code.=<<___;
8041cb0ef41Sopenharmony_ci	aes_dround01	%f56, %f0, %f2, %f4
8051cb0ef41Sopenharmony_ci	aes_dround23	%f58, %f0, %f2, %f2
8061cb0ef41Sopenharmony_ci	aes_dround01_l	%f60, %f4, %f2, %f0
8071cb0ef41Sopenharmony_ci	retl
8081cb0ef41Sopenharmony_ci	aes_dround23_l	%f62, %f4, %f2, %f2
8091cb0ef41Sopenharmony_ci.type	_aes192_decrypt_1x,#function
8101cb0ef41Sopenharmony_ci.size	_aes192_decrypt_1x,.-_aes192_decrypt_1x
8111cb0ef41Sopenharmony_ci
8121cb0ef41Sopenharmony_ci.align	32
8131cb0ef41Sopenharmony_ci_aes192_decrypt_2x:
8141cb0ef41Sopenharmony_ci___
8151cb0ef41Sopenharmony_cifor ($i=0; $i<5; $i++) {
8161cb0ef41Sopenharmony_ci    $code.=<<___;
8171cb0ef41Sopenharmony_ci	aes_dround01	%f`16+8*$i+0`, %f0, %f2, %f8
8181cb0ef41Sopenharmony_ci	aes_dround23	%f`16+8*$i+2`, %f0, %f2, %f2
8191cb0ef41Sopenharmony_ci	aes_dround01	%f`16+8*$i+0`, %f4, %f6, %f10
8201cb0ef41Sopenharmony_ci	aes_dround23	%f`16+8*$i+2`, %f4, %f6, %f6
8211cb0ef41Sopenharmony_ci	aes_dround01	%f`16+8*$i+4`, %f8, %f2, %f0
8221cb0ef41Sopenharmony_ci	aes_dround23	%f`16+8*$i+6`, %f8, %f2, %f2
8231cb0ef41Sopenharmony_ci	aes_dround01	%f`16+8*$i+4`, %f10, %f6, %f4
8241cb0ef41Sopenharmony_ci	aes_dround23	%f`16+8*$i+6`, %f10, %f6, %f6
8251cb0ef41Sopenharmony_ci___
8261cb0ef41Sopenharmony_ci}
8271cb0ef41Sopenharmony_ci$code.=<<___;
8281cb0ef41Sopenharmony_ci	aes_dround01	%f56, %f0, %f2, %f8
8291cb0ef41Sopenharmony_ci	aes_dround23	%f58, %f0, %f2, %f2
8301cb0ef41Sopenharmony_ci	aes_dround01	%f56, %f4, %f6, %f10
8311cb0ef41Sopenharmony_ci	aes_dround23	%f58, %f4, %f6, %f6
8321cb0ef41Sopenharmony_ci	aes_dround01_l	%f60, %f8, %f2, %f0
8331cb0ef41Sopenharmony_ci	aes_dround23_l	%f62, %f8, %f2, %f2
8341cb0ef41Sopenharmony_ci	aes_dround01_l	%f60, %f10, %f6, %f4
8351cb0ef41Sopenharmony_ci	retl
8361cb0ef41Sopenharmony_ci	aes_dround23_l	%f62, %f10, %f6, %f6
8371cb0ef41Sopenharmony_ci.type	_aes192_decrypt_2x,#function
8381cb0ef41Sopenharmony_ci.size	_aes192_decrypt_2x,.-_aes192_decrypt_2x
8391cb0ef41Sopenharmony_ci___
8401cb0ef41Sopenharmony_ci}}}
8411cb0ef41Sopenharmony_ci
8421cb0ef41Sopenharmony_ciif (!$::evp) {
8431cb0ef41Sopenharmony_ci$code.=<<___;
8441cb0ef41Sopenharmony_ci.global	AES_encrypt
8451cb0ef41Sopenharmony_ciAES_encrypt=aes_t4_encrypt
8461cb0ef41Sopenharmony_ci.global	AES_decrypt
8471cb0ef41Sopenharmony_ciAES_decrypt=aes_t4_decrypt
8481cb0ef41Sopenharmony_ci.global	AES_set_encrypt_key
8491cb0ef41Sopenharmony_ci.align	32
8501cb0ef41Sopenharmony_ciAES_set_encrypt_key:
8511cb0ef41Sopenharmony_ci	andcc		%o2, 7, %g0		! check alignment
8521cb0ef41Sopenharmony_ci	bnz,a,pn	%icc, 1f
8531cb0ef41Sopenharmony_ci	mov		-1, %o0
8541cb0ef41Sopenharmony_ci	brz,a,pn	%o0, 1f
8551cb0ef41Sopenharmony_ci	mov		-1, %o0
8561cb0ef41Sopenharmony_ci	brz,a,pn	%o2, 1f
8571cb0ef41Sopenharmony_ci	mov		-1, %o0
8581cb0ef41Sopenharmony_ci	andncc		%o1, 0x1c0, %g0
8591cb0ef41Sopenharmony_ci	bnz,a,pn	%icc, 1f
8601cb0ef41Sopenharmony_ci	mov		-2, %o0
8611cb0ef41Sopenharmony_ci	cmp		%o1, 128
8621cb0ef41Sopenharmony_ci	bl,a,pn		%icc, 1f
8631cb0ef41Sopenharmony_ci	mov		-2, %o0
8641cb0ef41Sopenharmony_ci	b		aes_t4_set_encrypt_key
8651cb0ef41Sopenharmony_ci	nop
8661cb0ef41Sopenharmony_ci1:	retl
8671cb0ef41Sopenharmony_ci	nop
8681cb0ef41Sopenharmony_ci.type	AES_set_encrypt_key,#function
8691cb0ef41Sopenharmony_ci.size	AES_set_encrypt_key,.-AES_set_encrypt_key
8701cb0ef41Sopenharmony_ci
8711cb0ef41Sopenharmony_ci.global	AES_set_decrypt_key
8721cb0ef41Sopenharmony_ci.align	32
8731cb0ef41Sopenharmony_ciAES_set_decrypt_key:
8741cb0ef41Sopenharmony_ci	andcc		%o2, 7, %g0		! check alignment
8751cb0ef41Sopenharmony_ci	bnz,a,pn	%icc, 1f
8761cb0ef41Sopenharmony_ci	mov		-1, %o0
8771cb0ef41Sopenharmony_ci	brz,a,pn	%o0, 1f
8781cb0ef41Sopenharmony_ci	mov		-1, %o0
8791cb0ef41Sopenharmony_ci	brz,a,pn	%o2, 1f
8801cb0ef41Sopenharmony_ci	mov		-1, %o0
8811cb0ef41Sopenharmony_ci	andncc		%o1, 0x1c0, %g0
8821cb0ef41Sopenharmony_ci	bnz,a,pn	%icc, 1f
8831cb0ef41Sopenharmony_ci	mov		-2, %o0
8841cb0ef41Sopenharmony_ci	cmp		%o1, 128
8851cb0ef41Sopenharmony_ci	bl,a,pn		%icc, 1f
8861cb0ef41Sopenharmony_ci	mov		-2, %o0
8871cb0ef41Sopenharmony_ci	b		aes_t4_set_decrypt_key
8881cb0ef41Sopenharmony_ci	nop
8891cb0ef41Sopenharmony_ci1:	retl
8901cb0ef41Sopenharmony_ci	nop
8911cb0ef41Sopenharmony_ci.type	AES_set_decrypt_key,#function
8921cb0ef41Sopenharmony_ci.size	AES_set_decrypt_key,.-AES_set_decrypt_key
8931cb0ef41Sopenharmony_ci___
8941cb0ef41Sopenharmony_ci
8951cb0ef41Sopenharmony_cimy ($inp,$out,$len,$key,$ivec,$enc)=map("%o$_",(0..5));
8961cb0ef41Sopenharmony_ci
8971cb0ef41Sopenharmony_ci$code.=<<___;
8981cb0ef41Sopenharmony_ci.globl	AES_cbc_encrypt
8991cb0ef41Sopenharmony_ci.align	32
9001cb0ef41Sopenharmony_ciAES_cbc_encrypt:
9011cb0ef41Sopenharmony_ci	ld		[$key + 240], %g1
9021cb0ef41Sopenharmony_ci	nop
9031cb0ef41Sopenharmony_ci	brz		$enc, .Lcbc_decrypt
9041cb0ef41Sopenharmony_ci	cmp		%g1, 12
9051cb0ef41Sopenharmony_ci
9061cb0ef41Sopenharmony_ci	bl,pt		%icc, aes128_t4_cbc_encrypt
9071cb0ef41Sopenharmony_ci	nop
9081cb0ef41Sopenharmony_ci	be,pn		%icc, aes192_t4_cbc_encrypt
9091cb0ef41Sopenharmony_ci	nop
9101cb0ef41Sopenharmony_ci	ba		aes256_t4_cbc_encrypt
9111cb0ef41Sopenharmony_ci	nop
9121cb0ef41Sopenharmony_ci
9131cb0ef41Sopenharmony_ci.Lcbc_decrypt:
9141cb0ef41Sopenharmony_ci	bl,pt		%icc, aes128_t4_cbc_decrypt
9151cb0ef41Sopenharmony_ci	nop
9161cb0ef41Sopenharmony_ci	be,pn		%icc, aes192_t4_cbc_decrypt
9171cb0ef41Sopenharmony_ci	nop
9181cb0ef41Sopenharmony_ci	ba		aes256_t4_cbc_decrypt
9191cb0ef41Sopenharmony_ci	nop
9201cb0ef41Sopenharmony_ci.type	AES_cbc_encrypt,#function
9211cb0ef41Sopenharmony_ci.size	AES_cbc_encrypt,.-AES_cbc_encrypt
9221cb0ef41Sopenharmony_ci___
9231cb0ef41Sopenharmony_ci}
9241cb0ef41Sopenharmony_ci$code.=<<___;
9251cb0ef41Sopenharmony_ci.asciz	"AES for SPARC T4, David S. Miller, Andy Polyakov"
9261cb0ef41Sopenharmony_ci.align	4
9271cb0ef41Sopenharmony_ci___
9281cb0ef41Sopenharmony_ci
9291cb0ef41Sopenharmony_ci&emit_assembler();
9301cb0ef41Sopenharmony_ci
9311cb0ef41Sopenharmony_ciclose STDOUT or die "error closing STDOUT: $!";
932