summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/evp/encode.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/evp/encode.c')
-rw-r--r--src/lib/libcrypto/evp/encode.c74
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
113void EVP_EncodeInit(ctx) 124void EVP_EncodeInit(EVP_ENCODE_CTX *ctx)
114EVP_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
121void EVP_EncodeUpdate(ctx,out,outl,in,inl) 131void EVP_EncodeUpdate(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl,
122EVP_ENCODE_CTX *ctx; 132 unsigned char *in, int inl)
123unsigned char *out;
124int *outl;
125unsigned char *in;
126int 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
168void EVP_EncodeFinal(ctx,out,outl) 174void EVP_EncodeFinal(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl)
169EVP_ENCODE_CTX *ctx;
170unsigned char *out;
171int *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
185int EVP_EncodeBlock(t,f,dlen) 188int EVP_EncodeBlock(unsigned char *t, const unsigned char *f, int dlen)
186unsigned char *t,*f;
187int 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
221void EVP_DecodeInit(ctx) 222void EVP_DecodeInit(EVP_ENCODE_CTX *ctx)
222EVP_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 */
234int EVP_DecodeUpdate(ctx,out,outl,in,inl) 234int EVP_DecodeUpdate(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl,
235EVP_ENCODE_CTX *ctx; 235 unsigned char *in, int inl)
236unsigned char *out;
237int *outl;
238unsigned char *in;
239int 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
344int EVP_DecodeBlock(t,f,n) 357int EVP_DecodeBlock(unsigned char *t, const unsigned char *f, int n)
345unsigned char *t,*f;
346int 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
386int EVP_DecodeFinal(ctx,out,outl) 397int EVP_DecodeFinal(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl)
387EVP_ENCODE_CTX *ctx;
388unsigned char *out;
389int *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
407int EVP_DecodeValid(buf,len) 415int EVP_DecodeValid(unsigned char *buf, int len)
408unsigned char *buf;
409int len;
410 { 416 {
411 int i,num=0,bad=0; 417 int i,num=0,bad=0;
412 418