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