]>
Commit | Line | Data |
---|---|---|
e0a65194 | 1 | #! /usr/bin/env perl |
33388b44 | 2 | # Copyright 2015-2020 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 | |
18 | die "can't locate arm-xlate.pl"; | |
19 | ||
1aa89a7a RL |
20 | open 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 | |
77f3612e AP |
83 | .globl _armv8_sha512_probe |
84 | .type _armv8_sha512_probe,%function | |
85 | _armv8_sha512_probe: | |
19e277dd | 86 | AARCH64_VALID_CALL_TARGET |
77f3612e AP |
87 | .long 0xcec08000 // sha512su0 v0.2d,v0.2d |
88 | ret | |
89 | .size _armv8_sha512_probe,.-_armv8_sha512_probe | |
90 | ||
5ea64b45 FF |
91 | .globl _armv8_cpuid_probe |
92 | .type _armv8_cpuid_probe,%function | |
93 | _armv8_cpuid_probe: | |
19e277dd | 94 | AARCH64_VALID_CALL_TARGET |
5ea64b45 FF |
95 | mrs x0, midr_el1 |
96 | ret | |
97 | .size _armv8_cpuid_probe,.-_armv8_cpuid_probe | |
98 | ||
6133b4ed AP |
99 | .globl OPENSSL_cleanse |
100 | .type OPENSSL_cleanse,%function | |
101 | .align 5 | |
102 | OPENSSL_cleanse: | |
19e277dd | 103 | AARCH64_VALID_CALL_TARGET |
6133b4ed AP |
104 | cbz x1,.Lret // len==0? |
105 | cmp x1,#15 | |
106 | b.hi .Lot // len>15 | |
107 | nop | |
108 | .Little: | |
109 | strb wzr,[x0],#1 // store byte-by-byte | |
110 | subs x1,x1,#1 | |
111 | b.ne .Little | |
112 | .Lret: ret | |
113 | ||
114 | .align 4 | |
115 | .Lot: tst x0,#7 | |
116 | b.eq .Laligned // inp is aligned | |
117 | strb wzr,[x0],#1 // store byte-by-byte | |
118 | sub x1,x1,#1 | |
119 | b .Lot | |
120 | ||
121 | .align 4 | |
122 | .Laligned: | |
123 | str xzr,[x0],#8 // store word-by-word | |
124 | sub x1,x1,#8 | |
125 | tst x1,#-8 | |
126 | b.ne .Laligned // len>=8 | |
127 | cbnz x1,.Little // len!=0? | |
128 | ret | |
129 | .size OPENSSL_cleanse,.-OPENSSL_cleanse | |
e33826f0 AP |
130 | |
131 | .globl CRYPTO_memcmp | |
132 | .type CRYPTO_memcmp,%function | |
133 | .align 4 | |
134 | CRYPTO_memcmp: | |
19e277dd | 135 | AARCH64_VALID_CALL_TARGET |
e33826f0 AP |
136 | eor w3,w3,w3 |
137 | cbz x2,.Lno_data // len==0? | |
9a708bf9 AP |
138 | cmp x2,#16 |
139 | b.ne .Loop_cmp | |
140 | ldp x8,x9,[x0] | |
141 | ldp x10,x11,[x1] | |
142 | eor x8,x8,x10 | |
143 | eor x9,x9,x11 | |
144 | orr x8,x8,x9 | |
145 | mov x0,#1 | |
146 | cmp x8,#0 | |
147 | csel x0,xzr,x0,eq | |
148 | ret | |
149 | ||
150 | .align 4 | |
e33826f0 AP |
151 | .Loop_cmp: |
152 | ldrb w4,[x0],#1 | |
153 | ldrb w5,[x1],#1 | |
154 | eor w4,w4,w5 | |
155 | orr w3,w3,w4 | |
156 | subs x2,x2,#1 | |
157 | b.ne .Loop_cmp | |
158 | ||
159 | .Lno_data: | |
160 | neg w0,w3 | |
161 | lsr w0,w0,#31 | |
162 | ret | |
163 | .size CRYPTO_memcmp,.-CRYPTO_memcmp | |
efa1f224 OT |
164 | |
165 | .globl _armv8_rng_probe | |
166 | .type _armv8_rng_probe,%function | |
167 | _armv8_rng_probe: | |
168 | mrs x0, s3_3_c2_c4_0 // rndr | |
169 | mrs x0, s3_3_c2_c4_1 // rndrrs | |
170 | ret | |
171 | .size _armv8_rng_probe,.-_armv8_rng_probe | |
172 | ___ | |
173 | ||
174 | sub gen_random { | |
175 | my $rdop = shift; | |
176 | my $rand_reg = $rdop eq "rndr" ? "s3_3_c2_c4_0" : "s3_3_c2_c4_1"; | |
177 | ||
178 | print<<___; | |
179 | // Fill buffer with Randomly Generated Bytes | |
180 | // inputs: char * in x0 - Pointer to buffer | |
181 | // size_t in x1 - Number of bytes to write to buffer | |
182 | // outputs: size_t in x0 - Number of bytes successfully written to buffer | |
183 | .globl OPENSSL_${rdop}_asm | |
184 | .type OPENSSL_${rdop}_asm,%function | |
185 | .align 4 | |
186 | OPENSSL_${rdop}_asm: | |
187 | mov x2,xzr | |
188 | mov x3,xzr | |
189 | ||
190 | .align 4 | |
191 | .Loop_${rdop}: | |
192 | cmp x1,#0 | |
193 | b.eq .${rdop}_done | |
194 | mov x3,xzr | |
195 | mrs x3,$rand_reg | |
196 | b.eq .${rdop}_done | |
197 | ||
198 | cmp x1,#8 | |
199 | b.lt .Loop_single_byte_${rdop} | |
200 | ||
201 | str x3,[x0] | |
202 | add x0,x0,#8 | |
203 | add x2,x2,#8 | |
204 | subs x1,x1,#8 | |
205 | b.ge .Loop_${rdop} | |
206 | ||
207 | .align 4 | |
208 | .Loop_single_byte_${rdop}: | |
209 | strb w3,[x0] | |
210 | lsr x3,x3,#8 | |
211 | add x2,x2,#1 | |
212 | add x0,x0,#1 | |
213 | subs x1,x1,#1 | |
214 | b.gt .Loop_single_byte_${rdop} | |
215 | ||
216 | .align 4 | |
217 | .${rdop}_done: | |
218 | mov x0,x2 | |
219 | ret | |
220 | .size OPENSSL_${rdop}_asm,.-OPENSSL_${rdop}_asm | |
9b05cbc3 | 221 | ___ |
efa1f224 OT |
222 | } |
223 | gen_random("rndr"); | |
224 | gen_random("rndrrs"); | |
9b05cbc3 AP |
225 | |
226 | print $code; | |
a21314db | 227 | close STDOUT or die "error closing STDOUT: $!"; |