Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/libressl/src/crypto/evp/evp_enc.c |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /* $OpenBSD: evp_enc.c,v 1.39 2018/04/14 07:09:21 tb Exp $ */ | - | ||||||||||||||||||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | - | ||||||||||||||||||
3 | * All rights reserved. | - | ||||||||||||||||||
4 | * | - | ||||||||||||||||||
5 | * This package is an SSL implementation written | - | ||||||||||||||||||
6 | * by Eric Young (eay@cryptsoft.com). | - | ||||||||||||||||||
7 | * The implementation was written so as to conform with Netscapes SSL. | - | ||||||||||||||||||
8 | * | - | ||||||||||||||||||
9 | * This library is free for commercial and non-commercial use as long as | - | ||||||||||||||||||
10 | * the following conditions are aheared to. The following conditions | - | ||||||||||||||||||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | - | ||||||||||||||||||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | - | ||||||||||||||||||
13 | * included with this distribution is covered by the same copyright terms | - | ||||||||||||||||||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | - | ||||||||||||||||||
15 | * | - | ||||||||||||||||||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | - | ||||||||||||||||||
17 | * the code are not to be removed. | - | ||||||||||||||||||
18 | * If this package is used in a product, Eric Young should be given attribution | - | ||||||||||||||||||
19 | * as the author of the parts of the library used. | - | ||||||||||||||||||
20 | * This can be in the form of a textual message at program startup or | - | ||||||||||||||||||
21 | * in documentation (online or textual) provided with the package. | - | ||||||||||||||||||
22 | * | - | ||||||||||||||||||
23 | * Redistribution and use in source and binary forms, with or without | - | ||||||||||||||||||
24 | * modification, are permitted provided that the following conditions | - | ||||||||||||||||||
25 | * are met: | - | ||||||||||||||||||
26 | * 1. Redistributions of source code must retain the copyright | - | ||||||||||||||||||
27 | * notice, this list of conditions and the following disclaimer. | - | ||||||||||||||||||
28 | * 2. Redistributions in binary form must reproduce the above copyright | - | ||||||||||||||||||
29 | * notice, this list of conditions and the following disclaimer in the | - | ||||||||||||||||||
30 | * documentation and/or other materials provided with the distribution. | - | ||||||||||||||||||
31 | * 3. All advertising materials mentioning features or use of this software | - | ||||||||||||||||||
32 | * must display the following acknowledgement: | - | ||||||||||||||||||
33 | * "This product includes cryptographic software written by | - | ||||||||||||||||||
34 | * Eric Young (eay@cryptsoft.com)" | - | ||||||||||||||||||
35 | * The word 'cryptographic' can be left out if the rouines from the library | - | ||||||||||||||||||
36 | * being used are not cryptographic related :-). | - | ||||||||||||||||||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | - | ||||||||||||||||||
38 | * the apps directory (application code) you must include an acknowledgement: | - | ||||||||||||||||||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | - | ||||||||||||||||||
40 | * | - | ||||||||||||||||||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | - | ||||||||||||||||||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | - | ||||||||||||||||||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | - | ||||||||||||||||||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | - | ||||||||||||||||||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | - | ||||||||||||||||||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | - | ||||||||||||||||||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | - | ||||||||||||||||||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | - | ||||||||||||||||||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | - | ||||||||||||||||||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | - | ||||||||||||||||||
51 | * SUCH DAMAGE. | - | ||||||||||||||||||
52 | * | - | ||||||||||||||||||
53 | * The licence and distribution terms for any publically available version or | - | ||||||||||||||||||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | - | ||||||||||||||||||
55 | * copied and put under another distribution licence | - | ||||||||||||||||||
56 | * [including the GNU Public Licence.] | - | ||||||||||||||||||
57 | */ | - | ||||||||||||||||||
58 | - | |||||||||||||||||||
59 | #include <stdio.h> | - | ||||||||||||||||||
60 | #include <stdlib.h> | - | ||||||||||||||||||
61 | #include <string.h> | - | ||||||||||||||||||
62 | - | |||||||||||||||||||
63 | #include <sys/types.h> | - | ||||||||||||||||||
64 | - | |||||||||||||||||||
65 | #include <openssl/opensslconf.h> | - | ||||||||||||||||||
66 | - | |||||||||||||||||||
67 | #include <openssl/err.h> | - | ||||||||||||||||||
68 | #include <openssl/evp.h> | - | ||||||||||||||||||
69 | - | |||||||||||||||||||
70 | #ifndef OPENSSL_NO_ENGINE | - | ||||||||||||||||||
71 | #include <openssl/engine.h> | - | ||||||||||||||||||
72 | #endif | - | ||||||||||||||||||
73 | - | |||||||||||||||||||
74 | #include "evp_locl.h" | - | ||||||||||||||||||
75 | - | |||||||||||||||||||
76 | #define M_do_cipher(ctx, out, in, inl) ctx->cipher->do_cipher(ctx, out, in, inl) | - | ||||||||||||||||||
77 | - | |||||||||||||||||||
78 | int | - | ||||||||||||||||||
79 | EVP_CipherInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, | - | ||||||||||||||||||
80 | const unsigned char *key, const unsigned char *iv, int enc) | - | ||||||||||||||||||
81 | { | - | ||||||||||||||||||
82 | if (cipher)
| 0 | ||||||||||||||||||
83 | EVP_CIPHER_CTX_init(ctx); never executed: EVP_CIPHER_CTX_init(ctx); | 0 | ||||||||||||||||||
84 | return EVP_CipherInit_ex(ctx, cipher, NULL, key, iv, enc); never executed: return EVP_CipherInit_ex(ctx, cipher, ((void *)0) , key, iv, enc); | 0 | ||||||||||||||||||
85 | } | - | ||||||||||||||||||
86 | - | |||||||||||||||||||
87 | int | - | ||||||||||||||||||
88 | EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *impl, | - | ||||||||||||||||||
89 | const unsigned char *key, const unsigned char *iv, int enc) | - | ||||||||||||||||||
90 | { | - | ||||||||||||||||||
91 | if (enc == -1)
| 0-878 | ||||||||||||||||||
92 | enc = ctx->encrypt; never executed: enc = ctx->encrypt; | 0 | ||||||||||||||||||
93 | else { | - | ||||||||||||||||||
94 | if (enc)
| 392-486 | ||||||||||||||||||
95 | enc = 1; executed 486 times by 5 tests: enc = 1; Executed by:
| 486 | ||||||||||||||||||
96 | ctx->encrypt = enc; | - | ||||||||||||||||||
97 | } executed 878 times by 5 tests: end of block Executed by:
| 878 | ||||||||||||||||||
98 | #ifndef OPENSSL_NO_ENGINE | - | ||||||||||||||||||
99 | /* Whether it's nice or not, "Inits" can be used on "Final"'d contexts | - | ||||||||||||||||||
100 | * so this context may already have an ENGINE! Try to avoid releasing | - | ||||||||||||||||||
101 | * the previous handle, re-querying for an ENGINE, and having a | - | ||||||||||||||||||
102 | * reinitialisation, when it may all be unecessary. */ | - | ||||||||||||||||||
103 | if (ctx->engine && ctx->cipher &&
| 0-878 | ||||||||||||||||||
104 | (!cipher || (cipher && (cipher->nid == ctx->cipher->nid))))
| 0 | ||||||||||||||||||
105 | goto skip_to_init; never executed: goto skip_to_init; | 0 | ||||||||||||||||||
106 | #endif | - | ||||||||||||||||||
107 | if (cipher) {
| 198-680 | ||||||||||||||||||
108 | /* Ensure a context left lying around from last time is cleared | - | ||||||||||||||||||
109 | * (the previous check attempted to avoid this if the same | - | ||||||||||||||||||
110 | * ENGINE and EVP_CIPHER could be used). */ | - | ||||||||||||||||||
111 | if (ctx->cipher) {
| 66-614 | ||||||||||||||||||
112 | unsigned long flags = ctx->flags; | - | ||||||||||||||||||
113 | EVP_CIPHER_CTX_cleanup(ctx); | - | ||||||||||||||||||
114 | /* Restore encrypt and flags */ | - | ||||||||||||||||||
115 | ctx->encrypt = enc; | - | ||||||||||||||||||
116 | ctx->flags = flags; | - | ||||||||||||||||||
117 | } executed 66 times by 1 test: end of block Executed by:
| 66 | ||||||||||||||||||
118 | #ifndef OPENSSL_NO_ENGINE | - | ||||||||||||||||||
119 | if (impl) {
| 0-680 | ||||||||||||||||||
120 | if (!ENGINE_init(impl)) {
| 0 | ||||||||||||||||||
121 | EVPerror(EVP_R_INITIALIZATION_ERROR); | - | ||||||||||||||||||
122 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
123 | } | - | ||||||||||||||||||
124 | } else never executed: end of block | 0 | ||||||||||||||||||
125 | /* Ask if an ENGINE is reserved for this job */ | - | ||||||||||||||||||
126 | impl = ENGINE_get_cipher_engine(cipher->nid); executed 680 times by 5 tests: impl = ENGINE_get_cipher_engine(cipher->nid); Executed by:
| 680 | ||||||||||||||||||
127 | if (impl) {
| 0-680 | ||||||||||||||||||
128 | /* There's an ENGINE for this job ... (apparently) */ | - | ||||||||||||||||||
129 | const EVP_CIPHER *c = | - | ||||||||||||||||||
130 | ENGINE_get_cipher(impl, cipher->nid); | - | ||||||||||||||||||
131 | if (!c) {
| 0 | ||||||||||||||||||
132 | EVPerror(EVP_R_INITIALIZATION_ERROR); | - | ||||||||||||||||||
133 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
134 | } | - | ||||||||||||||||||
135 | /* We'll use the ENGINE's private cipher definition */ | - | ||||||||||||||||||
136 | cipher = c; | - | ||||||||||||||||||
137 | /* Store the ENGINE functional reference so we know | - | ||||||||||||||||||
138 | * 'cipher' came from an ENGINE and we need to release | - | ||||||||||||||||||
139 | * it when done. */ | - | ||||||||||||||||||
140 | ctx->engine = impl; | - | ||||||||||||||||||
141 | } else never executed: end of block | 0 | ||||||||||||||||||
142 | ctx->engine = NULL; executed 680 times by 5 tests: ctx->engine = ((void *)0) ; Executed by:
| 680 | ||||||||||||||||||
143 | #endif | - | ||||||||||||||||||
144 | - | |||||||||||||||||||
145 | ctx->cipher = cipher; | - | ||||||||||||||||||
146 | if (ctx->cipher->ctx_size) {
| 12-668 | ||||||||||||||||||
147 | ctx->cipher_data = malloc(ctx->cipher->ctx_size); | - | ||||||||||||||||||
148 | if (!ctx->cipher_data) {
| 0-668 | ||||||||||||||||||
149 | EVPerror(ERR_R_MALLOC_FAILURE); | - | ||||||||||||||||||
150 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
151 | } | - | ||||||||||||||||||
152 | } else { executed 668 times by 5 tests: end of block Executed by:
| 668 | ||||||||||||||||||
153 | ctx->cipher_data = NULL; | - | ||||||||||||||||||
154 | } executed 12 times by 1 test: end of block Executed by:
| 12 | ||||||||||||||||||
155 | ctx->key_len = cipher->key_len; | - | ||||||||||||||||||
156 | ctx->flags = 0; | - | ||||||||||||||||||
157 | if (ctx->cipher->flags & EVP_CIPH_CTRL_INIT) {
| 36-644 | ||||||||||||||||||
158 | if (!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_INIT, 0, NULL)) {
| 0-36 | ||||||||||||||||||
159 | EVPerror(EVP_R_INITIALIZATION_ERROR); | - | ||||||||||||||||||
160 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
161 | } | - | ||||||||||||||||||
162 | } executed 36 times by 2 tests: end of block Executed by:
| 36 | ||||||||||||||||||
163 | } else if (!ctx->cipher) { executed 680 times by 5 tests: end of block Executed by:
| 0-680 | ||||||||||||||||||
164 | EVPerror(EVP_R_NO_CIPHER_SET); | - | ||||||||||||||||||
165 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
166 | } | - | ||||||||||||||||||
167 | #ifndef OPENSSL_NO_ENGINE | - | ||||||||||||||||||
168 | skip_to_init: code before this statement executed 878 times by 5 tests: skip_to_init: Executed by:
| 878 | ||||||||||||||||||
169 | #endif | - | ||||||||||||||||||
170 | /* we assume block size is a power of 2 in *cryptUpdate */ | - | ||||||||||||||||||
171 | if (ctx->cipher->block_size != 1 &&
| 361-517 | ||||||||||||||||||
172 | ctx->cipher->block_size != 8 &&
| 154-363 | ||||||||||||||||||
173 | ctx->cipher->block_size != 16) {
| 0-363 | ||||||||||||||||||
174 | EVPerror(EVP_R_BAD_BLOCK_LENGTH); | - | ||||||||||||||||||
175 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
176 | } | - | ||||||||||||||||||
177 | - | |||||||||||||||||||
178 | if (!(EVP_CIPHER_CTX_flags(ctx) & EVP_CIPH_CUSTOM_IV)) {
| 0-878 | ||||||||||||||||||
179 | switch (EVP_CIPHER_CTX_mode(ctx)) { | - | ||||||||||||||||||
180 | - | |||||||||||||||||||
181 | case EVP_CIPH_STREAM_CIPHER: executed 48 times by 3 tests: case 0x0: Executed by:
| 48 | ||||||||||||||||||
182 | case EVP_CIPH_ECB_MODE: executed 150 times by 3 tests: case 0x1: Executed by:
| 150 | ||||||||||||||||||
183 | break; executed 198 times by 4 tests: break; Executed by:
| 198 | ||||||||||||||||||
184 | - | |||||||||||||||||||
185 | case EVP_CIPH_CFB_MODE: executed 181 times by 3 tests: case 0x3: Executed by:
| 181 | ||||||||||||||||||
186 | case EVP_CIPH_OFB_MODE: executed 123 times by 3 tests: case 0x4: Executed by:
| 123 | ||||||||||||||||||
187 | - | |||||||||||||||||||
188 | ctx->num = 0; | - | ||||||||||||||||||
189 | /* fall-through */ | - | ||||||||||||||||||
190 | - | |||||||||||||||||||
191 | case EVP_CIPH_CBC_MODE: code before this statement executed 304 times by 3 tests: case 0x2: Executed by:
executed 367 times by 4 tests: case 0x2: Executed by:
| 304-367 | ||||||||||||||||||
192 | - | |||||||||||||||||||
193 | if ((size_t)EVP_CIPHER_CTX_iv_length(ctx) >
| 0-671 | ||||||||||||||||||
194 | sizeof(ctx->iv)) {
| 0-671 | ||||||||||||||||||
195 | EVPerror(EVP_R_IV_TOO_LARGE); | - | ||||||||||||||||||
196 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
197 | } | - | ||||||||||||||||||
198 | if (iv)
| 155-516 | ||||||||||||||||||
199 | memcpy(ctx->oiv, iv, executed 516 times by 5 tests: memcpy(ctx->oiv, iv, EVP_CIPHER_CTX_iv_length(ctx)); Executed by:
| 516 | ||||||||||||||||||
200 | EVP_CIPHER_CTX_iv_length(ctx)); executed 516 times by 5 tests: memcpy(ctx->oiv, iv, EVP_CIPHER_CTX_iv_length(ctx)); Executed by:
| 516 | ||||||||||||||||||
201 | memcpy(ctx->iv, ctx->oiv, | - | ||||||||||||||||||
202 | EVP_CIPHER_CTX_iv_length(ctx)); | - | ||||||||||||||||||
203 | break; executed 671 times by 5 tests: break; Executed by:
| 671 | ||||||||||||||||||
204 | - | |||||||||||||||||||
205 | case EVP_CIPH_CTR_MODE: executed 9 times by 1 test: case 0x5: Executed by:
| 9 | ||||||||||||||||||
206 | ctx->num = 0; | - | ||||||||||||||||||
207 | /* Don't reuse IV for CTR mode */ | - | ||||||||||||||||||
208 | if (iv)
| 0-9 | ||||||||||||||||||
209 | memcpy(ctx->iv, iv, executed 9 times by 1 test: memcpy(ctx->iv, iv, EVP_CIPHER_CTX_iv_length(ctx)); Executed by:
| 9 | ||||||||||||||||||
210 | EVP_CIPHER_CTX_iv_length(ctx)); executed 9 times by 1 test: memcpy(ctx->iv, iv, EVP_CIPHER_CTX_iv_length(ctx)); Executed by:
| 9 | ||||||||||||||||||
211 | break; executed 9 times by 1 test: break; Executed by:
| 9 | ||||||||||||||||||
212 | - | |||||||||||||||||||
213 | default: never executed: default: | 0 | ||||||||||||||||||
214 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
215 | break; dead code: break; | - | ||||||||||||||||||
216 | } | - | ||||||||||||||||||
217 | } | - | ||||||||||||||||||
218 | - | |||||||||||||||||||
219 | if (key || (ctx->cipher->flags & EVP_CIPH_ALWAYS_CALL_INIT)) {
| 0-680 | ||||||||||||||||||
220 | if (!ctx->cipher->init(ctx, key, iv, enc))
| 0-680 | ||||||||||||||||||
221 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
222 | } executed 680 times by 5 tests: end of block Executed by:
| 680 | ||||||||||||||||||
223 | ctx->buf_len = 0; | - | ||||||||||||||||||
224 | ctx->final_used = 0; | - | ||||||||||||||||||
225 | ctx->block_mask = ctx->cipher->block_size - 1; | - | ||||||||||||||||||
226 | return 1; executed 878 times by 5 tests: return 1; Executed by:
| 878 | ||||||||||||||||||
227 | } | - | ||||||||||||||||||
228 | - | |||||||||||||||||||
229 | int | - | ||||||||||||||||||
230 | EVP_CipherUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl, | - | ||||||||||||||||||
231 | const unsigned char *in, int inl) | - | ||||||||||||||||||
232 | { | - | ||||||||||||||||||
233 | if (ctx->encrypt)
| 99 | ||||||||||||||||||
234 | return EVP_EncryptUpdate(ctx, out, outl, in, inl); executed 99 times by 2 tests: return EVP_EncryptUpdate(ctx, out, outl, in, inl); Executed by:
| 99 | ||||||||||||||||||
235 | else | - | ||||||||||||||||||
236 | return EVP_DecryptUpdate(ctx, out, outl, in, inl); executed 99 times by 2 tests: return EVP_DecryptUpdate(ctx, out, outl, in, inl); Executed by:
| 99 | ||||||||||||||||||
237 | } | - | ||||||||||||||||||
238 | - | |||||||||||||||||||
239 | int | - | ||||||||||||||||||
240 | EVP_CipherFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl) | - | ||||||||||||||||||
241 | { | - | ||||||||||||||||||
242 | if (ctx->encrypt)
| 99 | ||||||||||||||||||
243 | return EVP_EncryptFinal_ex(ctx, out, outl); executed 99 times by 2 tests: return EVP_EncryptFinal_ex(ctx, out, outl); Executed by:
| 99 | ||||||||||||||||||
244 | else | - | ||||||||||||||||||
245 | return EVP_DecryptFinal_ex(ctx, out, outl); executed 99 times by 2 tests: return EVP_DecryptFinal_ex(ctx, out, outl); Executed by:
| 99 | ||||||||||||||||||
246 | } | - | ||||||||||||||||||
247 | - | |||||||||||||||||||
248 | __warn_references(EVP_CipherFinal, | - | ||||||||||||||||||
249 | "EVP_CipherFinal is often misused, please use EVP_CipherFinal_ex and EVP_CIPHER_CTX_cleanup"); | - | ||||||||||||||||||
250 | - | |||||||||||||||||||
251 | int | - | ||||||||||||||||||
252 | EVP_CipherFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl) | - | ||||||||||||||||||
253 | { | - | ||||||||||||||||||
254 | int ret; | - | ||||||||||||||||||
255 | if (ctx->encrypt)
| 0 | ||||||||||||||||||
256 | ret = EVP_EncryptFinal_ex(ctx, out, outl); never executed: ret = EVP_EncryptFinal_ex(ctx, out, outl); | 0 | ||||||||||||||||||
257 | else | - | ||||||||||||||||||
258 | ret = EVP_DecryptFinal_ex(ctx, out, outl); never executed: ret = EVP_DecryptFinal_ex(ctx, out, outl); | 0 | ||||||||||||||||||
259 | return ret; never executed: return ret; | 0 | ||||||||||||||||||
260 | } | - | ||||||||||||||||||
261 | - | |||||||||||||||||||
262 | int | - | ||||||||||||||||||
263 | EVP_EncryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, | - | ||||||||||||||||||
264 | const unsigned char *key, const unsigned char *iv) | - | ||||||||||||||||||
265 | { | - | ||||||||||||||||||
266 | return EVP_CipherInit(ctx, cipher, key, iv, 1); never executed: return EVP_CipherInit(ctx, cipher, key, iv, 1); | 0 | ||||||||||||||||||
267 | } | - | ||||||||||||||||||
268 | - | |||||||||||||||||||
269 | int | - | ||||||||||||||||||
270 | EVP_EncryptInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *impl, | - | ||||||||||||||||||
271 | const unsigned char *key, const unsigned char *iv) | - | ||||||||||||||||||
272 | { | - | ||||||||||||||||||
273 | return EVP_CipherInit_ex(ctx, cipher, impl, key, iv, 1); executed 208 times by 3 tests: return EVP_CipherInit_ex(ctx, cipher, impl, key, iv, 1); Executed by:
| 208 | ||||||||||||||||||
274 | } | - | ||||||||||||||||||
275 | - | |||||||||||||||||||
276 | int | - | ||||||||||||||||||
277 | EVP_DecryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, | - | ||||||||||||||||||
278 | const unsigned char *key, const unsigned char *iv) | - | ||||||||||||||||||
279 | { | - | ||||||||||||||||||
280 | return EVP_CipherInit(ctx, cipher, key, iv, 0); never executed: return EVP_CipherInit(ctx, cipher, key, iv, 0); | 0 | ||||||||||||||||||
281 | } | - | ||||||||||||||||||
282 | - | |||||||||||||||||||
283 | int | - | ||||||||||||||||||
284 | EVP_DecryptInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *impl, | - | ||||||||||||||||||
285 | const unsigned char *key, const unsigned char *iv) | - | ||||||||||||||||||
286 | { | - | ||||||||||||||||||
287 | return EVP_CipherInit_ex(ctx, cipher, impl, key, iv, 0); executed 114 times by 1 test: return EVP_CipherInit_ex(ctx, cipher, impl, key, iv, 0); Executed by:
| 114 | ||||||||||||||||||
288 | } | - | ||||||||||||||||||
289 | - | |||||||||||||||||||
290 | int | - | ||||||||||||||||||
291 | EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl, | - | ||||||||||||||||||
292 | const unsigned char *in, int inl) | - | ||||||||||||||||||
293 | { | - | ||||||||||||||||||
294 | int i, j, bl; | - | ||||||||||||||||||
295 | - | |||||||||||||||||||
296 | if (ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_CIPHER) {
| 0-520 | ||||||||||||||||||
297 | i = M_do_cipher(ctx, out, in, inl); | - | ||||||||||||||||||
298 | if (i < 0)
| 0 | ||||||||||||||||||
299 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
300 | else | - | ||||||||||||||||||
301 | *outl = i; never executed: *outl = i; | 0 | ||||||||||||||||||
302 | return 1; never executed: return 1; | 0 | ||||||||||||||||||
303 | } | - | ||||||||||||||||||
304 | - | |||||||||||||||||||
305 | if (inl <= 0) {
| 0-520 | ||||||||||||||||||
306 | *outl = 0; | - | ||||||||||||||||||
307 | return inl == 0; never executed: return inl == 0; | 0 | ||||||||||||||||||
308 | } | - | ||||||||||||||||||
309 | - | |||||||||||||||||||
310 | if (ctx->buf_len == 0 && (inl&(ctx->block_mask)) == 0) {
| 0-520 | ||||||||||||||||||
311 | if (M_do_cipher(ctx, out, in, inl)) {
| 0-448 | ||||||||||||||||||
312 | *outl = inl; | - | ||||||||||||||||||
313 | return 1; executed 448 times by 4 tests: return 1; Executed by:
| 448 | ||||||||||||||||||
314 | } else { | - | ||||||||||||||||||
315 | *outl = 0; | - | ||||||||||||||||||
316 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
317 | } | - | ||||||||||||||||||
318 | } | - | ||||||||||||||||||
319 | i = ctx->buf_len; | - | ||||||||||||||||||
320 | bl = ctx->cipher->block_size; | - | ||||||||||||||||||
321 | if ((size_t)bl > sizeof(ctx->buf)) {
| 0-72 | ||||||||||||||||||
322 | EVPerror(EVP_R_BAD_BLOCK_LENGTH); | - | ||||||||||||||||||
323 | *outl = 0; | - | ||||||||||||||||||
324 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
325 | } | - | ||||||||||||||||||
326 | if (i != 0) {
| 0-72 | ||||||||||||||||||
327 | if (bl - i > inl) {
| 0 | ||||||||||||||||||
328 | memcpy(&(ctx->buf[i]), in, inl); | - | ||||||||||||||||||
329 | ctx->buf_len += inl; | - | ||||||||||||||||||
330 | *outl = 0; | - | ||||||||||||||||||
331 | return 1; never executed: return 1; | 0 | ||||||||||||||||||
332 | } else { | - | ||||||||||||||||||
333 | j = bl - i; | - | ||||||||||||||||||
334 | memcpy(&(ctx->buf[i]), in, j); | - | ||||||||||||||||||
335 | if (!M_do_cipher(ctx, out, ctx->buf, bl))
| 0 | ||||||||||||||||||
336 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
337 | inl -= j; | - | ||||||||||||||||||
338 | in += j; | - | ||||||||||||||||||
339 | out += bl; | - | ||||||||||||||||||
340 | *outl = bl; | - | ||||||||||||||||||
341 | } never executed: end of block | 0 | ||||||||||||||||||
342 | } else | - | ||||||||||||||||||
343 | *outl = 0; executed 72 times by 3 tests: *outl = 0; Executed by:
| 72 | ||||||||||||||||||
344 | i = inl&(bl - 1); | - | ||||||||||||||||||
345 | inl -= i; | - | ||||||||||||||||||
346 | if (inl > 0) {
| 0-72 | ||||||||||||||||||
347 | if (!M_do_cipher(ctx, out, in, inl))
| 0-72 | ||||||||||||||||||
348 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
349 | *outl += inl; | - | ||||||||||||||||||
350 | } executed 72 times by 3 tests: end of block Executed by:
| 72 | ||||||||||||||||||
351 | - | |||||||||||||||||||
352 | if (i != 0)
| 0-72 | ||||||||||||||||||
353 | memcpy(ctx->buf, &(in[inl]), i); executed 72 times by 3 tests: memcpy(ctx->buf, &(in[inl]), i); Executed by:
| 72 | ||||||||||||||||||
354 | ctx->buf_len = i; | - | ||||||||||||||||||
355 | return 1; executed 72 times by 3 tests: return 1; Executed by:
| 72 | ||||||||||||||||||
356 | } | - | ||||||||||||||||||
357 | - | |||||||||||||||||||
358 | __warn_references(EVP_EncryptFinal, | - | ||||||||||||||||||
359 | "EVP_EncryptFinal is often misused, please use EVP_EncryptFinal_ex and EVP_CIPHER_CTX_cleanup"); | - | ||||||||||||||||||
360 | - | |||||||||||||||||||
361 | int | - | ||||||||||||||||||
362 | EVP_EncryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl) | - | ||||||||||||||||||
363 | { | - | ||||||||||||||||||
364 | int ret; | - | ||||||||||||||||||
365 | - | |||||||||||||||||||
366 | ret = EVP_EncryptFinal_ex(ctx, out, outl); | - | ||||||||||||||||||
367 | return ret; never executed: return ret; | 0 | ||||||||||||||||||
368 | } | - | ||||||||||||||||||
369 | - | |||||||||||||||||||
370 | int | - | ||||||||||||||||||
371 | EVP_EncryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl) | - | ||||||||||||||||||
372 | { | - | ||||||||||||||||||
373 | int n, ret; | - | ||||||||||||||||||
374 | unsigned int i, b, bl; | - | ||||||||||||||||||
375 | - | |||||||||||||||||||
376 | if (ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_CIPHER) {
| 0-303 | ||||||||||||||||||
377 | ret = M_do_cipher(ctx, out, NULL, 0); | - | ||||||||||||||||||
378 | if (ret < 0)
| 0 | ||||||||||||||||||
379 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
380 | else | - | ||||||||||||||||||
381 | *outl = ret; never executed: *outl = ret; | 0 | ||||||||||||||||||
382 | return 1; never executed: return 1; | 0 | ||||||||||||||||||
383 | } | - | ||||||||||||||||||
384 | - | |||||||||||||||||||
385 | b = ctx->cipher->block_size; | - | ||||||||||||||||||
386 | if (b > sizeof ctx->buf) {
| 0-303 | ||||||||||||||||||
387 | EVPerror(EVP_R_BAD_BLOCK_LENGTH); | - | ||||||||||||||||||
388 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
389 | } | - | ||||||||||||||||||
390 | if (b == 1) {
| 133-170 | ||||||||||||||||||
391 | *outl = 0; | - | ||||||||||||||||||
392 | return 1; executed 133 times by 3 tests: return 1; Executed by:
| 133 | ||||||||||||||||||
393 | } | - | ||||||||||||||||||
394 | bl = ctx->buf_len; | - | ||||||||||||||||||
395 | if (ctx->flags & EVP_CIPH_NO_PADDING) {
| 66-104 | ||||||||||||||||||
396 | if (bl) {
| 0-66 | ||||||||||||||||||
397 | EVPerror(EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH); | - | ||||||||||||||||||
398 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
399 | } | - | ||||||||||||||||||
400 | *outl = 0; | - | ||||||||||||||||||
401 | return 1; executed 66 times by 1 test: return 1; Executed by:
| 66 | ||||||||||||||||||
402 | } | - | ||||||||||||||||||
403 | - | |||||||||||||||||||
404 | n = b - bl; | - | ||||||||||||||||||
405 | for (i = bl; i < b; i++)
| 104-884 | ||||||||||||||||||
406 | ctx->buf[i] = n; executed 884 times by 3 tests: ctx->buf[i] = n; Executed by:
| 884 | ||||||||||||||||||
407 | ret = M_do_cipher(ctx, out, ctx->buf, b); | - | ||||||||||||||||||
408 | - | |||||||||||||||||||
409 | - | |||||||||||||||||||
410 | if (ret)
| 0-104 | ||||||||||||||||||
411 | *outl = b; executed 104 times by 3 tests: *outl = b; Executed by:
| 104 | ||||||||||||||||||
412 | - | |||||||||||||||||||
413 | return ret; executed 104 times by 3 tests: return ret; Executed by:
| 104 | ||||||||||||||||||
414 | } | - | ||||||||||||||||||
415 | - | |||||||||||||||||||
416 | int | - | ||||||||||||||||||
417 | EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl, | - | ||||||||||||||||||
418 | const unsigned char *in, int inl) | - | ||||||||||||||||||
419 | { | - | ||||||||||||||||||
420 | int fix_len; | - | ||||||||||||||||||
421 | unsigned int b; | - | ||||||||||||||||||
422 | - | |||||||||||||||||||
423 | if (ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_CIPHER) {
| 0-213 | ||||||||||||||||||
424 | fix_len = M_do_cipher(ctx, out, in, inl); | - | ||||||||||||||||||
425 | if (fix_len < 0) {
| 0 | ||||||||||||||||||
426 | *outl = 0; | - | ||||||||||||||||||
427 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
428 | } else | - | ||||||||||||||||||
429 | *outl = fix_len; never executed: *outl = fix_len; | 0 | ||||||||||||||||||
430 | return 1; never executed: return 1; | 0 | ||||||||||||||||||
431 | } | - | ||||||||||||||||||
432 | - | |||||||||||||||||||
433 | if (inl <= 0) {
| 0-213 | ||||||||||||||||||
434 | *outl = 0; | - | ||||||||||||||||||
435 | return inl == 0; never executed: return inl == 0; | 0 | ||||||||||||||||||
436 | } | - | ||||||||||||||||||
437 | - | |||||||||||||||||||
438 | if (ctx->flags & EVP_CIPH_NO_PADDING)
| 99-114 | ||||||||||||||||||
439 | return EVP_EncryptUpdate(ctx, out, outl, in, inl); executed 114 times by 1 test: return EVP_EncryptUpdate(ctx, out, outl, in, inl); Executed by:
| 114 | ||||||||||||||||||
440 | - | |||||||||||||||||||
441 | b = ctx->cipher->block_size; | - | ||||||||||||||||||
442 | if (b > sizeof ctx->final) {
| 0-99 | ||||||||||||||||||
443 | EVPerror(EVP_R_BAD_BLOCK_LENGTH); | - | ||||||||||||||||||
444 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
445 | } | - | ||||||||||||||||||
446 | - | |||||||||||||||||||
447 | if (ctx->final_used) {
| 0-99 | ||||||||||||||||||
448 | memcpy(out, ctx->final, b); | - | ||||||||||||||||||
449 | out += b; | - | ||||||||||||||||||
450 | fix_len = 1; | - | ||||||||||||||||||
451 | } else never executed: end of block | 0 | ||||||||||||||||||
452 | fix_len = 0; executed 99 times by 2 tests: fix_len = 0; Executed by:
| 99 | ||||||||||||||||||
453 | - | |||||||||||||||||||
454 | - | |||||||||||||||||||
455 | if (!EVP_EncryptUpdate(ctx, out, outl, in, inl))
| 0-99 | ||||||||||||||||||
456 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
457 | - | |||||||||||||||||||
458 | /* if we have 'decrypted' a multiple of block size, make sure | - | ||||||||||||||||||
459 | * we have a copy of this last block */ | - | ||||||||||||||||||
460 | if (b > 1 && !ctx->buf_len) {
| 0-54 | ||||||||||||||||||
461 | *outl -= b; | - | ||||||||||||||||||
462 | ctx->final_used = 1; | - | ||||||||||||||||||
463 | memcpy(ctx->final, &out[*outl], b); | - | ||||||||||||||||||
464 | } else executed 45 times by 2 tests: end of block Executed by:
| 45 | ||||||||||||||||||
465 | ctx->final_used = 0; executed 54 times by 1 test: ctx->final_used = 0; Executed by:
| 54 | ||||||||||||||||||
466 | - | |||||||||||||||||||
467 | if (fix_len)
| 0-99 | ||||||||||||||||||
468 | *outl += b; never executed: *outl += b; | 0 | ||||||||||||||||||
469 | - | |||||||||||||||||||
470 | return 1; executed 99 times by 2 tests: return 1; Executed by:
| 99 | ||||||||||||||||||
471 | } | - | ||||||||||||||||||
472 | - | |||||||||||||||||||
473 | __warn_references(EVP_DecryptFinal, | - | ||||||||||||||||||
474 | "EVP_DecryptFinal is often misused, please use EVP_DecryptFinal_ex and EVP_CIPHER_CTX_cleanup"); | - | ||||||||||||||||||
475 | - | |||||||||||||||||||
476 | int | - | ||||||||||||||||||
477 | EVP_DecryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl) | - | ||||||||||||||||||
478 | { | - | ||||||||||||||||||
479 | int ret; | - | ||||||||||||||||||
480 | - | |||||||||||||||||||
481 | ret = EVP_DecryptFinal_ex(ctx, out, outl); | - | ||||||||||||||||||
482 | return ret; never executed: return ret; | 0 | ||||||||||||||||||
483 | } | - | ||||||||||||||||||
484 | - | |||||||||||||||||||
485 | int | - | ||||||||||||||||||
486 | EVP_DecryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl) | - | ||||||||||||||||||
487 | { | - | ||||||||||||||||||
488 | int i, n; | - | ||||||||||||||||||
489 | unsigned int b; | - | ||||||||||||||||||
490 | *outl = 0; | - | ||||||||||||||||||
491 | - | |||||||||||||||||||
492 | if (ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_CIPHER) {
| 0-213 | ||||||||||||||||||
493 | i = M_do_cipher(ctx, out, NULL, 0); | - | ||||||||||||||||||
494 | if (i < 0)
| 0 | ||||||||||||||||||
495 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
496 | else | - | ||||||||||||||||||
497 | *outl = i; never executed: *outl = i; | 0 | ||||||||||||||||||
498 | return 1; never executed: return 1; | 0 | ||||||||||||||||||
499 | } | - | ||||||||||||||||||
500 | - | |||||||||||||||||||
501 | b = ctx->cipher->block_size; | - | ||||||||||||||||||
502 | if (ctx->flags & EVP_CIPH_NO_PADDING) {
| 99-114 | ||||||||||||||||||
503 | if (ctx->buf_len) {
| 0-114 | ||||||||||||||||||
504 | EVPerror(EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH); | - | ||||||||||||||||||
505 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
506 | } | - | ||||||||||||||||||
507 | *outl = 0; | - | ||||||||||||||||||
508 | return 1; executed 114 times by 1 test: return 1; Executed by:
| 114 | ||||||||||||||||||
509 | } | - | ||||||||||||||||||
510 | if (b > 1) {
| 45-54 | ||||||||||||||||||
511 | if (ctx->buf_len || !ctx->final_used) {
| 0-45 | ||||||||||||||||||
512 | EVPerror(EVP_R_WRONG_FINAL_BLOCK_LENGTH); | - | ||||||||||||||||||
513 | return (0); never executed: return (0); | 0 | ||||||||||||||||||
514 | } | - | ||||||||||||||||||
515 | if (b > sizeof ctx->final) {
| 0-45 | ||||||||||||||||||
516 | EVPerror(EVP_R_BAD_BLOCK_LENGTH); | - | ||||||||||||||||||
517 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
518 | } | - | ||||||||||||||||||
519 | n = ctx->final[b - 1]; | - | ||||||||||||||||||
520 | if (n == 0 || n > (int)b) {
| 0-45 | ||||||||||||||||||
521 | EVPerror(EVP_R_BAD_DECRYPT); | - | ||||||||||||||||||
522 | return (0); never executed: return (0); | 0 | ||||||||||||||||||
523 | } | - | ||||||||||||||||||
524 | for (i = 0; i < n; i++) {
| 45-362 | ||||||||||||||||||
525 | if (ctx->final[--b] != n) {
| 0-362 | ||||||||||||||||||
526 | EVPerror(EVP_R_BAD_DECRYPT); | - | ||||||||||||||||||
527 | return (0); never executed: return (0); | 0 | ||||||||||||||||||
528 | } | - | ||||||||||||||||||
529 | } executed 362 times by 2 tests: end of block Executed by:
| 362 | ||||||||||||||||||
530 | n = ctx->cipher->block_size - n; | - | ||||||||||||||||||
531 | for (i = 0; i < n; i++)
| 45-102 | ||||||||||||||||||
532 | out[i] = ctx->final[i]; executed 102 times by 2 tests: out[i] = ctx->final[i]; Executed by:
| 102 | ||||||||||||||||||
533 | *outl = n; | - | ||||||||||||||||||
534 | } else executed 45 times by 2 tests: end of block Executed by:
| 45 | ||||||||||||||||||
535 | *outl = 0; executed 54 times by 1 test: *outl = 0; Executed by:
| 54 | ||||||||||||||||||
536 | return (1); executed 99 times by 2 tests: return (1); Executed by:
| 99 | ||||||||||||||||||
537 | } | - | ||||||||||||||||||
538 | - | |||||||||||||||||||
539 | EVP_CIPHER_CTX * | - | ||||||||||||||||||
540 | EVP_CIPHER_CTX_new(void) | - | ||||||||||||||||||
541 | { | - | ||||||||||||||||||
542 | return calloc(1, sizeof(EVP_CIPHER_CTX)); executed 160 times by 1 test: return calloc(1, sizeof(EVP_CIPHER_CTX)); Executed by:
| 160 | ||||||||||||||||||
543 | } | - | ||||||||||||||||||
544 | - | |||||||||||||||||||
545 | void | - | ||||||||||||||||||
546 | EVP_CIPHER_CTX_free(EVP_CIPHER_CTX *ctx) | - | ||||||||||||||||||
547 | { | - | ||||||||||||||||||
548 | if (ctx == NULL)
| 160-1432 | ||||||||||||||||||
549 | return; executed 1432 times by 12 tests: return; Executed by:
| 1432 | ||||||||||||||||||
550 | - | |||||||||||||||||||
551 | EVP_CIPHER_CTX_cleanup(ctx); | - | ||||||||||||||||||
552 | - | |||||||||||||||||||
553 | free(ctx); | - | ||||||||||||||||||
554 | } executed 160 times by 1 test: end of block Executed by:
| 160 | ||||||||||||||||||
555 | - | |||||||||||||||||||
556 | void | - | ||||||||||||||||||
557 | EVP_CIPHER_CTX_init(EVP_CIPHER_CTX *ctx) | - | ||||||||||||||||||
558 | { | - | ||||||||||||||||||
559 | memset(ctx, 0, sizeof(EVP_CIPHER_CTX)); | - | ||||||||||||||||||
560 | } executed 454 times by 5 tests: end of block Executed by:
| 454 | ||||||||||||||||||
561 | - | |||||||||||||||||||
562 | int | - | ||||||||||||||||||
563 | EVP_CIPHER_CTX_reset(EVP_CIPHER_CTX *a) | - | ||||||||||||||||||
564 | { | - | ||||||||||||||||||
565 | return EVP_CIPHER_CTX_cleanup(a); never executed: return EVP_CIPHER_CTX_cleanup(a); | 0 | ||||||||||||||||||
566 | } | - | ||||||||||||||||||
567 | - | |||||||||||||||||||
568 | int | - | ||||||||||||||||||
569 | EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *c) | - | ||||||||||||||||||
570 | { | - | ||||||||||||||||||
571 | if (c->cipher != NULL) {
| 0-680 | ||||||||||||||||||
572 | if (c->cipher->cleanup && !c->cipher->cleanup(c))
| 0-680 | ||||||||||||||||||
573 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
574 | /* Cleanse cipher context data */ | - | ||||||||||||||||||
575 | if (c->cipher_data)
| 12-668 | ||||||||||||||||||
576 | explicit_bzero(c->cipher_data, c->cipher->ctx_size); executed 668 times by 5 tests: explicit_bzero(c->cipher_data, c->cipher->ctx_size); Executed by:
| 668 | ||||||||||||||||||
577 | } executed 680 times by 5 tests: end of block Executed by:
| 680 | ||||||||||||||||||
578 | free(c->cipher_data); | - | ||||||||||||||||||
579 | #ifndef OPENSSL_NO_ENGINE | - | ||||||||||||||||||
580 | ENGINE_finish(c->engine); | - | ||||||||||||||||||
581 | #endif | - | ||||||||||||||||||
582 | explicit_bzero(c, sizeof(EVP_CIPHER_CTX)); | - | ||||||||||||||||||
583 | return 1; executed 680 times by 5 tests: return 1; Executed by:
| 680 | ||||||||||||||||||
584 | } | - | ||||||||||||||||||
585 | - | |||||||||||||||||||
586 | int | - | ||||||||||||||||||
587 | EVP_CIPHER_CTX_set_key_length(EVP_CIPHER_CTX *c, int keylen) | - | ||||||||||||||||||
588 | { | - | ||||||||||||||||||
589 | if (c->cipher->flags & EVP_CIPH_CUSTOM_KEY_LENGTH)
| 0 | ||||||||||||||||||
590 | return EVP_CIPHER_CTX_ctrl(c, EVP_CTRL_SET_KEY_LENGTH, never executed: return EVP_CIPHER_CTX_ctrl(c, 0x1, keylen, ((void *)0) ); | 0 | ||||||||||||||||||
591 | keylen, NULL); never executed: return EVP_CIPHER_CTX_ctrl(c, 0x1, keylen, ((void *)0) ); | 0 | ||||||||||||||||||
592 | if (c->key_len == keylen)
| 0 | ||||||||||||||||||
593 | return 1; never executed: return 1; | 0 | ||||||||||||||||||
594 | if ((keylen > 0) && (c->cipher->flags & EVP_CIPH_VARIABLE_LENGTH)) {
| 0 | ||||||||||||||||||
595 | c->key_len = keylen; | - | ||||||||||||||||||
596 | return 1; never executed: return 1; | 0 | ||||||||||||||||||
597 | } | - | ||||||||||||||||||
598 | EVPerror(EVP_R_INVALID_KEY_LENGTH); | - | ||||||||||||||||||
599 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
600 | } | - | ||||||||||||||||||
601 | - | |||||||||||||||||||
602 | int | - | ||||||||||||||||||
603 | EVP_CIPHER_CTX_set_padding(EVP_CIPHER_CTX *ctx, int pad) | - | ||||||||||||||||||
604 | { | - | ||||||||||||||||||
605 | if (pad)
| 0-251 | ||||||||||||||||||
606 | ctx->flags &= ~EVP_CIPH_NO_PADDING; never executed: ctx->flags &= ~0x100; | 0 | ||||||||||||||||||
607 | else | - | ||||||||||||||||||
608 | ctx->flags |= EVP_CIPH_NO_PADDING; executed 251 times by 1 test: ctx->flags |= 0x100; Executed by:
| 251 | ||||||||||||||||||
609 | return 1; executed 251 times by 1 test: return 1; Executed by:
| 251 | ||||||||||||||||||
610 | } | - | ||||||||||||||||||
611 | - | |||||||||||||||||||
612 | int | - | ||||||||||||||||||
613 | EVP_CIPHER_CTX_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr) | - | ||||||||||||||||||
614 | { | - | ||||||||||||||||||
615 | int ret; | - | ||||||||||||||||||
616 | - | |||||||||||||||||||
617 | if (!ctx->cipher) {
| 0-48 | ||||||||||||||||||
618 | EVPerror(EVP_R_NO_CIPHER_SET); | - | ||||||||||||||||||
619 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
620 | } | - | ||||||||||||||||||
621 | - | |||||||||||||||||||
622 | if (!ctx->cipher->ctrl) {
| 0-48 | ||||||||||||||||||
623 | EVPerror(EVP_R_CTRL_NOT_IMPLEMENTED); | - | ||||||||||||||||||
624 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
625 | } | - | ||||||||||||||||||
626 | - | |||||||||||||||||||
627 | ret = ctx->cipher->ctrl(ctx, type, arg, ptr); | - | ||||||||||||||||||
628 | if (ret == -1) {
| 0-48 | ||||||||||||||||||
629 | EVPerror(EVP_R_CTRL_OPERATION_NOT_IMPLEMENTED); | - | ||||||||||||||||||
630 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
631 | } | - | ||||||||||||||||||
632 | return ret; executed 48 times by 2 tests: return ret; Executed by:
| 48 | ||||||||||||||||||
633 | } | - | ||||||||||||||||||
634 | - | |||||||||||||||||||
635 | int | - | ||||||||||||||||||
636 | EVP_CIPHER_CTX_rand_key(EVP_CIPHER_CTX *ctx, unsigned char *key) | - | ||||||||||||||||||
637 | { | - | ||||||||||||||||||
638 | if (ctx->cipher->flags & EVP_CIPH_RAND_KEY)
| 0-2 | ||||||||||||||||||
639 | return EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_RAND_KEY, 0, key); never executed: return EVP_CIPHER_CTX_ctrl(ctx, 0x6, 0, key); | 0 | ||||||||||||||||||
640 | arc4random_buf(key, ctx->key_len); | - | ||||||||||||||||||
641 | return 1; executed 2 times by 1 test: return 1; Executed by:
| 2 | ||||||||||||||||||
642 | } | - | ||||||||||||||||||
643 | - | |||||||||||||||||||
644 | int | - | ||||||||||||||||||
645 | EVP_CIPHER_CTX_copy(EVP_CIPHER_CTX *out, const EVP_CIPHER_CTX *in) | - | ||||||||||||||||||
646 | { | - | ||||||||||||||||||
647 | if ((in == NULL) || (in->cipher == NULL)) {
| 0 | ||||||||||||||||||
648 | EVPerror(EVP_R_INPUT_NOT_INITIALIZED); | - | ||||||||||||||||||
649 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
650 | } | - | ||||||||||||||||||
651 | #ifndef OPENSSL_NO_ENGINE | - | ||||||||||||||||||
652 | /* Make sure it's safe to copy a cipher context using an ENGINE */ | - | ||||||||||||||||||
653 | if (in->engine && !ENGINE_init(in->engine)) {
| 0 | ||||||||||||||||||
654 | EVPerror(ERR_R_ENGINE_LIB); | - | ||||||||||||||||||
655 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
656 | } | - | ||||||||||||||||||
657 | #endif | - | ||||||||||||||||||
658 | - | |||||||||||||||||||
659 | EVP_CIPHER_CTX_cleanup(out); | - | ||||||||||||||||||
660 | memcpy(out, in, sizeof *out); | - | ||||||||||||||||||
661 | - | |||||||||||||||||||
662 | if (in->cipher_data && in->cipher->ctx_size) {
| 0 | ||||||||||||||||||
663 | out->cipher_data = malloc(in->cipher->ctx_size); | - | ||||||||||||||||||
664 | if (!out->cipher_data) {
| 0 | ||||||||||||||||||
665 | EVPerror(ERR_R_MALLOC_FAILURE); | - | ||||||||||||||||||
666 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
667 | } | - | ||||||||||||||||||
668 | memcpy(out->cipher_data, in->cipher_data, in->cipher->ctx_size); | - | ||||||||||||||||||
669 | } never executed: end of block | 0 | ||||||||||||||||||
670 | - | |||||||||||||||||||
671 | if (in->cipher->flags & EVP_CIPH_CUSTOM_COPY)
| 0 | ||||||||||||||||||
672 | return in->cipher->ctrl((EVP_CIPHER_CTX *)in, never executed: return in->cipher->ctrl((EVP_CIPHER_CTX *)in, 0x8, 0, out); | 0 | ||||||||||||||||||
673 | EVP_CTRL_COPY, 0, out); never executed: return in->cipher->ctrl((EVP_CIPHER_CTX *)in, 0x8, 0, out); | 0 | ||||||||||||||||||
674 | return 1; never executed: return 1; | 0 | ||||||||||||||||||
675 | } | - | ||||||||||||||||||
Source code | Switch to Preprocessed file |