Changeset View
Changeset View
Standalone View
Standalone View
cipher/rijndael-ppc8.pl
- This file was moved from cipher/aesp8-ppc.pl.
#! /usr/bin/env perl | #! /usr/bin/env perl | ||||
# SPDX-License-Identifier: BSD-3-Clause | # SPDX-License-Identifier: BSD-3-Clause | ||||
# | # | ||||
# Changes: adjust struct offsets to work with libgcrypt ctx | |||||
# rename ppc-xlate.pl | |||||
# | |||||
# ==================================================================== | # ==================================================================== | ||||
# Written by Andy Polyakov <appro@openssl.org> for the OpenSSL | # Written by Andy Polyakov <appro@openssl.org> for the OpenSSL | ||||
# project. The module is, however, dual licensed under OpenSSL and | # project. The module is, however, dual licensed under OpenSSL and | ||||
# CRYPTOGAMS licenses depending on where you obtain it. For further | # CRYPTOGAMS licenses depending on where you obtain it. For further | ||||
# details see http://www.openssl.org/~appro/cryptogams/. | # details see http://www.openssl.org/~appro/cryptogams/. | ||||
# ==================================================================== | # ==================================================================== | ||||
# | # | ||||
# This module implements support for AES instructions as per PowerISA | # This module implements support for AES instructions as per PowerISA | ||||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | if ($flavour =~ /64/) { | ||||
$PUSH ="stw"; | $PUSH ="stw"; | ||||
$UCMP ="cmplw"; | $UCMP ="cmplw"; | ||||
$SHL ="slwi"; | $SHL ="slwi"; | ||||
} else { die "nonsense $flavour"; } | } else { die "nonsense $flavour"; } | ||||
$LITTLE_ENDIAN = ($flavour=~/le$/) ? $SIZE_T : 0; | $LITTLE_ENDIAN = ($flavour=~/le$/) ? $SIZE_T : 0; | ||||
$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1; | $0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1; | ||||
( $xlate="${dir}asm-common-ppc.pl" and -f $xlate ) or | |||||
( $xlate="${dir}ppc-xlate.pl" and -f $xlate ) or | ( $xlate="${dir}ppc-xlate.pl" and -f $xlate ) or | ||||
( $xlate="${dir}../../perlasm/ppc-xlate.pl" and -f $xlate) or | ( $xlate="${dir}../../perlasm/ppc-xlate.pl" and -f $xlate) or | ||||
die "can't locate ppc-xlate.pl"; | die "can't locate ppc-xlate.pl"; | ||||
open STDOUT,"| $^X $xlate $flavour ".shift || die "can't call $xlate: $!"; | open STDOUT,"| $^X $xlate $flavour ".shift || die "can't call $xlate: $!"; | ||||
$FRAME=8*$SIZE_T; | $FRAME=8*$SIZE_T; | ||||
$prefix="aes_p8"; | $prefix="aes_p8"; | ||||
▲ Show 20 Lines • Show All 277 Lines • ▼ Show 20 Lines | |||||
.align 4 | .align 4 | ||||
Ldone: | Ldone: | ||||
lvx $in1,0,$inp # redundant in aligned case | lvx $in1,0,$inp # redundant in aligned case | ||||
vsel $in1,$outhead,$in1,$outmask | vsel $in1,$outhead,$in1,$outmask | ||||
stvx $in1,0,$inp | stvx $in1,0,$inp | ||||
li $ptr,0 | li $ptr,0 | ||||
mtspr 256,$vrsave | mtspr 256,$vrsave | ||||
stw $rounds,0($out) | |||||
Lenc_key_abort: | Lenc_key_abort: | ||||
mr r3,$ptr | mr r3,$ptr | ||||
blr | blr | ||||
.long 0 | .long 0 | ||||
.byte 0,12,0x14,1,0,0,3,0 | .byte 0,12,0x14,1,0,0,3,0 | ||||
.long 0 | .long 0 | ||||
.size .${prefix}_set_encrypt_key,.-.${prefix}_set_encrypt_key | .size .${prefix}_set_encrypt_key,.-.${prefix}_set_encrypt_key | ||||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | |||||
.size .${prefix}_set_decrypt_key,.-.${prefix}_set_decrypt_key | .size .${prefix}_set_decrypt_key,.-.${prefix}_set_decrypt_key | ||||
___ | ___ | ||||
}}} | }}} | ||||
######################################################################### | ######################################################################### | ||||
{{{ # Single block en- and decrypt procedures # | {{{ # Single block en- and decrypt procedures # | ||||
sub gen_block () { | sub gen_block () { | ||||
my $dir = shift; | my $dir = shift; | ||||
my $n = $dir eq "de" ? "n" : ""; | my $n = $dir eq "de" ? "n" : ""; | ||||
my $rounds_off = $dir eq "de" ? "240" : "480"; | |||||
my ($inp,$out,$key,$rounds,$idx)=map("r$_",(3..7)); | my ($inp,$out,$key,$rounds,$idx)=map("r$_",(3..7)); | ||||
$code.=<<___; | $code.=<<___; | ||||
.globl .${prefix}_${dir}crypt | .globl .${prefix}_${dir}crypt | ||||
.align 5 | .align 5 | ||||
.${prefix}_${dir}crypt: | .${prefix}_${dir}crypt: | ||||
lwz $rounds,240($key) | lwz $rounds,$rounds_off($key) | ||||
lis r0,0xfc00 | lis r0,0xfc00 | ||||
mfspr $vrsave,256 | mfspr $vrsave,256 | ||||
li $idx,15 # 15 is not typo | li $idx,15 # 15 is not typo | ||||
mtspr 256,r0 | mtspr 256,r0 | ||||
lvx v0,0,$inp | lvx v0,0,$inp | ||||
neg r11,$out | neg r11,$out | ||||
lvx v1,$idx,$inp | lvx v1,$idx,$inp | ||||
▲ Show 20 Lines • Show All 82 Lines • ▼ Show 20 Lines | .${prefix}_cbc_encrypt: | ||||
lvx $ivec,0,$ivp # load [unaligned] iv | lvx $ivec,0,$ivp # load [unaligned] iv | ||||
lvsl $inpperm,0,$ivp | lvsl $inpperm,0,$ivp | ||||
lvx $inptail,$idx,$ivp | lvx $inptail,$idx,$ivp | ||||
le?vxor $inpperm,$inpperm,$tmp | le?vxor $inpperm,$inpperm,$tmp | ||||
vperm $ivec,$ivec,$inptail,$inpperm | vperm $ivec,$ivec,$inptail,$inpperm | ||||
neg r11,$inp | neg r11,$inp | ||||
?lvsl $keyperm,0,$key # prepare for unaligned key | ?lvsl $keyperm,0,$key # prepare for unaligned key | ||||
lwz $rounds,240($key) | lwz $rounds,480($key) | ||||
lvsr $inpperm,0,r11 # prepare for unaligned load | lvsr $inpperm,0,r11 # prepare for unaligned load | ||||
lvx $inptail,0,$inp | lvx $inptail,0,$inp | ||||
addi $inp,$inp,15 # 15 is not typo | addi $inp,$inp,15 # 15 is not typo | ||||
le?vxor $inpperm,$inpperm,$tmp | le?vxor $inpperm,$inpperm,$tmp | ||||
?lvsr $outperm,0,$out # prepare for unaligned store | ?lvsr $outperm,0,$out # prepare for unaligned store | ||||
vspltisb $outmask,-1 | vspltisb $outmask,-1 | ||||
▲ Show 20 Lines • Show All 744 Lines • ▼ Show 20 Lines | .${prefix}_ctr32_encrypt_blocks: | ||||
lvx $inptail,$idx,$ivp | lvx $inptail,$idx,$ivp | ||||
vspltisb $one,1 | vspltisb $one,1 | ||||
le?vxor $inpperm,$inpperm,$tmp | le?vxor $inpperm,$inpperm,$tmp | ||||
vperm $ivec,$ivec,$inptail,$inpperm | vperm $ivec,$ivec,$inptail,$inpperm | ||||
vsldoi $one,$rndkey0,$one,1 | vsldoi $one,$rndkey0,$one,1 | ||||
neg r11,$inp | neg r11,$inp | ||||
?lvsl $keyperm,0,$key # prepare for unaligned key | ?lvsl $keyperm,0,$key # prepare for unaligned key | ||||
lwz $rounds,240($key) | lwz $rounds,480($key) | ||||
lvsr $inpperm,0,r11 # prepare for unaligned load | lvsr $inpperm,0,r11 # prepare for unaligned load | ||||
lvx $inptail,0,$inp | lvx $inptail,0,$inp | ||||
addi $inp,$inp,15 # 15 is not typo | addi $inp,$inp,15 # 15 is not typo | ||||
le?vxor $inpperm,$inpperm,$tmp | le?vxor $inpperm,$inpperm,$tmp | ||||
srwi $rounds,$rounds,1 | srwi $rounds,$rounds,1 | ||||
li $idx,16 | li $idx,16 | ||||
▲ Show 20 Lines • Show All 658 Lines • ▼ Show 20 Lines | .${prefix}_xts_encrypt: | ||||
lvx $inout,0,$inp | lvx $inout,0,$inp | ||||
addi $inp,$inp,15 # 15 is not typo | addi $inp,$inp,15 # 15 is not typo | ||||
le?vxor $inpperm,$inpperm,$tmp | le?vxor $inpperm,$inpperm,$tmp | ||||
${UCMP}i $key2,0 # key2==NULL? | ${UCMP}i $key2,0 # key2==NULL? | ||||
beq Lxts_enc_no_key2 | beq Lxts_enc_no_key2 | ||||
?lvsl $keyperm,0,$key2 # prepare for unaligned key | ?lvsl $keyperm,0,$key2 # prepare for unaligned key | ||||
lwz $rounds,240($key2) | lwz $rounds,480($key2) | ||||
srwi $rounds,$rounds,1 | srwi $rounds,$rounds,1 | ||||
subi $rounds,$rounds,1 | subi $rounds,$rounds,1 | ||||
li $idx,16 | li $idx,16 | ||||
lvx $rndkey0,0,$key2 | lvx $rndkey0,0,$key2 | ||||
lvx $rndkey1,$idx,$key2 | lvx $rndkey1,$idx,$key2 | ||||
addi $idx,$idx,16 | addi $idx,$idx,16 | ||||
?vperm $rndkey0,$rndkey0,$rndkey1,$keyperm | ?vperm $rndkey0,$rndkey0,$rndkey1,$keyperm | ||||
Show All 27 Lines | Lxts_enc_no_key2: | ||||
and $len,$len,$idx # in "tweak chaining" | and $len,$len,$idx # in "tweak chaining" | ||||
# mode only complete | # mode only complete | ||||
# blocks are processed | # blocks are processed | ||||
Lxts_enc: | Lxts_enc: | ||||
lvx $inptail,0,$inp | lvx $inptail,0,$inp | ||||
addi $inp,$inp,16 | addi $inp,$inp,16 | ||||
?lvsl $keyperm,0,$key1 # prepare for unaligned key | ?lvsl $keyperm,0,$key1 # prepare for unaligned key | ||||
lwz $rounds,240($key1) | lwz $rounds,480($key1) | ||||
srwi $rounds,$rounds,1 | srwi $rounds,$rounds,1 | ||||
subi $rounds,$rounds,1 | subi $rounds,$rounds,1 | ||||
li $idx,16 | li $idx,16 | ||||
vslb $eighty7,$seven,$seven # 0x808080..80 | vslb $eighty7,$seven,$seven # 0x808080..80 | ||||
vor $eighty7,$eighty7,$seven # 0x878787..87 | vor $eighty7,$eighty7,$seven # 0x878787..87 | ||||
vspltisb $tmp,1 # 0x010101..01 | vspltisb $tmp,1 # 0x010101..01 | ||||
vsldoi $eighty7,$eighty7,$tmp,15 # 0x870101..01 | vsldoi $eighty7,$eighty7,$tmp,15 # 0x870101..01 | ||||
▲ Show 20 Lines • Show All 1,788 Lines • Show Last 20 Lines |