OpenCoverage

evp_enc.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/libressl/src/crypto/evp/evp_enc.c
Source codeSwitch to Preprocessed file
LineSourceCount
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-
78int-
79EVP_CipherInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,-
80 const unsigned char *key, const unsigned char *iv, int enc)-
81{-
82 if (cipher)
cipherDescription
TRUEnever evaluated
FALSEnever evaluated
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-
87int-
88EVP_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)
enc == -1Description
TRUEnever evaluated
FALSEevaluated 878 times by 5 tests
Evaluated by:
  • evptest
  • gost2814789t
  • libcrypto.so.44.0.1
  • pkcs7test
  • ssltest
0-878
92 enc = ctx->encrypt;
never executed: enc = ctx->encrypt;
0
93 else {-
94 if (enc)
encDescription
TRUEevaluated 486 times by 5 tests
Evaluated by:
  • evptest
  • gost2814789t
  • libcrypto.so.44.0.1
  • pkcs7test
  • ssltest
FALSEevaluated 392 times by 4 tests
Evaluated by:
  • evptest
  • libcrypto.so.44.0.1
  • pkcs7test
  • ssltest
392-486
95 enc = 1;
executed 486 times by 5 tests: enc = 1;
Executed by:
  • evptest
  • gost2814789t
  • libcrypto.so.44.0.1
  • pkcs7test
  • ssltest
486
96 ctx->encrypt = enc;-
97 }
executed 878 times by 5 tests: end of block
Executed by:
  • evptest
  • gost2814789t
  • libcrypto.so.44.0.1
  • pkcs7test
  • ssltest
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 &&
ctx->engineDescription
TRUEnever evaluated
FALSEevaluated 878 times by 5 tests
Evaluated by:
  • evptest
  • gost2814789t
  • libcrypto.so.44.0.1
  • pkcs7test
  • ssltest
ctx->cipherDescription
TRUEnever evaluated
FALSEnever evaluated
0-878
104 (!cipher || (cipher && (cipher->nid == ctx->cipher->nid))))
!cipherDescription
TRUEnever evaluated
FALSEnever evaluated
cipherDescription
TRUEnever evaluated
FALSEnever evaluated
(cipher->nid =...->cipher->nid)Description
TRUEnever evaluated
FALSEnever evaluated
0
105 goto skip_to_init;
never executed: goto skip_to_init;
0
106#endif-
107 if (cipher) {
cipherDescription
TRUEevaluated 680 times by 5 tests
Evaluated by:
  • evptest
  • gost2814789t
  • libcrypto.so.44.0.1
  • pkcs7test
  • ssltest
FALSEevaluated 198 times by 2 tests
Evaluated by:
  • libcrypto.so.44.0.1
  • pkcs7test
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) {
ctx->cipherDescription
TRUEevaluated 66 times by 1 test
Evaluated by:
  • evptest
FALSEevaluated 614 times by 5 tests
Evaluated by:
  • evptest
  • gost2814789t
  • libcrypto.so.44.0.1
  • pkcs7test
  • ssltest
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:
  • evptest
66
118#ifndef OPENSSL_NO_ENGINE-
119 if (impl) {
implDescription
TRUEnever evaluated
FALSEevaluated 680 times by 5 tests
Evaluated by:
  • evptest
  • gost2814789t
  • libcrypto.so.44.0.1
  • pkcs7test
  • ssltest
0-680
120 if (!ENGINE_init(impl)) {
!ENGINE_init(impl)Description
TRUEnever evaluated
FALSEnever evaluated
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:
  • evptest
  • gost2814789t
  • libcrypto.so.44.0.1
  • pkcs7test
  • ssltest
680
127 if (impl) {
implDescription
TRUEnever evaluated
FALSEevaluated 680 times by 5 tests
Evaluated by:
  • evptest
  • gost2814789t
  • libcrypto.so.44.0.1
  • pkcs7test
  • ssltest
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) {
!cDescription
TRUEnever evaluated
FALSEnever evaluated
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:
  • evptest
  • gost2814789t
  • libcrypto.so.44.0.1
  • pkcs7test
  • ssltest
680
143#endif-
144-
145 ctx->cipher = cipher;-
146 if (ctx->cipher->ctx_size) {
ctx->cipher->ctx_sizeDescription
TRUEevaluated 668 times by 5 tests
Evaluated by:
  • evptest
  • gost2814789t
  • libcrypto.so.44.0.1
  • pkcs7test
  • ssltest
FALSEevaluated 12 times by 1 test
Evaluated by:
  • ssltest
12-668
147 ctx->cipher_data = malloc(ctx->cipher->ctx_size);-
148 if (!ctx->cipher_data) {
!ctx->cipher_dataDescription
TRUEnever evaluated
FALSEevaluated 668 times by 5 tests
Evaluated by:
  • evptest
  • gost2814789t
  • libcrypto.so.44.0.1
  • pkcs7test
  • ssltest
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:
  • evptest
  • gost2814789t
  • libcrypto.so.44.0.1
  • pkcs7test
  • ssltest
668
153 ctx->cipher_data = NULL;-
154 }
executed 12 times by 1 test: end of block
Executed by:
  • ssltest
12
155 ctx->key_len = cipher->key_len;-
156 ctx->flags = 0;-
157 if (ctx->cipher->flags & EVP_CIPH_CTRL_INIT) {
ctx->cipher->flags & 0x40Description
TRUEevaluated 36 times by 2 tests
Evaluated by:
  • gost2814789t
  • libcrypto.so.44.0.1
FALSEevaluated 644 times by 4 tests
Evaluated by:
  • evptest
  • libcrypto.so.44.0.1
  • pkcs7test
  • ssltest
36-644
158 if (!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_INIT, 0, NULL)) {
!EVP_CIPHER_CT... ((void *)0) )Description
TRUEnever evaluated
FALSEevaluated 36 times by 2 tests
Evaluated by:
  • gost2814789t
  • libcrypto.so.44.0.1
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:
  • gost2814789t
  • libcrypto.so.44.0.1
36
163 } else if (!ctx->cipher) {
executed 680 times by 5 tests: end of block
Executed by:
  • evptest
  • gost2814789t
  • libcrypto.so.44.0.1
  • pkcs7test
  • ssltest
!ctx->cipherDescription
TRUEnever evaluated
FALSEevaluated 198 times by 2 tests
Evaluated by:
  • libcrypto.so.44.0.1
  • pkcs7test
0-680
164 EVPerror(EVP_R_NO_CIPHER_SET);-
165 return 0;
never executed: return 0;
0
166 }-
167#ifndef OPENSSL_NO_ENGINE-
168skip_to_init:
code before this statement executed 878 times by 5 tests: skip_to_init:
Executed by:
  • evptest
  • gost2814789t
  • libcrypto.so.44.0.1
  • pkcs7test
  • ssltest
878
169#endif-
170 /* we assume block size is a power of 2 in *cryptUpdate */-
171 if (ctx->cipher->block_size != 1 &&
ctx->cipher->block_size != 1Description
TRUEevaluated 517 times by 5 tests
Evaluated by:
  • evptest
  • gost2814789t
  • libcrypto.so.44.0.1
  • pkcs7test
  • ssltest
FALSEevaluated 361 times by 4 tests
Evaluated by:
  • evptest
  • gost2814789t
  • libcrypto.so.44.0.1
  • ssltest
361-517
172 ctx->cipher->block_size != 8 &&
ctx->cipher->block_size != 8Description
TRUEevaluated 363 times by 4 tests
Evaluated by:
  • evptest
  • libcrypto.so.44.0.1
  • pkcs7test
  • ssltest
FALSEevaluated 154 times by 4 tests
Evaluated by:
  • evptest
  • gost2814789t
  • libcrypto.so.44.0.1
  • ssltest
154-363
173 ctx->cipher->block_size != 16) {
ctx->cipher->block_size != 16Description
TRUEnever evaluated
FALSEevaluated 363 times by 4 tests
Evaluated by:
  • evptest
  • libcrypto.so.44.0.1
  • pkcs7test
  • ssltest
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)) {
!(EVP_CIPHER_C...s(ctx) & 0x10)Description
TRUEevaluated 878 times by 5 tests
Evaluated by:
  • evptest
  • gost2814789t
  • libcrypto.so.44.0.1
  • pkcs7test
  • ssltest
FALSEnever evaluated
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:
  • evptest
  • libcrypto.so.44.0.1
  • ssltest
48
182 case EVP_CIPH_ECB_MODE:
executed 150 times by 3 tests: case 0x1:
Executed by:
  • evptest
  • gost2814789t
  • libcrypto.so.44.0.1
150
183 break;
executed 198 times by 4 tests: break;
Executed by:
  • evptest
  • gost2814789t
  • libcrypto.so.44.0.1
  • ssltest
198
184-
185 case EVP_CIPH_CFB_MODE:
executed 181 times by 3 tests: case 0x3:
Executed by:
  • evptest
  • gost2814789t
  • libcrypto.so.44.0.1
181
186 case EVP_CIPH_OFB_MODE:
executed 123 times by 3 tests: case 0x4:
Executed by:
  • evptest
  • gost2814789t
  • libcrypto.so.44.0.1
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:
  • evptest
  • gost2814789t
  • libcrypto.so.44.0.1
executed 367 times by 4 tests: case 0x2:
Executed by:
  • evptest
  • libcrypto.so.44.0.1
  • pkcs7test
  • ssltest
304-367
192-
193 if ((size_t)EVP_CIPHER_CTX_iv_length(ctx) >
(size_t)EVP_CI...izeof(ctx->iv)Description
TRUEnever evaluated
FALSEevaluated 671 times by 5 tests
Evaluated by:
  • evptest
  • gost2814789t
  • libcrypto.so.44.0.1
  • pkcs7test
  • ssltest
0-671
194 sizeof(ctx->iv)) {
(size_t)EVP_CI...izeof(ctx->iv)Description
TRUEnever evaluated
FALSEevaluated 671 times by 5 tests
Evaluated by:
  • evptest
  • gost2814789t
  • libcrypto.so.44.0.1
  • pkcs7test
  • ssltest
0-671
195 EVPerror(EVP_R_IV_TOO_LARGE);-
196 return 0;
never executed: return 0;
0
197 }-
198 if (iv)
ivDescription
TRUEevaluated 516 times by 5 tests
Evaluated by:
  • evptest
  • gost2814789t
  • libcrypto.so.44.0.1
  • pkcs7test
  • ssltest
FALSEevaluated 155 times by 2 tests
Evaluated by:
  • libcrypto.so.44.0.1
  • pkcs7test
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:
  • evptest
  • gost2814789t
  • libcrypto.so.44.0.1
  • pkcs7test
  • ssltest
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:
  • evptest
  • gost2814789t
  • libcrypto.so.44.0.1
  • pkcs7test
  • ssltest
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:
  • evptest
  • gost2814789t
  • libcrypto.so.44.0.1
  • pkcs7test
  • ssltest
671
204-
205 case EVP_CIPH_CTR_MODE:
executed 9 times by 1 test: case 0x5:
Executed by:
  • evptest
9
206 ctx->num = 0;-
207 /* Don't reuse IV for CTR mode */-
208 if (iv)
ivDescription
TRUEevaluated 9 times by 1 test
Evaluated by:
  • evptest
FALSEnever evaluated
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:
  • evptest
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:
  • evptest
9
211 break;
executed 9 times by 1 test: break;
Executed by:
  • evptest
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)) {
keyDescription
TRUEevaluated 680 times by 5 tests
Evaluated by:
  • evptest
  • gost2814789t
  • libcrypto.so.44.0.1
  • pkcs7test
  • ssltest
FALSEevaluated 198 times by 2 tests
Evaluated by:
  • libcrypto.so.44.0.1
  • pkcs7test
(ctx->cipher->flags & 0x20)Description
TRUEnever evaluated
FALSEevaluated 198 times by 2 tests
Evaluated by:
  • libcrypto.so.44.0.1
  • pkcs7test
0-680
220 if (!ctx->cipher->init(ctx, key, iv, enc))
!ctx->cipher->... key, iv, enc)Description
TRUEnever evaluated
FALSEevaluated 680 times by 5 tests
Evaluated by:
  • evptest
  • gost2814789t
  • libcrypto.so.44.0.1
  • pkcs7test
  • ssltest
0-680
221 return 0;
never executed: return 0;
0
222 }
executed 680 times by 5 tests: end of block
Executed by:
  • evptest
  • gost2814789t
  • libcrypto.so.44.0.1
  • pkcs7test
  • ssltest
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:
  • evptest
  • gost2814789t
  • libcrypto.so.44.0.1
  • pkcs7test
  • ssltest
878
227}-
228-
229int-
230EVP_CipherUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,-
231 const unsigned char *in, int inl)-
232{-
233 if (ctx->encrypt)
ctx->encryptDescription
TRUEevaluated 99 times by 2 tests
Evaluated by:
  • libcrypto.so.44.0.1
  • pkcs7test
FALSEevaluated 99 times by 2 tests
Evaluated by:
  • libcrypto.so.44.0.1
  • pkcs7test
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:
  • libcrypto.so.44.0.1
  • pkcs7test
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:
  • libcrypto.so.44.0.1
  • pkcs7test
99
237}-
238-
239int-
240EVP_CipherFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)-
241{-
242 if (ctx->encrypt)
ctx->encryptDescription
TRUEevaluated 99 times by 2 tests
Evaluated by:
  • libcrypto.so.44.0.1
  • pkcs7test
FALSEevaluated 99 times by 2 tests
Evaluated by:
  • libcrypto.so.44.0.1
  • pkcs7test
99
243 return EVP_EncryptFinal_ex(ctx, out, outl);
executed 99 times by 2 tests: return EVP_EncryptFinal_ex(ctx, out, outl);
Executed by:
  • libcrypto.so.44.0.1
  • pkcs7test
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:
  • libcrypto.so.44.0.1
  • pkcs7test
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-
251int-
252EVP_CipherFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)-
253{-
254 int ret;-
255 if (ctx->encrypt)
ctx->encryptDescription
TRUEnever evaluated
FALSEnever evaluated
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-
262int-
263EVP_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-
269int-
270EVP_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:
  • evptest
  • gost2814789t
  • ssltest
208
274}-
275-
276int-
277EVP_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-
283int-
284EVP_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:
  • evptest
114
288}-
289-
290int-
291EVP_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) {
ctx->cipher->flags & 0x100000Description
TRUEnever evaluated
FALSEevaluated 520 times by 5 tests
Evaluated by:
  • evptest
  • gost2814789t
  • libcrypto.so.44.0.1
  • pkcs7test
  • ssltest
0-520
297 i = M_do_cipher(ctx, out, in, inl);-
298 if (i < 0)
i < 0Description
TRUEnever evaluated
FALSEnever evaluated
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) {
inl <= 0Description
TRUEnever evaluated
FALSEevaluated 520 times by 5 tests
Evaluated by:
  • evptest
  • gost2814789t
  • libcrypto.so.44.0.1
  • pkcs7test
  • ssltest
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) {
ctx->buf_len == 0Description
TRUEevaluated 520 times by 5 tests
Evaluated by:
  • evptest
  • gost2814789t
  • libcrypto.so.44.0.1
  • pkcs7test
  • ssltest
FALSEnever evaluated
(inl&(ctx->block_mask)) == 0Description
TRUEevaluated 448 times by 4 tests
Evaluated by:
  • evptest
  • gost2814789t
  • libcrypto.so.44.0.1
  • pkcs7test
FALSEevaluated 72 times by 3 tests
Evaluated by:
  • libcrypto.so.44.0.1
  • pkcs7test
  • ssltest
0-520
311 if (M_do_cipher(ctx, out, in, inl)) {
ctx->cipher->d... out, in, inl)Description
TRUEevaluated 448 times by 4 tests
Evaluated by:
  • evptest
  • gost2814789t
  • libcrypto.so.44.0.1
  • pkcs7test
FALSEnever evaluated
0-448
312 *outl = inl;-
313 return 1;
executed 448 times by 4 tests: return 1;
Executed by:
  • evptest
  • gost2814789t
  • libcrypto.so.44.0.1
  • pkcs7test
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)) {
(size_t)bl > sizeof(ctx->buf)Description
TRUEnever evaluated
FALSEevaluated 72 times by 3 tests
Evaluated by:
  • libcrypto.so.44.0.1
  • pkcs7test
  • ssltest
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) {
i != 0Description
TRUEnever evaluated
FALSEevaluated 72 times by 3 tests
Evaluated by:
  • libcrypto.so.44.0.1
  • pkcs7test
  • ssltest
0-72
327 if (bl - i > inl) {
bl - i > inlDescription
TRUEnever evaluated
FALSEnever evaluated
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))
!ctx->cipher->... ctx->buf, bl)Description
TRUEnever evaluated
FALSEnever evaluated
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:
  • libcrypto.so.44.0.1
  • pkcs7test
  • ssltest
72
344 i = inl&(bl - 1);-
345 inl -= i;-
346 if (inl > 0) {
inl > 0Description
TRUEevaluated 72 times by 3 tests
Evaluated by:
  • libcrypto.so.44.0.1
  • pkcs7test
  • ssltest
FALSEnever evaluated
0-72
347 if (!M_do_cipher(ctx, out, in, inl))
!ctx->cipher->... out, in, inl)Description
TRUEnever evaluated
FALSEevaluated 72 times by 3 tests
Evaluated by:
  • libcrypto.so.44.0.1
  • pkcs7test
  • ssltest
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:
  • libcrypto.so.44.0.1
  • pkcs7test
  • ssltest
72
351-
352 if (i != 0)
i != 0Description
TRUEevaluated 72 times by 3 tests
Evaluated by:
  • libcrypto.so.44.0.1
  • pkcs7test
  • ssltest
FALSEnever evaluated
0-72
353 memcpy(ctx->buf, &(in[inl]), i);
executed 72 times by 3 tests: memcpy(ctx->buf, &(in[inl]), i);
Executed by:
  • libcrypto.so.44.0.1
  • pkcs7test
  • ssltest
72
354 ctx->buf_len = i;-
355 return 1;
executed 72 times by 3 tests: return 1;
Executed by:
  • libcrypto.so.44.0.1
  • pkcs7test
  • ssltest
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-
361int-
362EVP_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-
370int-
371EVP_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) {
ctx->cipher->flags & 0x100000Description
TRUEnever evaluated
FALSEevaluated 303 times by 5 tests
Evaluated by:
  • evptest
  • gost2814789t
  • libcrypto.so.44.0.1
  • pkcs7test
  • ssltest
0-303
377 ret = M_do_cipher(ctx, out, NULL, 0);-
378 if (ret < 0)
ret < 0Description
TRUEnever evaluated
FALSEnever evaluated
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) {
b > sizeof ctx->bufDescription
TRUEnever evaluated
FALSEevaluated 303 times by 5 tests
Evaluated by:
  • evptest
  • gost2814789t
  • libcrypto.so.44.0.1
  • pkcs7test
  • ssltest
0-303
387 EVPerror(EVP_R_BAD_BLOCK_LENGTH);-
388 return 0;
never executed: return 0;
0
389 }-
390 if (b == 1) {
b == 1Description
TRUEevaluated 133 times by 3 tests
Evaluated by:
  • evptest
  • gost2814789t
  • libcrypto.so.44.0.1
FALSEevaluated 170 times by 4 tests
Evaluated by:
  • evptest
  • libcrypto.so.44.0.1
  • pkcs7test
  • ssltest
133-170
391 *outl = 0;-
392 return 1;
executed 133 times by 3 tests: return 1;
Executed by:
  • evptest
  • gost2814789t
  • libcrypto.so.44.0.1
133
393 }-
394 bl = ctx->buf_len;-
395 if (ctx->flags & EVP_CIPH_NO_PADDING) {
ctx->flags & 0x100Description
TRUEevaluated 66 times by 1 test
Evaluated by:
  • evptest
FALSEevaluated 104 times by 3 tests
Evaluated by:
  • libcrypto.so.44.0.1
  • pkcs7test
  • ssltest
66-104
396 if (bl) {
blDescription
TRUEnever evaluated
FALSEevaluated 66 times by 1 test
Evaluated by:
  • evptest
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:
  • evptest
66
402 }-
403-
404 n = b - bl;-
405 for (i = bl; i < b; i++)
i < bDescription
TRUEevaluated 884 times by 3 tests
Evaluated by:
  • libcrypto.so.44.0.1
  • pkcs7test
  • ssltest
FALSEevaluated 104 times by 3 tests
Evaluated by:
  • libcrypto.so.44.0.1
  • pkcs7test
  • ssltest
104-884
406 ctx->buf[i] = n;
executed 884 times by 3 tests: ctx->buf[i] = n;
Executed by:
  • libcrypto.so.44.0.1
  • pkcs7test
  • ssltest
884
407 ret = M_do_cipher(ctx, out, ctx->buf, b);-
408-
409-
410 if (ret)
retDescription
TRUEevaluated 104 times by 3 tests
Evaluated by:
  • libcrypto.so.44.0.1
  • pkcs7test
  • ssltest
FALSEnever evaluated
0-104
411 *outl = b;
executed 104 times by 3 tests: *outl = b;
Executed by:
  • libcrypto.so.44.0.1
  • pkcs7test
  • ssltest
104
412-
413 return ret;
executed 104 times by 3 tests: return ret;
Executed by:
  • libcrypto.so.44.0.1
  • pkcs7test
  • ssltest
104
414}-
415-
416int-
417EVP_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) {
ctx->cipher->flags & 0x100000Description
TRUEnever evaluated
FALSEevaluated 213 times by 3 tests
Evaluated by:
  • evptest
  • libcrypto.so.44.0.1
  • pkcs7test
0-213
424 fix_len = M_do_cipher(ctx, out, in, inl);-
425 if (fix_len < 0) {
fix_len < 0Description
TRUEnever evaluated
FALSEnever evaluated
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) {
inl <= 0Description
TRUEnever evaluated
FALSEevaluated 213 times by 3 tests
Evaluated by:
  • evptest
  • libcrypto.so.44.0.1
  • pkcs7test
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)
ctx->flags & 0x100Description
TRUEevaluated 114 times by 1 test
Evaluated by:
  • evptest
FALSEevaluated 99 times by 2 tests
Evaluated by:
  • libcrypto.so.44.0.1
  • pkcs7test
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:
  • evptest
114
440-
441 b = ctx->cipher->block_size;-
442 if (b > sizeof ctx->final) {
b > sizeof ctx->finalDescription
TRUEnever evaluated
FALSEevaluated 99 times by 2 tests
Evaluated by:
  • libcrypto.so.44.0.1
  • pkcs7test
0-99
443 EVPerror(EVP_R_BAD_BLOCK_LENGTH);-
444 return 0;
never executed: return 0;
0
445 }-
446-
447 if (ctx->final_used) {
ctx->final_usedDescription
TRUEnever evaluated
FALSEevaluated 99 times by 2 tests
Evaluated by:
  • libcrypto.so.44.0.1
  • pkcs7test
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:
  • libcrypto.so.44.0.1
  • pkcs7test
99
453-
454-
455 if (!EVP_EncryptUpdate(ctx, out, outl, in, inl))
!EVP_EncryptUp...outl, in, inl)Description
TRUEnever evaluated
FALSEevaluated 99 times by 2 tests
Evaluated by:
  • libcrypto.so.44.0.1
  • pkcs7test
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) {
b > 1Description
TRUEevaluated 45 times by 2 tests
Evaluated by:
  • libcrypto.so.44.0.1
  • pkcs7test
FALSEevaluated 54 times by 1 test
Evaluated by:
  • libcrypto.so.44.0.1
!ctx->buf_lenDescription
TRUEevaluated 45 times by 2 tests
Evaluated by:
  • libcrypto.so.44.0.1
  • pkcs7test
FALSEnever evaluated
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:
  • libcrypto.so.44.0.1
  • pkcs7test
45
465 ctx->final_used = 0;
executed 54 times by 1 test: ctx->final_used = 0;
Executed by:
  • libcrypto.so.44.0.1
54
466-
467 if (fix_len)
fix_lenDescription
TRUEnever evaluated
FALSEevaluated 99 times by 2 tests
Evaluated by:
  • libcrypto.so.44.0.1
  • pkcs7test
0-99
468 *outl += b;
never executed: *outl += b;
0
469-
470 return 1;
executed 99 times by 2 tests: return 1;
Executed by:
  • libcrypto.so.44.0.1
  • pkcs7test
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-
476int-
477EVP_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-
485int-
486EVP_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) {
ctx->cipher->flags & 0x100000Description
TRUEnever evaluated
FALSEevaluated 213 times by 3 tests
Evaluated by:
  • evptest
  • libcrypto.so.44.0.1
  • pkcs7test
0-213
493 i = M_do_cipher(ctx, out, NULL, 0);-
494 if (i < 0)
i < 0Description
TRUEnever evaluated
FALSEnever evaluated
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) {
ctx->flags & 0x100Description
TRUEevaluated 114 times by 1 test
Evaluated by:
  • evptest
FALSEevaluated 99 times by 2 tests
Evaluated by:
  • libcrypto.so.44.0.1
  • pkcs7test
99-114
503 if (ctx->buf_len) {
ctx->buf_lenDescription
TRUEnever evaluated
FALSEevaluated 114 times by 1 test
Evaluated by:
  • evptest
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:
  • evptest
114
509 }-
510 if (b > 1) {
b > 1Description
TRUEevaluated 45 times by 2 tests
Evaluated by:
  • libcrypto.so.44.0.1
  • pkcs7test
FALSEevaluated 54 times by 1 test
Evaluated by:
  • libcrypto.so.44.0.1
45-54
511 if (ctx->buf_len || !ctx->final_used) {
ctx->buf_lenDescription
TRUEnever evaluated
FALSEevaluated 45 times by 2 tests
Evaluated by:
  • libcrypto.so.44.0.1
  • pkcs7test
!ctx->final_usedDescription
TRUEnever evaluated
FALSEevaluated 45 times by 2 tests
Evaluated by:
  • libcrypto.so.44.0.1
  • pkcs7test
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) {
b > sizeof ctx->finalDescription
TRUEnever evaluated
FALSEevaluated 45 times by 2 tests
Evaluated by:
  • libcrypto.so.44.0.1
  • pkcs7test
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) {
n == 0Description
TRUEnever evaluated
FALSEevaluated 45 times by 2 tests
Evaluated by:
  • libcrypto.so.44.0.1
  • pkcs7test
n > (int)bDescription
TRUEnever evaluated
FALSEevaluated 45 times by 2 tests
Evaluated by:
  • libcrypto.so.44.0.1
  • pkcs7test
0-45
521 EVPerror(EVP_R_BAD_DECRYPT);-
522 return (0);
never executed: return (0);
0
523 }-
524 for (i = 0; i < n; i++) {
i < nDescription
TRUEevaluated 362 times by 2 tests
Evaluated by:
  • libcrypto.so.44.0.1
  • pkcs7test
FALSEevaluated 45 times by 2 tests
Evaluated by:
  • libcrypto.so.44.0.1
  • pkcs7test
45-362
525 if (ctx->final[--b] != n) {
ctx->final[--b] != nDescription
TRUEnever evaluated
FALSEevaluated 362 times by 2 tests
Evaluated by:
  • libcrypto.so.44.0.1
  • pkcs7test
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:
  • libcrypto.so.44.0.1
  • pkcs7test
362
530 n = ctx->cipher->block_size - n;-
531 for (i = 0; i < n; i++)
i < nDescription
TRUEevaluated 102 times by 2 tests
Evaluated by:
  • libcrypto.so.44.0.1
  • pkcs7test
FALSEevaluated 45 times by 2 tests
Evaluated by:
  • libcrypto.so.44.0.1
  • pkcs7test
45-102
532 out[i] = ctx->final[i];
executed 102 times by 2 tests: out[i] = ctx->final[i];
Executed by:
  • libcrypto.so.44.0.1
  • pkcs7test
102
533 *outl = n;-
534 } else
executed 45 times by 2 tests: end of block
Executed by:
  • libcrypto.so.44.0.1
  • pkcs7test
45
535 *outl = 0;
executed 54 times by 1 test: *outl = 0;
Executed by:
  • libcrypto.so.44.0.1
54
536 return (1);
executed 99 times by 2 tests: return (1);
Executed by:
  • libcrypto.so.44.0.1
  • pkcs7test
99
537}-
538-
539EVP_CIPHER_CTX *-
540EVP_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:
  • ssltest
160
543}-
544-
545void-
546EVP_CIPHER_CTX_free(EVP_CIPHER_CTX *ctx)-
547{-
548 if (ctx == NULL)
ctx == ((void *)0)Description
TRUEevaluated 1432 times by 12 tests
Evaluated by:
  • cipher_list
  • cipherstest
  • clienttest
  • freenull
  • libcrypto.so.44.0.1
  • servertest
  • ssl_versions
  • ssltest
  • tls_ext_alpn
  • tls_prf
  • tlsexttest
  • tlstest
FALSEevaluated 160 times by 1 test
Evaluated by:
  • ssltest
160-1432
549 return;
executed 1432 times by 12 tests: return;
Executed by:
  • cipher_list
  • cipherstest
  • clienttest
  • freenull
  • libcrypto.so.44.0.1
  • servertest
  • ssl_versions
  • ssltest
  • tls_ext_alpn
  • tls_prf
  • tlsexttest
  • tlstest
1432
550-
551 EVP_CIPHER_CTX_cleanup(ctx);-
552-
553 free(ctx);-
554}
executed 160 times by 1 test: end of block
Executed by:
  • ssltest
160
555-
556void-
557EVP_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:
  • evptest
  • gost2814789t
  • libcrypto.so.44.0.1
  • pkcs7test
  • ssltest
454
561-
562int-
563EVP_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-
568int-
569EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *c)-
570{-
571 if (c->cipher != NULL) {
c->cipher != ((void *)0)Description
TRUEevaluated 680 times by 5 tests
Evaluated by:
  • evptest
  • gost2814789t
  • libcrypto.so.44.0.1
  • pkcs7test
  • ssltest
FALSEnever evaluated
0-680
572 if (c->cipher->cleanup && !c->cipher->cleanup(c))
c->cipher->cleanupDescription
TRUEnever evaluated
FALSEevaluated 680 times by 5 tests
Evaluated by:
  • evptest
  • gost2814789t
  • libcrypto.so.44.0.1
  • pkcs7test
  • ssltest
!c->cipher->cleanup(c)Description
TRUEnever evaluated
FALSEnever evaluated
0-680
573 return 0;
never executed: return 0;
0
574 /* Cleanse cipher context data */-
575 if (c->cipher_data)
c->cipher_dataDescription
TRUEevaluated 668 times by 5 tests
Evaluated by:
  • evptest
  • gost2814789t
  • libcrypto.so.44.0.1
  • pkcs7test
  • ssltest
FALSEevaluated 12 times by 1 test
Evaluated by:
  • ssltest
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:
  • evptest
  • gost2814789t
  • libcrypto.so.44.0.1
  • pkcs7test
  • ssltest
668
577 }
executed 680 times by 5 tests: end of block
Executed by:
  • evptest
  • gost2814789t
  • libcrypto.so.44.0.1
  • pkcs7test
  • ssltest
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:
  • evptest
  • gost2814789t
  • libcrypto.so.44.0.1
  • pkcs7test
  • ssltest
680
584}-
585-
586int-
587EVP_CIPHER_CTX_set_key_length(EVP_CIPHER_CTX *c, int keylen)-
588{-
589 if (c->cipher->flags & EVP_CIPH_CUSTOM_KEY_LENGTH)
c->cipher->flags & 0x80Description
TRUEnever evaluated
FALSEnever evaluated
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)
c->key_len == keylenDescription
TRUEnever evaluated
FALSEnever evaluated
0
593 return 1;
never executed: return 1;
0
594 if ((keylen > 0) && (c->cipher->flags & EVP_CIPH_VARIABLE_LENGTH)) {
(keylen > 0)Description
TRUEnever evaluated
FALSEnever evaluated
(c->cipher->flags & 0x8)Description
TRUEnever evaluated
FALSEnever evaluated
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-
602int-
603EVP_CIPHER_CTX_set_padding(EVP_CIPHER_CTX *ctx, int pad)-
604{-
605 if (pad)
padDescription
TRUEnever evaluated
FALSEevaluated 251 times by 1 test
Evaluated by:
  • evptest
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:
  • evptest
251
609 return 1;
executed 251 times by 1 test: return 1;
Executed by:
  • evptest
251
610}-
611-
612int-
613EVP_CIPHER_CTX_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr)-
614{-
615 int ret;-
616-
617 if (!ctx->cipher) {
!ctx->cipherDescription
TRUEnever evaluated
FALSEevaluated 48 times by 2 tests
Evaluated by:
  • gost2814789t
  • libcrypto.so.44.0.1
0-48
618 EVPerror(EVP_R_NO_CIPHER_SET);-
619 return 0;
never executed: return 0;
0
620 }-
621-
622 if (!ctx->cipher->ctrl) {
!ctx->cipher->ctrlDescription
TRUEnever evaluated
FALSEevaluated 48 times by 2 tests
Evaluated by:
  • gost2814789t
  • libcrypto.so.44.0.1
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) {
ret == -1Description
TRUEnever evaluated
FALSEevaluated 48 times by 2 tests
Evaluated by:
  • gost2814789t
  • libcrypto.so.44.0.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:
  • gost2814789t
  • libcrypto.so.44.0.1
48
633}-
634-
635int-
636EVP_CIPHER_CTX_rand_key(EVP_CIPHER_CTX *ctx, unsigned char *key)-
637{-
638 if (ctx->cipher->flags & EVP_CIPH_RAND_KEY)
ctx->cipher->flags & 0x200Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • pkcs7test
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:
  • pkcs7test
2
642}-
643-
644int-
645EVP_CIPHER_CTX_copy(EVP_CIPHER_CTX *out, const EVP_CIPHER_CTX *in)-
646{-
647 if ((in == NULL) || (in->cipher == NULL)) {
(in == ((void *)0) )Description
TRUEnever evaluated
FALSEnever evaluated
(in->cipher == ((void *)0) )Description
TRUEnever evaluated
FALSEnever evaluated
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)) {
in->engineDescription
TRUEnever evaluated
FALSEnever evaluated
!ENGINE_init(in->engine)Description
TRUEnever evaluated
FALSEnever evaluated
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) {
in->cipher_dataDescription
TRUEnever evaluated
FALSEnever evaluated
in->cipher->ctx_sizeDescription
TRUEnever evaluated
FALSEnever evaluated
0
663 out->cipher_data = malloc(in->cipher->ctx_size);-
664 if (!out->cipher_data) {
!out->cipher_dataDescription
TRUEnever evaluated
FALSEnever evaluated
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)
in->cipher->flags & 0x400Description
TRUEnever evaluated
FALSEnever evaluated
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 codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.2