OpenCoverage

eng_init.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/engine/eng_init.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/*-
2 * Copyright 2001-2017 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-
13/*-
14 * Initialise a engine type for use (or up its functional reference count if-
15 * it's already in use). This version is only used internally.-
16 */-
17int engine_unlocked_init(ENGINE *e)-
18{-
19 int to_return = 1;-
20-
21 if ((e->funct_ref == 0) && e->init)
(e->funct_ref == 0)Description
TRUEevaluated 378 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 53646 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
e->initDescription
TRUEevaluated 373 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 5 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
5-53646
22 /*-
23 * This is the first functional reference and the engine requires-
24 * initialisation so we do it now.-
25 */-
26 to_return = e->init(e);
executed 373 times by 1 test: to_return = e->init(e);
Executed by:
  • libcrypto.so.1.1
373
27 if (to_return) {
to_returnDescription
TRUEevaluated 54024 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-54024
28 /*-
29 * OK, we return a functional reference which is also a structural-
30 * reference.-
31 */-
32 e->struct_ref++;-
33 e->funct_ref++;-
34 engine_ref_debug(e, 0, 1);-
35 engine_ref_debug(e, 1, 1);-
36 }
executed 54024 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
54024
37 return to_return;
executed 54024 times by 1 test: return to_return;
Executed by:
  • libcrypto.so.1.1
54024
38}-
39-
40/*-
41 * Free a functional reference to a engine type. This version is only used-
42 * internally.-
43 */-
44int engine_unlocked_finish(ENGINE *e, int unlock_for_handlers)-
45{-
46 int to_return = 1;-
47-
48 /*-
49 * Reduce the functional reference count here so if it's the terminating-
50 * case, we can release the lock safely and call the finish() handler-
51 * without risk of a race. We get a race if we leave the count until-
52 * after and something else is calling "finish" at the same time --
53 * there's a chance that both threads will together take the count from 2-
54 * to 0 without either calling finish().-
55 */-
56 e->funct_ref--;-
57 engine_ref_debug(e, 1, -1);-
58 if ((e->funct_ref == 0) && e->finish) {
(e->funct_ref == 0)Description
TRUEevaluated 378 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 53646 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
e->finishDescription
TRUEevaluated 373 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 5 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
5-53646
59 if (unlock_for_handlers)
unlock_for_handlersDescription
TRUEevaluated 6 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 367 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
6-367
60 CRYPTO_THREAD_unlock(global_engine_lock);
executed 6 times by 1 test: CRYPTO_THREAD_unlock(global_engine_lock);
Executed by:
  • libcrypto.so.1.1
6
61 to_return = e->finish(e);-
62 if (unlock_for_handlers)
unlock_for_handlersDescription
TRUEevaluated 6 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 367 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
6-367
63 CRYPTO_THREAD_write_lock(global_engine_lock);
executed 6 times by 1 test: CRYPTO_THREAD_write_lock(global_engine_lock);
Executed by:
  • libcrypto.so.1.1
6
64 if (!to_return)
!to_returnDescription
TRUEnever evaluated
FALSEevaluated 373 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-373
65 return 0;
never executed: return 0;
0
66 }
executed 373 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
373
67 REF_ASSERT_ISNT(e->funct_ref < 0);-
68 /* Release the structural reference too */-
69 if (!engine_free_util(e, 0)) {
!engine_free_util(e, 0)Description
TRUEnever evaluated
FALSEevaluated 54024 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-54024
70 ENGINEerr(ENGINE_F_ENGINE_UNLOCKED_FINISH, ENGINE_R_FINISH_FAILED);-
71 return 0;
never executed: return 0;
0
72 }-
73 return to_return;
executed 54024 times by 1 test: return to_return;
Executed by:
  • libcrypto.so.1.1
54024
74}-
75-
76/* The API (locked) version of "init" */-
77int ENGINE_init(ENGINE *e)-
78{-
79 int ret;-
80 if (e == NULL) {
e == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 39223 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-39223
81 ENGINEerr(ENGINE_F_ENGINE_INIT, ERR_R_PASSED_NULL_PARAMETER);-
82 return 0;
never executed: return 0;
0
83 }-
84 if (!RUN_ONCE(&engine_lock_init, do_engine_lock_init)) {
!(CRYPTO_THREA...ossl_ret_ : 0)Description
TRUEnever evaluated
FALSEevaluated 39223 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
CRYPTO_THREAD_...ck_init_ossl_)Description
TRUEevaluated 39223 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-39223
85 ENGINEerr(ENGINE_F_ENGINE_INIT, ERR_R_MALLOC_FAILURE);-
86 return 0;
never executed: return 0;
0
87 }-
88 CRYPTO_THREAD_write_lock(global_engine_lock);-
89 ret = engine_unlocked_init(e);-
90 CRYPTO_THREAD_unlock(global_engine_lock);-
91 return ret;
executed 39223 times by 1 test: return ret;
Executed by:
  • libcrypto.so.1.1
39223
92}-
93-
94/* The API (locked) version of "finish" */-
95int ENGINE_finish(ENGINE *e)-
96{-
97 int to_return = 1;-
98-
99 if (e == NULL)
e == ((void *)0)Description
TRUEevaluated 7183616 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 51088 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
51088-7183616
100 return 1;
executed 7182302 times by 12 tests: return 1;
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
7182302
101 CRYPTO_THREAD_write_lock(global_engine_lock);-
102 to_return = engine_unlocked_finish(e, 1);-
103 CRYPTO_THREAD_unlock(global_engine_lock);-
104 if (!to_return) {
!to_returnDescription
TRUEnever evaluated
FALSEevaluated 51088 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-51088
105 ENGINEerr(ENGINE_F_ENGINE_FINISH, ENGINE_R_FINISH_FAILED);-
106 return 0;
never executed: return 0;
0
107 }-
108 return to_return;
executed 51088 times by 1 test: return to_return;
Executed by:
  • libcrypto.so.1.1
51088
109}-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.2