2 * Copyright 2019-2020 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, NULL }; \
79 for (p = dev; *p != NULL; p++) { \
81 OPENSSL_strlcat(seeds, " ", sizeof(seeds)); \
83 OPENSSL_strlcat(seeds, *p, sizeof(seeds)); \
86 OPENSSL_strlcat(seeds, ")", sizeof(seeds)); \
89 #ifdef OPENSSL_RAND_SEED_NONE
90 add_seeds_string("none");
92 #ifdef OPENSSL_RAND_SEED_RTDSC
93 add_seeds_string("stdsc");
95 #ifdef OPENSSL_RAND_SEED_RDCPU
96 add_seeds_string("rdrand ( rdseed rdrand )");
98 #ifdef OPENSSL_RAND_SEED_LIBRANDOM
99 add_seeds_string("C-library-random");
101 #ifdef OPENSSL_RAND_SEED_GETRANDOM
102 add_seeds_string("getrandom-syscall");
104 #ifdef OPENSSL_RAND_SEED_DEVRANDOM
105 add_seeds_stringlist("random-device", DEVRANDOM);
107 #ifdef OPENSSL_RAND_SEED_EGD
108 add_seeds_stringlist("EGD", DEVRANDOM_EGD);
110 #ifdef OPENSSL_RAND_SEED_OS
111 add_seeds_string("os-specific");
113 seed_sources = seeds;
118 const char *OPENSSL_info(int t)
121 * We don't care about the result. Worst case scenario, the strings
122 * won't be initialised, i.e. remain NULL, which means that the info
123 * isn't available anyway...
125 (void)RUN_ONCE(&init_info, init_info_strings);
128 case OPENSSL_INFO_CONFIG_DIR:
130 case OPENSSL_INFO_ENGINES_DIR:
132 case OPENSSL_INFO_MODULES_DIR:
134 case OPENSSL_INFO_DSO_EXTENSION:
135 return DSO_EXTENSION;
136 case OPENSSL_INFO_DIR_FILENAME_SEPARATOR:
141 #else /* Assume POSIX */
144 case OPENSSL_INFO_LIST_SEPARATOR:
146 static const char list_sep[] = { LIST_SEPARATOR_CHAR, '\0' };
149 case OPENSSL_INFO_SEED_SOURCE:
151 case OPENSSL_INFO_CPU_SETTINGS:
153 * If successfully initialized, ossl_cpu_info_str will start
154 * with CPUINFO_PREFIX, if failed it will be an empty string.
155 * Strip away the CPUINFO_PREFIX which we don't need here.
157 if (ossl_cpu_info_str[0] != '\0')
158 return ossl_cpu_info_str + strlen(CPUINFO_PREFIX);