Add CPU info to the speed command summary
[openssl.git] / apps / version.c
1 /*
2  * Copyright 1995-2018 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 <stdio.h>
11 #include <stdlib.h>
12 #include <string.h>
13 #include "apps.h"
14 #include "progs.h"
15 #include <openssl/evp.h>
16 #include <openssl/crypto.h>
17 #include <openssl/bn.h>
18 #ifndef OPENSSL_NO_MD2
19 # include <openssl/md2.h>
20 #endif
21 #ifndef OPENSSL_NO_RC4
22 # include <openssl/rc4.h>
23 #endif
24 #ifndef OPENSSL_NO_DES
25 # include <openssl/des.h>
26 #endif
27 #ifndef OPENSSL_NO_IDEA
28 # include <openssl/idea.h>
29 #endif
30 #ifndef OPENSSL_NO_BF
31 # include <openssl/blowfish.h>
32 #endif
33
34 typedef enum OPTION_choice {
35     OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
36     OPT_B, OPT_D, OPT_E, OPT_M, OPT_F, OPT_O, OPT_P, OPT_V, OPT_A, OPT_R, OPT_C
37 } OPTION_CHOICE;
38
39 const OPTIONS version_options[] = {
40     {"help", OPT_HELP, '-', "Display this summary"},
41     {"a", OPT_A, '-', "Show all data"},
42     {"b", OPT_B, '-', "Show build date"},
43     {"d", OPT_D, '-', "Show configuration directory"},
44     {"e", OPT_E, '-', "Show engines directory"},
45     {"m", OPT_M, '-', "Show modules directory"},
46     {"f", OPT_F, '-', "Show compiler flags used"},
47     {"o", OPT_O, '-', "Show some internal datatype options"},
48     {"p", OPT_P, '-', "Show target build platform"},
49     {"r", OPT_R, '-', "Show random seeding options"},
50     {"v", OPT_V, '-', "Show library version"},
51     {"c", OPT_C, '-', "Show CPU settings info"},
52     {NULL}
53 };
54
55 int version_main(int argc, char **argv)
56 {
57     int ret = 1, dirty = 0, seed = 0;
58     int cflags = 0, version = 0, date = 0, options = 0, platform = 0, dir = 0;
59     int engdir = 0, moddir = 0, cpuinfo = 0;
60     char *prog;
61     OPTION_CHOICE o;
62
63     prog = opt_init(argc, argv, version_options);
64     while ((o = opt_next()) != OPT_EOF) {
65         switch (o) {
66         case OPT_EOF:
67         case OPT_ERR:
68 opthelp:
69             BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
70             goto end;
71         case OPT_HELP:
72             opt_help(version_options);
73             ret = 0;
74             goto end;
75         case OPT_B:
76             dirty = date = 1;
77             break;
78         case OPT_D:
79             dirty = dir = 1;
80             break;
81         case OPT_E:
82             dirty = engdir = 1;
83             break;
84         case OPT_M:
85             dirty = moddir = 1;
86             break;
87         case OPT_F:
88             dirty = cflags = 1;
89             break;
90         case OPT_O:
91             dirty = options = 1;
92             break;
93         case OPT_P:
94             dirty = platform = 1;
95             break;
96         case OPT_R:
97             dirty = seed = 1;
98             break;
99         case OPT_V:
100             dirty = version = 1;
101             break;
102         case OPT_C:
103             dirty = cpuinfo = 1;
104             break;
105         case OPT_A:
106             seed = options = cflags = version = date = platform
107                 = dir = engdir = moddir = cpuinfo
108                 = 1;
109             break;
110         }
111     }
112     if (opt_num_rest() != 0) {
113         BIO_printf(bio_err, "Extra parameters given.\n");
114         goto opthelp;
115     }
116     if (!dirty)
117         version = 1;
118
119     if (version)
120         printf("%s (Library: %s)\n",
121                OPENSSL_VERSION_TEXT, OpenSSL_version(OPENSSL_VERSION));
122     if (date)
123         printf("%s\n", OpenSSL_version(OPENSSL_BUILT_ON));
124     if (platform)
125         printf("%s\n", OpenSSL_version(OPENSSL_PLATFORM));
126     if (options) {
127         printf("options: ");
128         printf(" %s", BN_options());
129 #ifndef OPENSSL_NO_MD2
130         printf(" %s", MD2_options());
131 #endif
132 #ifndef OPENSSL_NO_RC4
133         printf(" %s", RC4_options());
134 #endif
135 #ifndef OPENSSL_NO_DES
136         printf(" %s", DES_options());
137 #endif
138 #ifndef OPENSSL_NO_IDEA
139         printf(" %s", IDEA_options());
140 #endif
141 #ifndef OPENSSL_NO_BF
142         printf(" %s", BF_options());
143 #endif
144         printf("\n");
145     }
146     if (cflags)
147         printf("%s\n", OpenSSL_version(OPENSSL_CFLAGS));
148     if (dir)
149         printf("%s\n", OpenSSL_version(OPENSSL_DIR));
150     if (engdir)
151         printf("%s\n", OpenSSL_version(OPENSSL_ENGINES_DIR));
152     if (moddir)
153         printf("%s\n", OpenSSL_version(OPENSSL_MODULES_DIR));
154     if (seed) {
155         const char *src = OPENSSL_info(OPENSSL_INFO_SEED_SOURCE);
156         printf("Seeding source: %s\n", src ? src : "N/A");
157     }
158     if (cpuinfo)
159         printf("%s\n", OpenSSL_version(OPENSSL_CPU_INFO));
160     ret = 0;
161  end:
162     return ret;
163 }