Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/libressl/src/crypto/evp/p5_crpt2.c |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||||||||
2 | - | |||||||||||||||||||
3 | - | |||||||||||||||||||
4 | - | |||||||||||||||||||
5 | - | |||||||||||||||||||
6 | - | |||||||||||||||||||
7 | - | |||||||||||||||||||
8 | - | |||||||||||||||||||
9 | - | |||||||||||||||||||
10 | - | |||||||||||||||||||
11 | - | |||||||||||||||||||
12 | - | |||||||||||||||||||
13 | int | - | ||||||||||||||||||
14 | PKCS5_PBKDF2_HMAC(const char *pass, int passlen, const unsigned char *salt, | - | ||||||||||||||||||
15 | int saltlen, int iter, const EVP_MD *digest, int keylen, unsigned char *out) | - | ||||||||||||||||||
16 | { | - | ||||||||||||||||||
17 | unsigned char digtmp[64], *p, itmp[4]; | - | ||||||||||||||||||
18 | int cplen, j, k, tkeylen, mdlen; | - | ||||||||||||||||||
19 | unsigned long i = 1; | - | ||||||||||||||||||
20 | HMAC_CTX hctx_tpl, hctx; | - | ||||||||||||||||||
21 | - | |||||||||||||||||||
22 | mdlen = EVP_MD_size(digest); | - | ||||||||||||||||||
23 | if (mdlen < 0
| 0-15 | ||||||||||||||||||
24 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||
25 | - | |||||||||||||||||||
26 | HMAC_CTX_init(&hctx_tpl); | - | ||||||||||||||||||
27 | p = out; | - | ||||||||||||||||||
28 | tkeylen = keylen; | - | ||||||||||||||||||
29 | if (!pass
| 0-15 | ||||||||||||||||||
30 | passlen = 0; never executed: passlen = 0; | 0 | ||||||||||||||||||
31 | else if (passlen == -1
| 0-15 | ||||||||||||||||||
32 | passlen = strlen(pass); never executed: passlen = strlen(pass); | 0 | ||||||||||||||||||
33 | if (!HMAC_Init_ex(&hctx_tpl, pass, passlen, digest,
| 0-15 | ||||||||||||||||||
34 | ((void *)0)
| 0-15 | ||||||||||||||||||
35 | )
| 0-15 | ||||||||||||||||||
36 | HMAC_CTX_cleanup(&hctx_tpl); | - | ||||||||||||||||||
37 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||
38 | } | - | ||||||||||||||||||
39 | while (tkeylen
| 15-17 | ||||||||||||||||||
40 | if (tkeylen > mdlen
| 2-15 | ||||||||||||||||||
41 | cplen = mdlen; executed 2 times by 1 test: cplen = mdlen; Executed by:
| 2 | ||||||||||||||||||
42 | else | - | ||||||||||||||||||
43 | cplen = tkeylen; executed 15 times by 1 test: cplen = tkeylen; Executed by:
| 15 | ||||||||||||||||||
44 | - | |||||||||||||||||||
45 | - | |||||||||||||||||||
46 | - | |||||||||||||||||||
47 | itmp[0] = (unsigned char)((i >> 24) & 0xff); | - | ||||||||||||||||||
48 | itmp[1] = (unsigned char)((i >> 16) & 0xff); | - | ||||||||||||||||||
49 | itmp[2] = (unsigned char)((i >> 8) & 0xff); | - | ||||||||||||||||||
50 | itmp[3] = (unsigned char)(i & 0xff); | - | ||||||||||||||||||
51 | if (!HMAC_CTX_copy(&hctx, &hctx_tpl)
| 0-17 | ||||||||||||||||||
52 | HMAC_CTX_cleanup(&hctx_tpl); | - | ||||||||||||||||||
53 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||
54 | } | - | ||||||||||||||||||
55 | if (!HMAC_Update(&hctx, salt, saltlen)
| 0-17 | ||||||||||||||||||
56 | !HMAC_Update(&hctx, itmp, 4)
| 0-17 | ||||||||||||||||||
57 | !HMAC_Final(&hctx, digtmp,
| 0-17 | ||||||||||||||||||
58 | ((void *)0)
| 0-17 | ||||||||||||||||||
59 | )
| 0-17 | ||||||||||||||||||
60 | HMAC_CTX_cleanup(&hctx_tpl); | - | ||||||||||||||||||
61 | HMAC_CTX_cleanup(&hctx); | - | ||||||||||||||||||
62 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||
63 | } | - | ||||||||||||||||||
64 | HMAC_CTX_cleanup(&hctx); | - | ||||||||||||||||||
65 | memcpy(p, digtmp, cplen); | - | ||||||||||||||||||
66 | for (j = 1; j < iter
| 17-45048 | ||||||||||||||||||
67 | if (!HMAC_CTX_copy(&hctx, &hctx_tpl)
| 0-45048 | ||||||||||||||||||
68 | HMAC_CTX_cleanup(&hctx_tpl); | - | ||||||||||||||||||
69 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||
70 | } | - | ||||||||||||||||||
71 | if (!HMAC_Update(&hctx, digtmp, mdlen)
| 0-45048 | ||||||||||||||||||
72 | !HMAC_Final(&hctx, digtmp,
| 0-45048 | ||||||||||||||||||
73 | ((void *)0)
| 0-45048 | ||||||||||||||||||
74 | )
| 0-45048 | ||||||||||||||||||
75 | HMAC_CTX_cleanup(&hctx_tpl); | - | ||||||||||||||||||
76 | HMAC_CTX_cleanup(&hctx); | - | ||||||||||||||||||
77 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||
78 | } | - | ||||||||||||||||||
79 | HMAC_CTX_cleanup(&hctx); | - | ||||||||||||||||||
80 | for (k = 0; k < cplen
| 45048-1199951 | ||||||||||||||||||
81 | p[k] ^= digtmp[k]; executed 1199951 times by 1 test: p[k] ^= digtmp[k]; Executed by:
| 1199951 | ||||||||||||||||||
82 | } executed 45048 times by 1 test: end of block Executed by:
| 45048 | ||||||||||||||||||
83 | tkeylen -= cplen; | - | ||||||||||||||||||
84 | i++; | - | ||||||||||||||||||
85 | p += cplen; | - | ||||||||||||||||||
86 | } executed 17 times by 1 test: end of block Executed by:
| 17 | ||||||||||||||||||
87 | HMAC_CTX_cleanup(&hctx_tpl); | - | ||||||||||||||||||
88 | return executed 15 times by 1 test: 1;return 1; Executed by:
executed 15 times by 1 test: return 1; Executed by:
| 15 | ||||||||||||||||||
89 | } | - | ||||||||||||||||||
90 | - | |||||||||||||||||||
91 | int | - | ||||||||||||||||||
92 | PKCS5_PBKDF2_HMAC_SHA1(const char *pass, int passlen, const unsigned char *salt, | - | ||||||||||||||||||
93 | int saltlen, int iter, int keylen, unsigned char *out) | - | ||||||||||||||||||
94 | { | - | ||||||||||||||||||
95 | return never executed: PKCS5_PBKDF2_HMAC(pass, passlen, salt, saltlen, iter,return PKCS5_PBKDF2_HMAC(pass, passlen, salt, saltlen, iter, EVP_sha1(), keylen, out); never executed: return PKCS5_PBKDF2_HMAC(pass, passlen, salt, saltlen, iter, EVP_sha1(), keylen, out); | 0 | ||||||||||||||||||
96 | EVP_sha1(), keylen, out); never executed: return PKCS5_PBKDF2_HMAC(pass, passlen, salt, saltlen, iter, EVP_sha1(), keylen, out); | 0 | ||||||||||||||||||
97 | } | - | ||||||||||||||||||
98 | - | |||||||||||||||||||
99 | - | |||||||||||||||||||
100 | - | |||||||||||||||||||
101 | - | |||||||||||||||||||
102 | - | |||||||||||||||||||
103 | - | |||||||||||||||||||
104 | int | - | ||||||||||||||||||
105 | PKCS5_v2_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen, | - | ||||||||||||||||||
106 | ASN1_TYPE *param, const EVP_CIPHER *c, const EVP_MD *md, int en_de) | - | ||||||||||||||||||
107 | { | - | ||||||||||||||||||
108 | const unsigned char *pbuf; | - | ||||||||||||||||||
109 | int plen; | - | ||||||||||||||||||
110 | PBE2PARAM *pbe2 = | - | ||||||||||||||||||
111 | ((void *)0) | - | ||||||||||||||||||
112 | ; | - | ||||||||||||||||||
113 | const EVP_CIPHER *cipher; | - | ||||||||||||||||||
114 | - | |||||||||||||||||||
115 | int rv = 0; | - | ||||||||||||||||||
116 | - | |||||||||||||||||||
117 | if (param ==
| 0 | ||||||||||||||||||
118 | ((void *)0)
| 0 | ||||||||||||||||||
119 | || param->type != 16
| 0 | ||||||||||||||||||
120 | param->value.sequence ==
| 0 | ||||||||||||||||||
121 | ((void *)0)
| 0 | ||||||||||||||||||
122 | ) { | - | ||||||||||||||||||
123 | ERR_put_error(6,(0xfff),(114),__FILE__,178); | - | ||||||||||||||||||
124 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
125 | } | - | ||||||||||||||||||
126 | - | |||||||||||||||||||
127 | pbuf = param->value.sequence->data; | - | ||||||||||||||||||
128 | plen = param->value.sequence->length; | - | ||||||||||||||||||
129 | if (!(pbe2 = d2i_PBE2PARAM(
| 0 | ||||||||||||||||||
130 | ((void *)0)
| 0 | ||||||||||||||||||
131 | , &pbuf, plen))
| 0 | ||||||||||||||||||
132 | ERR_put_error(6,(0xfff),(114),__FILE__,185); | - | ||||||||||||||||||
133 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
134 | } | - | ||||||||||||||||||
135 | - | |||||||||||||||||||
136 | - | |||||||||||||||||||
137 | - | |||||||||||||||||||
138 | if (OBJ_obj2nid(pbe2->keyfunc->algorithm) != 69
| 0 | ||||||||||||||||||
139 | ERR_put_error(6,(0xfff),(124),__FILE__,192); | - | ||||||||||||||||||
140 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
141 | } | - | ||||||||||||||||||
142 | - | |||||||||||||||||||
143 | - | |||||||||||||||||||
144 | - | |||||||||||||||||||
145 | - | |||||||||||||||||||
146 | cipher = EVP_get_cipherbyname(OBJ_nid2sn(OBJ_obj2nid(pbe2->encryption->algorithm))); | - | ||||||||||||||||||
147 | - | |||||||||||||||||||
148 | if (!cipher
| 0 | ||||||||||||||||||
149 | ERR_put_error(6,(0xfff),(107),__FILE__,202); | - | ||||||||||||||||||
150 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
151 | } | - | ||||||||||||||||||
152 | - | |||||||||||||||||||
153 | - | |||||||||||||||||||
154 | if (!EVP_CipherInit_ex(ctx, cipher,
| 0 | ||||||||||||||||||
155 | ((void *)0)
| 0 | ||||||||||||||||||
156 | ,
| 0 | ||||||||||||||||||
157 | ((void *)0)
| 0 | ||||||||||||||||||
158 | ,
| 0 | ||||||||||||||||||
159 | ((void *)0)
| 0 | ||||||||||||||||||
160 | , en_de)
| 0 | ||||||||||||||||||
161 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
162 | if (EVP_CIPHER_asn1_to_param(ctx, pbe2->encryption->parameter) < 0
| 0 | ||||||||||||||||||
163 | ERR_put_error(6,(0xfff),(122),__FILE__,210); | - | ||||||||||||||||||
164 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
165 | } | - | ||||||||||||||||||
166 | rv = PKCS5_v2_PBKDF2_keyivgen(ctx, pass, passlen, | - | ||||||||||||||||||
167 | pbe2->keyfunc->parameter, c, md, en_de); | - | ||||||||||||||||||
168 | - | |||||||||||||||||||
169 | err: code before this statement never executed: err: | 0 | ||||||||||||||||||
170 | PBE2PARAM_free(pbe2); | - | ||||||||||||||||||
171 | return never executed: rv;return rv; never executed: return rv; | 0 | ||||||||||||||||||
172 | } | - | ||||||||||||||||||
173 | - | |||||||||||||||||||
174 | int | - | ||||||||||||||||||
175 | PKCS5_v2_PBKDF2_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen, | - | ||||||||||||||||||
176 | ASN1_TYPE *param, const EVP_CIPHER *c, const EVP_MD *md, int en_de) | - | ||||||||||||||||||
177 | { | - | ||||||||||||||||||
178 | unsigned char *salt, key[64]; | - | ||||||||||||||||||
179 | const unsigned char *pbuf; | - | ||||||||||||||||||
180 | int saltlen, iter, plen; | - | ||||||||||||||||||
181 | int rv = 0; | - | ||||||||||||||||||
182 | unsigned int keylen = 0; | - | ||||||||||||||||||
183 | int prf_nid, hmac_md_nid; | - | ||||||||||||||||||
184 | PBKDF2PARAM *kdf = | - | ||||||||||||||||||
185 | ((void *)0) | - | ||||||||||||||||||
186 | ; | - | ||||||||||||||||||
187 | const EVP_MD *prfmd; | - | ||||||||||||||||||
188 | - | |||||||||||||||||||
189 | if (EVP_CIPHER_CTX_cipher(ctx) ==
| 0 | ||||||||||||||||||
190 | ((void *)0)
| 0 | ||||||||||||||||||
191 | ) { | - | ||||||||||||||||||
192 | ERR_put_error(6,(0xfff),(131),__FILE__,235); | - | ||||||||||||||||||
193 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||
194 | } | - | ||||||||||||||||||
195 | keylen = EVP_CIPHER_CTX_key_length(ctx); | - | ||||||||||||||||||
196 | if (keylen > sizeof key
| 0 | ||||||||||||||||||
197 | ERR_put_error(6,(0xfff),(137),__FILE__,240); | - | ||||||||||||||||||
198 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||
199 | } | - | ||||||||||||||||||
200 | - | |||||||||||||||||||
201 | - | |||||||||||||||||||
202 | - | |||||||||||||||||||
203 | if (!param
| 0 | ||||||||||||||||||
204 | ERR_put_error(6,(0xfff),(114),__FILE__,247); | - | ||||||||||||||||||
205 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||
206 | } | - | ||||||||||||||||||
207 | - | |||||||||||||||||||
208 | pbuf = param->value.sequence->data; | - | ||||||||||||||||||
209 | plen = param->value.sequence->length; | - | ||||||||||||||||||
210 | - | |||||||||||||||||||
211 | if (!(kdf = d2i_PBKDF2PARAM(
| 0 | ||||||||||||||||||
212 | ((void *)0)
| 0 | ||||||||||||||||||
213 | , &pbuf, plen))
| 0 | ||||||||||||||||||
214 | ERR_put_error(6,(0xfff),(114),__FILE__,255); | - | ||||||||||||||||||
215 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||
216 | } | - | ||||||||||||||||||
217 | - | |||||||||||||||||||
218 | - | |||||||||||||||||||
219 | - | |||||||||||||||||||
220 | if (kdf->keylength
| 0 | ||||||||||||||||||
221 | (
| 0 | ||||||||||||||||||
222 | ERR_put_error(6,(0xfff),(123),__FILE__,263); | - | ||||||||||||||||||
223 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
224 | } | - | ||||||||||||||||||
225 | - | |||||||||||||||||||
226 | if (kdf->prf
| 0 | ||||||||||||||||||
227 | prf_nid = OBJ_obj2nid(kdf->prf->algorithm); never executed: prf_nid = OBJ_obj2nid(kdf->prf->algorithm); | 0 | ||||||||||||||||||
228 | else | - | ||||||||||||||||||
229 | prf_nid = 163; never executed: prf_nid = 163; | 0 | ||||||||||||||||||
230 | - | |||||||||||||||||||
231 | if (!EVP_PBE_find(0x1, prf_nid,
| 0 | ||||||||||||||||||
232 | ((void *)0)
| 0 | ||||||||||||||||||
233 | , &hmac_md_nid, 0)
| 0 | ||||||||||||||||||
234 | ERR_put_error(6,(0xfff),(125),__FILE__,273); | - | ||||||||||||||||||
235 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
236 | } | - | ||||||||||||||||||
237 | - | |||||||||||||||||||
238 | prfmd = EVP_get_digestbyname(OBJ_nid2sn(hmac_md_nid)); | - | ||||||||||||||||||
239 | if (prfmd ==
| 0 | ||||||||||||||||||
240 | ((void *)0)
| 0 | ||||||||||||||||||
241 | ) { | - | ||||||||||||||||||
242 | ERR_put_error(6,(0xfff),(125),__FILE__,279); | - | ||||||||||||||||||
243 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
244 | } | - | ||||||||||||||||||
245 | - | |||||||||||||||||||
246 | if (kdf->salt->type != 4
| 0 | ||||||||||||||||||
247 | ERR_put_error(6,(0xfff),(126),__FILE__,284); | - | ||||||||||||||||||
248 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
249 | } | - | ||||||||||||||||||
250 | - | |||||||||||||||||||
251 | - | |||||||||||||||||||
252 | salt = kdf->salt->value.octet_string->data; | - | ||||||||||||||||||
253 | saltlen = kdf->salt->value.octet_string->length; | - | ||||||||||||||||||
254 | if ((
| 0 | ||||||||||||||||||
255 | ERR_put_error(6,(0xfff),(135),__FILE__,292); | - | ||||||||||||||||||
256 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
257 | } | - | ||||||||||||||||||
258 | if (!PKCS5_PBKDF2_HMAC(pass, passlen, salt, saltlen, iter, prfmd,
| 0 | ||||||||||||||||||
259 | keylen, key)
| 0 | ||||||||||||||||||
260 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
261 | rv = EVP_CipherInit_ex(ctx, | - | ||||||||||||||||||
262 | ((void *)0) | - | ||||||||||||||||||
263 | , | - | ||||||||||||||||||
264 | ((void *)0) | - | ||||||||||||||||||
265 | , key, | - | ||||||||||||||||||
266 | ((void *)0) | - | ||||||||||||||||||
267 | , en_de); | - | ||||||||||||||||||
268 | - | |||||||||||||||||||
269 | err: code before this statement never executed: err: | 0 | ||||||||||||||||||
270 | explicit_bzero(key, keylen); | - | ||||||||||||||||||
271 | PBKDF2PARAM_free(kdf); | - | ||||||||||||||||||
272 | return never executed: rv;return rv; never executed: return rv; | 0 | ||||||||||||||||||
273 | } | - | ||||||||||||||||||
Switch to Source code | Preprocessed file |