OpenCoverage

evp_enc.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/evp/evp_enc.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/*-
2 * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.-
3 *-
4 * Licensed under the OpenSSL license (the "License"). You may not use-
5 * this file except in compliance with the License. You can obtain a copy-
6 * in the file LICENSE in the source distribution or at-
7 * https://www.openssl.org/source/license.html-
8 */-
9-
10#include <stdio.h>-
11#include <assert.h>-
12#include "internal/cryptlib.h"-
13#include <openssl/evp.h>-
14#include <openssl/err.h>-
15#include <openssl/rand.h>-
16#include <openssl/rand_drbg.h>-
17#include <openssl/engine.h>-
18#include "internal/evp_int.h"-
19#include "evp_locl.h"-
20-
21int EVP_CIPHER_CTX_reset(EVP_CIPHER_CTX *c)-
22{-
23 if (c == NULL)
c == ((void *)0)Description
TRUEevaluated 8965 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 3259726 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
8965-3259726
24 return 1;
executed 8965 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
8965
25 if (c->cipher != NULL) {
c->cipher != ((void *)0)Description
TRUEevaluated 3252687 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 13304 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
13304-3252687
26 if (c->cipher->cleanup && !c->cipher->cleanup(c))
c->cipher->cleanupDescription
TRUEevaluated 14517 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 3232397 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
!c->cipher->cleanup(c)Description
TRUEnever evaluated
FALSEevaluated 14517 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-3232397
27 return 0;
never executed: return 0;
0
28 /* Cleanse cipher context data */-
29 if (c->cipher_data && c->cipher->ctx_size)
c->cipher_dataDescription
TRUEevaluated 3247908 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 79 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
c->cipher->ctx_sizeDescription
TRUEevaluated 3256262 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 6645 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
79-3256262
30 OPENSSL_cleanse(c->cipher_data, c->cipher->ctx_size);
executed 3253969 times by 2 tests: OPENSSL_cleanse(c->cipher_data, c->cipher->ctx_size);
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
3253969
31 }
executed 3274767 times by 2 tests: end of block
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
3274767
32 OPENSSL_free(c->cipher_data);-
33#ifndef OPENSSL_NO_ENGINE-
34 ENGINE_finish(c->engine);-
35#endif-
36 memset(c, 0, sizeof(*c));-
37 return 1;
executed 3267094 times by 2 tests: return 1;
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
3267094
38}-
39-
40EVP_CIPHER_CTX *EVP_CIPHER_CTX_new(void)-
41{-
42 return OPENSSL_zalloc(sizeof(EVP_CIPHER_CTX));
executed 78927 times by 2 tests: return CRYPTO_zalloc(sizeof(EVP_CIPHER_CTX), __FILE__, 42);
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
78927
43}-
44-
45void EVP_CIPHER_CTX_free(EVP_CIPHER_CTX *ctx)-
46{-
47 EVP_CIPHER_CTX_reset(ctx);-
48 OPENSSL_free(ctx);-
49}
executed 87892 times by 2 tests: end of block
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
87892
50-
51int EVP_CipherInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,-
52 const unsigned char *key, const unsigned char *iv, int enc)-
53{-
54 if (cipher != NULL)
cipher != ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
55 EVP_CIPHER_CTX_reset(ctx);
never executed: EVP_CIPHER_CTX_reset(ctx);
0
56 return EVP_CipherInit_ex(ctx, cipher, NULL, key, iv, enc);
never executed: return EVP_CipherInit_ex(ctx, cipher, ((void *)0) , key, iv, enc);
0
57}-
58-
59int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,-
60 ENGINE *impl, const unsigned char *key,-
61 const unsigned char *iv, int enc)-
62{-
63 if (enc == -1)
enc == -1Description
TRUEevaluated 11850 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 3268282 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
11850-3268282
64 enc = ctx->encrypt;
executed 11850 times by 1 test: enc = ctx->encrypt;
Executed by:
  • libcrypto.so.1.1
11850
65 else {-
66 if (enc)
encDescription
TRUEevaluated 3212285 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 48724 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
48724-3212285
67 enc = 1;
executed 3207314 times by 2 tests: enc = 1;
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
3207314
68 ctx->encrypt = enc;-
69 }
executed 3270978 times by 2 tests: end of block
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
3270978
70#ifndef OPENSSL_NO_ENGINE-
71 /*-
72 * Whether it's nice or not, "Inits" can be used on "Final"'d contexts so-
73 * this context may already have an ENGINE! Try to avoid releasing the-
74 * previous handle, re-querying for an ENGINE, and having a-
75 * reinitialisation, when it may all be unnecessary.-
76 */-
77 if (ctx->engine && ctx->cipher
ctx->engineDescription
TRUEevaluated 1338 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 3268681 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
ctx->cipherDescription
TRUEevaluated 1338 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-3268681
78 && (cipher == NULL || cipher->nid == ctx->cipher->nid))
cipher == ((void *)0)Description
TRUEevaluated 1338 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
cipher->nid ==...x->cipher->nidDescription
TRUEnever evaluated
FALSEnever evaluated
0-1338
79 goto skip_to_init;
executed 1338 times by 1 test: goto skip_to_init;
Executed by:
  • libcrypto.so.1.1
1338
80#endif-
81 if (cipher) {
cipherDescription
TRUEevaluated 3246307 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 44958 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
44958-3246307
82 /*-
83 * Ensure a context left lying around from last time is cleared (the-
84 * previous check attempted to avoid this if the same ENGINE and-
85 * EVP_CIPHER could be used).-
86 */-
87 if (ctx->cipher) {
ctx->cipherDescription
TRUEevaluated 3174184 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 70747 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
70747-3174184
88 unsigned long flags = ctx->flags;-
89 EVP_CIPHER_CTX_reset(ctx);-
90 /* Restore encrypt and flags */-
91 ctx->encrypt = enc;-
92 ctx->flags = flags;-
93 }
executed 3149954 times by 2 tests: end of block
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
3149954
94#ifndef OPENSSL_NO_ENGINE-
95 if (impl) {
implDescription
TRUEevaluated 6 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 3198085 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
6-3198085
96 if (!ENGINE_init(impl)) {
!ENGINE_init(impl)Description
TRUEnever evaluated
FALSEevaluated 6 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-6
97 EVPerr(EVP_F_EVP_CIPHERINIT_EX, EVP_R_INITIALIZATION_ERROR);-
98 return 0;
never executed: return 0;
0
99 }-
100 } else
executed 6 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
6
101 /* Ask if an ENGINE is reserved for this job */-
102 impl = ENGINE_get_cipher_engine(cipher->nid);
executed 3210132 times by 2 tests: impl = ENGINE_get_cipher_engine(cipher->nid);
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
3210132
103 if (impl) {
implDescription
TRUEevaluated 757 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 3200483 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
757-3200483
104 /* There's an ENGINE for this job ... (apparently) */-
105 const EVP_CIPHER *c = ENGINE_get_cipher(impl, cipher->nid);-
106 if (!c) {
!cDescription
TRUEnever evaluated
FALSEevaluated 757 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-757
107 /*-
108 * One positive side-effect of US's export control history,-
109 * is that we should at least be able to avoid using US-
110 * misspellings of "initialisation"?-
111 */-
112 EVPerr(EVP_F_EVP_CIPHERINIT_EX, EVP_R_INITIALIZATION_ERROR);-
113 return 0;
never executed: return 0;
0
114 }-
115 /* We'll use the ENGINE's private cipher definition */-
116 cipher = c;-
117 /*-
118 * Store the ENGINE functional reference so we know 'cipher' came-
119 * from an ENGINE and we need to release it when done.-
120 */-
121 ctx->engine = impl;-
122 } else
executed 757 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
757
123 ctx->engine = NULL;
executed 3224519 times by 2 tests: ctx->engine = ((void *)0) ;
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
3224519
124#endif-
125-
126 ctx->cipher = cipher;-
127 if (ctx->cipher->ctx_size) {
ctx->cipher->ctx_sizeDescription
TRUEevaluated 3217950 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 6724 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
6724-3217950
128 ctx->cipher_data = OPENSSL_zalloc(ctx->cipher->ctx_size);-
129 if (ctx->cipher_data == NULL) {
ctx->cipher_da...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 3198603 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
0-3198603
130 ctx->cipher = NULL;-
131 EVPerr(EVP_F_EVP_CIPHERINIT_EX, ERR_R_MALLOC_FAILURE);-
132 return 0;
never executed: return 0;
0
133 }-
134 } else {
executed 3185841 times by 2 tests: end of block
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
3185841
135 ctx->cipher_data = NULL;-
136 }
executed 6724 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
6724
137 ctx->key_len = cipher->key_len;-
138 /* Preserve wrap enable flag, zero everything else */-
139 ctx->flags &= EVP_CIPHER_CTX_FLAG_WRAP_ALLOW;-
140 if (ctx->cipher->flags & EVP_CIPH_CTRL_INIT) {
ctx->cipher->flags & 0x40Description
TRUEevaluated 15840 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 3236914 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
15840-3236914
141 if (!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_INIT, 0, NULL)) {
!EVP_CIPHER_CT... ((void *)0) )Description
TRUEnever evaluated
FALSEevaluated 15840 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-15840
142 ctx->cipher = NULL;-
143 EVPerr(EVP_F_EVP_CIPHERINIT_EX, EVP_R_INITIALIZATION_ERROR);-
144 return 0;
never executed: return 0;
0
145 }-
146 }
executed 15840 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
15840
147 } else if (!ctx->cipher) {
executed 3262368 times by 2 tests: end of block
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
!ctx->cipherDescription
TRUEnever evaluated
FALSEevaluated 44958 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-3262368
148 EVPerr(EVP_F_EVP_CIPHERINIT_EX, EVP_R_NO_CIPHER_SET);-
149 return 0;
never executed: return 0;
0
150 }-
151#ifndef OPENSSL_NO_ENGINE-
152 skip_to_init:
code before this statement executed 3291146 times by 2 tests: skip_to_init:
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
3291146
153#endif-
154 /* we assume block size is a power of 2 in *cryptUpdate */-
155 OPENSSL_assert(ctx->cipher->block_size == 1-
156 || ctx->cipher->block_size == 8-
157 || ctx->cipher->block_size == 16);-
158-
159 if (!(ctx->flags & EVP_CIPHER_CTX_FLAG_WRAP_ALLOW)
!(ctx->flags & 0x1)Description
TRUEevaluated 3270346 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 12378 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
12378-3270346
160 && EVP_CIPHER_CTX_mode(ctx) == EVP_CIPH_WRAP_MODE) {
(EVP_CIPHER_fl...07) == 0x10002Description
TRUEnever evaluated
FALSEevaluated 3284593 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
0-3284593
161 EVPerr(EVP_F_EVP_CIPHERINIT_EX, EVP_R_WRAP_MODE_NOT_ALLOWED);-
162 return 0;
never executed: return 0;
0
163 }-
164-
165 if (!(EVP_CIPHER_flags(EVP_CIPHER_CTX_cipher(ctx)) & EVP_CIPH_CUSTOM_IV)) {
!(EVP_CIPHER_f...(ctx)) & 0x10)Description
TRUEevaluated 3240148 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 64194 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
64194-3240148
166 switch (EVP_CIPHER_CTX_mode(ctx)) {-
167-
168 case EVP_CIPH_STREAM_CIPHER:
executed 391 times by 1 test: case 0x0:
Executed by:
  • libcrypto.so.1.1
391
169 case EVP_CIPH_ECB_MODE:
executed 3214221 times by 2 tests: case 0x1:
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
3214221
170 break;
executed 3204513 times by 2 tests: break;
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
3204513
171-
172 case EVP_CIPH_CFB_MODE:
executed 8004 times by 1 test: case 0x3:
Executed by:
  • libcrypto.so.1.1
8004
173 case EVP_CIPH_OFB_MODE:
executed 7652 times by 1 test: case 0x4:
Executed by:
  • libcrypto.so.1.1
7652
174-
175 ctx->num = 0;-
176 /* fall-through */-
177-
178 case EVP_CIPH_CBC_MODE:
code before this statement executed 15656 times by 1 test: case 0x2:
Executed by:
  • libcrypto.so.1.1
executed 12951 times by 1 test: case 0x2:
Executed by:
  • libcrypto.so.1.1
12951-15656
179-
180 OPENSSL_assert(EVP_CIPHER_CTX_iv_length(ctx) <=-
181 (int)sizeof(ctx->iv));-
182 if (iv)
ivDescription
TRUEevaluated 16621 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 11986 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
11986-16621
183 memcpy(ctx->oiv, iv, EVP_CIPHER_CTX_iv_length(ctx));
executed 16621 times by 1 test: memcpy(ctx->oiv, iv, EVP_CIPHER_CTX_iv_length(ctx));
Executed by:
  • libcrypto.so.1.1
16621
184 memcpy(ctx->iv, ctx->oiv, EVP_CIPHER_CTX_iv_length(ctx));-
185 break;
executed 28607 times by 1 test: break;
Executed by:
  • libcrypto.so.1.1
28607
186-
187 case EVP_CIPH_CTR_MODE:
executed 6884 times by 1 test: case 0x5:
Executed by:
  • libcrypto.so.1.1
6884
188 ctx->num = 0;-
189 /* Don't reuse IV for CTR mode */-
190 if (iv)
ivDescription
TRUEevaluated 3442 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 3442 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
3442
191 memcpy(ctx->iv, iv, EVP_CIPHER_CTX_iv_length(ctx));
executed 3442 times by 1 test: memcpy(ctx->iv, iv, EVP_CIPHER_CTX_iv_length(ctx));
Executed by:
  • libcrypto.so.1.1
3442
192 break;
executed 6884 times by 1 test: break;
Executed by:
  • libcrypto.so.1.1
6884
193-
194 default:
never executed: default:
0
195 return 0;
never executed: return 0;
0
196 }-
197 }-
198-
199 if (key || (ctx->cipher->flags & EVP_CIPH_ALWAYS_CALL_INIT)) {
keyDescription
TRUEevaluated 3257506 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 46296 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
(ctx->cipher->flags & 0x20)Description
TRUEevaluated 41763 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 4533 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
4533-3257506
200 if (!ctx->cipher->init(ctx, key, iv, enc))
!ctx->cipher->... key, iv, enc)Description
TRUEnever evaluated
FALSEevaluated 3221972 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
0-3221972
201 return 0;
never executed: return 0;
0
202 }
executed 3223980 times by 2 tests: end of block
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
3223980
203 ctx->buf_len = 0;-
204 ctx->final_used = 0;-
205 ctx->block_mask = ctx->cipher->block_size - 1;-
206 return 1;
executed 3201095 times by 2 tests: return 1;
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
3201095
207}-
208-
209int EVP_CipherUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,-
210 const unsigned char *in, int inl)-
211{-
212 if (ctx->encrypt)
ctx->encryptDescription
TRUEevaluated 28719072 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 107643 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
107643-28719072
213 return EVP_EncryptUpdate(ctx, out, outl, in, inl);
executed 28549154 times by 2 tests: return EVP_EncryptUpdate(ctx, out, outl, in, inl);
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
28549154
214 else-
215 return EVP_DecryptUpdate(ctx, out, outl, in, inl);
executed 107643 times by 1 test: return EVP_DecryptUpdate(ctx, out, outl, in, inl);
Executed by:
  • libcrypto.so.1.1
107643
216}-
217-
218int EVP_CipherFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)-
219{-
220 if (ctx->encrypt)
ctx->encryptDescription
TRUEevaluated 34482 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 43062 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
34482-43062
221 return EVP_EncryptFinal_ex(ctx, out, outl);
executed 34482 times by 1 test: return EVP_EncryptFinal_ex(ctx, out, outl);
Executed by:
  • libcrypto.so.1.1
34482
222 else-
223 return EVP_DecryptFinal_ex(ctx, out, outl);
executed 43062 times by 1 test: return EVP_DecryptFinal_ex(ctx, out, outl);
Executed by:
  • libcrypto.so.1.1
43062
224}-
225-
226int EVP_CipherFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)-
227{-
228 if (ctx->encrypt)
ctx->encryptDescription
TRUEnever evaluated
FALSEnever evaluated
0
229 return EVP_EncryptFinal(ctx, out, outl);
never executed: return EVP_EncryptFinal(ctx, out, outl);
0
230 else-
231 return EVP_DecryptFinal(ctx, out, outl);
never executed: return EVP_DecryptFinal(ctx, out, outl);
0
232}-
233-
234int EVP_EncryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,-
235 const unsigned char *key, const unsigned char *iv)-
236{-
237 return EVP_CipherInit(ctx, cipher, key, iv, 1);
never executed: return EVP_CipherInit(ctx, cipher, key, iv, 1);
0
238}-
239-
240int EVP_EncryptInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,-
241 ENGINE *impl, const unsigned char *key,-
242 const unsigned char *iv)-
243{-
244 return EVP_CipherInit_ex(ctx, cipher, impl, key, iv, 1);
executed 1774 times by 1 test: return EVP_CipherInit_ex(ctx, cipher, impl, key, iv, 1);
Executed by:
  • libcrypto.so.1.1
1774
245}-
246-
247int EVP_DecryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,-
248 const unsigned char *key, const unsigned char *iv)-
249{-
250 return EVP_CipherInit(ctx, cipher, key, iv, 0);
never executed: return EVP_CipherInit(ctx, cipher, key, iv, 0);
0
251}-
252-
253int EVP_DecryptInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,-
254 ENGINE *impl, const unsigned char *key,-
255 const unsigned char *iv)-
256{-
257 return EVP_CipherInit_ex(ctx, cipher, impl, key, iv, 0);
executed 223 times by 1 test: return EVP_CipherInit_ex(ctx, cipher, impl, key, iv, 0);
Executed by:
  • libcrypto.so.1.1
223
258}-
259-
260/*-
261 * According to the letter of standard difference between pointers-
262 * is specified to be valid only within same object. This makes-
263 * it formally challenging to determine if input and output buffers-
264 * are not partially overlapping with standard pointer arithmetic.-
265 */-
266#ifdef PTRDIFF_T-
267# undef PTRDIFF_T-
268#endif-
269#if defined(OPENSSL_SYS_VMS) && __INITIAL_POINTER_SIZE==64-
270/*-
271 * Then we have VMS that distinguishes itself by adhering to-
272 * sizeof(size_t)==4 even in 64-bit builds, which means that-
273 * difference between two pointers might be truncated to 32 bits.-
274 * In the context one can even wonder how comparison for-
275 * equality is implemented. To be on the safe side we adhere to-
276 * PTRDIFF_T even for comparison for equality.-
277 */-
278# define PTRDIFF_T uint64_t-
279#else-
280# define PTRDIFF_T size_t-
281#endif-
282-
283int is_partially_overlapping(const void *ptr1, const void *ptr2, int len)-
284{-
285 PTRDIFF_T diff = (PTRDIFF_T)ptr1-(PTRDIFF_T)ptr2;-
286 /*-
287 * Check for partially overlapping buffers. [Binary logical-
288 * operations are used instead of boolean to minimize number-
289 * of conditional branches.]-
290 */-
291 int overlapped = (len > 0) & (diff != 0) & ((diff < (PTRDIFF_T)len) |-
292 (diff > (0 - (PTRDIFF_T)len)));-
293-
294 return overlapped;
executed 30073570 times by 2 tests: return overlapped;
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
30073570
295}-
296-
297int EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,-
298 const unsigned char *in, int inl)-
299{-
300 int i, j, bl, cmpl = inl;-
301-
302 if (EVP_CIPHER_CTX_test_flags(ctx, EVP_CIPH_FLAG_LENGTH_BITS))
EVP_CIPHER_CTX...s(ctx, 0x2000)Description
TRUEnever evaluated
FALSEevaluated 28299335 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
0-28299335
303 cmpl = (cmpl + 7) / 8;
never executed: cmpl = (cmpl + 7) / 8;
0
304-
305 bl = ctx->cipher->block_size;-
306-
307 if (ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_CIPHER) {
ctx->cipher->flags & 0x100000Description
TRUEevaluated 36373 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 29385530 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
36373-29385530
308 /* If block size > 1 then the cipher will have to do this check */-
309 if (bl == 1 && is_partially_overlapping(out, in, cmpl)) {
bl == 1Description
TRUEevaluated 35423 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 950 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
is_partially_o...out, in, cmpl)Description
TRUEnever evaluated
FALSEevaluated 35423 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-35423
310 EVPerr(EVP_F_EVP_ENCRYPTUPDATE, EVP_R_PARTIALLY_OVERLAPPING);-
311 return 0;
never executed: return 0;
0
312 }-
313-
314 i = ctx->cipher->do_cipher(ctx, out, in, inl);-
315 if (i < 0)
i < 0Description
TRUEnever evaluated
FALSEevaluated 36373 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-36373
316 return 0;
never executed: return 0;
0
317 else-
318 *outl = i;
executed 36373 times by 1 test: *outl = i;
Executed by:
  • libcrypto.so.1.1
36373
319 return 1;
executed 36373 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
36373
320 }-
321-
322 if (inl <= 0) {
inl <= 0Description
TRUEnever evaluated
FALSEevaluated 30027432 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
0-30027432
323 *outl = 0;-
324 return inl == 0;
never executed: return inl == 0;
0
325 }-
326 if (is_partially_overlapping(out + ctx->buf_len, in, cmpl)) {
is_partially_o...len, in, cmpl)Description
TRUEnever evaluated
FALSEevaluated 30006938 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
0-30006938
327 EVPerr(EVP_F_EVP_ENCRYPTUPDATE, EVP_R_PARTIALLY_OVERLAPPING);-
328 return 0;
never executed: return 0;
0
329 }-
330-
331 if (ctx->buf_len == 0 && (inl & (ctx->block_mask)) == 0) {
ctx->buf_len == 0Description
TRUEevaluated 28971308 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 12738 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
(inl & (ctx->block_mask)) == 0Description
TRUEevaluated 29413053 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 7007 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
7007-29413053
332 if (ctx->cipher->do_cipher(ctx, out, in, inl)) {
ctx->cipher->d... out, in, inl)Description
TRUEevaluated 28321037 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
1-28321037
333 *outl = inl;-
334 return 1;
executed 28209791 times by 2 tests: return 1;
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
28209791
335 } else {-
336 *outl = 0;-
337 return 0;
executed 1 time by 1 test: return 0;
Executed by:
  • libcrypto.so.1.1
1
338 }-
339 }-
340 i = ctx->buf_len;-
341 OPENSSL_assert(bl <= (int)sizeof(ctx->buf));-
342 if (i != 0) {
i != 0Description
TRUEevaluated 12738 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 7007 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
7007-12738
343 if (bl - i > inl) {
bl - i > inlDescription
TRUEevaluated 898 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 11840 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
898-11840
344 memcpy(&(ctx->buf[i]), in, inl);-
345 ctx->buf_len += inl;-
346 *outl = 0;-
347 return 1;
executed 898 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
898
348 } else {-
349 j = bl - i;-
350 memcpy(&(ctx->buf[i]), in, j);-
351 inl -= j;-
352 in += j;-
353 if (!ctx->cipher->do_cipher(ctx, out, ctx->buf, bl))
!ctx->cipher->... ctx->buf, bl)Description
TRUEnever evaluated
FALSEevaluated 11840 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-11840
354 return 0;
never executed: return 0;
0
355 out += bl;-
356 *outl = bl;-
357 }
executed 11840 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
11840
358 } else-
359 *outl = 0;
executed 7007 times by 1 test: *outl = 0;
Executed by:
  • libcrypto.so.1.1
7007
360 i = inl & (bl - 1);-
361 inl -= i;-
362 if (inl > 0) {
inl > 0Description
TRUEevaluated 16691 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 2156 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
2156-16691
363 if (!ctx->cipher->do_cipher(ctx, out, in, inl))
!ctx->cipher->... out, in, inl)Description
TRUEnever evaluated
FALSEevaluated 16691 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-16691
364 return 0;
never executed: return 0;
0
365 *outl += inl;-
366 }
executed 16691 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
16691
367-
368 if (i != 0)
i != 0Description
TRUEevaluated 13675 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 5172 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
5172-13675
369 memcpy(ctx->buf, &(in[inl]), i);
executed 13675 times by 1 test: memcpy(ctx->buf, &(in[inl]), i);
Executed by:
  • libcrypto.so.1.1
13675
370 ctx->buf_len = i;-
371 return 1;
executed 18847 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
18847
372}-
373-
374int EVP_EncryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)-
375{-
376 int ret;-
377 ret = EVP_EncryptFinal_ex(ctx, out, outl);-
378 return ret;
executed 1750 times by 1 test: return ret;
Executed by:
  • libcrypto.so.1.1
1750
379}-
380-
381int EVP_EncryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)-
382{-
383 int n, ret;-
384 unsigned int i, b, bl;-
385-
386 if (ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_CIPHER) {
ctx->cipher->flags & 0x100000Description
TRUEevaluated 16244 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 19989 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
16244-19989
387 ret = ctx->cipher->do_cipher(ctx, out, NULL, 0);-
388 if (ret < 0)
ret < 0Description
TRUEnever evaluated
FALSEevaluated 16244 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-16244
389 return 0;
never executed: return 0;
0
390 else-
391 *outl = ret;
executed 16244 times by 1 test: *outl = ret;
Executed by:
  • libcrypto.so.1.1
16244
392 return 1;
executed 16244 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
16244
393 }-
394-
395 b = ctx->cipher->block_size;-
396 OPENSSL_assert(b <= sizeof(ctx->buf));-
397 if (b == 1) {
b == 1Description
TRUEevaluated 13935 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 6054 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
6054-13935
398 *outl = 0;-
399 return 1;
executed 13935 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
13935
400 }-
401 bl = ctx->buf_len;-
402 if (ctx->flags & EVP_CIPH_NO_PADDING) {
ctx->flags & 0x100Description
TRUEevaluated 996 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 5058 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
996-5058
403 if (bl) {
blDescription
TRUEnever evaluated
FALSEevaluated 996 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-996
404 EVPerr(EVP_F_EVP_ENCRYPTFINAL_EX,-
405 EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH);-
406 return 0;
never executed: return 0;
0
407 }-
408 *outl = 0;-
409 return 1;
executed 996 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
996
410 }-
411-
412 n = b - bl;-
413 for (i = bl; i < b; i++)
i < bDescription
TRUEevaluated 62228 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 5058 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
5058-62228
414 ctx->buf[i] = n;
executed 62228 times by 1 test: ctx->buf[i] = n;
Executed by:
  • libcrypto.so.1.1
62228
415 ret = ctx->cipher->do_cipher(ctx, out, ctx->buf, b);-
416-
417 if (ret)
retDescription
TRUEevaluated 5058 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-5058
418 *outl = b;
executed 5058 times by 1 test: *outl = b;
Executed by:
  • libcrypto.so.1.1
5058
419-
420 return ret;
executed 5058 times by 1 test: return ret;
Executed by:
  • libcrypto.so.1.1
5058
421}-
422-
423int EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,-
424 const unsigned char *in, int inl)-
425{-
426 int fix_len, cmpl = inl;-
427 unsigned int b;-
428-
429 b = ctx->cipher->block_size;-
430-
431 if (EVP_CIPHER_CTX_test_flags(ctx, EVP_CIPH_FLAG_LENGTH_BITS))
EVP_CIPHER_CTX...s(ctx, 0x2000)Description
TRUEnever evaluated
FALSEevaluated 107860 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-107860
432 cmpl = (cmpl + 7) / 8;
never executed: cmpl = (cmpl + 7) / 8;
0
433-
434 if (ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_CIPHER) {
ctx->cipher->flags & 0x100000Description
TRUEevaluated 54303 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 53557 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
53557-54303
435 if (b == 1 && is_partially_overlapping(out, in, cmpl)) {
b == 1Description
TRUEevaluated 53352 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 951 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
is_partially_o...out, in, cmpl)Description
TRUEnever evaluated
FALSEevaluated 53352 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-53352
436 EVPerr(EVP_F_EVP_DECRYPTUPDATE, EVP_R_PARTIALLY_OVERLAPPING);-
437 return 0;
never executed: return 0;
0
438 }-
439-
440 fix_len = ctx->cipher->do_cipher(ctx, out, in, inl);-
441 if (fix_len < 0) {
fix_len < 0Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 54301 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
2-54301
442 *outl = 0;-
443 return 0;
executed 2 times by 1 test: return 0;
Executed by:
  • libcrypto.so.1.1
2
444 } else-
445 *outl = fix_len;
executed 54301 times by 1 test: *outl = fix_len;
Executed by:
  • libcrypto.so.1.1
54301
446 return 1;
executed 54301 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
54301
447 }-
448-
449 if (inl <= 0) {
inl <= 0Description
TRUEnever evaluated
FALSEevaluated 53557 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-53557
450 *outl = 0;-
451 return inl == 0;
never executed: return inl == 0;
0
452 }-
453-
454 if (ctx->flags & EVP_CIPH_NO_PADDING)
ctx->flags & 0x100Description
TRUEevaluated 4032 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 49525 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
4032-49525
455 return EVP_EncryptUpdate(ctx, out, outl, in, inl);
executed 4032 times by 1 test: return EVP_EncryptUpdate(ctx, out, outl, in, inl);
Executed by:
  • libcrypto.so.1.1
4032
456-
457 OPENSSL_assert(b <= sizeof(ctx->final));-
458-
459 if (ctx->final_used) {
ctx->final_usedDescription
TRUEevaluated 2900 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 46625 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
2900-46625
460 /* see comment about PTRDIFF_T comparison above */-
461 if (((PTRDIFF_T)out == (PTRDIFF_T)in)
((size_t)out == (size_t)in)Description
TRUEnever evaluated
FALSEevaluated 2900 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-2900
462 || is_partially_overlapping(out, in, b)) {
is_partially_o...ng(out, in, b)Description
TRUEnever evaluated
FALSEevaluated 2900 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-2900
463 EVPerr(EVP_F_EVP_DECRYPTUPDATE, EVP_R_PARTIALLY_OVERLAPPING);-
464 return 0;
never executed: return 0;
0
465 }-
466 memcpy(out, ctx->final, b);-
467 out += b;-
468 fix_len = 1;-
469 } else
executed 2900 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
2900
470 fix_len = 0;
executed 46625 times by 1 test: fix_len = 0;
Executed by:
  • libcrypto.so.1.1
46625
471-
472 if (!EVP_EncryptUpdate(ctx, out, outl, in, inl))
!EVP_EncryptUp...outl, in, inl)Description
TRUEnever evaluated
FALSEevaluated 49525 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-49525
473 return 0;
never executed: return 0;
0
474-
475 /*-
476 * if we have 'decrypted' a multiple of block size, make sure we have a-
477 * copy of this last block-
478 */-
479 if (b > 1 && !ctx->buf_len) {
b > 1Description
TRUEevaluated 11630 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 37895 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
!ctx->buf_lenDescription
TRUEevaluated 6422 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 5208 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
5208-37895
480 *outl -= b;-
481 ctx->final_used = 1;-
482 memcpy(ctx->final, &out[*outl], b);-
483 } else
executed 6422 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
6422
484 ctx->final_used = 0;
executed 43103 times by 1 test: ctx->final_used = 0;
Executed by:
  • libcrypto.so.1.1
43103
485-
486 if (fix_len)
fix_lenDescription
TRUEevaluated 2900 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 46625 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
2900-46625
487 *outl += b;
executed 2900 times by 1 test: *outl += b;
Executed by:
  • libcrypto.so.1.1
2900
488-
489 return 1;
executed 49525 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
49525
490}-
491-
492int EVP_DecryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)-
493{-
494 int ret;-
495 ret = EVP_DecryptFinal_ex(ctx, out, outl);-
496 return ret;
executed 213 times by 1 test: return ret;
Executed by:
  • libcrypto.so.1.1
213
497}-
498-
499int EVP_DecryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)-
500{-
501 int i, n;-
502 unsigned int b;-
503 *outl = 0;-
504-
505 if (ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_CIPHER) {
ctx->cipher->flags & 0x100000Description
TRUEevaluated 25210 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 18069 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
18069-25210
506 i = ctx->cipher->do_cipher(ctx, out, NULL, 0);-
507 if (i < 0)
i < 0Description
TRUEevaluated 10601 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 14609 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
10601-14609
508 return 0;
executed 10601 times by 1 test: return 0;
Executed by:
  • libcrypto.so.1.1
10601
509 else-
510 *outl = i;
executed 14609 times by 1 test: *outl = i;
Executed by:
  • libcrypto.so.1.1
14609
511 return 1;
executed 14609 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
14609
512 }-
513-
514 b = ctx->cipher->block_size;-
515 if (ctx->flags & EVP_CIPH_NO_PADDING) {
ctx->flags & 0x100Description
TRUEevaluated 2112 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 15957 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
2112-15957
516 if (ctx->buf_len) {
ctx->buf_lenDescription
TRUEnever evaluated
FALSEevaluated 2112 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-2112
517 EVPerr(EVP_F_EVP_DECRYPTFINAL_EX,-
518 EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH);-
519 return 0;
never executed: return 0;
0
520 }-
521 *outl = 0;-
522 return 1;
executed 2112 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
2112
523 }-
524 if (b > 1) {
b > 1Description
TRUEevaluated 3526 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 12431 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
3526-12431
525 if (ctx->buf_len || !ctx->final_used) {
ctx->buf_lenDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 3524 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
!ctx->final_usedDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 3522 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
2-3524
526 EVPerr(EVP_F_EVP_DECRYPTFINAL_EX, EVP_R_WRONG_FINAL_BLOCK_LENGTH);-
527 return 0;
executed 4 times by 1 test: return 0;
Executed by:
  • libcrypto.so.1.1
4
528 }-
529 OPENSSL_assert(b <= sizeof(ctx->final));-
530-
531 /*-
532 * The following assumes that the ciphertext has been authenticated.-
533 * Otherwise it provides a padding oracle.-
534 */-
535 n = ctx->final[b - 1];-
536 if (n == 0 || n > (int)b) {
n == 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 3521 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
n > (int)bDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 3519 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
1-3521
537 EVPerr(EVP_F_EVP_DECRYPTFINAL_EX, EVP_R_BAD_DECRYPT);-
538 return 0;
executed 3 times by 1 test: return 0;
Executed by:
  • libcrypto.so.1.1
3
539 }-
540 for (i = 0; i < n; i++) {
i < nDescription
TRUEevaluated 52177 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 3515 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
3515-52177
541 if (ctx->final[--b] != n) {
ctx->final[--b] != nDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 52173 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
4-52173
542 EVPerr(EVP_F_EVP_DECRYPTFINAL_EX, EVP_R_BAD_DECRYPT);-
543 return 0;
executed 4 times by 1 test: return 0;
Executed by:
  • libcrypto.so.1.1
4
544 }-
545 }
executed 52173 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
52173
546 n = ctx->cipher->block_size - n;-
547 for (i = 0; i < n; i++)
i < nDescription
TRUEevaluated 3302 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 3515 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
3302-3515
548 out[i] = ctx->final[i];
executed 3302 times by 1 test: out[i] = ctx->final[i];
Executed by:
  • libcrypto.so.1.1
3302
549 *outl = n;-
550 } else
executed 3515 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
3515
551 *outl = 0;
executed 12431 times by 1 test: *outl = 0;
Executed by:
  • libcrypto.so.1.1
12431
552 return 1;
executed 15946 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
15946
553}-
554-
555int EVP_CIPHER_CTX_set_key_length(EVP_CIPHER_CTX *c, int keylen)-
556{-
557 if (c->cipher->flags & EVP_CIPH_CUSTOM_KEY_LENGTH)
c->cipher->flags & 0x80Description
TRUEnever evaluated
FALSEevaluated 6185 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-6185
558 return EVP_CIPHER_CTX_ctrl(c, EVP_CTRL_SET_KEY_LENGTH, keylen, NULL);
never executed: return EVP_CIPHER_CTX_ctrl(c, 0x1, keylen, ((void *)0) );
0
559 if (c->key_len == keylen)
c->key_len == keylenDescription
TRUEevaluated 6183 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
2-6183
560 return 1;
executed 6183 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
6183
561 if ((keylen > 0) && (c->cipher->flags & EVP_CIPH_VARIABLE_LENGTH)) {
(keylen > 0)Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
(c->cipher->flags & 0x8)Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-2
562 c->key_len = keylen;-
563 return 1;
executed 2 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
2
564 }-
565 EVPerr(EVP_F_EVP_CIPHER_CTX_SET_KEY_LENGTH, EVP_R_INVALID_KEY_LENGTH);-
566 return 0;
never executed: return 0;
0
567}-
568-
569int EVP_CIPHER_CTX_set_padding(EVP_CIPHER_CTX *ctx, int pad)-
570{-
571 if (pad)
padDescription
TRUEnever evaluated
FALSEevaluated 6176 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-6176
572 ctx->flags &= ~EVP_CIPH_NO_PADDING;
never executed: ctx->flags &= ~0x100;
0
573 else-
574 ctx->flags |= EVP_CIPH_NO_PADDING;
executed 6176 times by 1 test: ctx->flags |= 0x100;
Executed by:
  • libcrypto.so.1.1
6176
575 return 1;
executed 6176 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
6176
576}-
577-
578int EVP_CIPHER_CTX_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr)-
579{-
580 int ret;-
581-
582 if (!ctx->cipher) {
!ctx->cipherDescription
TRUEnever evaluated
FALSEevaluated 72983 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-72983
583 EVPerr(EVP_F_EVP_CIPHER_CTX_CTRL, EVP_R_NO_CIPHER_SET);-
584 return 0;
never executed: return 0;
0
585 }-
586-
587 if (!ctx->cipher->ctrl) {
!ctx->cipher->ctrlDescription
TRUEnever evaluated
FALSEevaluated 72983 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-72983
588 EVPerr(EVP_F_EVP_CIPHER_CTX_CTRL, EVP_R_CTRL_NOT_IMPLEMENTED);-
589 return 0;
never executed: return 0;
0
590 }-
591-
592 ret = ctx->cipher->ctrl(ctx, type, arg, ptr);-
593 if (ret == -1) {
ret == -1Description
TRUEnever evaluated
FALSEevaluated 72983 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-72983
594 EVPerr(EVP_F_EVP_CIPHER_CTX_CTRL,-
595 EVP_R_CTRL_OPERATION_NOT_IMPLEMENTED);-
596 return 0;
never executed: return 0;
0
597 }-
598 return ret;
executed 72983 times by 1 test: return ret;
Executed by:
  • libcrypto.so.1.1
72983
599}-
600-
601int EVP_CIPHER_CTX_rand_key(EVP_CIPHER_CTX *ctx, unsigned char *key)-
602{-
603 if (ctx->cipher->flags & EVP_CIPH_RAND_KEY)
ctx->cipher->flags & 0x200Description
TRUEevaluated 31 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 22 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
22-31
604 return EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_RAND_KEY, 0, key);
executed 31 times by 1 test: return EVP_CIPHER_CTX_ctrl(ctx, 0x6, 0, key);
Executed by:
  • libcrypto.so.1.1
31
605 if (RAND_priv_bytes(key, ctx->key_len) <= 0)
RAND_priv_byte...>key_len) <= 0Description
TRUEnever evaluated
FALSEevaluated 22 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-22
606 return 0;
never executed: return 0;
0
607 return 1;
executed 22 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
22
608}-
609-
610int EVP_CIPHER_CTX_copy(EVP_CIPHER_CTX *out, const EVP_CIPHER_CTX *in)-
611{-
612 if ((in == NULL) || (in->cipher == NULL)) {
(in == ((void *)0) )Description
TRUEnever evaluated
FALSEevaluated 8 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
(in->cipher == ((void *)0) )Description
TRUEnever evaluated
FALSEevaluated 8 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-8
613 EVPerr(EVP_F_EVP_CIPHER_CTX_COPY, EVP_R_INPUT_NOT_INITIALIZED);-
614 return 0;
never executed: return 0;
0
615 }-
616#ifndef OPENSSL_NO_ENGINE-
617 /* Make sure it's safe to copy a cipher context using an ENGINE */-
618 if (in->engine && !ENGINE_init(in->engine)) {
in->engineDescription
TRUEnever evaluated
FALSEevaluated 8 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
!ENGINE_init(in->engine)Description
TRUEnever evaluated
FALSEnever evaluated
0-8
619 EVPerr(EVP_F_EVP_CIPHER_CTX_COPY, ERR_R_ENGINE_LIB);-
620 return 0;
never executed: return 0;
0
621 }-
622#endif-
623-
624 EVP_CIPHER_CTX_reset(out);-
625 memcpy(out, in, sizeof(*out));-
626-
627 if (in->cipher_data && in->cipher->ctx_size) {
in->cipher_dataDescription
TRUEevaluated 8 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
in->cipher->ctx_sizeDescription
TRUEevaluated 8 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-8
628 out->cipher_data = OPENSSL_malloc(in->cipher->ctx_size);-
629 if (out->cipher_data == NULL) {
out->cipher_da...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 8 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-8
630 out->cipher = NULL;-
631 EVPerr(EVP_F_EVP_CIPHER_CTX_COPY, ERR_R_MALLOC_FAILURE);-
632 return 0;
never executed: return 0;
0
633 }-
634 memcpy(out->cipher_data, in->cipher_data, in->cipher->ctx_size);-
635 }
executed 8 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
8
636-
637 if (in->cipher->flags & EVP_CIPH_CUSTOM_COPY)
in->cipher->flags & 0x400Description
TRUEnever evaluated
FALSEevaluated 8 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-8
638 if (!in->cipher->ctrl((EVP_CIPHER_CTX *)in, EVP_CTRL_COPY, 0, out)) {
!in->cipher->c..., 0x8, 0, out)Description
TRUEnever evaluated
FALSEnever evaluated
0
639 out->cipher = NULL;-
640 EVPerr(EVP_F_EVP_CIPHER_CTX_COPY, EVP_R_INITIALIZATION_ERROR);-
641 return 0;
never executed: return 0;
0
642 }-
643 return 1;
executed 8 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
8
644}-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.2