/src/openssl/crypto/engine/tb_digest.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 *digest_table = NULL; |
13 | | |
14 | | void ENGINE_unregister_digests(ENGINE *e) |
15 | 0 | { |
16 | 0 | engine_table_unregister(&digest_table, e); |
17 | 0 | } |
18 | | |
19 | | static void engine_unregister_all_digests(void) |
20 | 0 | { |
21 | 0 | engine_table_cleanup(&digest_table); |
22 | 0 | } |
23 | | |
24 | | int ENGINE_register_digests(ENGINE *e) |
25 | 0 | { |
26 | 0 | if (e->digests) { |
27 | 0 | const int *nids; |
28 | 0 | int num_nids = e->digests(e, NULL, &nids, 0); |
29 | 0 | if (num_nids > 0) |
30 | 0 | return engine_table_register(&digest_table, |
31 | 0 | engine_unregister_all_digests, e, |
32 | 0 | nids, num_nids, 0); |
33 | 0 | } |
34 | 0 | return 1; |
35 | 0 | } |
36 | | |
37 | | void ENGINE_register_all_digests(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_digests(e); |
43 | 0 | } |
44 | | |
45 | | int ENGINE_set_default_digests(ENGINE *e) |
46 | 0 | { |
47 | 0 | if (e->digests) { |
48 | 0 | const int *nids; |
49 | 0 | int num_nids = e->digests(e, NULL, &nids, 0); |
50 | 0 | if (num_nids > 0) |
51 | 0 | return engine_table_register(&digest_table, |
52 | 0 | engine_unregister_all_digests, 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 digest 'nid' |
62 | | */ |
63 | | ENGINE *ENGINE_get_digest_engine(int nid) |
64 | 0 | { |
65 | 0 | return engine_table_select(&digest_table, nid); |
66 | 0 | } |
67 | | |
68 | | /* Obtains a digest implementation from an ENGINE functional reference */ |
69 | | const EVP_MD *ENGINE_get_digest(ENGINE *e, int nid) |
70 | 0 | { |
71 | 0 | const EVP_MD *ret; |
72 | 0 | ENGINE_DIGESTS_PTR fn = ENGINE_get_digests(e); |
73 | 0 | if (!fn || !fn(e, &ret, NULL, nid)) { |
74 | 0 | ENGINEerr(ENGINE_F_ENGINE_GET_DIGEST, ENGINE_R_UNIMPLEMENTED_DIGEST); |
75 | 0 | return NULL; |
76 | 0 | } |
77 | 0 | return ret; |
78 | 0 | } |
79 | | |
80 | | /* Gets the digest callback from an ENGINE structure */ |
81 | | ENGINE_DIGESTS_PTR ENGINE_get_digests(const ENGINE *e) |
82 | 0 | { |
83 | 0 | return e->digests; |
84 | 0 | } |
85 | | |
86 | | /* Sets the digest callback in an ENGINE structure */ |
87 | | int ENGINE_set_digests(ENGINE *e, ENGINE_DIGESTS_PTR f) |
88 | 0 | { |
89 | 0 | e->digests = f; |
90 | 0 | return 1; |
91 | 0 | } |