2 # Copyright 2009-2016 The OpenSSL Project Authors. All Rights Reserved.
4 # Licensed under the Apache License 2.0 (the "License"). You may not use
5 # this file except in compliance with the License. You can obtain a copy
6 # in the file LICENSE in the source distribution or at
7 # https://www.openssl.org/source/license.html
10 # ====================================================================
11 # Written by Andy Polyakov <appro@openssl.org> for the OpenSSL
12 # project. The module is, however, dual licensed under OpenSSL and
13 # CRYPTOGAMS licenses depending on where you obtain it. For further
14 # details see http://www.openssl.org/~appro/cryptogams/.
15 # ====================================================================
19 # Performance is 2x of gcc 3.4.6 on z10. Coding "secret" is to
20 # "cluster" Address Generation Interlocks, so that one pipeline stall
21 # resolves several dependencies.
25 # Adapt for -m31 build. If kernel supports what's called "highgprs"
26 # feature on Linux [see /proc/cpuinfo], it's possible to use 64-bit
27 # instructions and achieve "64-bit" performance even in 31-bit legacy
28 # application context. The feature is not specific to any particular
29 # processor, as long as it's "z-CPU". Latter implies that the code
30 # remains z/Architecture specific. On z990 it was measured to perform
31 # 50% better than code generated by gcc 4.3.
33 # $output is the last argument if it looks like a file (it has an extension)
34 # $flavour is the first argument if it doesn't look like a file
35 $output = $#ARGV >= 0 && $ARGV[$#ARGV] =~ m|\.\w+$| ? pop : undef;
36 $flavour = $#ARGV >= 0 && $ARGV[0] !~ m|\.| ? shift : undef;
38 if ($flavour =~ /3[12]/) {
46 $output and open STDOUT,">$output";
55 # void RC4(RC4_KEY *key,size_t len,const void *inp,void *out)
74 stm${g} %r6,%r11,6*$SIZE_T($sp)
76 $code.=<<___ if ($flavour =~ /3[12]/);
86 llgc $TX[0],2($XX[0],$key)
93 for ($i=0;$i<8;$i++) {
95 la $YY,0($YY,$TX[0]) # $i
100 $code.=<<___ if ($i==1);
101 llgc $acc,2($TY,$key)
103 $code.=<<___ if ($i>1);
109 stc $TX[0],2($YY,$key)
110 llgc $TX[1],2($XX[1],$key)
111 stc $TY,2($XX[0],$key)
119 push(@TX,shift(@TX)); push(@XX,shift(@XX)); # "rotate" registers
143 stc $TX[0],2($YY,$key)
144 stc $TY,2($XX[0],$key)
152 llgc $TX[0],2($XX[0],$key)
162 lm${g} %r6,%r11,6*$SIZE_T($sp)
165 .string "RC4 for s390x, CRYPTOGAMS by <appro\@openssl.org>"
170 # void RC4_set_key(RC4_KEY *key,unsigned int len,const void *inp)
184 .type RC4_set_key,\@function
187 stm${g} %r6,%r8,6*$SIZE_T($sp)
193 stc $idx,2($idx,$key)
203 llgc $acc,2+256($ikey,$key)
204 llgc $dat,0($iinp,$inp)
211 llgc $dat,2($idx,$key)
212 stc $dat,2+256-1($ikey,$key)
213 stc $acc,2($idx,$key)
220 lm${g} %r6,%r8,6*$SIZE_T($sp)
222 .size RC4_set_key,.-RC4_set_key
227 # const char *RC4_options()
230 .type RC4_options,\@function
235 .size RC4_options,.-RC4_options
239 .string "rc4(8x,char)"
243 close STDOUT or die "error closing STDOUT"; # force flush