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

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