X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=crypto%2Fevp%2Fbio_enc.c;h=629bf4b95d9675db4d2e0fb21a548af3ccc3a0bc;hb=8d5b4ee1cab7cd02f9fe246fb60d7d018a315a86;hp=ad09b94b1a186e351f011417ff355ff368d1f579;hpb=dfeab0689f69c0b4bd3480ffd37a9cacc2f17d9c;p=oweals%2Fopenssl.git diff --git a/crypto/evp/bio_enc.c b/crypto/evp/bio_enc.c index ad09b94b1a..629bf4b95d 100644 --- a/crypto/evp/bio_enc.c +++ b/crypto/evp/bio_enc.c @@ -59,10 +59,9 @@ #include #include #include "cryptlib.h" -#include "buffer.h" -#include "evp.h" +#include +#include -#ifndef NOPROTO static int enc_write(BIO *h,char *buf,int num); static int enc_read(BIO *h,char *buf,int size); /*static int enc_puts(BIO *h,char *str); */ @@ -70,16 +69,7 @@ static int enc_read(BIO *h,char *buf,int size); static long enc_ctrl(BIO *h,int cmd,long arg1,char *arg2); static int enc_new(BIO *h); static int enc_free(BIO *data); -#else -static int enc_write(); -static int enc_read(); -/*static int enc_puts(); */ -/*static int enc_gets(); */ -static long enc_ctrl(); -static int enc_new(); -static int enc_free(); -#endif - +static long enc_callback_ctrl(BIO *h,int cmd,void (*fp)()); #define ENC_BLOCK_SIZE (1024*4) typedef struct enc_struct @@ -103,15 +93,15 @@ static BIO_METHOD methods_enc= enc_ctrl, enc_new, enc_free, + enc_callback_ctrl, }; -BIO_METHOD *BIO_f_cipher() +BIO_METHOD *BIO_f_cipher(void) { return(&methods_enc); } -static int enc_new(bi) -BIO *bi; +static int enc_new(BIO *bi) { BIO_ENC_CTX *ctx; @@ -131,8 +121,7 @@ BIO *bi; return(1); } -static int enc_free(a) -BIO *a; +static int enc_free(BIO *a) { BIO_ENC_CTX *b; @@ -147,10 +136,7 @@ BIO *a; return(1); } -static int enc_read(b,out,outl) -BIO *b; -char *out; -int outl; +static int enc_read(BIO *b, char *out, int outl) { int ret=0,i; BIO_ENC_CTX *ctx; @@ -200,9 +186,11 @@ int outl; ctx->ok=i; ctx->buf_off=0; } - else + else + { ret=(ret == 0)?i:ret; - break; + break; + } } else { @@ -210,13 +198,19 @@ int outl; (unsigned char *)ctx->buf,&ctx->buf_len, (unsigned char *)&(ctx->buf[8]),i); ctx->cont=1; + /* Note: it is possible for EVP_CipherUpdate to + * decrypt zero bytes because this is or looks like + * the final block: if this happens we should retry + * and either read more data or decrypt the final + * block + */ + if(ctx->buf_len == 0) continue; } if (ctx->buf_len <= outl) i=ctx->buf_len; else i=outl; - if (i <= 0) break; memcpy(out,ctx->buf,i); ret+=i; @@ -230,10 +224,7 @@ int outl; return((ret == 0)?ctx->cont:ret); } -static int enc_write(b,in,inl) -BIO *b; -char *in; -int inl; +static int enc_write(BIO *b, char *in, int inl) { int ret=0,n,i; BIO_ENC_CTX *ctx; @@ -288,11 +279,7 @@ int inl; return(ret); } -static long enc_ctrl(b,cmd,num,ptr) -BIO *b; -int cmd; -long num; -char *ptr; +static long enc_ctrl(BIO *b, int cmd, long num, char *ptr) { BIO *dbio; BIO_ENC_CTX *ctx,*dctx; @@ -383,6 +370,20 @@ again: return(ret); } +static long enc_callback_ctrl(BIO *b, int cmd, void (*fp)()) + { + long ret=1; + + if (b->next_bio == NULL) return(0); + switch (cmd) + { + default: + ret=BIO_callback_ctrl(b->next_bio,cmd,fp); + break; + } + return(ret); + } + /* void BIO_set_cipher_ctx(b,c) BIO *b; @@ -403,19 +404,15 @@ EVP_CIPHER_ctx *c; } */ -void BIO_set_cipher(b,c,k,i,e) -BIO *b; -EVP_CIPHER *c; -unsigned char *k; -unsigned char *i; -int e; +void BIO_set_cipher(BIO *b, const EVP_CIPHER *c, unsigned char *k, + unsigned char *i, int e) { BIO_ENC_CTX *ctx; if (b == NULL) return; if ((b->callback != NULL) && - (b->callback(b,BIO_CB_CTRL,(char *)c,BIO_CTRL_SET,e,0L) <= 0)) + (b->callback(b,BIO_CB_CTRL,(const char *)c,BIO_CTRL_SET,e,0L) <= 0)) return; b->init=1; @@ -423,6 +420,6 @@ int e; EVP_CipherInit(&(ctx->cipher),c,k,i,e); if (b->callback != NULL) - b->callback(b,BIO_CB_CTRL,(char *)c,BIO_CTRL_SET,e,1L); + b->callback(b,BIO_CB_CTRL,(const char *)c,BIO_CTRL_SET,e,1L); }