VirtualBox

source: vbox/trunk/src/libs/openssl-3.0.7/crypto/info.c@ 98227

Last change on this file since 98227 was 94320, checked in by vboxsync, 3 years ago

libs/openssl-3.0.1: Export to OSE and fix copyright headers in Makefiles, bugref:10128

File size: 7.9 KB
Line 
1/*
2 * Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved.
3 *
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
8 */
9
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"
15#include "e_os.h"
16#include "buildinf.h"
17
18#if defined(__arm__) || defined(__arm) || defined(__aarch64__)
19# include "arm_arch.h"
20# define CPU_INFO_STR_LEN 128
21#elif defined(__s390__) || defined(__s390x__)
22# include "s390x_arch.h"
23# define CPU_INFO_STR_LEN 2048
24#else
25# define CPU_INFO_STR_LEN 128
26#endif
27
28/* extern declaration to avoid warning */
29extern char ossl_cpu_info_str[];
30
31static char *seed_sources = NULL;
32
33char ossl_cpu_info_str[CPU_INFO_STR_LEN] = "";
34#define CPUINFO_PREFIX "CPUINFO: "
35
36#ifndef VBOX
37static CRYPTO_ONCE init_info = CRYPTO_ONCE_STATIC_INIT;
38
39DEFINE_RUN_ONCE_STATIC(init_info_strings)
40{
41#if defined(OPENSSL_CPUID_OBJ)
42# if defined(__i386) || defined(__i386__) || defined(_M_IX86) || \
43 defined(__x86_64) || defined(__x86_64__) || \
44 defined(_M_AMD64) || defined(_M_X64)
45 const char *env;
46
47 BIO_snprintf(ossl_cpu_info_str, sizeof(ossl_cpu_info_str),
48 CPUINFO_PREFIX "OPENSSL_ia32cap=0x%llx:0x%llx",
49 (long long)OPENSSL_ia32cap_P[0] |
50 (long long)OPENSSL_ia32cap_P[1] << 32,
51 (long long)OPENSSL_ia32cap_P[2] |
52 (long long)OPENSSL_ia32cap_P[3] << 32);
53 if ((env = getenv("OPENSSL_ia32cap")) != NULL)
54 BIO_snprintf(ossl_cpu_info_str + strlen(ossl_cpu_info_str),
55 sizeof(ossl_cpu_info_str) - strlen(ossl_cpu_info_str),
56 " env:%s", env);
57# elif defined(__arm__) || defined(__arm) || defined(__aarch64__)
58 const char *env;
59
60 BIO_snprintf(ossl_cpu_info_str, sizeof(ossl_cpu_info_str),
61 CPUINFO_PREFIX "OPENSSL_armcap=0x%x", OPENSSL_armcap_P);
62 if ((env = getenv("OPENSSL_armcap")) != NULL)
63 BIO_snprintf(ossl_cpu_info_str + strlen(ossl_cpu_info_str),
64 sizeof(ossl_cpu_info_str) - strlen(ossl_cpu_info_str),
65 " env:%s", env);
66# elif defined(__s390__) || defined(__s390x__)
67 const char *env;
68
69 BIO_snprintf(ossl_cpu_info_str, sizeof(ossl_cpu_info_str),
70 CPUINFO_PREFIX "OPENSSL_s390xcap="
71 "stfle:0x%llx:0x%llx:0x%llx:0x%llx:"
72 "kimd:0x%llx:0x%llx:"
73 "klmd:0x%llx:0x%llx:"
74 "km:0x%llx:0x%llx:"
75 "kmc:0x%llx:0x%llx:"
76 "kmac:0x%llx:0x%llx:"
77 "kmctr:0x%llx:0x%llx:"
78 "kmo:0x%llx:0x%llx:"
79 "kmf:0x%llx:0x%llx:"
80 "prno:0x%llx:0x%llx:"
81 "kma:0x%llx:0x%llx:"
82 "pcc:0x%llx:0x%llx:"
83 "kdsa:0x%llx:0x%llx",
84 OPENSSL_s390xcap_P.stfle[0], OPENSSL_s390xcap_P.stfle[1],
85 OPENSSL_s390xcap_P.stfle[2], OPENSSL_s390xcap_P.stfle[3],
86 OPENSSL_s390xcap_P.kimd[0], OPENSSL_s390xcap_P.kimd[1],
87 OPENSSL_s390xcap_P.klmd[0], OPENSSL_s390xcap_P.klmd[1],
88 OPENSSL_s390xcap_P.km[0], OPENSSL_s390xcap_P.km[1],
89 OPENSSL_s390xcap_P.kmc[0], OPENSSL_s390xcap_P.kmc[1],
90 OPENSSL_s390xcap_P.kmac[0], OPENSSL_s390xcap_P.kmac[1],
91 OPENSSL_s390xcap_P.kmctr[0], OPENSSL_s390xcap_P.kmctr[1],
92 OPENSSL_s390xcap_P.kmo[0], OPENSSL_s390xcap_P.kmo[1],
93 OPENSSL_s390xcap_P.kmf[0], OPENSSL_s390xcap_P.kmf[1],
94 OPENSSL_s390xcap_P.prno[0], OPENSSL_s390xcap_P.prno[1],
95 OPENSSL_s390xcap_P.kma[0], OPENSSL_s390xcap_P.kma[1],
96 OPENSSL_s390xcap_P.pcc[0], OPENSSL_s390xcap_P.pcc[1],
97 OPENSSL_s390xcap_P.kdsa[0], OPENSSL_s390xcap_P.kdsa[1]);
98 if ((env = getenv("OPENSSL_s390xcap")) != NULL)
99 BIO_snprintf(ossl_cpu_info_str + strlen(ossl_cpu_info_str),
100 sizeof(ossl_cpu_info_str) - strlen(ossl_cpu_info_str),
101 " env:%s", env);
102# endif
103#endif
104
105 {
106 static char seeds[512] = "";
107
108#define add_seeds_string(str) \
109 do { \
110 if (seeds[0] != '\0') \
111 OPENSSL_strlcat(seeds, " ", sizeof(seeds)); \
112 OPENSSL_strlcat(seeds, str, sizeof(seeds)); \
113 } while (0)
114#define add_seeds_stringlist(label, strlist) \
115 do { \
116 add_seeds_string(label "("); \
117 { \
118 const char *dev[] = { strlist, NULL }; \
119 const char **p; \
120 int first = 1; \
121 \
122 for (p = dev; *p != NULL; p++) { \
123 if (!first) \
124 OPENSSL_strlcat(seeds, " ", sizeof(seeds)); \
125 first = 0; \
126 OPENSSL_strlcat(seeds, *p, sizeof(seeds)); \
127 } \
128 } \
129 OPENSSL_strlcat(seeds, ")", sizeof(seeds)); \
130 } while (0)
131
132#ifdef OPENSSL_RAND_SEED_NONE
133 add_seeds_string("none");
134#endif
135#ifdef OPENSSL_RAND_SEED_RTDSC
136 add_seeds_string("stdsc");
137#endif
138#ifdef OPENSSL_RAND_SEED_RDCPU
139 add_seeds_string("rdrand ( rdseed rdrand )");
140#endif
141#ifdef OPENSSL_RAND_SEED_LIBRANDOM
142 add_seeds_string("C-library-random");
143#endif
144#ifdef OPENSSL_RAND_SEED_GETRANDOM
145 add_seeds_string("getrandom-syscall");
146#endif
147#ifdef OPENSSL_RAND_SEED_DEVRANDOM
148 add_seeds_stringlist("random-device", DEVRANDOM);
149#endif
150#ifdef OPENSSL_RAND_SEED_EGD
151 add_seeds_stringlist("EGD", DEVRANDOM_EGD);
152#endif
153#ifdef OPENSSL_RAND_SEED_OS
154 add_seeds_string("os-specific");
155#endif
156 seed_sources = seeds;
157 }
158 return 1;
159}
160#endif /* VBOX */
161
162const char *OPENSSL_info(int t)
163{
164#ifndef VBOX
165 /*
166 * We don't care about the result. Worst case scenario, the strings
167 * won't be initialised, i.e. remain NULL, which means that the info
168 * isn't available anyway...
169 */
170 (void)RUN_ONCE(&init_info, init_info_strings);
171
172 switch (t) {
173 case OPENSSL_INFO_CONFIG_DIR:
174 return OPENSSLDIR;
175 case OPENSSL_INFO_ENGINES_DIR:
176 return ENGINESDIR;
177 case OPENSSL_INFO_MODULES_DIR:
178 return MODULESDIR;
179 case OPENSSL_INFO_DSO_EXTENSION:
180 return DSO_EXTENSION;
181 case OPENSSL_INFO_DIR_FILENAME_SEPARATOR:
182#if defined(_WIN32)
183 return "\\";
184#elif defined(__VMS)
185 return "";
186#else /* Assume POSIX */
187 return "/";
188#endif
189 case OPENSSL_INFO_LIST_SEPARATOR:
190 {
191 static const char list_sep[] = { LIST_SEPARATOR_CHAR, '\0' };
192 return list_sep;
193 }
194 case OPENSSL_INFO_SEED_SOURCE:
195 return seed_sources;
196 case OPENSSL_INFO_CPU_SETTINGS:
197 /*
198 * If successfully initialized, ossl_cpu_info_str will start
199 * with CPUINFO_PREFIX, if failed it will be an empty string.
200 * Strip away the CPUINFO_PREFIX which we don't need here.
201 */
202 if (ossl_cpu_info_str[0] != '\0')
203 return ossl_cpu_info_str + strlen(CPUINFO_PREFIX);
204 break;
205 default:
206 break;
207 }
208#endif
209 /* Not an error */
210 return NULL;
211}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette