diff options
author | markus <> | 2002-09-05 12:51:50 +0000 |
---|---|---|
committer | markus <> | 2002-09-05 12:51:50 +0000 |
commit | 15b5d84f9da2ce4bfae8580e56e34a859f74ad71 (patch) | |
tree | bf939e82d7fd73cc8a01cf6959002209972091bc /src/lib/libcrypto/evp/encode.c | |
parent | 027351f729b9e837200dae6e1520cda6577ab930 (diff) | |
download | openbsd-15b5d84f9da2ce4bfae8580e56e34a859f74ad71.tar.gz openbsd-15b5d84f9da2ce4bfae8580e56e34a859f74ad71.tar.bz2 openbsd-15b5d84f9da2ce4bfae8580e56e34a859f74ad71.zip |
import openssl-0.9.7-beta1
Diffstat (limited to 'src/lib/libcrypto/evp/encode.c')
-rw-r--r-- | src/lib/libcrypto/evp/encode.c | 74 |
1 files changed, 40 insertions, 34 deletions
diff --git a/src/lib/libcrypto/evp/encode.c b/src/lib/libcrypto/evp/encode.c index 14d47c1eed..12c6379df1 100644 --- a/src/lib/libcrypto/evp/encode.c +++ b/src/lib/libcrypto/evp/encode.c | |||
@@ -58,10 +58,21 @@ | |||
58 | 58 | ||
59 | #include <stdio.h> | 59 | #include <stdio.h> |
60 | #include "cryptlib.h" | 60 | #include "cryptlib.h" |
61 | #include "evp.h" | 61 | #include <openssl/evp.h> |
62 | 62 | ||
63 | #ifndef CHARSET_EBCDIC | ||
63 | #define conv_bin2ascii(a) (data_bin2ascii[(a)&0x3f]) | 64 | #define conv_bin2ascii(a) (data_bin2ascii[(a)&0x3f]) |
64 | #define conv_ascii2bin(a) (data_ascii2bin[(a)&0x7f]) | 65 | #define conv_ascii2bin(a) (data_ascii2bin[(a)&0x7f]) |
66 | #else | ||
67 | /* We assume that PEM encoded files are EBCDIC files | ||
68 | * (i.e., printable text files). Convert them here while decoding. | ||
69 | * When encoding, output is EBCDIC (text) format again. | ||
70 | * (No need for conversion in the conv_bin2ascii macro, as the | ||
71 | * underlying textstring data_bin2ascii[] is already EBCDIC) | ||
72 | */ | ||
73 | #define conv_bin2ascii(a) (data_bin2ascii[(a)&0x3f]) | ||
74 | #define conv_ascii2bin(a) (data_ascii2bin[os_toascii[a]&0x7f]) | ||
75 | #endif | ||
65 | 76 | ||
66 | /* 64 char lines | 77 | /* 64 char lines |
67 | * pad input with 0 | 78 | * pad input with 0 |
@@ -110,20 +121,15 @@ static unsigned char data_ascii2bin[128]={ | |||
110 | 0x31,0x32,0x33,0xFF,0xFF,0xFF,0xFF,0xFF, | 121 | 0x31,0x32,0x33,0xFF,0xFF,0xFF,0xFF,0xFF, |
111 | }; | 122 | }; |
112 | 123 | ||
113 | void EVP_EncodeInit(ctx) | 124 | void EVP_EncodeInit(EVP_ENCODE_CTX *ctx) |
114 | EVP_ENCODE_CTX *ctx; | ||
115 | { | 125 | { |
116 | ctx->length=48; | 126 | ctx->length=48; |
117 | ctx->num=0; | 127 | ctx->num=0; |
118 | ctx->line_num=0; | 128 | ctx->line_num=0; |
119 | } | 129 | } |
120 | 130 | ||
121 | void EVP_EncodeUpdate(ctx,out,outl,in,inl) | 131 | void EVP_EncodeUpdate(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl, |
122 | EVP_ENCODE_CTX *ctx; | 132 | unsigned char *in, int inl) |
123 | unsigned char *out; | ||
124 | int *outl; | ||
125 | unsigned char *in; | ||
126 | int inl; | ||
127 | { | 133 | { |
128 | int i,j; | 134 | int i,j; |
129 | unsigned int total=0; | 135 | unsigned int total=0; |
@@ -165,10 +171,7 @@ int inl; | |||
165 | *outl=total; | 171 | *outl=total; |
166 | } | 172 | } |
167 | 173 | ||
168 | void EVP_EncodeFinal(ctx,out,outl) | 174 | void EVP_EncodeFinal(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl) |
169 | EVP_ENCODE_CTX *ctx; | ||
170 | unsigned char *out; | ||
171 | int *outl; | ||
172 | { | 175 | { |
173 | unsigned int ret=0; | 176 | unsigned int ret=0; |
174 | 177 | ||
@@ -182,9 +185,7 @@ int *outl; | |||
182 | *outl=ret; | 185 | *outl=ret; |
183 | } | 186 | } |
184 | 187 | ||
185 | int EVP_EncodeBlock(t,f,dlen) | 188 | int EVP_EncodeBlock(unsigned char *t, const unsigned char *f, int dlen) |
186 | unsigned char *t,*f; | ||
187 | int dlen; | ||
188 | { | 189 | { |
189 | int i,ret=0; | 190 | int i,ret=0; |
190 | unsigned long l; | 191 | unsigned long l; |
@@ -218,8 +219,7 @@ int dlen; | |||
218 | return(ret); | 219 | return(ret); |
219 | } | 220 | } |
220 | 221 | ||
221 | void EVP_DecodeInit(ctx) | 222 | void EVP_DecodeInit(EVP_ENCODE_CTX *ctx) |
222 | EVP_ENCODE_CTX *ctx; | ||
223 | { | 223 | { |
224 | ctx->length=30; | 224 | ctx->length=30; |
225 | ctx->num=0; | 225 | ctx->num=0; |
@@ -231,12 +231,8 @@ EVP_ENCODE_CTX *ctx; | |||
231 | * 0 for last line | 231 | * 0 for last line |
232 | * 1 for full line | 232 | * 1 for full line |
233 | */ | 233 | */ |
234 | int EVP_DecodeUpdate(ctx,out,outl,in,inl) | 234 | int EVP_DecodeUpdate(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl, |
235 | EVP_ENCODE_CTX *ctx; | 235 | unsigned char *in, int inl) |
236 | unsigned char *out; | ||
237 | int *outl; | ||
238 | unsigned char *in; | ||
239 | int inl; | ||
240 | { | 236 | { |
241 | int seof= -1,eof=0,rv= -1,ret=0,i,v,tmp,n,ln,tmp2,exp_nl; | 237 | int seof= -1,eof=0,rv= -1,ret=0,i,v,tmp,n,ln,tmp2,exp_nl; |
242 | unsigned char *d; | 238 | unsigned char *d; |
@@ -281,6 +277,13 @@ int inl; | |||
281 | eof++; | 277 | eof++; |
282 | } | 278 | } |
283 | 279 | ||
280 | if (v == B64_CR) | ||
281 | { | ||
282 | ln = 0; | ||
283 | if (exp_nl) | ||
284 | continue; | ||
285 | } | ||
286 | |||
284 | /* eoln */ | 287 | /* eoln */ |
285 | if (v == B64_EOLN) | 288 | if (v == B64_EOLN) |
286 | { | 289 | { |
@@ -296,7 +299,17 @@ int inl; | |||
296 | /* If we are at the end of input and it looks like a | 299 | /* If we are at the end of input and it looks like a |
297 | * line, process it. */ | 300 | * line, process it. */ |
298 | if (((i+1) == inl) && (((n&3) == 0) || eof)) | 301 | if (((i+1) == inl) && (((n&3) == 0) || eof)) |
302 | { | ||
299 | v=B64_EOF; | 303 | v=B64_EOF; |
304 | /* In case things were given us in really small | ||
305 | records (so two '=' were given in separate | ||
306 | updates), eof may contain the incorrect number | ||
307 | of ending bytes to skip, so let's redo the count */ | ||
308 | eof = 0; | ||
309 | if (d[n-1] == '=') eof++; | ||
310 | if (d[n-2] == '=') eof++; | ||
311 | /* There will never be more than two '=' */ | ||
312 | } | ||
300 | 313 | ||
301 | if ((v == B64_EOF) || (n >= 64)) | 314 | if ((v == B64_EOF) || (n >= 64)) |
302 | { | 315 | { |
@@ -341,9 +354,7 @@ end: | |||
341 | return(rv); | 354 | return(rv); |
342 | } | 355 | } |
343 | 356 | ||
344 | int EVP_DecodeBlock(t,f,n) | 357 | int EVP_DecodeBlock(unsigned char *t, const unsigned char *f, int n) |
345 | unsigned char *t,*f; | ||
346 | int n; | ||
347 | { | 358 | { |
348 | int i,ret=0,a,b,c,d; | 359 | int i,ret=0,a,b,c,d; |
349 | unsigned long l; | 360 | unsigned long l; |
@@ -383,10 +394,7 @@ int n; | |||
383 | return(ret); | 394 | return(ret); |
384 | } | 395 | } |
385 | 396 | ||
386 | int EVP_DecodeFinal(ctx,out,outl) | 397 | int EVP_DecodeFinal(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl) |
387 | EVP_ENCODE_CTX *ctx; | ||
388 | unsigned char *out; | ||
389 | int *outl; | ||
390 | { | 398 | { |
391 | int i; | 399 | int i; |
392 | 400 | ||
@@ -404,9 +412,7 @@ int *outl; | |||
404 | } | 412 | } |
405 | 413 | ||
406 | #ifdef undef | 414 | #ifdef undef |
407 | int EVP_DecodeValid(buf,len) | 415 | int EVP_DecodeValid(unsigned char *buf, int len) |
408 | unsigned char *buf; | ||
409 | int len; | ||
410 | { | 416 | { |
411 | int i,num=0,bad=0; | 417 | int i,num=0,bad=0; |
412 | 418 | ||