summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/evp/bio_enc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/evp/bio_enc.c')
-rw-r--r--src/lib/libcrypto/evp/bio_enc.c30
1 files changed, 27 insertions, 3 deletions
diff --git a/src/lib/libcrypto/evp/bio_enc.c b/src/lib/libcrypto/evp/bio_enc.c
index 0a7b1ecf07..629bf4b95d 100644
--- a/src/lib/libcrypto/evp/bio_enc.c
+++ b/src/lib/libcrypto/evp/bio_enc.c
@@ -69,6 +69,7 @@ static int enc_read(BIO *h,char *buf,int size);
69static long enc_ctrl(BIO *h,int cmd,long arg1,char *arg2); 69static long enc_ctrl(BIO *h,int cmd,long arg1,char *arg2);
70static int enc_new(BIO *h); 70static int enc_new(BIO *h);
71static int enc_free(BIO *data); 71static int enc_free(BIO *data);
72static long enc_callback_ctrl(BIO *h,int cmd,void (*fp)());
72#define ENC_BLOCK_SIZE (1024*4) 73#define ENC_BLOCK_SIZE (1024*4)
73 74
74typedef struct enc_struct 75typedef struct enc_struct
@@ -92,6 +93,7 @@ static BIO_METHOD methods_enc=
92 enc_ctrl, 93 enc_ctrl,
93 enc_new, 94 enc_new,
94 enc_free, 95 enc_free,
96 enc_callback_ctrl,
95 }; 97 };
96 98
97BIO_METHOD *BIO_f_cipher(void) 99BIO_METHOD *BIO_f_cipher(void)
@@ -184,9 +186,11 @@ static int enc_read(BIO *b, char *out, int outl)
184 ctx->ok=i; 186 ctx->ok=i;
185 ctx->buf_off=0; 187 ctx->buf_off=0;
186 } 188 }
187 else 189 else
190 {
188 ret=(ret == 0)?i:ret; 191 ret=(ret == 0)?i:ret;
189 break; 192 break;
193 }
190 } 194 }
191 else 195 else
192 { 196 {
@@ -194,13 +198,19 @@ static int enc_read(BIO *b, char *out, int outl)
194 (unsigned char *)ctx->buf,&ctx->buf_len, 198 (unsigned char *)ctx->buf,&ctx->buf_len,
195 (unsigned char *)&(ctx->buf[8]),i); 199 (unsigned char *)&(ctx->buf[8]),i);
196 ctx->cont=1; 200 ctx->cont=1;
201 /* Note: it is possible for EVP_CipherUpdate to
202 * decrypt zero bytes because this is or looks like
203 * the final block: if this happens we should retry
204 * and either read more data or decrypt the final
205 * block
206 */
207 if(ctx->buf_len == 0) continue;
197 } 208 }
198 209
199 if (ctx->buf_len <= outl) 210 if (ctx->buf_len <= outl)
200 i=ctx->buf_len; 211 i=ctx->buf_len;
201 else 212 else
202 i=outl; 213 i=outl;
203
204 if (i <= 0) break; 214 if (i <= 0) break;
205 memcpy(out,ctx->buf,i); 215 memcpy(out,ctx->buf,i);
206 ret+=i; 216 ret+=i;
@@ -360,6 +370,20 @@ again:
360 return(ret); 370 return(ret);
361 } 371 }
362 372
373static long enc_callback_ctrl(BIO *b, int cmd, void (*fp)())
374 {
375 long ret=1;
376
377 if (b->next_bio == NULL) return(0);
378 switch (cmd)
379 {
380 default:
381 ret=BIO_callback_ctrl(b->next_bio,cmd,fp);
382 break;
383 }
384 return(ret);
385 }
386
363/* 387/*
364void BIO_set_cipher_ctx(b,c) 388void BIO_set_cipher_ctx(b,c)
365BIO *b; 389BIO *b;