Blame SOURCES/openssl-1.0.2k-ppc-update.patch

e62613
diff -up openssl-1.0.2k/crypto/aes/asm/aesp8-ppc.pl.ppc-update openssl-1.0.2k/crypto/aes/asm/aesp8-ppc.pl
e62613
--- openssl-1.0.2k/crypto/aes/asm/aesp8-ppc.pl.ppc-update	2017-01-26 14:22:03.000000000 +0100
e62613
+++ openssl-1.0.2k/crypto/aes/asm/aesp8-ppc.pl	2017-04-13 09:51:40.611133165 +0200
e62613
@@ -20,6 +20,19 @@
e62613
 # instructions are interleaved. It's reckoned that eventual
e62613
 # misalignment penalties at page boundaries are in average lower
e62613
 # than additional overhead in pure AltiVec approach.
e62613
+#
e62613
+# May 2016
e62613
+#
e62613
+# Add XTS subroutine, 9x on little- and 12x improvement on big-endian
e62613
+# systems were measured.
e62613
+#
e62613
+######################################################################
e62613
+# Current large-block performance in cycles per byte processed with
e62613
+# 128-bit key (less is better).
e62613
+#
e62613
+#		CBC en-/decrypt	CTR	XTS
e62613
+# POWER8[le]	3.96/0.72	0.74	1.1
e62613
+# POWER8[be]	3.75/0.65	0.66	1.0
e62613
 
e62613
 $flavour = shift;
e62613
 
e62613
@@ -486,6 +499,8 @@ $code.=<<___;
e62613
 .globl	.${prefix}_cbc_encrypt
e62613
 .align	5
e62613
 .${prefix}_cbc_encrypt:
e62613
+	li		$idx,15
e62613
+	andc		$len,$len,$idx
e62613
 	${UCMP}i	$len,16
e62613
 	bltlr-
e62613
 
e62613
@@ -494,7 +509,6 @@ $code.=<<___;
e62613
 	mfspr		$vrsave,256
e62613
 	mtspr		256,r0
e62613
 
e62613
-	li		$idx,15
e62613
 	vxor		$rndkey0,$rndkey0,$rndkey0
e62613
 	le?vspltisb	$tmp,0x0f
e62613
 
e62613
@@ -1887,6 +1901,1849 @@ Lctr32_enc8x_done:
e62613
 ___
e62613
 }}	}}}
e62613
 
e62613
+#########################################################################
e62613
+{{{	# XTS procedures						#
e62613
+# int aes_p8_xts_[en|de]crypt(const char *inp, char *out, size_t len,	#
e62613
+#                             const AES_KEY *key1, const AES_KEY *key2,	#
e62613
+#                             [const] unsigned char iv[16]);		#
e62613
+# If $key2 is NULL, then a "tweak chaining" mode is engaged, in which	#
e62613
+# input tweak value is assumed to be encrypted already, and last tweak	#
e62613
+# value, one suitable for consecutive call on same chunk of data, is	#
e62613
+# written back to original buffer. In addition, in "tweak chaining"	#
e62613
+# mode only complete input blocks are processed.			#
e62613
+
e62613
+my ($inp,$out,$len,$key1,$key2,$ivp,$rounds,$idx) =	map("r$_",(3..10));
e62613
+my ($rndkey0,$rndkey1,$inout) =				map("v$_",(0..2));
e62613
+my ($output,$inptail,$inpperm,$leperm,$keyperm) =	map("v$_",(3..7));
e62613
+my ($tweak,$seven,$eighty7,$tmp,$tweak1) =		map("v$_",(8..12));
e62613
+my $taillen = $key2;
e62613
+
e62613
+   ($inp,$idx) = ($idx,$inp);				# reassign
e62613
+
e62613
+$code.=<<___;
e62613
+.globl	.${prefix}_xts_encrypt
e62613
+.align	5
e62613
+.${prefix}_xts_encrypt:
e62613
+	mr		$inp,r3				# reassign
e62613
+	li		r3,-1
e62613
+	${UCMP}i	$len,16
e62613
+	bltlr-
e62613
+
e62613
+	lis		r0,0xfff0
e62613
+	mfspr		r12,256				# save vrsave
e62613
+	li		r11,0
e62613
+	mtspr		256,r0
e62613
+
e62613
+	vspltisb	$seven,0x07			# 0x070707..07
e62613
+	le?lvsl		$leperm,r11,r11
e62613
+	le?vspltisb	$tmp,0x0f
e62613
+	le?vxor		$leperm,$leperm,$seven
e62613
+
e62613
+	li		$idx,15
e62613
+	lvx		$tweak,0,$ivp			# load [unaligned] iv
e62613
+	lvsl		$inpperm,0,$ivp
e62613
+	lvx		$inptail,$idx,$ivp
e62613
+	le?vxor		$inpperm,$inpperm,$tmp
e62613
+	vperm		$tweak,$tweak,$inptail,$inpperm
e62613
+
e62613
+	neg		r11,$inp
e62613
+	lvsr		$inpperm,0,r11			# prepare for unaligned load
e62613
+	lvx		$inout,0,$inp
e62613
+	addi		$inp,$inp,15			# 15 is not typo
e62613
+	le?vxor		$inpperm,$inpperm,$tmp
e62613
+
e62613
+	${UCMP}i	$key2,0				# key2==NULL?
e62613
+	beq		Lxts_enc_no_key2
e62613
+
e62613
+	?lvsl		$keyperm,0,$key2		# prepare for unaligned key
e62613
+	lwz		$rounds,240($key2)
e62613
+	srwi		$rounds,$rounds,1
e62613
+	subi		$rounds,$rounds,1
e62613
+	li		$idx,16
e62613
+
e62613
+	lvx		$rndkey0,0,$key2
e62613
+	lvx		$rndkey1,$idx,$key2
e62613
+	addi		$idx,$idx,16
e62613
+	?vperm		$rndkey0,$rndkey0,$rndkey1,$keyperm
e62613
+	vxor		$tweak,$tweak,$rndkey0
e62613
+	lvx		$rndkey0,$idx,$key2
e62613
+	addi		$idx,$idx,16
e62613
+	mtctr		$rounds
e62613
+
e62613
+Ltweak_xts_enc:
e62613
+	?vperm		$rndkey1,$rndkey1,$rndkey0,$keyperm
e62613
+	vcipher		$tweak,$tweak,$rndkey1
e62613
+	lvx		$rndkey1,$idx,$key2
e62613
+	addi		$idx,$idx,16
e62613
+	?vperm		$rndkey0,$rndkey0,$rndkey1,$keyperm
e62613
+	vcipher		$tweak,$tweak,$rndkey0
e62613
+	lvx		$rndkey0,$idx,$key2
e62613
+	addi		$idx,$idx,16
e62613
+	bdnz		Ltweak_xts_enc
e62613
+
e62613
+	?vperm		$rndkey1,$rndkey1,$rndkey0,$keyperm
e62613
+	vcipher		$tweak,$tweak,$rndkey1
e62613
+	lvx		$rndkey1,$idx,$key2
e62613
+	?vperm		$rndkey0,$rndkey0,$rndkey1,$keyperm
e62613
+	vcipherlast	$tweak,$tweak,$rndkey0
e62613
+
e62613
+	li		$ivp,0				# don't chain the tweak
e62613
+	b		Lxts_enc
e62613
+
e62613
+Lxts_enc_no_key2:
e62613
+	li		$idx,-16
e62613
+	and		$len,$len,$idx			# in "tweak chaining"
e62613
+							# mode only complete
e62613
+							# blocks are processed
e62613
+Lxts_enc:
e62613
+	lvx		$inptail,0,$inp
e62613
+	addi		$inp,$inp,16
e62613
+
e62613
+	?lvsl		$keyperm,0,$key1		# prepare for unaligned key
e62613
+	lwz		$rounds,240($key1)
e62613
+	srwi		$rounds,$rounds,1
e62613
+	subi		$rounds,$rounds,1
e62613
+	li		$idx,16
e62613
+
e62613
+	vslb		$eighty7,$seven,$seven		# 0x808080..80
e62613
+	vor		$eighty7,$eighty7,$seven	# 0x878787..87
e62613
+	vspltisb	$tmp,1				# 0x010101..01
e62613
+	vsldoi		$eighty7,$eighty7,$tmp,15	# 0x870101..01
e62613
+
e62613
+	${UCMP}i	$len,96
e62613
+	bge		_aesp8_xts_encrypt6x
e62613
+
e62613
+	andi.		$taillen,$len,15
e62613
+	subic		r0,$len,32
e62613
+	subi		$taillen,$taillen,16
e62613
+	subfe		r0,r0,r0
e62613
+	and		r0,r0,$taillen
e62613
+	add		$inp,$inp,r0
e62613
+
e62613
+	lvx		$rndkey0,0,$key1
e62613
+	lvx		$rndkey1,$idx,$key1
e62613
+	addi		$idx,$idx,16
e62613
+	vperm		$inout,$inout,$inptail,$inpperm
e62613
+	?vperm		$rndkey0,$rndkey0,$rndkey1,$keyperm
e62613
+	vxor		$inout,$inout,$tweak
e62613
+	vxor		$inout,$inout,$rndkey0
e62613
+	lvx		$rndkey0,$idx,$key1
e62613
+	addi		$idx,$idx,16
e62613
+	mtctr		$rounds
e62613
+	b		Loop_xts_enc
e62613
+
e62613
+.align	5
e62613
+Loop_xts_enc:
e62613
+	?vperm		$rndkey1,$rndkey1,$rndkey0,$keyperm
e62613
+	vcipher		$inout,$inout,$rndkey1
e62613
+	lvx		$rndkey1,$idx,$key1
e62613
+	addi		$idx,$idx,16
e62613
+	?vperm		$rndkey0,$rndkey0,$rndkey1,$keyperm
e62613
+	vcipher		$inout,$inout,$rndkey0
e62613
+	lvx		$rndkey0,$idx,$key1
e62613
+	addi		$idx,$idx,16
e62613
+	bdnz		Loop_xts_enc
e62613
+
e62613
+	?vperm		$rndkey1,$rndkey1,$rndkey0,$keyperm
e62613
+	vcipher		$inout,$inout,$rndkey1
e62613
+	lvx		$rndkey1,$idx,$key1
e62613
+	li		$idx,16
e62613
+	?vperm		$rndkey0,$rndkey0,$rndkey1,$keyperm
e62613
+	vxor		$rndkey0,$rndkey0,$tweak
e62613
+	vcipherlast	$output,$inout,$rndkey0
e62613
+
e62613
+	le?vperm	$tmp,$output,$output,$leperm
e62613
+	be?nop
e62613
+	le?stvx_u	$tmp,0,$out
e62613
+	be?stvx_u	$output,0,$out
e62613
+	addi		$out,$out,16
e62613
+
e62613
+	subic.		$len,$len,16
e62613
+	beq		Lxts_enc_done
e62613
+
e62613
+	vmr		$inout,$inptail
e62613
+	lvx		$inptail,0,$inp
e62613
+	addi		$inp,$inp,16
e62613
+	lvx		$rndkey0,0,$key1
e62613
+	lvx		$rndkey1,$idx,$key1
e62613
+	addi		$idx,$idx,16
e62613
+
e62613
+	subic		r0,$len,32
e62613
+	subfe		r0,r0,r0
e62613
+	and		r0,r0,$taillen
e62613
+	add		$inp,$inp,r0
e62613
+
e62613
+	vsrab		$tmp,$tweak,$seven		# next tweak value
e62613
+	vaddubm		$tweak,$tweak,$tweak
e62613
+	vsldoi		$tmp,$tmp,$tmp,15
e62613
+	vand		$tmp,$tmp,$eighty7
e62613
+	vxor		$tweak,$tweak,$tmp
e62613
+
e62613
+	vperm		$inout,$inout,$inptail,$inpperm
e62613
+	?vperm		$rndkey0,$rndkey0,$rndkey1,$keyperm
e62613
+	vxor		$inout,$inout,$tweak
e62613
+	vxor		$output,$output,$rndkey0	# just in case $len<16
e62613
+	vxor		$inout,$inout,$rndkey0
e62613
+	lvx		$rndkey0,$idx,$key1
e62613
+	addi		$idx,$idx,16
e62613
+
e62613
+	mtctr		$rounds
e62613
+	${UCMP}i	$len,16
e62613
+	bge		Loop_xts_enc
e62613
+
e62613
+	vxor		$output,$output,$tweak
e62613
+	lvsr		$inpperm,0,$len			# $inpperm is no longer needed
e62613
+	vxor		$inptail,$inptail,$inptail	# $inptail is no longer needed
e62613
+	vspltisb	$tmp,-1
e62613
+	vperm		$inptail,$inptail,$tmp,$inpperm
e62613
+	vsel		$inout,$inout,$output,$inptail
e62613
+
e62613
+	subi		r11,$out,17
e62613
+	subi		$out,$out,16
e62613
+	mtctr		$len
e62613
+	li		$len,16
e62613
+Loop_xts_enc_steal:
e62613
+	lbzu		r0,1(r11)
e62613
+	stb		r0,16(r11)
e62613
+	bdnz		Loop_xts_enc_steal
e62613
+
e62613
+	mtctr		$rounds
e62613
+	b		Loop_xts_enc			# one more time...
e62613
+
e62613
+Lxts_enc_done:
e62613
+	${UCMP}i	$ivp,0
e62613
+	beq		Lxts_enc_ret
e62613
+
e62613
+	vsrab		$tmp,$tweak,$seven		# next tweak value
e62613
+	vaddubm		$tweak,$tweak,$tweak
e62613
+	vsldoi		$tmp,$tmp,$tmp,15
e62613
+	vand		$tmp,$tmp,$eighty7
e62613
+	vxor		$tweak,$tweak,$tmp
e62613
+
e62613
+	le?vperm	$tweak,$tweak,$tweak,$leperm
e62613
+	stvx_u		$tweak,0,$ivp
e62613
+
e62613
+Lxts_enc_ret:
e62613
+	mtspr		256,r12				# restore vrsave
e62613
+	li		r3,0
e62613
+	blr
e62613
+	.long		0
e62613
+	.byte		0,12,0x04,0,0x80,6,6,0
e62613
+	.long		0
e62613
+.size	.${prefix}_xts_encrypt,.-.${prefix}_xts_encrypt
e62613
+
e62613
+.globl	.${prefix}_xts_decrypt
e62613
+.align	5
e62613
+.${prefix}_xts_decrypt:
e62613
+	mr		$inp,r3				# reassign
e62613
+	li		r3,-1
e62613
+	${UCMP}i	$len,16
e62613
+	bltlr-
e62613
+
e62613
+	lis		r0,0xfff8
e62613
+	mfspr		r12,256				# save vrsave
e62613
+	li		r11,0
e62613
+	mtspr		256,r0
e62613
+
e62613
+	andi.		r0,$len,15
e62613
+	neg		r0,r0
e62613
+	andi.		r0,r0,16
e62613
+	sub		$len,$len,r0
e62613
+
e62613
+	vspltisb	$seven,0x07			# 0x070707..07
e62613
+	le?lvsl		$leperm,r11,r11
e62613
+	le?vspltisb	$tmp,0x0f
e62613
+	le?vxor		$leperm,$leperm,$seven
e62613
+
e62613
+	li		$idx,15
e62613
+	lvx		$tweak,0,$ivp			# load [unaligned] iv
e62613
+	lvsl		$inpperm,0,$ivp
e62613
+	lvx		$inptail,$idx,$ivp
e62613
+	le?vxor		$inpperm,$inpperm,$tmp
e62613
+	vperm		$tweak,$tweak,$inptail,$inpperm
e62613
+
e62613
+	neg		r11,$inp
e62613
+	lvsr		$inpperm,0,r11			# prepare for unaligned load
e62613
+	lvx		$inout,0,$inp
e62613
+	addi		$inp,$inp,15			# 15 is not typo
e62613
+	le?vxor		$inpperm,$inpperm,$tmp
e62613
+
e62613
+	${UCMP}i	$key2,0				# key2==NULL?
e62613
+	beq		Lxts_dec_no_key2
e62613
+
e62613
+	?lvsl		$keyperm,0,$key2		# prepare for unaligned key
e62613
+	lwz		$rounds,240($key2)
e62613
+	srwi		$rounds,$rounds,1
e62613
+	subi		$rounds,$rounds,1
e62613
+	li		$idx,16
e62613
+
e62613
+	lvx		$rndkey0,0,$key2
e62613
+	lvx		$rndkey1,$idx,$key2
e62613
+	addi		$idx,$idx,16
e62613
+	?vperm		$rndkey0,$rndkey0,$rndkey1,$keyperm
e62613
+	vxor		$tweak,$tweak,$rndkey0
e62613
+	lvx		$rndkey0,$idx,$key2
e62613
+	addi		$idx,$idx,16
e62613
+	mtctr		$rounds
e62613
+
e62613
+Ltweak_xts_dec:
e62613
+	?vperm		$rndkey1,$rndkey1,$rndkey0,$keyperm
e62613
+	vcipher		$tweak,$tweak,$rndkey1
e62613
+	lvx		$rndkey1,$idx,$key2
e62613
+	addi		$idx,$idx,16
e62613
+	?vperm		$rndkey0,$rndkey0,$rndkey1,$keyperm
e62613
+	vcipher		$tweak,$tweak,$rndkey0
e62613
+	lvx		$rndkey0,$idx,$key2
e62613
+	addi		$idx,$idx,16
e62613
+	bdnz		Ltweak_xts_dec
e62613
+
e62613
+	?vperm		$rndkey1,$rndkey1,$rndkey0,$keyperm
e62613
+	vcipher		$tweak,$tweak,$rndkey1
e62613
+	lvx		$rndkey1,$idx,$key2
e62613
+	?vperm		$rndkey0,$rndkey0,$rndkey1,$keyperm
e62613
+	vcipherlast	$tweak,$tweak,$rndkey0
e62613
+
e62613
+	li		$ivp,0				# don't chain the tweak
e62613
+	b		Lxts_dec
e62613
+
e62613
+Lxts_dec_no_key2:
e62613
+	neg		$idx,$len
e62613
+	andi.		$idx,$idx,15
e62613
+	add		$len,$len,$idx			# in "tweak chaining"
e62613
+							# mode only complete
e62613
+							# blocks are processed
e62613
+Lxts_dec:
e62613
+	lvx		$inptail,0,$inp
e62613
+	addi		$inp,$inp,16
e62613
+
e62613
+	?lvsl		$keyperm,0,$key1		# prepare for unaligned key
e62613
+	lwz		$rounds,240($key1)
e62613
+	srwi		$rounds,$rounds,1
e62613
+	subi		$rounds,$rounds,1
e62613
+	li		$idx,16
e62613
+
e62613
+	vslb		$eighty7,$seven,$seven		# 0x808080..80
e62613
+	vor		$eighty7,$eighty7,$seven	# 0x878787..87
e62613
+	vspltisb	$tmp,1				# 0x010101..01
e62613
+	vsldoi		$eighty7,$eighty7,$tmp,15	# 0x870101..01
e62613
+
e62613
+	${UCMP}i	$len,96
e62613
+	bge		_aesp8_xts_decrypt6x
e62613
+
e62613
+	lvx		$rndkey0,0,$key1
e62613
+	lvx		$rndkey1,$idx,$key1
e62613
+	addi		$idx,$idx,16
e62613
+	vperm		$inout,$inout,$inptail,$inpperm
e62613
+	?vperm		$rndkey0,$rndkey0,$rndkey1,$keyperm
e62613
+	vxor		$inout,$inout,$tweak
e62613
+	vxor		$inout,$inout,$rndkey0
e62613
+	lvx		$rndkey0,$idx,$key1
e62613
+	addi		$idx,$idx,16
e62613
+	mtctr		$rounds
e62613
+
e62613
+	${UCMP}i	$len,16
e62613
+	blt		Ltail_xts_dec
e62613
+	be?b		Loop_xts_dec
e62613
+
e62613
+.align	5
e62613
+Loop_xts_dec:
e62613
+	?vperm		$rndkey1,$rndkey1,$rndkey0,$keyperm
e62613
+	vncipher	$inout,$inout,$rndkey1
e62613
+	lvx		$rndkey1,$idx,$key1
e62613
+	addi		$idx,$idx,16
e62613
+	?vperm		$rndkey0,$rndkey0,$rndkey1,$keyperm
e62613
+	vncipher	$inout,$inout,$rndkey0
e62613
+	lvx		$rndkey0,$idx,$key1
e62613
+	addi		$idx,$idx,16
e62613
+	bdnz		Loop_xts_dec
e62613
+
e62613
+	?vperm		$rndkey1,$rndkey1,$rndkey0,$keyperm
e62613
+	vncipher	$inout,$inout,$rndkey1
e62613
+	lvx		$rndkey1,$idx,$key1
e62613
+	li		$idx,16
e62613
+	?vperm		$rndkey0,$rndkey0,$rndkey1,$keyperm
e62613
+	vxor		$rndkey0,$rndkey0,$tweak
e62613
+	vncipherlast	$output,$inout,$rndkey0
e62613
+
e62613
+	le?vperm	$tmp,$output,$output,$leperm
e62613
+	be?nop
e62613
+	le?stvx_u	$tmp,0,$out
e62613
+	be?stvx_u	$output,0,$out
e62613
+	addi		$out,$out,16
e62613
+
e62613
+	subic.		$len,$len,16
e62613
+	beq		Lxts_dec_done
e62613
+
e62613
+	vmr		$inout,$inptail
e62613
+	lvx		$inptail,0,$inp
e62613
+	addi		$inp,$inp,16
e62613
+	lvx		$rndkey0,0,$key1
e62613
+	lvx		$rndkey1,$idx,$key1
e62613
+	addi		$idx,$idx,16
e62613
+
e62613
+	vsrab		$tmp,$tweak,$seven		# next tweak value
e62613
+	vaddubm		$tweak,$tweak,$tweak
e62613
+	vsldoi		$tmp,$tmp,$tmp,15
e62613
+	vand		$tmp,$tmp,$eighty7
e62613
+	vxor		$tweak,$tweak,$tmp
e62613
+
e62613
+	vperm		$inout,$inout,$inptail,$inpperm
e62613
+	?vperm		$rndkey0,$rndkey0,$rndkey1,$keyperm
e62613
+	vxor		$inout,$inout,$tweak
e62613
+	vxor		$inout,$inout,$rndkey0
e62613
+	lvx		$rndkey0,$idx,$key1
e62613
+	addi		$idx,$idx,16
e62613
+
e62613
+	mtctr		$rounds
e62613
+	${UCMP}i	$len,16
e62613
+	bge		Loop_xts_dec
e62613
+
e62613
+Ltail_xts_dec:
e62613
+	vsrab		$tmp,$tweak,$seven		# next tweak value
e62613
+	vaddubm		$tweak1,$tweak,$tweak
e62613
+	vsldoi		$tmp,$tmp,$tmp,15
e62613
+	vand		$tmp,$tmp,$eighty7
e62613
+	vxor		$tweak1,$tweak1,$tmp
e62613
+
e62613
+	subi		$inp,$inp,16
e62613
+	add		$inp,$inp,$len
e62613
+
e62613
+	vxor		$inout,$inout,$tweak		# :-(
e62613
+	vxor		$inout,$inout,$tweak1		# :-)
e62613
+
e62613
+Loop_xts_dec_short:
e62613
+	?vperm		$rndkey1,$rndkey1,$rndkey0,$keyperm
e62613
+	vncipher	$inout,$inout,$rndkey1
e62613
+	lvx		$rndkey1,$idx,$key1
e62613
+	addi		$idx,$idx,16
e62613
+	?vperm		$rndkey0,$rndkey0,$rndkey1,$keyperm
e62613
+	vncipher	$inout,$inout,$rndkey0
e62613
+	lvx		$rndkey0,$idx,$key1
e62613
+	addi		$idx,$idx,16
e62613
+	bdnz		Loop_xts_dec_short
e62613
+
e62613
+	?vperm		$rndkey1,$rndkey1,$rndkey0,$keyperm
e62613
+	vncipher	$inout,$inout,$rndkey1
e62613
+	lvx		$rndkey1,$idx,$key1
e62613
+	li		$idx,16
e62613
+	?vperm		$rndkey0,$rndkey0,$rndkey1,$keyperm
e62613
+	vxor		$rndkey0,$rndkey0,$tweak1
e62613
+	vncipherlast	$output,$inout,$rndkey0
e62613
+
e62613
+	le?vperm	$tmp,$output,$output,$leperm
e62613
+	be?nop
e62613
+	le?stvx_u	$tmp,0,$out
e62613
+	be?stvx_u	$output,0,$out
e62613
+
e62613
+	vmr		$inout,$inptail
e62613
+	lvx		$inptail,0,$inp
e62613
+	#addi		$inp,$inp,16
e62613
+	lvx		$rndkey0,0,$key1
e62613
+	lvx		$rndkey1,$idx,$key1
e62613
+	addi		$idx,$idx,16
e62613
+	vperm		$inout,$inout,$inptail,$inpperm
e62613
+	?vperm		$rndkey0,$rndkey0,$rndkey1,$keyperm
e62613
+
e62613
+	lvsr		$inpperm,0,$len			# $inpperm is no longer needed
e62613
+	vxor		$inptail,$inptail,$inptail	# $inptail is no longer needed
e62613
+	vspltisb	$tmp,-1
e62613
+	vperm		$inptail,$inptail,$tmp,$inpperm
e62613
+	vsel		$inout,$inout,$output,$inptail
e62613
+
e62613
+	vxor		$rndkey0,$rndkey0,$tweak
e62613
+	vxor		$inout,$inout,$rndkey0
e62613
+	lvx		$rndkey0,$idx,$key1
e62613
+	addi		$idx,$idx,16
e62613
+
e62613
+	subi		r11,$out,1
e62613
+	mtctr		$len
e62613
+	li		$len,16
e62613
+Loop_xts_dec_steal:
e62613
+	lbzu		r0,1(r11)
e62613
+	stb		r0,16(r11)
e62613
+	bdnz		Loop_xts_dec_steal
e62613
+
e62613
+	mtctr		$rounds
e62613
+	b		Loop_xts_dec			# one more time...
e62613
+
e62613
+Lxts_dec_done:
e62613
+	${UCMP}i	$ivp,0
e62613
+	beq		Lxts_dec_ret
e62613
+
e62613
+	vsrab		$tmp,$tweak,$seven		# next tweak value
e62613
+	vaddubm		$tweak,$tweak,$tweak
e62613
+	vsldoi		$tmp,$tmp,$tmp,15
e62613
+	vand		$tmp,$tmp,$eighty7
e62613
+	vxor		$tweak,$tweak,$tmp
e62613
+
e62613
+	le?vperm	$tweak,$tweak,$tweak,$leperm
e62613
+	stvx_u		$tweak,0,$ivp
e62613
+
e62613
+Lxts_dec_ret:
e62613
+	mtspr		256,r12				# restore vrsave
e62613
+	li		r3,0
e62613
+	blr
e62613
+	.long		0
e62613
+	.byte		0,12,0x04,0,0x80,6,6,0
e62613
+	.long		0
e62613
+.size	.${prefix}_xts_decrypt,.-.${prefix}_xts_decrypt
e62613
+___
e62613
+#########################################################################
e62613
+{{	# Optimized XTS procedures					#
e62613
+my $key_=$key2;
e62613
+my ($x00,$x10,$x20,$x30,$x40,$x50,$x60,$x70)=map("r$_",(0,3,26..31));
e62613
+    $x00=0 if ($flavour =~ /osx/);
e62613
+my ($in0,  $in1,  $in2,  $in3,  $in4,  $in5 )=map("v$_",(0..5));
e62613
+my ($out0, $out1, $out2, $out3, $out4, $out5)=map("v$_",(7,12..16));
e62613
+my ($twk0, $twk1, $twk2, $twk3, $twk4, $twk5)=map("v$_",(17..22));
e62613
+my $rndkey0="v23";	# v24-v25 rotating buffer for first found keys
e62613
+			# v26-v31 last 6 round keys
e62613
+my ($keyperm)=($out0);	# aliases with "caller", redundant assignment
e62613
+my $taillen=$x70;
e62613
+
e62613
+$code.=<<___;
e62613
+.align	5
e62613
+_aesp8_xts_encrypt6x:
e62613
+	$STU		$sp,-`($FRAME+21*16+6*$SIZE_T)`($sp)
e62613
+	mflr		r11
e62613
+	li		r7,`$FRAME+8*16+15`
e62613
+	li		r3,`$FRAME+8*16+31`
e62613
+	$PUSH		r11,`$FRAME+21*16+6*$SIZE_T+$LRSAVE`($sp)
e62613
+	stvx		v20,r7,$sp		# ABI says so
e62613
+	addi		r7,r7,32
e62613
+	stvx		v21,r3,$sp
e62613
+	addi		r3,r3,32
e62613
+	stvx		v22,r7,$sp
e62613
+	addi		r7,r7,32
e62613
+	stvx		v23,r3,$sp
e62613
+	addi		r3,r3,32
e62613
+	stvx		v24,r7,$sp
e62613
+	addi		r7,r7,32
e62613
+	stvx		v25,r3,$sp
e62613
+	addi		r3,r3,32
e62613
+	stvx		v26,r7,$sp
e62613
+	addi		r7,r7,32
e62613
+	stvx		v27,r3,$sp
e62613
+	addi		r3,r3,32
e62613
+	stvx		v28,r7,$sp
e62613
+	addi		r7,r7,32
e62613
+	stvx		v29,r3,$sp
e62613
+	addi		r3,r3,32
e62613
+	stvx		v30,r7,$sp
e62613
+	stvx		v31,r3,$sp
e62613
+	li		r0,-1
e62613
+	stw		$vrsave,`$FRAME+21*16-4`($sp)	# save vrsave
e62613
+	li		$x10,0x10
e62613
+	$PUSH		r26,`$FRAME+21*16+0*$SIZE_T`($sp)
e62613
+	li		$x20,0x20
e62613
+	$PUSH		r27,`$FRAME+21*16+1*$SIZE_T`($sp)
e62613
+	li		$x30,0x30
e62613
+	$PUSH		r28,`$FRAME+21*16+2*$SIZE_T`($sp)
e62613
+	li		$x40,0x40
e62613
+	$PUSH		r29,`$FRAME+21*16+3*$SIZE_T`($sp)
e62613
+	li		$x50,0x50
e62613
+	$PUSH		r30,`$FRAME+21*16+4*$SIZE_T`($sp)
e62613
+	li		$x60,0x60
e62613
+	$PUSH		r31,`$FRAME+21*16+5*$SIZE_T`($sp)
e62613
+	li		$x70,0x70
e62613
+	mtspr		256,r0
e62613
+
e62613
+	subi		$rounds,$rounds,3	# -4 in total
e62613
+
e62613
+	lvx		$rndkey0,$x00,$key1	# load key schedule
e62613
+	lvx		v30,$x10,$key1
e62613
+	addi		$key1,$key1,0x20
e62613
+	lvx		v31,$x00,$key1
e62613
+	?vperm		$rndkey0,$rndkey0,v30,$keyperm
e62613
+	addi		$key_,$sp,$FRAME+15
e62613
+	mtctr		$rounds
e62613
+
e62613
+Load_xts_enc_key:
e62613
+	?vperm		v24,v30,v31,$keyperm
e62613
+	lvx		v30,$x10,$key1
e62613
+	addi		$key1,$key1,0x20
e62613
+	stvx		v24,$x00,$key_		# off-load round[1]
e62613
+	?vperm		v25,v31,v30,$keyperm
e62613
+	lvx		v31,$x00,$key1
e62613
+	stvx		v25,$x10,$key_		# off-load round[2]
e62613
+	addi		$key_,$key_,0x20
e62613
+	bdnz		Load_xts_enc_key
e62613
+
e62613
+	lvx		v26,$x10,$key1
e62613
+	?vperm		v24,v30,v31,$keyperm
e62613
+	lvx		v27,$x20,$key1
e62613
+	stvx		v24,$x00,$key_		# off-load round[3]
e62613
+	?vperm		v25,v31,v26,$keyperm
e62613
+	lvx		v28,$x30,$key1
e62613
+	stvx		v25,$x10,$key_		# off-load round[4]
e62613
+	addi		$key_,$sp,$FRAME+15	# rewind $key_
e62613
+	?vperm		v26,v26,v27,$keyperm
e62613
+	lvx		v29,$x40,$key1
e62613
+	?vperm		v27,v27,v28,$keyperm
e62613
+	lvx		v30,$x50,$key1
e62613
+	?vperm		v28,v28,v29,$keyperm
e62613
+	lvx		v31,$x60,$key1
e62613
+	?vperm		v29,v29,v30,$keyperm
e62613
+	lvx		$twk5,$x70,$key1	# borrow $twk5
e62613
+	?vperm		v30,v30,v31,$keyperm
e62613
+	lvx		v24,$x00,$key_		# pre-load round[1]
e62613
+	?vperm		v31,v31,$twk5,$keyperm
e62613
+	lvx		v25,$x10,$key_		# pre-load round[2]
e62613
+
e62613
+	 vperm		$in0,$inout,$inptail,$inpperm
e62613
+	 subi		$inp,$inp,31		# undo "caller"
e62613
+	vxor		$twk0,$tweak,$rndkey0
e62613
+	vsrab		$tmp,$tweak,$seven	# next tweak value
e62613
+	vaddubm		$tweak,$tweak,$tweak
e62613
+	vsldoi		$tmp,$tmp,$tmp,15
e62613
+	vand		$tmp,$tmp,$eighty7
e62613
+	 vxor		$out0,$in0,$twk0
e62613
+	vxor		$tweak,$tweak,$tmp
e62613
+
e62613
+	 lvx_u		$in1,$x10,$inp
e62613
+	vxor		$twk1,$tweak,$rndkey0
e62613
+	vsrab		$tmp,$tweak,$seven	# next tweak value
e62613
+	vaddubm		$tweak,$tweak,$tweak
e62613
+	vsldoi		$tmp,$tmp,$tmp,15
e62613
+	 le?vperm	$in1,$in1,$in1,$leperm
e62613
+	vand		$tmp,$tmp,$eighty7
e62613
+	 vxor		$out1,$in1,$twk1
e62613
+	vxor		$tweak,$tweak,$tmp
e62613
+
e62613
+	 lvx_u		$in2,$x20,$inp
e62613
+	 andi.		$taillen,$len,15
e62613
+	vxor		$twk2,$tweak,$rndkey0
e62613
+	vsrab		$tmp,$tweak,$seven	# next tweak value
e62613
+	vaddubm		$tweak,$tweak,$tweak
e62613
+	vsldoi		$tmp,$tmp,$tmp,15
e62613
+	 le?vperm	$in2,$in2,$in2,$leperm
e62613
+	vand		$tmp,$tmp,$eighty7
e62613
+	 vxor		$out2,$in2,$twk2
e62613
+	vxor		$tweak,$tweak,$tmp
e62613
+
e62613
+	 lvx_u		$in3,$x30,$inp
e62613
+	 sub		$len,$len,$taillen
e62613
+	vxor		$twk3,$tweak,$rndkey0
e62613
+	vsrab		$tmp,$tweak,$seven	# next tweak value
e62613
+	vaddubm		$tweak,$tweak,$tweak
e62613
+	vsldoi		$tmp,$tmp,$tmp,15
e62613
+	 le?vperm	$in3,$in3,$in3,$leperm
e62613
+	vand		$tmp,$tmp,$eighty7
e62613
+	 vxor		$out3,$in3,$twk3
e62613
+	vxor		$tweak,$tweak,$tmp
e62613
+
e62613
+	 lvx_u		$in4,$x40,$inp
e62613
+	 subi		$len,$len,0x60
e62613
+	vxor		$twk4,$tweak,$rndkey0
e62613
+	vsrab		$tmp,$tweak,$seven	# next tweak value
e62613
+	vaddubm		$tweak,$tweak,$tweak
e62613
+	vsldoi		$tmp,$tmp,$tmp,15
e62613
+	 le?vperm	$in4,$in4,$in4,$leperm
e62613
+	vand		$tmp,$tmp,$eighty7
e62613
+	 vxor		$out4,$in4,$twk4
e62613
+	vxor		$tweak,$tweak,$tmp
e62613
+
e62613
+	 lvx_u		$in5,$x50,$inp
e62613
+	 addi		$inp,$inp,0x60
e62613
+	vxor		$twk5,$tweak,$rndkey0
e62613
+	vsrab		$tmp,$tweak,$seven	# next tweak value
e62613
+	vaddubm		$tweak,$tweak,$tweak
e62613
+	vsldoi		$tmp,$tmp,$tmp,15
e62613
+	 le?vperm	$in5,$in5,$in5,$leperm
e62613
+	vand		$tmp,$tmp,$eighty7
e62613
+	 vxor		$out5,$in5,$twk5
e62613
+	vxor		$tweak,$tweak,$tmp
e62613
+
e62613
+	vxor		v31,v31,$rndkey0
e62613
+	mtctr		$rounds
e62613
+	b		Loop_xts_enc6x
e62613
+
e62613
+.align	5
e62613
+Loop_xts_enc6x:
e62613
+	vcipher		$out0,$out0,v24
e62613
+	vcipher		$out1,$out1,v24
e62613
+	vcipher		$out2,$out2,v24
e62613
+	vcipher		$out3,$out3,v24
e62613
+	vcipher		$out4,$out4,v24
e62613
+	vcipher		$out5,$out5,v24
e62613
+	lvx		v24,$x20,$key_		# round[3]
e62613
+	addi		$key_,$key_,0x20
e62613
+
e62613
+	vcipher		$out0,$out0,v25
e62613
+	vcipher		$out1,$out1,v25
e62613
+	vcipher		$out2,$out2,v25
e62613
+	vcipher		$out3,$out3,v25
e62613
+	vcipher		$out4,$out4,v25
e62613
+	vcipher		$out5,$out5,v25
e62613
+	lvx		v25,$x10,$key_		# round[4]
e62613
+	bdnz		Loop_xts_enc6x
e62613
+
e62613
+	subic		$len,$len,96		# $len-=96
e62613
+	 vxor		$in0,$twk0,v31		# xor with last round key
e62613
+	vcipher		$out0,$out0,v24
e62613
+	vcipher		$out1,$out1,v24
e62613
+	 vsrab		$tmp,$tweak,$seven	# next tweak value
e62613
+	 vxor		$twk0,$tweak,$rndkey0
e62613
+	 vaddubm	$tweak,$tweak,$tweak
e62613
+	vcipher		$out2,$out2,v24
e62613
+	vcipher		$out3,$out3,v24
e62613
+	 vsldoi		$tmp,$tmp,$tmp,15
e62613
+	vcipher		$out4,$out4,v24
e62613
+	vcipher		$out5,$out5,v24
e62613
+
e62613
+	subfe.		r0,r0,r0		# borrow?-1:0
e62613
+	 vand		$tmp,$tmp,$eighty7
e62613
+	vcipher		$out0,$out0,v25
e62613
+	vcipher		$out1,$out1,v25
e62613
+	 vxor		$tweak,$tweak,$tmp
e62613
+	vcipher		$out2,$out2,v25
e62613
+	vcipher		$out3,$out3,v25
e62613
+	 vxor		$in1,$twk1,v31
e62613
+	 vsrab		$tmp,$tweak,$seven	# next tweak value
e62613
+	 vxor		$twk1,$tweak,$rndkey0
e62613
+	vcipher		$out4,$out4,v25
e62613
+	vcipher		$out5,$out5,v25
e62613
+
e62613
+	and		r0,r0,$len
e62613
+	 vaddubm	$tweak,$tweak,$tweak
e62613
+	 vsldoi		$tmp,$tmp,$tmp,15
e62613
+	vcipher		$out0,$out0,v26
e62613
+	vcipher		$out1,$out1,v26
e62613
+	 vand		$tmp,$tmp,$eighty7
e62613
+	vcipher		$out2,$out2,v26
e62613
+	vcipher		$out3,$out3,v26
e62613
+	 vxor		$tweak,$tweak,$tmp
e62613
+	vcipher		$out4,$out4,v26
e62613
+	vcipher		$out5,$out5,v26
e62613
+
e62613
+	add		$inp,$inp,r0		# $inp is adjusted in such
e62613
+						# way that at exit from the
e62613
+						# loop inX-in5 are loaded
e62613
+						# with last "words"
e62613
+	 vxor		$in2,$twk2,v31
e62613
+	 vsrab		$tmp,$tweak,$seven	# next tweak value
e62613
+	 vxor		$twk2,$tweak,$rndkey0
e62613
+	 vaddubm	$tweak,$tweak,$tweak
e62613
+	vcipher		$out0,$out0,v27
e62613
+	vcipher		$out1,$out1,v27
e62613
+	 vsldoi		$tmp,$tmp,$tmp,15
e62613
+	vcipher		$out2,$out2,v27
e62613
+	vcipher		$out3,$out3,v27
e62613
+	 vand		$tmp,$tmp,$eighty7
e62613
+	vcipher		$out4,$out4,v27
e62613
+	vcipher		$out5,$out5,v27
e62613
+
e62613
+	addi		$key_,$sp,$FRAME+15	# rewind $key_
e62613
+	 vxor		$tweak,$tweak,$tmp
e62613
+	vcipher		$out0,$out0,v28
e62613
+	vcipher		$out1,$out1,v28
e62613
+	 vxor		$in3,$twk3,v31
e62613
+	 vsrab		$tmp,$tweak,$seven	# next tweak value
e62613
+	 vxor		$twk3,$tweak,$rndkey0
e62613
+	vcipher		$out2,$out2,v28
e62613
+	vcipher		$out3,$out3,v28
e62613
+	 vaddubm	$tweak,$tweak,$tweak
e62613
+	 vsldoi		$tmp,$tmp,$tmp,15
e62613
+	vcipher		$out4,$out4,v28
e62613
+	vcipher		$out5,$out5,v28
e62613
+	lvx		v24,$x00,$key_		# re-pre-load round[1]
e62613
+	 vand		$tmp,$tmp,$eighty7
e62613
+
e62613
+	vcipher		$out0,$out0,v29
e62613
+	vcipher		$out1,$out1,v29
e62613
+	 vxor		$tweak,$tweak,$tmp
e62613
+	vcipher		$out2,$out2,v29
e62613
+	vcipher		$out3,$out3,v29
e62613
+	 vxor		$in4,$twk4,v31
e62613
+	 vsrab		$tmp,$tweak,$seven	# next tweak value
e62613
+	 vxor		$twk4,$tweak,$rndkey0
e62613
+	vcipher		$out4,$out4,v29
e62613
+	vcipher		$out5,$out5,v29
e62613
+	lvx		v25,$x10,$key_		# re-pre-load round[2]
e62613
+	 vaddubm	$tweak,$tweak,$tweak
e62613
+	 vsldoi		$tmp,$tmp,$tmp,15
e62613
+
e62613
+	vcipher		$out0,$out0,v30
e62613
+	vcipher		$out1,$out1,v30
e62613
+	 vand		$tmp,$tmp,$eighty7
e62613
+	vcipher		$out2,$out2,v30
e62613
+	vcipher		$out3,$out3,v30
e62613
+	 vxor		$tweak,$tweak,$tmp
e62613
+	vcipher		$out4,$out4,v30
e62613
+	vcipher		$out5,$out5,v30
e62613
+	 vxor		$in5,$twk5,v31
e62613
+	 vsrab		$tmp,$tweak,$seven	# next tweak value
e62613
+	 vxor		$twk5,$tweak,$rndkey0
e62613
+
e62613
+	vcipherlast	$out0,$out0,$in0
e62613
+	 lvx_u		$in0,$x00,$inp		# load next input block
e62613
+	 vaddubm	$tweak,$tweak,$tweak
e62613
+	 vsldoi		$tmp,$tmp,$tmp,15
e62613
+	vcipherlast	$out1,$out1,$in1
e62613
+	 lvx_u		$in1,$x10,$inp
e62613
+	vcipherlast	$out2,$out2,$in2
e62613
+	 le?vperm	$in0,$in0,$in0,$leperm
e62613
+	 lvx_u		$in2,$x20,$inp
e62613
+	 vand		$tmp,$tmp,$eighty7
e62613
+	vcipherlast	$out3,$out3,$in3
e62613
+	 le?vperm	$in1,$in1,$in1,$leperm
e62613
+	 lvx_u		$in3,$x30,$inp
e62613
+	vcipherlast	$out4,$out4,$in4
e62613
+	 le?vperm	$in2,$in2,$in2,$leperm
e62613
+	 lvx_u		$in4,$x40,$inp
e62613
+	 vxor		$tweak,$tweak,$tmp
e62613
+	vcipherlast	$tmp,$out5,$in5		# last block might be needed
e62613
+						# in stealing mode
e62613
+	 le?vperm	$in3,$in3,$in3,$leperm
e62613
+	 lvx_u		$in5,$x50,$inp
e62613
+	 addi		$inp,$inp,0x60
e62613
+	 le?vperm	$in4,$in4,$in4,$leperm
e62613
+	 le?vperm	$in5,$in5,$in5,$leperm
e62613
+
e62613
+	le?vperm	$out0,$out0,$out0,$leperm
e62613
+	le?vperm	$out1,$out1,$out1,$leperm
e62613
+	stvx_u		$out0,$x00,$out		# store output
e62613
+	 vxor		$out0,$in0,$twk0
e62613
+	le?vperm	$out2,$out2,$out2,$leperm
e62613
+	stvx_u		$out1,$x10,$out
e62613
+	 vxor		$out1,$in1,$twk1
e62613
+	le?vperm	$out3,$out3,$out3,$leperm
e62613
+	stvx_u		$out2,$x20,$out
e62613
+	 vxor		$out2,$in2,$twk2
e62613
+	le?vperm	$out4,$out4,$out4,$leperm
e62613
+	stvx_u		$out3,$x30,$out
e62613
+	 vxor		$out3,$in3,$twk3
e62613
+	le?vperm	$out5,$tmp,$tmp,$leperm
e62613
+	stvx_u		$out4,$x40,$out
e62613
+	 vxor		$out4,$in4,$twk4
e62613
+	le?stvx_u	$out5,$x50,$out
e62613
+	be?stvx_u	$tmp, $x50,$out
e62613
+	 vxor		$out5,$in5,$twk5
e62613
+	addi		$out,$out,0x60
e62613
+
e62613
+	mtctr		$rounds
e62613
+	beq		Loop_xts_enc6x		# did $len-=96 borrow?
e62613
+
e62613
+	addic.		$len,$len,0x60
e62613
+	beq		Lxts_enc6x_zero
e62613
+	cmpwi		$len,0x20
e62613
+	blt		Lxts_enc6x_one
e62613
+	nop
e62613
+	beq		Lxts_enc6x_two
e62613
+	cmpwi		$len,0x40
e62613
+	blt		Lxts_enc6x_three
e62613
+	nop
e62613
+	beq		Lxts_enc6x_four
e62613
+
e62613
+Lxts_enc6x_five:
e62613
+	vxor		$out0,$in1,$twk0
e62613
+	vxor		$out1,$in2,$twk1
e62613
+	vxor		$out2,$in3,$twk2
e62613
+	vxor		$out3,$in4,$twk3
e62613
+	vxor		$out4,$in5,$twk4
e62613
+
e62613
+	bl		_aesp8_xts_enc5x
e62613
+
e62613
+	le?vperm	$out0,$out0,$out0,$leperm
e62613
+	vmr		$twk0,$twk5		# unused tweak
e62613
+	le?vperm	$out1,$out1,$out1,$leperm
e62613
+	stvx_u		$out0,$x00,$out		# store output
e62613
+	le?vperm	$out2,$out2,$out2,$leperm
e62613
+	stvx_u		$out1,$x10,$out
e62613
+	le?vperm	$out3,$out3,$out3,$leperm
e62613
+	stvx_u		$out2,$x20,$out
e62613
+	vxor		$tmp,$out4,$twk5	# last block prep for stealing
e62613
+	le?vperm	$out4,$out4,$out4,$leperm
e62613
+	stvx_u		$out3,$x30,$out
e62613
+	stvx_u		$out4,$x40,$out
e62613
+	addi		$out,$out,0x50
e62613
+	bne		Lxts_enc6x_steal
e62613
+	b		Lxts_enc6x_done
e62613
+
e62613
+.align	4
e62613
+Lxts_enc6x_four:
e62613
+	vxor		$out0,$in2,$twk0
e62613
+	vxor		$out1,$in3,$twk1
e62613
+	vxor		$out2,$in4,$twk2
e62613
+	vxor		$out3,$in5,$twk3
e62613
+	vxor		$out4,$out4,$out4
e62613
+
e62613
+	bl		_aesp8_xts_enc5x
e62613
+
e62613
+	le?vperm	$out0,$out0,$out0,$leperm
e62613
+	vmr		$twk0,$twk4		# unused tweak
e62613
+	le?vperm	$out1,$out1,$out1,$leperm
e62613
+	stvx_u		$out0,$x00,$out		# store output
e62613
+	le?vperm	$out2,$out2,$out2,$leperm
e62613
+	stvx_u		$out1,$x10,$out
e62613
+	vxor		$tmp,$out3,$twk4	# last block prep for stealing
e62613
+	le?vperm	$out3,$out3,$out3,$leperm
e62613
+	stvx_u		$out2,$x20,$out
e62613
+	stvx_u		$out3,$x30,$out
e62613
+	addi		$out,$out,0x40
e62613
+	bne		Lxts_enc6x_steal
e62613
+	b		Lxts_enc6x_done
e62613
+
e62613
+.align	4
e62613
+Lxts_enc6x_three:
e62613
+	vxor		$out0,$in3,$twk0
e62613
+	vxor		$out1,$in4,$twk1
e62613
+	vxor		$out2,$in5,$twk2
e62613
+	vxor		$out3,$out3,$out3
e62613
+	vxor		$out4,$out4,$out4
e62613
+
e62613
+	bl		_aesp8_xts_enc5x
e62613
+
e62613
+	le?vperm	$out0,$out0,$out0,$leperm
e62613
+	vmr		$twk0,$twk3		# unused tweak
e62613
+	le?vperm	$out1,$out1,$out1,$leperm
e62613
+	stvx_u		$out0,$x00,$out		# store output
e62613
+	vxor		$tmp,$out2,$twk3	# last block prep for stealing
e62613
+	le?vperm	$out2,$out2,$out2,$leperm
e62613
+	stvx_u		$out1,$x10,$out
e62613
+	stvx_u		$out2,$x20,$out
e62613
+	addi		$out,$out,0x30
e62613
+	bne		Lxts_enc6x_steal
e62613
+	b		Lxts_enc6x_done
e62613
+
e62613
+.align	4
e62613
+Lxts_enc6x_two:
e62613
+	vxor		$out0,$in4,$twk0
e62613
+	vxor		$out1,$in5,$twk1
e62613
+	vxor		$out2,$out2,$out2
e62613
+	vxor		$out3,$out3,$out3
e62613
+	vxor		$out4,$out4,$out4
e62613
+
e62613
+	bl		_aesp8_xts_enc5x
e62613
+
e62613
+	le?vperm	$out0,$out0,$out0,$leperm
e62613
+	vmr		$twk0,$twk2		# unused tweak
e62613
+	vxor		$tmp,$out1,$twk2	# last block prep for stealing
e62613
+	le?vperm	$out1,$out1,$out1,$leperm
e62613
+	stvx_u		$out0,$x00,$out		# store output
e62613
+	stvx_u		$out1,$x10,$out
e62613
+	addi		$out,$out,0x20
e62613
+	bne		Lxts_enc6x_steal
e62613
+	b		Lxts_enc6x_done
e62613
+
e62613
+.align	4
e62613
+Lxts_enc6x_one:
e62613
+	vxor		$out0,$in5,$twk0
e62613
+	nop
e62613
+Loop_xts_enc1x:
e62613
+	vcipher		$out0,$out0,v24
e62613
+	lvx		v24,$x20,$key_		# round[3]
e62613
+	addi		$key_,$key_,0x20
e62613
+
e62613
+	vcipher		$out0,$out0,v25
e62613
+	lvx		v25,$x10,$key_		# round[4]
e62613
+	bdnz		Loop_xts_enc1x
e62613
+
e62613
+	add		$inp,$inp,$taillen
e62613
+	cmpwi		$taillen,0
e62613
+	vcipher		$out0,$out0,v24
e62613
+
e62613
+	subi		$inp,$inp,16
e62613
+	vcipher		$out0,$out0,v25
e62613
+
e62613
+	lvsr		$inpperm,0,$taillen
e62613
+	vcipher		$out0,$out0,v26
e62613
+
e62613
+	lvx_u		$in0,0,$inp
e62613
+	vcipher		$out0,$out0,v27
e62613
+
e62613
+	addi		$key_,$sp,$FRAME+15	# rewind $key_
e62613
+	vcipher		$out0,$out0,v28
e62613
+	lvx		v24,$x00,$key_		# re-pre-load round[1]
e62613
+
e62613
+	vcipher		$out0,$out0,v29
e62613
+	lvx		v25,$x10,$key_		# re-pre-load round[2]
e62613
+	 vxor		$twk0,$twk0,v31
e62613
+
e62613
+	le?vperm	$in0,$in0,$in0,$leperm
e62613
+	vcipher		$out0,$out0,v30
e62613
+
e62613
+	vperm		$in0,$in0,$in0,$inpperm
e62613
+	vcipherlast	$out0,$out0,$twk0
e62613
+
e62613
+	vmr		$twk0,$twk1		# unused tweak
e62613
+	vxor		$tmp,$out0,$twk1	# last block prep for stealing
e62613
+	le?vperm	$out0,$out0,$out0,$leperm
e62613
+	stvx_u		$out0,$x00,$out		# store output
e62613
+	addi		$out,$out,0x10
e62613
+	bne		Lxts_enc6x_steal
e62613
+	b		Lxts_enc6x_done
e62613
+
e62613
+.align	4
e62613
+Lxts_enc6x_zero:
e62613
+	cmpwi		$taillen,0
e62613
+	beq		Lxts_enc6x_done
e62613
+
e62613
+	add		$inp,$inp,$taillen
e62613
+	subi		$inp,$inp,16
e62613
+	lvx_u		$in0,0,$inp
e62613
+	lvsr		$inpperm,0,$taillen	# $in5 is no more
e62613
+	le?vperm	$in0,$in0,$in0,$leperm
e62613
+	vperm		$in0,$in0,$in0,$inpperm
e62613
+	vxor		$tmp,$tmp,$twk0
e62613
+Lxts_enc6x_steal:
e62613
+	vxor		$in0,$in0,$twk0
e62613
+	vxor		$out0,$out0,$out0
e62613
+	vspltisb	$out1,-1
e62613
+	vperm		$out0,$out0,$out1,$inpperm
e62613
+	vsel		$out0,$in0,$tmp,$out0	# $tmp is last block, remember?
e62613
+
e62613
+	subi		r30,$out,17
e62613
+	subi		$out,$out,16
e62613
+	mtctr		$taillen
e62613
+Loop_xts_enc6x_steal:
e62613
+	lbzu		r0,1(r30)
e62613
+	stb		r0,16(r30)
e62613
+	bdnz		Loop_xts_enc6x_steal
e62613
+
e62613
+	li		$taillen,0
e62613
+	mtctr		$rounds
e62613
+	b		Loop_xts_enc1x		# one more time...
e62613
+
e62613
+.align	4
e62613
+Lxts_enc6x_done:
e62613
+	${UCMP}i	$ivp,0
e62613
+	beq		Lxts_enc6x_ret
e62613
+
e62613
+	vxor		$tweak,$twk0,$rndkey0
e62613
+	le?vperm	$tweak,$tweak,$tweak,$leperm
e62613
+	stvx_u		$tweak,0,$ivp
e62613
+
e62613
+Lxts_enc6x_ret:
e62613
+	mtlr		r11
e62613
+	li		r10,`$FRAME+15`
e62613
+	li		r11,`$FRAME+31`
e62613
+	stvx		$seven,r10,$sp		# wipe copies of round keys
e62613
+	addi		r10,r10,32
e62613
+	stvx		$seven,r11,$sp
e62613
+	addi		r11,r11,32
e62613
+	stvx		$seven,r10,$sp
e62613
+	addi		r10,r10,32
e62613
+	stvx		$seven,r11,$sp
e62613
+	addi		r11,r11,32
e62613
+	stvx		$seven,r10,$sp
e62613
+	addi		r10,r10,32
e62613
+	stvx		$seven,r11,$sp
e62613
+	addi		r11,r11,32
e62613
+	stvx		$seven,r10,$sp
e62613
+	addi		r10,r10,32
e62613
+	stvx		$seven,r11,$sp
e62613
+	addi		r11,r11,32
e62613
+
e62613
+	mtspr		256,$vrsave
e62613
+	lvx		v20,r10,$sp		# ABI says so
e62613
+	addi		r10,r10,32
e62613
+	lvx		v21,r11,$sp
e62613
+	addi		r11,r11,32
e62613
+	lvx		v22,r10,$sp
e62613
+	addi		r10,r10,32
e62613
+	lvx		v23,r11,$sp
e62613
+	addi		r11,r11,32
e62613
+	lvx		v24,r10,$sp
e62613
+	addi		r10,r10,32
e62613
+	lvx		v25,r11,$sp
e62613
+	addi		r11,r11,32
e62613
+	lvx		v26,r10,$sp
e62613
+	addi		r10,r10,32
e62613
+	lvx		v27,r11,$sp
e62613
+	addi		r11,r11,32
e62613
+	lvx		v28,r10,$sp
e62613
+	addi		r10,r10,32
e62613
+	lvx		v29,r11,$sp
e62613
+	addi		r11,r11,32
e62613
+	lvx		v30,r10,$sp
e62613
+	lvx		v31,r11,$sp
e62613
+	$POP		r26,`$FRAME+21*16+0*$SIZE_T`($sp)
e62613
+	$POP		r27,`$FRAME+21*16+1*$SIZE_T`($sp)
e62613
+	$POP		r28,`$FRAME+21*16+2*$SIZE_T`($sp)
e62613
+	$POP		r29,`$FRAME+21*16+3*$SIZE_T`($sp)
e62613
+	$POP		r30,`$FRAME+21*16+4*$SIZE_T`($sp)
e62613
+	$POP		r31,`$FRAME+21*16+5*$SIZE_T`($sp)
e62613
+	addi		$sp,$sp,`$FRAME+21*16+6*$SIZE_T`
e62613
+	blr
e62613
+	.long		0
e62613
+	.byte		0,12,0x04,1,0x80,6,6,0
e62613
+	.long		0
e62613
+
e62613
+.align	5
e62613
+_aesp8_xts_enc5x:
e62613
+	vcipher		$out0,$out0,v24
e62613
+	vcipher		$out1,$out1,v24
e62613
+	vcipher		$out2,$out2,v24
e62613
+	vcipher		$out3,$out3,v24
e62613
+	vcipher		$out4,$out4,v24
e62613
+	lvx		v24,$x20,$key_		# round[3]
e62613
+	addi		$key_,$key_,0x20
e62613
+
e62613
+	vcipher		$out0,$out0,v25
e62613
+	vcipher		$out1,$out1,v25
e62613
+	vcipher		$out2,$out2,v25
e62613
+	vcipher		$out3,$out3,v25
e62613
+	vcipher		$out4,$out4,v25
e62613
+	lvx		v25,$x10,$key_		# round[4]
e62613
+	bdnz		_aesp8_xts_enc5x
e62613
+
e62613
+	add		$inp,$inp,$taillen
e62613
+	cmpwi		$taillen,0
e62613
+	vcipher		$out0,$out0,v24
e62613
+	vcipher		$out1,$out1,v24
e62613
+	vcipher		$out2,$out2,v24
e62613
+	vcipher		$out3,$out3,v24
e62613
+	vcipher		$out4,$out4,v24
e62613
+
e62613
+	subi		$inp,$inp,16
e62613
+	vcipher		$out0,$out0,v25
e62613
+	vcipher		$out1,$out1,v25
e62613
+	vcipher		$out2,$out2,v25
e62613
+	vcipher		$out3,$out3,v25
e62613
+	vcipher		$out4,$out4,v25
e62613
+	 vxor		$twk0,$twk0,v31
e62613
+
e62613
+	vcipher		$out0,$out0,v26
e62613
+	lvsr		$inpperm,r0,$taillen	# $in5 is no more
e62613
+	vcipher		$out1,$out1,v26
e62613
+	vcipher		$out2,$out2,v26
e62613
+	vcipher		$out3,$out3,v26
e62613
+	vcipher		$out4,$out4,v26
e62613
+	 vxor		$in1,$twk1,v31
e62613
+
e62613
+	vcipher		$out0,$out0,v27
e62613
+	lvx_u		$in0,0,$inp
e62613
+	vcipher		$out1,$out1,v27
e62613
+	vcipher		$out2,$out2,v27
e62613
+	vcipher		$out3,$out3,v27
e62613
+	vcipher		$out4,$out4,v27
e62613
+	 vxor		$in2,$twk2,v31
e62613
+
e62613
+	addi		$key_,$sp,$FRAME+15	# rewind $key_
e62613
+	vcipher		$out0,$out0,v28
e62613
+	vcipher		$out1,$out1,v28
e62613
+	vcipher		$out2,$out2,v28
e62613
+	vcipher		$out3,$out3,v28
e62613
+	vcipher		$out4,$out4,v28
e62613
+	lvx		v24,$x00,$key_		# re-pre-load round[1]
e62613
+	 vxor		$in3,$twk3,v31
e62613
+
e62613
+	vcipher		$out0,$out0,v29
e62613
+	le?vperm	$in0,$in0,$in0,$leperm
e62613
+	vcipher		$out1,$out1,v29
e62613
+	vcipher		$out2,$out2,v29
e62613
+	vcipher		$out3,$out3,v29
e62613
+	vcipher		$out4,$out4,v29
e62613
+	lvx		v25,$x10,$key_		# re-pre-load round[2]
e62613
+	 vxor		$in4,$twk4,v31
e62613
+
e62613
+	vcipher		$out0,$out0,v30
e62613
+	vperm		$in0,$in0,$in0,$inpperm
e62613
+	vcipher		$out1,$out1,v30
e62613
+	vcipher		$out2,$out2,v30
e62613
+	vcipher		$out3,$out3,v30
e62613
+	vcipher		$out4,$out4,v30
e62613
+
e62613
+	vcipherlast	$out0,$out0,$twk0
e62613
+	vcipherlast	$out1,$out1,$in1
e62613
+	vcipherlast	$out2,$out2,$in2
e62613
+	vcipherlast	$out3,$out3,$in3
e62613
+	vcipherlast	$out4,$out4,$in4
e62613
+	blr
e62613
+        .long   	0
e62613
+        .byte   	0,12,0x14,0,0,0,0,0
e62613
+
e62613
+.align	5
e62613
+_aesp8_xts_decrypt6x:
e62613
+	$STU		$sp,-`($FRAME+21*16+6*$SIZE_T)`($sp)
e62613
+	mflr		r11
e62613
+	li		r7,`$FRAME+8*16+15`
e62613
+	li		r3,`$FRAME+8*16+31`
e62613
+	$PUSH		r11,`$FRAME+21*16+6*$SIZE_T+$LRSAVE`($sp)
e62613
+	stvx		v20,r7,$sp		# ABI says so
e62613
+	addi		r7,r7,32
e62613
+	stvx		v21,r3,$sp
e62613
+	addi		r3,r3,32
e62613
+	stvx		v22,r7,$sp
e62613
+	addi		r7,r7,32
e62613
+	stvx		v23,r3,$sp
e62613
+	addi		r3,r3,32
e62613
+	stvx		v24,r7,$sp
e62613
+	addi		r7,r7,32
e62613
+	stvx		v25,r3,$sp
e62613
+	addi		r3,r3,32
e62613
+	stvx		v26,r7,$sp
e62613
+	addi		r7,r7,32
e62613
+	stvx		v27,r3,$sp
e62613
+	addi		r3,r3,32
e62613
+	stvx		v28,r7,$sp
e62613
+	addi		r7,r7,32
e62613
+	stvx		v29,r3,$sp
e62613
+	addi		r3,r3,32
e62613
+	stvx		v30,r7,$sp
e62613
+	stvx		v31,r3,$sp
e62613
+	li		r0,-1
e62613
+	stw		$vrsave,`$FRAME+21*16-4`($sp)	# save vrsave
e62613
+	li		$x10,0x10
e62613
+	$PUSH		r26,`$FRAME+21*16+0*$SIZE_T`($sp)
e62613
+	li		$x20,0x20
e62613
+	$PUSH		r27,`$FRAME+21*16+1*$SIZE_T`($sp)
e62613
+	li		$x30,0x30
e62613
+	$PUSH		r28,`$FRAME+21*16+2*$SIZE_T`($sp)
e62613
+	li		$x40,0x40
e62613
+	$PUSH		r29,`$FRAME+21*16+3*$SIZE_T`($sp)
e62613
+	li		$x50,0x50
e62613
+	$PUSH		r30,`$FRAME+21*16+4*$SIZE_T`($sp)
e62613
+	li		$x60,0x60
e62613
+	$PUSH		r31,`$FRAME+21*16+5*$SIZE_T`($sp)
e62613
+	li		$x70,0x70
e62613
+	mtspr		256,r0
e62613
+
e62613
+	subi		$rounds,$rounds,3	# -4 in total
e62613
+
e62613
+	lvx		$rndkey0,$x00,$key1	# load key schedule
e62613
+	lvx		v30,$x10,$key1
e62613
+	addi		$key1,$key1,0x20
e62613
+	lvx		v31,$x00,$key1
e62613
+	?vperm		$rndkey0,$rndkey0,v30,$keyperm
e62613
+	addi		$key_,$sp,$FRAME+15
e62613
+	mtctr		$rounds
e62613
+
e62613
+Load_xts_dec_key:
e62613
+	?vperm		v24,v30,v31,$keyperm
e62613
+	lvx		v30,$x10,$key1
e62613
+	addi		$key1,$key1,0x20
e62613
+	stvx		v24,$x00,$key_		# off-load round[1]
e62613
+	?vperm		v25,v31,v30,$keyperm
e62613
+	lvx		v31,$x00,$key1
e62613
+	stvx		v25,$x10,$key_		# off-load round[2]
e62613
+	addi		$key_,$key_,0x20
e62613
+	bdnz		Load_xts_dec_key
e62613
+
e62613
+	lvx		v26,$x10,$key1
e62613
+	?vperm		v24,v30,v31,$keyperm
e62613
+	lvx		v27,$x20,$key1
e62613
+	stvx		v24,$x00,$key_		# off-load round[3]
e62613
+	?vperm		v25,v31,v26,$keyperm
e62613
+	lvx		v28,$x30,$key1
e62613
+	stvx		v25,$x10,$key_		# off-load round[4]
e62613
+	addi		$key_,$sp,$FRAME+15	# rewind $key_
e62613
+	?vperm		v26,v26,v27,$keyperm
e62613
+	lvx		v29,$x40,$key1
e62613
+	?vperm		v27,v27,v28,$keyperm
e62613
+	lvx		v30,$x50,$key1
e62613
+	?vperm		v28,v28,v29,$keyperm
e62613
+	lvx		v31,$x60,$key1
e62613
+	?vperm		v29,v29,v30,$keyperm
e62613
+	lvx		$twk5,$x70,$key1	# borrow $twk5
e62613
+	?vperm		v30,v30,v31,$keyperm
e62613
+	lvx		v24,$x00,$key_		# pre-load round[1]
e62613
+	?vperm		v31,v31,$twk5,$keyperm
e62613
+	lvx		v25,$x10,$key_		# pre-load round[2]
e62613
+
e62613
+	 vperm		$in0,$inout,$inptail,$inpperm
e62613
+	 subi		$inp,$inp,31		# undo "caller"
e62613
+	vxor		$twk0,$tweak,$rndkey0
e62613
+	vsrab		$tmp,$tweak,$seven	# next tweak value
e62613
+	vaddubm		$tweak,$tweak,$tweak
e62613
+	vsldoi		$tmp,$tmp,$tmp,15
e62613
+	vand		$tmp,$tmp,$eighty7
e62613
+	 vxor		$out0,$in0,$twk0
e62613
+	vxor		$tweak,$tweak,$tmp
e62613
+
e62613
+	 lvx_u		$in1,$x10,$inp
e62613
+	vxor		$twk1,$tweak,$rndkey0
e62613
+	vsrab		$tmp,$tweak,$seven	# next tweak value
e62613
+	vaddubm		$tweak,$tweak,$tweak
e62613
+	vsldoi		$tmp,$tmp,$tmp,15
e62613
+	 le?vperm	$in1,$in1,$in1,$leperm
e62613
+	vand		$tmp,$tmp,$eighty7
e62613
+	 vxor		$out1,$in1,$twk1
e62613
+	vxor		$tweak,$tweak,$tmp
e62613
+
e62613
+	 lvx_u		$in2,$x20,$inp
e62613
+	 andi.		$taillen,$len,15
e62613
+	vxor		$twk2,$tweak,$rndkey0
e62613
+	vsrab		$tmp,$tweak,$seven	# next tweak value
e62613
+	vaddubm		$tweak,$tweak,$tweak
e62613
+	vsldoi		$tmp,$tmp,$tmp,15
e62613
+	 le?vperm	$in2,$in2,$in2,$leperm
e62613
+	vand		$tmp,$tmp,$eighty7
e62613
+	 vxor		$out2,$in2,$twk2
e62613
+	vxor		$tweak,$tweak,$tmp
e62613
+
e62613
+	 lvx_u		$in3,$x30,$inp
e62613
+	 sub		$len,$len,$taillen
e62613
+	vxor		$twk3,$tweak,$rndkey0
e62613
+	vsrab		$tmp,$tweak,$seven	# next tweak value
e62613
+	vaddubm		$tweak,$tweak,$tweak
e62613
+	vsldoi		$tmp,$tmp,$tmp,15
e62613
+	 le?vperm	$in3,$in3,$in3,$leperm
e62613
+	vand		$tmp,$tmp,$eighty7
e62613
+	 vxor		$out3,$in3,$twk3
e62613
+	vxor		$tweak,$tweak,$tmp
e62613
+
e62613
+	 lvx_u		$in4,$x40,$inp
e62613
+	 subi		$len,$len,0x60
e62613
+	vxor		$twk4,$tweak,$rndkey0
e62613
+	vsrab		$tmp,$tweak,$seven	# next tweak value
e62613
+	vaddubm		$tweak,$tweak,$tweak
e62613
+	vsldoi		$tmp,$tmp,$tmp,15
e62613
+	 le?vperm	$in4,$in4,$in4,$leperm
e62613
+	vand		$tmp,$tmp,$eighty7
e62613
+	 vxor		$out4,$in4,$twk4
e62613
+	vxor		$tweak,$tweak,$tmp
e62613
+
e62613
+	 lvx_u		$in5,$x50,$inp
e62613
+	 addi		$inp,$inp,0x60
e62613
+	vxor		$twk5,$tweak,$rndkey0
e62613
+	vsrab		$tmp,$tweak,$seven	# next tweak value
e62613
+	vaddubm		$tweak,$tweak,$tweak
e62613
+	vsldoi		$tmp,$tmp,$tmp,15
e62613
+	 le?vperm	$in5,$in5,$in5,$leperm
e62613
+	vand		$tmp,$tmp,$eighty7
e62613
+	 vxor		$out5,$in5,$twk5
e62613
+	vxor		$tweak,$tweak,$tmp
e62613
+
e62613
+	vxor		v31,v31,$rndkey0
e62613
+	mtctr		$rounds
e62613
+	b		Loop_xts_dec6x
e62613
+
e62613
+.align	5
e62613
+Loop_xts_dec6x:
e62613
+	vncipher	$out0,$out0,v24
e62613
+	vncipher	$out1,$out1,v24
e62613
+	vncipher	$out2,$out2,v24
e62613
+	vncipher	$out3,$out3,v24
e62613
+	vncipher	$out4,$out4,v24
e62613
+	vncipher	$out5,$out5,v24
e62613
+	lvx		v24,$x20,$key_		# round[3]
e62613
+	addi		$key_,$key_,0x20
e62613
+
e62613
+	vncipher	$out0,$out0,v25
e62613
+	vncipher	$out1,$out1,v25
e62613
+	vncipher	$out2,$out2,v25
e62613
+	vncipher	$out3,$out3,v25
e62613
+	vncipher	$out4,$out4,v25
e62613
+	vncipher	$out5,$out5,v25
e62613
+	lvx		v25,$x10,$key_		# round[4]
e62613
+	bdnz		Loop_xts_dec6x
e62613
+
e62613
+	subic		$len,$len,96		# $len-=96
e62613
+	 vxor		$in0,$twk0,v31		# xor with last round key
e62613
+	vncipher	$out0,$out0,v24
e62613
+	vncipher	$out1,$out1,v24
e62613
+	 vsrab		$tmp,$tweak,$seven	# next tweak value
e62613
+	 vxor		$twk0,$tweak,$rndkey0
e62613
+	 vaddubm	$tweak,$tweak,$tweak
e62613
+	vncipher	$out2,$out2,v24
e62613
+	vncipher	$out3,$out3,v24
e62613
+	 vsldoi		$tmp,$tmp,$tmp,15
e62613
+	vncipher	$out4,$out4,v24
e62613
+	vncipher	$out5,$out5,v24
e62613
+
e62613
+	subfe.		r0,r0,r0		# borrow?-1:0
e62613
+	 vand		$tmp,$tmp,$eighty7
e62613
+	vncipher	$out0,$out0,v25
e62613
+	vncipher	$out1,$out1,v25
e62613
+	 vxor		$tweak,$tweak,$tmp
e62613
+	vncipher	$out2,$out2,v25
e62613
+	vncipher	$out3,$out3,v25
e62613
+	 vxor		$in1,$twk1,v31
e62613
+	 vsrab		$tmp,$tweak,$seven	# next tweak value
e62613
+	 vxor		$twk1,$tweak,$rndkey0
e62613
+	vncipher	$out4,$out4,v25
e62613
+	vncipher	$out5,$out5,v25
e62613
+
e62613
+	and		r0,r0,$len
e62613
+	 vaddubm	$tweak,$tweak,$tweak
e62613
+	 vsldoi		$tmp,$tmp,$tmp,15
e62613
+	vncipher	$out0,$out0,v26
e62613
+	vncipher	$out1,$out1,v26
e62613
+	 vand		$tmp,$tmp,$eighty7
e62613
+	vncipher	$out2,$out2,v26
e62613
+	vncipher	$out3,$out3,v26
e62613
+	 vxor		$tweak,$tweak,$tmp
e62613
+	vncipher	$out4,$out4,v26
e62613
+	vncipher	$out5,$out5,v26
e62613
+
e62613
+	add		$inp,$inp,r0		# $inp is adjusted in such
e62613
+						# way that at exit from the
e62613
+						# loop inX-in5 are loaded
e62613
+						# with last "words"
e62613
+	 vxor		$in2,$twk2,v31
e62613
+	 vsrab		$tmp,$tweak,$seven	# next tweak value
e62613
+	 vxor		$twk2,$tweak,$rndkey0
e62613
+	 vaddubm	$tweak,$tweak,$tweak
e62613
+	vncipher	$out0,$out0,v27
e62613
+	vncipher	$out1,$out1,v27
e62613
+	 vsldoi		$tmp,$tmp,$tmp,15
e62613
+	vncipher	$out2,$out2,v27
e62613
+	vncipher	$out3,$out3,v27
e62613
+	 vand		$tmp,$tmp,$eighty7
e62613
+	vncipher	$out4,$out4,v27
e62613
+	vncipher	$out5,$out5,v27
e62613
+
e62613
+	addi		$key_,$sp,$FRAME+15	# rewind $key_
e62613
+	 vxor		$tweak,$tweak,$tmp
e62613
+	vncipher	$out0,$out0,v28
e62613
+	vncipher	$out1,$out1,v28
e62613
+	 vxor		$in3,$twk3,v31
e62613
+	 vsrab		$tmp,$tweak,$seven	# next tweak value
e62613
+	 vxor		$twk3,$tweak,$rndkey0
e62613
+	vncipher	$out2,$out2,v28
e62613
+	vncipher	$out3,$out3,v28
e62613
+	 vaddubm	$tweak,$tweak,$tweak
e62613
+	 vsldoi		$tmp,$tmp,$tmp,15
e62613
+	vncipher	$out4,$out4,v28
e62613
+	vncipher	$out5,$out5,v28
e62613
+	lvx		v24,$x00,$key_		# re-pre-load round[1]
e62613
+	 vand		$tmp,$tmp,$eighty7
e62613
+
e62613
+	vncipher	$out0,$out0,v29
e62613
+	vncipher	$out1,$out1,v29
e62613
+	 vxor		$tweak,$tweak,$tmp
e62613
+	vncipher	$out2,$out2,v29
e62613
+	vncipher	$out3,$out3,v29
e62613
+	 vxor		$in4,$twk4,v31
e62613
+	 vsrab		$tmp,$tweak,$seven	# next tweak value
e62613
+	 vxor		$twk4,$tweak,$rndkey0
e62613
+	vncipher	$out4,$out4,v29
e62613
+	vncipher	$out5,$out5,v29
e62613
+	lvx		v25,$x10,$key_		# re-pre-load round[2]
e62613
+	 vaddubm	$tweak,$tweak,$tweak
e62613
+	 vsldoi		$tmp,$tmp,$tmp,15
e62613
+
e62613
+	vncipher	$out0,$out0,v30
e62613
+	vncipher	$out1,$out1,v30
e62613
+	 vand		$tmp,$tmp,$eighty7
e62613
+	vncipher	$out2,$out2,v30
e62613
+	vncipher	$out3,$out3,v30
e62613
+	 vxor		$tweak,$tweak,$tmp
e62613
+	vncipher	$out4,$out4,v30
e62613
+	vncipher	$out5,$out5,v30
e62613
+	 vxor		$in5,$twk5,v31
e62613
+	 vsrab		$tmp,$tweak,$seven	# next tweak value
e62613
+	 vxor		$twk5,$tweak,$rndkey0
e62613
+
e62613
+	vncipherlast	$out0,$out0,$in0
e62613
+	 lvx_u		$in0,$x00,$inp		# load next input block
e62613
+	 vaddubm	$tweak,$tweak,$tweak
e62613
+	 vsldoi		$tmp,$tmp,$tmp,15
e62613
+	vncipherlast	$out1,$out1,$in1
e62613
+	 lvx_u		$in1,$x10,$inp
e62613
+	vncipherlast	$out2,$out2,$in2
e62613
+	 le?vperm	$in0,$in0,$in0,$leperm
e62613
+	 lvx_u		$in2,$x20,$inp
e62613
+	 vand		$tmp,$tmp,$eighty7
e62613
+	vncipherlast	$out3,$out3,$in3
e62613
+	 le?vperm	$in1,$in1,$in1,$leperm
e62613
+	 lvx_u		$in3,$x30,$inp
e62613
+	vncipherlast	$out4,$out4,$in4
e62613
+	 le?vperm	$in2,$in2,$in2,$leperm
e62613
+	 lvx_u		$in4,$x40,$inp
e62613
+	 vxor		$tweak,$tweak,$tmp
e62613
+	vncipherlast	$out5,$out5,$in5
e62613
+	 le?vperm	$in3,$in3,$in3,$leperm
e62613
+	 lvx_u		$in5,$x50,$inp
e62613
+	 addi		$inp,$inp,0x60
e62613
+	 le?vperm	$in4,$in4,$in4,$leperm
e62613
+	 le?vperm	$in5,$in5,$in5,$leperm
e62613
+
e62613
+	le?vperm	$out0,$out0,$out0,$leperm
e62613
+	le?vperm	$out1,$out1,$out1,$leperm
e62613
+	stvx_u		$out0,$x00,$out		# store output
e62613
+	 vxor		$out0,$in0,$twk0
e62613
+	le?vperm	$out2,$out2,$out2,$leperm
e62613
+	stvx_u		$out1,$x10,$out
e62613
+	 vxor		$out1,$in1,$twk1
e62613
+	le?vperm	$out3,$out3,$out3,$leperm
e62613
+	stvx_u		$out2,$x20,$out
e62613
+	 vxor		$out2,$in2,$twk2
e62613
+	le?vperm	$out4,$out4,$out4,$leperm
e62613
+	stvx_u		$out3,$x30,$out
e62613
+	 vxor		$out3,$in3,$twk3
e62613
+	le?vperm	$out5,$out5,$out5,$leperm
e62613
+	stvx_u		$out4,$x40,$out
e62613
+	 vxor		$out4,$in4,$twk4
e62613
+	stvx_u		$out5,$x50,$out
e62613
+	 vxor		$out5,$in5,$twk5
e62613
+	addi		$out,$out,0x60
e62613
+
e62613
+	mtctr		$rounds
e62613
+	beq		Loop_xts_dec6x		# did $len-=96 borrow?
e62613
+
e62613
+	addic.		$len,$len,0x60
e62613
+	beq		Lxts_dec6x_zero
e62613
+	cmpwi		$len,0x20
e62613
+	blt		Lxts_dec6x_one
e62613
+	nop
e62613
+	beq		Lxts_dec6x_two
e62613
+	cmpwi		$len,0x40
e62613
+	blt		Lxts_dec6x_three
e62613
+	nop
e62613
+	beq		Lxts_dec6x_four
e62613
+
e62613
+Lxts_dec6x_five:
e62613
+	vxor		$out0,$in1,$twk0
e62613
+	vxor		$out1,$in2,$twk1
e62613
+	vxor		$out2,$in3,$twk2
e62613
+	vxor		$out3,$in4,$twk3
e62613
+	vxor		$out4,$in5,$twk4
e62613
+
e62613
+	bl		_aesp8_xts_dec5x
e62613
+
e62613
+	le?vperm	$out0,$out0,$out0,$leperm
e62613
+	vmr		$twk0,$twk5		# unused tweak
e62613
+	vxor		$twk1,$tweak,$rndkey0
e62613
+	le?vperm	$out1,$out1,$out1,$leperm
e62613
+	stvx_u		$out0,$x00,$out		# store output
e62613
+	vxor		$out0,$in0,$twk1
e62613
+	le?vperm	$out2,$out2,$out2,$leperm
e62613
+	stvx_u		$out1,$x10,$out
e62613
+	le?vperm	$out3,$out3,$out3,$leperm
e62613
+	stvx_u		$out2,$x20,$out
e62613
+	le?vperm	$out4,$out4,$out4,$leperm
e62613
+	stvx_u		$out3,$x30,$out
e62613
+	stvx_u		$out4,$x40,$out
e62613
+	addi		$out,$out,0x50
e62613
+	bne		Lxts_dec6x_steal
e62613
+	b		Lxts_dec6x_done
e62613
+
e62613
+.align	4
e62613
+Lxts_dec6x_four:
e62613
+	vxor		$out0,$in2,$twk0
e62613
+	vxor		$out1,$in3,$twk1
e62613
+	vxor		$out2,$in4,$twk2
e62613
+	vxor		$out3,$in5,$twk3
e62613
+	vxor		$out4,$out4,$out4
e62613
+
e62613
+	bl		_aesp8_xts_dec5x
e62613
+
e62613
+	le?vperm	$out0,$out0,$out0,$leperm
e62613
+	vmr		$twk0,$twk4		# unused tweak
e62613
+	vmr		$twk1,$twk5
e62613
+	le?vperm	$out1,$out1,$out1,$leperm
e62613
+	stvx_u		$out0,$x00,$out		# store output
e62613
+	vxor		$out0,$in0,$twk5
e62613
+	le?vperm	$out2,$out2,$out2,$leperm
e62613
+	stvx_u		$out1,$x10,$out
e62613
+	le?vperm	$out3,$out3,$out3,$leperm
e62613
+	stvx_u		$out2,$x20,$out
e62613
+	stvx_u		$out3,$x30,$out
e62613
+	addi		$out,$out,0x40
e62613
+	bne		Lxts_dec6x_steal
e62613
+	b		Lxts_dec6x_done
e62613
+
e62613
+.align	4
e62613
+Lxts_dec6x_three:
e62613
+	vxor		$out0,$in3,$twk0
e62613
+	vxor		$out1,$in4,$twk1
e62613
+	vxor		$out2,$in5,$twk2
e62613
+	vxor		$out3,$out3,$out3
e62613
+	vxor		$out4,$out4,$out4
e62613
+
e62613
+	bl		_aesp8_xts_dec5x
e62613
+
e62613
+	le?vperm	$out0,$out0,$out0,$leperm
e62613
+	vmr		$twk0,$twk3		# unused tweak
e62613
+	vmr		$twk1,$twk4
e62613
+	le?vperm	$out1,$out1,$out1,$leperm
e62613
+	stvx_u		$out0,$x00,$out		# store output
e62613
+	vxor		$out0,$in0,$twk4
e62613
+	le?vperm	$out2,$out2,$out2,$leperm
e62613
+	stvx_u		$out1,$x10,$out
e62613
+	stvx_u		$out2,$x20,$out
e62613
+	addi		$out,$out,0x30
e62613
+	bne		Lxts_dec6x_steal
e62613
+	b		Lxts_dec6x_done
e62613
+
e62613
+.align	4
e62613
+Lxts_dec6x_two:
e62613
+	vxor		$out0,$in4,$twk0
e62613
+	vxor		$out1,$in5,$twk1
e62613
+	vxor		$out2,$out2,$out2
e62613
+	vxor		$out3,$out3,$out3
e62613
+	vxor		$out4,$out4,$out4
e62613
+
e62613
+	bl		_aesp8_xts_dec5x
e62613
+
e62613
+	le?vperm	$out0,$out0,$out0,$leperm
e62613
+	vmr		$twk0,$twk2		# unused tweak
e62613
+	vmr		$twk1,$twk3
e62613
+	le?vperm	$out1,$out1,$out1,$leperm
e62613
+	stvx_u		$out0,$x00,$out		# store output
e62613
+	vxor		$out0,$in0,$twk3
e62613
+	stvx_u		$out1,$x10,$out
e62613
+	addi		$out,$out,0x20
e62613
+	bne		Lxts_dec6x_steal
e62613
+	b		Lxts_dec6x_done
e62613
+
e62613
+.align	4
e62613
+Lxts_dec6x_one:
e62613
+	vxor		$out0,$in5,$twk0
e62613
+	nop
e62613
+Loop_xts_dec1x:
e62613
+	vncipher	$out0,$out0,v24
e62613
+	lvx		v24,$x20,$key_		# round[3]
e62613
+	addi		$key_,$key_,0x20
e62613
+
e62613
+	vncipher	$out0,$out0,v25
e62613
+	lvx		v25,$x10,$key_		# round[4]
e62613
+	bdnz		Loop_xts_dec1x
e62613
+
e62613
+	subi		r0,$taillen,1
e62613
+	vncipher	$out0,$out0,v24
e62613
+
e62613
+	andi.		r0,r0,16
e62613
+	cmpwi		$taillen,0
e62613
+	vncipher	$out0,$out0,v25
e62613
+
e62613
+	sub		$inp,$inp,r0
e62613
+	vncipher	$out0,$out0,v26
e62613
+
e62613
+	lvx_u		$in0,0,$inp
e62613
+	vncipher	$out0,$out0,v27
e62613
+
e62613
+	addi		$key_,$sp,$FRAME+15	# rewind $key_
e62613
+	vncipher	$out0,$out0,v28
e62613
+	lvx		v24,$x00,$key_		# re-pre-load round[1]
e62613
+
e62613
+	vncipher	$out0,$out0,v29
e62613
+	lvx		v25,$x10,$key_		# re-pre-load round[2]
e62613
+	 vxor		$twk0,$twk0,v31
e62613
+
e62613
+	le?vperm	$in0,$in0,$in0,$leperm
e62613
+	vncipher	$out0,$out0,v30
e62613
+
e62613
+	mtctr		$rounds
e62613
+	vncipherlast	$out0,$out0,$twk0
e62613
+
e62613
+	vmr		$twk0,$twk1		# unused tweak
e62613
+	vmr		$twk1,$twk2
e62613
+	le?vperm	$out0,$out0,$out0,$leperm
e62613
+	stvx_u		$out0,$x00,$out		# store output
e62613
+	addi		$out,$out,0x10
e62613
+	vxor		$out0,$in0,$twk2
e62613
+	bne		Lxts_dec6x_steal
e62613
+	b		Lxts_dec6x_done
e62613
+
e62613
+.align	4
e62613
+Lxts_dec6x_zero:
e62613
+	cmpwi		$taillen,0
e62613
+	beq		Lxts_dec6x_done
e62613
+
e62613
+	lvx_u		$in0,0,$inp
e62613
+	le?vperm	$in0,$in0,$in0,$leperm
e62613
+	vxor		$out0,$in0,$twk1
e62613
+Lxts_dec6x_steal:
e62613
+	vncipher	$out0,$out0,v24
e62613
+	lvx		v24,$x20,$key_		# round[3]
e62613
+	addi		$key_,$key_,0x20
e62613
+
e62613
+	vncipher	$out0,$out0,v25
e62613
+	lvx		v25,$x10,$key_		# round[4]
e62613
+	bdnz		Lxts_dec6x_steal
e62613
+
e62613
+	add		$inp,$inp,$taillen
e62613
+	vncipher	$out0,$out0,v24
e62613
+
e62613
+	cmpwi		$taillen,0
e62613
+	vncipher	$out0,$out0,v25
e62613
+
e62613
+	lvx_u		$in0,0,$inp
e62613
+	vncipher	$out0,$out0,v26
e62613
+
e62613
+	lvsr		$inpperm,0,$taillen	# $in5 is no more
e62613
+	vncipher	$out0,$out0,v27
e62613
+
e62613
+	addi		$key_,$sp,$FRAME+15	# rewind $key_
e62613
+	vncipher	$out0,$out0,v28
e62613
+	lvx		v24,$x00,$key_		# re-pre-load round[1]
e62613
+
e62613
+	vncipher	$out0,$out0,v29
e62613
+	lvx		v25,$x10,$key_		# re-pre-load round[2]
e62613
+	 vxor		$twk1,$twk1,v31
e62613
+
e62613
+	le?vperm	$in0,$in0,$in0,$leperm
e62613
+	vncipher	$out0,$out0,v30
e62613
+
e62613
+	vperm		$in0,$in0,$in0,$inpperm
e62613
+	vncipherlast	$tmp,$out0,$twk1
e62613
+
e62613
+	le?vperm	$out0,$tmp,$tmp,$leperm
e62613
+	le?stvx_u	$out0,0,$out
e62613
+	be?stvx_u	$tmp,0,$out
e62613
+
e62613
+	vxor		$out0,$out0,$out0
e62613
+	vspltisb	$out1,-1
e62613
+	vperm		$out0,$out0,$out1,$inpperm
e62613
+	vsel		$out0,$in0,$tmp,$out0
e62613
+	vxor		$out0,$out0,$twk0
e62613
+
e62613
+	subi		r30,$out,1
e62613
+	mtctr		$taillen
e62613
+Loop_xts_dec6x_steal:
e62613
+	lbzu		r0,1(r30)
e62613
+	stb		r0,16(r30)
e62613
+	bdnz		Loop_xts_dec6x_steal
e62613
+
e62613
+	li		$taillen,0
e62613
+	mtctr		$rounds
e62613
+	b		Loop_xts_dec1x		# one more time...
e62613
+
e62613
+.align	4
e62613
+Lxts_dec6x_done:
e62613
+	${UCMP}i	$ivp,0
e62613
+	beq		Lxts_dec6x_ret
e62613
+
e62613
+	vxor		$tweak,$twk0,$rndkey0
e62613
+	le?vperm	$tweak,$tweak,$tweak,$leperm
e62613
+	stvx_u		$tweak,0,$ivp
e62613
+
e62613
+Lxts_dec6x_ret:
e62613
+	mtlr		r11
e62613
+	li		r10,`$FRAME+15`
e62613
+	li		r11,`$FRAME+31`
e62613
+	stvx		$seven,r10,$sp		# wipe copies of round keys
e62613
+	addi		r10,r10,32
e62613
+	stvx		$seven,r11,$sp
e62613
+	addi		r11,r11,32
e62613
+	stvx		$seven,r10,$sp
e62613
+	addi		r10,r10,32
e62613
+	stvx		$seven,r11,$sp
e62613
+	addi		r11,r11,32
e62613
+	stvx		$seven,r10,$sp
e62613
+	addi		r10,r10,32
e62613
+	stvx		$seven,r11,$sp
e62613
+	addi		r11,r11,32
e62613
+	stvx		$seven,r10,$sp
e62613
+	addi		r10,r10,32
e62613
+	stvx		$seven,r11,$sp
e62613
+	addi		r11,r11,32
e62613
+
e62613
+	mtspr		256,$vrsave
e62613
+	lvx		v20,r10,$sp		# ABI says so
e62613
+	addi		r10,r10,32
e62613
+	lvx		v21,r11,$sp
e62613
+	addi		r11,r11,32
e62613
+	lvx		v22,r10,$sp
e62613
+	addi		r10,r10,32
e62613
+	lvx		v23,r11,$sp
e62613
+	addi		r11,r11,32
e62613
+	lvx		v24,r10,$sp
e62613
+	addi		r10,r10,32
e62613
+	lvx		v25,r11,$sp
e62613
+	addi		r11,r11,32
e62613
+	lvx		v26,r10,$sp
e62613
+	addi		r10,r10,32
e62613
+	lvx		v27,r11,$sp
e62613
+	addi		r11,r11,32
e62613
+	lvx		v28,r10,$sp
e62613
+	addi		r10,r10,32
e62613
+	lvx		v29,r11,$sp
e62613
+	addi		r11,r11,32
e62613
+	lvx		v30,r10,$sp
e62613
+	lvx		v31,r11,$sp
e62613
+	$POP		r26,`$FRAME+21*16+0*$SIZE_T`($sp)
e62613
+	$POP		r27,`$FRAME+21*16+1*$SIZE_T`($sp)
e62613
+	$POP		r28,`$FRAME+21*16+2*$SIZE_T`($sp)
e62613
+	$POP		r29,`$FRAME+21*16+3*$SIZE_T`($sp)
e62613
+	$POP		r30,`$FRAME+21*16+4*$SIZE_T`($sp)
e62613
+	$POP		r31,`$FRAME+21*16+5*$SIZE_T`($sp)
e62613
+	addi		$sp,$sp,`$FRAME+21*16+6*$SIZE_T`
e62613
+	blr
e62613
+	.long		0
e62613
+	.byte		0,12,0x04,1,0x80,6,6,0
e62613
+	.long		0
e62613
+
e62613
+.align	5
e62613
+_aesp8_xts_dec5x:
e62613
+	vncipher	$out0,$out0,v24
e62613
+	vncipher	$out1,$out1,v24
e62613
+	vncipher	$out2,$out2,v24
e62613
+	vncipher	$out3,$out3,v24
e62613
+	vncipher	$out4,$out4,v24
e62613
+	lvx		v24,$x20,$key_		# round[3]
e62613
+	addi		$key_,$key_,0x20
e62613
+
e62613
+	vncipher	$out0,$out0,v25
e62613
+	vncipher	$out1,$out1,v25
e62613
+	vncipher	$out2,$out2,v25
e62613
+	vncipher	$out3,$out3,v25
e62613
+	vncipher	$out4,$out4,v25
e62613
+	lvx		v25,$x10,$key_		# round[4]
e62613
+	bdnz		_aesp8_xts_dec5x
e62613
+
e62613
+	subi		r0,$taillen,1
e62613
+	vncipher	$out0,$out0,v24
e62613
+	vncipher	$out1,$out1,v24
e62613
+	vncipher	$out2,$out2,v24
e62613
+	vncipher	$out3,$out3,v24
e62613
+	vncipher	$out4,$out4,v24
e62613
+
e62613
+	andi.		r0,r0,16
e62613
+	cmpwi		$taillen,0
e62613
+	vncipher	$out0,$out0,v25
e62613
+	vncipher	$out1,$out1,v25
e62613
+	vncipher	$out2,$out2,v25
e62613
+	vncipher	$out3,$out3,v25
e62613
+	vncipher	$out4,$out4,v25
e62613
+	 vxor		$twk0,$twk0,v31
e62613
+
e62613
+	sub		$inp,$inp,r0
e62613
+	vncipher	$out0,$out0,v26
e62613
+	vncipher	$out1,$out1,v26
e62613
+	vncipher	$out2,$out2,v26
e62613
+	vncipher	$out3,$out3,v26
e62613
+	vncipher	$out4,$out4,v26
e62613
+	 vxor		$in1,$twk1,v31
e62613
+
e62613
+	vncipher	$out0,$out0,v27
e62613
+	lvx_u		$in0,0,$inp
e62613
+	vncipher	$out1,$out1,v27
e62613
+	vncipher	$out2,$out2,v27
e62613
+	vncipher	$out3,$out3,v27
e62613
+	vncipher	$out4,$out4,v27
e62613
+	 vxor		$in2,$twk2,v31
e62613
+
e62613
+	addi		$key_,$sp,$FRAME+15	# rewind $key_
e62613
+	vncipher	$out0,$out0,v28
e62613
+	vncipher	$out1,$out1,v28
e62613
+	vncipher	$out2,$out2,v28
e62613
+	vncipher	$out3,$out3,v28
e62613
+	vncipher	$out4,$out4,v28
e62613
+	lvx		v24,$x00,$key_		# re-pre-load round[1]
e62613
+	 vxor		$in3,$twk3,v31
e62613
+
e62613
+	vncipher	$out0,$out0,v29
e62613
+	le?vperm	$in0,$in0,$in0,$leperm
e62613
+	vncipher	$out1,$out1,v29
e62613
+	vncipher	$out2,$out2,v29
e62613
+	vncipher	$out3,$out3,v29
e62613
+	vncipher	$out4,$out4,v29
e62613
+	lvx		v25,$x10,$key_		# re-pre-load round[2]
e62613
+	 vxor		$in4,$twk4,v31
e62613
+
e62613
+	vncipher	$out0,$out0,v30
e62613
+	vncipher	$out1,$out1,v30
e62613
+	vncipher	$out2,$out2,v30
e62613
+	vncipher	$out3,$out3,v30
e62613
+	vncipher	$out4,$out4,v30
e62613
+
e62613
+	vncipherlast	$out0,$out0,$twk0
e62613
+	vncipherlast	$out1,$out1,$in1
e62613
+	vncipherlast	$out2,$out2,$in2
e62613
+	vncipherlast	$out3,$out3,$in3
e62613
+	vncipherlast	$out4,$out4,$in4
e62613
+	mtctr		$rounds
e62613
+	blr
e62613
+        .long   	0
e62613
+        .byte   	0,12,0x14,0,0,0,0,0
e62613
+___
e62613
+}}	}}}
e62613
+
e62613
 my $consts=1;
e62613
 foreach(split("\n",$code)) {
e62613
         s/\`([^\`]*)\`/eval($1)/geo;
e62613
diff -up openssl-1.0.2k/crypto/evp/e_aes.c.ppc-update openssl-1.0.2k/crypto/evp/e_aes.c
e62613
--- openssl-1.0.2k/crypto/evp/e_aes.c.ppc-update	2017-03-09 17:59:26.303232439 +0100
e62613
+++ openssl-1.0.2k/crypto/evp/e_aes.c	2017-03-09 17:59:26.314232696 +0100
e62613
@@ -172,6 +172,8 @@ void AES_xts_decrypt(const unsigned char
e62613
 #  define HWAES_decrypt aes_p8_decrypt
e62613
 #  define HWAES_cbc_encrypt aes_p8_cbc_encrypt
e62613
 #  define HWAES_ctr32_encrypt_blocks aes_p8_ctr32_encrypt_blocks
e62613
+#  define HWAES_xts_encrypt aes_p8_xts_encrypt
e62613
+#  define HWAES_xts_decrypt aes_p8_xts_decrypt
e62613
 # endif
e62613
 
e62613
 # if     defined(AES_ASM) && !defined(I386_ONLY) &&      (  \
e62613
@@ -911,6 +913,12 @@ void HWAES_cbc_encrypt(const unsigned ch
e62613
 void HWAES_ctr32_encrypt_blocks(const unsigned char *in, unsigned char *out,
e62613
                                 size_t len, const AES_KEY *key,
e62613
                                 const unsigned char ivec[16]);
e62613
+void HWAES_xts_encrypt(const unsigned char *inp, unsigned char *out,
e62613
+                       size_t len, const AES_KEY *key1,
e62613
+                       const AES_KEY *key2, const unsigned char iv[16]);
e62613
+void HWAES_xts_decrypt(const unsigned char *inp, unsigned char *out,
e62613
+                       size_t len, const AES_KEY *key1,
e62613
+                       const AES_KEY *key2, const unsigned char iv[16]);
e62613
 # endif
e62613
 
e62613
 # define BLOCK_CIPHER_generic_pack(nid,keylen,flags)             \
e62613
@@ -1664,10 +1672,16 @@ static int aes_xts_init_key(EVP_CIPHER_C
e62613
                     HWAES_set_encrypt_key(key, ctx->key_len * 4,
e62613
                                           &xctx->ks1.ks);
e62613
                     xctx->xts.block1 = (block128_f) HWAES_encrypt;
e62613
+# ifdef HWAES_xts_encrypt
e62613
+                    xctx->stream = HWAES_xts_encrypt;
e62613
+# endif
e62613
                 } else {
e62613
                     HWAES_set_decrypt_key(key, ctx->key_len * 4,
e62613
                                           &xctx->ks1.ks);
e62613
                     xctx->xts.block1 = (block128_f) HWAES_decrypt;
e62613
+# ifdef HWAES_xts_decrypt
e62613
+                    xctx->stream = HWAES_xts_decrypt;
e62613
+#endif
e62613
                 }
e62613
 
e62613
                 HWAES_set_encrypt_key(key + ctx->key_len / 2,