OpenSSL: update to 1.0.1m
[tomato.git] / release / src / router / openssl / apps / openssl.c.rej
blob763bad318a66cd752f820d16c9a7a34497c4065e
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"
6  
8  static int do_cmd(LHASH_OF(FUNCTION) *prog, int argc, char *argv[])
9 -       {
10 -       FUNCTION f,*fp;
11 -       int i,ret=1,tp,nl;
13 -       if ((argc <= 0) || (argv[0] == NULL))
14 -               { ret=0; goto end; }
15 -       f.name=argv[0];
16 -       fp=lh_FUNCTION_retrieve(prog,&f);
17 -       if (fp == NULL)
18 -               {
19 -               if (EVP_get_digestbyname(argv[0]))
20 -                       {
21 -                       f.type = FUNC_TYPE_MD;
22 -                       f.func = dgst_main;
23 -                       fp = &f;
24 -                       }
25 -               else if (EVP_get_cipherbyname(argv[0]))
26 -                       {
27 -                       f.type = FUNC_TYPE_CIPHER;
28 -                       f.func = enc_main;
29 -                       fp = &f;
30 -                       }
31 -               }
32 -       if (fp != NULL)
33 -               {
34 -               ret=fp->func(argc,argv);
35 -               }
36 -       else if ((strncmp(argv[0],"no-",3)) == 0)
37 -               {
38 -               BIO *bio_stdout = BIO_new_fp(stdout,BIO_NOCLOSE);
40 +    FUNCTION f, *fp;
41 +    int i, ret = 1, tp, nl;
43 +    if ((argc <= 0) || (argv[0] == NULL)) {
44 +        ret = 0;
45 +        goto end;
46 +    }
47 +    f.name = argv[0];
48 +    fp = lh_FUNCTION_retrieve(prog, &f);
49 +    if (fp == NULL) {
50 +        if (EVP_get_digestbyname(argv[0])) {
51 +            f.type = FUNC_TYPE_MD;
52 +            f.func = dgst_main;
53 +            fp = &f;
54 +        } else if (EVP_get_cipherbyname(argv[0])) {
55 +            f.type = FUNC_TYPE_CIPHER;
56 +            f.func = enc_main;
57 +            fp = &f;
58 +        }
59 +    }
60 +    if (fp != NULL) {
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
65 -               {
66 -               BIO *tmpbio = BIO_new(BIO_f_linebuffer());
67 -               bio_stdout = BIO_push(tmpbio, bio_stdout);
68 -               }
69 -#endif
70 -               f.name=argv[0]+3;
71 -               ret = (lh_FUNCTION_retrieve(prog,&f) != NULL);
72 -               if (!ret)
73 -                       BIO_printf(bio_stdout, "%s\n", argv[0]);
74 -               else
75 -                       BIO_printf(bio_stdout, "%s\n", argv[0]+3);
76 -               BIO_free_all(bio_stdout);
77 -               goto end;
78 -               }
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))
83 -               {
84 -               ret= -1;
85 -               goto end;
86 -               }
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))
93 -               {
94 -               int list_type;
95 -               BIO *bio_stdout;
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);
110 +        {
111 +            BIO *tmpbio = BIO_new(BIO_f_linebuffer());
112 +            bio_stdout = BIO_push(tmpbio, bio_stdout);
113 +        }
114 +#endif
115 +        f.name = argv[0] + 3;
116 +        ret = (lh_FUNCTION_retrieve(prog, &f) != NULL);
117 +        if (!ret)
118 +            BIO_printf(bio_stdout, "%s\n", argv[0]);
119 +        else
120 +            BIO_printf(bio_stdout, "%s\n", argv[0] + 3);
121 +        BIO_free_all(bio_stdout);
122 +        goto end;
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)) {
127 +        ret = -1;
128 +        goto end;
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)) {
135 +        int list_type;
136 +        BIO *bio_stdout;
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
152 -               {
153 -               BIO *tmpbio = BIO_new(BIO_f_linebuffer());
154 -               bio_stdout = BIO_push(tmpbio, bio_stdout);
155 -               }
156 -#endif
158 -               if (!load_config(bio_err, NULL))
159 -                       goto end;
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);        
167 -               else
168 -                       {
169 -                       for (fp=functions; fp->name != NULL; fp++)
170 -                               if (fp->type == list_type)
171 -                                       BIO_printf(bio_stdout, "%s\n",
172 -                                                               fp->name);
173 -                       }
174 -               BIO_free_all(bio_stdout);
175 -               ret=0;
176 -               goto end;
177 -               }
178 -       else
179 -               {
180 -               BIO_printf(bio_err,"openssl:Error: '%s' is an invalid command.\n",
181 -                       argv[0]);
182 -               BIO_printf(bio_err, "\nStandard commands");
183 -               i=0;
184 -               tp=0;
185 -               for (fp=functions; fp->name != NULL; fp++)
186 -                       {
187 -                       nl=0;
188 +        {
189 +            BIO *tmpbio = BIO_new(BIO_f_linebuffer());
190 +            bio_stdout = BIO_push(tmpbio, bio_stdout);
191 +        }
192 +#endif
194 +        if (!load_config(bio_err, NULL))
195 +            goto end;
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);
203 +        else {
204 +            for (fp = functions; fp->name != NULL; fp++)
205 +                if (fp->type == list_type)
206 +                    BIO_printf(bio_stdout, "%s\n", fp->name);
207 +        }
208 +        BIO_free_all(bio_stdout);
209 +        ret = 0;
210 +        goto end;
211 +    } else {
212 +        BIO_printf(bio_err, "openssl:Error: '%s' is an invalid command.\n",
213 +                   argv[0]);
214 +        BIO_printf(bio_err, "\nStandard commands");
215 +        i = 0;
216 +        tp = 0;
217 +        for (fp = functions; fp->name != NULL; fp++) {
218 +            nl = 0;
219  #ifdef OPENSSL_NO_CAMELLIA
220 -                       if (((i++) % 5) == 0)
221 +            if (((i++) % 5) == 0)
222  #else
223 -                       if (((i++) % 4) == 0)
224 +            if (((i++) % 4) == 0)
225  #endif
226 -                               {
227 -                               BIO_printf(bio_err,"\n");
228 -                               nl=1;
229 -                               }
230 -                       if (fp->type != tp)
231 -                               {
232 -                               tp=fp->type;
233 -                               if (!nl) BIO_printf(bio_err,"\n");
234 -                               if (tp == FUNC_TYPE_MD)
235 -                                       {
236 -                                       i=1;
237 -                                       BIO_printf(bio_err,
238 -                                               "\nMessage Digest commands (see the `dgst' command for more details)\n");
239 -                                       }
240 -                               else if (tp == FUNC_TYPE_CIPHER)
241 -                                       {
242 -                                       i=1;
243 -                                       BIO_printf(bio_err,"\nCipher commands (see the `enc' command for more details)\n");
244 -                                       }
245 -                               }
246 +            {
247 +                BIO_printf(bio_err, "\n");
248 +                nl = 1;
249 +            }
250 +            if (fp->type != tp) {
251 +                tp = fp->type;
252 +                if (!nl)
253 +                    BIO_printf(bio_err, "\n");
254 +                if (tp == FUNC_TYPE_MD) {
255 +                    i = 1;
256 +                    BIO_printf(bio_err,
257 +                               "\nMessage Digest commands (see the `dgst' command for more details)\n");
258 +                } else if (tp == FUNC_TYPE_CIPHER) {
259 +                    i = 1;
260 +                    BIO_printf(bio_err,
261 +                               "\nCipher commands (see the `enc' command for more details)\n");
262 +                }
263 +            }
264  #ifdef OPENSSL_NO_CAMELLIA
265 -                       BIO_printf(bio_err,"%-15s",fp->name);
266 +            BIO_printf(bio_err, "%-15s", fp->name);
267  #else
268 -                       BIO_printf(bio_err,"%-18s",fp->name);
269 +            BIO_printf(bio_err, "%-18s", fp->name);
270  #endif
271 -                       }
272 -               BIO_printf(bio_err,"\n\n");
273 -               ret=0;
274 -               }
275 -end:
276 -       return(ret);
277 -       }
279 -static int SortFnByName(const void *_f1,const void *_f2)
280 -    {
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);
287 +        }
288 +        BIO_printf(bio_err, "\n\n");
289 +        ret = 0;
290      }
291 + end:
292 +    return (ret);
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)
306 -       {
307 -       int i;
308 -       for (i = 0; i < EVP_PKEY_asn1_get_count(); i++)
309 -               {
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)
317 -                       {
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));
322 -                       }
323 -               else
324 -                       {
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);
333 -                       }
334 -                                       
335 -               }
336 -       }
338 +    int i;
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));
350 +        } else {
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);
359 +        }
361 +    }
364  static void list_cipher_fn(const EVP_CIPHER *c,
365 -                       const char *from, const char *to, void *arg)
366 -       {
367 -       if (c)
368 -               BIO_printf(arg, "%s\n", EVP_CIPHER_name(c));
369 -       else
370 -               {
371 -               if (!from)
372 -                       from = "<undefined>";
373 -               if (!to)
374 -                       to = "<undefined>";
375 -               BIO_printf(arg, "%s => %s\n", from, to);
376 -               }
377 -       }
378 +                           const char *from, const char *to, void *arg)
380 +    if (c)
381 +        BIO_printf(arg, "%s\n", EVP_CIPHER_name(c));
382 +    else {
383 +        if (!from)
384 +            from = "<undefined>";
385 +        if (!to)
386 +            to = "<undefined>";
387 +        BIO_printf(arg, "%s => %s\n", from, to);
388 +    }
391  static void list_cipher(BIO *out)
392 -       {
393 -       EVP_CIPHER_do_all_sorted(list_cipher_fn, out);
394 -       }
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)
401 -       {
402 -       if (m)
403 -               BIO_printf(arg, "%s\n", EVP_MD_name(m));
404 -       else
405 -               {
406 -               if (!from)
407 -                       from = "<undefined>";
408 -               if (!to)
409 -                       to = "<undefined>";
410 -               BIO_printf(arg, "%s => %s\n", from, to);
411 -               }
412 -       }
413 +                       const char *from, const char *to, void *arg)
415 +    if (m)
416 +        BIO_printf(arg, "%s\n", EVP_MD_name(m));
417 +    else {
418 +        if (!from)
419 +            from = "<undefined>";
420 +        if (!to)
421 +            to = "<undefined>";
422 +        BIO_printf(arg, "%s => %s\n", from, to);
423 +    }
426  static void list_md(BIO *out)
427 -       {
428 -       EVP_MD_do_all_sorted(list_md_fn, out);
429 -       }
431 -static int MS_CALLBACK function_cmp(const FUNCTION *a, const FUNCTION *b)
432 -       {
433 -       return strncmp(a->name,b->name,8);
434 -       }
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)
447 -       {
448 -       return lh_strhash(a->name);
449 -       }       
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)
458 -       {
459 -       LHASH_OF(FUNCTION) *ret;
460 -       FUNCTION *f;
461 -       size_t i;
463 -       /* Purely so it looks nice when the user hits ? */
464 -       for(i=0,f=functions ; f->name != NULL ; ++f,++i)
465 -           ;
466 -       qsort(functions,i,sizeof *functions,SortFnByName);
468 -       if ((ret=lh_FUNCTION_new()) == NULL)
469 -               return(NULL);
471 -       for (f=functions; f->name != NULL; f++)
472 -               (void)lh_FUNCTION_insert(ret,f);
473 -       return(ret);
474 -       }
477 +    LHASH_OF(FUNCTION) *ret;
478 +    FUNCTION *f;
479 +    size_t i;
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)
486 +        return (NULL);
488 +    for (f = functions; f->name != NULL; f++)
489 +        (void)lh_FUNCTION_insert(ret, f);
490 +    return (ret);