1 --- apps/openssl.c 2015-01-15 15:43:49.000000000 +0100
2 +++ apps/openssl.c 2015-03-19 14:19:00.000000000 +0100
3 @@ -451,270 +441,246 @@
4 #define LIST_CIPHER_ALGORITHMS "list-cipher-algorithms"
5 #define LIST_PUBLIC_KEY_ALGORITHMS "list-public-key-algorithms"
8 static int do_cmd(LHASH_OF(FUNCTION) *prog, int argc, char *argv[])
13 - if ((argc <= 0) || (argv[0] == NULL))
14 - { ret=0; goto end; }
16 - fp=lh_FUNCTION_retrieve(prog,&f);
19 - if (EVP_get_digestbyname(argv[0]))
21 - f.type = FUNC_TYPE_MD;
25 - else if (EVP_get_cipherbyname(argv[0]))
27 - f.type = FUNC_TYPE_CIPHER;
34 - ret=fp->func(argc,argv);
36 - else if ((strncmp(argv[0],"no-",3)) == 0)
38 - BIO *bio_stdout = BIO_new_fp(stdout,BIO_NOCLOSE);
41 + int i, ret = 1, tp, nl;
43 + if ((argc <= 0) || (argv[0] == NULL)) {
48 + fp = lh_FUNCTION_retrieve(prog, &f);
50 + if (EVP_get_digestbyname(argv[0])) {
51 + f.type = FUNC_TYPE_MD;
54 + } else if (EVP_get_cipherbyname(argv[0])) {
55 + f.type = FUNC_TYPE_CIPHER;
61 + ret = fp->func(argc, argv);
62 + } else if ((strncmp(argv[0], "no-", 3)) == 0) {
63 + BIO *bio_stdout = BIO_new_fp(stdout, BIO_NOCLOSE);
64 #ifdef OPENSSL_SYS_VMS
66 - BIO *tmpbio = BIO_new(BIO_f_linebuffer());
67 - bio_stdout = BIO_push(tmpbio, bio_stdout);
71 - ret = (lh_FUNCTION_retrieve(prog,&f) != NULL);
73 - BIO_printf(bio_stdout, "%s\n", argv[0]);
75 - BIO_printf(bio_stdout, "%s\n", argv[0]+3);
76 - BIO_free_all(bio_stdout);
79 - else if ((strcmp(argv[0],"quit") == 0) ||
80 - (strcmp(argv[0],"q") == 0) ||
81 - (strcmp(argv[0],"exit") == 0) ||
82 - (strcmp(argv[0],"bye") == 0))
87 - else if ((strcmp(argv[0],LIST_STANDARD_COMMANDS) == 0) ||
88 - (strcmp(argv[0],LIST_MESSAGE_DIGEST_COMMANDS) == 0) ||
89 - (strcmp(argv[0],LIST_MESSAGE_DIGEST_ALGORITHMS) == 0) ||
90 - (strcmp(argv[0],LIST_CIPHER_COMMANDS) == 0) ||
91 - (strcmp(argv[0],LIST_CIPHER_ALGORITHMS) == 0) ||
92 - (strcmp(argv[0],LIST_PUBLIC_KEY_ALGORITHMS) == 0))
97 - if (strcmp(argv[0],LIST_STANDARD_COMMANDS) == 0)
98 - list_type = FUNC_TYPE_GENERAL;
99 - else if (strcmp(argv[0],LIST_MESSAGE_DIGEST_COMMANDS) == 0)
100 - list_type = FUNC_TYPE_MD;
101 - else if (strcmp(argv[0],LIST_MESSAGE_DIGEST_ALGORITHMS) == 0)
102 - list_type = FUNC_TYPE_MD_ALG;
103 - else if (strcmp(argv[0],LIST_PUBLIC_KEY_ALGORITHMS) == 0)
104 - list_type = FUNC_TYPE_PKEY;
105 - else if (strcmp(argv[0],LIST_CIPHER_ALGORITHMS) == 0)
106 - list_type = FUNC_TYPE_CIPHER_ALG;
107 - else /* strcmp(argv[0],LIST_CIPHER_COMMANDS) == 0 */
108 - list_type = FUNC_TYPE_CIPHER;
109 - bio_stdout = BIO_new_fp(stdout,BIO_NOCLOSE);
111 + BIO *tmpbio = BIO_new(BIO_f_linebuffer());
112 + bio_stdout = BIO_push(tmpbio, bio_stdout);
115 + f.name = argv[0] + 3;
116 + ret = (lh_FUNCTION_retrieve(prog, &f) != NULL);
118 + BIO_printf(bio_stdout, "%s\n", argv[0]);
120 + BIO_printf(bio_stdout, "%s\n", argv[0] + 3);
121 + BIO_free_all(bio_stdout);
123 + } else if ((strcmp(argv[0], "quit") == 0) ||
124 + (strcmp(argv[0], "q") == 0) ||
125 + (strcmp(argv[0], "exit") == 0) ||
126 + (strcmp(argv[0], "bye") == 0)) {
129 + } else if ((strcmp(argv[0], LIST_STANDARD_COMMANDS) == 0) ||
130 + (strcmp(argv[0], LIST_MESSAGE_DIGEST_COMMANDS) == 0) ||
131 + (strcmp(argv[0], LIST_MESSAGE_DIGEST_ALGORITHMS) == 0) ||
132 + (strcmp(argv[0], LIST_CIPHER_COMMANDS) == 0) ||
133 + (strcmp(argv[0], LIST_CIPHER_ALGORITHMS) == 0) ||
134 + (strcmp(argv[0], LIST_PUBLIC_KEY_ALGORITHMS) == 0)) {
138 + if (strcmp(argv[0], LIST_STANDARD_COMMANDS) == 0)
139 + list_type = FUNC_TYPE_GENERAL;
140 + else if (strcmp(argv[0], LIST_MESSAGE_DIGEST_COMMANDS) == 0)
141 + list_type = FUNC_TYPE_MD;
142 + else if (strcmp(argv[0], LIST_MESSAGE_DIGEST_ALGORITHMS) == 0)
143 + list_type = FUNC_TYPE_MD_ALG;
144 + else if (strcmp(argv[0], LIST_PUBLIC_KEY_ALGORITHMS) == 0)
145 + list_type = FUNC_TYPE_PKEY;
146 + else if (strcmp(argv[0], LIST_CIPHER_ALGORITHMS) == 0)
147 + list_type = FUNC_TYPE_CIPHER_ALG;
148 + else /* strcmp(argv[0],LIST_CIPHER_COMMANDS) == 0 */
149 + list_type = FUNC_TYPE_CIPHER;
150 + bio_stdout = BIO_new_fp(stdout, BIO_NOCLOSE);
151 #ifdef OPENSSL_SYS_VMS
153 - BIO *tmpbio = BIO_new(BIO_f_linebuffer());
154 - bio_stdout = BIO_push(tmpbio, bio_stdout);
158 - if (!load_config(bio_err, NULL))
161 - if (list_type == FUNC_TYPE_PKEY)
162 - list_pkey(bio_stdout);
163 - if (list_type == FUNC_TYPE_MD_ALG)
164 - list_md(bio_stdout);
165 - if (list_type == FUNC_TYPE_CIPHER_ALG)
166 - list_cipher(bio_stdout);
169 - for (fp=functions; fp->name != NULL; fp++)
170 - if (fp->type == list_type)
171 - BIO_printf(bio_stdout, "%s\n",
174 - BIO_free_all(bio_stdout);
180 - BIO_printf(bio_err,"openssl:Error: '%s' is an invalid command.\n",
182 - BIO_printf(bio_err, "\nStandard commands");
185 - for (fp=functions; fp->name != NULL; fp++)
189 + BIO *tmpbio = BIO_new(BIO_f_linebuffer());
190 + bio_stdout = BIO_push(tmpbio, bio_stdout);
194 + if (!load_config(bio_err, NULL))
197 + if (list_type == FUNC_TYPE_PKEY)
198 + list_pkey(bio_stdout);
199 + if (list_type == FUNC_TYPE_MD_ALG)
200 + list_md(bio_stdout);
201 + if (list_type == FUNC_TYPE_CIPHER_ALG)
202 + list_cipher(bio_stdout);
204 + for (fp = functions; fp->name != NULL; fp++)
205 + if (fp->type == list_type)
206 + BIO_printf(bio_stdout, "%s\n", fp->name);
208 + BIO_free_all(bio_stdout);
212 + BIO_printf(bio_err, "openssl:Error: '%s' is an invalid command.\n",
214 + BIO_printf(bio_err, "\nStandard commands");
217 + for (fp = functions; fp->name != NULL; fp++) {
219 #ifdef OPENSSL_NO_CAMELLIA
220 - if (((i++) % 5) == 0)
221 + if (((i++) % 5) == 0)
223 - if (((i++) % 4) == 0)
224 + if (((i++) % 4) == 0)
227 - BIO_printf(bio_err,"\n");
230 - if (fp->type != tp)
233 - if (!nl) BIO_printf(bio_err,"\n");
234 - if (tp == FUNC_TYPE_MD)
237 - BIO_printf(bio_err,
238 - "\nMessage Digest commands (see the `dgst' command for more details)\n");
240 - else if (tp == FUNC_TYPE_CIPHER)
243 - BIO_printf(bio_err,"\nCipher commands (see the `enc' command for more details)\n");
247 + BIO_printf(bio_err, "\n");
250 + if (fp->type != tp) {
253 + BIO_printf(bio_err, "\n");
254 + if (tp == FUNC_TYPE_MD) {
256 + BIO_printf(bio_err,
257 + "\nMessage Digest commands (see the `dgst' command for more details)\n");
258 + } else if (tp == FUNC_TYPE_CIPHER) {
260 + BIO_printf(bio_err,
261 + "\nCipher commands (see the `enc' command for more details)\n");
264 #ifdef OPENSSL_NO_CAMELLIA
265 - BIO_printf(bio_err,"%-15s",fp->name);
266 + BIO_printf(bio_err, "%-15s", fp->name);
268 - BIO_printf(bio_err,"%-18s",fp->name);
269 + BIO_printf(bio_err, "%-18s", fp->name);
272 - BIO_printf(bio_err,"\n\n");
279 -static int SortFnByName(const void *_f1,const void *_f2)
281 - const FUNCTION *f1=_f1;
282 - const FUNCTION *f2=_f2;
284 - if(f1->type != f2->type)
285 - return f1->type-f2->type;
286 - return strcmp(f1->name,f2->name);
288 + BIO_printf(bio_err, "\n\n");
295 +static int SortFnByName(const void *_f1, const void *_f2)
297 + const FUNCTION *f1 = _f1;
298 + const FUNCTION *f2 = _f2;
300 + if (f1->type != f2->type)
301 + return f1->type - f2->type;
302 + return strcmp(f1->name, f2->name);
305 static void list_pkey(BIO *out)
308 - for (i = 0; i < EVP_PKEY_asn1_get_count(); i++)
310 - const EVP_PKEY_ASN1_METHOD *ameth;
311 - int pkey_id, pkey_base_id, pkey_flags;
312 - const char *pinfo, *pem_str;
313 - ameth = EVP_PKEY_asn1_get0(i);
314 - EVP_PKEY_asn1_get0_info(&pkey_id, &pkey_base_id, &pkey_flags,
315 - &pinfo, &pem_str, ameth);
316 - if (pkey_flags & ASN1_PKEY_ALIAS)
318 - BIO_printf(out, "Name: %s\n",
319 - OBJ_nid2ln(pkey_id));
320 - BIO_printf(out, "\tType: Alias to %s\n",
321 - OBJ_nid2ln(pkey_base_id));
325 - BIO_printf(out, "Name: %s\n", pinfo);
326 - BIO_printf(out, "\tType: %s Algorithm\n",
327 - pkey_flags & ASN1_PKEY_DYNAMIC ?
328 - "External" : "Builtin");
329 - BIO_printf(out, "\tOID: %s\n", OBJ_nid2ln(pkey_id));
330 - if (pem_str == NULL)
331 - pem_str = "(none)";
332 - BIO_printf(out, "\tPEM string: %s\n", pem_str);
339 + for (i = 0; i < EVP_PKEY_asn1_get_count(); i++) {
340 + const EVP_PKEY_ASN1_METHOD *ameth;
341 + int pkey_id, pkey_base_id, pkey_flags;
342 + const char *pinfo, *pem_str;
343 + ameth = EVP_PKEY_asn1_get0(i);
344 + EVP_PKEY_asn1_get0_info(&pkey_id, &pkey_base_id, &pkey_flags,
345 + &pinfo, &pem_str, ameth);
346 + if (pkey_flags & ASN1_PKEY_ALIAS) {
347 + BIO_printf(out, "Name: %s\n", OBJ_nid2ln(pkey_id));
348 + BIO_printf(out, "\tType: Alias to %s\n",
349 + OBJ_nid2ln(pkey_base_id));
351 + BIO_printf(out, "Name: %s\n", pinfo);
352 + BIO_printf(out, "\tType: %s Algorithm\n",
353 + pkey_flags & ASN1_PKEY_DYNAMIC ?
354 + "External" : "Builtin");
355 + BIO_printf(out, "\tOID: %s\n", OBJ_nid2ln(pkey_id));
356 + if (pem_str == NULL)
357 + pem_str = "(none)";
358 + BIO_printf(out, "\tPEM string: %s\n", pem_str);
364 static void list_cipher_fn(const EVP_CIPHER *c,
365 - const char *from, const char *to, void *arg)
368 - BIO_printf(arg, "%s\n", EVP_CIPHER_name(c));
372 - from = "<undefined>";
374 - to = "<undefined>";
375 - BIO_printf(arg, "%s => %s\n", from, to);
378 + const char *from, const char *to, void *arg)
381 + BIO_printf(arg, "%s\n", EVP_CIPHER_name(c));
384 + from = "<undefined>";
386 + to = "<undefined>";
387 + BIO_printf(arg, "%s => %s\n", from, to);
391 static void list_cipher(BIO *out)
393 - EVP_CIPHER_do_all_sorted(list_cipher_fn, out);
396 + EVP_CIPHER_do_all_sorted(list_cipher_fn, out);
399 static void list_md_fn(const EVP_MD *m,
400 - const char *from, const char *to, void *arg)
403 - BIO_printf(arg, "%s\n", EVP_MD_name(m));
407 - from = "<undefined>";
409 - to = "<undefined>";
410 - BIO_printf(arg, "%s => %s\n", from, to);
413 + const char *from, const char *to, void *arg)
416 + BIO_printf(arg, "%s\n", EVP_MD_name(m));
419 + from = "<undefined>";
421 + to = "<undefined>";
422 + BIO_printf(arg, "%s => %s\n", from, to);
426 static void list_md(BIO *out)
428 - EVP_MD_do_all_sorted(list_md_fn, out);
431 -static int MS_CALLBACK function_cmp(const FUNCTION *a, const FUNCTION *b)
433 - return strncmp(a->name,b->name,8);
436 + EVP_MD_do_all_sorted(list_md_fn, out);
439 +static int MS_CALLBACK function_cmp(const FUNCTION * a, const FUNCTION * b)
441 + return strncmp(a->name, b->name, 8);
444 static IMPLEMENT_LHASH_COMP_FN(function, FUNCTION)
446 -static unsigned long MS_CALLBACK function_hash(const FUNCTION *a)
448 - return lh_strhash(a->name);
450 +static unsigned long MS_CALLBACK function_hash(const FUNCTION * a)
452 + return lh_strhash(a->name);
455 static IMPLEMENT_LHASH_HASH_FN(function, FUNCTION)
457 static LHASH_OF(FUNCTION) *prog_init(void)
459 - LHASH_OF(FUNCTION) *ret;
463 - /* Purely so it looks nice when the user hits ? */
464 - for(i=0,f=functions ; f->name != NULL ; ++f,++i)
466 - qsort(functions,i,sizeof *functions,SortFnByName);
468 - if ((ret=lh_FUNCTION_new()) == NULL)
471 - for (f=functions; f->name != NULL; f++)
472 - (void)lh_FUNCTION_insert(ret,f);
477 + LHASH_OF(FUNCTION) *ret;
481 + /* Purely so it looks nice when the user hits ? */
482 + for (i = 0, f = functions; f->name != NULL; ++f, ++i) ;
483 + qsort(functions, i, sizeof *functions, SortFnByName);
485 + if ((ret = lh_FUNCTION_new()) == NULL)
488 + for (f = functions; f->name != NULL; f++)
489 + (void)lh_FUNCTION_insert(ret, f);