summaryrefslogtreecommitdiffstats
path: root/crypto/arm64cpuid.pl
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/arm64cpuid.pl')
-rwxr-xr-xcrypto/arm64cpuid.pl60
1 files changed, 60 insertions, 0 deletions
diff --git a/crypto/arm64cpuid.pl b/crypto/arm64cpuid.pl
index 11f0e50279..a86fa6073a 100755
--- a/crypto/arm64cpuid.pl
+++ b/crypto/arm64cpuid.pl
@@ -161,7 +161,67 @@ CRYPTO_memcmp:
lsr w0,w0,#31
ret
.size CRYPTO_memcmp,.-CRYPTO_memcmp
+
+.globl _armv8_rng_probe
+.type _armv8_rng_probe,%function
+_armv8_rng_probe:
+ mrs x0, s3_3_c2_c4_0 // rndr
+ mrs x0, s3_3_c2_c4_1 // rndrrs
+ ret
+.size _armv8_rng_probe,.-_armv8_rng_probe
+___
+
+sub gen_random {
+my $rdop = shift;
+my $rand_reg = $rdop eq "rndr" ? "s3_3_c2_c4_0" : "s3_3_c2_c4_1";
+
+print<<___;
+// Fill buffer with Randomly Generated Bytes
+// inputs: char * in x0 - Pointer to buffer
+// size_t in x1 - Number of bytes to write to buffer
+// outputs: size_t in x0 - Number of bytes successfully written to buffer
+.globl OPENSSL_${rdop}_asm
+.type OPENSSL_${rdop}_asm,%function
+.align 4
+OPENSSL_${rdop}_asm:
+ mov x2,xzr
+ mov x3,xzr
+
+.align 4
+.Loop_${rdop}:
+ cmp x1,#0
+ b.eq .${rdop}_done
+ mov x3,xzr
+ mrs x3,$rand_reg
+ b.eq .${rdop}_done
+
+ cmp x1,#8
+ b.lt .Loop_single_byte_${rdop}
+
+ str x3,[x0]
+ add x0,x0,#8
+ add x2,x2,#8
+ subs x1,x1,#8
+ b.ge .Loop_${rdop}
+
+.align 4
+.Loop_single_byte_${rdop}:
+ strb w3,[x0]
+ lsr x3,x3,#8
+ add x2,x2,#1
+ add x0,x0,#1
+ subs x1,x1,#1
+ b.gt .Loop_single_byte_${rdop}
+
+.align 4
+.${rdop}_done:
+ mov x0,x2
+ ret
+.size OPENSSL_${rdop}_asm,.-OPENSSL_${rdop}_asm
___
+}
+gen_random("rndr");
+gen_random("rndrrs");
print $code;
close STDOUT or die "error closing STDOUT: $!";