Add --with-rand-seed
[openssl.git] / apps / version.c
1 /*
2  * Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved.
3  *
4  * Licensed under the OpenSSL license (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 <openssl/evp.h>
15 #include <openssl/crypto.h>
16 #include <openssl/bn.h>
17 #ifndef OPENSSL_NO_MD2
18 # include <openssl/md2.h>
19 #endif
20 #ifndef OPENSSL_NO_RC4
21 # include <openssl/rc4.h>
22 #endif
23 #ifndef OPENSSL_NO_DES
24 # include <openssl/des.h>
25 #endif
26 #ifndef OPENSSL_NO_IDEA
27 # include <openssl/idea.h>
28 #endif
29 #ifndef OPENSSL_NO_BF
30 # include <openssl/blowfish.h>
31 #endif
32
33 typedef enum OPTION_choice {
34     OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
35     OPT_B, OPT_D, OPT_E, OPT_F, OPT_O, OPT_P, OPT_V, OPT_A, OPT_R
36 } OPTION_CHOICE;
37
38 const OPTIONS version_options[] = {
39     {"help", OPT_HELP, '-', "Display this summary"},
40     {"a", OPT_A, '-', "Show all data"},
41     {"b", OPT_B, '-', "Show build date"},
42     {"d", OPT_D, '-', "Show configuration directory"},
43     {"e", OPT_E, '-', "Show engines directory"},
44     {"f", OPT_F, '-', "Show compiler flags used"},
45     {"o", OPT_O, '-', "Show some internal datatype options"},
46     {"p", OPT_P, '-', "Show target build platform"},
47     {"r", OPT_R, '-', "Show random seeding options"},
48     {"v", OPT_V, '-', "Show library version"},
49     {NULL}
50 };
51
52 int version_main(int argc, char **argv)
53 {
54     int ret = 1, dirty = 0, seed = 0;
55     int cflags = 0, version = 0, date = 0, options = 0, platform = 0, dir = 0;
56     int engdir = 0;
57     char *prog;
58     OPTION_CHOICE o;
59
60     prog = opt_init(argc, argv, version_options);
61     while ((o = opt_next()) != OPT_EOF) {
62         switch (o) {
63         case OPT_EOF:
64         case OPT_ERR:
65             BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
66             goto end;
67         case OPT_HELP:
68             opt_help(version_options);
69             ret = 0;
70             goto end;
71         case OPT_B:
72             dirty = date = 1;
73             break;
74         case OPT_D:
75             dirty = dir = 1;
76             break;
77         case OPT_E:
78             dirty = engdir = 1;
79             break;
80         case OPT_F:
81             dirty = cflags = 1;
82             break;
83         case OPT_O:
84             dirty = options = 1;
85             break;
86         case OPT_P:
87             dirty = platform = 1;
88             break;
89         case OPT_R:
90             dirty = seed = 1;
91             break;
92         case OPT_V:
93             dirty = version = 1;
94             break;
95         case OPT_A:
96             seed = cflags = version = date = platform = dir = engdir = 1;
97             break;
98         }
99     }
100     if (!dirty)
101         version = 1;
102
103     if (version) {
104         if (OpenSSL_version_num() == OPENSSL_VERSION_NUMBER)
105             printf("%s\n", OpenSSL_version(OPENSSL_VERSION));
106         else
107             printf("%s (Library: %s)\n",
108                    OPENSSL_VERSION_TEXT, OpenSSL_version(OPENSSL_VERSION));
109     }
110     if (date)
111         printf("%s\n", OpenSSL_version(OPENSSL_BUILT_ON));
112     if (platform)
113         printf("%s\n", OpenSSL_version(OPENSSL_PLATFORM));
114     if (options) {
115         printf("options:  ");
116         printf("%s ", BN_options());
117 #ifndef OPENSSL_NO_MD2
118         printf("%s ", MD2_options());
119 #endif
120 #ifndef OPENSSL_NO_RC4
121         printf("%s ", RC4_options());
122 #endif
123 #ifndef OPENSSL_NO_DES
124         printf("%s ", DES_options());
125 #endif
126 #ifndef OPENSSL_NO_IDEA
127         printf("%s ", IDEA_options());
128 #endif
129 #ifndef OPENSSL_NO_BF
130         printf("%s ", BF_options());
131 #endif
132         printf("\n");
133     }
134     if (cflags)
135         printf("%s\n", OpenSSL_version(OPENSSL_CFLAGS));
136     if (dir)
137         printf("%s\n", OpenSSL_version(OPENSSL_DIR));
138     if (engdir)
139         printf("%s\n", OpenSSL_version(OPENSSL_ENGINES_DIR));
140     if (seed) {
141         printf("Seeding source:");
142 #ifdef OPENSSL_RAND_SEED_RTDSC
143         printf(" rtdsc");
144 #endif
145 #ifdef OPENSSL_RAND_SEED_RDCPU
146         printf(" rdrand-hardware");
147 #endif
148 #ifdef OPENSSL_RAND_SEED_LIBRANDOM
149         printf(" C-library-random");
150 #endif
151 #ifdef OPENSSL_RAND_SEED_GETRANDOM
152         printf(" getrandom-syscall");
153 #endif
154 #ifdef OPENSSL_RAND_SEED_DEVRANDOM
155         printf(" random-device");
156 #endif
157 #ifdef OPENSSL_RAND_SEED_EGD
158         printf(" EGD");
159 #endif
160 #ifdef OPENSSL_RAND_SEED_NONE
161         printf(" none");
162 #endif
163 #ifdef OPENSSL_RAND_SEED_OS
164         printf(" os-specific");
165 #endif
166         printf("\n");
167     }
168     ret = 0;
169  end:
170     return (ret);
171 }