]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Add CPU info to the speed command summary
authorBernd Edlinger <bernd.edlinger@hotmail.de>
Thu, 22 Aug 2019 12:28:23 +0000 (14:28 +0200)
committerBernd Edlinger <bernd.edlinger@hotmail.de>
Mon, 2 Sep 2019 18:46:34 +0000 (20:46 +0200)
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9669)

apps/info.c
apps/speed.c
apps/version.c
crypto/cversion.c
crypto/info.c
doc/man1/openssl-info.pod
doc/man1/openssl-version.pod
doc/man3/OpenSSL_version.pod
include/openssl/crypto.h

index d67ed87df33ad2419eccf61f760706a62bee59dc..4656141184e08c33f0c7425783728a89286e2c00 100644 (file)
@@ -14,7 +14,7 @@
 typedef enum OPTION_choice {
     OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
     OPT_CONFIGDIR, OPT_ENGINESDIR, OPT_MODULESDIR, OPT_DSOEXT, OPT_DIRNAMESEP,
 typedef enum OPTION_choice {
     OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
     OPT_CONFIGDIR, OPT_ENGINESDIR, OPT_MODULESDIR, OPT_DSOEXT, OPT_DIRNAMESEP,
-    OPT_LISTSEP, OPT_SEEDS
+    OPT_LISTSEP, OPT_SEEDS, OPT_CPUSETTINGS
 } OPTION_CHOICE;
 
 const OPTIONS info_options[] = {
 } OPTION_CHOICE;
 
 const OPTIONS info_options[] = {
@@ -31,6 +31,7 @@ const OPTIONS info_options[] = {
     {"dirnamesep", OPT_DIRNAMESEP, '-', "Directory-filename separator"},
     {"listsep", OPT_LISTSEP, '-', "List separator character"},
     {"seeds", OPT_SEEDS, '-', "Seed sources"},
     {"dirnamesep", OPT_DIRNAMESEP, '-', "Directory-filename separator"},
     {"listsep", OPT_LISTSEP, '-', "List separator character"},
     {"seeds", OPT_SEEDS, '-', "Seed sources"},
+    {"cpusettings", OPT_CPUSETTINGS, '-', "CPU settings info"},
     {NULL}
 };
 
     {NULL}
 };
 
@@ -79,6 +80,10 @@ opthelp:
             type = OPENSSL_INFO_SEED_SOURCE;
             dirty++;
             break;
             type = OPENSSL_INFO_SEED_SOURCE;
             dirty++;
             break;
+        case OPT_CPUSETTINGS:
+            type = OPENSSL_INFO_CPU_SETTINGS;
+            dirty++;
+            break;
         }
     }
     if (opt_num_rest() != 0) {
         }
     }
     if (opt_num_rest() != 0) {
index d71b823f2af11623c0ebc624191042a0f4b7f68f..59594f0e4966ac08f13cd0267be74336891428ea 100644 (file)
@@ -3363,6 +3363,7 @@ int speed_main(int argc, char **argv)
         printf("%s ", BF_options());
 #endif
         printf("\n%s\n", OpenSSL_version(OPENSSL_CFLAGS));
         printf("%s ", BF_options());
 #endif
         printf("\n%s\n", OpenSSL_version(OPENSSL_CFLAGS));
+        printf("%s\n", OpenSSL_version(OPENSSL_CPU_INFO));
     }
 
     if (pr_header) {
     }
 
     if (pr_header) {
index caa3e76ffec15a1255b6e4ced484a10a626fd42b..7350ccf78f091a25386eab7d0d41a6b794508bac 100644 (file)
@@ -33,7 +33,7 @@
 
 typedef enum OPTION_choice {
     OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
 
 typedef enum OPTION_choice {
     OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
-    OPT_B, OPT_D, OPT_E, OPT_M, OPT_F, OPT_O, OPT_P, OPT_V, OPT_A, OPT_R
+    OPT_B, OPT_D, OPT_E, OPT_M, OPT_F, OPT_O, OPT_P, OPT_V, OPT_A, OPT_R, OPT_C
 } OPTION_CHOICE;
 
 const OPTIONS version_options[] = {
 } OPTION_CHOICE;
 
 const OPTIONS version_options[] = {
@@ -48,24 +48,15 @@ const OPTIONS version_options[] = {
     {"p", OPT_P, '-', "Show target build platform"},
     {"r", OPT_R, '-', "Show random seeding options"},
     {"v", OPT_V, '-', "Show library version"},
     {"p", OPT_P, '-', "Show target build platform"},
     {"r", OPT_R, '-', "Show random seeding options"},
     {"v", OPT_V, '-', "Show library version"},
+    {"c", OPT_C, '-', "Show CPU settings info"},
     {NULL}
 };
 
     {NULL}
 };
 
-#if defined(OPENSSL_RAND_SEED_DEVRANDOM) || defined(OPENSSL_RAND_SEED_EGD)
-static void printlist(const char *prefix, const char **dev)
-{
-    printf("%s (", prefix);
-    for ( ; *dev != NULL; dev++)
-        printf(" \"%s\"", *dev);
-    printf(" )");
-}
-#endif
-
 int version_main(int argc, char **argv)
 {
     int ret = 1, dirty = 0, seed = 0;
     int cflags = 0, version = 0, date = 0, options = 0, platform = 0, dir = 0;
 int version_main(int argc, char **argv)
 {
     int ret = 1, dirty = 0, seed = 0;
     int cflags = 0, version = 0, date = 0, options = 0, platform = 0, dir = 0;
-    int engdir = 0, moddir = 0;
+    int engdir = 0, moddir = 0, cpuinfo = 0;
     char *prog;
     OPTION_CHOICE o;
 
     char *prog;
     OPTION_CHOICE o;
 
@@ -108,9 +99,12 @@ opthelp:
         case OPT_V:
             dirty = version = 1;
             break;
         case OPT_V:
             dirty = version = 1;
             break;
+        case OPT_C:
+            dirty = cpuinfo = 1;
+            break;
         case OPT_A:
             seed = options = cflags = version = date = platform
         case OPT_A:
             seed = options = cflags = version = date = platform
-                = dir = engdir = moddir
+                = dir = engdir = moddir = cpuinfo
                 = 1;
             break;
         }
                 = 1;
             break;
         }
@@ -157,8 +151,12 @@ opthelp:
         printf("%s\n", OpenSSL_version(OPENSSL_ENGINES_DIR));
     if (moddir)
         printf("%s\n", OpenSSL_version(OPENSSL_MODULES_DIR));
         printf("%s\n", OpenSSL_version(OPENSSL_ENGINES_DIR));
     if (moddir)
         printf("%s\n", OpenSSL_version(OPENSSL_MODULES_DIR));
-    if (seed)
-        printf("Seeding source: %s\n", OPENSSL_info(OPENSSL_INFO_SEED_SOURCE));
+    if (seed) {
+        const char *src = OPENSSL_info(OPENSSL_INFO_SEED_SOURCE);
+        printf("Seeding source: %s\n", src ? src : "N/A");
+    }
+    if (cpuinfo)
+        printf("%s\n", OpenSSL_version(OPENSSL_CPU_INFO));
     ret = 0;
  end:
     return ret;
     ret = 0;
  end:
     return ret;
index aef84e9c60cc038cb0e13bdb6ccd8c722e69460f..2a0dcf944591a75d882494f15ed2ad51277e1889 100644 (file)
@@ -43,6 +43,8 @@ const char *OPENSSL_version_build_metadata(void)
     return OPENSSL_VERSION_BUILD_METADATA_STR;
 }
 
     return OPENSSL_VERSION_BUILD_METADATA_STR;
 }
 
+extern char ossl_cpu_info_str[];
+
 const char *OpenSSL_version(int t)
 {
     switch (t) {
 const char *OpenSSL_version(int t)
 {
     switch (t) {
@@ -76,6 +78,11 @@ const char *OpenSSL_version(int t)
 #else
         return "MODULESDIR: N/A";
 #endif
 #else
         return "MODULESDIR: N/A";
 #endif
+    case OPENSSL_CPU_INFO:
+        if (OPENSSL_info(OPENSSL_INFO_CPU_SETTINGS) != NULL)
+            return ossl_cpu_info_str;
+        else
+            return "CPUINFO: N/A";
     }
     return "not available";
 }
     }
     return "not available";
 }
index c5eb1fcba9b8f78fcf84e5055ad8b2beaf6e5438..355827c4518ae437de9251ec725ff36674f58199 100644 (file)
@@ -7,18 +7,57 @@
  * https://www.openssl.org/source/license.html
  */
 
  * https://www.openssl.org/source/license.html
  */
 
-#include <stddef.h>
 #include <openssl/crypto.h>
 #include "internal/dso_conf.h"
 #include <openssl/crypto.h>
 #include "internal/dso_conf.h"
+#include "internal/thread_once.h"
+#include "internal/cryptlib.h"
 #include "e_os.h"
 #include "buildinf.h"
 #include "e_os.h"
 #include "buildinf.h"
-#include "internal/thread_once.h"
+
+#if defined(__arm__) || defined(__arm) || defined(__aarch64__)
+# include "arm_arch.h"
+#endif
+
+/* extern declaration to avoid warning */
+extern char ossl_cpu_info_str[];
 
 static char *seed_sources = NULL;
 
 static char *seed_sources = NULL;
+
+char ossl_cpu_info_str[128] = "";
+#define CPUINFO_PREFIX "CPUINFO: "
+
 static CRYPTO_ONCE init_info = CRYPTO_ONCE_STATIC_INIT;
 
 DEFINE_RUN_ONCE_STATIC(init_info_strings)
 {
 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)
+    const char *env;
+
+    BIO_snprintf(ossl_cpu_info_str, sizeof(ossl_cpu_info_str),
+                 CPUINFO_PREFIX "OPENSSL_ia32cap=0x%llx:0x%llx",
+                 (long long)OPENSSL_ia32cap_P[0] |
+                 (long long)OPENSSL_ia32cap_P[1] << 32,
+                 (long long)OPENSSL_ia32cap_P[2] |
+                 (long long)OPENSSL_ia32cap_P[3] << 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__)
+    const char *env;
+
+    BIO_snprintf(ossl_cpu_info_str, sizeof(ossl_cpu_info_str),
+                 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);
+# endif
+#endif
+
     {
         static char seeds[512] = "";
 
     {
         static char seeds[512] = "";
 
@@ -107,6 +146,15 @@ const char *OPENSSL_info(int t)
         }
     case OPENSSL_INFO_SEED_SOURCE:
         return seed_sources;
         }
     case OPENSSL_INFO_SEED_SOURCE:
         return seed_sources;
+    case OPENSSL_INFO_CPU_SETTINGS:
+        /*
+         * If successfully initialized, ossl_cpu_info_str will start
+         * with CPUINFO_PREFIX, if failed it will be an empty string.
+         * Strip away the CPUINFO_PREFIX which we don't need here.
+         */
+        if (ossl_cpu_info_str[0] != '\0')
+            return ossl_cpu_info_str + strlen(CPUINFO_PREFIX);
+        break;
     default:
         break;
     }
     default:
         break;
     }
index 2b9383fc9d3d313863836444c114cdf867e654f5..637b60b267173f693e6ce9e0347db8013323fe9d 100644 (file)
@@ -15,6 +15,7 @@ B<openssl info>
 [B<-dirfilesep>]
 [B<-listsep]>
 [B<-seeds]>
 [B<-dirfilesep>]
 [B<-listsep]>
 [B<-seeds]>
+[B<-cpusettings]>
 
 =head1 DESCRIPTION
 
 
 =head1 DESCRIPTION
 
@@ -67,6 +68,10 @@ style lists.
 
 Outputs the randomness seed sources.
 
 
 Outputs the randomness seed sources.
 
+=item B<-cpusettings>
+
+Outputs the OpenSSL CPU settings info.
+
 =back
 
 =head1 HISTORY
 =back
 
 =head1 HISTORY
index b2a235e0b7233b7ef6313245e9173f9c0f6ecbf3..278769423edad128053f49156092a74a7e45af69 100644 (file)
@@ -16,6 +16,9 @@ B<openssl version>
 [B<-p>]
 [B<-d>]
 [B<-e>]
 [B<-p>]
 [B<-d>]
 [B<-e>]
+[B<-m>]
+[B<-r>]
+[B<-c>]
 
 =head1 DESCRIPTION
 
 
 =head1 DESCRIPTION
 
@@ -61,6 +64,18 @@ OPENSSLDIR setting.
 
 ENGINESDIR settings.
 
 
 ENGINESDIR settings.
 
+=item B<-m>
+
+MODULESDIR settings.
+
+=item B<-r>
+
+The random number generator source settings.
+
+=item B<-c>
+
+The OpenSSL CPU settings info.
+
 =back
 
 =head1 NOTES
 =back
 
 =head1 NOTES
index 9b8ecd2d2cd80d879b62ea297ad1af471132b2fa..66abd3e4b7a5282ac7575f029109e8f246e11dcb 100644 (file)
@@ -125,6 +125,20 @@ if available or "OPENSSLDIR: N/A" otherwise.
 The "ENGINESDIR" setting of the library build in the form "ENGINESDIR: "...""
 if available or "ENGINESDIR: N/A" otherwise.
 
 The "ENGINESDIR" setting of the library build in the form "ENGINESDIR: "...""
 if available or "ENGINESDIR: N/A" otherwise.
 
+=item OPENSSL_MODULES_DIR
+
+The "MODULESDIR" setting of the library build in the form "MODULESDIR: "...""
+if available or "MODULESDIR: N/A" otherwise.
+
+=item OPENSSL_CPU_INFO
+
+The current OpenSSL cpu settings.
+This is the current setting of the cpu capability flags. It is usually
+automatically configured but may be set via an environment variable.
+The value has the same syntax as the environment variable.
+For x86 the string looks like "CPUINFO: OPENSSL_ia32cap=0x123:0x456".
+Or "CPUINFO: N/A" if not available, e.g. no-asm build.
+
 =back
 
 For an unknown B<t>, the text "not available" is returned.
 =back
 
 For an unknown B<t>, the text "not available" is returned.
@@ -166,6 +180,14 @@ value of the environment variable C<$PATH> on Unix (where the
 separator is ":") or C<%PATH%> on Windows (where the separator is
 ";").
 
 separator is ":") or C<%PATH%> on Windows (where the separator is
 ";").
 
+=item OPENSSL_INFO_CPU_SETTINGS
+
+The current OpenSSL cpu settings.
+This is the current setting of the cpu capability flags. It is usually
+automatically configured but may be set via an environment variable.
+The value has the same syntax as the environment variable.
+For x86 the string looks like "OPENSSL_ia32cap=0x123:0x456".
+
 =back
 
 For an unknown B<t>, NULL is returned.
 =back
 
 For an unknown B<t>, NULL is returned.
@@ -224,7 +246,7 @@ with the exception of the L</BACKWARD COMPATIBILITY> ones.
 
 =head1 COPYRIGHT
 
 
 =head1 COPYRIGHT
 
-Copyright 2018 The OpenSSL Project Authors. All Rights Reserved.
+Copyright 2018-2019 The OpenSSL Project Authors. All Rights Reserved.
 
 Licensed under the Apache License 2.0 (the "License").  You may not use
 this file except in compliance with the License.  You can obtain a copy
 
 Licensed under the Apache License 2.0 (the "License").  You may not use
 this file except in compliance with the License.  You can obtain a copy
index e16e3e47438c46e3e1cf17437b4638efea665f3b..05580ad93cf2b479f11a1bead0955c5f75daf968 100644 (file)
@@ -169,6 +169,7 @@ const char *OpenSSL_version(int type);
 # define OPENSSL_VERSION_STRING         6
 # define OPENSSL_FULL_VERSION_STRING    7
 # define OPENSSL_MODULES_DIR            8
 # define OPENSSL_VERSION_STRING         6
 # define OPENSSL_FULL_VERSION_STRING    7
 # define OPENSSL_MODULES_DIR            8
+# define OPENSSL_CPU_INFO               9
 
 const char *OPENSSL_info(int type);
 /*
 
 const char *OPENSSL_info(int type);
 /*
@@ -182,6 +183,7 @@ const char *OPENSSL_info(int type);
 # define OPENSSL_INFO_DIR_FILENAME_SEPARATOR    1005
 # define OPENSSL_INFO_LIST_SEPARATOR            1006
 # define OPENSSL_INFO_SEED_SOURCE               1007
 # define OPENSSL_INFO_DIR_FILENAME_SEPARATOR    1005
 # define OPENSSL_INFO_LIST_SEPARATOR            1006
 # define OPENSSL_INFO_SEED_SOURCE               1007
+# define OPENSSL_INFO_CPU_SETTINGS              1008
 
 int OPENSSL_issetugid(void);
 
 
 int OPENSSL_issetugid(void);