Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/rand/drbg_ctr.c |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||
2 | - | |||||||||||||
3 | - | |||||||||||||
4 | - | |||||||||||||
5 | static void inc_128(RAND_DRBG_CTR *ctr) | - | ||||||||||||
6 | { | - | ||||||||||||
7 | int i; | - | ||||||||||||
8 | unsigned char c; | - | ||||||||||||
9 | unsigned char *p = &ctr->V[15]; | - | ||||||||||||
10 | - | |||||||||||||
11 | for (i = 0; i < 16
| 0-17777205 | ||||||||||||
12 | c = *p; | - | ||||||||||||
13 | c++; | - | ||||||||||||
14 | *p = c; | - | ||||||||||||
15 | if (c != 0
| 77099-17923679 | ||||||||||||
16 | - | |||||||||||||
17 | break; executed 17729011 times by 2 tests: break; Executed by:
| 17729011 | ||||||||||||
18 | } | - | ||||||||||||
19 | } executed 77097 times by 2 tests: end of block Executed by:
| 77097 | ||||||||||||
20 | } executed 17675448 times by 2 tests: end of block Executed by:
| 17675448 | ||||||||||||
21 | - | |||||||||||||
22 | static void ctr_XOR(RAND_DRBG_CTR *ctr, const unsigned char *in, size_t inlen) | - | ||||||||||||
23 | { | - | ||||||||||||
24 | size_t i, n; | - | ||||||||||||
25 | - | |||||||||||||
26 | if (in ==
| 7218-2100727 | ||||||||||||
27 | ((void *)0)
| 7218-2100727 | ||||||||||||
28 | || inlen == 0
| 3600-2113562 | ||||||||||||
29 | return; executed 10818 times by 1 test: return; Executed by:
| 10818 | ||||||||||||
30 | - | |||||||||||||
31 | - | |||||||||||||
32 | - | |||||||||||||
33 | - | |||||||||||||
34 | - | |||||||||||||
35 | n = inlen < ctr->keylen
| 0-2107945 | ||||||||||||
36 | for (i = 0; i < n
| 2133729-65699309 | ||||||||||||
37 | ctr->K[i] ^= in[i]; executed 65704331 times by 2 tests: ctr->K[i] ^= in[i]; Executed by:
| 65704331 | ||||||||||||
38 | if (inlen <= ctr->keylen
| 0-2120534 | ||||||||||||
39 | return; never executed: return; | 0 | ||||||||||||
40 | - | |||||||||||||
41 | n = inlen - ctr->keylen; | - | ||||||||||||
42 | if (n > 16
| 0-2116629 | ||||||||||||
43 | - | |||||||||||||
44 | n = 16; | - | ||||||||||||
45 | } never executed: end of block | 0 | ||||||||||||
46 | for (i = 0; i < n
| 2131999-33413748 | ||||||||||||
47 | ctr->V[i] ^= in[i + ctr->keylen]; executed 33447824 times by 2 tests: ctr->V[i] ^= in[i + ctr->keylen]; Executed by:
| 33447824 | ||||||||||||
48 | } executed 2119266 times by 2 tests: end of block Executed by:
| 2119266 | ||||||||||||
49 | - | |||||||||||||
50 | - | |||||||||||||
51 | - | |||||||||||||
52 | - | |||||||||||||
53 | static int ctr_BCC_block(RAND_DRBG_CTR *ctr, unsigned char *out, | - | ||||||||||||
54 | const unsigned char *in) | - | ||||||||||||
55 | { | - | ||||||||||||
56 | int i, outlen = 16; | - | ||||||||||||
57 | - | |||||||||||||
58 | for (i = 0; i < 16
| 9487527-144141478 | ||||||||||||
59 | out[i] ^= in[i]; executed 144315469 times by 2 tests: out[i] ^= in[i]; Executed by:
| 144315469 | ||||||||||||
60 | - | |||||||||||||
61 | if (!EVP_CipherUpdate(ctr->ctx_df, out, &outlen, out, 16)
| 0-9107744 | ||||||||||||
62 | || outlen != 16
| 0-9277088 | ||||||||||||
63 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
64 | return executed 9242579 times by 2 tests: 1;return 1; Executed by:
executed 9242579 times by 2 tests: return 1; Executed by:
| 9242579 | ||||||||||||
65 | } | - | ||||||||||||
66 | - | |||||||||||||
67 | - | |||||||||||||
68 | - | |||||||||||||
69 | - | |||||||||||||
70 | - | |||||||||||||
71 | static int ctr_BCC_blocks(RAND_DRBG_CTR *ctr, const unsigned char *in) | - | ||||||||||||
72 | { | - | ||||||||||||
73 | if (!ctr_BCC_block(ctr, ctr->KX, in)
| 0-2126716 | ||||||||||||
74 | || !ctr_BCC_block(ctr, ctr->KX + 16, in)
| 0-2126487 | ||||||||||||
75 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
76 | if (ctr->keylen != 16
| 0-2125097 | ||||||||||||
77 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
78 | return executed 2128112 times by 2 tests: 1;return 1; Executed by:
executed 2128112 times by 2 tests: return 1; Executed by:
| 2128112 | ||||||||||||
79 | } | - | ||||||||||||
80 | - | |||||||||||||
81 | - | |||||||||||||
82 | - | |||||||||||||
83 | - | |||||||||||||
84 | - | |||||||||||||
85 | static int ctr_BCC_init(RAND_DRBG_CTR *ctr) | - | ||||||||||||
86 | { | - | ||||||||||||
87 | memset(ctr->KX, 0, 48); | - | ||||||||||||
88 | memset(ctr->bltmp, 0, 16); | - | ||||||||||||
89 | if (!ctr_BCC_block(ctr, ctr->KX, ctr->bltmp)
| 0-1048909 | ||||||||||||
90 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
91 | ctr->bltmp[3] = 1; | - | ||||||||||||
92 | if (!ctr_BCC_block(ctr, ctr->KX + 16, ctr->bltmp)
| 0-1054781 | ||||||||||||
93 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
94 | if (ctr->keylen != 16
| 2406-1055022 | ||||||||||||
95 | ctr->bltmp[3] = 2; | - | ||||||||||||
96 | if (!ctr_BCC_block(ctr, ctr->KX + 32, ctr->bltmp)
| 0-1052786 | ||||||||||||
97 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
98 | } executed 1052231 times by 2 tests: end of block Executed by:
| 1052231 | ||||||||||||
99 | return executed 1056216 times by 2 tests: 1;return 1; Executed by:
executed 1056216 times by 2 tests: return 1; Executed by:
| 1056216 | ||||||||||||
100 | } | - | ||||||||||||
101 | - | |||||||||||||
102 | - | |||||||||||||
103 | - | |||||||||||||
104 | - | |||||||||||||
105 | static int ctr_BCC_update(RAND_DRBG_CTR *ctr, | - | ||||||||||||
106 | const unsigned char *in, size_t inlen) | - | ||||||||||||
107 | { | - | ||||||||||||
108 | if (in ==
| 2109284-2116530 | ||||||||||||
109 | ((void *)0)
| 2109284-2116530 | ||||||||||||
110 | || inlen == 0
| 3600-2127705 | ||||||||||||
111 | return executed 2114178 times by 2 tests: 1;return 1; Executed by:
executed 2114178 times by 2 tests: return 1; Executed by:
| 2114178 | ||||||||||||
112 | - | |||||||||||||
113 | - | |||||||||||||
114 | if (ctr->bltmp_pos
| 4757-2121858 | ||||||||||||
115 | size_t left = 16 - ctr->bltmp_pos; | - | ||||||||||||
116 | - | |||||||||||||
117 | - | |||||||||||||
118 | if (inlen >= left
| 1062805-1068528 | ||||||||||||
119 | memcpy(ctr->bltmp + ctr->bltmp_pos, in, left); | - | ||||||||||||
120 | if (!ctr_BCC_blocks(ctr, ctr->bltmp)
| 0-1061982 | ||||||||||||
121 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
122 | ctr->bltmp_pos = 0; | - | ||||||||||||
123 | inlen -= left; | - | ||||||||||||
124 | in += left; | - | ||||||||||||
125 | } executed 1060802 times by 2 tests: end of block Executed by:
| 1060802 | ||||||||||||
126 | } executed 2120769 times by 2 tests: end of block Executed by:
| 2120769 | ||||||||||||
127 | - | |||||||||||||
128 | - | |||||||||||||
129 | for (; inlen >= 16
| 14057-2122941 | ||||||||||||
130 | if (!ctr_BCC_blocks(ctr, in)
| 0-14057 | ||||||||||||
131 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
132 | } executed 14057 times by 2 tests: end of block Executed by:
| 14057 | ||||||||||||
133 | - | |||||||||||||
134 | - | |||||||||||||
135 | if (inlen > 0
| 4757-2116703 | ||||||||||||
136 | memcpy(ctr->bltmp + ctr->bltmp_pos, in, inlen); | - | ||||||||||||
137 | ctr->bltmp_pos += inlen; | - | ||||||||||||
138 | } executed 2118794 times by 2 tests: end of block Executed by:
| 2118794 | ||||||||||||
139 | return executed 2128649 times by 2 tests: 1;return 1; Executed by:
executed 2128649 times by 2 tests: return 1; Executed by:
| 2128649 | ||||||||||||
140 | } | - | ||||||||||||
141 | - | |||||||||||||
142 | static int ctr_BCC_final(RAND_DRBG_CTR *ctr) | - | ||||||||||||
143 | { | - | ||||||||||||
144 | if (ctr->bltmp_pos
| 0-1065727 | ||||||||||||
145 | memset(ctr->bltmp + ctr->bltmp_pos, 0, 16 - ctr->bltmp_pos); | - | ||||||||||||
146 | if (!ctr_BCC_blocks(ctr, ctr->bltmp)
| 0-1058357 | ||||||||||||
147 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
148 | } executed 1058171 times by 2 tests: end of block Executed by:
| 1058171 | ||||||||||||
149 | return executed 1060204 times by 2 tests: 1;return 1; Executed by:
executed 1060204 times by 2 tests: return 1; Executed by:
| 1060204 | ||||||||||||
150 | } | - | ||||||||||||
151 | - | |||||||||||||
152 | static int ctr_df(RAND_DRBG_CTR *ctr, | - | ||||||||||||
153 | const unsigned char *in1, size_t in1len, | - | ||||||||||||
154 | const unsigned char *in2, size_t in2len, | - | ||||||||||||
155 | const unsigned char *in3, size_t in3len) | - | ||||||||||||
156 | { | - | ||||||||||||
157 | static unsigned char c80 = 0x80; | - | ||||||||||||
158 | size_t inlen; | - | ||||||||||||
159 | unsigned char *p = ctr->bltmp; | - | ||||||||||||
160 | int outlen = 16; | - | ||||||||||||
161 | - | |||||||||||||
162 | if (!ctr_BCC_init(ctr)
| 0-1054484 | ||||||||||||
163 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
164 | if (in1 ==
| 0-1056829 | ||||||||||||
165 | ((void *)0)
| 0-1056829 | ||||||||||||
166 | ) | - | ||||||||||||
167 | in1len = 0; never executed: in1len = 0; | 0 | ||||||||||||
168 | if (in2 ==
| 2947-1058043 | ||||||||||||
169 | ((void *)0)
| 2947-1058043 | ||||||||||||
170 | ) | - | ||||||||||||
171 | in2len = 0; executed 1057171 times by 2 tests: in2len = 0; Executed by:
| 1057171 | ||||||||||||
172 | if (in3 ==
| 6171-1055418 | ||||||||||||
173 | ((void *)0)
| 6171-1055418 | ||||||||||||
174 | ) | - | ||||||||||||
175 | in3len = 0; executed 1057536 times by 2 tests: in3len = 0; Executed by:
| 1057536 | ||||||||||||
176 | inlen = in1len + in2len + in3len; | - | ||||||||||||
177 | - | |||||||||||||
178 | *p++ = (inlen >> 24) & 0xff; | - | ||||||||||||
179 | *p++ = (inlen >> 16) & 0xff; | - | ||||||||||||
180 | *p++ = (inlen >> 8) & 0xff; | - | ||||||||||||
181 | *p++ = inlen & 0xff; | - | ||||||||||||
182 | - | |||||||||||||
183 | - | |||||||||||||
184 | *p++ = 0; | - | ||||||||||||
185 | *p++ = 0; | - | ||||||||||||
186 | *p++ = 0; | - | ||||||||||||
187 | *p = (unsigned char)((ctr->keylen + 16) & 0xff); | - | ||||||||||||
188 | ctr->bltmp_pos = 8; | - | ||||||||||||
189 | if (!ctr_BCC_update(ctr, in1, in1len)
| 0-1060519 | ||||||||||||
190 | || !ctr_BCC_update(ctr, in2, in2len)
| 0-1061657 | ||||||||||||
191 | || !ctr_BCC_update(ctr, in3, in3len)
| 0-1061592 | ||||||||||||
192 | || !ctr_BCC_update(ctr, &c80, 1)
| 0-1067026 | ||||||||||||
193 | || !ctr_BCC_final(ctr)
| 0-1059890 | ||||||||||||
194 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
195 | - | |||||||||||||
196 | if (!EVP_CipherInit_ex(ctr->ctx, ctr->cipher,
| 0-1039622 | ||||||||||||
197 | ((void *)0)
| 0-1039622 | ||||||||||||
198 | , ctr->KX,
| 0-1039622 | ||||||||||||
199 | ((void *)0)
| 0-1039622 | ||||||||||||
200 | , 1)
| 0-1039622 | ||||||||||||
201 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
202 | - | |||||||||||||
203 | if (!EVP_CipherUpdate(ctr->ctx, ctr->KX, &outlen, ctr->KX + ctr->keylen,
| 0-1033080 | ||||||||||||
204 | 16)
| 0-1033080 | ||||||||||||
205 | || outlen != 16
| 0-1032116 | ||||||||||||
206 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
207 | if (!EVP_CipherUpdate(ctr->ctx, ctr->KX + 16, &outlen, ctr->KX,
| 0-1036967 | ||||||||||||
208 | 16)
| 0-1036967 | ||||||||||||
209 | || outlen != 16
| 0-1053122 | ||||||||||||
210 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
211 | if (ctr->keylen != 16
| 2406-1048801 | ||||||||||||
212 | if (!EVP_CipherUpdate(ctr->ctx, ctr->KX + 32, &outlen, ctr->KX + 16,
| 0-1036021 | ||||||||||||
213 | 16)
| 0-1036021 | ||||||||||||
214 | || outlen != 16
| 0-1036464 | ||||||||||||
215 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
216 | return executed 1037211 times by 2 tests: 1;return 1; Executed by:
executed 1037211 times by 2 tests: return 1; Executed by:
| 1037211 | ||||||||||||
217 | } | - | ||||||||||||
218 | - | |||||||||||||
219 | - | |||||||||||||
220 | - | |||||||||||||
221 | - | |||||||||||||
222 | - | |||||||||||||
223 | - | |||||||||||||
224 | - | |||||||||||||
225 | static int ctr_update(RAND_DRBG *drbg, | - | ||||||||||||
226 | const unsigned char *in1, size_t in1len, | - | ||||||||||||
227 | const unsigned char *in2, size_t in2len, | - | ||||||||||||
228 | const unsigned char *nonce, size_t noncelen) | - | ||||||||||||
229 | { | - | ||||||||||||
230 | RAND_DRBG_CTR *ctr = &drbg->data.ctr; | - | ||||||||||||
231 | int outlen = 16; | - | ||||||||||||
232 | - | |||||||||||||
233 | - | |||||||||||||
234 | inc_128(ctr); | - | ||||||||||||
235 | if (!EVP_CipherUpdate(ctr->ctx, ctr->K, &outlen, ctr->V, 16)
| 0-2077957 | ||||||||||||
236 | || outlen != 16
| 0-2090106 | ||||||||||||
237 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
238 | - | |||||||||||||
239 | - | |||||||||||||
240 | if (ctr->keylen != 16
| 6738-2084114 | ||||||||||||
241 | inc_128(ctr); | - | ||||||||||||
242 | if (!EVP_CipherUpdate(ctr->ctx, ctr->K+16, &outlen, ctr->V,
| 0-2083800 | ||||||||||||
243 | 16)
| 0-2083800 | ||||||||||||
244 | || outlen != 16
| 0-2085401 | ||||||||||||
245 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
246 | } executed 2077559 times by 2 tests: end of block Executed by:
| 2077559 | ||||||||||||
247 | inc_128(ctr); | - | ||||||||||||
248 | if (!EVP_CipherUpdate(ctr->ctx, ctr->V, &outlen, ctr->V, 16)
| 0-2091943 | ||||||||||||
249 | || outlen != 16
| 0-2109462 | ||||||||||||
250 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
251 | - | |||||||||||||
252 | - | |||||||||||||
253 | if (ctr->keylen == 24
| 6738-2099521 | ||||||||||||
254 | memcpy(ctr->V + 8, ctr->V, 8); | - | ||||||||||||
255 | memcpy(ctr->V, ctr->K + 24, 8); | - | ||||||||||||
256 | } executed 6738 times by 1 test: end of block Executed by:
| 6738 | ||||||||||||
257 | - | |||||||||||||
258 | if ((
| 10107-2094452 | ||||||||||||
259 | - | |||||||||||||
260 | if (in1 !=
| 1051507-1052792 | ||||||||||||
261 | ((void *)0)
| 1051507-1052792 | ||||||||||||
262 | || nonce !=
| 0-1053558 | ||||||||||||
263 | ((void *)0)
| 0-1053558 | ||||||||||||
264 | || in2 !=
| 0-1059308 | ||||||||||||
265 | ((void *)0)
| 0-1059308 | ||||||||||||
266 | ) | - | ||||||||||||
267 | if (!ctr_df(ctr, in1, in1len, nonce, noncelen, in2, in2len)
| 0-1036562 | ||||||||||||
268 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
269 | - | |||||||||||||
270 | if (in1len
| 3984-2104731 | ||||||||||||
271 | ctr_XOR(ctr, ctr->KX, drbg->seedlen); executed 2094558 times by 2 tests: ctr_XOR(ctr, ctr->KX, drbg->seedlen); Executed by:
| 2094558 | ||||||||||||
272 | } executed 2112796 times by 2 tests: else {end of block Executed by:
| 2112796 | ||||||||||||
273 | ctr_XOR(ctr, in1, in1len); | - | ||||||||||||
274 | ctr_XOR(ctr, in2, in2len); | - | ||||||||||||
275 | } executed 10107 times by 1 test: end of block Executed by:
| 10107 | ||||||||||||
276 | - | |||||||||||||
277 | if (!EVP_CipherInit_ex(ctr->ctx, ctr->cipher,
| 0-2082205 | ||||||||||||
278 | ((void *)0)
| 0-2082205 | ||||||||||||
279 | , ctr->K,
| 0-2082205 | ||||||||||||
280 | ((void *)0)
| 0-2082205 | ||||||||||||
281 | , 1)
| 0-2082205 | ||||||||||||
282 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
283 | return executed 2079305 times by 2 tests: 1;return 1; Executed by:
executed 2079305 times by 2 tests: return 1; Executed by:
| 2079305 | ||||||||||||
284 | } | - | ||||||||||||
285 | - | |||||||||||||
286 | static int drbg_ctr_instantiate(RAND_DRBG *drbg, | - | ||||||||||||
287 | const unsigned char *entropy, size_t entropylen, | - | ||||||||||||
288 | const unsigned char *nonce, size_t noncelen, | - | ||||||||||||
289 | const unsigned char *pers, size_t perslen) | - | ||||||||||||
290 | { | - | ||||||||||||
291 | RAND_DRBG_CTR *ctr = &drbg->data.ctr; | - | ||||||||||||
292 | - | |||||||||||||
293 | if (entropy ==
| 0-6125 | ||||||||||||
294 | ((void *)0)
| 0-6125 | ||||||||||||
295 | ) | - | ||||||||||||
296 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
297 | - | |||||||||||||
298 | memset(ctr->K, 0, sizeof(ctr->K)); | - | ||||||||||||
299 | memset(ctr->V, 0, sizeof(ctr->V)); | - | ||||||||||||
300 | if (!EVP_CipherInit_ex(ctr->ctx, ctr->cipher,
| 0-6125 | ||||||||||||
301 | ((void *)0)
| 0-6125 | ||||||||||||
302 | , ctr->K,
| 0-6125 | ||||||||||||
303 | ((void *)0)
| 0-6125 | ||||||||||||
304 | , 1)
| 0-6125 | ||||||||||||
305 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
306 | if (!ctr_update(drbg, entropy, entropylen, pers, perslen, nonce, noncelen)
| 0-6125 | ||||||||||||
307 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
308 | return executed 6125 times by 2 tests: 1;return 1; Executed by:
executed 6125 times by 2 tests: return 1; Executed by:
| 6125 | ||||||||||||
309 | } | - | ||||||||||||
310 | - | |||||||||||||
311 | static int drbg_ctr_reseed(RAND_DRBG *drbg, | - | ||||||||||||
312 | const unsigned char *entropy, size_t entropylen, | - | ||||||||||||
313 | const unsigned char *adin, size_t adinlen) | - | ||||||||||||
314 | { | - | ||||||||||||
315 | if (entropy ==
| 0-4400 | ||||||||||||
316 | ((void *)0)
| 0-4400 | ||||||||||||
317 | ) | - | ||||||||||||
318 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
319 | if (!ctr_update(drbg, entropy, entropylen, adin, adinlen,
| 0-4400 | ||||||||||||
320 | ((void *)0)
| 0-4400 | ||||||||||||
321 | , 0)
| 0-4400 | ||||||||||||
322 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
323 | return executed 4400 times by 1 test: 1;return 1; Executed by:
executed 4400 times by 1 test: return 1; Executed by:
| 4400 | ||||||||||||
324 | } | - | ||||||||||||
325 | - | |||||||||||||
326 | static int drbg_ctr_generate(RAND_DRBG *drbg, | - | ||||||||||||
327 | unsigned char *out, size_t outlen, | - | ||||||||||||
328 | const unsigned char *adin, size_t adinlen) | - | ||||||||||||
329 | { | - | ||||||||||||
330 | RAND_DRBG_CTR *ctr = &drbg->data.ctr; | - | ||||||||||||
331 | - | |||||||||||||
332 | if (adin !=
| 3990-1043409 | ||||||||||||
333 | ((void *)0)
| 3990-1043409 | ||||||||||||
334 | && adinlen != 0
| 2880-1044062 | ||||||||||||
335 | if (!ctr_update(drbg, adin, adinlen,
| 0-1034495 | ||||||||||||
336 | ((void *)0)
| 0-1034495 | ||||||||||||
337 | , 0,
| 0-1034495 | ||||||||||||
338 | ((void *)0)
| 0-1034495 | ||||||||||||
339 | , 0)
| 0-1034495 | ||||||||||||
340 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
341 | - | |||||||||||||
342 | if ((
| 1443-1035196 | ||||||||||||
343 | adin = | - | ||||||||||||
344 | ((void *)0) | - | ||||||||||||
345 | ; | - | ||||||||||||
346 | adinlen = 1; | - | ||||||||||||
347 | } executed 1033532 times by 2 tests: end of block Executed by:
| 1033532 | ||||||||||||
348 | } executed 1039031 times by 2 tests: else {end of block Executed by:
| 1039031 | ||||||||||||
349 | adinlen = 0; | - | ||||||||||||
350 | } executed 6870 times by 2 tests: end of block Executed by:
| 6870 | ||||||||||||
351 | - | |||||||||||||
352 | for ( ; ; ) { | - | ||||||||||||
353 | int outl = 16; | - | ||||||||||||
354 | - | |||||||||||||
355 | inc_128(ctr); | - | ||||||||||||
356 | if (outlen < 16
| 230486-11753918 | ||||||||||||
357 | - | |||||||||||||
358 | if (!EVP_CipherUpdate(ctr->ctx, ctr->K, &outl, ctr->V,
| 0-230486 | ||||||||||||
359 | 16)
| 0-230486 | ||||||||||||
360 | || outl != 16
| 0-230486 | ||||||||||||
361 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
362 | memcpy(out, ctr->K, outlen); | - | ||||||||||||
363 | break; executed 230486 times by 2 tests: break; Executed by:
| 230486 | ||||||||||||
364 | } | - | ||||||||||||
365 | if (!EVP_CipherUpdate(ctr->ctx, out, &outl, ctr->V, 16)
| 0-11465781 | ||||||||||||
366 | || outl != 16
| 0-11885959 | ||||||||||||
367 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
368 | out += 16; | - | ||||||||||||
369 | outlen -= 16; | - | ||||||||||||
370 | if (outlen == 0
| 827529-11119617 | ||||||||||||
371 | break; executed 827491 times by 2 tests: break; Executed by:
| 827491 | ||||||||||||
372 | } executed 11085862 times by 2 tests: end of block Executed by:
| 11085862 | ||||||||||||
373 | - | |||||||||||||
374 | if (!ctr_update(drbg, adin, adinlen,
| 0-1038266 | ||||||||||||
375 | ((void *)0)
| 0-1038266 | ||||||||||||
376 | , 0,
| 0-1038266 | ||||||||||||
377 | ((void *)0)
| 0-1038266 | ||||||||||||
378 | , 0)
| 0-1038266 | ||||||||||||
379 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
380 | return executed 1036700 times by 2 tests: 1;return 1; Executed by:
executed 1036700 times by 2 tests: return 1; Executed by:
| 1036700 | ||||||||||||
381 | } | - | ||||||||||||
382 | - | |||||||||||||
383 | static int drbg_ctr_uninstantiate(RAND_DRBG *drbg) | - | ||||||||||||
384 | { | - | ||||||||||||
385 | EVP_CIPHER_CTX_free(drbg->data.ctr.ctx); | - | ||||||||||||
386 | EVP_CIPHER_CTX_free(drbg->data.ctr.ctx_df); | - | ||||||||||||
387 | OPENSSL_cleanse(&drbg->data.ctr, sizeof(drbg->data.ctr)); | - | ||||||||||||
388 | return executed 14785 times by 2 tests: 1;return 1; Executed by:
executed 14785 times by 2 tests: return 1; Executed by:
| 14785 | ||||||||||||
389 | } | - | ||||||||||||
390 | - | |||||||||||||
391 | static RAND_DRBG_METHOD drbg_ctr_meth = { | - | ||||||||||||
392 | drbg_ctr_instantiate, | - | ||||||||||||
393 | drbg_ctr_reseed, | - | ||||||||||||
394 | drbg_ctr_generate, | - | ||||||||||||
395 | drbg_ctr_uninstantiate | - | ||||||||||||
396 | }; | - | ||||||||||||
397 | - | |||||||||||||
398 | int drbg_ctr_init(RAND_DRBG *drbg) | - | ||||||||||||
399 | { | - | ||||||||||||
400 | RAND_DRBG_CTR *ctr = &drbg->data.ctr; | - | ||||||||||||
401 | size_t keylen; | - | ||||||||||||
402 | - | |||||||||||||
403 | switch (drbg->type) { | - | ||||||||||||
404 | default never executed: :default: never executed: default: | 0 | ||||||||||||
405 | - | |||||||||||||
406 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
407 | case executed 4332 times by 1 test: 904:case 904: Executed by:
executed 4332 times by 1 test: case 904: Executed by:
| 4332 | ||||||||||||
408 | keylen = 16; | - | ||||||||||||
409 | ctr->cipher = EVP_aes_128_ecb(); | - | ||||||||||||
410 | break; executed 4332 times by 1 test: break; Executed by:
| 4332 | ||||||||||||
411 | case executed 4332 times by 1 test: 905:case 905: Executed by:
executed 4332 times by 1 test: case 905: Executed by:
| 4332 | ||||||||||||
412 | keylen = 24; | - | ||||||||||||
413 | ctr->cipher = EVP_aes_192_ecb(); | - | ||||||||||||
414 | break; executed 4332 times by 1 test: break; Executed by:
| 4332 | ||||||||||||
415 | case executed 6133 times by 2 tests: 906:case 906: Executed by:
executed 6133 times by 2 tests: case 906: Executed by:
| 6133 | ||||||||||||
416 | keylen = 32; | - | ||||||||||||
417 | ctr->cipher = EVP_aes_256_ecb(); | - | ||||||||||||
418 | break; executed 6133 times by 2 tests: break; Executed by:
| 6133 | ||||||||||||
419 | } | - | ||||||||||||
420 | - | |||||||||||||
421 | drbg->meth = &drbg_ctr_meth; | - | ||||||||||||
422 | - | |||||||||||||
423 | ctr->keylen = keylen; | - | ||||||||||||
424 | if (ctr->ctx ==
| 12-14785 | ||||||||||||
425 | ((void *)0)
| 12-14785 | ||||||||||||
426 | ) | - | ||||||||||||
427 | ctr->ctx = EVP_CIPHER_CTX_new(); executed 14785 times by 2 tests: ctr->ctx = EVP_CIPHER_CTX_new(); Executed by:
| 14785 | ||||||||||||
428 | if (ctr->ctx ==
| 0-14797 | ||||||||||||
429 | ((void *)0)
| 0-14797 | ||||||||||||
430 | ) | - | ||||||||||||
431 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
432 | drbg->strength = keylen * 8; | - | ||||||||||||
433 | drbg->seedlen = keylen + 16; | - | ||||||||||||
434 | - | |||||||||||||
435 | if ((
| 6498-8299 | ||||||||||||
436 | - | |||||||||||||
437 | static const unsigned char df_key[32] = { | - | ||||||||||||
438 | 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07, | - | ||||||||||||
439 | 0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f, | - | ||||||||||||
440 | 0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17, | - | ||||||||||||
441 | 0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f | - | ||||||||||||
442 | }; | - | ||||||||||||
443 | - | |||||||||||||
444 | if (ctr->ctx_df ==
| 6-8293 | ||||||||||||
445 | ((void *)0)
| 6-8293 | ||||||||||||
446 | ) | - | ||||||||||||
447 | ctr->ctx_df = EVP_CIPHER_CTX_new(); executed 8293 times by 2 tests: ctr->ctx_df = EVP_CIPHER_CTX_new(); Executed by:
| 8293 | ||||||||||||
448 | if (ctr->ctx_df ==
| 0-8299 | ||||||||||||
449 | ((void *)0)
| 0-8299 | ||||||||||||
450 | ) | - | ||||||||||||
451 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
452 | - | |||||||||||||
453 | if (!EVP_CipherInit_ex(ctr->ctx_df, ctr->cipher,
| 0-8299 | ||||||||||||
454 | ((void *)0)
| 0-8299 | ||||||||||||
455 | , df_key,
| 0-8299 | ||||||||||||
456 | ((void *)0)
| 0-8299 | ||||||||||||
457 | , 1)
| 0-8299 | ||||||||||||
458 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
459 | - | |||||||||||||
460 | drbg->min_entropylen = ctr->keylen; | - | ||||||||||||
461 | drbg->max_entropylen = 128 * drbg->min_entropylen; | - | ||||||||||||
462 | drbg->min_noncelen = drbg->min_entropylen / 2; | - | ||||||||||||
463 | drbg->max_noncelen = 128 * drbg->min_noncelen; | - | ||||||||||||
464 | drbg->max_perslen = 4096; | - | ||||||||||||
465 | drbg->max_adinlen = 4096; | - | ||||||||||||
466 | } executed 8299 times by 2 tests: else {end of block Executed by:
| 8299 | ||||||||||||
467 | drbg->min_entropylen = drbg->seedlen; | - | ||||||||||||
468 | drbg->max_entropylen = drbg->seedlen; | - | ||||||||||||
469 | - | |||||||||||||
470 | drbg->min_noncelen = 0; | - | ||||||||||||
471 | drbg->max_noncelen = 0; | - | ||||||||||||
472 | drbg->max_perslen = drbg->seedlen; | - | ||||||||||||
473 | drbg->max_adinlen = drbg->seedlen; | - | ||||||||||||
474 | } executed 6498 times by 1 test: end of block Executed by:
| 6498 | ||||||||||||
475 | - | |||||||||||||
476 | drbg->max_request = 1 << 16; | - | ||||||||||||
477 | - | |||||||||||||
478 | return executed 14797 times by 2 tests: 1;return 1; Executed by:
executed 14797 times by 2 tests: return 1; Executed by:
| 14797 | ||||||||||||
479 | } | - | ||||||||||||
Switch to Source code | Preprocessed file |