Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/cms/cms_enc.c |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||
2 | - | |||||||||||||
3 | - | |||||||||||||
4 | - | |||||||||||||
5 | - | |||||||||||||
6 | - | |||||||||||||
7 | BIO *cms_EncryptedContent_init_bio(CMS_EncryptedContentInfo *ec) | - | ||||||||||||
8 | { | - | ||||||||||||
9 | BIO *b; | - | ||||||||||||
10 | EVP_CIPHER_CTX *ctx; | - | ||||||||||||
11 | const EVP_CIPHER *ciph; | - | ||||||||||||
12 | X509_ALGOR *calg = ec->contentEncryptionAlgorithm; | - | ||||||||||||
13 | unsigned char iv[16], *piv = | - | ||||||||||||
14 | ((void *)0) | - | ||||||||||||
15 | ; | - | ||||||||||||
16 | unsigned char *tkey = | - | ||||||||||||
17 | ((void *)0) | - | ||||||||||||
18 | ; | - | ||||||||||||
19 | size_t tkeylen = 0; | - | ||||||||||||
20 | - | |||||||||||||
21 | int ok = 0; | - | ||||||||||||
22 | - | |||||||||||||
23 | int enc, keep_key = 0; | - | ||||||||||||
24 | - | |||||||||||||
25 | enc = ec->cipher
| 24 | ||||||||||||
26 | - | |||||||||||||
27 | b = BIO_new(BIO_f_cipher()); | - | ||||||||||||
28 | if (b ==
| 0-48 | ||||||||||||
29 | ((void *)0)
| 0-48 | ||||||||||||
30 | ) { | - | ||||||||||||
31 | ERR_put_error(46,(120),((1|64)),__FILE__,41); | - | ||||||||||||
32 | return never executed: return ((void *)0) ; never executed: return ((void *)0) ; | 0 | ||||||||||||
33 | ((void *)0) never executed: return ((void *)0) ; | 0 | ||||||||||||
34 | ; never executed: return ((void *)0) ; | 0 | ||||||||||||
35 | } | - | ||||||||||||
36 | - | |||||||||||||
37 | BIO_ctrl(b,129,0, (char *)(&ctx)); | - | ||||||||||||
38 | - | |||||||||||||
39 | if (enc
| 24 | ||||||||||||
40 | ciph = ec->cipher; | - | ||||||||||||
41 | - | |||||||||||||
42 | - | |||||||||||||
43 | - | |||||||||||||
44 | if (ec->key
| 4-20 | ||||||||||||
45 | ec->cipher = executed 4 times by 1 test: ec->cipher = ((void *)0) ; Executed by:
| 4 | ||||||||||||
46 | ((void *)0) executed 4 times by 1 test: ec->cipher = ((void *)0) ; Executed by:
| 4 | ||||||||||||
47 | ; executed 4 times by 1 test: ec->cipher = ((void *)0) ; Executed by:
| 4 | ||||||||||||
48 | } executed 24 times by 1 test: else {end of block Executed by:
| 24 | ||||||||||||
49 | ciph = EVP_get_cipherbyname(OBJ_nid2sn(OBJ_obj2nid(calg->algorithm))); | - | ||||||||||||
50 | - | |||||||||||||
51 | if (!ciph
| 0-24 | ||||||||||||
52 | ERR_put_error(46,(120),(148),__FILE__,58); | - | ||||||||||||
53 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
54 | } | - | ||||||||||||
55 | } executed 24 times by 1 test: end of block Executed by:
| 24 | ||||||||||||
56 | - | |||||||||||||
57 | if (EVP_CipherInit_ex(ctx, ciph,
| 0-48 | ||||||||||||
58 | ((void *)0)
| 0-48 | ||||||||||||
59 | ,
| 0-48 | ||||||||||||
60 | ((void *)0)
| 0-48 | ||||||||||||
61 | ,
| 0-48 | ||||||||||||
62 | ((void *)0)
| 0-48 | ||||||||||||
63 | , enc) <= 0
| 0-48 | ||||||||||||
64 | ERR_put_error(46,(120),(101),__FILE__,65) | - | ||||||||||||
65 | ; | - | ||||||||||||
66 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
67 | } | - | ||||||||||||
68 | - | |||||||||||||
69 | if (enc
| 24 | ||||||||||||
70 | int ivlen; | - | ||||||||||||
71 | calg->algorithm = OBJ_nid2obj(EVP_CIPHER_type(EVP_CIPHER_CTX_cipher(ctx))); | - | ||||||||||||
72 | - | |||||||||||||
73 | ivlen = EVP_CIPHER_CTX_iv_length(ctx); | - | ||||||||||||
74 | if (ivlen > 0
| 0-24 | ||||||||||||
75 | if (RAND_bytes(iv, ivlen) <= 0
| 0-24 | ||||||||||||
76 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
77 | piv = iv; | - | ||||||||||||
78 | } executed 24 times by 1 test: end of block Executed by:
| 24 | ||||||||||||
79 | } executed 24 times by 1 test: else if (EVP_CIPHER_asn1_to_param(ctx, calg->parameter) <= 0end of block Executed by:
| 0-24 | ||||||||||||
80 | ERR_put_error(46,(120),(102),__FILE__,81) | - | ||||||||||||
81 | ; | - | ||||||||||||
82 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
83 | } | - | ||||||||||||
84 | tkeylen = EVP_CIPHER_CTX_key_length(ctx); | - | ||||||||||||
85 | - | |||||||||||||
86 | if (!enc
| 4-24 | ||||||||||||
87 | tkey = CRYPTO_malloc(tkeylen, __FILE__, 87); | - | ||||||||||||
88 | if (tkey ==
| 0-44 | ||||||||||||
89 | ((void *)0)
| 0-44 | ||||||||||||
90 | ) { | - | ||||||||||||
91 | ERR_put_error(46,(120),((1|64)),__FILE__,89); | - | ||||||||||||
92 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
93 | } | - | ||||||||||||
94 | if (EVP_CIPHER_CTX_rand_key(ctx, tkey) <= 0
| 0-44 | ||||||||||||
95 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
96 | } executed 44 times by 1 test: end of block Executed by:
| 44 | ||||||||||||
97 | - | |||||||||||||
98 | if (!ec->key
| 20-28 | ||||||||||||
99 | ec->key = tkey; | - | ||||||||||||
100 | ec->keylen = tkeylen; | - | ||||||||||||
101 | tkey = | - | ||||||||||||
102 | ((void *)0) | - | ||||||||||||
103 | ; | - | ||||||||||||
104 | if (enc
| 0-20 | ||||||||||||
105 | keep_key = 1; executed 20 times by 1 test: keep_key = 1; Executed by:
| 20 | ||||||||||||
106 | else | - | ||||||||||||
107 | ERR_clear_error(); never executed: ERR_clear_error(); | 0 | ||||||||||||
108 | - | |||||||||||||
109 | } | - | ||||||||||||
110 | - | |||||||||||||
111 | if (ec->keylen != tkeylen
| 2-46 | ||||||||||||
112 | - | |||||||||||||
113 | if (EVP_CIPHER_CTX_set_key_length(ctx, ec->keylen) <= 0
| 0-2 | ||||||||||||
114 | - | |||||||||||||
115 | - | |||||||||||||
116 | - | |||||||||||||
117 | - | |||||||||||||
118 | if (enc
| 0 | ||||||||||||
119 | ERR_put_error(46,(120),(118),__FILE__,116) | - | ||||||||||||
120 | ; | - | ||||||||||||
121 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
122 | } else { | - | ||||||||||||
123 | - | |||||||||||||
124 | CRYPTO_clear_free(ec->key, ec->keylen, __FILE__, 120); | - | ||||||||||||
125 | ec->key = tkey; | - | ||||||||||||
126 | ec->keylen = tkeylen; | - | ||||||||||||
127 | tkey = | - | ||||||||||||
128 | ((void *)0) | - | ||||||||||||
129 | ; | - | ||||||||||||
130 | ERR_clear_error(); | - | ||||||||||||
131 | } never executed: end of block | 0 | ||||||||||||
132 | } | - | ||||||||||||
133 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||
134 | - | |||||||||||||
135 | if (EVP_CipherInit_ex(ctx,
| 0-48 | ||||||||||||
136 | ((void *)0)
| 0-48 | ||||||||||||
137 | ,
| 0-48 | ||||||||||||
138 | ((void *)0)
| 0-48 | ||||||||||||
139 | , ec->key, piv, enc) <= 0
| 0-48 | ||||||||||||
140 | ERR_put_error(46,(120),(101),__FILE__,131) | - | ||||||||||||
141 | ; | - | ||||||||||||
142 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
143 | } | - | ||||||||||||
144 | if (enc
| 24 | ||||||||||||
145 | calg->parameter = ASN1_TYPE_new(); | - | ||||||||||||
146 | if (calg->parameter ==
| 0-24 | ||||||||||||
147 | ((void *)0)
| 0-24 | ||||||||||||
148 | ) { | - | ||||||||||||
149 | ERR_put_error(46,(120),((1|64)),__FILE__,137); | - | ||||||||||||
150 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
151 | } | - | ||||||||||||
152 | if (EVP_CIPHER_param_to_asn1(ctx, calg->parameter) <= 0
| 0-24 | ||||||||||||
153 | ERR_put_error(46,(120),(102),__FILE__,142) | - | ||||||||||||
154 | ; | - | ||||||||||||
155 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
156 | } | - | ||||||||||||
157 | - | |||||||||||||
158 | if (calg->parameter->type == -1
| 0-24 | ||||||||||||
159 | ASN1_TYPE_free(calg->parameter); | - | ||||||||||||
160 | calg->parameter = | - | ||||||||||||
161 | ((void *)0) | - | ||||||||||||
162 | ; | - | ||||||||||||
163 | } never executed: end of block | 0 | ||||||||||||
164 | } executed 24 times by 1 test: end of block Executed by:
| 24 | ||||||||||||
165 | ok = 1; | - | ||||||||||||
166 | - | |||||||||||||
167 | err: code before this statement executed 48 times by 1 test: err: Executed by:
| 48 | ||||||||||||
168 | if (!keep_key
| 0-28 | ||||||||||||
169 | CRYPTO_clear_free(ec->key, ec->keylen, __FILE__, 155); | - | ||||||||||||
170 | ec->key = | - | ||||||||||||
171 | ((void *)0) | - | ||||||||||||
172 | ; | - | ||||||||||||
173 | } executed 28 times by 1 test: end of block Executed by:
| 28 | ||||||||||||
174 | CRYPTO_clear_free(tkey, tkeylen, __FILE__, 158); | - | ||||||||||||
175 | if (ok
| 0-48 | ||||||||||||
176 | return executed 48 times by 1 test: b;return b; Executed by:
executed 48 times by 1 test: return b; Executed by:
| 48 | ||||||||||||
177 | BIO_free(b); | - | ||||||||||||
178 | return never executed: return ((void *)0) ; never executed: return ((void *)0) ; | 0 | ||||||||||||
179 | ((void *)0) never executed: return ((void *)0) ; | 0 | ||||||||||||
180 | ; never executed: return ((void *)0) ; | 0 | ||||||||||||
181 | } | - | ||||||||||||
182 | - | |||||||||||||
183 | int cms_EncryptedContent_init(CMS_EncryptedContentInfo *ec, | - | ||||||||||||
184 | const EVP_CIPHER *cipher, | - | ||||||||||||
185 | const unsigned char *key, size_t keylen) | - | ||||||||||||
186 | { | - | ||||||||||||
187 | ec->cipher = cipher; | - | ||||||||||||
188 | if (key
| 8-20 | ||||||||||||
189 | if ((
| 0-8 | ||||||||||||
190 | ((void *)0)
| 0-8 | ||||||||||||
191 | ) { | - | ||||||||||||
192 | ERR_put_error(46,(179),((1|64)),__FILE__,172); | - | ||||||||||||
193 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
194 | } | - | ||||||||||||
195 | memcpy(ec->key, key, keylen); | - | ||||||||||||
196 | } executed 8 times by 1 test: end of block Executed by:
| 8 | ||||||||||||
197 | ec->keylen = keylen; | - | ||||||||||||
198 | if (cipher
| 4-24 | ||||||||||||
199 | ec->contentType = OBJ_nid2obj(21); executed 24 times by 1 test: ec->contentType = OBJ_nid2obj(21); Executed by:
| 24 | ||||||||||||
200 | return executed 28 times by 1 test: 1;return 1; Executed by:
executed 28 times by 1 test: return 1; Executed by:
| 28 | ||||||||||||
201 | } | - | ||||||||||||
202 | - | |||||||||||||
203 | int CMS_EncryptedData_set1_key(CMS_ContentInfo *cms, const EVP_CIPHER *ciph, | - | ||||||||||||
204 | const unsigned char *key, size_t keylen) | - | ||||||||||||
205 | { | - | ||||||||||||
206 | CMS_EncryptedContentInfo *ec; | - | ||||||||||||
207 | if (!key
| 0-8 | ||||||||||||
208 | ERR_put_error(46,(123),(130),__FILE__,188); | - | ||||||||||||
209 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
210 | } | - | ||||||||||||
211 | if (ciph
| 4 | ||||||||||||
212 | cms->d.encryptedData = (CMS_EncryptedData *)ASN1_item_new((&(CMS_EncryptedData_it))); | - | ||||||||||||
213 | if (!cms->d.encryptedData
| 0-4 | ||||||||||||
214 | ERR_put_error(46,(123),((1|64)),__FILE__,194); | - | ||||||||||||
215 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
216 | } | - | ||||||||||||
217 | cms->contentType = OBJ_nid2obj(26); | - | ||||||||||||
218 | cms->d.encryptedData->version = 0; | - | ||||||||||||
219 | } executed 4 times by 1 test: else if (OBJ_obj2nid(cms->contentType) != 26end of block Executed by:
| 0-4 | ||||||||||||
220 | ERR_put_error(46,(123),(122),__FILE__,200); | - | ||||||||||||
221 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
222 | } | - | ||||||||||||
223 | ec = cms->d.encryptedData->encryptedContentInfo; | - | ||||||||||||
224 | return executed 8 times by 1 test: cms_EncryptedContent_init(ec, ciph, key, keylen);return cms_EncryptedContent_init(ec, ciph, key, keylen); Executed by:
executed 8 times by 1 test: return cms_EncryptedContent_init(ec, ciph, key, keylen); Executed by:
| 8 | ||||||||||||
225 | } | - | ||||||||||||
226 | - | |||||||||||||
227 | BIO *cms_EncryptedData_init_bio(CMS_ContentInfo *cms) | - | ||||||||||||
228 | { | - | ||||||||||||
229 | CMS_EncryptedData *enc = cms->d.encryptedData; | - | ||||||||||||
230 | if (enc->encryptedContentInfo->cipher
| 0-4 | ||||||||||||
231 | enc->version = 2; never executed: enc->version = 2; | 0 | ||||||||||||
232 | return executed 8 times by 1 test: cms_EncryptedContent_init_bio(enc->encryptedContentInfo);return cms_EncryptedContent_init_bio(enc->encryptedContentInfo); Executed by:
executed 8 times by 1 test: return cms_EncryptedContent_init_bio(enc->encryptedContentInfo); Executed by:
| 8 | ||||||||||||
233 | } | - | ||||||||||||
Switch to Source code | Preprocessed file |