OLD | NEW |
1 /* crypto/evp/encode.c */ | 1 /* crypto/evp/encode.c */ |
2 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 * All rights reserved. | 3 * All rights reserved. |
4 * | 4 * |
5 * This package is an SSL implementation written | 5 * This package is an SSL implementation written |
6 * by Eric Young (eay@cryptsoft.com). | 6 * by Eric Young (eay@cryptsoft.com). |
7 * The implementation was written so as to conform with Netscapes SSL. | 7 * The implementation was written so as to conform with Netscapes SSL. |
8 * | 8 * |
9 * This library is free for commercial and non-commercial use as long as | 9 * This library is free for commercial and non-commercial use as long as |
10 * the following conditions are aheared to. The following conditions | 10 * the following conditions are aheared to. The following conditions |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 * pad input with 0 | 78 * pad input with 0 |
79 * left over chars are set to = | 79 * left over chars are set to = |
80 * 1 byte => xx== | 80 * 1 byte => xx== |
81 * 2 bytes => xxx= | 81 * 2 bytes => xxx= |
82 * 3 bytes => xxxx | 82 * 3 bytes => xxxx |
83 */ | 83 */ |
84 #define BIN_PER_LINE (64/4*3) | 84 #define BIN_PER_LINE (64/4*3) |
85 #define CHUNKS_PER_LINE (64/4) | 85 #define CHUNKS_PER_LINE (64/4) |
86 #define CHAR_PER_LINE (64+1) | 86 #define CHAR_PER_LINE (64+1) |
87 | 87 |
88 static unsigned char data_bin2ascii[65]="ABCDEFGHIJKLMNOPQRSTUVWXYZ\ | 88 static const unsigned char data_bin2ascii[65]="ABCDEFGHIJKLMNOPQRSTUVWXYZ\ |
89 abcdefghijklmnopqrstuvwxyz0123456789+/"; | 89 abcdefghijklmnopqrstuvwxyz0123456789+/"; |
90 | 90 |
91 /* 0xF0 is a EOLN | 91 /* 0xF0 is a EOLN |
92 * 0xF1 is ignore but next needs to be 0xF0 (for \r\n processing). | 92 * 0xF1 is ignore but next needs to be 0xF0 (for \r\n processing). |
93 * 0xF2 is EOF | 93 * 0xF2 is EOF |
94 * 0xE0 is ignore at start of line. | 94 * 0xE0 is ignore at start of line. |
95 * 0xFF is error | 95 * 0xFF is error |
96 */ | 96 */ |
97 | 97 |
98 #define B64_EOLN 0xF0 | 98 #define B64_EOLN 0xF0 |
99 #define B64_CR 0xF1 | 99 #define B64_CR 0xF1 |
100 #define B64_EOF 0xF2 | 100 #define B64_EOF 0xF2 |
101 #define B64_WS 0xE0 | 101 #define B64_WS 0xE0 |
102 #define B64_ERROR 0xFF | 102 #define B64_ERROR 0xFF |
103 #define B64_NOT_BASE64(a) (((a)|0x13) == 0xF3) | 103 #define B64_NOT_BASE64(a) (((a)|0x13) == 0xF3) |
104 | 104 |
105 static unsigned char data_ascii2bin[128]={ | 105 static const unsigned char data_ascii2bin[128]={ |
106 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, | 106 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
107 0xFF,0xE0,0xF0,0xFF,0xFF,0xF1,0xFF,0xFF, | 107 0xFF,0xE0,0xF0,0xFF,0xFF,0xF1,0xFF,0xFF, |
108 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, | 108 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
109 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, | 109 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
110 0xE0,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, | 110 0xE0,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
111 0xFF,0xFF,0xFF,0x3E,0xFF,0xF2,0xFF,0x3F, | 111 0xFF,0xFF,0xFF,0x3E,0xFF,0xF2,0xFF,0x3F, |
112 0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B, | 112 0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B, |
113 0x3C,0x3D,0xFF,0xFF,0xFF,0x00,0xFF,0xFF, | 113 0x3C,0x3D,0xFF,0xFF,0xFF,0x00,0xFF,0xFF, |
114 0xFF,0x00,0x01,0x02,0x03,0x04,0x05,0x06, | 114 0xFF,0x00,0x01,0x02,0x03,0x04,0x05,0x06, |
115 0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E, | 115 0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E, |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 ctx->expect_nl=0; | 228 ctx->expect_nl=0; |
229 } | 229 } |
230 | 230 |
231 /* -1 for error | 231 /* -1 for error |
232 * 0 for last line | 232 * 0 for last line |
233 * 1 for full line | 233 * 1 for full line |
234 */ | 234 */ |
235 int EVP_DecodeUpdate(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl, | 235 int EVP_DecodeUpdate(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl, |
236 const unsigned char *in, int inl) | 236 const unsigned char *in, int inl) |
237 { | 237 { |
238 » int seof= -1,eof=0,rv= -1,ret=0,i,v,tmp,n,ln,tmp2,exp_nl; | 238 » int seof= -1,eof=0,rv= -1,ret=0,i,v,tmp,n,ln,exp_nl; |
239 unsigned char *d; | 239 unsigned char *d; |
240 | 240 |
241 n=ctx->num; | 241 n=ctx->num; |
242 d=ctx->enc_data; | 242 d=ctx->enc_data; |
243 ln=ctx->line_num; | 243 ln=ctx->line_num; |
244 exp_nl=ctx->expect_nl; | 244 exp_nl=ctx->expect_nl; |
245 | 245 |
246 /* last line of input. */ | 246 /* last line of input. */ |
247 if ((inl == 0) || ((n == 0) && (conv_ascii2bin(in[0]) == B64_EOF))) | 247 if ((inl == 0) || ((n == 0) && (conv_ascii2bin(in[0]) == B64_EOF))) |
248 { rv=0; goto end; } | 248 { rv=0; goto end; } |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 if (d[n-2] == '=') eof++; | 312 if (d[n-2] == '=') eof++; |
313 /* There will never be more than two '=' */ | 313 /* There will never be more than two '=' */ |
314 } | 314 } |
315 | 315 |
316 if ((v == B64_EOF && (n&3) == 0) || (n >= 64)) | 316 if ((v == B64_EOF && (n&3) == 0) || (n >= 64)) |
317 { | 317 { |
318 /* This is needed to work correctly on 64 byte input | 318 /* This is needed to work correctly on 64 byte input |
319 * lines. We process the line and then need to | 319 * lines. We process the line and then need to |
320 * accept the '\n' */ | 320 * accept the '\n' */ |
321 if ((v != B64_EOF) && (n >= 64)) exp_nl=1; | 321 if ((v != B64_EOF) && (n >= 64)) exp_nl=1; |
322 tmp2=v; | |
323 if (n > 0) | 322 if (n > 0) |
324 { | 323 { |
325 v=EVP_DecodeBlock(out,d,n); | 324 v=EVP_DecodeBlock(out,d,n); |
326 n=0; | 325 n=0; |
327 if (v < 0) { rv=0; goto end; } | 326 if (v < 0) { rv=0; goto end; } |
328 ret+=(v-eof); | 327 ret+=(v-eof); |
329 } | 328 } |
330 else | 329 else |
331 { | 330 { |
332 eof=1; | 331 eof=1; |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 num+=1+(buf[2] != '=')+(buf[3] != '='); | 436 num+=1+(buf[2] != '=')+(buf[3] != '='); |
438 } | 437 } |
439 if ((i == 1) && (conv_ascii2bin(buf[0]) == B64_EOLN)) | 438 if ((i == 1) && (conv_ascii2bin(buf[0]) == B64_EOLN)) |
440 return(num); | 439 return(num); |
441 if ((i == 2) && (conv_ascii2bin(buf[0]) == B64_EOLN) && | 440 if ((i == 2) && (conv_ascii2bin(buf[0]) == B64_EOLN) && |
442 (conv_ascii2bin(buf[0]) == B64_EOLN)) | 441 (conv_ascii2bin(buf[0]) == B64_EOLN)) |
443 return(num); | 442 return(num); |
444 return(1); | 443 return(1); |
445 } | 444 } |
446 #endif | 445 #endif |
OLD | NEW |