Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/libressl/src/crypto/evp/encode.c |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /* $OpenBSD: encode.c,v 1.25 2018/08/24 19:45:11 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 <limits.h> | - | ||||||||||||||||||||||||
60 | #include <stdio.h> | - | ||||||||||||||||||||||||
61 | #include <string.h> | - | ||||||||||||||||||||||||
62 | - | |||||||||||||||||||||||||
63 | #include <openssl/evp.h> | - | ||||||||||||||||||||||||
64 | - | |||||||||||||||||||||||||
65 | #define conv_bin2ascii(a) (data_bin2ascii[(a)&0x3f]) | - | ||||||||||||||||||||||||
66 | #define conv_ascii2bin(a) (data_ascii2bin[(a)&0x7f]) | - | ||||||||||||||||||||||||
67 | - | |||||||||||||||||||||||||
68 | /* 64 char lines | - | ||||||||||||||||||||||||
69 | * pad input with 0 | - | ||||||||||||||||||||||||
70 | * left over chars are set to = | - | ||||||||||||||||||||||||
71 | * 1 byte => xx== | - | ||||||||||||||||||||||||
72 | * 2 bytes => xxx= | - | ||||||||||||||||||||||||
73 | * 3 bytes => xxxx | - | ||||||||||||||||||||||||
74 | */ | - | ||||||||||||||||||||||||
75 | #define BIN_PER_LINE (64/4*3) | - | ||||||||||||||||||||||||
76 | #define CHUNKS_PER_LINE (64/4) | - | ||||||||||||||||||||||||
77 | #define CHAR_PER_LINE (64+1) | - | ||||||||||||||||||||||||
78 | - | |||||||||||||||||||||||||
79 | static const unsigned char data_bin2ascii[65] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ\ | - | ||||||||||||||||||||||||
80 | abcdefghijklmnopqrstuvwxyz0123456789+/"; | - | ||||||||||||||||||||||||
81 | - | |||||||||||||||||||||||||
82 | /* 0xF0 is a EOLN | - | ||||||||||||||||||||||||
83 | * 0xF1 is ignore but next needs to be 0xF0 (for \r\n processing). | - | ||||||||||||||||||||||||
84 | * 0xF2 is EOF | - | ||||||||||||||||||||||||
85 | * 0xE0 is ignore at start of line. | - | ||||||||||||||||||||||||
86 | * 0xFF is error | - | ||||||||||||||||||||||||
87 | */ | - | ||||||||||||||||||||||||
88 | - | |||||||||||||||||||||||||
89 | #define B64_EOLN 0xF0 | - | ||||||||||||||||||||||||
90 | #define B64_CR 0xF1 | - | ||||||||||||||||||||||||
91 | #define B64_EOF 0xF2 | - | ||||||||||||||||||||||||
92 | #define B64_WS 0xE0 | - | ||||||||||||||||||||||||
93 | #define B64_ERROR 0xFF | - | ||||||||||||||||||||||||
94 | #define B64_NOT_BASE64(a) (((a)|0x13) == 0xF3) | - | ||||||||||||||||||||||||
95 | - | |||||||||||||||||||||||||
96 | static const unsigned char data_ascii2bin[128] = { | - | ||||||||||||||||||||||||
97 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, | - | ||||||||||||||||||||||||
98 | 0xFF, 0xE0, 0xF0, 0xFF, 0xFF, 0xF1, 0xFF, 0xFF, | - | ||||||||||||||||||||||||
99 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, | - | ||||||||||||||||||||||||
100 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, | - | ||||||||||||||||||||||||
101 | 0xE0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, | - | ||||||||||||||||||||||||
102 | 0xFF, 0xFF, 0xFF, 0x3E, 0xFF, 0xF2, 0xFF, 0x3F, | - | ||||||||||||||||||||||||
103 | 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, | - | ||||||||||||||||||||||||
104 | 0x3C, 0x3D, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, | - | ||||||||||||||||||||||||
105 | 0xFF, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, | - | ||||||||||||||||||||||||
106 | 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, | - | ||||||||||||||||||||||||
107 | 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, | - | ||||||||||||||||||||||||
108 | 0x17, 0x18, 0x19, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, | - | ||||||||||||||||||||||||
109 | 0xFF, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, | - | ||||||||||||||||||||||||
110 | 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, | - | ||||||||||||||||||||||||
111 | 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, | - | ||||||||||||||||||||||||
112 | 0x31, 0x32, 0x33, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, | - | ||||||||||||||||||||||||
113 | }; | - | ||||||||||||||||||||||||
114 | - | |||||||||||||||||||||||||
115 | void | - | ||||||||||||||||||||||||
116 | EVP_EncodeInit(EVP_ENCODE_CTX *ctx) | - | ||||||||||||||||||||||||
117 | { | - | ||||||||||||||||||||||||
118 | ctx->length = 48; | - | ||||||||||||||||||||||||
119 | ctx->num = 0; | - | ||||||||||||||||||||||||
120 | ctx->line_num = 0; | - | ||||||||||||||||||||||||
121 | } executed 117 times by 4 tests: end of block Executed by:
| 117 | ||||||||||||||||||||||||
122 | - | |||||||||||||||||||||||||
123 | int | - | ||||||||||||||||||||||||
124 | EVP_EncodeUpdate(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl, | - | ||||||||||||||||||||||||
125 | const unsigned char *in, int inl) | - | ||||||||||||||||||||||||
126 | { | - | ||||||||||||||||||||||||
127 | int i, j; | - | ||||||||||||||||||||||||
128 | size_t total = 0; | - | ||||||||||||||||||||||||
129 | - | |||||||||||||||||||||||||
130 | *outl = 0; | - | ||||||||||||||||||||||||
131 | if (inl <= 0)
| 0-213 | ||||||||||||||||||||||||
132 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
133 | OPENSSL_assert(ctx->length <= (int)sizeof(ctx->enc_data)); | - | ||||||||||||||||||||||||
134 | if (ctx->length - ctx->num > inl) {
| 86-127 | ||||||||||||||||||||||||
135 | memcpy(&(ctx->enc_data[ctx->num]), in, inl); | - | ||||||||||||||||||||||||
136 | ctx->num += inl; | - | ||||||||||||||||||||||||
137 | return 1; executed 127 times by 2 tests: return 1; Executed by:
| 127 | ||||||||||||||||||||||||
138 | } | - | ||||||||||||||||||||||||
139 | if (ctx->num != 0) {
| 15-71 | ||||||||||||||||||||||||
140 | i = ctx->length - ctx->num; | - | ||||||||||||||||||||||||
141 | memcpy(&(ctx->enc_data[ctx->num]), in, i); | - | ||||||||||||||||||||||||
142 | in += i; | - | ||||||||||||||||||||||||
143 | inl -= i; | - | ||||||||||||||||||||||||
144 | j = EVP_EncodeBlock(out, ctx->enc_data, ctx->length); | - | ||||||||||||||||||||||||
145 | ctx->num = 0; | - | ||||||||||||||||||||||||
146 | out += j; | - | ||||||||||||||||||||||||
147 | *(out++) = '\n'; | - | ||||||||||||||||||||||||
148 | *out = '\0'; | - | ||||||||||||||||||||||||
149 | total = j + 1; | - | ||||||||||||||||||||||||
150 | } executed 71 times by 1 test: end of block Executed by:
| 71 | ||||||||||||||||||||||||
151 | while (inl >= ctx->length && total <= INT_MAX) {
| 0-1131 | ||||||||||||||||||||||||
152 | j = EVP_EncodeBlock(out, in, ctx->length); | - | ||||||||||||||||||||||||
153 | in += ctx->length; | - | ||||||||||||||||||||||||
154 | inl -= ctx->length; | - | ||||||||||||||||||||||||
155 | out += j; | - | ||||||||||||||||||||||||
156 | *(out++) = '\n'; | - | ||||||||||||||||||||||||
157 | *out = '\0'; | - | ||||||||||||||||||||||||
158 | total += j + 1; | - | ||||||||||||||||||||||||
159 | } executed 1131 times by 3 tests: end of block Executed by:
| 1131 | ||||||||||||||||||||||||
160 | if (total > INT_MAX) {
| 0-86 | ||||||||||||||||||||||||
161 | /* Too much output data! */ | - | ||||||||||||||||||||||||
162 | *outl = 0; | - | ||||||||||||||||||||||||
163 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
164 | } | - | ||||||||||||||||||||||||
165 | if (inl != 0)
| 22-64 | ||||||||||||||||||||||||
166 | memcpy(&(ctx->enc_data[0]), in, inl); executed 64 times by 3 tests: memcpy(&(ctx->enc_data[0]), in, inl); Executed by:
| 64 | ||||||||||||||||||||||||
167 | ctx->num = inl; | - | ||||||||||||||||||||||||
168 | *outl = total; | - | ||||||||||||||||||||||||
169 | - | |||||||||||||||||||||||||
170 | return 1; executed 86 times by 3 tests: return 1; Executed by:
| 86 | ||||||||||||||||||||||||
171 | } | - | ||||||||||||||||||||||||
172 | - | |||||||||||||||||||||||||
173 | void | - | ||||||||||||||||||||||||
174 | EVP_EncodeFinal(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl) | - | ||||||||||||||||||||||||
175 | { | - | ||||||||||||||||||||||||
176 | unsigned int ret = 0; | - | ||||||||||||||||||||||||
177 | - | |||||||||||||||||||||||||
178 | if (ctx->num != 0) {
| 0-71 | ||||||||||||||||||||||||
179 | ret = EVP_EncodeBlock(out, ctx->enc_data, ctx->num); | - | ||||||||||||||||||||||||
180 | out[ret++] = '\n'; | - | ||||||||||||||||||||||||
181 | out[ret] = '\0'; | - | ||||||||||||||||||||||||
182 | ctx->num = 0; | - | ||||||||||||||||||||||||
183 | } executed 71 times by 4 tests: end of block Executed by:
| 71 | ||||||||||||||||||||||||
184 | *outl = ret; | - | ||||||||||||||||||||||||
185 | } executed 71 times by 4 tests: end of block Executed by:
| 71 | ||||||||||||||||||||||||
186 | - | |||||||||||||||||||||||||
187 | int | - | ||||||||||||||||||||||||
188 | EVP_EncodeBlock(unsigned char *t, const unsigned char *f, int dlen) | - | ||||||||||||||||||||||||
189 | { | - | ||||||||||||||||||||||||
190 | int i, ret = 0; | - | ||||||||||||||||||||||||
191 | unsigned long l; | - | ||||||||||||||||||||||||
192 | - | |||||||||||||||||||||||||
193 | for (i = dlen; i > 0; i -= 3) {
| 1309-19828 | ||||||||||||||||||||||||
194 | if (i >= 3) {
| 80-19748 | ||||||||||||||||||||||||
195 | l = (((unsigned long)f[0]) << 16L) | | - | ||||||||||||||||||||||||
196 | (((unsigned long)f[1]) << 8L) | f[2]; | - | ||||||||||||||||||||||||
197 | *(t++) = conv_bin2ascii(l >> 18L); | - | ||||||||||||||||||||||||
198 | *(t++) = conv_bin2ascii(l >> 12L); | - | ||||||||||||||||||||||||
199 | *(t++) = conv_bin2ascii(l >> 6L); | - | ||||||||||||||||||||||||
200 | *(t++) = conv_bin2ascii(l ); | - | ||||||||||||||||||||||||
201 | } else { executed 19748 times by 4 tests: end of block Executed by:
| 19748 | ||||||||||||||||||||||||
202 | l = ((unsigned long)f[0]) << 16L; | - | ||||||||||||||||||||||||
203 | if (i == 2)
| 17-63 | ||||||||||||||||||||||||
204 | l |= ((unsigned long)f[1] << 8L); executed 17 times by 3 tests: l |= ((unsigned long)f[1] << 8L); Executed by:
| 17 | ||||||||||||||||||||||||
205 | - | |||||||||||||||||||||||||
206 | *(t++) = conv_bin2ascii(l >> 18L); | - | ||||||||||||||||||||||||
207 | *(t++) = conv_bin2ascii(l >> 12L); | - | ||||||||||||||||||||||||
208 | *(t++) = (i == 1) ? '=' : conv_bin2ascii(l >> 6L);
| 17-63 | ||||||||||||||||||||||||
209 | *(t++) = '='; | - | ||||||||||||||||||||||||
210 | } executed 80 times by 4 tests: end of block Executed by:
| 80 | ||||||||||||||||||||||||
211 | ret += 4; | - | ||||||||||||||||||||||||
212 | f += 3; | - | ||||||||||||||||||||||||
213 | } executed 19828 times by 4 tests: end of block Executed by:
| 19828 | ||||||||||||||||||||||||
214 | - | |||||||||||||||||||||||||
215 | *t = '\0'; | - | ||||||||||||||||||||||||
216 | return (ret); executed 1309 times by 4 tests: return (ret); Executed by:
| 1309 | ||||||||||||||||||||||||
217 | } | - | ||||||||||||||||||||||||
218 | - | |||||||||||||||||||||||||
219 | void | - | ||||||||||||||||||||||||
220 | EVP_DecodeInit(EVP_ENCODE_CTX *ctx) | - | ||||||||||||||||||||||||
221 | { | - | ||||||||||||||||||||||||
222 | ctx->length = 30; | - | ||||||||||||||||||||||||
223 | ctx->num = 0; | - | ||||||||||||||||||||||||
224 | ctx->line_num = 0; | - | ||||||||||||||||||||||||
225 | ctx->expect_nl = 0; | - | ||||||||||||||||||||||||
226 | } executed 519 times by 8 tests: end of block Executed by:
| 519 | ||||||||||||||||||||||||
227 | - | |||||||||||||||||||||||||
228 | /* -1 for error | - | ||||||||||||||||||||||||
229 | * 0 for last line | - | ||||||||||||||||||||||||
230 | * 1 for full line | - | ||||||||||||||||||||||||
231 | */ | - | ||||||||||||||||||||||||
232 | int | - | ||||||||||||||||||||||||
233 | EVP_DecodeUpdate(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl, | - | ||||||||||||||||||||||||
234 | const unsigned char *in, int inl) | - | ||||||||||||||||||||||||
235 | { | - | ||||||||||||||||||||||||
236 | int seof = -1, eof = 0, rv = -1, ret = 0, i, v, tmp, n, ln, exp_nl; | - | ||||||||||||||||||||||||
237 | unsigned char *d; | - | ||||||||||||||||||||||||
238 | - | |||||||||||||||||||||||||
239 | n = ctx->num; | - | ||||||||||||||||||||||||
240 | d = ctx->enc_data; | - | ||||||||||||||||||||||||
241 | ln = ctx->line_num; | - | ||||||||||||||||||||||||
242 | exp_nl = ctx->expect_nl; | - | ||||||||||||||||||||||||
243 | - | |||||||||||||||||||||||||
244 | /* last line of input. */ | - | ||||||||||||||||||||||||
245 | if ((inl == 0) || ((n == 0) && (conv_ascii2bin(in[0]) == B64_EOF))) {
| 0-507 | ||||||||||||||||||||||||
246 | rv = 0; | - | ||||||||||||||||||||||||
247 | goto end; never executed: goto end; | 0 | ||||||||||||||||||||||||
248 | } | - | ||||||||||||||||||||||||
249 | - | |||||||||||||||||||||||||
250 | /* We parse the input data */ | - | ||||||||||||||||||||||||
251 | for (i = 0; i < inl; i++) {
| 180-418999 | ||||||||||||||||||||||||
252 | /* If the current line is > 80 characters, scream alot */ | - | ||||||||||||||||||||||||
253 | if (ln >= 80) {
| 0-418999 | ||||||||||||||||||||||||
254 | rv = -1; | - | ||||||||||||||||||||||||
255 | goto end; never executed: goto end; | 0 | ||||||||||||||||||||||||
256 | } | - | ||||||||||||||||||||||||
257 | - | |||||||||||||||||||||||||
258 | /* Get char and put it into the buffer */ | - | ||||||||||||||||||||||||
259 | tmp= *(in++); | - | ||||||||||||||||||||||||
260 | v = conv_ascii2bin(tmp); | - | ||||||||||||||||||||||||
261 | /* only save the good data :-) */ | - | ||||||||||||||||||||||||
262 | if (!B64_NOT_BASE64(v)) {
| 6709-412290 | ||||||||||||||||||||||||
263 | OPENSSL_assert(n < (int)sizeof(ctx->enc_data)); | - | ||||||||||||||||||||||||
264 | d[n++] = tmp; | - | ||||||||||||||||||||||||
265 | ln++; | - | ||||||||||||||||||||||||
266 | } else if (v == B64_ERROR) { executed 412290 times by 8 tests: end of block Executed by:
| 0-412290 | ||||||||||||||||||||||||
267 | rv = -1; | - | ||||||||||||||||||||||||
268 | goto end; never executed: goto end; | 0 | ||||||||||||||||||||||||
269 | } | - | ||||||||||||||||||||||||
270 | - | |||||||||||||||||||||||||
271 | /* There should not be base64 data after padding. */ | - | ||||||||||||||||||||||||
272 | if (eof && tmp != '=' && tmp != '\r' && tmp != '\n' &&
| 10-418332 | ||||||||||||||||||||||||
273 | v != B64_EOF) {
| 0-10 | ||||||||||||||||||||||||
274 | rv = -1; | - | ||||||||||||||||||||||||
275 | goto end; executed 10 times by 1 test: goto end; Executed by:
| 10 | ||||||||||||||||||||||||
276 | } | - | ||||||||||||||||||||||||
277 | - | |||||||||||||||||||||||||
278 | /* have we seen a '=' which is 'definitely' the last | - | ||||||||||||||||||||||||
279 | * input line. seof will point to the character that | - | ||||||||||||||||||||||||
280 | * holds it. and eof will hold how many characters to | - | ||||||||||||||||||||||||
281 | * chop off. */ | - | ||||||||||||||||||||||||
282 | if (tmp == '=') {
| 612-418377 | ||||||||||||||||||||||||
283 | if (seof == -1)
| 281-331 | ||||||||||||||||||||||||
284 | seof = n; executed 331 times by 8 tests: seof = n; Executed by:
| 331 | ||||||||||||||||||||||||
285 | eof++; | - | ||||||||||||||||||||||||
286 | } executed 612 times by 8 tests: end of block Executed by:
| 612 | ||||||||||||||||||||||||
287 | - | |||||||||||||||||||||||||
288 | /* There should be no more than two padding markers. */ | - | ||||||||||||||||||||||||
289 | if (eof > 2) {
| 8-418981 | ||||||||||||||||||||||||
290 | rv = -1; | - | ||||||||||||||||||||||||
291 | goto end; executed 8 times by 1 test: goto end; Executed by:
| 8 | ||||||||||||||||||||||||
292 | } | - | ||||||||||||||||||||||||
293 | - | |||||||||||||||||||||||||
294 | if (v == B64_CR) {
| 85-418896 | ||||||||||||||||||||||||
295 | ln = 0; | - | ||||||||||||||||||||||||
296 | if (exp_nl)
| 0-85 | ||||||||||||||||||||||||
297 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||
298 | } executed 85 times by 1 test: end of block Executed by:
| 85 | ||||||||||||||||||||||||
299 | - | |||||||||||||||||||||||||
300 | /* eoln */ | - | ||||||||||||||||||||||||
301 | if (v == B64_EOLN) {
| 6624-412357 | ||||||||||||||||||||||||
302 | ln = 0; | - | ||||||||||||||||||||||||
303 | if (exp_nl) {
| 377-6247 | ||||||||||||||||||||||||
304 | exp_nl = 0; | - | ||||||||||||||||||||||||
305 | continue; executed 6247 times by 7 tests: continue; Executed by:
| 6247 | ||||||||||||||||||||||||
306 | } | - | ||||||||||||||||||||||||
307 | } executed 377 times by 8 tests: end of block Executed by:
| 377 | ||||||||||||||||||||||||
308 | exp_nl = 0; | - | ||||||||||||||||||||||||
309 | - | |||||||||||||||||||||||||
310 | /* If we are at the end of input and it looks like a | - | ||||||||||||||||||||||||
311 | * line, process it. */ | - | ||||||||||||||||||||||||
312 | if (((i + 1) == inl) && (((n&3) == 0) || eof)) {
| 10-412317 | ||||||||||||||||||||||||
313 | v = B64_EOF; | - | ||||||||||||||||||||||||
314 | /* In case things were given us in really small | - | ||||||||||||||||||||||||
315 | records (so two '=' were given in separate | - | ||||||||||||||||||||||||
316 | updates), eof may contain the incorrect number | - | ||||||||||||||||||||||||
317 | of ending bytes to skip, so let's redo the count */ | - | ||||||||||||||||||||||||
318 | eof = 0; | - | ||||||||||||||||||||||||
319 | if (d[n-1] == '=')
| 45-313 | ||||||||||||||||||||||||
320 | eof++; executed 313 times by 8 tests: eof++; Executed by:
| 313 | ||||||||||||||||||||||||
321 | if (d[n-2] == '=')
| 95-263 | ||||||||||||||||||||||||
322 | eof++; executed 263 times by 8 tests: eof++; Executed by:
| 263 | ||||||||||||||||||||||||
323 | /* There will never be more than two '=' */ | - | ||||||||||||||||||||||||
324 | } executed 358 times by 8 tests: end of block Executed by:
| 358 | ||||||||||||||||||||||||
325 | - | |||||||||||||||||||||||||
326 | if ((v == B64_EOF && (n&3) == 0) || (n >= 64)) {
| 10-412376 | ||||||||||||||||||||||||
327 | /* This is needed to work correctly on 64 byte input | - | ||||||||||||||||||||||||
328 | * lines. We process the line and then need to | - | ||||||||||||||||||||||||
329 | * accept the '\n' */ | - | ||||||||||||||||||||||||
330 | if ((v != B64_EOF) && (n >= 64))
| 0-6247 | ||||||||||||||||||||||||
331 | exp_nl = 1; executed 6247 times by 7 tests: exp_nl = 1; Executed by:
| 6247 | ||||||||||||||||||||||||
332 | if (n > 0) {
| 4-6591 | ||||||||||||||||||||||||
333 | v = EVP_DecodeBlock(out, d, n); | - | ||||||||||||||||||||||||
334 | n = 0; | - | ||||||||||||||||||||||||
335 | if (v < 0) {
| 2-6589 | ||||||||||||||||||||||||
336 | rv = 0; | - | ||||||||||||||||||||||||
337 | goto end; executed 2 times by 1 test: goto end; Executed by:
| 2 | ||||||||||||||||||||||||
338 | } | - | ||||||||||||||||||||||||
339 | ret += (v - eof); | - | ||||||||||||||||||||||||
340 | } else { executed 6589 times by 8 tests: end of block Executed by:
| 6589 | ||||||||||||||||||||||||
341 | eof = 1; | - | ||||||||||||||||||||||||
342 | v = 0; | - | ||||||||||||||||||||||||
343 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||||||||||||||
344 | - | |||||||||||||||||||||||||
345 | /* This is the case where we have had a short | - | ||||||||||||||||||||||||
346 | * but valid input line */ | - | ||||||||||||||||||||||||
347 | if ((v < ctx->length) && eof) {
| 39-6249 | ||||||||||||||||||||||||
348 | rv = 0; | - | ||||||||||||||||||||||||
349 | goto end; executed 305 times by 8 tests: goto end; Executed by:
| 305 | ||||||||||||||||||||||||
350 | } else | - | ||||||||||||||||||||||||
351 | ctx->length = v; executed 6288 times by 8 tests: ctx->length = v; Executed by:
| 6288 | ||||||||||||||||||||||||
352 | - | |||||||||||||||||||||||||
353 | if (seof >= 0) {
| 2-6286 | ||||||||||||||||||||||||
354 | rv = 0; | - | ||||||||||||||||||||||||
355 | goto end; executed 2 times by 1 test: goto end; Executed by:
| 2 | ||||||||||||||||||||||||
356 | } | - | ||||||||||||||||||||||||
357 | out += v; | - | ||||||||||||||||||||||||
358 | } executed 6286 times by 8 tests: end of block Executed by:
| 6286 | ||||||||||||||||||||||||
359 | } executed 412425 times by 8 tests: end of block Executed by:
| 412425 | ||||||||||||||||||||||||
360 | rv = 1; | - | ||||||||||||||||||||||||
361 | - | |||||||||||||||||||||||||
362 | end: code before this statement executed 180 times by 5 tests: end: Executed by:
| 180 | ||||||||||||||||||||||||
363 | *outl = ret; | - | ||||||||||||||||||||||||
364 | ctx->num = n; | - | ||||||||||||||||||||||||
365 | ctx->line_num = ln; | - | ||||||||||||||||||||||||
366 | ctx->expect_nl = exp_nl; | - | ||||||||||||||||||||||||
367 | return (rv); executed 507 times by 8 tests: return (rv); Executed by:
| 507 | ||||||||||||||||||||||||
368 | } | - | ||||||||||||||||||||||||
369 | - | |||||||||||||||||||||||||
370 | int | - | ||||||||||||||||||||||||
371 | EVP_DecodeBlock(unsigned char *t, const unsigned char *f, int n) | - | ||||||||||||||||||||||||
372 | { | - | ||||||||||||||||||||||||
373 | int i, ret = 0, a, b, c, d; | - | ||||||||||||||||||||||||
374 | unsigned long l; | - | ||||||||||||||||||||||||
375 | - | |||||||||||||||||||||||||
376 | /* trim white space from the start of the line. */ | - | ||||||||||||||||||||||||
377 | while ((conv_ascii2bin(*f) == B64_WS) && (n > 0)) {
| 0-6651 | ||||||||||||||||||||||||
378 | f++; | - | ||||||||||||||||||||||||
379 | n--; | - | ||||||||||||||||||||||||
380 | } never executed: end of block | 0 | ||||||||||||||||||||||||
381 | - | |||||||||||||||||||||||||
382 | /* strip off stuff at the end of the line | - | ||||||||||||||||||||||||
383 | * ascii2bin values B64_WS, B64_EOLN, B64_EOLN and B64_EOF */ | - | ||||||||||||||||||||||||
384 | while ((n > 3) && (B64_NOT_BASE64(conv_ascii2bin(f[n - 1]))))
| 1-6637 | ||||||||||||||||||||||||
385 | n--; executed 1 time by 1 test: n--; Executed by:
| 1 | ||||||||||||||||||||||||
386 | - | |||||||||||||||||||||||||
387 | if (n % 4 != 0)
| 1-6650 | ||||||||||||||||||||||||
388 | return (-1); executed 1 time by 1 test: return (-1); Executed by:
| 1 | ||||||||||||||||||||||||
389 | - | |||||||||||||||||||||||||
390 | for (i = 0; i < n; i += 4) {
| 6641-103124 | ||||||||||||||||||||||||
391 | a = conv_ascii2bin(*(f++)); | - | ||||||||||||||||||||||||
392 | b = conv_ascii2bin(*(f++)); | - | ||||||||||||||||||||||||
393 | c = conv_ascii2bin(*(f++)); | - | ||||||||||||||||||||||||
394 | d = conv_ascii2bin(*(f++)); | - | ||||||||||||||||||||||||
395 | if ((a & 0x80) || (b & 0x80) ||
| 2-103121 | ||||||||||||||||||||||||
396 | (c & 0x80) || (d & 0x80))
| 1-103118 | ||||||||||||||||||||||||
397 | return (-1); executed 9 times by 1 test: return (-1); Executed by:
| 9 | ||||||||||||||||||||||||
398 | l = ((((unsigned long)a) << 18L) | | - | ||||||||||||||||||||||||
399 | (((unsigned long)b) << 12L) | | - | ||||||||||||||||||||||||
400 | (((unsigned long)c) << 6L) | | - | ||||||||||||||||||||||||
401 | (((unsigned long)d))); | - | ||||||||||||||||||||||||
402 | *(t++) = (unsigned char)(l >> 16L) & 0xff; | - | ||||||||||||||||||||||||
403 | *(t++) = (unsigned char)(l >> 8L) & 0xff; | - | ||||||||||||||||||||||||
404 | *(t++) = (unsigned char)(l) & 0xff; | - | ||||||||||||||||||||||||
405 | ret += 3; | - | ||||||||||||||||||||||||
406 | } executed 103115 times by 8 tests: end of block Executed by:
| 103115 | ||||||||||||||||||||||||
407 | return (ret); executed 6641 times by 8 tests: return (ret); Executed by:
| 6641 | ||||||||||||||||||||||||
408 | } | - | ||||||||||||||||||||||||
409 | - | |||||||||||||||||||||||||
410 | int | - | ||||||||||||||||||||||||
411 | EVP_DecodeFinal(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl) | - | ||||||||||||||||||||||||
412 | { | - | ||||||||||||||||||||||||
413 | int i; | - | ||||||||||||||||||||||||
414 | - | |||||||||||||||||||||||||
415 | *outl = 0; | - | ||||||||||||||||||||||||
416 | if (ctx->num != 0) {
| 0-257 | ||||||||||||||||||||||||
417 | i = EVP_DecodeBlock(out, ctx->enc_data, ctx->num); | - | ||||||||||||||||||||||||
418 | if (i < 0)
| 0 | ||||||||||||||||||||||||
419 | return (-1); never executed: return (-1); | 0 | ||||||||||||||||||||||||
420 | ctx->num = 0; | - | ||||||||||||||||||||||||
421 | *outl = i; | - | ||||||||||||||||||||||||
422 | return (1); never executed: return (1); | 0 | ||||||||||||||||||||||||
423 | } else | - | ||||||||||||||||||||||||
424 | return (1); executed 257 times by 7 tests: return (1); Executed by:
| 257 | ||||||||||||||||||||||||
425 | } | - | ||||||||||||||||||||||||
Source code | Switch to Preprocessed file |