Use RAND_DRBG_bytes() for RAND_bytes() and RAND_priv_bytes()
[openssl.git] / crypto / pariscid.pl
1 #! /usr/bin/env perl
2 # Copyright 2009-2016 The OpenSSL Project Authors. All Rights Reserved.
3 #
4 # Licensed under the OpenSSL license (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
8
9
10 $flavour = shift;
11 $output = shift;
12 open STDOUT,">$output";
13
14 if ($flavour =~ /64/) {
15         $LEVEL          ="2.0W";
16         $SIZE_T         =8;
17         $ST             ="std";
18 } else {
19         $LEVEL          ="1.1";
20         $SIZE_T         =4;
21         $ST             ="stw";
22 }
23
24 $rp="%r2";
25 $sp="%r30";
26 $rv="%r28";
27
28 $code=<<___;
29         .LEVEL  $LEVEL
30         .SPACE  \$TEXT\$
31         .SUBSPA \$CODE\$,QUAD=0,ALIGN=8,ACCESS=0x2C,CODE_ONLY
32
33         .EXPORT OPENSSL_cpuid_setup,ENTRY
34         .ALIGN  8
35 OPENSSL_cpuid_setup
36         .PROC
37         .CALLINFO       NO_CALLS
38         .ENTRY
39         bv      ($rp)
40         .EXIT
41         nop
42         .PROCEND
43
44         .EXPORT OPENSSL_rdtsc,ENTRY
45         .ALIGN  8
46 OPENSSL_rdtsc
47         .PROC
48         .CALLINFO       NO_CALLS
49         .ENTRY
50         mfctl   %cr16,$rv
51         bv      ($rp)
52         .EXIT
53         nop
54         .PROCEND
55
56         .EXPORT OPENSSL_wipe_cpu,ENTRY
57         .ALIGN  8
58 OPENSSL_wipe_cpu
59         .PROC
60         .CALLINFO       NO_CALLS
61         .ENTRY
62         xor             %r0,%r0,%r1
63         fcpy,dbl        %fr0,%fr4
64         xor             %r0,%r0,%r19
65         fcpy,dbl        %fr0,%fr5
66         xor             %r0,%r0,%r20
67         fcpy,dbl        %fr0,%fr6
68         xor             %r0,%r0,%r21
69         fcpy,dbl        %fr0,%fr7
70         xor             %r0,%r0,%r22
71         fcpy,dbl        %fr0,%fr8
72         xor             %r0,%r0,%r23
73         fcpy,dbl        %fr0,%fr9
74         xor             %r0,%r0,%r24
75         fcpy,dbl        %fr0,%fr10
76         xor             %r0,%r0,%r25
77         fcpy,dbl        %fr0,%fr11
78         xor             %r0,%r0,%r26
79         fcpy,dbl        %fr0,%fr22
80         xor             %r0,%r0,%r29
81         fcpy,dbl        %fr0,%fr23
82         xor             %r0,%r0,%r31
83         fcpy,dbl        %fr0,%fr24
84         fcpy,dbl        %fr0,%fr25
85         fcpy,dbl        %fr0,%fr26
86         fcpy,dbl        %fr0,%fr27
87         fcpy,dbl        %fr0,%fr28
88         fcpy,dbl        %fr0,%fr29
89         fcpy,dbl        %fr0,%fr30
90         fcpy,dbl        %fr0,%fr31
91         bv              ($rp)
92         .EXIT
93         ldo             0($sp),$rv
94         .PROCEND
95 ___
96 {
97 my $inp="%r26";
98 my $len="%r25";
99
100 $code.=<<___;
101         .EXPORT OPENSSL_cleanse,ENTRY,ARGW0=GR,ARGW1=GR
102         .ALIGN  8
103 OPENSSL_cleanse
104         .PROC
105         .CALLINFO       NO_CALLS
106         .ENTRY
107         cmpib,*=        0,$len,L\$done
108         nop
109         cmpib,*>>=      15,$len,L\$ittle
110         ldi             $SIZE_T-1,%r1
111
112 L\$align
113         and,*<>         $inp,%r1,%r28
114         b,n             L\$aligned
115         stb             %r0,0($inp)
116         ldo             -1($len),$len
117         b               L\$align
118         ldo             1($inp),$inp
119
120 L\$aligned
121         andcm           $len,%r1,%r28
122 L\$ot
123         $ST             %r0,0($inp)
124         addib,*<>       -$SIZE_T,%r28,L\$ot
125         ldo             $SIZE_T($inp),$inp
126
127         and,*<>         $len,%r1,$len
128         b,n             L\$done
129 L\$ittle
130         stb             %r0,0($inp)
131         addib,*<>       -1,$len,L\$ittle
132         ldo             1($inp),$inp
133 L\$done
134         bv              ($rp)
135         .EXIT
136         nop
137         .PROCEND
138 ___
139 }
140 {
141 my ($in1,$in2,$len)=("%r26","%r25","%r24");
142
143 $code.=<<___;
144         .EXPORT CRYPTO_memcmp,ENTRY,ARGW0=GR,ARGW1=GR,ARGW1=GR
145         .ALIGN  8
146 CRYPTO_memcmp
147         .PROC
148         .CALLINFO       NO_CALLS
149         .ENTRY
150         cmpib,*=        0,$len,L\$no_data
151         xor             $rv,$rv,$rv
152
153 L\$oop_cmp
154         ldb             0($in1),%r19
155         ldb             0($in2),%r20
156         ldo             1($in1),$in1
157         ldo             1($in2),$in2
158         xor             %r19,%r20,%r29
159         addib,*<>       -1,$len,L\$oop_cmp
160         or              %r29,$rv,$rv
161
162         sub             %r0,$rv,%r29
163         extru           %r29,31,1,$rv
164 L\$no_data
165         bv              ($rp)
166         .EXIT
167         nop
168         .PROCEND
169 ___
170 }
171 {
172 my ($out,$cnt,$max)=("%r26","%r25","%r24");
173 my ($tick,$lasttick)=("%r23","%r22");
174 my ($diff,$lastdiff)=("%r21","%r20");
175
176 $code.=<<___;
177         .EXPORT OPENSSL_instrument_bus,ENTRY,ARGW0=GR,ARGW1=GR
178         .ALIGN  8
179 OPENSSL_instrument_bus
180         .PROC
181         .CALLINFO       NO_CALLS
182         .ENTRY
183         copy            $cnt,$rv
184         mfctl           %cr16,$tick
185         copy            $tick,$lasttick
186         ldi             0,$diff
187
188         fdc             0($out)
189         ldw             0($out),$tick
190         add             $diff,$tick,$tick
191         stw             $tick,0($out)
192 L\$oop
193         mfctl           %cr16,$tick
194         sub             $tick,$lasttick,$diff
195         copy            $tick,$lasttick
196
197         fdc             0($out)
198         ldw             0($out),$tick
199         add             $diff,$tick,$tick
200         stw             $tick,0($out)
201
202         addib,<>        -1,$cnt,L\$oop
203         addi            4,$out,$out
204
205         bv              ($rp)
206         .EXIT
207         sub             $rv,$cnt,$rv
208         .PROCEND
209
210         .EXPORT OPENSSL_instrument_bus2,ENTRY,ARGW0=GR,ARGW1=GR
211         .ALIGN  8
212 OPENSSL_instrument_bus2
213         .PROC
214         .CALLINFO       NO_CALLS
215         .ENTRY
216         copy            $cnt,$rv
217         sub             %r0,$cnt,$cnt
218
219         mfctl           %cr16,$tick
220         copy            $tick,$lasttick
221         ldi             0,$diff
222
223         fdc             0($out)
224         ldw             0($out),$tick
225         add             $diff,$tick,$tick
226         stw             $tick,0($out)
227
228         mfctl           %cr16,$tick
229         sub             $tick,$lasttick,$diff
230         copy            $tick,$lasttick
231 L\$oop2
232         copy            $diff,$lastdiff
233         fdc             0($out)
234         ldw             0($out),$tick
235         add             $diff,$tick,$tick
236         stw             $tick,0($out)
237
238         addib,=         -1,$max,L\$done2
239         nop
240
241         mfctl           %cr16,$tick
242         sub             $tick,$lasttick,$diff
243         copy            $tick,$lasttick
244         cmpclr,<>       $lastdiff,$diff,$tick
245         ldi             1,$tick
246
247         ldi             1,%r1
248         xor             %r1,$tick,$tick
249         addb,<>         $tick,$cnt,L\$oop2
250         shladd,l        $tick,2,$out,$out
251 L\$done2
252         bv              ($rp)
253         .EXIT
254         add             $rv,$cnt,$rv
255         .PROCEND
256 ___
257 }
258 $code =~ s/cmpib,\*/comib,/gm   if ($SIZE_T==4);
259 $code =~ s/,\*/,/gm             if ($SIZE_T==4);
260 $code =~ s/\bbv\b/bve/gm        if ($SIZE_T==8);
261 print $code;
262 close STDOUT;
263