diff options
Diffstat (limited to 'crypto/info.c')
| -rw-r--r-- | crypto/info.c | 251 |
1 files changed, 135 insertions, 116 deletions
diff --git a/crypto/info.c b/crypto/info.c index e760ec094027..a0344a887694 100644 --- a/crypto/info.c +++ b/crypto/info.c @@ -16,24 +16,24 @@ #include "buildinf.h" #ifndef OPENSSL_NO_JITTER -# include <stdio.h> -# include <jitterentropy.h> +#include <stdio.h> +#include <jitterentropy.h> #endif #if defined(__arm__) || defined(__arm) || defined(__aarch64__) -# include "arm_arch.h" -# define CPU_INFO_STR_LEN 128 +#include "arm_arch.h" +#define CPU_INFO_STR_LEN 128 #elif defined(__powerpc__) || defined(__POWERPC__) || defined(_ARCH_PPC) -# include "crypto/ppc_arch.h" -# define CPU_INFO_STR_LEN 128 +#include "crypto/ppc_arch.h" +#define CPU_INFO_STR_LEN 128 #elif defined(__s390__) || defined(__s390x__) -# include "s390x_arch.h" -# define CPU_INFO_STR_LEN 2048 +#include "s390x_arch.h" +#define CPU_INFO_STR_LEN 2048 #elif defined(__riscv) -# include "crypto/riscv_arch.h" -# define CPU_INFO_STR_LEN 2048 +#include "crypto/riscv_arch.h" +#define CPU_INFO_STR_LEN 2048 #else -# define CPU_INFO_STR_LEN 256 +#define CPU_INFO_STR_LEN 256 #endif /* extern declaration to avoid warning */ @@ -49,138 +49,158 @@ static CRYPTO_ONCE init_info = CRYPTO_ONCE_STATIC_INIT; DEFINE_RUN_ONCE_STATIC(init_info_strings) { #if defined(OPENSSL_CPUID_OBJ) -# if defined(__i386) || defined(__i386__) || defined(_M_IX86) || \ - defined(__x86_64) || defined(__x86_64__) || \ - defined(_M_AMD64) || defined(_M_X64) +#if defined(__i386) || defined(__i386__) || defined(_M_IX86) || defined(__x86_64) || defined(__x86_64__) || defined(_M_AMD64) || defined(_M_X64) const char *env; BIO_snprintf(ossl_cpu_info_str, sizeof(ossl_cpu_info_str), - CPUINFO_PREFIX "OPENSSL_ia32cap=0x%.16llx:0x%.16llx:0x%.16llx:0x%.16llx:0x%.16llx", - (unsigned long long)OPENSSL_ia32cap_P[0] | - (unsigned long long)OPENSSL_ia32cap_P[1] << 32, - (unsigned long long)OPENSSL_ia32cap_P[2] | - (unsigned long long)OPENSSL_ia32cap_P[3] << 32, - (unsigned long long)OPENSSL_ia32cap_P[4] | - (unsigned long long)OPENSSL_ia32cap_P[5] << 32, - (unsigned long long)OPENSSL_ia32cap_P[6] | - (unsigned long long)OPENSSL_ia32cap_P[7] << 32, - (unsigned long long)OPENSSL_ia32cap_P[8] | - (unsigned long long)OPENSSL_ia32cap_P[9] << 32); + CPUINFO_PREFIX "OPENSSL_ia32cap=0x%.16llx:0x%.16llx:0x%.16llx:0x%.16llx:0x%.16llx", + (unsigned long long)OPENSSL_ia32cap_P[0] | (unsigned long long)OPENSSL_ia32cap_P[1] << 32, + (unsigned long long)OPENSSL_ia32cap_P[2] | (unsigned long long)OPENSSL_ia32cap_P[3] << 32, + (unsigned long long)OPENSSL_ia32cap_P[4] | (unsigned long long)OPENSSL_ia32cap_P[5] << 32, + (unsigned long long)OPENSSL_ia32cap_P[6] | (unsigned long long)OPENSSL_ia32cap_P[7] << 32, + (unsigned long long)OPENSSL_ia32cap_P[8] | (unsigned long long)OPENSSL_ia32cap_P[9] << 32); if ((env = getenv("OPENSSL_ia32cap")) != NULL) BIO_snprintf(ossl_cpu_info_str + strlen(ossl_cpu_info_str), - sizeof(ossl_cpu_info_str) - strlen(ossl_cpu_info_str), - " env:%s", env); -# elif defined(__arm__) || defined(__arm) || defined(__aarch64__) + sizeof(ossl_cpu_info_str) - strlen(ossl_cpu_info_str), + " env:%s", env); +#elif defined(__arm__) || defined(__arm) || defined(__aarch64__) const char *env; BIO_snprintf(ossl_cpu_info_str, sizeof(ossl_cpu_info_str), - CPUINFO_PREFIX "OPENSSL_armcap=0x%x", OPENSSL_armcap_P); + CPUINFO_PREFIX "OPENSSL_armcap=0x%x", OPENSSL_armcap_P); if ((env = getenv("OPENSSL_armcap")) != NULL) BIO_snprintf(ossl_cpu_info_str + strlen(ossl_cpu_info_str), - sizeof(ossl_cpu_info_str) - strlen(ossl_cpu_info_str), - " env:%s", env); -# elif defined(__powerpc__) || defined(__POWERPC__) || defined(_ARCH_PPC) + sizeof(ossl_cpu_info_str) - strlen(ossl_cpu_info_str), + " env:%s", env); +#elif defined(__powerpc__) || defined(__POWERPC__) || defined(_ARCH_PPC) const char *env; BIO_snprintf(ossl_cpu_info_str, sizeof(ossl_cpu_info_str), - CPUINFO_PREFIX "OPENSSL_ppccap=0x%x", OPENSSL_ppccap_P); + CPUINFO_PREFIX "OPENSSL_ppccap=0x%x", OPENSSL_ppccap_P); if ((env = getenv("OPENSSL_ppccap")) != NULL) BIO_snprintf(ossl_cpu_info_str + strlen(ossl_cpu_info_str), - sizeof(ossl_cpu_info_str) - strlen(ossl_cpu_info_str), - " env:%s", env); -# elif defined(__s390__) || defined(__s390x__) + sizeof(ossl_cpu_info_str) - strlen(ossl_cpu_info_str), + " env:%s", env); +#elif defined(__s390__) || defined(__s390x__) const char *env; BIO_snprintf(ossl_cpu_info_str, sizeof(ossl_cpu_info_str), - CPUINFO_PREFIX "OPENSSL_s390xcap=" - "stfle:0x%llx:0x%llx:0x%llx:0x%llx:" - "kimd:0x%llx:0x%llx:" - "klmd:0x%llx:0x%llx:" - "km:0x%llx:0x%llx:" - "kmc:0x%llx:0x%llx:" - "kmac:0x%llx:0x%llx:" - "kmctr:0x%llx:0x%llx:" - "kmo:0x%llx:0x%llx:" - "kmf:0x%llx:0x%llx:" - "prno:0x%llx:0x%llx:" - "kma:0x%llx:0x%llx:" - "pcc:0x%llx:0x%llx:" - "kdsa:0x%llx:0x%llx", - OPENSSL_s390xcap_P.stfle[0], OPENSSL_s390xcap_P.stfle[1], - OPENSSL_s390xcap_P.stfle[2], OPENSSL_s390xcap_P.stfle[3], - OPENSSL_s390xcap_P.kimd[0], OPENSSL_s390xcap_P.kimd[1], - OPENSSL_s390xcap_P.klmd[0], OPENSSL_s390xcap_P.klmd[1], - OPENSSL_s390xcap_P.km[0], OPENSSL_s390xcap_P.km[1], - OPENSSL_s390xcap_P.kmc[0], OPENSSL_s390xcap_P.kmc[1], - OPENSSL_s390xcap_P.kmac[0], OPENSSL_s390xcap_P.kmac[1], - OPENSSL_s390xcap_P.kmctr[0], OPENSSL_s390xcap_P.kmctr[1], - OPENSSL_s390xcap_P.kmo[0], OPENSSL_s390xcap_P.kmo[1], - OPENSSL_s390xcap_P.kmf[0], OPENSSL_s390xcap_P.kmf[1], - OPENSSL_s390xcap_P.prno[0], OPENSSL_s390xcap_P.prno[1], - OPENSSL_s390xcap_P.kma[0], OPENSSL_s390xcap_P.kma[1], - OPENSSL_s390xcap_P.pcc[0], OPENSSL_s390xcap_P.pcc[1], - OPENSSL_s390xcap_P.kdsa[0], OPENSSL_s390xcap_P.kdsa[1]); + CPUINFO_PREFIX "OPENSSL_s390xcap=" + "stfle:0x%llx:0x%llx:0x%llx:0x%llx:" + "kimd:0x%llx:0x%llx:" + "klmd:0x%llx:0x%llx:" + "km:0x%llx:0x%llx:" + "kmc:0x%llx:0x%llx:" + "kmac:0x%llx:0x%llx:" + "kmctr:0x%llx:0x%llx:" + "kmo:0x%llx:0x%llx:" + "kmf:0x%llx:0x%llx:" + "prno:0x%llx:0x%llx:" + "kma:0x%llx:0x%llx:" + "pcc:0x%llx:0x%llx:" + "kdsa:0x%llx:0x%llx", + OPENSSL_s390xcap_P.stfle[0], OPENSSL_s390xcap_P.stfle[1], + OPENSSL_s390xcap_P.stfle[2], OPENSSL_s390xcap_P.stfle[3], + OPENSSL_s390xcap_P.kimd[0], OPENSSL_s390xcap_P.kimd[1], + OPENSSL_s390xcap_P.klmd[0], OPENSSL_s390xcap_P.klmd[1], + OPENSSL_s390xcap_P.km[0], OPENSSL_s390xcap_P.km[1], + OPENSSL_s390xcap_P.kmc[0], OPENSSL_s390xcap_P.kmc[1], + OPENSSL_s390xcap_P.kmac[0], OPENSSL_s390xcap_P.kmac[1], + OPENSSL_s390xcap_P.kmctr[0], OPENSSL_s390xcap_P.kmctr[1], + OPENSSL_s390xcap_P.kmo[0], OPENSSL_s390xcap_P.kmo[1], + OPENSSL_s390xcap_P.kmf[0], OPENSSL_s390xcap_P.kmf[1], + OPENSSL_s390xcap_P.prno[0], OPENSSL_s390xcap_P.prno[1], + OPENSSL_s390xcap_P.kma[0], OPENSSL_s390xcap_P.kma[1], + OPENSSL_s390xcap_P.pcc[0], OPENSSL_s390xcap_P.pcc[1], + OPENSSL_s390xcap_P.kdsa[0], OPENSSL_s390xcap_P.kdsa[1]); if ((env = getenv("OPENSSL_s390xcap")) != NULL) BIO_snprintf(ossl_cpu_info_str + strlen(ossl_cpu_info_str), - sizeof(ossl_cpu_info_str) - strlen(ossl_cpu_info_str), - " env:%s", env); -# elif defined(__riscv) + sizeof(ossl_cpu_info_str) - strlen(ossl_cpu_info_str), + " env:%s", env); +#elif defined(__riscv) const char *env; - char sep = '='; + size_t i; BIO_snprintf(ossl_cpu_info_str, sizeof(ossl_cpu_info_str), - CPUINFO_PREFIX "OPENSSL_riscvcap"); - for (size_t i = 0; i < kRISCVNumCaps; ++i) { + CPUINFO_PREFIX "OPENSSL_riscvcap=RV" +#if __riscv_xlen == 32 + "32" +#elif __riscv_xlen == 64 + "64" +#elif __riscv_xlen == 128 + "128" +#endif +#if defined(__riscv_i) && defined(__riscv_m) && defined(__riscv_a) \ + && defined(__riscv_f) && defined(__riscv_d) \ + && defined(__riscv_zicsr) && defined(__riscv_zifencei) + "G" /* shorthand for IMAFD_Zicsr_Zifencei */ +#else +#ifdef __riscv_i + "I" +#endif +#ifdef __riscv_m + "M" +#endif +#ifdef __riscv_a + "A" +#endif +#ifdef __riscv_f + "F" +#endif +#ifdef __riscv_d + "D" +#endif +#endif +#ifdef __riscv_c + "C" +#endif + ); + for (i = 0; i < kRISCVNumCaps; i++) { if (OPENSSL_riscvcap_P[RISCV_capabilities[i].index] - & (1 << RISCV_capabilities[i].bit_offset)) { + & (1 << RISCV_capabilities[i].bit_offset)) /* Match, display the name */ BIO_snprintf(ossl_cpu_info_str + strlen(ossl_cpu_info_str), - sizeof(ossl_cpu_info_str) - strlen(ossl_cpu_info_str), - "%c%s", sep, RISCV_capabilities[i].name); - /* Only the first sep is '=' */ - sep = '_'; - } + sizeof(ossl_cpu_info_str) - strlen(ossl_cpu_info_str), + "_%s", RISCV_capabilities[i].name); } - /* If no capability is found, add back the = */ - if (sep == '=') { + if (RISCV_HAS_V()) BIO_snprintf(ossl_cpu_info_str + strlen(ossl_cpu_info_str), - sizeof(ossl_cpu_info_str) - strlen(ossl_cpu_info_str), - "%c", sep); - } + sizeof(ossl_cpu_info_str) - strlen(ossl_cpu_info_str), + " vlen:%lu", riscv_vlen()); if ((env = getenv("OPENSSL_riscvcap")) != NULL) BIO_snprintf(ossl_cpu_info_str + strlen(ossl_cpu_info_str), - sizeof(ossl_cpu_info_str) - strlen(ossl_cpu_info_str), - " env:%s", env); -# endif + sizeof(ossl_cpu_info_str) - strlen(ossl_cpu_info_str), + " env:%s", env); +#endif #endif { static char seeds[512] = ""; -#define add_seeds_string(str) \ - do { \ - if (seeds[0] != '\0') \ - OPENSSL_strlcat(seeds, " ", sizeof(seeds)); \ - OPENSSL_strlcat(seeds, str, sizeof(seeds)); \ - } while (0) -#define add_seeds_stringlist(label, strlist) \ - do { \ - add_seeds_string(label "("); \ - { \ - const char *dev[] = { strlist, NULL }; \ - const char **p; \ - int first = 1; \ - \ - for (p = dev; *p != NULL; p++) { \ - if (!first) \ - OPENSSL_strlcat(seeds, " ", sizeof(seeds)); \ - first = 0; \ - OPENSSL_strlcat(seeds, *p, sizeof(seeds)); \ - } \ - } \ - OPENSSL_strlcat(seeds, ")", sizeof(seeds)); \ - } while (0) +#define add_seeds_string(str) \ + do { \ + if (seeds[0] != '\0') \ + OPENSSL_strlcat(seeds, " ", sizeof(seeds)); \ + OPENSSL_strlcat(seeds, str, sizeof(seeds)); \ + } while (0) +#define add_seeds_stringlist(label, strlist) \ + do { \ + add_seeds_string(label "("); \ + { \ + const char *dev[] = { strlist, NULL }; \ + const char **p; \ + int first = 1; \ + \ + for (p = dev; *p != NULL; p++) { \ + if (!first) \ + OPENSSL_strlcat(seeds, " ", sizeof(seeds)); \ + first = 0; \ + OPENSSL_strlcat(seeds, *p, sizeof(seeds)); \ + } \ + } \ + OPENSSL_strlcat(seeds, ")", sizeof(seeds)); \ + } while (0) #ifdef OPENSSL_RAND_SEED_NONE add_seeds_string("none"); @@ -189,11 +209,11 @@ DEFINE_RUN_ONCE_STATIC(init_info_strings) add_seeds_string("rdtsc"); #endif #ifdef OPENSSL_RAND_SEED_RDCPU -# ifdef __aarch64__ +#ifdef __aarch64__ add_seeds_string("rndr ( rndrrs rndr )"); -# else +#else add_seeds_string("rdrand ( rdseed rdrand )"); -# endif +#endif #endif #ifdef OPENSSL_RAND_SEED_GETRANDOM add_seeds_string("getrandom-syscall"); @@ -243,14 +263,13 @@ const char *OPENSSL_info(int t) return "\\"; #elif defined(__VMS) return ""; -#else /* Assume POSIX */ +#else /* Assume POSIX */ return "/"; #endif - case OPENSSL_INFO_LIST_SEPARATOR: - { - static const char list_sep[] = { LIST_SEPARATOR_CHAR, '\0' }; - return list_sep; - } + case OPENSSL_INFO_LIST_SEPARATOR: { + static const char list_sep[] = { LIST_SEPARATOR_CHAR, '\0' }; + return list_sep; + } case OPENSSL_INFO_SEED_SOURCE: return seed_sources; case OPENSSL_INFO_CPU_SETTINGS: |
