OpenCoverage

eng_lib.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/engine/eng_lib.c
Source codeSwitch to Preprocessed file
LineSourceCount
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 "e_os.h"-
11#include "eng_int.h"-
12#include <openssl/rand.h>-
13#include "internal/refcount.h"-
14-
15CRYPTO_RWLOCK *global_engine_lock;-
16-
17CRYPTO_ONCE engine_lock_init = CRYPTO_ONCE_STATIC_INIT;-
18-
19/* The "new"/"free" stuff first */-
20-
21DEFINE_RUN_ONCE(do_engine_lock_init)
executed 1960 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
1960
22{-
23 if (!OPENSSL_init_crypto(0, NULL))
!OPENSSL_init_... ((void *)0) )Description
TRUEnever evaluated
FALSEevaluated 1960 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1960
24 return 0;
never executed: return 0;
0
25 global_engine_lock = CRYPTO_THREAD_lock_new();-
26 return global_engine_lock != NULL;
executed 1960 times by 1 test: return global_engine_lock != ((void *)0) ;
Executed by:
  • libcrypto.so.1.1
1960
27}-
28-
29ENGINE *ENGINE_new(void)-
30{-
31 ENGINE *ret;-
32-
33 if (!RUN_ONCE(&engine_lock_init, do_engine_lock_init)
CRYPTO_THREAD_...ck_init_ossl_)Description
TRUEevaluated 2844 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
!(CRYPTO_THREA...ossl_ret_ : 0)Description
TRUEnever evaluated
FALSEevaluated 2844 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-2844
34 || (ret = OPENSSL_zalloc(sizeof(*ret))) == NULL) {
(ret = CRYPTO_...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 2844 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-2844
35 ENGINEerr(ENGINE_F_ENGINE_NEW, ERR_R_MALLOC_FAILURE);-
36 return NULL;
never executed: return ((void *)0) ;
0
37 }-
38 ret->struct_ref = 1;-
39 engine_ref_debug(ret, 0, 1);-
40 if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_ENGINE, ret, &ret->ex_data)) {
!CRYPTO_new_ex...&ret->ex_data)Description
TRUEnever evaluated
FALSEevaluated 2844 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-2844
41 OPENSSL_free(ret);-
42 return NULL;
never executed: return ((void *)0) ;
0
43 }-
44 return ret;
executed 2844 times by 1 test: return ret;
Executed by:
  • libcrypto.so.1.1
2844
45}-
46-
47/*-
48 * Placed here (close proximity to ENGINE_new) so that modifications to the-
49 * elements of the ENGINE structure are more likely to be caught and changed-
50 * here.-
51 */-
52void engine_set_all_null(ENGINE *e)-
53{-
54 e->id = NULL;-
55 e->name = NULL;-
56 e->rsa_meth = NULL;-
57 e->dsa_meth = NULL;-
58 e->dh_meth = NULL;-
59 e->rand_meth = NULL;-
60 e->ciphers = NULL;-
61 e->digests = NULL;-
62 e->destroy = NULL;-
63 e->init = NULL;-
64 e->finish = NULL;-
65 e->ctrl = NULL;-
66 e->load_privkey = NULL;-
67 e->load_pubkey = NULL;-
68 e->cmd_defns = NULL;-
69 e->flags = 0;-
70}
executed 368 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
368
71-
72int engine_free_util(ENGINE *e, int not_locked)-
73{-
74 int i;-
75-
76 if (e == NULL)
e == ((void *)0)Description
TRUEevaluated 42 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 63980 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
42-63980
77 return 1;
executed 42 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
42
78 if (not_locked)
not_lockedDescription
TRUEevaluated 7112 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 56868 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
7112-56868
79 CRYPTO_DOWN_REF(&e->struct_ref, &i, global_engine_lock);
executed 7112 times by 1 test: CRYPTO_DOWN_REF(&e->struct_ref, &i, global_engine_lock);
Executed by:
  • libcrypto.so.1.1
7112
80 else-
81 i = --e->struct_ref;
executed 56868 times by 1 test: i = --e->struct_ref;
Executed by:
  • libcrypto.so.1.1
56868
82 engine_ref_debug(e, 0, -1);-
83 if (i > 0)
i > 0Description
TRUEevaluated 61136 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 2844 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
2844-61136
84 return 1;
executed 61136 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
61136
85 REF_ASSERT_ISNT(i < 0);-
86 /* Free up any dynamically allocated public key methods */-
87 engine_pkey_meths_free(e);-
88 engine_pkey_asn1_meths_free(e);-
89 /*-
90 * Give the ENGINE a chance to do any structural cleanup corresponding to-
91 * allocation it did in its constructor (eg. unload error strings)-
92 */-
93 if (e->destroy)
e->destroyDescription
TRUEevaluated 368 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 2476 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
368-2476
94 e->destroy(e);
executed 368 times by 1 test: e->destroy(e);
Executed by:
  • libcrypto.so.1.1
368
95 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_ENGINE, e, &e->ex_data);-
96 OPENSSL_free(e);-
97 return 1;
executed 2844 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
2844
98}-
99-
100int ENGINE_free(ENGINE *e)-
101{-
102 return engine_free_util(e, 1);
executed 7154 times by 1 test: return engine_free_util(e, 1);
Executed by:
  • libcrypto.so.1.1
7154
103}-
104-
105/* Cleanup stuff */-
106-
107/*-
108 * engine_cleanup_int() is coded such that anything that does work that will-
109 * need cleanup can register a "cleanup" callback here. That way we don't get-
110 * linker bloat by referring to all *possible* cleanups, but any linker bloat-
111 * into code "X" will cause X's cleanup function to end up here.-
112 */-
113static STACK_OF(ENGINE_CLEANUP_ITEM) *cleanup_stack = NULL;-
114static int int_cleanup_check(int create)-
115{-
116 if (cleanup_stack)
cleanup_stackDescription
TRUEevaluated 3064 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 2076 times by 12 tests
Evaluated by:
  • asn1_internal_test
  • chacha_internal_test
  • ctype_internal_test
  • curve448_internal_test
  • libcrypto.so.1.1
  • modes_internal_test
  • poly1305_internal_test
  • rdrand_sanitytest
  • siphash_internal_test
  • sm2_internal_test
  • sm4_internal_test
  • x509_internal_test
2076-3064
117 return 1;
executed 3064 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
3064
118 if (!create)
!createDescription
TRUEevaluated 116 times by 12 tests
Evaluated by:
  • asn1_internal_test
  • chacha_internal_test
  • ctype_internal_test
  • curve448_internal_test
  • libcrypto.so.1.1
  • modes_internal_test
  • poly1305_internal_test
  • rdrand_sanitytest
  • siphash_internal_test
  • sm2_internal_test
  • sm4_internal_test
  • x509_internal_test
FALSEevaluated 1960 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
116-1960
119 return 0;
executed 116 times by 12 tests: return 0;
Executed by:
  • asn1_internal_test
  • chacha_internal_test
  • ctype_internal_test
  • curve448_internal_test
  • libcrypto.so.1.1
  • modes_internal_test
  • poly1305_internal_test
  • rdrand_sanitytest
  • siphash_internal_test
  • sm2_internal_test
  • sm4_internal_test
  • x509_internal_test
116
120 cleanup_stack = sk_ENGINE_CLEANUP_ITEM_new_null();-
121 return (cleanup_stack ? 1 : 0);
executed 1960 times by 1 test: return (cleanup_stack ? 1 : 0);
Executed by:
  • libcrypto.so.1.1
cleanup_stackDescription
TRUEevaluated 1960 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-1960
122}-
123-
124static ENGINE_CLEANUP_ITEM *int_cleanup_item(ENGINE_CLEANUP_CB *cb)-
125{-
126 ENGINE_CLEANUP_ITEM *item;-
127 -
128 if ((item = OPENSSL_malloc(sizeof(*item))) == NULL) {
(item = CRYPTO...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 3064 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-3064
129 ENGINEerr(ENGINE_F_INT_CLEANUP_ITEM, ERR_R_MALLOC_FAILURE);-
130 return NULL;
never executed: return ((void *)0) ;
0
131 }-
132 item->cb = cb;-
133 return item;
executed 3064 times by 1 test: return item;
Executed by:
  • libcrypto.so.1.1
3064
134}-
135-
136void engine_cleanup_add_first(ENGINE_CLEANUP_CB *cb)-
137{-
138 ENGINE_CLEANUP_ITEM *item;-
139-
140 if (!int_cleanup_check(1))
!int_cleanup_check(1)Description
TRUEnever evaluated
FALSEevaluated 1101 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1101
141 return;
never executed: return;
0
142 item = int_cleanup_item(cb);-
143 if (item)
itemDescription
TRUEevaluated 1101 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-1101
144 sk_ENGINE_CLEANUP_ITEM_insert(cleanup_stack, item, 0);
executed 1101 times by 1 test: sk_ENGINE_CLEANUP_ITEM_insert(cleanup_stack, item, 0);
Executed by:
  • libcrypto.so.1.1
1101
145}
executed 1101 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
1101
146-
147void engine_cleanup_add_last(ENGINE_CLEANUP_CB *cb)-
148{-
149 ENGINE_CLEANUP_ITEM *item;-
150 if (!int_cleanup_check(1))
!int_cleanup_check(1)Description
TRUEnever evaluated
FALSEevaluated 1963 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1963
151 return;
never executed: return;
0
152 item = int_cleanup_item(cb);-
153 if (item != NULL) {
item != ((void *)0)Description
TRUEevaluated 1963 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-1963
154 if (sk_ENGINE_CLEANUP_ITEM_push(cleanup_stack, item) <= 0)
sk_ENGINE_CLEA...ck, item) <= 0Description
TRUEnever evaluated
FALSEevaluated 1963 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1963
155 OPENSSL_free(item);
never executed: CRYPTO_free(item, __FILE__, 155);
0
156 }
executed 1963 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
1963
157}
executed 1963 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
1963
158-
159/* The API function that performs all cleanup */-
160static void engine_cleanup_cb_free(ENGINE_CLEANUP_ITEM *item)-
161{-
162 (*(item->cb)) ();-
163 OPENSSL_free(item);-
164}
executed 3064 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
3064
165-
166void engine_cleanup_int(void)-
167{-
168 if (int_cleanup_check(0)) {
int_cleanup_check(0)Description
TRUEevaluated 1960 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 116 times by 12 tests
Evaluated by:
  • asn1_internal_test
  • chacha_internal_test
  • ctype_internal_test
  • curve448_internal_test
  • libcrypto.so.1.1
  • modes_internal_test
  • poly1305_internal_test
  • rdrand_sanitytest
  • siphash_internal_test
  • sm2_internal_test
  • sm4_internal_test
  • x509_internal_test
116-1960
169 sk_ENGINE_CLEANUP_ITEM_pop_free(cleanup_stack,-
170 engine_cleanup_cb_free);-
171 cleanup_stack = NULL;-
172 }
executed 1960 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
1960
173 CRYPTO_THREAD_lock_free(global_engine_lock);-
174}
executed 2076 times by 12 tests: end of block
Executed by:
  • asn1_internal_test
  • chacha_internal_test
  • ctype_internal_test
  • curve448_internal_test
  • libcrypto.so.1.1
  • modes_internal_test
  • poly1305_internal_test
  • rdrand_sanitytest
  • siphash_internal_test
  • sm2_internal_test
  • sm4_internal_test
  • x509_internal_test
2076
175-
176/* Now the "ex_data" support */-
177-
178int ENGINE_set_ex_data(ENGINE *e, int idx, void *arg)-
179{-
180 return CRYPTO_set_ex_data(&e->ex_data, idx, arg);
executed 368 times by 1 test: return CRYPTO_set_ex_data(&e->ex_data, idx, arg);
Executed by:
  • libcrypto.so.1.1
368
181}-
182-
183void *ENGINE_get_ex_data(const ENGINE *e, int idx)-
184{-
185 return CRYPTO_get_ex_data(&e->ex_data, idx);
executed 2208 times by 1 test: return CRYPTO_get_ex_data(&e->ex_data, idx);
Executed by:
  • libcrypto.so.1.1
2208
186}-
187-
188/*-
189 * Functions to get/set an ENGINE's elements - mainly to avoid exposing the-
190 * ENGINE structure itself.-
191 */-
192-
193int ENGINE_set_id(ENGINE *e, const char *id)-
194{-
195 if (id == NULL) {
id == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 2844 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-2844
196 ENGINEerr(ENGINE_F_ENGINE_SET_ID, ERR_R_PASSED_NULL_PARAMETER);-
197 return 0;
never executed: return 0;
0
198 }-
199 e->id = id;-
200 return 1;
executed 2844 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
2844
201}-
202-
203int ENGINE_set_name(ENGINE *e, const char *name)-
204{-
205 if (name == NULL) {
name == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 2844 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-2844
206 ENGINEerr(ENGINE_F_ENGINE_SET_NAME, ERR_R_PASSED_NULL_PARAMETER);-
207 return 0;
never executed: return 0;
0
208 }-
209 e->name = name;-
210 return 1;
executed 2844 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
2844
211}-
212-
213int ENGINE_set_destroy_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR destroy_f)-
214{-
215 e->destroy = destroy_f;-
216 return 1;
executed 368 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
368
217}-
218-
219int ENGINE_set_init_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR init_f)-
220{-
221 e->init = init_f;-
222 return 1;
executed 2327 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
2327
223}-
224-
225int ENGINE_set_finish_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR finish_f)-
226{-
227 e->finish = finish_f;-
228 return 1;
executed 2327 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
2327
229}-
230-
231int ENGINE_set_ctrl_function(ENGINE *e, ENGINE_CTRL_FUNC_PTR ctrl_f)-
232{-
233 e->ctrl = ctrl_f;-
234 return 1;
executed 1959 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
1959
235}-
236-
237int ENGINE_set_flags(ENGINE *e, int flags)-
238{-
239 e->flags = flags;-
240 return 1;
executed 1959 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
1959
241}-
242-
243int ENGINE_set_cmd_defns(ENGINE *e, const ENGINE_CMD_DEFN *defns)-
244{-
245 e->cmd_defns = defns;-
246 return 1;
executed 1959 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
1959
247}-
248-
249const char *ENGINE_get_id(const ENGINE *e)-
250{-
251 return e->id;
executed 886 times by 1 test: return e->id;
Executed by:
  • libcrypto.so.1.1
886
252}-
253-
254const char *ENGINE_get_name(const ENGINE *e)-
255{-
256 return e->name;
executed 519 times by 1 test: return e->name;
Executed by:
  • libcrypto.so.1.1
519
257}-
258-
259ENGINE_GEN_INT_FUNC_PTR ENGINE_get_destroy_function(const ENGINE *e)-
260{-
261 return e->destroy;
never executed: return e->destroy;
0
262}-
263-
264ENGINE_GEN_INT_FUNC_PTR ENGINE_get_init_function(const ENGINE *e)-
265{-
266 return e->init;
never executed: return e->init;
0
267}-
268-
269ENGINE_GEN_INT_FUNC_PTR ENGINE_get_finish_function(const ENGINE *e)-
270{-
271 return e->finish;
never executed: return e->finish;
0
272}-
273-
274ENGINE_CTRL_FUNC_PTR ENGINE_get_ctrl_function(const ENGINE *e)-
275{-
276 return e->ctrl;
never executed: return e->ctrl;
0
277}-
278-
279int ENGINE_get_flags(const ENGINE *e)-
280{-
281 return e->flags;
never executed: return e->flags;
0
282}-
283-
284const ENGINE_CMD_DEFN *ENGINE_get_cmd_defns(const ENGINE *e)-
285{-
286 return e->cmd_defns;
never executed: return e->cmd_defns;
0
287}-
288-
289/*-
290 * eng_lib.o is pretty much linked into anything that touches ENGINE already,-
291 * so put the "static_state" hack here.-
292 */-
293-
294static int internal_static_hack = 0;-
295-
296void *ENGINE_get_static_state(void)-
297{-
298 return &internal_static_hack;
executed 736 times by 1 test: return &internal_static_hack;
Executed by:
  • libcrypto.so.1.1
736
299}-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.2