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/. | ||||
| Context not available. | |||||
| } 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: $!"; | ||||
| Context not available. | |||||
| 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 | ||||
| Context not available. | |||||
| ######################################################################### | ######################################################################### | ||||
| {{{ # 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 | ||||
| Context not available. | |||||
| 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 | ||||
| Context not available. | |||||
| 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 | ||||
| Context not available. | |||||
| ${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 | ||||
| Context not available. | |||||
| 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 | ||||
| Context not available. | |||||