Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/evp/e_des.c |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||
2 | - | |||||||||||||
3 | - | |||||||||||||
4 | typedef struct { | - | ||||||||||||
5 | union { | - | ||||||||||||
6 | double align; | - | ||||||||||||
7 | DES_key_schedule ks; | - | ||||||||||||
8 | } ks; | - | ||||||||||||
9 | union { | - | ||||||||||||
10 | void (*cbc) (const void *, void *, size_t, | - | ||||||||||||
11 | const DES_key_schedule *, unsigned char *); | - | ||||||||||||
12 | } stream; | - | ||||||||||||
13 | } EVP_DES_KEY; | - | ||||||||||||
14 | static int des_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | - | ||||||||||||
15 | const unsigned char *iv, int enc); | - | ||||||||||||
16 | static int des_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr); | - | ||||||||||||
17 | - | |||||||||||||
18 | - | |||||||||||||
19 | - | |||||||||||||
20 | - | |||||||||||||
21 | - | |||||||||||||
22 | - | |||||||||||||
23 | static int des_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | - | ||||||||||||
24 | const unsigned char *in, size_t inl) | - | ||||||||||||
25 | { | - | ||||||||||||
26 | size_t i, bl; bl = EVP_CIPHER_CTX_cipher(ctx)->block_size; if (inl < bl
never executed: 1;return 1; never executed: inl -= bl; for (i=0; i <= inlreturn 1;
| 0-1740 | ||||||||||||
27 | DES_ecb_encrypt((DES_cblock *)(in + i), (DES_cblock *)(out + i), executed 1740 times by 1 test: DES_ecb_encrypt((DES_cblock *)(in + i), (DES_cblock *)(out + i), EVP_CIPHER_CTX_get_cipher_data(ctx), EVP_CIPHER_CTX_encrypting(ctx)); Executed by:
| 1740 | ||||||||||||
28 | EVP_CIPHER_CTX_get_cipher_data(ctx), executed 1740 times by 1 test: DES_ecb_encrypt((DES_cblock *)(in + i), (DES_cblock *)(out + i), EVP_CIPHER_CTX_get_cipher_data(ctx), EVP_CIPHER_CTX_encrypting(ctx)); Executed by:
| 1740 | ||||||||||||
29 | EVP_CIPHER_CTX_encrypting(ctx)); executed 1740 times by 1 test: DES_ecb_encrypt((DES_cblock *)(in + i), (DES_cblock *)(out + i), EVP_CIPHER_CTX_get_cipher_data(ctx), EVP_CIPHER_CTX_encrypting(ctx)); Executed by:
| 1740 | ||||||||||||
30 | return executed 297 times by 1 test: 1;return 1; Executed by:
executed 297 times by 1 test: return 1; Executed by:
| 297 | ||||||||||||
31 | } | - | ||||||||||||
32 | - | |||||||||||||
33 | static int des_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | - | ||||||||||||
34 | const unsigned char *in, size_t inl) | - | ||||||||||||
35 | { | - | ||||||||||||
36 | while (inl >= ((size_t)1<<(sizeof(long)*8-2))
| 0-70 | ||||||||||||
37 | int num = EVP_CIPHER_CTX_num(ctx); | - | ||||||||||||
38 | DES_ofb64_encrypt(in, out, (long)((size_t)1<<(sizeof(long)*8-2)), | - | ||||||||||||
39 | EVP_CIPHER_CTX_get_cipher_data(ctx), | - | ||||||||||||
40 | (DES_cblock *)EVP_CIPHER_CTX_iv_noconst(ctx), &num); | - | ||||||||||||
41 | EVP_CIPHER_CTX_set_num(ctx, num); | - | ||||||||||||
42 | inl -= ((size_t)1<<(sizeof(long)*8-2)); | - | ||||||||||||
43 | in += ((size_t)1<<(sizeof(long)*8-2)); | - | ||||||||||||
44 | out += ((size_t)1<<(sizeof(long)*8-2)); | - | ||||||||||||
45 | } never executed: end of block | 0 | ||||||||||||
46 | if (inl
| 0-70 | ||||||||||||
47 | int num = EVP_CIPHER_CTX_num(ctx); | - | ||||||||||||
48 | DES_ofb64_encrypt(in, out, (long)inl, | - | ||||||||||||
49 | EVP_CIPHER_CTX_get_cipher_data(ctx), | - | ||||||||||||
50 | (DES_cblock *)EVP_CIPHER_CTX_iv_noconst(ctx), &num); | - | ||||||||||||
51 | EVP_CIPHER_CTX_set_num(ctx, num); | - | ||||||||||||
52 | } executed 70 times by 1 test: end of block Executed by:
| 70 | ||||||||||||
53 | return executed 70 times by 1 test: 1;return 1; Executed by:
executed 70 times by 1 test: return 1; Executed by:
| 70 | ||||||||||||
54 | } | - | ||||||||||||
55 | - | |||||||||||||
56 | static int des_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | - | ||||||||||||
57 | const unsigned char *in, size_t inl) | - | ||||||||||||
58 | { | - | ||||||||||||
59 | EVP_DES_KEY *dat = (EVP_DES_KEY *) EVP_CIPHER_CTX_get_cipher_data(ctx); | - | ||||||||||||
60 | - | |||||||||||||
61 | if (dat->stream.cbc !=
| 0-258 | ||||||||||||
62 | ((void *)0)
| 0-258 | ||||||||||||
63 | ) { | - | ||||||||||||
64 | (*dat->stream.cbc) (in, out, inl, &dat->ks.ks, | - | ||||||||||||
65 | EVP_CIPHER_CTX_iv_noconst(ctx)); | - | ||||||||||||
66 | return never executed: 1;return 1; never executed: return 1; | 0 | ||||||||||||
67 | } | - | ||||||||||||
68 | while (inl >= ((size_t)1<<(sizeof(long)*8-2))
| 0-258 | ||||||||||||
69 | DES_ncbc_encrypt(in, out, (long)((size_t)1<<(sizeof(long)*8-2)), | - | ||||||||||||
70 | EVP_CIPHER_CTX_get_cipher_data(ctx), | - | ||||||||||||
71 | (DES_cblock *)EVP_CIPHER_CTX_iv_noconst(ctx), | - | ||||||||||||
72 | EVP_CIPHER_CTX_encrypting(ctx)); | - | ||||||||||||
73 | inl -= ((size_t)1<<(sizeof(long)*8-2)); | - | ||||||||||||
74 | in += ((size_t)1<<(sizeof(long)*8-2)); | - | ||||||||||||
75 | out += ((size_t)1<<(sizeof(long)*8-2)); | - | ||||||||||||
76 | } never executed: end of block | 0 | ||||||||||||
77 | if (inl
| 0-258 | ||||||||||||
78 | DES_ncbc_encrypt(in, out, (long)inl, executed 258 times by 1 test: DES_ncbc_encrypt(in, out, (long)inl, EVP_CIPHER_CTX_get_cipher_data(ctx), (DES_cblock *)EVP_CIPHER_CTX_iv_noconst(ctx), EVP_CIPHER_CTX_encrypting(ctx)); Executed by:
| 258 | ||||||||||||
79 | EVP_CIPHER_CTX_get_cipher_data(ctx), executed 258 times by 1 test: DES_ncbc_encrypt(in, out, (long)inl, EVP_CIPHER_CTX_get_cipher_data(ctx), (DES_cblock *)EVP_CIPHER_CTX_iv_noconst(ctx), EVP_CIPHER_CTX_encrypting(ctx)); Executed by:
| 258 | ||||||||||||
80 | (DES_cblock *)EVP_CIPHER_CTX_iv_noconst(ctx), executed 258 times by 1 test: DES_ncbc_encrypt(in, out, (long)inl, EVP_CIPHER_CTX_get_cipher_data(ctx), (DES_cblock *)EVP_CIPHER_CTX_iv_noconst(ctx), EVP_CIPHER_CTX_encrypting(ctx)); Executed by:
| 258 | ||||||||||||
81 | EVP_CIPHER_CTX_encrypting(ctx)); executed 258 times by 1 test: DES_ncbc_encrypt(in, out, (long)inl, EVP_CIPHER_CTX_get_cipher_data(ctx), (DES_cblock *)EVP_CIPHER_CTX_iv_noconst(ctx), EVP_CIPHER_CTX_encrypting(ctx)); Executed by:
| 258 | ||||||||||||
82 | return executed 258 times by 1 test: 1;return 1; Executed by:
executed 258 times by 1 test: return 1; Executed by:
| 258 | ||||||||||||
83 | } | - | ||||||||||||
84 | - | |||||||||||||
85 | static int des_cfb64_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | - | ||||||||||||
86 | const unsigned char *in, size_t inl) | - | ||||||||||||
87 | { | - | ||||||||||||
88 | while (inl >= ((size_t)1<<(sizeof(long)*8-2))
| 0-70 | ||||||||||||
89 | int num = EVP_CIPHER_CTX_num(ctx); | - | ||||||||||||
90 | DES_cfb64_encrypt(in, out, (long)((size_t)1<<(sizeof(long)*8-2)), | - | ||||||||||||
91 | EVP_CIPHER_CTX_get_cipher_data(ctx), | - | ||||||||||||
92 | (DES_cblock *)EVP_CIPHER_CTX_iv_noconst(ctx), &num, | - | ||||||||||||
93 | EVP_CIPHER_CTX_encrypting(ctx)); | - | ||||||||||||
94 | EVP_CIPHER_CTX_set_num(ctx, num); | - | ||||||||||||
95 | inl -= ((size_t)1<<(sizeof(long)*8-2)); | - | ||||||||||||
96 | in += ((size_t)1<<(sizeof(long)*8-2)); | - | ||||||||||||
97 | out += ((size_t)1<<(sizeof(long)*8-2)); | - | ||||||||||||
98 | } never executed: end of block | 0 | ||||||||||||
99 | if (inl
| 0-70 | ||||||||||||
100 | int num = EVP_CIPHER_CTX_num(ctx); | - | ||||||||||||
101 | DES_cfb64_encrypt(in, out, (long)inl, | - | ||||||||||||
102 | EVP_CIPHER_CTX_get_cipher_data(ctx), | - | ||||||||||||
103 | (DES_cblock *)EVP_CIPHER_CTX_iv_noconst(ctx), &num, | - | ||||||||||||
104 | EVP_CIPHER_CTX_encrypting(ctx)); | - | ||||||||||||
105 | EVP_CIPHER_CTX_set_num(ctx, num); | - | ||||||||||||
106 | } executed 70 times by 1 test: end of block Executed by:
| 70 | ||||||||||||
107 | return executed 70 times by 1 test: 1;return 1; Executed by:
executed 70 times by 1 test: return 1; Executed by:
| 70 | ||||||||||||
108 | } | - | ||||||||||||
109 | - | |||||||||||||
110 | - | |||||||||||||
111 | - | |||||||||||||
112 | - | |||||||||||||
113 | - | |||||||||||||
114 | static int des_cfb1_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | - | ||||||||||||
115 | const unsigned char *in, size_t inl) | - | ||||||||||||
116 | { | - | ||||||||||||
117 | size_t n, chunk = ((size_t)1<<(sizeof(long)*8-2)) / 8; | - | ||||||||||||
118 | unsigned char c[1], d[1]; | - | ||||||||||||
119 | - | |||||||||||||
120 | if (inl < chunk
| 0-2 | ||||||||||||
121 | chunk = inl; executed 2 times by 1 test: chunk = inl; Executed by:
| 2 | ||||||||||||
122 | - | |||||||||||||
123 | while (inl
| 0-2 | ||||||||||||
124 | for (n = 0; n < chunk * 8
| 2-31360 | ||||||||||||
125 | c[0] = (
| 14277-17083 | ||||||||||||
126 | DES_cfb_encrypt(c, d, 1, 1, EVP_CIPHER_CTX_get_cipher_data(ctx), | - | ||||||||||||
127 | (DES_cblock *)EVP_CIPHER_CTX_iv_noconst(ctx), | - | ||||||||||||
128 | EVP_CIPHER_CTX_encrypting(ctx)); | - | ||||||||||||
129 | out[n / 8] = | - | ||||||||||||
130 | (out[n / 8] & ~(0x80 >> (unsigned int)(n % 8))) | | - | ||||||||||||
131 | ((d[0] & 0x80) >> (unsigned int)(n % 8)); | - | ||||||||||||
132 | } executed 31360 times by 1 test: end of block Executed by:
| 31360 | ||||||||||||
133 | inl -= chunk; | - | ||||||||||||
134 | in += chunk; | - | ||||||||||||
135 | out += chunk; | - | ||||||||||||
136 | if (inl < chunk
| 0-2 | ||||||||||||
137 | chunk = inl; executed 2 times by 1 test: chunk = inl; Executed by:
| 2 | ||||||||||||
138 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||
139 | - | |||||||||||||
140 | return executed 2 times by 1 test: 1;return 1; Executed by:
executed 2 times by 1 test: return 1; Executed by:
| 2 | ||||||||||||
141 | } | - | ||||||||||||
142 | - | |||||||||||||
143 | static int des_cfb8_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | - | ||||||||||||
144 | const unsigned char *in, size_t inl) | - | ||||||||||||
145 | { | - | ||||||||||||
146 | while (inl >= ((size_t)1<<(sizeof(long)*8-2))
| 0-2 | ||||||||||||
147 | DES_cfb_encrypt(in, out, 8, (long)((size_t)1<<(sizeof(long)*8-2)), | - | ||||||||||||
148 | EVP_CIPHER_CTX_get_cipher_data(ctx), | - | ||||||||||||
149 | (DES_cblock *)EVP_CIPHER_CTX_iv_noconst(ctx), | - | ||||||||||||
150 | EVP_CIPHER_CTX_encrypting(ctx)); | - | ||||||||||||
151 | inl -= ((size_t)1<<(sizeof(long)*8-2)); | - | ||||||||||||
152 | in += ((size_t)1<<(sizeof(long)*8-2)); | - | ||||||||||||
153 | out += ((size_t)1<<(sizeof(long)*8-2)); | - | ||||||||||||
154 | } never executed: end of block | 0 | ||||||||||||
155 | if (inl
| 0-2 | ||||||||||||
156 | DES_cfb_encrypt(in, out, 8, (long)inl, executed 2 times by 1 test: DES_cfb_encrypt(in, out, 8, (long)inl, EVP_CIPHER_CTX_get_cipher_data(ctx), (DES_cblock *)EVP_CIPHER_CTX_iv_noconst(ctx), EVP_CIPHER_CTX_encrypting(ctx)); Executed by:
| 2 | ||||||||||||
157 | EVP_CIPHER_CTX_get_cipher_data(ctx), executed 2 times by 1 test: DES_cfb_encrypt(in, out, 8, (long)inl, EVP_CIPHER_CTX_get_cipher_data(ctx), (DES_cblock *)EVP_CIPHER_CTX_iv_noconst(ctx), EVP_CIPHER_CTX_encrypting(ctx)); Executed by:
| 2 | ||||||||||||
158 | (DES_cblock *)EVP_CIPHER_CTX_iv_noconst(ctx), executed 2 times by 1 test: DES_cfb_encrypt(in, out, 8, (long)inl, EVP_CIPHER_CTX_get_cipher_data(ctx), (DES_cblock *)EVP_CIPHER_CTX_iv_noconst(ctx), EVP_CIPHER_CTX_encrypting(ctx)); Executed by:
| 2 | ||||||||||||
159 | EVP_CIPHER_CTX_encrypting(ctx)); executed 2 times by 1 test: DES_cfb_encrypt(in, out, 8, (long)inl, EVP_CIPHER_CTX_get_cipher_data(ctx), (DES_cblock *)EVP_CIPHER_CTX_iv_noconst(ctx), EVP_CIPHER_CTX_encrypting(ctx)); Executed by:
| 2 | ||||||||||||
160 | return executed 2 times by 1 test: 1;return 1; Executed by:
executed 2 times by 1 test: return 1; Executed by:
| 2 | ||||||||||||
161 | } | - | ||||||||||||
162 | - | |||||||||||||
163 | static const EVP_CIPHER des_cbc = { 31, 8, 8, 8, 0x200 | 0x2, des_init_key, des_cbc_cipher, | - | ||||||||||||
164 | ((void *)0) | - | ||||||||||||
165 | , sizeof(EVP_DES_KEY), EVP_CIPHER_set_asn1_iv, EVP_CIPHER_get_asn1_iv, des_ctrl, | - | ||||||||||||
166 | ((void *)0) | - | ||||||||||||
167 | }; const EVP_CIPHER *EVP_des_cbc(void) { return executed 3920 times by 1 test: &des_cbc;return &des_cbc; Executed by:
executed 3920 times by 1 test: } static const EVP_CIPHER des_cfb64 = { 30, 1, 8, 8, 0x200 | 0x3, des_init_key, des_cfb64_cipher, return &des_cbc; Executed by:
| 3920 | ||||||||||||
168 | ((void *)0) | - | ||||||||||||
169 | , sizeof(EVP_DES_KEY), EVP_CIPHER_set_asn1_iv, EVP_CIPHER_get_asn1_iv, des_ctrl, | - | ||||||||||||
170 | ((void *)0) | - | ||||||||||||
171 | }; const EVP_CIPHER *EVP_des_cfb64(void) { return executed 1962 times by 1 test: &des_cfb64;return &des_cfb64; Executed by:
executed 1962 times by 1 test: } static const EVP_CIPHER des_ofb = { 45, 1, 8, 8, 0x200 | 0x4, des_init_key, des_ofb_cipher, return &des_cfb64; Executed by:
| 1962 | ||||||||||||
172 | ((void *)0) | - | ||||||||||||
173 | , sizeof(EVP_DES_KEY), EVP_CIPHER_set_asn1_iv, EVP_CIPHER_get_asn1_iv, des_ctrl, | - | ||||||||||||
174 | ((void *)0) | - | ||||||||||||
175 | }; const EVP_CIPHER *EVP_des_ofb(void) { return executed 1962 times by 1 test: &des_ofb;return &des_ofb; Executed by:
executed 1962 times by 1 test: } static const EVP_CIPHER des_ecb = { 29, 8, 8, 0, 0x200 | 0x1, des_init_key, des_ecb_cipher, return &des_ofb; Executed by:
| 1962 | ||||||||||||
176 | ((void *)0) | - | ||||||||||||
177 | , sizeof(EVP_DES_KEY), EVP_CIPHER_set_asn1_iv, EVP_CIPHER_get_asn1_iv, des_ctrl, | - | ||||||||||||
178 | ((void *)0) | - | ||||||||||||
179 | }; const EVP_CIPHER *EVP_des_ecb(void) { return executed 1962 times by 1 test: &des_ecb;return &des_ecb; Executed by:
executed 1962 times by 1 test: }return &des_ecb; Executed by:
| 1962 | ||||||||||||
180 | - | |||||||||||||
181 | - | |||||||||||||
182 | - | |||||||||||||
183 | static const EVP_CIPHER des_cfb1 = { 656, 1, 8, 8, 0x200 | 0x3, des_init_key, des_cfb1_cipher, | - | ||||||||||||
184 | ((void *)0) | - | ||||||||||||
185 | , sizeof(EVP_DES_KEY), EVP_CIPHER_set_asn1_iv, EVP_CIPHER_get_asn1_iv, des_ctrl, | - | ||||||||||||
186 | ((void *)0) | - | ||||||||||||
187 | }; const EVP_CIPHER *EVP_des_cfb1(void) { return executed 1962 times by 1 test: &des_cfb1;return &des_cfb1; Executed by:
executed 1962 times by 1 test: }return &des_cfb1; Executed by:
| 1962 | ||||||||||||
188 | - | |||||||||||||
189 | - | |||||||||||||
190 | - | |||||||||||||
191 | static const EVP_CIPHER des_cfb8 = { 657, 1, 8, 8, 0x200 | 0x3, des_init_key, des_cfb8_cipher, | - | ||||||||||||
192 | ((void *)0) | - | ||||||||||||
193 | , sizeof(EVP_DES_KEY), EVP_CIPHER_set_asn1_iv, EVP_CIPHER_get_asn1_iv, des_ctrl, | - | ||||||||||||
194 | ((void *)0) | - | ||||||||||||
195 | }; const EVP_CIPHER *EVP_des_cfb8(void) { return executed 1962 times by 1 test: &des_cfb8;return &des_cfb8; Executed by:
executed 1962 times by 1 test: }return &des_cfb8; Executed by:
| 1962 | ||||||||||||
196 | - | |||||||||||||
197 | - | |||||||||||||
198 | - | |||||||||||||
199 | static int des_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | - | ||||||||||||
200 | const unsigned char *iv, int enc) | - | ||||||||||||
201 | { | - | ||||||||||||
202 | DES_cblock *deskey = (DES_cblock *)key; | - | ||||||||||||
203 | EVP_DES_KEY *dat = (EVP_DES_KEY *) EVP_CIPHER_CTX_get_cipher_data(ctx); | - | ||||||||||||
204 | - | |||||||||||||
205 | dat->stream.cbc = | - | ||||||||||||
206 | ((void *)0) | - | ||||||||||||
207 | ; | - | ||||||||||||
208 | DES_set_key_unchecked(deskey, EVP_CIPHER_CTX_get_cipher_data(ctx)); | - | ||||||||||||
209 | return executed 202 times by 1 test: 1;return 1; Executed by:
executed 202 times by 1 test: return 1; Executed by:
| 202 | ||||||||||||
210 | } | - | ||||||||||||
211 | - | |||||||||||||
212 | static int des_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr) | - | ||||||||||||
213 | { | - | ||||||||||||
214 | - | |||||||||||||
215 | switch (type) { | - | ||||||||||||
216 | case never executed: 0x6:case 0x6: never executed: case 0x6: | 0 | ||||||||||||
217 | if (RAND_priv_bytes(ptr, 8) <= 0
| 0 | ||||||||||||
218 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
219 | DES_set_odd_parity((DES_cblock *)ptr); | - | ||||||||||||
220 | return never executed: 1;return 1; never executed: return 1; | 0 | ||||||||||||
221 | - | |||||||||||||
222 | default never executed: :default: never executed: default: | 0 | ||||||||||||
223 | return never executed: -1;return -1; never executed: return -1; | 0 | ||||||||||||
224 | } | - | ||||||||||||
225 | } | - | ||||||||||||
Switch to Source code | Preprocessed file |