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 "internal/dso_conf.h"
12 #include "internal/thread_once.h"
13 #include "internal/cryptlib.h"
17 #if defined(__arm__) || defined(__arm) || defined(__aarch64__)
18 # include "arm_arch.h"
21 /* extern declaration to avoid warning */
22 extern char ossl_cpu_info_str[];
24 static char *seed_sources = NULL;
26 char ossl_cpu_info_str[128] = "";
27 #define CPUINFO_PREFIX "CPUINFO: "
29 static CRYPTO_ONCE init_info = CRYPTO_ONCE_STATIC_INIT;
31 DEFINE_RUN_ONCE_STATIC(init_info_strings)
33 #if defined(OPENSSL_CPUID_OBJ)
34 # if defined(__i386) || defined(__i386__) || defined(_M_IX86) || \
35 defined(__x86_64) || defined(__x86_64__) || \
36 defined(_M_AMD64) || defined(_M_X64)
39 BIO_snprintf(ossl_cpu_info_str, sizeof(ossl_cpu_info_str),
40 CPUINFO_PREFIX "OPENSSL_ia32cap=0x%llx:0x%llx",
41 (long long)OPENSSL_ia32cap_P[0] |
42 (long long)OPENSSL_ia32cap_P[1] << 32,
43 (long long)OPENSSL_ia32cap_P[2] |
44 (long long)OPENSSL_ia32cap_P[3] << 32);
45 if ((env = getenv("OPENSSL_ia32cap")) != NULL)
46 BIO_snprintf(ossl_cpu_info_str + strlen(ossl_cpu_info_str),
47 sizeof(ossl_cpu_info_str) - strlen(ossl_cpu_info_str),
49 # elif defined(__arm__) || defined(__arm) || defined(__aarch64__)
52 BIO_snprintf(ossl_cpu_info_str, sizeof(ossl_cpu_info_str),
53 CPUINFO_PREFIX "OPENSSL_armcap=0x%x", OPENSSL_armcap_P);
54 if ((env = getenv("OPENSSL_armcap")) != NULL)
55 BIO_snprintf(ossl_cpu_info_str + strlen(ossl_cpu_info_str),
56 sizeof(ossl_cpu_info_str) - strlen(ossl_cpu_info_str),
62 static char seeds[512] = "";
64 #define add_seeds_string(str) \
66 if (seeds[0] != '\0') \
67 OPENSSL_strlcat(seeds, " ", sizeof(seeds)); \
68 OPENSSL_strlcat(seeds, str, sizeof(seeds)); \
70 #define add_seeds_stringlist(label, strlist) \
72 add_seeds_string(label "("); \
74 const char *dev[] = strlist; \
77 for (; *dev != NULL; dev++) { \
79 OPENSSL_strlcat(seeds, " ", sizeof(seeds)); \
81 OPENSSL_strlcat(seeds, *dev, sizeof(seeds)); \
84 OPENSSL_strlcat(seeds, ")", sizeof(seeds)); \
87 #ifdef OPENSSL_RAND_SEED_NONE
88 add_seeds_string("none");
90 #ifdef OPENSSL_RAND_SEED_RTDSC
91 add_seeds_string("stdsc");
93 #ifdef OPENSSL_RAND_SEED_RDCPU
94 add_seeds_string("rdrand ( rdseed rdrand )");
96 #ifdef OPENSSL_RAND_SEED_LIBRANDOM
97 add_seeds_string("C-library-random");
99 #ifdef OPENSSL_RAND_SEED_GETRANDOM
100 add_seeds_string("getrandom-syscall");
102 #ifdef OPENSSL_RAND_SEED_DEVRANDOM
103 add_seeds_stringlist("random-device", { DEVRANDOM, NULL });
105 #ifdef OPENSSL_RAND_SEED_EGD
106 add_seeds_stringlist("EGD", { DEVRANDOM_EGD, NULL });
108 #ifdef OPENSSL_RAND_SEED_OS
109 add_seeds_string("os-specific");
111 seed_sources = seeds;
116 const char *OPENSSL_info(int t)
119 * We don't care about the result. Worst case scenario, the strings
120 * won't be initialised, i.e. remain NULL, which means that the info
121 * isn't available anyway...
123 (void)RUN_ONCE(&init_info, init_info_strings);
126 case OPENSSL_INFO_CONFIG_DIR:
128 case OPENSSL_INFO_ENGINES_DIR:
130 case OPENSSL_INFO_MODULES_DIR:
132 case OPENSSL_INFO_DSO_EXTENSION:
133 return DSO_EXTENSION;
134 case OPENSSL_INFO_DIR_FILENAME_SEPARATOR:
139 #else /* Assume POSIX */
142 case OPENSSL_INFO_LIST_SEPARATOR:
144 static const char list_sep[] = { LIST_SEPARATOR_CHAR, '\0' };
147 case OPENSSL_INFO_SEED_SOURCE:
149 case OPENSSL_INFO_CPU_SETTINGS:
151 * If successfully initialized, ossl_cpu_info_str will start
152 * with CPUINFO_PREFIX, if failed it will be an empty string.
153 * Strip away the CPUINFO_PREFIX which we don't need here.
155 if (ossl_cpu_info_str[0] != '\0')
156 return ossl_cpu_info_str + strlen(CPUINFO_PREFIX);