/src/openssl/crypto/engine/tb_cipher.c
Line  | Count  | Source (jump to first uncovered line)  | 
1  |  | /*  | 
2  |  |  * Copyright 2001-2021 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  |  | /* We need to use some engine deprecated APIs */  | 
11  |  | #define OPENSSL_SUPPRESS_DEPRECATED  | 
12  |  |  | 
13  |  | #include "eng_local.h"  | 
14  |  |  | 
15  |  | static ENGINE_TABLE *cipher_table = NULL;  | 
16  |  |  | 
17  |  | void ENGINE_unregister_ciphers(ENGINE *e)  | 
18  | 0  | { | 
19  | 0  |     engine_table_unregister(&cipher_table, e);  | 
20  | 0  | }  | 
21  |  |  | 
22  |  | static void engine_unregister_all_ciphers(void)  | 
23  | 0  | { | 
24  | 0  |     engine_table_cleanup(&cipher_table);  | 
25  | 0  | }  | 
26  |  |  | 
27  |  | int ENGINE_register_ciphers(ENGINE *e)  | 
28  | 0  | { | 
29  | 0  |     if (e->ciphers) { | 
30  | 0  |         const int *nids;  | 
31  | 0  |         int num_nids = e->ciphers(e, NULL, &nids, 0);  | 
32  | 0  |         if (num_nids > 0)  | 
33  | 0  |             return engine_table_register(&cipher_table,  | 
34  | 0  |                                          engine_unregister_all_ciphers, e,  | 
35  | 0  |                                          nids, num_nids, 0);  | 
36  | 0  |     }  | 
37  | 0  |     return 1;  | 
38  | 0  | }  | 
39  |  |  | 
40  |  | void ENGINE_register_all_ciphers(void)  | 
41  | 0  | { | 
42  | 0  |     ENGINE *e;  | 
43  |  | 
  | 
44  | 0  |     for (e = ENGINE_get_first(); e; e = ENGINE_get_next(e))  | 
45  | 0  |         ENGINE_register_ciphers(e);  | 
46  | 0  | }  | 
47  |  |  | 
48  |  | int ENGINE_set_default_ciphers(ENGINE *e)  | 
49  | 0  | { | 
50  | 0  |     if (e->ciphers) { | 
51  | 0  |         const int *nids;  | 
52  | 0  |         int num_nids = e->ciphers(e, NULL, &nids, 0);  | 
53  | 0  |         if (num_nids > 0)  | 
54  | 0  |             return engine_table_register(&cipher_table,  | 
55  | 0  |                                          engine_unregister_all_ciphers, e,  | 
56  | 0  |                                          nids, num_nids, 1);  | 
57  | 0  |     }  | 
58  | 0  |     return 1;  | 
59  | 0  | }  | 
60  |  |  | 
61  |  | /*  | 
62  |  |  * Exposed API function to get a functional reference from the implementation  | 
63  |  |  * table (ie. try to get a functional reference from the tabled structural  | 
64  |  |  * references) for a given cipher 'nid'  | 
65  |  |  */  | 
66  |  | ENGINE *ENGINE_get_cipher_engine(int nid)  | 
67  | 9  | { | 
68  | 9  |     return ossl_engine_table_select(&cipher_table, nid,  | 
69  | 9  |                                     OPENSSL_FILE, OPENSSL_LINE);  | 
70  | 9  | }  | 
71  |  |  | 
72  |  | /* Obtains a cipher implementation from an ENGINE functional reference */  | 
73  |  | const EVP_CIPHER *ENGINE_get_cipher(ENGINE *e, int nid)  | 
74  | 0  | { | 
75  | 0  |     const EVP_CIPHER *ret;  | 
76  | 0  |     ENGINE_CIPHERS_PTR fn = ENGINE_get_ciphers(e);  | 
77  | 0  |     if (!fn || !fn(e, &ret, NULL, nid)) { | 
78  | 0  |         ERR_raise(ERR_LIB_ENGINE, ENGINE_R_UNIMPLEMENTED_CIPHER);  | 
79  | 0  |         return NULL;  | 
80  | 0  |     }  | 
81  | 0  |     return ret;  | 
82  | 0  | }  | 
83  |  |  | 
84  |  | /* Gets the cipher callback from an ENGINE structure */  | 
85  |  | ENGINE_CIPHERS_PTR ENGINE_get_ciphers(const ENGINE *e)  | 
86  | 0  | { | 
87  | 0  |     return e->ciphers;  | 
88  | 0  | }  | 
89  |  |  | 
90  |  | /* Sets the cipher callback in an ENGINE structure */  | 
91  |  | int ENGINE_set_ciphers(ENGINE *e, ENGINE_CIPHERS_PTR f)  | 
92  | 0  | { | 
93  | 0  |     e->ciphers = f;  | 
94  | 0  |     return 1;  | 
95  | 0  | }  |