xref: /openbsd/lib/libcrypto/evp/evp_names.c (revision 73530852)
1 /*	$OpenBSD: evp_names.c,v 1.18 2024/08/31 10:38:49 tb Exp $ */
2 /*
3  * Copyright (c) 2023 Theo Buehler <tb@openbsd.org>
4  *
5  * Permission to use, copy, modify, and distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16  */
17 
18 #include <openssl/err.h>
19 #include <openssl/evp.h>
20 #include <openssl/objects.h>
21 
22 #include <stdlib.h>
23 #include <string.h>
24 
25 /*
26  * In the following two structs, .name is the lookup name that is used
27  * for EVP_get_cipherbyname() and EVP_get_digestbyname(), while .alias
28  * keeps track of the aliased name.
29  */
30 
31 struct cipher_name {
32 	const char *name;
33 	const EVP_CIPHER *(*cipher)(void);
34 	const char *alias;
35 };
36 
37 struct digest_name {
38 	const char *name;
39 	const EVP_MD *(*digest)(void);
40 	const char *alias;
41 };
42 
43 /*
44  * Keep this table alphabetically sorted by increasing .name.
45  * regress/lib/libcrypto/evp/evp_test.c checks that.
46  */
47 
48 static const struct cipher_name cipher_names[] = {
49 	{
50 		.name = SN_aes_128_cbc,
51 		.cipher = EVP_aes_128_cbc,
52 	},
53 	{
54 		.name = SN_aes_128_cfb128,
55 		.cipher = EVP_aes_128_cfb128,
56 	},
57 	{
58 		.name = SN_aes_128_cfb1,
59 		.cipher = EVP_aes_128_cfb1,
60 	},
61 	{
62 		.name = SN_aes_128_cfb8,
63 		.cipher = EVP_aes_128_cfb8,
64 	},
65 	{
66 		.name = SN_aes_128_ctr,
67 		.cipher = EVP_aes_128_ctr,
68 	},
69 	{
70 		.name = SN_aes_128_ecb,
71 		.cipher = EVP_aes_128_ecb,
72 	},
73 	{
74 		.name = SN_aes_128_ofb128,
75 		.cipher = EVP_aes_128_ofb,
76 	},
77 	{
78 		.name = SN_aes_128_xts,
79 		.cipher = EVP_aes_128_xts,
80 	},
81 
82 	{
83 		.name = SN_aes_192_cbc,
84 		.cipher = EVP_aes_192_cbc,
85 	},
86 	{
87 		.name = SN_aes_192_cfb128,
88 		.cipher = EVP_aes_192_cfb128,
89 	},
90 	{
91 		.name = SN_aes_192_cfb1,
92 		.cipher = EVP_aes_192_cfb1,
93 	},
94 	{
95 		.name = SN_aes_192_cfb8,
96 		.cipher = EVP_aes_192_cfb8,
97 	},
98 	{
99 		.name = SN_aes_192_ctr,
100 		.cipher = EVP_aes_192_ctr,
101 	},
102 	{
103 		.name = SN_aes_192_ecb,
104 		.cipher = EVP_aes_192_ecb,
105 	},
106 	{
107 		.name = SN_aes_192_ofb128,
108 		.cipher = EVP_aes_192_ofb,
109 	},
110 
111 	{
112 		.name = SN_aes_256_cbc,
113 		.cipher = EVP_aes_256_cbc,
114 	},
115 	{
116 		.name = SN_aes_256_cfb128,
117 		.cipher = EVP_aes_256_cfb128,
118 	},
119 	{
120 		.name = SN_aes_256_cfb1,
121 		.cipher = EVP_aes_256_cfb1,
122 	},
123 	{
124 		.name = SN_aes_256_cfb8,
125 		.cipher = EVP_aes_256_cfb8,
126 	},
127 	{
128 		.name = SN_aes_256_ctr,
129 		.cipher = EVP_aes_256_ctr,
130 	},
131 	{
132 		.name = SN_aes_256_ecb,
133 		.cipher = EVP_aes_256_ecb,
134 	},
135 	{
136 		.name = SN_aes_256_ofb128,
137 		.cipher = EVP_aes_256_ofb,
138 	},
139 	{
140 		.name = SN_aes_256_xts,
141 		.cipher = EVP_aes_256_xts,
142 	},
143 
144 	{
145 		.name = "AES128",
146 		.cipher = EVP_aes_128_cbc,
147 		.alias = SN_aes_128_cbc,
148 	},
149 	{
150 		.name = "AES192",
151 		.cipher = EVP_aes_192_cbc,
152 		.alias = SN_aes_192_cbc,
153 	},
154 	{
155 		.name = "AES256",
156 		.cipher = EVP_aes_256_cbc,
157 		.alias = SN_aes_256_cbc,
158 	},
159 
160 	{
161 		.name = "BF",
162 		.cipher = EVP_bf_cbc,
163 		.alias = SN_bf_cbc,
164 	},
165 
166 	{
167 		.name = SN_bf_cbc,
168 		.cipher = EVP_bf_cbc,
169 	},
170 	{
171 		.name = SN_bf_cfb64,
172 		.cipher = EVP_bf_cfb64,
173 	},
174 	{
175 		.name = SN_bf_ecb,
176 		.cipher = EVP_bf_ecb,
177 	},
178 	{
179 		.name = SN_bf_ofb64,
180 		.cipher = EVP_bf_ofb,
181 	},
182 
183 	{
184 		.name = SN_camellia_128_cbc,
185 		.cipher = EVP_camellia_128_cbc,
186 	},
187 	{
188 		.name = SN_camellia_128_cfb128,
189 		.cipher = EVP_camellia_128_cfb128,
190 	},
191 	{
192 		.name = SN_camellia_128_cfb1,
193 		.cipher = EVP_camellia_128_cfb1,
194 	},
195 	{
196 		.name = SN_camellia_128_cfb8,
197 		.cipher = EVP_camellia_128_cfb8,
198 	},
199 	{
200 		.name = SN_camellia_128_ecb,
201 		.cipher = EVP_camellia_128_ecb,
202 	},
203 	{
204 		.name = SN_camellia_128_ofb128,
205 		.cipher = EVP_camellia_128_ofb,
206 	},
207 
208 	{
209 		.name = SN_camellia_192_cbc,
210 		.cipher = EVP_camellia_192_cbc,
211 	},
212 	{
213 		.name = SN_camellia_192_cfb128,
214 		.cipher = EVP_camellia_192_cfb128,
215 	},
216 	{
217 		.name = SN_camellia_192_cfb1,
218 		.cipher = EVP_camellia_192_cfb1,
219 	},
220 	{
221 		.name = SN_camellia_192_cfb8,
222 		.cipher = EVP_camellia_192_cfb8,
223 	},
224 	{
225 		.name = SN_camellia_192_ecb,
226 		.cipher = EVP_camellia_192_ecb,
227 	},
228 	{
229 		.name = SN_camellia_192_ofb128,
230 		.cipher = EVP_camellia_192_ofb,
231 	},
232 
233 	{
234 		.name = SN_camellia_256_cbc,
235 		.cipher = EVP_camellia_256_cbc,
236 	},
237 	{
238 		.name = SN_camellia_256_cfb128,
239 		.cipher = EVP_camellia_256_cfb128,
240 	},
241 	{
242 		.name = SN_camellia_256_cfb1,
243 		.cipher = EVP_camellia_256_cfb1,
244 	},
245 	{
246 		.name = SN_camellia_256_cfb8,
247 		.cipher = EVP_camellia_256_cfb8,
248 	},
249 	{
250 		.name = SN_camellia_256_ecb,
251 		.cipher = EVP_camellia_256_ecb,
252 	},
253 	{
254 		.name = SN_camellia_256_ofb128,
255 		.cipher = EVP_camellia_256_ofb,
256 	},
257 
258 	{
259 		.name = "CAMELLIA128",
260 		.cipher = EVP_camellia_128_cbc,
261 		.alias = SN_camellia_128_cbc,
262 	},
263 	{
264 		.name = "CAMELLIA192",
265 		.cipher = EVP_camellia_192_cbc,
266 		.alias = SN_camellia_192_cbc,
267 	},
268 	{
269 		.name = "CAMELLIA256",
270 		.cipher = EVP_camellia_256_cbc,
271 		.alias = SN_camellia_256_cbc,
272 	},
273 
274 	{
275 		.name = "CAST",
276 		.cipher = EVP_cast5_cbc,
277 		.alias = SN_cast5_cbc,
278 	},
279 	{
280 		.name = "CAST-cbc",
281 		.cipher = EVP_cast5_cbc,
282 		.alias = SN_cast5_cbc,
283 	},
284 
285 	{
286 		.name = SN_cast5_cbc,
287 		.cipher = EVP_cast5_cbc,
288 	},
289 	{
290 		.name = SN_cast5_cfb64,
291 		.cipher = EVP_cast5_cfb,
292 	},
293 	{
294 		.name = SN_cast5_ecb,
295 		.cipher = EVP_cast5_ecb,
296 	},
297 	{
298 		.name = SN_cast5_ofb64,
299 		.cipher = EVP_cast5_ofb,
300 	},
301 
302 	{
303 		.name = SN_chacha20,
304 		.cipher = EVP_chacha20,
305 	},
306 	{
307 		.name = "ChaCha20",
308 		.cipher = EVP_chacha20,
309 		.alias = SN_chacha20,
310 	},
311 
312 	{
313 		.name = SN_chacha20_poly1305,
314 		.cipher = EVP_chacha20_poly1305,
315 	},
316 
317 	{
318 		.name = "DES",
319 		.cipher = EVP_des_cbc,
320 		.alias = SN_des_cbc,
321 	},
322 
323 	{
324 		.name = SN_des_cbc,
325 		.cipher = EVP_des_cbc,
326 	},
327 	{
328 		.name = SN_des_cfb64,
329 		.cipher = EVP_des_cfb64,
330 	},
331 	{
332 		.name = SN_des_cfb1,
333 		.cipher = EVP_des_cfb1,
334 	},
335 	{
336 		.name = SN_des_cfb8,
337 		.cipher = EVP_des_cfb8,
338 	},
339 	{
340 		.name = SN_des_ecb,
341 		.cipher = EVP_des_ecb,
342 	},
343 	{
344 		.name = SN_des_ede_ecb,
345 		.cipher = EVP_des_ede,
346 	},
347 	{
348 		.name = SN_des_ede_cbc,
349 		.cipher = EVP_des_ede_cbc,
350 	},
351 	{
352 		.name = SN_des_ede_cfb64,
353 		.cipher = EVP_des_ede_cfb64,
354 	},
355 	{
356 		.name = SN_des_ede_ofb64,
357 		.cipher = EVP_des_ede_ofb,
358 	},
359 	{
360 		.name = SN_des_ede3_ecb,
361 		.cipher = EVP_des_ede3_ecb,
362 	},
363 	{
364 		.name = SN_des_ede3_cbc,
365 		.cipher = EVP_des_ede3_cbc,
366 	},
367 	{
368 		.name = SN_des_ede3_cfb64,
369 		.cipher = EVP_des_ede3_cfb,
370 	},
371 	{
372 		.name = SN_des_ede3_cfb1,
373 		.cipher = EVP_des_ede3_cfb1,
374 	},
375 	{
376 		.name = SN_des_ede3_cfb8,
377 		.cipher = EVP_des_ede3_cfb8,
378 	},
379 	{
380 		.name = SN_des_ede3_ofb64,
381 		.cipher = EVP_des_ede3_ofb,
382 	},
383 	{
384 		.name = SN_des_ofb64,
385 		.cipher = EVP_des_ofb,
386 	},
387 
388 	{
389 		.name = "DES3",
390 		.cipher = EVP_des_ede3_cbc,
391 		.alias = SN_des_ede3_cbc,
392 	},
393 
394 	{
395 		.name = "DESX",
396 		.cipher = EVP_desx_cbc,
397 		.alias = SN_desx_cbc,
398 	},
399 	{
400 		.name = SN_desx_cbc,
401 		.cipher = EVP_desx_cbc,
402 	},
403 
404 	{
405 		.name = "IDEA",
406 		.cipher = EVP_idea_cbc,
407 		.alias = SN_idea_cbc,
408 	},
409 
410 	{
411 		.name = SN_idea_cbc,
412 		.cipher = EVP_idea_cbc,
413 	},
414 	{
415 		.name = SN_idea_cfb64,
416 		.cipher = EVP_idea_cfb64,
417 	},
418 	{
419 		.name = SN_idea_ecb,
420 		.cipher = EVP_idea_ecb,
421 	},
422 	{
423 		.name = SN_idea_ofb64,
424 		.cipher = EVP_idea_ofb,
425 	},
426 
427 	{
428 		.name = "RC2",
429 		.cipher = EVP_rc2_cbc,
430 		.alias = SN_rc2_cbc,
431 	},
432 
433 	{
434 		.name = SN_rc2_40_cbc,
435 		.cipher = EVP_rc2_40_cbc,
436 	},
437 	{
438 		.name = SN_rc2_64_cbc,
439 		.cipher = EVP_rc2_64_cbc,
440 	},
441 	{
442 		.name = SN_rc2_cbc,
443 		.cipher = EVP_rc2_cbc,
444 	},
445 	{
446 		.name = SN_rc2_cfb64,
447 		.cipher = EVP_rc2_cfb64,
448 	},
449 	{
450 		.name = SN_rc2_ecb,
451 		.cipher = EVP_rc2_ecb,
452 	},
453 	{
454 		.name = SN_rc2_ofb64,
455 		.cipher = EVP_rc2_ofb,
456 	},
457 
458 	{
459 		.name = SN_rc4,
460 		.cipher = EVP_rc4,
461 	},
462 	{
463 		.name = SN_rc4_40,
464 		.cipher = EVP_rc4_40,
465 	},
466 
467 	{
468 		.name = "SM4",
469 		.cipher = EVP_sm4_cbc,
470 		.alias = SN_sm4_cbc,
471 	},
472 
473 	{
474 		.name = SN_sm4_cbc,
475 		.cipher = EVP_sm4_cbc,
476 	},
477 	{
478 		.name = SN_sm4_cfb128,
479 		.cipher = EVP_sm4_cfb128,
480 	},
481 	{
482 		.name = SN_sm4_ctr,
483 		.cipher = EVP_sm4_ctr,
484 	},
485 	{
486 		.name = SN_sm4_ecb,
487 		.cipher = EVP_sm4_ecb,
488 	},
489 	{
490 		.name = SN_sm4_ofb128,
491 		.cipher = EVP_sm4_ofb,
492 	},
493 
494 	{
495 		.name = LN_aes_128_cbc,
496 		.cipher = EVP_aes_128_cbc,
497 	},
498 	{
499 		.name = LN_aes_128_ccm,
500 		.cipher = EVP_aes_128_ccm,
501 	},
502 	{
503 		.name = LN_aes_128_cfb128,
504 		.cipher = EVP_aes_128_cfb128,
505 	},
506 	{
507 		.name = LN_aes_128_cfb1,
508 		.cipher = EVP_aes_128_cfb1,
509 	},
510 	{
511 		.name = LN_aes_128_cfb8,
512 		.cipher = EVP_aes_128_cfb8,
513 	},
514 	{
515 		.name = LN_aes_128_ctr,
516 		.cipher = EVP_aes_128_ctr,
517 	},
518 	{
519 		.name = LN_aes_128_ecb,
520 		.cipher = EVP_aes_128_ecb,
521 	},
522 	{
523 		.name = LN_aes_128_gcm,
524 		.cipher = EVP_aes_128_gcm,
525 	},
526 	{
527 		.name = LN_aes_128_ofb128,
528 		.cipher = EVP_aes_128_ofb,
529 	},
530 	{
531 		.name = LN_aes_128_xts,
532 		.cipher = EVP_aes_128_xts,
533 	},
534 
535 	{
536 		.name = LN_aes_192_cbc,
537 		.cipher = EVP_aes_192_cbc,
538 	},
539 	{
540 		.name = LN_aes_192_ccm,
541 		.cipher = EVP_aes_192_ccm,
542 	},
543 	{
544 		.name = LN_aes_192_cfb128,
545 		.cipher = EVP_aes_192_cfb128,
546 	},
547 	{
548 		.name = LN_aes_192_cfb1,
549 		.cipher = EVP_aes_192_cfb1,
550 	},
551 	{
552 		.name = LN_aes_192_cfb8,
553 		.cipher = EVP_aes_192_cfb8,
554 	},
555 	{
556 		.name = LN_aes_192_ctr,
557 		.cipher = EVP_aes_192_ctr,
558 	},
559 	{
560 		.name = LN_aes_192_ecb,
561 		.cipher = EVP_aes_192_ecb,
562 	},
563 	{
564 		.name = LN_aes_192_gcm,
565 		.cipher = EVP_aes_192_gcm,
566 	},
567 	{
568 		.name = LN_aes_192_ofb128,
569 		.cipher = EVP_aes_192_ofb,
570 	},
571 
572 	{
573 		.name = LN_aes_256_cbc,
574 		.cipher = EVP_aes_256_cbc,
575 	},
576 	{
577 		.name = LN_aes_256_ccm,
578 		.cipher = EVP_aes_256_ccm,
579 	},
580 	{
581 		.name = LN_aes_256_cfb128,
582 		.cipher = EVP_aes_256_cfb128,
583 	},
584 	{
585 		.name = LN_aes_256_cfb1,
586 		.cipher = EVP_aes_256_cfb1,
587 	},
588 	{
589 		.name = LN_aes_256_cfb8,
590 		.cipher = EVP_aes_256_cfb8,
591 	},
592 	{
593 		.name = LN_aes_256_ctr,
594 		.cipher = EVP_aes_256_ctr,
595 	},
596 	{
597 		.name = LN_aes_256_ecb,
598 		.cipher = EVP_aes_256_ecb,
599 	},
600 	{
601 		.name = LN_aes_256_gcm,
602 		.cipher = EVP_aes_256_gcm,
603 	},
604 	{
605 		.name = LN_aes_256_ofb128,
606 		.cipher = EVP_aes_256_ofb,
607 	},
608 	{
609 		.name = LN_aes_256_xts,
610 		.cipher = EVP_aes_256_xts,
611 	},
612 
613 	{
614 		.name = "aes128",
615 		.cipher = EVP_aes_128_cbc,
616 		.alias = SN_aes_128_cbc,
617 	},
618 	{
619 		.name = "aes192",
620 		.cipher = EVP_aes_192_cbc,
621 		.alias = SN_aes_192_cbc,
622 	},
623 	{
624 		.name = "aes256",
625 		.cipher = EVP_aes_256_cbc,
626 		.alias = SN_aes_256_cbc,
627 	},
628 
629 	{
630 		.name = "bf",
631 		.cipher = EVP_bf_cbc,
632 		.alias = SN_bf_cbc,
633 	},
634 
635 	{
636 		.name = LN_bf_cbc,
637 		.cipher = EVP_bf_cbc,
638 	},
639 	{
640 		.name = LN_bf_cfb64,
641 		.cipher = EVP_bf_cfb64,
642 	},
643 	{
644 		.name = LN_bf_ecb,
645 		.cipher = EVP_bf_ecb,
646 	},
647 	{
648 		.name = LN_bf_ofb64,
649 		.cipher = EVP_bf_ofb,
650 	},
651 
652 	{
653 		.name = "blowfish",
654 		.cipher = EVP_bf_cbc,
655 		.alias = SN_bf_cbc,
656 	},
657 
658 	{
659 		.name = LN_camellia_128_cbc,
660 		.cipher = EVP_camellia_128_cbc,
661 	},
662 	{
663 		.name = LN_camellia_128_cfb128,
664 		.cipher = EVP_camellia_128_cfb128,
665 	},
666 	{
667 		.name = LN_camellia_128_cfb1,
668 		.cipher = EVP_camellia_128_cfb1,
669 	},
670 	{
671 		.name = LN_camellia_128_cfb8,
672 		.cipher = EVP_camellia_128_cfb8,
673 	},
674 	{
675 		.name = LN_camellia_128_ecb,
676 		.cipher = EVP_camellia_128_ecb,
677 	},
678 	{
679 		.name = LN_camellia_128_ofb128,
680 		.cipher = EVP_camellia_128_ofb,
681 	},
682 
683 	{
684 		.name = LN_camellia_192_cbc,
685 		.cipher = EVP_camellia_192_cbc,
686 	},
687 	{
688 		.name = LN_camellia_192_cfb128,
689 		.cipher = EVP_camellia_192_cfb128,
690 	},
691 	{
692 		.name = LN_camellia_192_cfb1,
693 		.cipher = EVP_camellia_192_cfb1,
694 	},
695 	{
696 		.name = LN_camellia_192_cfb8,
697 		.cipher = EVP_camellia_192_cfb8,
698 	},
699 	{
700 		.name = LN_camellia_192_ecb,
701 		.cipher = EVP_camellia_192_ecb,
702 	},
703 	{
704 		.name = LN_camellia_192_ofb128,
705 		.cipher = EVP_camellia_192_ofb,
706 	},
707 
708 	{
709 		.name = LN_camellia_256_cbc,
710 		.cipher = EVP_camellia_256_cbc,
711 	},
712 	{
713 		.name = LN_camellia_256_cfb128,
714 		.cipher = EVP_camellia_256_cfb128,
715 	},
716 	{
717 		.name = LN_camellia_256_cfb1,
718 		.cipher = EVP_camellia_256_cfb1,
719 	},
720 	{
721 		.name = LN_camellia_256_cfb8,
722 		.cipher = EVP_camellia_256_cfb8,
723 	},
724 	{
725 		.name = LN_camellia_256_ecb,
726 		.cipher = EVP_camellia_256_ecb,
727 	},
728 	{
729 		.name = LN_camellia_256_ofb128,
730 		.cipher = EVP_camellia_256_ofb,
731 	},
732 
733 	{
734 		.name = "camellia128",
735 		.cipher = EVP_camellia_128_cbc,
736 		.alias = SN_camellia_128_cbc,
737 	},
738 	{
739 		.name = "camellia192",
740 		.cipher = EVP_camellia_192_cbc,
741 		.alias = SN_camellia_192_cbc,
742 	},
743 	{
744 		.name = "camellia256",
745 		.cipher = EVP_camellia_256_cbc,
746 		.alias = SN_camellia_256_cbc,
747 	},
748 
749 	{
750 		.name = "cast",
751 		.cipher = EVP_cast5_cbc,
752 		.alias = SN_cast5_cbc,
753 	},
754 	{
755 		.name = "cast-cbc",
756 		.cipher = EVP_cast5_cbc,
757 		.alias = SN_cast5_cbc,
758 	},
759 
760 	{
761 		.name = LN_cast5_cbc,
762 		.cipher = EVP_cast5_cbc,
763 	},
764 	{
765 		.name = LN_cast5_cfb64,
766 		.cipher = EVP_cast5_cfb,
767 	},
768 	{
769 		.name = LN_cast5_ecb,
770 		.cipher = EVP_cast5_ecb,
771 	},
772 	{
773 		.name = LN_cast5_ofb64,
774 		.cipher = EVP_cast5_ofb,
775 	},
776 
777 	{
778 		.name = LN_chacha20,
779 		.cipher = EVP_chacha20,
780 	},
781 	{
782 		.name = "chacha20",
783 		.cipher = EVP_chacha20,
784 		.alias = LN_chacha20,
785 	},
786 
787 	{
788 		.name = LN_chacha20_poly1305,
789 		.cipher = EVP_chacha20_poly1305,
790 	},
791 
792 	{
793 		.name = "des",
794 		.cipher = EVP_des_cbc,
795 		.alias = SN_des_cbc,
796 	},
797 
798 	{
799 		.name = LN_des_cbc,
800 		.cipher = EVP_des_cbc,
801 	},
802 	{
803 		.name = LN_des_cfb64,
804 		.cipher = EVP_des_cfb64,
805 	},
806 	{
807 		.name = LN_des_cfb1,
808 		.cipher = EVP_des_cfb1,
809 	},
810 	{
811 		.name = LN_des_cfb8,
812 		.cipher = EVP_des_cfb8,
813 	},
814 	{
815 		.name = LN_des_ecb,
816 		.cipher = EVP_des_ecb,
817 	},
818 	{
819 		.name = LN_des_ede_ecb,
820 		.cipher = EVP_des_ede,
821 	},
822 	{
823 		.name = LN_des_ede_cbc,
824 		.cipher = EVP_des_ede_cbc,
825 	},
826 	{
827 		.name = LN_des_ede_cfb64,
828 		.cipher = EVP_des_ede_cfb64,
829 	},
830 	{
831 		.name = LN_des_ede_ofb64,
832 		.cipher = EVP_des_ede_ofb,
833 	},
834 	{
835 		.name = LN_des_ede3_ecb,
836 		.cipher = EVP_des_ede3_ecb,
837 	},
838 	{
839 		.name = LN_des_ede3_cbc,
840 		.cipher = EVP_des_ede3_cbc,
841 	},
842 	{
843 		.name = LN_des_ede3_cfb64,
844 		.cipher = EVP_des_ede3_cfb,
845 	},
846 	{
847 		.name = LN_des_ede3_cfb1,
848 		.cipher = EVP_des_ede3_cfb1,
849 	},
850 	{
851 		.name = LN_des_ede3_cfb8,
852 		.cipher = EVP_des_ede3_cfb8,
853 	},
854 	{
855 		.name = LN_des_ede3_ofb64,
856 		.cipher = EVP_des_ede3_ofb,
857 	},
858 	{
859 		.name = LN_des_ofb64,
860 		.cipher = EVP_des_ofb,
861 	},
862 
863 	{
864 		.name = "des3",
865 		.cipher = EVP_des_ede3_cbc,
866 		.alias = SN_des_ede3_cbc,
867 	},
868 
869 	{
870 		.name = "desx",
871 		.cipher = EVP_desx_cbc,
872 		.alias = SN_desx_cbc,
873 	},
874 	{
875 		.name = LN_desx_cbc,
876 		.cipher = EVP_desx_cbc,
877 	},
878 
879 	{
880 		.name = SN_aes_128_ccm,
881 		.cipher = EVP_aes_128_ccm,
882 	},
883 	{
884 		.name = SN_aes_128_gcm,
885 		.cipher = EVP_aes_128_gcm,
886 	},
887 	{
888 		.name = SN_id_aes128_wrap,
889 		.cipher = EVP_aes_128_wrap,
890 	},
891 
892 	{
893 		.name = SN_aes_192_ccm,
894 		.cipher = EVP_aes_192_ccm,
895 	},
896 	{
897 		.name = SN_aes_192_gcm,
898 		.cipher = EVP_aes_192_gcm,
899 	},
900 	{
901 		.name = SN_id_aes192_wrap,
902 		.cipher = EVP_aes_192_wrap,
903 	},
904 
905 	{
906 		.name = SN_aes_256_ccm,
907 		.cipher = EVP_aes_256_ccm,
908 	},
909 	{
910 		.name = SN_aes_256_gcm,
911 		.cipher = EVP_aes_256_gcm,
912 	},
913 	{
914 		.name = SN_id_aes256_wrap,
915 		.cipher = EVP_aes_256_wrap,
916 	},
917 
918 	{
919 		.name = "idea",
920 		.cipher = EVP_idea_cbc,
921 		.alias = SN_idea_cbc,
922 	},
923 
924 	{
925 		.name = LN_idea_cbc,
926 		.cipher = EVP_idea_cbc,
927 	},
928 	{
929 		.name = LN_idea_cfb64,
930 		.cipher = EVP_idea_cfb64,
931 	},
932 	{
933 		.name = LN_idea_ecb,
934 		.cipher = EVP_idea_ecb,
935 	},
936 	{
937 		.name = LN_idea_ofb64,
938 		.cipher = EVP_idea_ofb,
939 	},
940 
941 	{
942 		.name = "rc2",
943 		.cipher = EVP_rc2_cbc,
944 		.alias = SN_rc2_cbc,
945 	},
946 
947 	{
948 		.name = LN_rc2_40_cbc,
949 		.cipher = EVP_rc2_40_cbc,
950 	},
951 	{
952 		.name = LN_rc2_64_cbc,
953 		.cipher = EVP_rc2_64_cbc,
954 	},
955 	{
956 		.name = LN_rc2_cbc,
957 		.cipher = EVP_rc2_cbc,
958 	},
959 	{
960 		.name = LN_rc2_cfb64,
961 		.cipher = EVP_rc2_cfb64,
962 	},
963 	{
964 		.name = LN_rc2_ecb,
965 		.cipher = EVP_rc2_ecb,
966 	},
967 	{
968 		.name = LN_rc2_ofb64,
969 		.cipher = EVP_rc2_ofb,
970 	},
971 
972 	{
973 		.name = LN_rc4,
974 		.cipher = EVP_rc4,
975 	},
976 	{
977 		.name = LN_rc4_40,
978 		.cipher = EVP_rc4_40,
979 	},
980 
981 	{
982 		.name = "sm4",
983 		.cipher = EVP_sm4_cbc,
984 		.alias = SN_sm4_cbc,
985 	},
986 
987 	{
988 		.name = LN_sm4_cbc,
989 		.cipher = EVP_sm4_cbc,
990 	},
991 	{
992 		.name = LN_sm4_cfb128,
993 		.cipher = EVP_sm4_cfb128,
994 	},
995 	{
996 		.name = LN_sm4_ctr,
997 		.cipher = EVP_sm4_ctr,
998 	},
999 	{
1000 		.name = LN_sm4_ecb,
1001 		.cipher = EVP_sm4_ecb,
1002 	},
1003 	{
1004 		.name = LN_sm4_ofb128,
1005 		.cipher = EVP_sm4_ofb,
1006 	},
1007 };
1008 
1009 #define N_CIPHER_NAMES (sizeof(cipher_names) / sizeof(cipher_names[0]))
1010 
1011 /*
1012  * Keep this table alphabetically sorted by increasing .name.
1013  * regress/lib/libcrypto/evp/evp_test.c checks that.
1014  */
1015 
1016 static const struct digest_name digest_names[] = {
1017 	{
1018 		.name = SN_dsaWithSHA1,
1019 		.digest = EVP_sha1,
1020 		.alias = SN_sha1,
1021 	},
1022 
1023 	{
1024 		.name = SN_md4,
1025 		.digest = EVP_md4,
1026 	},
1027 
1028 	{
1029 		.name = SN_md5,
1030 		.digest = EVP_md5,
1031 	},
1032 
1033 	{
1034 		.name = SN_md5_sha1,
1035 		.digest = EVP_md5_sha1,
1036 	},
1037 
1038 	{
1039 		.name = SN_ripemd160,
1040 		.digest = EVP_ripemd160,
1041 	},
1042 
1043 	{
1044 		.name = SN_md4WithRSAEncryption,
1045 		.digest = EVP_md4,
1046 		.alias = SN_md4,
1047 	},
1048 	{
1049 		.name = SN_md5WithRSAEncryption,
1050 		.digest = EVP_md5,
1051 		.alias = SN_md5,
1052 	},
1053 	{
1054 		.name = SN_ripemd160WithRSA,
1055 		.digest = EVP_ripemd160,
1056 		.alias = SN_ripemd160,
1057 	},
1058 	{
1059 		.name = SN_sha1WithRSAEncryption,
1060 		.digest = EVP_sha1,
1061 		.alias = SN_sha1,
1062 	},
1063 	{
1064 		.name = SN_sha1WithRSA,
1065 		.digest = EVP_sha1,
1066 		.alias = SN_sha1, /* XXX - alias to SN_sha1WithRSAEncryption? */
1067 	},
1068 	{
1069 		.name = SN_sha224WithRSAEncryption,
1070 		.digest = EVP_sha224,
1071 		.alias = SN_sha224,
1072 	},
1073 	{
1074 		.name = SN_sha256WithRSAEncryption,
1075 		.digest = EVP_sha256,
1076 		.alias = SN_sha256,
1077 	},
1078 	{
1079 		.name = LN_RSA_SHA3_224,
1080 		.digest = EVP_sha3_224,
1081 		.alias = SN_sha3_224,
1082 	},
1083 	{
1084 		.name = LN_RSA_SHA3_256,
1085 		.digest = EVP_sha3_256,
1086 		.alias = SN_sha3_256,
1087 	},
1088 	{
1089 		.name = LN_RSA_SHA3_384,
1090 		.digest = EVP_sha3_384,
1091 		.alias = SN_sha3_384,
1092 	},
1093 	{
1094 		.name = LN_RSA_SHA3_512,
1095 		.digest = EVP_sha3_512,
1096 		.alias = SN_sha3_512,
1097 	},
1098 	{
1099 		.name = SN_sha384WithRSAEncryption,
1100 		.digest = EVP_sha384,
1101 		.alias = SN_sha384,
1102 	},
1103 	{
1104 		.name = SN_sha512WithRSAEncryption,
1105 		.digest = EVP_sha512,
1106 		.alias = SN_sha512,
1107 	},
1108 	{
1109 		.name = SN_sha512_224WithRSAEncryption,
1110 		.digest = EVP_sha512_224,
1111 		.alias = SN_sha512_224,
1112 	},
1113 	{
1114 		.name = SN_sha512_256WithRSAEncryption,
1115 		.digest = EVP_sha512_256,
1116 		.alias = SN_sha512_256,
1117 	},
1118 	{
1119 		.name = SN_sm3WithRSAEncryption,
1120 		.digest = EVP_sm3,
1121 		.alias = SN_sm3,
1122 	},
1123 
1124 	{
1125 		.name = SN_sha1,
1126 		.digest = EVP_sha1,
1127 	},
1128 	{
1129 		.name = SN_sha224,
1130 		.digest = EVP_sha224,
1131 	},
1132 	{
1133 		.name = SN_sha256,
1134 		.digest = EVP_sha256,
1135 	},
1136 	{
1137 		.name = SN_sha3_224,
1138 		.digest = EVP_sha3_224,
1139 	},
1140 	{
1141 		.name = SN_sha3_256,
1142 		.digest = EVP_sha3_256,
1143 	},
1144 	{
1145 		.name = SN_sha3_384,
1146 		.digest = EVP_sha3_384,
1147 	},
1148 	{
1149 		.name = SN_sha3_512,
1150 		.digest = EVP_sha3_512,
1151 	},
1152 
1153 	{
1154 		.name = SN_sha384,
1155 		.digest = EVP_sha384,
1156 	},
1157 	{
1158 		.name = SN_sha512,
1159 		.digest = EVP_sha512,
1160 	},
1161 	{
1162 		.name = SN_sha512_224,
1163 		.digest = EVP_sha512_224,
1164 	},
1165 	{
1166 		.name = SN_sha512_256,
1167 		.digest = EVP_sha512_256,
1168 	},
1169 
1170 	{
1171 		.name = SN_sm3,
1172 		.digest = EVP_sm3,
1173 	},
1174 
1175 	{
1176 		.name = LN_dsaWithSHA1,
1177 		.digest = EVP_sha1,
1178 		.alias = SN_sha1,
1179 	},
1180 
1181 	{
1182 		.name = LN_dsa_with_SHA224,
1183 		.digest = EVP_sha224,
1184 		.alias = SN_sha224,
1185 	},
1186 	{
1187 		.name = LN_dsa_with_SHA256,
1188 		.digest = EVP_sha256,
1189 		.alias = SN_sha256,
1190 	},
1191 	{
1192 		.name = LN_dsa_with_SHA384,
1193 		.digest = EVP_sha384,
1194 		.alias = SN_sha384,
1195 	},
1196 	{
1197 		.name = LN_dsa_with_SHA512,
1198 		.digest = EVP_sha512,
1199 		.alias = SN_sha512,
1200 	},
1201 
1202 	{
1203 		.name = SN_ecdsa_with_SHA1,
1204 		.digest = EVP_sha1,
1205 		.alias = SN_sha1,
1206 	},
1207 
1208 	{
1209 		.name = SN_ecdsa_with_SHA224,
1210 		.digest = EVP_sha224,
1211 		.alias = SN_sha224,
1212 	},
1213 	{
1214 		.name = SN_ecdsa_with_SHA256,
1215 		.digest = EVP_sha256,
1216 		.alias = SN_sha256,
1217 	},
1218 	{
1219 		.name = SN_ecdsa_with_SHA384,
1220 		.digest = EVP_sha384,
1221 		.alias = SN_sha384,
1222 	},
1223 	{
1224 		.name = SN_ecdsa_with_SHA512,
1225 		.digest = EVP_sha512,
1226 		.alias = SN_sha512,
1227 	},
1228 
1229 	{
1230 		.name = SN_dsa_with_SHA224,
1231 		.digest = EVP_sha224,
1232 		.alias = SN_sha224,
1233 	},
1234 	{
1235 		.name = SN_dsa_with_SHA256,
1236 		.digest = EVP_sha256,
1237 		.alias = SN_sha256,
1238 	},
1239 
1240 	{
1241 		.name = SN_dsa_with_SHA3_224,
1242 		.digest = EVP_sha3_224,
1243 		.alias = SN_sha3_224,
1244 	},
1245 	{
1246 		.name = SN_dsa_with_SHA3_256,
1247 		.digest = EVP_sha3_256,
1248 		.alias = SN_sha3_256,
1249 	},
1250 	{
1251 		.name = SN_dsa_with_SHA3_384,
1252 		.digest = EVP_sha3_384,
1253 		.alias = SN_sha3_384,
1254 	},
1255 	{
1256 		.name = SN_dsa_with_SHA3_512,
1257 		.digest = EVP_sha3_512,
1258 		.alias = SN_sha3_512,
1259 	},
1260 
1261 	{
1262 		.name = SN_dsa_with_SHA384,
1263 		.digest = EVP_sha384,
1264 		.alias = SN_sha384,
1265 	},
1266 	{
1267 		.name = SN_dsa_with_SHA512,
1268 		.digest = EVP_sha512,
1269 		.alias = SN_sha512,
1270 	},
1271 
1272 	{
1273 		.name = SN_ecdsa_with_SHA3_224,
1274 		.digest = EVP_sha3_224,
1275 		.alias = SN_sha3_224,
1276 	},
1277 	{
1278 		.name = SN_ecdsa_with_SHA3_256,
1279 		.digest = EVP_sha3_256,
1280 		.alias = SN_sha3_256,
1281 	},
1282 	{
1283 		.name = SN_ecdsa_with_SHA3_384,
1284 		.digest = EVP_sha3_384,
1285 		.alias = SN_sha3_384,
1286 	},
1287 	{
1288 		.name = SN_ecdsa_with_SHA3_512,
1289 		.digest = EVP_sha3_512,
1290 		.alias = SN_sha3_512,
1291 	},
1292 
1293 	{
1294 		.name = SN_RSA_SHA3_224,
1295 		.digest = EVP_sha3_224,
1296 		.alias = SN_sha3_224,
1297 	},
1298 	{
1299 		.name = SN_RSA_SHA3_256,
1300 		.digest = EVP_sha3_256,
1301 		.alias = SN_sha3_256,
1302 	},
1303 	{
1304 		.name = SN_RSA_SHA3_384,
1305 		.digest = EVP_sha3_384,
1306 		.alias = SN_sha3_384,
1307 	},
1308 	{
1309 		.name = SN_RSA_SHA3_512,
1310 		.digest = EVP_sha3_512,
1311 		.alias = SN_sha3_512,
1312 	},
1313 
1314 	{
1315 		.name = LN_md4,
1316 		.digest = EVP_md4,
1317 	},
1318 	{
1319 		.name = LN_md4WithRSAEncryption,
1320 		.digest = EVP_md4,
1321 		.alias = SN_md4,
1322 	},
1323 
1324 	{
1325 		.name = LN_md5,
1326 		.digest = EVP_md5,
1327 	},
1328 	{
1329 		.name = LN_md5_sha1,
1330 		.digest = EVP_md5_sha1,
1331 	},
1332 	{
1333 		.name = LN_md5WithRSAEncryption,
1334 		.digest = EVP_md5,
1335 		.alias = SN_md5,
1336 	},
1337 
1338 	{
1339 		.name = "ripemd",
1340 		.digest = EVP_ripemd160,
1341 		.alias = SN_ripemd160,
1342 	},
1343 	{
1344 		.name = LN_ripemd160,
1345 		.digest = EVP_ripemd160,
1346 	},
1347 	{
1348 		.name = LN_ripemd160WithRSA,
1349 		.digest = EVP_ripemd160,
1350 		.alias = SN_ripemd160,
1351 	},
1352 	{
1353 		.name = "rmd160",
1354 		.digest = EVP_ripemd160,
1355 		.alias = SN_ripemd160,
1356 	},
1357 
1358 	{
1359 		.name = LN_sha1,
1360 		.digest = EVP_sha1,
1361 	},
1362 	{
1363 		.name = LN_sha1WithRSAEncryption,
1364 		.digest = EVP_sha1,
1365 		.alias = SN_sha1,
1366 	},
1367 
1368 	{
1369 		.name = LN_sha224,
1370 		.digest = EVP_sha224,
1371 	},
1372 	{
1373 		.name = LN_sha224WithRSAEncryption,
1374 		.digest = EVP_sha224,
1375 		.alias = SN_sha224,
1376 	},
1377 	{
1378 		.name = LN_sha256,
1379 		.digest = EVP_sha256,
1380 	},
1381 	{
1382 		.name = LN_sha256WithRSAEncryption,
1383 		.digest = EVP_sha256,
1384 		.alias = SN_sha256,
1385 	},
1386 
1387 	{
1388 		.name = LN_sha3_224,
1389 		.digest = EVP_sha3_224,
1390 	},
1391 	{
1392 		.name = LN_sha3_256,
1393 		.digest = EVP_sha3_256,
1394 	},
1395 	{
1396 		.name = LN_sha3_384,
1397 		.digest = EVP_sha3_384,
1398 	},
1399 	{
1400 		.name = LN_sha3_512,
1401 		.digest = EVP_sha3_512,
1402 	},
1403 
1404 	{
1405 		.name = LN_sha384,
1406 		.digest = EVP_sha384,
1407 	},
1408 	{
1409 		.name = LN_sha384WithRSAEncryption,
1410 		.digest = EVP_sha384,
1411 		.alias = SN_sha384,
1412 	},
1413 	{
1414 		.name = LN_sha512,
1415 		.digest = EVP_sha512,
1416 	},
1417 	{
1418 		.name = LN_sha512_224,
1419 		.digest = EVP_sha512_224,
1420 	},
1421 	{
1422 		.name = LN_sha512_224WithRSAEncryption,
1423 		.digest = EVP_sha512_224,
1424 		.alias = SN_sha512_224,
1425 	},
1426 	{
1427 		.name = LN_sha512_256,
1428 		.digest = EVP_sha512_256,
1429 	},
1430 	{
1431 		.name = LN_sha512_256WithRSAEncryption,
1432 		.digest = EVP_sha512_256,
1433 		.alias = SN_sha512_256,
1434 	},
1435 	{
1436 		.name = LN_sha512WithRSAEncryption,
1437 		.digest = EVP_sha512,
1438 		.alias = SN_sha512,
1439 	},
1440 
1441 	{
1442 		.name = LN_sm3,
1443 		.digest = EVP_sm3,
1444 	},
1445 	{
1446 		.name = LN_sm3WithRSAEncryption,
1447 		.digest = EVP_sm3,
1448 		.alias = SN_sm3,
1449 	},
1450 
1451 	{
1452 		.name = "ssl2-md5",
1453 		.digest = EVP_md5,
1454 		.alias = SN_md5,
1455 	},
1456 	{
1457 		.name = "ssl3-md5",
1458 		.digest = EVP_md5,
1459 		.alias = SN_md5,
1460 	},
1461 
1462 	{
1463 		.name = "ssl3-sha1",
1464 		.digest = EVP_sha1,
1465 		.alias = SN_sha1,
1466 	},
1467 };
1468 
1469 #define N_DIGEST_NAMES (sizeof(digest_names) / sizeof(digest_names[0]))
1470 
1471 void
EVP_CIPHER_do_all_sorted(void (* fn)(const EVP_CIPHER *,const char *,const char *,void *),void * arg)1472 EVP_CIPHER_do_all_sorted(void (*fn)(const EVP_CIPHER *, const char *,
1473     const char *, void *), void *arg)
1474 {
1475 	size_t i;
1476 
1477 	/* Prayer and clean living lets you ignore errors, OpenSSL style. */
1478 	(void)OPENSSL_init_crypto(0, NULL);
1479 
1480 	for (i = 0; i < N_CIPHER_NAMES; i++) {
1481 		const struct cipher_name *cipher = &cipher_names[i];
1482 		const EVP_CIPHER *evp_cipher;
1483 
1484 		if ((evp_cipher = cipher->cipher()) == NULL)
1485 			continue;
1486 
1487 		if (cipher->alias != NULL)
1488 			fn(NULL, cipher->name, cipher->alias, arg);
1489 		else
1490 			fn(evp_cipher, cipher->name, NULL, arg);
1491 	}
1492 }
1493 LCRYPTO_ALIAS(EVP_CIPHER_do_all_sorted);
1494 
1495 void
EVP_CIPHER_do_all(void (* fn)(const EVP_CIPHER *,const char *,const char *,void *),void * arg)1496 EVP_CIPHER_do_all(void (*fn)(const EVP_CIPHER *, const char *, const char *,
1497     void *), void *arg)
1498 {
1499 	EVP_CIPHER_do_all_sorted(fn, arg);
1500 }
1501 LCRYPTO_ALIAS(EVP_CIPHER_do_all);
1502 
1503 void
EVP_MD_do_all_sorted(void (* fn)(const EVP_MD *,const char *,const char *,void *),void * arg)1504 EVP_MD_do_all_sorted(void (*fn)(const EVP_MD *, const char *, const char *,
1505     void *), void *arg)
1506 {
1507 	size_t i;
1508 
1509 	/* Prayer and clean living lets you ignore errors, OpenSSL style. */
1510 	(void)OPENSSL_init_crypto(0, NULL);
1511 
1512 	for (i = 0; i < N_DIGEST_NAMES; i++) {
1513 		const struct digest_name *digest = &digest_names[i];
1514 		const EVP_MD *evp_md;
1515 
1516 		if ((evp_md = digest->digest()) == NULL)
1517 			continue;
1518 
1519 		if (digest->alias != NULL)
1520 			fn(NULL, digest->name, digest->alias, arg);
1521 		else
1522 			fn(evp_md, digest->name, NULL, arg);
1523 	}
1524 }
1525 LCRYPTO_ALIAS(EVP_MD_do_all_sorted);
1526 
1527 void
EVP_MD_do_all(void (* fn)(const EVP_MD *,const char *,const char *,void *),void * arg)1528 EVP_MD_do_all(void (*fn)(const EVP_MD *, const char *, const char *, void *),
1529     void *arg)
1530 {
1531 	EVP_MD_do_all_sorted(fn, arg);
1532 }
1533 LCRYPTO_ALIAS(EVP_MD_do_all);
1534 
1535 /*
1536  * The OBJ_NAME API is completely misnamed. It has little to do with objects
1537  * and a lot to do with EVP. Therefore we implement a saner replacement for
1538  * the part of the old madness that we need to keep in the evp directory.
1539  */
1540 
1541 static int
OBJ_NAME_from_cipher_name(OBJ_NAME * obj_name,const struct cipher_name * cipher)1542 OBJ_NAME_from_cipher_name(OBJ_NAME *obj_name, const struct cipher_name *cipher)
1543 {
1544 	const EVP_CIPHER *evp_cipher;
1545 
1546 	if ((evp_cipher = cipher->cipher()) == NULL)
1547 		return 0;
1548 
1549 	obj_name->type = OBJ_NAME_TYPE_CIPHER_METH;
1550 	obj_name->name = cipher->name;
1551 	if (cipher->alias != NULL) {
1552 		obj_name->alias = OBJ_NAME_ALIAS;
1553 		obj_name->data = cipher->alias;
1554 	} else {
1555 		obj_name->alias = 0;
1556 		obj_name->data = evp_cipher;
1557 	}
1558 
1559 	return 1;
1560 }
1561 
1562 static void
OBJ_NAME_do_all_ciphers(void (* fn)(const OBJ_NAME *,void *),void * arg)1563 OBJ_NAME_do_all_ciphers(void (*fn)(const OBJ_NAME *, void *), void *arg)
1564 {
1565 	size_t i;
1566 
1567 	for (i = 0; i < N_CIPHER_NAMES; i++) {
1568 		const struct cipher_name *cipher = &cipher_names[i];
1569 		OBJ_NAME name;
1570 
1571 		if (OBJ_NAME_from_cipher_name(&name, cipher))
1572 			fn(&name, arg);
1573 	}
1574 }
1575 
1576 static int
OBJ_NAME_from_digest_name(OBJ_NAME * obj_name,const struct digest_name * digest)1577 OBJ_NAME_from_digest_name(OBJ_NAME *obj_name, const struct digest_name *digest)
1578 {
1579 	const EVP_MD *evp_md;
1580 
1581 	if ((evp_md = digest->digest()) == NULL)
1582 		return 0;
1583 
1584 	obj_name->type = OBJ_NAME_TYPE_MD_METH;
1585 	obj_name->name = digest->name;
1586 	if (digest->alias != NULL) {
1587 		obj_name->alias = OBJ_NAME_ALIAS;
1588 		obj_name->data = digest->alias;
1589 	} else {
1590 		obj_name->alias = 0;
1591 		obj_name->data = evp_md;
1592 	}
1593 
1594 	return 1;
1595 }
1596 
1597 static void
OBJ_NAME_do_all_digests(void (* fn)(const OBJ_NAME *,void *),void * arg)1598 OBJ_NAME_do_all_digests(void (*fn)(const OBJ_NAME *, void *), void *arg)
1599 {
1600 	size_t i;
1601 
1602 	for (i = 0; i < N_DIGEST_NAMES; i++) {
1603 		const struct digest_name *digest = &digest_names[i];
1604 		OBJ_NAME name;
1605 
1606 		if (OBJ_NAME_from_digest_name(&name, digest))
1607 			fn(&name, arg);
1608 	}
1609 }
1610 
1611 void
OBJ_NAME_do_all_sorted(int type,void (* fn)(const OBJ_NAME *,void *),void * arg)1612 OBJ_NAME_do_all_sorted(int type, void (*fn)(const OBJ_NAME *, void *), void *arg)
1613 {
1614 	/* Prayer and clean living lets you ignore errors, OpenSSL style. */
1615 	(void)OPENSSL_init_crypto(0, NULL);
1616 
1617 	if (type == OBJ_NAME_TYPE_CIPHER_METH)
1618 		OBJ_NAME_do_all_ciphers(fn, arg);
1619 	if (type == OBJ_NAME_TYPE_MD_METH)
1620 		OBJ_NAME_do_all_digests(fn, arg);
1621 }
1622 LCRYPTO_ALIAS(OBJ_NAME_do_all_sorted);
1623 
1624 void
OBJ_NAME_do_all(int type,void (* fn)(const OBJ_NAME *,void *),void * arg)1625 OBJ_NAME_do_all(int type, void (*fn)(const OBJ_NAME *, void *), void *arg)
1626 {
1627 	OBJ_NAME_do_all_sorted(type, fn, arg);
1628 }
1629 LCRYPTO_ALIAS(OBJ_NAME_do_all);
1630 
1631 static int
cipher_cmp(const void * a,const void * b)1632 cipher_cmp(const void *a, const void *b)
1633 {
1634 	return strcmp(a, ((const struct cipher_name *)b)->name);
1635 }
1636 
1637 const EVP_CIPHER *
EVP_get_cipherbyname(const char * name)1638 EVP_get_cipherbyname(const char *name)
1639 {
1640 	const struct cipher_name *cipher;
1641 
1642 	if (!OPENSSL_init_crypto(0, NULL))
1643 		return NULL;
1644 
1645 	if (name == NULL)
1646 		return NULL;
1647 
1648 	if ((cipher = bsearch(name, cipher_names, N_CIPHER_NAMES,
1649 	    sizeof(*cipher), cipher_cmp)) == NULL)
1650 		return NULL;
1651 
1652 	return cipher->cipher();
1653 }
1654 LCRYPTO_ALIAS(EVP_get_cipherbyname);
1655 
1656 static int
digest_cmp(const void * a,const void * b)1657 digest_cmp(const void *a, const void *b)
1658 {
1659 	return strcmp(a, ((const struct digest_name *)b)->name);
1660 }
1661 
1662 const EVP_MD *
EVP_get_digestbyname(const char * name)1663 EVP_get_digestbyname(const char *name)
1664 {
1665 	const struct digest_name *digest;
1666 
1667 	if (!OPENSSL_init_crypto(0, NULL))
1668 		return NULL;
1669 
1670 	if (name == NULL)
1671 		return NULL;
1672 
1673 	if ((digest = bsearch(name, digest_names, N_DIGEST_NAMES,
1674 	    sizeof(*digest), digest_cmp)) == NULL)
1675 		return NULL;
1676 
1677 	return digest->digest();
1678 }
1679 LCRYPTO_ALIAS(EVP_get_digestbyname);
1680 
1681 /*
1682  * XXX - this is here because most of its job was to clean up the dynamic
1683  * tables of ciphers and digests. If we get an evp_lib.c again, it should
1684  * probably move there.
1685  */
1686 
1687 void
EVP_cleanup(void)1688 EVP_cleanup(void)
1689 {
1690 }
1691 LCRYPTO_ALIAS(EVP_cleanup);
1692