]> git.ipfire.org Git - thirdparty/openssl.git/blame - crypto/arm64cpuid.pl
rand: remove unimplemented librandom stub code
[thirdparty/openssl.git] / crypto / arm64cpuid.pl
CommitLineData
e0a65194 1#! /usr/bin/env perl
fecb3aae 2# Copyright 2015-2022 The OpenSSL Project Authors. All Rights Reserved.
e0a65194 3#
0e9725bc 4# Licensed under the Apache License 2.0 (the "License"). You may not use
e0a65194
RS
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
9b05cbc3 9
1aa89a7a
RL
10# $output is the last argument if it looks like a file (it has an extension)
11# $flavour is the first argument if it doesn't look like a file
12$output = $#ARGV >= 0 && $ARGV[$#ARGV] =~ m|\.\w+$| ? pop : undef;
13$flavour = $#ARGV >= 0 && $ARGV[0] !~ m|\.| ? shift : undef;
9b05cbc3
AP
14
15$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
16( $xlate="${dir}arm-xlate.pl" and -f $xlate ) or
17( $xlate="${dir}perlasm/arm-xlate.pl" and -f $xlate) or
18die "can't locate arm-xlate.pl";
19
1aa89a7a
RL
20open OUT,"| \"$^X\" $xlate $flavour \"$output\""
21 or die "can't call $xlate: $!";
9b05cbc3
AP
22*STDOUT=*OUT;
23
24$code.=<<___;
e8d93e34
AP
25#include "arm_arch.h"
26
27.text
28.arch armv8-a+crypto
29
30.align 5
9b05cbc3 31.globl _armv7_neon_probe
e8d93e34
AP
32.type _armv7_neon_probe,%function
33_armv7_neon_probe:
19e277dd 34 AARCH64_VALID_CALL_TARGET
e8d93e34
AP
35 orr v15.16b, v15.16b, v15.16b
36 ret
37.size _armv7_neon_probe,.-_armv7_neon_probe
38
9b05cbc3 39.globl _armv7_tick
e8d93e34
AP
40.type _armv7_tick,%function
41_armv7_tick:
19e277dd 42 AARCH64_VALID_CALL_TARGET
9b05cbc3
AP
43#ifdef __APPLE__
44 mrs x0, CNTPCT_EL0
45#else
e8d93e34 46 mrs x0, CNTVCT_EL0
9b05cbc3 47#endif
e8d93e34
AP
48 ret
49.size _armv7_tick,.-_armv7_tick
50
9b05cbc3 51.globl _armv8_aes_probe
e8d93e34
AP
52.type _armv8_aes_probe,%function
53_armv8_aes_probe:
19e277dd 54 AARCH64_VALID_CALL_TARGET
e8d93e34
AP
55 aese v0.16b, v0.16b
56 ret
57.size _armv8_aes_probe,.-_armv8_aes_probe
58
9b05cbc3 59.globl _armv8_sha1_probe
e8d93e34
AP
60.type _armv8_sha1_probe,%function
61_armv8_sha1_probe:
19e277dd 62 AARCH64_VALID_CALL_TARGET
e8d93e34
AP
63 sha1h s0, s0
64 ret
65.size _armv8_sha1_probe,.-_armv8_sha1_probe
66
9b05cbc3 67.globl _armv8_sha256_probe
e8d93e34
AP
68.type _armv8_sha256_probe,%function
69_armv8_sha256_probe:
19e277dd 70 AARCH64_VALID_CALL_TARGET
e8d93e34
AP
71 sha256su0 v0.4s, v0.4s
72 ret
73.size _armv8_sha256_probe,.-_armv8_sha256_probe
77f3612e 74
9b05cbc3 75.globl _armv8_pmull_probe
e8d93e34
AP
76.type _armv8_pmull_probe,%function
77_armv8_pmull_probe:
19e277dd 78 AARCH64_VALID_CALL_TARGET
e8d93e34
AP
79 pmull v0.1q, v0.1d, v0.1d
80 ret
81.size _armv8_pmull_probe,.-_armv8_pmull_probe
6133b4ed 82
15b7175f
DH
83.globl _armv8_sm4_probe
84.type _armv8_sm4_probe,%function
85_armv8_sm4_probe:
86 AARCH64_VALID_CALL_TARGET
4d63eaf9 87 .inst 0xcec08400 // sm4e v0.4s, v0.4s
15b7175f
DH
88 ret
89.size _armv8_sm4_probe,.-_armv8_sm4_probe
90
77f3612e
AP
91.globl _armv8_sha512_probe
92.type _armv8_sha512_probe,%function
93_armv8_sha512_probe:
19e277dd 94 AARCH64_VALID_CALL_TARGET
4d63eaf9 95 .inst 0xcec08000 // sha512su0 v0.2d,v0.2d
77f3612e
AP
96 ret
97.size _armv8_sha512_probe,.-_armv8_sha512_probe
98
954f45ba
X
99.globl _armv8_eor3_probe
100.type _armv8_eor3_probe,%function
101_armv8_eor3_probe:
102 AARCH64_VALID_CALL_TARGET
4d63eaf9 103 .inst 0xce010800 // eor3 v0.16b, v0.16b, v1.16b, v2.16b
954f45ba
X
104 ret
105.size _armv8_eor3_probe,.-_armv8_eor3_probe
106
b1b2146d
DH
107.globl _armv8_sve_probe
108.type _armv8_sve_probe,%function
109_armv8_sve_probe:
110 AARCH64_VALID_CALL_TARGET
111 .inst 0x04a03000 // eor z0.d,z0.d,z0.d
112 ret
113.size _armv8_sve_probe,.-_armv8_sve_probe
114
115.globl _armv8_sve2_probe
116.type _armv8_sve2_probe,%function
117_armv8_sve2_probe:
118 AARCH64_VALID_CALL_TARGET
119 .inst 0x04e03400 // xar z0.d,z0.d,z0.d
120 ret
121.size _armv8_sve2_probe,.-_armv8_sve2_probe
122
5ea64b45
FF
123.globl _armv8_cpuid_probe
124.type _armv8_cpuid_probe,%function
125_armv8_cpuid_probe:
19e277dd 126 AARCH64_VALID_CALL_TARGET
5ea64b45
FF
127 mrs x0, midr_el1
128 ret
129.size _armv8_cpuid_probe,.-_armv8_cpuid_probe
130
71396cd0 131.globl _armv8_sm3_probe
132.type _armv8_sm3_probe,%function
133_armv8_sm3_probe:
134 AARCH64_VALID_CALL_TARGET
4d63eaf9 135 .inst 0xce63c004 // sm3partw1 v4.4s, v0.4s, v3.4s
71396cd0 136 ret
137.size _armv8_sm3_probe,.-_armv8_sm3_probe
138
6133b4ed
AP
139.globl OPENSSL_cleanse
140.type OPENSSL_cleanse,%function
141.align 5
142OPENSSL_cleanse:
19e277dd 143 AARCH64_VALID_CALL_TARGET
6133b4ed
AP
144 cbz x1,.Lret // len==0?
145 cmp x1,#15
146 b.hi .Lot // len>15
147 nop
148.Little:
149 strb wzr,[x0],#1 // store byte-by-byte
150 subs x1,x1,#1
151 b.ne .Little
152.Lret: ret
153
154.align 4
155.Lot: tst x0,#7
156 b.eq .Laligned // inp is aligned
157 strb wzr,[x0],#1 // store byte-by-byte
158 sub x1,x1,#1
159 b .Lot
160
161.align 4
162.Laligned:
163 str xzr,[x0],#8 // store word-by-word
164 sub x1,x1,#8
165 tst x1,#-8
166 b.ne .Laligned // len>=8
167 cbnz x1,.Little // len!=0?
168 ret
169.size OPENSSL_cleanse,.-OPENSSL_cleanse
e33826f0
AP
170
171.globl CRYPTO_memcmp
172.type CRYPTO_memcmp,%function
173.align 4
174CRYPTO_memcmp:
19e277dd 175 AARCH64_VALID_CALL_TARGET
e33826f0
AP
176 eor w3,w3,w3
177 cbz x2,.Lno_data // len==0?
9a708bf9
AP
178 cmp x2,#16
179 b.ne .Loop_cmp
180 ldp x8,x9,[x0]
181 ldp x10,x11,[x1]
182 eor x8,x8,x10
183 eor x9,x9,x11
184 orr x8,x8,x9
185 mov x0,#1
186 cmp x8,#0
187 csel x0,xzr,x0,eq
188 ret
189
190.align 4
e33826f0
AP
191.Loop_cmp:
192 ldrb w4,[x0],#1
193 ldrb w5,[x1],#1
194 eor w4,w4,w5
195 orr w3,w3,w4
196 subs x2,x2,#1
197 b.ne .Loop_cmp
198
199.Lno_data:
200 neg w0,w3
201 lsr w0,w0,#31
202 ret
203.size CRYPTO_memcmp,.-CRYPTO_memcmp
efa1f224
OT
204
205.globl _armv8_rng_probe
206.type _armv8_rng_probe,%function
207_armv8_rng_probe:
3a23f012 208 AARCH64_VALID_CALL_TARGET
efa1f224
OT
209 mrs x0, s3_3_c2_c4_0 // rndr
210 mrs x0, s3_3_c2_c4_1 // rndrrs
211 ret
212.size _armv8_rng_probe,.-_armv8_rng_probe
213___
214
215sub gen_random {
216my $rdop = shift;
217my $rand_reg = $rdop eq "rndr" ? "s3_3_c2_c4_0" : "s3_3_c2_c4_1";
218
3a23f012 219return <<___;
efa1f224
OT
220// Fill buffer with Randomly Generated Bytes
221// inputs: char * in x0 - Pointer to buffer
222// size_t in x1 - Number of bytes to write to buffer
223// outputs: size_t in x0 - Number of bytes successfully written to buffer
224.globl OPENSSL_${rdop}_asm
225.type OPENSSL_${rdop}_asm,%function
226.align 4
227OPENSSL_${rdop}_asm:
3a23f012 228 AARCH64_VALID_CALL_TARGET
efa1f224
OT
229 mov x2,xzr
230 mov x3,xzr
231
232.align 4
233.Loop_${rdop}:
234 cmp x1,#0
235 b.eq .${rdop}_done
236 mov x3,xzr
237 mrs x3,$rand_reg
238 b.eq .${rdop}_done
239
240 cmp x1,#8
241 b.lt .Loop_single_byte_${rdop}
242
243 str x3,[x0]
244 add x0,x0,#8
245 add x2,x2,#8
246 subs x1,x1,#8
247 b.ge .Loop_${rdop}
248
249.align 4
250.Loop_single_byte_${rdop}:
251 strb w3,[x0]
252 lsr x3,x3,#8
253 add x2,x2,#1
254 add x0,x0,#1
255 subs x1,x1,#1
256 b.gt .Loop_single_byte_${rdop}
257
258.align 4
259.${rdop}_done:
260 mov x0,x2
261 ret
262.size OPENSSL_${rdop}_asm,.-OPENSSL_${rdop}_asm
9b05cbc3 263___
efa1f224 264}
3a23f012
TC
265
266$code .= gen_random("rndr");
267$code .= gen_random("rndrrs");
9b05cbc3
AP
268
269print $code;
a21314db 270close STDOUT or die "error closing STDOUT: $!";