2 * Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (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
10 #include <openssl/crypto.h>
11 #include "crypto/rand.h"
12 #include "crypto/dso_conf.h"
13 #include "internal/thread_once.h"
14 #include "internal/cryptlib.h"
18 #if defined(__arm__) || defined(__arm) || defined(__aarch64__)
19 # include "arm_arch.h"
22 /* extern declaration to avoid warning */
23 extern char ossl_cpu_info_str[];
25 static char *seed_sources = NULL;
27 char ossl_cpu_info_str[128] = "";
28 #define CPUINFO_PREFIX "CPUINFO: "
30 static CRYPTO_ONCE init_info = CRYPTO_ONCE_STATIC_INIT;
32 DEFINE_RUN_ONCE_STATIC(init_info_strings)
34 #if defined(OPENSSL_CPUID_OBJ)
35 # if defined(__i386) || defined(__i386__) || defined(_M_IX86) || \
36 defined(__x86_64) || defined(__x86_64__) || \
37 defined(_M_AMD64) || defined(_M_X64)
40 BIO_snprintf(ossl_cpu_info_str, sizeof(ossl_cpu_info_str),
41 CPUINFO_PREFIX "OPENSSL_ia32cap=0x%llx:0x%llx",
42 (long long)OPENSSL_ia32cap_P[0] |
43 (long long)OPENSSL_ia32cap_P[1] << 32,
44 (long long)OPENSSL_ia32cap_P[2] |
45 (long long)OPENSSL_ia32cap_P[3] << 32);
46 if ((env = getenv("OPENSSL_ia32cap")) != NULL)
47 BIO_snprintf(ossl_cpu_info_str + strlen(ossl_cpu_info_str),
48 sizeof(ossl_cpu_info_str) - strlen(ossl_cpu_info_str),
50 # elif defined(__arm__) || defined(__arm) || defined(__aarch64__)
53 BIO_snprintf(ossl_cpu_info_str, sizeof(ossl_cpu_info_str),
54 CPUINFO_PREFIX "OPENSSL_armcap=0x%x", OPENSSL_armcap_P);
55 if ((env = getenv("OPENSSL_armcap")) != NULL)
56 BIO_snprintf(ossl_cpu_info_str + strlen(ossl_cpu_info_str),
57 sizeof(ossl_cpu_info_str) - strlen(ossl_cpu_info_str),
63 static char seeds[512] = "";
65 #define add_seeds_string(str) \
67 if (seeds[0] != '\0') \
68 OPENSSL_strlcat(seeds, " ", sizeof(seeds)); \
69 OPENSSL_strlcat(seeds, str, sizeof(seeds)); \
71 #define add_seeds_stringlist(label, strlist) \
73 add_seeds_string(label "("); \
75 const char *dev[] = strlist; \
78 for (; *dev != NULL; dev++) { \
80 OPENSSL_strlcat(seeds, " ", sizeof(seeds)); \
82 OPENSSL_strlcat(seeds, *dev, sizeof(seeds)); \
85 OPENSSL_strlcat(seeds, ")", sizeof(seeds)); \
88 #ifdef OPENSSL_RAND_SEED_NONE
89 add_seeds_string("none");
91 #ifdef OPENSSL_RAND_SEED_RTDSC
92 add_seeds_string("stdsc");
94 #ifdef OPENSSL_RAND_SEED_RDCPU
95 add_seeds_string("rdrand ( rdseed rdrand )");
97 #ifdef OPENSSL_RAND_SEED_LIBRANDOM
98 add_seeds_string("C-library-random");
100 #ifdef OPENSSL_RAND_SEED_GETRANDOM
101 add_seeds_string("getrandom-syscall");
103 #ifdef OPENSSL_RAND_SEED_DEVRANDOM
104 add_seeds_stringlist("random-device", { DEVRANDOM, NULL });
106 #ifdef OPENSSL_RAND_SEED_EGD
107 add_seeds_stringlist("EGD", { DEVRANDOM_EGD, NULL });
109 #ifdef OPENSSL_RAND_SEED_OS
110 add_seeds_string("os-specific");
112 seed_sources = seeds;
117 const char *OPENSSL_info(int t)
120 * We don't care about the result. Worst case scenario, the strings
121 * won't be initialised, i.e. remain NULL, which means that the info
122 * isn't available anyway...
124 (void)RUN_ONCE(&init_info, init_info_strings);
127 case OPENSSL_INFO_CONFIG_DIR:
129 case OPENSSL_INFO_ENGINES_DIR:
131 case OPENSSL_INFO_MODULES_DIR:
133 case OPENSSL_INFO_DSO_EXTENSION:
134 return DSO_EXTENSION;
135 case OPENSSL_INFO_DIR_FILENAME_SEPARATOR:
140 #else /* Assume POSIX */
143 case OPENSSL_INFO_LIST_SEPARATOR:
145 static const char list_sep[] = { LIST_SEPARATOR_CHAR, '\0' };
148 case OPENSSL_INFO_SEED_SOURCE:
150 case OPENSSL_INFO_CPU_SETTINGS:
152 * If successfully initialized, ossl_cpu_info_str will start
153 * with CPUINFO_PREFIX, if failed it will be an empty string.
154 * Strip away the CPUINFO_PREFIX which we don't need here.
156 if (ossl_cpu_info_str[0] != '\0')
157 return ossl_cpu_info_str + strlen(CPUINFO_PREFIX);