summaryrefslogtreecommitdiffstats
path: root/src/crypto/rand/hwrand.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/crypto/rand/hwrand.c')
-rw-r--r--src/crypto/rand/hwrand.c21
1 files changed, 11 insertions, 10 deletions
diff --git a/src/crypto/rand/hwrand.c b/src/crypto/rand/hwrand.c
index 5f81f09..f0bbccd 100644
--- a/src/crypto/rand/hwrand.c
+++ b/src/crypto/rand/hwrand.c
@@ -15,23 +15,28 @@
#include <openssl/rand.h>
#include <assert.h>
-#include <stdlib.h>
#include <string.h>
#include <openssl/cpu.h>
+#include "internal.h"
-#if defined(OPENSSL_X86_64) && !defined(OPENSSL_NO_ASM)
-int CRYPTO_have_hwrand(void) {
- return (OPENSSL_ia32cap_P[1] & (1u << 30)) != 0;
-}
+#if defined(OPENSSL_X86_64) && !defined(OPENSSL_NO_ASM)
/* These functions are defined in asm/rdrand-x86_64.pl */
extern int CRYPTO_rdrand(uint8_t out[8]);
extern int CRYPTO_rdrand_multiple8_buf(uint8_t *buf, size_t len);
+static int have_rdrand(void) {
+ return (OPENSSL_ia32cap_P[1] & (1u << 30)) != 0;
+}
+
int CRYPTO_hwrand(uint8_t *buf, size_t len) {
+ if (!have_rdrand()) {
+ return 0;
+ }
+
const size_t len_multiple8 = len & ~7;
if (!CRYPTO_rdrand_multiple8_buf(buf, len_multiple8)) {
return 0;
@@ -53,12 +58,8 @@ int CRYPTO_hwrand(uint8_t *buf, size_t len) {
#else
-int CRYPTO_have_hwrand(void) {
+int CRYPTO_hwrand(uint8_t *buf, size_t len) {
return 0;
}
-void CRYPTO_hwrand(uint8_t *buf, size_t len) {
- abort();
-}
-
#endif