OpenCoverage

e_des3.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/evp/e_des3.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 "internal/cryptlib.h"-
12#ifndef OPENSSL_NO_DES-
13# include <openssl/evp.h>-
14# include <openssl/objects.h>-
15# include "internal/evp_int.h"-
16# include <openssl/des.h>-
17# include <openssl/rand.h>-
18# include "evp_locl.h"-
19-
20typedef struct {-
21 union {-
22 double align;-
23 DES_key_schedule ks[3];-
24 } ks;-
25 union {-
26 void (*cbc) (const void *, void *, size_t,-
27 const DES_key_schedule *, unsigned char *);-
28 } stream;-
29} DES_EDE_KEY;-
30# define ks1 ks.ks[0]-
31# define ks2 ks.ks[1]-
32# define ks3 ks.ks[2]-
33-
34# if defined(AES_ASM) && (defined(__sparc) || defined(__sparc__))-
35/* ---------^^^ this is not a typo, just a way to detect that-
36 * assembler support was in general requested... */-
37# include "sparc_arch.h"-
38-
39extern unsigned int OPENSSL_sparcv9cap_P[];-
40-
41# define SPARC_DES_CAPABLE (OPENSSL_sparcv9cap_P[1] & CFR_DES)-
42-
43void des_t4_key_expand(const void *key, DES_key_schedule *ks);-
44void des_t4_ede3_cbc_encrypt(const void *inp, void *out, size_t len,-
45 const DES_key_schedule ks[3], unsigned char iv[8]);-
46void des_t4_ede3_cbc_decrypt(const void *inp, void *out, size_t len,-
47 const DES_key_schedule ks[3], unsigned char iv[8]);-
48# endif-
49-
50static int des_ede_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,-
51 const unsigned char *iv, int enc);-
52-
53static int des_ede3_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,-
54 const unsigned char *iv, int enc);-
55-
56static int des3_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr);-
57-
58# define data(ctx) EVP_C_DATA(DES_EDE_KEY,ctx)-
59-
60/*-
61 * Because of various casts and different args can't use-
62 * IMPLEMENT_BLOCK_CIPHER-
63 */-
64-
65static int des_ede_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,-
66 const unsigned char *in, size_t inl)-
67{-
68 BLOCK_CIPHER_ecb_loop()
never executed: return 1;
inl < blDescription
TRUEnever evaluated
FALSEevaluated 264 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
i <= inlDescription
TRUEevaluated 4128 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 264 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-4128
69 DES_ecb3_encrypt((const_DES_cblock *)(in + i),
executed 4128 times by 1 test: DES_ecb3_encrypt((const_DES_cblock *)(in + i), (DES_cblock *)(out + i), &((DES_EDE_KEY *)EVP_CIPHER_CTX_get_cipher_data(ctx))->ks.ks[0], &((DES_EDE_KEY *)EVP_CIPHER_CTX_get_cipher_data(ctx))->ks.ks[1], &((DES_EDE_KEY *)EVP_CIPHER_CTX_get_cipher_data(ctx))->ks.ks[2], EVP_CIPHER_CTX_encrypting(ctx));
Executed by:
  • libcrypto.so.1.1
4128
70 (DES_cblock *)(out + i),
executed 4128 times by 1 test: DES_ecb3_encrypt((const_DES_cblock *)(in + i), (DES_cblock *)(out + i), &((DES_EDE_KEY *)EVP_CIPHER_CTX_get_cipher_data(ctx))->ks.ks[0], &((DES_EDE_KEY *)EVP_CIPHER_CTX_get_cipher_data(ctx))->ks.ks[1], &((DES_EDE_KEY *)EVP_CIPHER_CTX_get_cipher_data(ctx))->ks.ks[2], EVP_CIPHER_CTX_encrypting(ctx));
Executed by:
  • libcrypto.so.1.1
4128
71 &data(ctx)->ks1, &data(ctx)->ks2,
executed 4128 times by 1 test: DES_ecb3_encrypt((const_DES_cblock *)(in + i), (DES_cblock *)(out + i), &((DES_EDE_KEY *)EVP_CIPHER_CTX_get_cipher_data(ctx))->ks.ks[0], &((DES_EDE_KEY *)EVP_CIPHER_CTX_get_cipher_data(ctx))->ks.ks[1], &((DES_EDE_KEY *)EVP_CIPHER_CTX_get_cipher_data(ctx))->ks.ks[2], EVP_CIPHER_CTX_encrypting(ctx));
Executed by:
  • libcrypto.so.1.1
4128
72 &data(ctx)->ks3, EVP_CIPHER_CTX_encrypting(ctx));
executed 4128 times by 1 test: DES_ecb3_encrypt((const_DES_cblock *)(in + i), (DES_cblock *)(out + i), &((DES_EDE_KEY *)EVP_CIPHER_CTX_get_cipher_data(ctx))->ks.ks[0], &((DES_EDE_KEY *)EVP_CIPHER_CTX_get_cipher_data(ctx))->ks.ks[1], &((DES_EDE_KEY *)EVP_CIPHER_CTX_get_cipher_data(ctx))->ks.ks[2], EVP_CIPHER_CTX_encrypting(ctx));
Executed by:
  • libcrypto.so.1.1
4128
73 return 1;
executed 264 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
264
74}-
75-
76static int des_ede_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,-
77 const unsigned char *in, size_t inl)-
78{-
79 while (inl >= EVP_MAXCHUNK) {
inl >= ((size_...of(long)*8-2))Description
TRUEnever evaluated
FALSEevaluated 140 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-140
80 int num = EVP_CIPHER_CTX_num(ctx);-
81 DES_ede3_ofb64_encrypt(in, out, (long)EVP_MAXCHUNK,-
82 &data(ctx)->ks1, &data(ctx)->ks2,-
83 &data(ctx)->ks3,-
84 (DES_cblock *)EVP_CIPHER_CTX_iv_noconst(ctx),-
85 &num);-
86 EVP_CIPHER_CTX_set_num(ctx, num);-
87 inl -= EVP_MAXCHUNK;-
88 in += EVP_MAXCHUNK;-
89 out += EVP_MAXCHUNK;-
90 }
never executed: end of block
0
91 if (inl) {
inlDescription
TRUEevaluated 140 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-140
92 int num = EVP_CIPHER_CTX_num(ctx);-
93 DES_ede3_ofb64_encrypt(in, out, (long)inl,-
94 &data(ctx)->ks1, &data(ctx)->ks2,-
95 &data(ctx)->ks3,-
96 (DES_cblock *)EVP_CIPHER_CTX_iv_noconst(ctx),-
97 &num);-
98 EVP_CIPHER_CTX_set_num(ctx, num);-
99 }
executed 140 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
140
100 return 1;
executed 140 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
140
101}-
102-
103static int des_ede_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,-
104 const unsigned char *in, size_t inl)-
105{-
106 DES_EDE_KEY *dat = data(ctx);-
107-
108 if (dat->stream.cbc != NULL) {
dat->stream.cbc != ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 511 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-511
109 (*dat->stream.cbc) (in, out, inl, dat->ks.ks,-
110 EVP_CIPHER_CTX_iv_noconst(ctx));-
111 return 1;
never executed: return 1;
0
112 }-
113-
114 while (inl >= EVP_MAXCHUNK) {
inl >= ((size_...of(long)*8-2))Description
TRUEnever evaluated
FALSEevaluated 511 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-511
115 DES_ede3_cbc_encrypt(in, out, (long)EVP_MAXCHUNK,-
116 &dat->ks1, &dat->ks2, &dat->ks3,-
117 (DES_cblock *)EVP_CIPHER_CTX_iv_noconst(ctx),-
118 EVP_CIPHER_CTX_encrypting(ctx));-
119 inl -= EVP_MAXCHUNK;-
120 in += EVP_MAXCHUNK;-
121 out += EVP_MAXCHUNK;-
122 }
never executed: end of block
0
123 if (inl)
inlDescription
TRUEevaluated 511 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-511
124 DES_ede3_cbc_encrypt(in, out, (long)inl,
executed 511 times by 1 test: DES_ede3_cbc_encrypt(in, out, (long)inl, &dat->ks.ks[0], &dat->ks.ks[1], &dat->ks.ks[2], (DES_cblock *)EVP_CIPHER_CTX_iv_noconst(ctx), EVP_CIPHER_CTX_encrypting(ctx));
Executed by:
  • libcrypto.so.1.1
511
125 &dat->ks1, &dat->ks2, &dat->ks3,
executed 511 times by 1 test: DES_ede3_cbc_encrypt(in, out, (long)inl, &dat->ks.ks[0], &dat->ks.ks[1], &dat->ks.ks[2], (DES_cblock *)EVP_CIPHER_CTX_iv_noconst(ctx), EVP_CIPHER_CTX_encrypting(ctx));
Executed by:
  • libcrypto.so.1.1
511
126 (DES_cblock *)EVP_CIPHER_CTX_iv_noconst(ctx),
executed 511 times by 1 test: DES_ede3_cbc_encrypt(in, out, (long)inl, &dat->ks.ks[0], &dat->ks.ks[1], &dat->ks.ks[2], (DES_cblock *)EVP_CIPHER_CTX_iv_noconst(ctx), EVP_CIPHER_CTX_encrypting(ctx));
Executed by:
  • libcrypto.so.1.1
511
127 EVP_CIPHER_CTX_encrypting(ctx));
executed 511 times by 1 test: DES_ede3_cbc_encrypt(in, out, (long)inl, &dat->ks.ks[0], &dat->ks.ks[1], &dat->ks.ks[2], (DES_cblock *)EVP_CIPHER_CTX_iv_noconst(ctx), EVP_CIPHER_CTX_encrypting(ctx));
Executed by:
  • libcrypto.so.1.1
511
128 return 1;
executed 511 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
511
129}-
130-
131static int des_ede_cfb64_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,-
132 const unsigned char *in, size_t inl)-
133{-
134 while (inl >= EVP_MAXCHUNK) {
inl >= ((size_...of(long)*8-2))Description
TRUEnever evaluated
FALSEevaluated 140 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-140
135 int num = EVP_CIPHER_CTX_num(ctx);-
136 DES_ede3_cfb64_encrypt(in, out, (long)EVP_MAXCHUNK,-
137 &data(ctx)->ks1, &data(ctx)->ks2,-
138 &data(ctx)->ks3,-
139 (DES_cblock *)EVP_CIPHER_CTX_iv_noconst(ctx),-
140 &num, EVP_CIPHER_CTX_encrypting(ctx));-
141 EVP_CIPHER_CTX_set_num(ctx, num);-
142 inl -= EVP_MAXCHUNK;-
143 in += EVP_MAXCHUNK;-
144 out += EVP_MAXCHUNK;-
145 }
never executed: end of block
0
146 if (inl) {
inlDescription
TRUEevaluated 140 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-140
147 int num = EVP_CIPHER_CTX_num(ctx);-
148 DES_ede3_cfb64_encrypt(in, out, (long)inl,-
149 &data(ctx)->ks1, &data(ctx)->ks2,-
150 &data(ctx)->ks3,-
151 (DES_cblock *)EVP_CIPHER_CTX_iv_noconst(ctx),-
152 &num, EVP_CIPHER_CTX_encrypting(ctx));-
153 EVP_CIPHER_CTX_set_num(ctx, num);-
154 }
executed 140 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
140
155 return 1;
executed 140 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
140
156}-
157-
158/*-
159 * Although we have a CFB-r implementation for 3-DES, it doesn't pack the-
160 * right way, so wrap it here-
161 */-
162static int des_ede3_cfb1_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,-
163 const unsigned char *in, size_t inl)-
164{-
165 size_t n;-
166 unsigned char c[1], d[1];-
167-
168 if (!EVP_CIPHER_CTX_test_flags(ctx, EVP_CIPH_FLAG_LENGTH_BITS))
!EVP_CIPHER_CT...s(ctx, 0x2000)Description
TRUEevaluated 74 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-74
169 inl *= 8;
executed 74 times by 1 test: inl *= 8;
Executed by:
  • libcrypto.so.1.1
74
170 for (n = 0; n < inl; ++n) {
n < inlDescription
TRUEevaluated 34528 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 74 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
74-34528
171 c[0] = (in[n / 8] & (1 << (7 - n % 8))) ? 0x80 : 0;
(in[n / 8] & (... (7 - n % 8)))Description
TRUEevaluated 15912 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 18616 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
15912-18616
172 DES_ede3_cfb_encrypt(c, d, 1, 1,-
173 &data(ctx)->ks1, &data(ctx)->ks2,-
174 &data(ctx)->ks3,-
175 (DES_cblock *)EVP_CIPHER_CTX_iv_noconst(ctx),-
176 EVP_CIPHER_CTX_encrypting(ctx));-
177 out[n / 8] = (out[n / 8] & ~(0x80 >> (unsigned int)(n % 8)))-
178 | ((d[0] & 0x80) >> (unsigned int)(n % 8));-
179 }
executed 34528 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
34528
180-
181 return 1;
executed 74 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
74
182}-
183-
184static int des_ede3_cfb8_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,-
185 const unsigned char *in, size_t inl)-
186{-
187 while (inl >= EVP_MAXCHUNK) {
inl >= ((size_...of(long)*8-2))Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-2
188 DES_ede3_cfb_encrypt(in, out, 8, (long)EVP_MAXCHUNK,-
189 &data(ctx)->ks1, &data(ctx)->ks2,-
190 &data(ctx)->ks3,-
191 (DES_cblock *)EVP_CIPHER_CTX_iv_noconst(ctx),-
192 EVP_CIPHER_CTX_encrypting(ctx));-
193 inl -= EVP_MAXCHUNK;-
194 in += EVP_MAXCHUNK;-
195 out += EVP_MAXCHUNK;-
196 }
never executed: end of block
0
197 if (inl)
inlDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-2
198 DES_ede3_cfb_encrypt(in, out, 8, (long)inl,
executed 2 times by 1 test: DES_ede3_cfb_encrypt(in, out, 8, (long)inl, &((DES_EDE_KEY *)EVP_CIPHER_CTX_get_cipher_data(ctx))->ks.ks[0], &((DES_EDE_KEY *)EVP_CIPHER_CTX_get_cipher_data(ctx))->ks.ks[1], &((DES_EDE_KEY *)EVP_CIPHER_CTX_get_cipher_data(ctx))->ks.ks[2], (DES_cblock *)EVP_CIPHER_CTX_iv_noconst(ctx), EVP_CIPHER_CTX_encrypting(ctx));
Executed by:
  • libcrypto.so.1.1
2
199 &data(ctx)->ks1, &data(ctx)->ks2,
executed 2 times by 1 test: DES_ede3_cfb_encrypt(in, out, 8, (long)inl, &((DES_EDE_KEY *)EVP_CIPHER_CTX_get_cipher_data(ctx))->ks.ks[0], &((DES_EDE_KEY *)EVP_CIPHER_CTX_get_cipher_data(ctx))->ks.ks[1], &((DES_EDE_KEY *)EVP_CIPHER_CTX_get_cipher_data(ctx))->ks.ks[2], (DES_cblock *)EVP_CIPHER_CTX_iv_noconst(ctx), EVP_CIPHER_CTX_encrypting(ctx));
Executed by:
  • libcrypto.so.1.1
2
200 &data(ctx)->ks3,
executed 2 times by 1 test: DES_ede3_cfb_encrypt(in, out, 8, (long)inl, &((DES_EDE_KEY *)EVP_CIPHER_CTX_get_cipher_data(ctx))->ks.ks[0], &((DES_EDE_KEY *)EVP_CIPHER_CTX_get_cipher_data(ctx))->ks.ks[1], &((DES_EDE_KEY *)EVP_CIPHER_CTX_get_cipher_data(ctx))->ks.ks[2], (DES_cblock *)EVP_CIPHER_CTX_iv_noconst(ctx), EVP_CIPHER_CTX_encrypting(ctx));
Executed by:
  • libcrypto.so.1.1
2
201 (DES_cblock *)EVP_CIPHER_CTX_iv_noconst(ctx),
executed 2 times by 1 test: DES_ede3_cfb_encrypt(in, out, 8, (long)inl, &((DES_EDE_KEY *)EVP_CIPHER_CTX_get_cipher_data(ctx))->ks.ks[0], &((DES_EDE_KEY *)EVP_CIPHER_CTX_get_cipher_data(ctx))->ks.ks[1], &((DES_EDE_KEY *)EVP_CIPHER_CTX_get_cipher_data(ctx))->ks.ks[2], (DES_cblock *)EVP_CIPHER_CTX_iv_noconst(ctx), EVP_CIPHER_CTX_encrypting(ctx));
Executed by:
  • libcrypto.so.1.1
2
202 EVP_CIPHER_CTX_encrypting(ctx));
executed 2 times by 1 test: DES_ede3_cfb_encrypt(in, out, 8, (long)inl, &((DES_EDE_KEY *)EVP_CIPHER_CTX_get_cipher_data(ctx))->ks.ks[0], &((DES_EDE_KEY *)EVP_CIPHER_CTX_get_cipher_data(ctx))->ks.ks[1], &((DES_EDE_KEY *)EVP_CIPHER_CTX_get_cipher_data(ctx))->ks.ks[2], (DES_cblock *)EVP_CIPHER_CTX_iv_noconst(ctx), EVP_CIPHER_CTX_encrypting(ctx));
Executed by:
  • libcrypto.so.1.1
2
203 return 1;
executed 2 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
2
204}-
205-
206BLOCK_CIPHER_defs(des_ede, DES_EDE_KEY, NID_des_ede, 8, 16, 8, 64,
executed 1962 times by 1 test: return &des_ede_cbc;
Executed by:
  • libcrypto.so.1.1
executed 1962 times by 1 test: return &des_ede_cfb64;
Executed by:
  • libcrypto.so.1.1
executed 1962 times by 1 test: return &des_ede_ofb;
Executed by:
  • libcrypto.so.1.1
never executed: return &des_ede_ecb;
0-1962
207 EVP_CIPH_RAND_KEY | EVP_CIPH_FLAG_DEFAULT_ASN1,-
208 des_ede_init_key, NULL, NULL, NULL, des3_ctrl)-
209# define des_ede3_cfb64_cipher des_ede_cfb64_cipher-
210# define des_ede3_ofb_cipher des_ede_ofb_cipher-
211# define des_ede3_cbc_cipher des_ede_cbc_cipher-
212# define des_ede3_ecb_cipher des_ede_ecb_cipher-
213 BLOCK_CIPHER_defs(des_ede3, DES_EDE_KEY, NID_des_ede3, 8, 24, 8, 64,
executed 3968 times by 1 test: return &des_ede3_cbc;
Executed by:
  • libcrypto.so.1.1
executed 1962 times by 1 test: return &des_ede3_cfb64;
Executed by:
  • libcrypto.so.1.1
executed 1962 times by 1 test: return &des_ede3_ofb;
Executed by:
  • libcrypto.so.1.1
never executed: return &des_ede3_ecb;
0-3968
214 EVP_CIPH_RAND_KEY | EVP_CIPH_FLAG_DEFAULT_ASN1,-
215 des_ede3_init_key, NULL, NULL, NULL, des3_ctrl)-
216-
217 BLOCK_CIPHER_def_cfb(des_ede3, DES_EDE_KEY, NID_des_ede3, 24, 8, 1,
executed 1962 times by 1 test: return &des_ede3_cfb1;
Executed by:
  • libcrypto.so.1.1
1962
218 EVP_CIPH_RAND_KEY | EVP_CIPH_FLAG_DEFAULT_ASN1,-
219 des_ede3_init_key, NULL, NULL, NULL, des3_ctrl)-
220-
221 BLOCK_CIPHER_def_cfb(des_ede3, DES_EDE_KEY, NID_des_ede3, 24, 8, 8,
executed 1962 times by 1 test: return &des_ede3_cfb8;
Executed by:
  • libcrypto.so.1.1
1962
222 EVP_CIPH_RAND_KEY | EVP_CIPH_FLAG_DEFAULT_ASN1,-
223 des_ede3_init_key, NULL, NULL, NULL, des3_ctrl)-
224-
225static int des_ede_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,-
226 const unsigned char *iv, int enc)-
227{-
228 DES_cblock *deskey = (DES_cblock *)key;-
229 DES_EDE_KEY *dat = data(ctx);-
230-
231 dat->stream.cbc = NULL;-
232# if defined(SPARC_DES_CAPABLE)-
233 if (SPARC_DES_CAPABLE) {-
234 int mode = EVP_CIPHER_CTX_mode(ctx);-
235-
236 if (mode == EVP_CIPH_CBC_MODE) {-
237 des_t4_key_expand(&deskey[0], &dat->ks1);-
238 des_t4_key_expand(&deskey[1], &dat->ks2);-
239 memcpy(&dat->ks3, &dat->ks1, sizeof(dat->ks1));-
240 dat->stream.cbc = enc ? des_t4_ede3_cbc_encrypt :-
241 des_t4_ede3_cbc_decrypt;-
242 return 1;-
243 }-
244 }-
245# endif-
246 DES_set_key_unchecked(&deskey[0], &dat->ks1);-
247 DES_set_key_unchecked(&deskey[1], &dat->ks2);-
248 memcpy(&dat->ks3, &dat->ks1, sizeof(dat->ks1));-
249 return 1;
executed 26 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
26
250}-
251-
252static int des_ede3_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,-
253 const unsigned char *iv, int enc)-
254{-
255 DES_cblock *deskey = (DES_cblock *)key;-
256 DES_EDE_KEY *dat = data(ctx);-
257-
258 dat->stream.cbc = NULL;-
259# if defined(SPARC_DES_CAPABLE)-
260 if (SPARC_DES_CAPABLE) {-
261 int mode = EVP_CIPHER_CTX_mode(ctx);-
262-
263 if (mode == EVP_CIPH_CBC_MODE) {-
264 des_t4_key_expand(&deskey[0], &dat->ks1);-
265 des_t4_key_expand(&deskey[1], &dat->ks2);-
266 des_t4_key_expand(&deskey[2], &dat->ks3);-
267 dat->stream.cbc = enc ? des_t4_ede3_cbc_encrypt :-
268 des_t4_ede3_cbc_decrypt;-
269 return 1;-
270 }-
271 }-
272# endif-
273 DES_set_key_unchecked(&deskey[0], &dat->ks1);-
274 DES_set_key_unchecked(&deskey[1], &dat->ks2);-
275 DES_set_key_unchecked(&deskey[2], &dat->ks3);-
276 return 1;
executed 136 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
136
277}-
278-
279static int des3_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr)-
280{-
281-
282 DES_cblock *deskey = ptr;-
283-
284 switch (type) {-
285 case EVP_CTRL_RAND_KEY:
executed 31 times by 1 test: case 0x6:
Executed by:
  • libcrypto.so.1.1
31
286 if (RAND_priv_bytes(ptr, EVP_CIPHER_CTX_key_length(ctx)) <= 0)
RAND_priv_byte...gth(ctx)) <= 0Description
TRUEnever evaluated
FALSEevaluated 31 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-31
287 return 0;
never executed: return 0;
0
288 DES_set_odd_parity(deskey);-
289 if (EVP_CIPHER_CTX_key_length(ctx) >= 16)
EVP_CIPHER_CTX...gth(ctx) >= 16Description
TRUEevaluated 31 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-31
290 DES_set_odd_parity(deskey + 1);
executed 31 times by 1 test: DES_set_odd_parity(deskey + 1);
Executed by:
  • libcrypto.so.1.1
31
291 if (EVP_CIPHER_CTX_key_length(ctx) >= 24)
EVP_CIPHER_CTX...gth(ctx) >= 24Description
TRUEevaluated 31 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-31
292 DES_set_odd_parity(deskey + 2);
executed 31 times by 1 test: DES_set_odd_parity(deskey + 2);
Executed by:
  • libcrypto.so.1.1
31
293 return 1;
executed 31 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
31
294-
295 default:
never executed: default:
0
296 return -1;
never executed: return -1;
0
297 }-
298}-
299-
300const EVP_CIPHER *EVP_des_ede(void)-
301{-
302 return &des_ede_ecb;
executed 1962 times by 1 test: return &des_ede_ecb;
Executed by:
  • libcrypto.so.1.1
1962
303}-
304-
305const EVP_CIPHER *EVP_des_ede3(void)-
306{-
307 return &des_ede3_ecb;
executed 1962 times by 1 test: return &des_ede3_ecb;
Executed by:
  • libcrypto.so.1.1
1962
308}-
309-
310-
311# include <openssl/sha.h>-
312-
313static const unsigned char wrap_iv[8] =-
314 { 0x4a, 0xdd, 0xa2, 0x2c, 0x79, 0xe8, 0x21, 0x05 };-
315-
316static int des_ede3_unwrap(EVP_CIPHER_CTX *ctx, unsigned char *out,-
317 const unsigned char *in, size_t inl)-
318{-
319 unsigned char icv[8], iv[8], sha1tmp[SHA_DIGEST_LENGTH];-
320 int rv = -1;-
321 if (inl < 24)
inl < 24Description
TRUEnever evaluated
FALSEevaluated 6 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-6
322 return -1;
never executed: return -1;
0
323 if (out == NULL)
out == ((void *)0)Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 3 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
3
324 return inl - 16;
executed 3 times by 1 test: return inl - 16;
Executed by:
  • libcrypto.so.1.1
3
325 memcpy(EVP_CIPHER_CTX_iv_noconst(ctx), wrap_iv, 8);-
326 /* Decrypt first block which will end up as icv */-
327 des_ede_cbc_cipher(ctx, icv, in, 8);-
328 /* Decrypt central blocks */-
329 /*-
330 * If decrypting in place move whole output along a block so the next-
331 * des_ede_cbc_cipher is in place.-
332 */-
333 if (out == in) {
out == inDescription
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-3
334 memmove(out, out + 8, inl - 8);-
335 in -= 8;-
336 }
never executed: end of block
0
337 des_ede_cbc_cipher(ctx, out, in + 8, inl - 16);-
338 /* Decrypt final block which will be IV */-
339 des_ede_cbc_cipher(ctx, iv, in + inl - 8, 8);-
340 /* Reverse order of everything */-
341 BUF_reverse(icv, NULL, 8);-
342 BUF_reverse(out, NULL, inl - 16);-
343 BUF_reverse(EVP_CIPHER_CTX_iv_noconst(ctx), iv, 8);-
344 /* Decrypt again using new IV */-
345 des_ede_cbc_cipher(ctx, out, out, inl - 16);-
346 des_ede_cbc_cipher(ctx, icv, icv, 8);-
347 /* Work out SHA1 hash of first portion */-
348 SHA1(out, inl - 16, sha1tmp);-
349-
350 if (!CRYPTO_memcmp(sha1tmp, icv, 8))
!CRYPTO_memcmp...a1tmp, icv, 8)Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-3
351 rv = inl - 16;
executed 3 times by 1 test: rv = inl - 16;
Executed by:
  • libcrypto.so.1.1
3
352 OPENSSL_cleanse(icv, 8);-
353 OPENSSL_cleanse(sha1tmp, SHA_DIGEST_LENGTH);-
354 OPENSSL_cleanse(iv, 8);-
355 OPENSSL_cleanse(EVP_CIPHER_CTX_iv_noconst(ctx), 8);-
356 if (rv == -1)
rv == -1Description
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-3
357 OPENSSL_cleanse(out, inl - 16);
never executed: OPENSSL_cleanse(out, inl - 16);
0
358-
359 return rv;
executed 3 times by 1 test: return rv;
Executed by:
  • libcrypto.so.1.1
3
360}-
361-
362static int des_ede3_wrap(EVP_CIPHER_CTX *ctx, unsigned char *out,-
363 const unsigned char *in, size_t inl)-
364{-
365 unsigned char sha1tmp[SHA_DIGEST_LENGTH];-
366 if (out == NULL)
out == ((void *)0)Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
4
367 return inl + 16;
executed 4 times by 1 test: return inl + 16;
Executed by:
  • libcrypto.so.1.1
4
368 /* Copy input to output buffer + 8 so we have space for IV */-
369 memmove(out + 8, in, inl);-
370 /* Work out ICV */-
371 SHA1(in, inl, sha1tmp);-
372 memcpy(out + inl + 8, sha1tmp, 8);-
373 OPENSSL_cleanse(sha1tmp, SHA_DIGEST_LENGTH);-
374 /* Generate random IV */-
375 if (RAND_bytes(EVP_CIPHER_CTX_iv_noconst(ctx), 8) <= 0)
RAND_bytes(EVP...(ctx), 8) <= 0Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-4
376 return -1;
never executed: return -1;
0
377 memcpy(out, EVP_CIPHER_CTX_iv_noconst(ctx), 8);-
378 /* Encrypt everything after IV in place */-
379 des_ede_cbc_cipher(ctx, out + 8, out + 8, inl + 8);-
380 BUF_reverse(out, NULL, inl + 16);-
381 memcpy(EVP_CIPHER_CTX_iv_noconst(ctx), wrap_iv, 8);-
382 des_ede_cbc_cipher(ctx, out, out, inl + 16);-
383 return inl + 16;
executed 4 times by 1 test: return inl + 16;
Executed by:
  • libcrypto.so.1.1
4
384}-
385-
386static int des_ede3_wrap_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,-
387 const unsigned char *in, size_t inl)-
388{-
389 /*-
390 * Sanity check input length: we typically only wrap keys so EVP_MAXCHUNK-
391 * is more than will ever be needed. Also input length must be a multiple-
392 * of 8 bits.-
393 */-
394 if (inl >= EVP_MAXCHUNK || inl % 8)
inl >= ((size_...of(long)*8-2))Description
TRUEnever evaluated
FALSEevaluated 14 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
inl % 8Description
TRUEnever evaluated
FALSEevaluated 14 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-14
395 return -1;
never executed: return -1;
0
396-
397 if (is_partially_overlapping(out, in, inl)) {
is_partially_o...(out, in, inl)Description
TRUEnever evaluated
FALSEevaluated 14 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-14
398 EVPerr(EVP_F_DES_EDE3_WRAP_CIPHER, EVP_R_PARTIALLY_OVERLAPPING);-
399 return 0;
never executed: return 0;
0
400 }-
401-
402 if (EVP_CIPHER_CTX_encrypting(ctx))
EVP_CIPHER_CTX_encrypting(ctx)Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 6 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
6-8
403 return des_ede3_wrap(ctx, out, in, inl);
executed 8 times by 1 test: return des_ede3_wrap(ctx, out, in, inl);
Executed by:
  • libcrypto.so.1.1
8
404 else-
405 return des_ede3_unwrap(ctx, out, in, inl);
executed 6 times by 1 test: return des_ede3_unwrap(ctx, out, in, inl);
Executed by:
  • libcrypto.so.1.1
6
406}-
407-
408static const EVP_CIPHER des3_wrap = {-
409 NID_id_smime_alg_CMS3DESwrap,-
410 8, 24, 0,-
411 EVP_CIPH_WRAP_MODE | EVP_CIPH_CUSTOM_IV | EVP_CIPH_FLAG_CUSTOM_CIPHER-
412 | EVP_CIPH_FLAG_DEFAULT_ASN1,-
413 des_ede3_init_key, des_ede3_wrap_cipher,-
414 NULL,-
415 sizeof(DES_EDE_KEY),-
416 NULL, NULL, NULL, NULL-
417};-
418-
419const EVP_CIPHER *EVP_des_ede3_wrap(void)-
420{-
421 return &des3_wrap;
executed 1966 times by 1 test: return &des3_wrap;
Executed by:
  • libcrypto.so.1.1
1966
422}-
423-
424#endif-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.2