Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/evp/evp_pbe.c |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||
2 | - | |||||||||||||
3 | - | |||||||||||||
4 | - | |||||||||||||
5 | - | |||||||||||||
6 | - | |||||||||||||
7 | struct evp_pbe_st { | - | ||||||||||||
8 | int pbe_type; | - | ||||||||||||
9 | int pbe_nid; | - | ||||||||||||
10 | int cipher_nid; | - | ||||||||||||
11 | int md_nid; | - | ||||||||||||
12 | EVP_PBE_KEYGEN *keygen; | - | ||||||||||||
13 | }; | - | ||||||||||||
14 | - | |||||||||||||
15 | static struct stack_st_EVP_PBE_CTL *pbe_algs; | - | ||||||||||||
16 | - | |||||||||||||
17 | static const EVP_PBE_CTL builtin_pbe[] = { | - | ||||||||||||
18 | {0x0, 9, | - | ||||||||||||
19 | 31, 3, PKCS5_PBE_keyivgen}, | - | ||||||||||||
20 | {0x0, 10, | - | ||||||||||||
21 | 31, 4, PKCS5_PBE_keyivgen}, | - | ||||||||||||
22 | {0x0, 68, | - | ||||||||||||
23 | 166, 64, PKCS5_PBE_keyivgen}, | - | ||||||||||||
24 | - | |||||||||||||
25 | {0x0, 69, -1, -1, PKCS5_v2_PBKDF2_keyivgen}, | - | ||||||||||||
26 | - | |||||||||||||
27 | {0x0, 144, | - | ||||||||||||
28 | 5, 64, PKCS12_PBE_keyivgen}, | - | ||||||||||||
29 | {0x0, 145, | - | ||||||||||||
30 | 97, 64, PKCS12_PBE_keyivgen}, | - | ||||||||||||
31 | {0x0, 146, | - | ||||||||||||
32 | 44, 64, PKCS12_PBE_keyivgen}, | - | ||||||||||||
33 | {0x0, 147, | - | ||||||||||||
34 | 43, 64, PKCS12_PBE_keyivgen}, | - | ||||||||||||
35 | {0x0, 148, | - | ||||||||||||
36 | 37, 64, PKCS12_PBE_keyivgen}, | - | ||||||||||||
37 | {0x0, 149, | - | ||||||||||||
38 | 98, 64, PKCS12_PBE_keyivgen}, | - | ||||||||||||
39 | - | |||||||||||||
40 | {0x0, 161, -1, -1, PKCS5_v2_PBE_keyivgen}, | - | ||||||||||||
41 | - | |||||||||||||
42 | {0x0, 168, | - | ||||||||||||
43 | 166, 3, PKCS5_PBE_keyivgen}, | - | ||||||||||||
44 | {0x0, 169, | - | ||||||||||||
45 | 166, 4, PKCS5_PBE_keyivgen}, | - | ||||||||||||
46 | {0x0, 170, | - | ||||||||||||
47 | 31, 64, PKCS5_PBE_keyivgen}, | - | ||||||||||||
48 | - | |||||||||||||
49 | {0x1, 163, -1, 64, 0}, | - | ||||||||||||
50 | {0x1, 780, -1, 4, 0}, | - | ||||||||||||
51 | {0x1, 781, -1, 64, 0}, | - | ||||||||||||
52 | {0x1, 797, -1, 4, 0}, | - | ||||||||||||
53 | {0x1, 798, -1, 675, 0}, | - | ||||||||||||
54 | {0x1, 799, -1, 672, 0}, | - | ||||||||||||
55 | {0x1, 800, -1, 673, 0}, | - | ||||||||||||
56 | {0x1, 801, -1, 674, 0}, | - | ||||||||||||
57 | {0x1, 810, -1, 809, 0}, | - | ||||||||||||
58 | {0x1, 988, -1, | - | ||||||||||||
59 | 982, 0}, | - | ||||||||||||
60 | {0x1, 989, -1, | - | ||||||||||||
61 | 983, 0}, | - | ||||||||||||
62 | {0x1, 1193, -1, 1094, 0}, | - | ||||||||||||
63 | {0x1, 1194, -1, 1095, 0}, | - | ||||||||||||
64 | {0x2, 69, -1, -1, PKCS5_v2_PBKDF2_keyivgen}, | - | ||||||||||||
65 | - | |||||||||||||
66 | {0x2, 973, -1, -1, PKCS5_v2_scrypt_keyivgen} | - | ||||||||||||
67 | - | |||||||||||||
68 | }; | - | ||||||||||||
69 | - | |||||||||||||
70 | int EVP_PBE_CipherInit(ASN1_OBJECT *pbe_obj, const char *pass, int passlen, | - | ||||||||||||
71 | ASN1_TYPE *param, EVP_CIPHER_CTX *ctx, int en_de) | - | ||||||||||||
72 | { | - | ||||||||||||
73 | const EVP_CIPHER *cipher; | - | ||||||||||||
74 | const EVP_MD *md; | - | ||||||||||||
75 | int cipher_nid, md_nid; | - | ||||||||||||
76 | EVP_PBE_KEYGEN *keygen; | - | ||||||||||||
77 | - | |||||||||||||
78 | if (!EVP_PBE_find(0x0, OBJ_obj2nid(pbe_obj),
| 0 | ||||||||||||
79 | &cipher_nid, &md_nid, &keygen)
| 0 | ||||||||||||
80 | char obj_tmp[80]; | - | ||||||||||||
81 | ERR_put_error(6,(116),(121),__FILE__,95); | - | ||||||||||||
82 | if (!pbe_obj
| 0 | ||||||||||||
83 | OPENSSL_strlcpy(obj_tmp, "NULL", sizeof(obj_tmp)); never executed: OPENSSL_strlcpy(obj_tmp, "NULL", sizeof(obj_tmp)); | 0 | ||||||||||||
84 | else | - | ||||||||||||
85 | i2t_ASN1_OBJECT(obj_tmp, sizeof(obj_tmp), pbe_obj); never executed: i2t_ASN1_OBJECT(obj_tmp, sizeof(obj_tmp), pbe_obj); | 0 | ||||||||||||
86 | ERR_add_error_data(2, "TYPE=", obj_tmp); | - | ||||||||||||
87 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
88 | } | - | ||||||||||||
89 | - | |||||||||||||
90 | if (!pass
| 0 | ||||||||||||
91 | passlen = 0; never executed: passlen = 0; | 0 | ||||||||||||
92 | else if (passlen == -1
| 0 | ||||||||||||
93 | passlen = strlen(pass); never executed: passlen = strlen(pass); | 0 | ||||||||||||
94 | - | |||||||||||||
95 | if (cipher_nid == -1
| 0 | ||||||||||||
96 | cipher = never executed: cipher = ((void *)0) ; | 0 | ||||||||||||
97 | ((void *)0) never executed: cipher = ((void *)0) ; | 0 | ||||||||||||
98 | ; never executed: cipher = ((void *)0) ; | 0 | ||||||||||||
99 | else { | - | ||||||||||||
100 | cipher = EVP_get_cipherbyname(OBJ_nid2sn(cipher_nid)); | - | ||||||||||||
101 | if (!cipher
| 0 | ||||||||||||
102 | ERR_put_error(6,(116),(160),__FILE__,114); | - | ||||||||||||
103 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
104 | } | - | ||||||||||||
105 | } never executed: end of block | 0 | ||||||||||||
106 | - | |||||||||||||
107 | if (md_nid == -1
| 0 | ||||||||||||
108 | md = never executed: md = ((void *)0) ; | 0 | ||||||||||||
109 | ((void *)0) never executed: md = ((void *)0) ; | 0 | ||||||||||||
110 | ; never executed: md = ((void *)0) ; | 0 | ||||||||||||
111 | else { | - | ||||||||||||
112 | md = EVP_get_digestbyname(OBJ_nid2sn(md_nid)); | - | ||||||||||||
113 | if (!md
| 0 | ||||||||||||
114 | ERR_put_error(6,(116),(161),__FILE__,124); | - | ||||||||||||
115 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
116 | } | - | ||||||||||||
117 | } never executed: end of block | 0 | ||||||||||||
118 | - | |||||||||||||
119 | if (!keygen(ctx, pass, passlen, param, cipher, md, en_de)
| 0 | ||||||||||||
120 | ERR_put_error(6,(116),(120),__FILE__,130); | - | ||||||||||||
121 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
122 | } | - | ||||||||||||
123 | return never executed: 1;return 1; never executed: return 1; | 0 | ||||||||||||
124 | } | - | ||||||||||||
125 | - | |||||||||||||
126 | static int pbe2_cmp_BSEARCH_CMP_FN(const void *, const void *); static int pbe2_cmp(EVP_PBE_CTL const *, EVP_PBE_CTL const *); static EVP_PBE_CTL * OBJ_bsearch_pbe2(EVP_PBE_CTL *key, EVP_PBE_CTL const *base, int num); | - | ||||||||||||
127 | - | |||||||||||||
128 | static int pbe2_cmp(const EVP_PBE_CTL *pbe1, const EVP_PBE_CTL *pbe2) | - | ||||||||||||
129 | { | - | ||||||||||||
130 | int ret = pbe1->pbe_type - pbe2->pbe_type; | - | ||||||||||||
131 | if (ret
| 20-99 | ||||||||||||
132 | return executed 20 times by 1 test: ret;return ret; Executed by:
executed 20 times by 1 test: return ret; Executed by:
| 20 | ||||||||||||
133 | else | - | ||||||||||||
134 | return executed 99 times by 1 test: pbe1->pbe_nid - pbe2->pbe_nid;return pbe1->pbe_nid - pbe2->pbe_nid; Executed by:
executed 99 times by 1 test: return pbe1->pbe_nid - pbe2->pbe_nid; Executed by:
| 99 | ||||||||||||
135 | } | - | ||||||||||||
136 | - | |||||||||||||
137 | static int pbe2_cmp_BSEARCH_CMP_FN(const void *a_, const void *b_) { EVP_PBE_CTL const *a = a_; EVP_PBE_CTL const *b = b_; return executed 119 times by 1 test: pbe2_cmp(a,b);return pbe2_cmp(a,b); Executed by:
executed 119 times by 1 test: } static EVP_PBE_CTL *OBJ_bsearch_pbe2(EVP_PBE_CTL *key, EVP_PBE_CTL const *base, int num) { returnreturn pbe2_cmp(a,b); Executed by:
executed 29 times by 1 test: (EVP_PBE_CTL *)OBJ_bsearch_(key, base, num, sizeof(EVP_PBE_CTL), pbe2_cmp_BSEARCH_CMP_FN);return (EVP_PBE_CTL *)OBJ_bsearch_(key, base, num, sizeof(EVP_PBE_CTL), pbe2_cmp_BSEARCH_CMP_FN); Executed by:
executed 29 times by 1 test: } extern void dummy_prototype(void);return (EVP_PBE_CTL *)OBJ_bsearch_(key, base, num, sizeof(EVP_PBE_CTL), pbe2_cmp_BSEARCH_CMP_FN); Executed by:
| 29-119 | ||||||||||||
138 | - | |||||||||||||
139 | static int pbe_cmp(const EVP_PBE_CTL *const *a, const EVP_PBE_CTL *const *b) | - | ||||||||||||
140 | { | - | ||||||||||||
141 | int ret = (*a)->pbe_type - (*b)->pbe_type; | - | ||||||||||||
142 | if (ret
| 0 | ||||||||||||
143 | return never executed: ret;return ret; never executed: return ret; | 0 | ||||||||||||
144 | else | - | ||||||||||||
145 | return never executed: (*a)->pbe_nid - (*b)->pbe_nid;return (*a)->pbe_nid - (*b)->pbe_nid; never executed: return (*a)->pbe_nid - (*b)->pbe_nid; | 0 | ||||||||||||
146 | } | - | ||||||||||||
147 | - | |||||||||||||
148 | - | |||||||||||||
149 | - | |||||||||||||
150 | int EVP_PBE_alg_add_type(int pbe_type, int pbe_nid, int cipher_nid, | - | ||||||||||||
151 | int md_nid, EVP_PBE_KEYGEN *keygen) | - | ||||||||||||
152 | { | - | ||||||||||||
153 | EVP_PBE_CTL *pbe_tmp; | - | ||||||||||||
154 | - | |||||||||||||
155 | if (pbe_algs ==
| 0 | ||||||||||||
156 | ((void *)0)
| 0 | ||||||||||||
157 | ) { | - | ||||||||||||
158 | pbe_algs = sk_EVP_PBE_CTL_new(pbe_cmp); | - | ||||||||||||
159 | if (pbe_algs ==
| 0 | ||||||||||||
160 | ((void *)0)
| 0 | ||||||||||||
161 | ) | - | ||||||||||||
162 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
163 | } never executed: end of block | 0 | ||||||||||||
164 | - | |||||||||||||
165 | if ((
| 0 | ||||||||||||
166 | ((void *)0)
| 0 | ||||||||||||
167 | ) | - | ||||||||||||
168 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
169 | - | |||||||||||||
170 | pbe_tmp->pbe_type = pbe_type; | - | ||||||||||||
171 | pbe_tmp->pbe_nid = pbe_nid; | - | ||||||||||||
172 | pbe_tmp->cipher_nid = cipher_nid; | - | ||||||||||||
173 | pbe_tmp->md_nid = md_nid; | - | ||||||||||||
174 | pbe_tmp->keygen = keygen; | - | ||||||||||||
175 | - | |||||||||||||
176 | if (!sk_EVP_PBE_CTL_push(pbe_algs, pbe_tmp)
| 0 | ||||||||||||
177 | CRYPTO_free(pbe_tmp, __FILE__, 181); | - | ||||||||||||
178 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
179 | } | - | ||||||||||||
180 | return never executed: 1;return 1; never executed: return 1; | 0 | ||||||||||||
181 | - | |||||||||||||
182 | err: | - | ||||||||||||
183 | ERR_put_error(6,(160),((1|64)),__FILE__,187); | - | ||||||||||||
184 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
185 | } | - | ||||||||||||
186 | - | |||||||||||||
187 | int EVP_PBE_alg_add(int nid, const EVP_CIPHER *cipher, const EVP_MD *md, | - | ||||||||||||
188 | EVP_PBE_KEYGEN *keygen) | - | ||||||||||||
189 | { | - | ||||||||||||
190 | int cipher_nid, md_nid; | - | ||||||||||||
191 | - | |||||||||||||
192 | if (cipher
| 0 | ||||||||||||
193 | cipher_nid = EVP_CIPHER_nid(cipher); never executed: cipher_nid = EVP_CIPHER_nid(cipher); | 0 | ||||||||||||
194 | else | - | ||||||||||||
195 | cipher_nid = -1; never executed: cipher_nid = -1; | 0 | ||||||||||||
196 | if (md
| 0 | ||||||||||||
197 | md_nid = EVP_MD_type(md); never executed: md_nid = EVP_MD_type(md); | 0 | ||||||||||||
198 | else | - | ||||||||||||
199 | md_nid = -1; never executed: md_nid = -1; | 0 | ||||||||||||
200 | - | |||||||||||||
201 | return never executed: EVP_PBE_alg_add_type(0x0, nid,return EVP_PBE_alg_add_type(0x0, nid, cipher_nid, md_nid, keygen); never executed: return EVP_PBE_alg_add_type(0x0, nid, cipher_nid, md_nid, keygen); | 0 | ||||||||||||
202 | cipher_nid, md_nid, keygen); never executed: return EVP_PBE_alg_add_type(0x0, nid, cipher_nid, md_nid, keygen); | 0 | ||||||||||||
203 | } | - | ||||||||||||
204 | - | |||||||||||||
205 | int EVP_PBE_find(int type, int pbe_nid, | - | ||||||||||||
206 | int *pcnid, int *pmnid, EVP_PBE_KEYGEN **pkeygen) | - | ||||||||||||
207 | { | - | ||||||||||||
208 | EVP_PBE_CTL *pbetmp = | - | ||||||||||||
209 | ((void *)0) | - | ||||||||||||
210 | , pbelu; | - | ||||||||||||
211 | int i; | - | ||||||||||||
212 | if (pbe_nid == 0
| 0-29 | ||||||||||||
213 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
214 | - | |||||||||||||
215 | pbelu.pbe_type = type; | - | ||||||||||||
216 | pbelu.pbe_nid = pbe_nid; | - | ||||||||||||
217 | - | |||||||||||||
218 | if (pbe_algs !=
| 0-29 | ||||||||||||
219 | ((void *)0)
| 0-29 | ||||||||||||
220 | ) { | - | ||||||||||||
221 | i = sk_EVP_PBE_CTL_find(pbe_algs, &pbelu); | - | ||||||||||||
222 | pbetmp = sk_EVP_PBE_CTL_value(pbe_algs, i); | - | ||||||||||||
223 | } never executed: end of block | 0 | ||||||||||||
224 | if (pbetmp ==
| 0-29 | ||||||||||||
225 | ((void *)0)
| 0-29 | ||||||||||||
226 | ) { | - | ||||||||||||
227 | pbetmp = OBJ_bsearch_pbe2(&pbelu, builtin_pbe, (sizeof(builtin_pbe)/sizeof((builtin_pbe)[0]))); | - | ||||||||||||
228 | } executed 29 times by 1 test: end of block Executed by:
| 29 | ||||||||||||
229 | if (pbetmp ==
| 0-29 | ||||||||||||
230 | ((void *)0)
| 0-29 | ||||||||||||
231 | ) | - | ||||||||||||
232 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
233 | if (pcnid
| 0-29 | ||||||||||||
234 | * never executed: pcnid = pbetmp->cipher_nid;*pcnid = pbetmp->cipher_nid; never executed: *pcnid = pbetmp->cipher_nid; | 0 | ||||||||||||
235 | if (pmnid
| 0-29 | ||||||||||||
236 | * never executed: pmnid = pbetmp->md_nid;*pmnid = pbetmp->md_nid; never executed: *pmnid = pbetmp->md_nid; | 0 | ||||||||||||
237 | if (pkeygen
| 0-29 | ||||||||||||
238 | * never executed: pkeygen = pbetmp->keygen;*pkeygen = pbetmp->keygen; never executed: *pkeygen = pbetmp->keygen; | 0 | ||||||||||||
239 | return executed 29 times by 1 test: 1;return 1; Executed by:
executed 29 times by 1 test: return 1; Executed by:
| 29 | ||||||||||||
240 | } | - | ||||||||||||
241 | - | |||||||||||||
242 | static void free_evp_pbe_ctl(EVP_PBE_CTL *pbe) | - | ||||||||||||
243 | { | - | ||||||||||||
244 | CRYPTO_free(pbe, __FILE__, 240); | - | ||||||||||||
245 | } never executed: end of block | 0 | ||||||||||||
246 | - | |||||||||||||
247 | void EVP_PBE_cleanup(void) | - | ||||||||||||
248 | { | - | ||||||||||||
249 | sk_EVP_PBE_CTL_pop_free(pbe_algs, free_evp_pbe_ctl); | - | ||||||||||||
250 | pbe_algs = | - | ||||||||||||
251 | ((void *)0) | - | ||||||||||||
252 | ; | - | ||||||||||||
253 | } executed 2076 times by 12 tests: end of block Executed by:
| 2076 | ||||||||||||
254 | - | |||||||||||||
255 | int EVP_PBE_get(int *ptype, int *ppbe_nid, size_t num) | - | ||||||||||||
256 | { | - | ||||||||||||
257 | const EVP_PBE_CTL *tpbe; | - | ||||||||||||
258 | - | |||||||||||||
259 | if (num >= (sizeof(builtin_pbe)/sizeof((builtin_pbe)[0]))
| 1-29 | ||||||||||||
260 | return executed 1 time by 1 test: 0;return 0; Executed by:
executed 1 time by 1 test: return 0; Executed by:
| 1 | ||||||||||||
261 | - | |||||||||||||
262 | tpbe = builtin_pbe + num; | - | ||||||||||||
263 | if (ptype
| 0-29 | ||||||||||||
264 | * executed 29 times by 1 test: ptype = tpbe->pbe_type;*ptype = tpbe->pbe_type; Executed by:
executed 29 times by 1 test: *ptype = tpbe->pbe_type; Executed by:
| 29 | ||||||||||||
265 | if (ppbe_nid
| 0-29 | ||||||||||||
266 | * executed 29 times by 1 test: ppbe_nid = tpbe->pbe_nid;*ppbe_nid = tpbe->pbe_nid; Executed by:
executed 29 times by 1 test: *ppbe_nid = tpbe->pbe_nid; Executed by:
| 29 | ||||||||||||
267 | return executed 29 times by 1 test: 1;return 1; Executed by:
executed 29 times by 1 test: return 1; Executed by:
| 29 | ||||||||||||
268 | } | - | ||||||||||||
Switch to Source code | Preprocessed file |