OpenCoverage

lhash.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/lhash/lhash.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/*-
2 * Copyright 1995-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 <stdio.h>-
11#include <string.h>-
12#include <stdlib.h>-
13#include <openssl/crypto.h>-
14#include <openssl/lhash.h>-
15#include <openssl/err.h>-
16#include "internal/ctype.h"-
17#include "internal/lhash.h"-
18#include "lhash_lcl.h"-
19-
20/*-
21 * A hashing implementation that appears to be based on the linear hashing-
22 * alogrithm:-
23 * https://en.wikipedia.org/wiki/Linear_hashing-
24 *-
25 * Litwin, Witold (1980), "Linear hashing: A new tool for file and table-
26 * addressing", Proc. 6th Conference on Very Large Databases: 212-223-
27 * http://hackthology.com/pdfs/Litwin-1980-Linear_Hashing.pdf-
28 *-
29 * From the wikipedia article "Linear hashing is used in the BDB Berkeley-
30 * database system, which in turn is used by many software systems such as-
31 * OpenLDAP, using a C implementation derived from the CACM article and first-
32 * published on the Usenet in 1988 by Esmond Pitt."-
33 *-
34 * The CACM paper is available here:-
35 * https://pdfs.semanticscholar.org/ff4d/1c5deca6269cc316bfd952172284dbf610ee.pdf-
36 */-
37-
38#undef MIN_NODES-
39#define MIN_NODES 16-
40#define UP_LOAD (2*LH_LOAD_MULT) /* load times 256 (default 2) */-
41#define DOWN_LOAD (LH_LOAD_MULT) /* load times 256 (default 1) */-
42-
43static int expand(OPENSSL_LHASH *lh);-
44static void contract(OPENSSL_LHASH *lh);-
45static OPENSSL_LH_NODE **getrn(OPENSSL_LHASH *lh, const void *data, unsigned long *rhash);-
46-
47OPENSSL_LHASH *OPENSSL_LH_new(OPENSSL_LH_HASHFUNC h, OPENSSL_LH_COMPFUNC c)-
48{-
49 OPENSSL_LHASH *ret;-
50-
51 if ((ret = OPENSSL_zalloc(sizeof(*ret))) == NULL) {
(ret = CRYPTO_...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 17183 times by 11 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
  • siphash_internal_test
  • sm2_internal_test
  • sm4_internal_test
  • x509_internal_test
0-17183
52 /*-
53 * Do not set the error code, because the ERR code uses LHASH-
54 * and we want to avoid possible endless error loop.-
55 * CRYPTOerr(CRYPTO_F_OPENSSL_LH_NEW, ERR_R_MALLOC_FAILURE);-
56 */-
57 return NULL;
never executed: return ((void *)0) ;
0
58 }-
59 if ((ret->b = OPENSSL_zalloc(sizeof(*ret->b) * MIN_NODES)) == NULL)
(ret->b = CRYP...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 17183 times by 11 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
  • siphash_internal_test
  • sm2_internal_test
  • sm4_internal_test
  • x509_internal_test
0-17183
60 goto err;
never executed: goto err;
0
61 ret->comp = ((c == NULL) ? (OPENSSL_LH_COMPFUNC)strcmp : c);
(c == ((void *)0) )Description
TRUEnever evaluated
FALSEevaluated 17183 times by 11 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
  • siphash_internal_test
  • sm2_internal_test
  • sm4_internal_test
  • x509_internal_test
0-17183
62 ret->hash = ((h == NULL) ? (OPENSSL_LH_HASHFUNC)OPENSSL_LH_strhash : h);
(h == ((void *)0) )Description
TRUEnever evaluated
FALSEevaluated 17183 times by 11 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
  • siphash_internal_test
  • sm2_internal_test
  • sm4_internal_test
  • x509_internal_test
0-17183
63 ret->num_nodes = MIN_NODES / 2;-
64 ret->num_alloc_nodes = MIN_NODES;-
65 ret->pmax = MIN_NODES / 2;-
66 ret->up_load = UP_LOAD;-
67 ret->down_load = DOWN_LOAD;-
68 return ret;
executed 17183 times by 11 tests: return ret;
Executed by:
  • asn1_internal_test
  • chacha_internal_test
  • ctype_internal_test
  • curve448_internal_test
  • libcrypto.so.1.1
  • modes_internal_test
  • poly1305_internal_test
  • siphash_internal_test
  • sm2_internal_test
  • sm4_internal_test
  • x509_internal_test
17183
69-
70err:-
71 OPENSSL_free(ret->b);-
72 OPENSSL_free(ret);-
73 return NULL;
never executed: return ((void *)0) ;
0
74}-
75-
76void OPENSSL_LH_free(OPENSSL_LHASH *lh)-
77{-
78 unsigned int i;-
79 OPENSSL_LH_NODE *n, *nn;-
80-
81 if (lh == NULL)
lh == ((void *)0)Description
TRUEevaluated 2153 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 17183 times by 11 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
  • siphash_internal_test
  • sm2_internal_test
  • sm4_internal_test
  • x509_internal_test
2153-17183
82 return;
executed 2153 times by 12 tests: return;
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
2153
83-
84 for (i = 0; i < lh->num_nodes; i++) {
i < lh->num_nodesDescription
TRUEevaluated 3191744 times by 11 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
  • siphash_internal_test
  • sm2_internal_test
  • sm4_internal_test
  • x509_internal_test
FALSEevaluated 17183 times by 11 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
  • siphash_internal_test
  • sm2_internal_test
  • sm4_internal_test
  • x509_internal_test
17183-3191744
85 n = lh->b[i];-
86 while (n != NULL) {
n != ((void *)0)Description
TRUEevaluated 5704218 times by 11 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
  • siphash_internal_test
  • sm2_internal_test
  • sm4_internal_test
  • x509_internal_test
FALSEevaluated 3191744 times by 11 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
  • siphash_internal_test
  • sm2_internal_test
  • sm4_internal_test
  • x509_internal_test
3191744-5704218
87 nn = n->next;-
88 OPENSSL_free(n);-
89 n = nn;-
90 }
executed 5704218 times by 11 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
  • siphash_internal_test
  • sm2_internal_test
  • sm4_internal_test
  • x509_internal_test
5704218
91 }
executed 3191744 times by 11 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
  • siphash_internal_test
  • sm2_internal_test
  • sm4_internal_test
  • x509_internal_test
3191744
92 OPENSSL_free(lh->b);-
93 OPENSSL_free(lh);-
94}
executed 17183 times by 11 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
  • siphash_internal_test
  • sm2_internal_test
  • sm4_internal_test
  • x509_internal_test
17183
95-
96void *OPENSSL_LH_insert(OPENSSL_LHASH *lh, void *data)-
97{-
98 unsigned long hash;-
99 OPENSSL_LH_NODE *nn, **rn;-
100 void *ret;-
101-
102 lh->error = 0;-
103 if ((lh->up_load <= (lh->num_items * LH_LOAD_MULT / lh->num_nodes)) && !expand(lh))
(lh->up_load <...h->num_nodes))Description
TRUEevaluated 4306235 times by 11 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
  • siphash_internal_test
  • sm2_internal_test
  • sm4_internal_test
  • x509_internal_test
FALSEevaluated 15659355 times by 11 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
  • siphash_internal_test
  • sm2_internal_test
  • sm4_internal_test
  • x509_internal_test
!expand(lh)Description
TRUEnever evaluated
FALSEevaluated 4306235 times by 11 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
  • siphash_internal_test
  • sm2_internal_test
  • sm4_internal_test
  • x509_internal_test
0-15659355
104 return NULL; /* 'lh->error++' already done in 'expand' */
never executed: return ((void *)0) ;
0
105-
106 rn = getrn(lh, data, &hash);-
107-
108 if (*rn == NULL) {
*rn == ((void *)0)Description
TRUEevaluated 8731482 times by 11 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
  • siphash_internal_test
  • sm2_internal_test
  • sm4_internal_test
  • x509_internal_test
FALSEevaluated 11234108 times by 11 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
  • siphash_internal_test
  • sm2_internal_test
  • sm4_internal_test
  • x509_internal_test
8731482-11234108
109 if ((nn = OPENSSL_malloc(sizeof(*nn))) == NULL) {
(nn = CRYPTO_m...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 8731482 times by 11 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
  • siphash_internal_test
  • sm2_internal_test
  • sm4_internal_test
  • x509_internal_test
0-8731482
110 lh->error++;-
111 return NULL;
never executed: return ((void *)0) ;
0
112 }-
113 nn->data = data;-
114 nn->next = NULL;-
115 nn->hash = hash;-
116 *rn = nn;-
117 ret = NULL;-
118 lh->num_insert++;-
119 lh->num_items++;-
120 } else { /* replace same key */
executed 8731482 times by 11 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
  • siphash_internal_test
  • sm2_internal_test
  • sm4_internal_test
  • x509_internal_test
8731482
121 ret = (*rn)->data;-
122 (*rn)->data = data;-
123 lh->num_replace++;-
124 }
executed 11234108 times by 11 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
  • siphash_internal_test
  • sm2_internal_test
  • sm4_internal_test
  • x509_internal_test
11234108
125 return ret;
executed 19965590 times by 11 tests: return ret;
Executed by:
  • asn1_internal_test
  • chacha_internal_test
  • ctype_internal_test
  • curve448_internal_test
  • libcrypto.so.1.1
  • modes_internal_test
  • poly1305_internal_test
  • siphash_internal_test
  • sm2_internal_test
  • sm4_internal_test
  • x509_internal_test
19965590
126}-
127-
128void *OPENSSL_LH_delete(OPENSSL_LHASH *lh, const void *data)-
129{-
130 unsigned long hash;-
131 OPENSSL_LH_NODE *nn, **rn;-
132 void *ret;-
133-
134 lh->error = 0;-
135 rn = getrn(lh, data, &hash);-
136-
137 if (*rn == NULL) {
*rn == ((void *)0)Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 3027264 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
2-3027264
138 lh->num_no_delete++;-
139 return NULL;
executed 2 times by 1 test: return ((void *)0) ;
Executed by:
  • libcrypto.so.1.1
2
140 } else {-
141 nn = *rn;-
142 *rn = nn->next;-
143 ret = nn->data;-
144 OPENSSL_free(nn);-
145 lh->num_delete++;-
146 }
executed 3027264 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
3027264
147-
148 lh->num_items--;-
149 if ((lh->num_nodes > MIN_NODES) &&
(lh->num_nodes > 16)Description
TRUEevaluated 2995125 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 32139 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
32139-2995125
150 (lh->down_load >= (lh->num_items * LH_LOAD_MULT / lh->num_nodes)))
(lh->down_load...h->num_nodes))Description
TRUEevaluated 1251955 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 1743170 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
1251955-1743170
151 contract(lh);
executed 1251955 times by 1 test: contract(lh);
Executed by:
  • libcrypto.so.1.1
1251955
152-
153 return ret;
executed 3027264 times by 1 test: return ret;
Executed by:
  • libcrypto.so.1.1
3027264
154}-
155-
156void *OPENSSL_LH_retrieve(OPENSSL_LHASH *lh, const void *data)-
157{-
158 unsigned long hash;-
159 OPENSSL_LH_NODE **rn;-
160 void *ret;-
161-
162 tsan_store((TSAN_QUALIFIER int *)&lh->error, 0);-
163-
164 rn = getrn(lh, data, &hash);-
165-
166 if (*rn == NULL) {
*rn == ((void *)0)Description
TRUEevaluated 125922 times by 11 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
  • siphash_internal_test
  • sm2_internal_test
  • sm4_internal_test
  • x509_internal_test
FALSEevaluated 179510 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
125922-179510
167 tsan_counter(&lh->num_retrieve_miss);-
168 return NULL;
executed 125922 times by 11 tests: return ((void *)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
  • siphash_internal_test
  • sm2_internal_test
  • sm4_internal_test
  • x509_internal_test
125922
169 } else {-
170 ret = (*rn)->data;-
171 tsan_counter(&lh->num_retrieve);-
172 }
executed 179510 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
179510
173-
174 return ret;
executed 179510 times by 1 test: return ret;
Executed by:
  • libcrypto.so.1.1
179510
175}-
176-
177static void doall_util_fn(OPENSSL_LHASH *lh, int use_arg,-
178 OPENSSL_LH_DOALL_FUNC func,-
179 OPENSSL_LH_DOALL_FUNCARG func_arg, void *arg)-
180{-
181 int i;-
182 OPENSSL_LH_NODE *a, *n;-
183-
184 if (lh == NULL)
lh == ((void *)0)Description
TRUEevaluated 27 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 19522 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
27-19522
185 return;
executed 27 times by 1 test: return;
Executed by:
  • libcrypto.so.1.1
27
186-
187 /*-
188 * reverse the order so we search from 'top to bottom' We were having-
189 * memory leaks otherwise-
190 */-
191 for (i = lh->num_nodes - 1; i >= 0; i--) {
i >= 0Description
TRUEevaluated 869701 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 19522 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
19522-869701
192 a = lh->b[i];-
193 while (a != NULL) {
a != ((void *)0)Description
TRUEevaluated 713011 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 869701 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
713011-869701
194 n = a->next;-
195 if (use_arg)
use_argDescription
TRUEevaluated 107849 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 605162 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
107849-605162
196 func_arg(a->data, arg);
executed 107849 times by 1 test: func_arg(a->data, arg);
Executed by:
  • libcrypto.so.1.1
107849
197 else-
198 func(a->data);
executed 605162 times by 1 test: func(a->data);
Executed by:
  • libcrypto.so.1.1
605162
199 a = n;-
200 }
executed 713011 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
713011
201 }
executed 869701 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
869701
202}
executed 19522 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
19522
203-
204void OPENSSL_LH_doall(OPENSSL_LHASH *lh, OPENSSL_LH_DOALL_FUNC func)-
205{-
206 doall_util_fn(lh, 0, func, (OPENSSL_LH_DOALL_FUNCARG)0, NULL);-
207}
executed 9380 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
9380
208-
209void OPENSSL_LH_doall_arg(OPENSSL_LHASH *lh, OPENSSL_LH_DOALL_FUNCARG func, void *arg)-
210{-
211 doall_util_fn(lh, 1, (OPENSSL_LH_DOALL_FUNC)0, func, arg);-
212}
executed 10169 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
10169
213-
214static int expand(OPENSSL_LHASH *lh)-
215{-
216 OPENSSL_LH_NODE **n, **n1, **n2, *np;-
217 unsigned int p, pmax, nni, j;-
218 unsigned long hash;-
219-
220 nni = lh->num_alloc_nodes;-
221 p = lh->p;-
222 pmax = lh->pmax;-
223 if (p + 1 >= pmax) {
p + 1 >= pmaxDescription
TRUEevaluated 26310 times by 11 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
  • siphash_internal_test
  • sm2_internal_test
  • sm4_internal_test
  • x509_internal_test
FALSEevaluated 4279925 times by 11 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
  • siphash_internal_test
  • sm2_internal_test
  • sm4_internal_test
  • x509_internal_test
26310-4279925
224 j = nni * 2;-
225 n = OPENSSL_realloc(lh->b, sizeof(OPENSSL_LH_NODE *) * j);-
226 if (n == NULL) {
n == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 26310 times by 11 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
  • siphash_internal_test
  • sm2_internal_test
  • sm4_internal_test
  • x509_internal_test
0-26310
227 lh->error++;-
228 return 0;
never executed: return 0;
0
229 }-
230 lh->b = n;-
231 memset(n + nni, 0, sizeof(*n) * (j - nni));-
232 lh->pmax = nni;-
233 lh->num_alloc_nodes = j;-
234 lh->num_expand_reallocs++;-
235 lh->p = 0;-
236 } else {
executed 26310 times by 11 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
  • siphash_internal_test
  • sm2_internal_test
  • sm4_internal_test
  • x509_internal_test
26310
237 lh->p++;-
238 }
executed 4279925 times by 11 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
  • siphash_internal_test
  • sm2_internal_test
  • sm4_internal_test
  • x509_internal_test
4279925
239-
240 lh->num_nodes++;-
241 lh->num_expands++;-
242 n1 = &(lh->b[p]);-
243 n2 = &(lh->b[p + pmax]);-
244 *n2 = NULL;-
245-
246 for (np = *n1; np != NULL;) {
np != ((void *)0)Description
TRUEevaluated 14212329 times by 11 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
  • siphash_internal_test
  • sm2_internal_test
  • sm4_internal_test
  • x509_internal_test
FALSEevaluated 4306235 times by 11 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
  • siphash_internal_test
  • sm2_internal_test
  • sm4_internal_test
  • x509_internal_test
4306235-14212329
247 hash = np->hash;-
248 if ((hash % nni) != p) { /* move it */
(hash % nni) != pDescription
TRUEevaluated 2936771 times by 11 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
  • siphash_internal_test
  • sm2_internal_test
  • sm4_internal_test
  • x509_internal_test
FALSEevaluated 11275558 times by 11 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
  • siphash_internal_test
  • sm2_internal_test
  • sm4_internal_test
  • x509_internal_test
2936771-11275558
249 *n1 = (*n1)->next;-
250 np->next = *n2;-
251 *n2 = np;-
252 } else
executed 2936771 times by 11 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
  • siphash_internal_test
  • sm2_internal_test
  • sm4_internal_test
  • x509_internal_test
2936771
253 n1 = &((*n1)->next);
executed 11275558 times by 11 tests: n1 = &((*n1)->next);
Executed by:
  • asn1_internal_test
  • chacha_internal_test
  • ctype_internal_test
  • curve448_internal_test
  • libcrypto.so.1.1
  • modes_internal_test
  • poly1305_internal_test
  • siphash_internal_test
  • sm2_internal_test
  • sm4_internal_test
  • x509_internal_test
11275558
254 np = *n1;-
255 }
executed 14212329 times by 11 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
  • siphash_internal_test
  • sm2_internal_test
  • sm4_internal_test
  • x509_internal_test
14212329
256-
257 return 1;
executed 4306235 times by 11 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
  • siphash_internal_test
  • sm2_internal_test
  • sm4_internal_test
  • x509_internal_test
4306235
258}-
259-
260static void contract(OPENSSL_LHASH *lh)-
261{-
262 OPENSSL_LH_NODE **n, *n1, *np;-
263-
264 np = lh->b[lh->p + lh->pmax - 1];-
265 lh->b[lh->p + lh->pmax - 1] = NULL; /* 24/07-92 - eay - weird but :-( */-
266 if (lh->p == 0) {
lh->p == 0Description
TRUEevaluated 16 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 1251939 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
16-1251939
267 n = OPENSSL_realloc(lh->b,-
268 (unsigned int)(sizeof(OPENSSL_LH_NODE *) * lh->pmax));-
269 if (n == NULL) {
n == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 16 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-16
270 /* fputs("realloc error in lhash",stderr); */-
271 lh->error++;-
272 return;
never executed: return;
0
273 }-
274 lh->num_contract_reallocs++;-
275 lh->num_alloc_nodes /= 2;-
276 lh->pmax /= 2;-
277 lh->p = lh->pmax - 1;-
278 lh->b = n;-
279 } else
executed 16 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
16
280 lh->p--;
executed 1251939 times by 1 test: lh->p--;
Executed by:
  • libcrypto.so.1.1
1251939
281-
282 lh->num_nodes--;-
283 lh->num_contracts++;-
284-
285 n1 = lh->b[(int)lh->p];-
286 if (n1 == NULL)
n1 == ((void *)0)Description
TRUEevaluated 401069 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 850886 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
401069-850886
287 lh->b[(int)lh->p] = np;
executed 401069 times by 1 test: lh->b[(int)lh->p] = np;
Executed by:
  • libcrypto.so.1.1
401069
288 else {-
289 while (n1->next != NULL)
n1->next != ((void *)0)Description
TRUEevaluated 61905 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 850886 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
61905-850886
290 n1 = n1->next;
executed 61905 times by 1 test: n1 = n1->next;
Executed by:
  • libcrypto.so.1.1
61905
291 n1->next = np;-
292 }
executed 850886 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
850886
293}-
294-
295static OPENSSL_LH_NODE **getrn(OPENSSL_LHASH *lh,-
296 const void *data, unsigned long *rhash)-
297{-
298 OPENSSL_LH_NODE **ret, *n1;-
299 unsigned long hash, nn;-
300 OPENSSL_LH_COMPFUNC cf;-
301-
302 hash = (*(lh->hash)) (data);-
303 tsan_counter(&lh->num_hash_calls);-
304 *rhash = hash;-
305-
306 nn = hash % lh->pmax;-
307 if (nn < lh->p)
nn < lh->pDescription
TRUEevaluated 12646341 times by 11 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
  • siphash_internal_test
  • sm2_internal_test
  • sm4_internal_test
  • x509_internal_test
FALSEevaluated 10651947 times by 11 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
  • siphash_internal_test
  • sm2_internal_test
  • sm4_internal_test
  • x509_internal_test
10651947-12646341
308 nn = hash % lh->num_alloc_nodes;
executed 12646341 times by 11 tests: nn = hash % lh->num_alloc_nodes;
Executed by:
  • asn1_internal_test
  • chacha_internal_test
  • ctype_internal_test
  • curve448_internal_test
  • libcrypto.so.1.1
  • modes_internal_test
  • poly1305_internal_test
  • siphash_internal_test
  • sm2_internal_test
  • sm4_internal_test
  • x509_internal_test
12646341
309-
310 cf = lh->comp;-
311 ret = &(lh->b[(int)nn]);-
312 for (n1 = *ret; n1 != NULL; n1 = n1->next) {
n1 != ((void *)0)Description
TRUEevaluated 54260711 times by 11 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
  • siphash_internal_test
  • sm2_internal_test
  • sm4_internal_test
  • x509_internal_test
FALSEevaluated 8857406 times by 11 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
  • siphash_internal_test
  • sm2_internal_test
  • sm4_internal_test
  • x509_internal_test
8857406-54260711
313 tsan_counter(&lh->num_hash_comps);-
314 if (n1->hash != hash) {
n1->hash != hashDescription
TRUEevaluated 39519144 times by 11 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
  • siphash_internal_test
  • sm2_internal_test
  • sm4_internal_test
  • x509_internal_test
FALSEevaluated 14741567 times by 11 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
  • siphash_internal_test
  • sm2_internal_test
  • sm4_internal_test
  • x509_internal_test
14741567-39519144
315 ret = &(n1->next);-
316 continue;
executed 39519144 times by 11 tests: continue;
Executed by:
  • asn1_internal_test
  • chacha_internal_test
  • ctype_internal_test
  • curve448_internal_test
  • libcrypto.so.1.1
  • modes_internal_test
  • poly1305_internal_test
  • siphash_internal_test
  • sm2_internal_test
  • sm4_internal_test
  • x509_internal_test
39519144
317 }-
318 tsan_counter(&lh->num_comp_calls);-
319 if (cf(n1->data, data) == 0)
cf(n1->data, data) == 0Description
TRUEevaluated 14440882 times by 11 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
  • siphash_internal_test
  • sm2_internal_test
  • sm4_internal_test
  • x509_internal_test
FALSEevaluated 300685 times by 11 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
  • siphash_internal_test
  • sm2_internal_test
  • sm4_internal_test
  • x509_internal_test
300685-14440882
320 break;
executed 14440882 times by 11 tests: break;
Executed by:
  • asn1_internal_test
  • chacha_internal_test
  • ctype_internal_test
  • curve448_internal_test
  • libcrypto.so.1.1
  • modes_internal_test
  • poly1305_internal_test
  • siphash_internal_test
  • sm2_internal_test
  • sm4_internal_test
  • x509_internal_test
14440882
321 ret = &(n1->next);-
322 }
executed 300685 times by 11 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
  • siphash_internal_test
  • sm2_internal_test
  • sm4_internal_test
  • x509_internal_test
300685
323 return ret;
executed 23298288 times by 11 tests: return ret;
Executed by:
  • asn1_internal_test
  • chacha_internal_test
  • ctype_internal_test
  • curve448_internal_test
  • libcrypto.so.1.1
  • modes_internal_test
  • poly1305_internal_test
  • siphash_internal_test
  • sm2_internal_test
  • sm4_internal_test
  • x509_internal_test
23298288
324}-
325-
326/*-
327 * The following hash seems to work very well on normal text strings no-
328 * collisions on /usr/dict/words and it distributes on %2^n quite well, not-
329 * as good as MD5, but still good.-
330 */-
331unsigned long OPENSSL_LH_strhash(const char *c)-
332{-
333 unsigned long ret = 0;-
334 long n;-
335 unsigned long v;-
336 int r;-
337-
338 if ((c == NULL) || (*c == '\0'))
(c == ((void *)0) )Description
TRUEevaluated 73393 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 771176 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
(*c == '\0')Description
TRUEevaluated 34175 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 737001 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
34175-771176
339 return ret;
executed 107568 times by 1 test: return ret;
Executed by:
  • libcrypto.so.1.1
107568
340-
341 n = 0x100;-
342 while (*c) {
*cDescription
TRUEevaluated 6560043 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 737001 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
737001-6560043
343 v = n | (*c);-
344 n += 0x100;-
345 r = (int)((v >> 2) ^ v) & 0x0f;-
346 ret = (ret << r) | (ret >> (32 - r));-
347 ret &= 0xFFFFFFFFL;-
348 ret ^= v * v;-
349 c++;-
350 }
executed 6560043 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
6560043
351 return (ret >> 16) ^ ret;
executed 737001 times by 1 test: return (ret >> 16) ^ ret;
Executed by:
  • libcrypto.so.1.1
737001
352}-
353-
354unsigned long openssl_lh_strcasehash(const char *c)-
355{-
356 unsigned long ret = 0;-
357 long n;-
358 unsigned long v;-
359 int r;-
360-
361 if (c == NULL || *c == '\0')
c == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 1492672 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
*c == '\0'Description
TRUEnever evaluated
FALSEevaluated 1492672 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1492672
362 return ret;
never executed: return ret;
0
363-
364 for (n = 0x100; *c != '\0'; n += 0x100) {
*c != '\0'Description
TRUEevaluated 16106614 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 1492672 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
1492672-16106614
365 v = n | ossl_tolower(*c);-
366 r = (int)((v >> 2) ^ v) & 0x0f;-
367 ret = (ret << r) | (ret >> (32 - r));-
368 ret &= 0xFFFFFFFFL;-
369 ret ^= v * v;-
370 c++;-
371 }
executed 16106614 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
16106614
372 return (ret >> 16) ^ ret;
executed 1492672 times by 1 test: return (ret >> 16) ^ ret;
Executed by:
  • libcrypto.so.1.1
1492672
373}-
374-
375unsigned long OPENSSL_LH_num_items(const OPENSSL_LHASH *lh)-
376{-
377 return lh ? lh->num_items : 0;
executed 520 times by 1 test: return lh ? lh->num_items : 0;
Executed by:
  • libcrypto.so.1.1
lhDescription
TRUEevaluated 520 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-520
378}-
379-
380unsigned long OPENSSL_LH_get_down_load(const OPENSSL_LHASH *lh)-
381{-
382 return lh->down_load;
executed 13930 times by 1 test: return lh->down_load;
Executed by:
  • libcrypto.so.1.1
13930
383}-
384-
385void OPENSSL_LH_set_down_load(OPENSSL_LHASH *lh, unsigned long down_load)-
386{-
387 lh->down_load = down_load;-
388}
executed 28100 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
28100
389-
390int OPENSSL_LH_error(OPENSSL_LHASH *lh)-
391{-
392 return lh->error;
executed 484895 times by 1 test: return lh->error;
Executed by:
  • libcrypto.so.1.1
484895
393}-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.2