summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/evp/bio_enc.c
diff options
context:
space:
mode:
authorbeck <>2002-05-15 02:29:21 +0000
committerbeck <>2002-05-15 02:29:21 +0000
commitb64270d1e45fe7f3241e4c9b6ce60d5ac89bc2e9 (patch)
treefa27cf82a1250b64ed3bf5f4a18c7354d470bbcc /src/lib/libcrypto/evp/bio_enc.c
parente471e1ea98d673597b182ea85f29e30c97cd08b5 (diff)
downloadopenbsd-b64270d1e45fe7f3241e4c9b6ce60d5ac89bc2e9.tar.gz
openbsd-b64270d1e45fe7f3241e4c9b6ce60d5ac89bc2e9.tar.bz2
openbsd-b64270d1e45fe7f3241e4c9b6ce60d5ac89bc2e9.zip
OpenSSL 0.9.7 stable 2002 05 08 merge
Diffstat (limited to 'src/lib/libcrypto/evp/bio_enc.c')
-rw-r--r--src/lib/libcrypto/evp/bio_enc.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/src/lib/libcrypto/evp/bio_enc.c b/src/lib/libcrypto/evp/bio_enc.c
index 831c71a2b5..05f4249458 100644
--- a/src/lib/libcrypto/evp/bio_enc.c
+++ b/src/lib/libcrypto/evp/bio_enc.c
@@ -71,6 +71,7 @@ static 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, bio_info_cb *fps); 72static long enc_callback_ctrl(BIO *h, int cmd, bio_info_cb *fps);
73#define ENC_BLOCK_SIZE (1024*4) 73#define ENC_BLOCK_SIZE (1024*4)
74#define BUF_OFFSET EVP_MAX_BLOCK_LENGTH
74 75
75typedef struct enc_struct 76typedef struct enc_struct
76 { 77 {
@@ -80,7 +81,10 @@ typedef struct enc_struct
80 int finished; 81 int finished;
81 int ok; /* bad decrypt */ 82 int ok; /* bad decrypt */
82 EVP_CIPHER_CTX cipher; 83 EVP_CIPHER_CTX cipher;
83 char buf[ENC_BLOCK_SIZE+10]; 84 /* buf is larger than ENC_BLOCK_SIZE because EVP_DecryptUpdate
85 * can return up to a block more data than is presented to it
86 */
87 char buf[ENC_BLOCK_SIZE+BUF_OFFSET+2];
84 } BIO_ENC_CTX; 88 } BIO_ENC_CTX;
85 89
86static BIO_METHOD methods_enc= 90static BIO_METHOD methods_enc=
@@ -170,9 +174,9 @@ static int enc_read(BIO *b, char *out, int outl)
170 { 174 {
171 if (ctx->cont <= 0) break; 175 if (ctx->cont <= 0) break;
172 176
173 /* read in at offset 8, read the EVP_Cipher 177 /* read in at IV offset, read the EVP_Cipher
174 * documentation about why */ 178 * documentation about why */
175 i=BIO_read(b->next_bio,&(ctx->buf[8]),ENC_BLOCK_SIZE); 179 i=BIO_read(b->next_bio,&(ctx->buf[BUF_OFFSET]),ENC_BLOCK_SIZE);
176 180
177 if (i <= 0) 181 if (i <= 0)
178 { 182 {
@@ -180,7 +184,7 @@ static int enc_read(BIO *b, char *out, int outl)
180 if (!BIO_should_retry(b->next_bio)) 184 if (!BIO_should_retry(b->next_bio))
181 { 185 {
182 ctx->cont=i; 186 ctx->cont=i;
183 i=EVP_CipherFinal(&(ctx->cipher), 187 i=EVP_CipherFinal_ex(&(ctx->cipher),
184 (unsigned char *)ctx->buf, 188 (unsigned char *)ctx->buf,
185 &(ctx->buf_len)); 189 &(ctx->buf_len));
186 ctx->ok=i; 190 ctx->ok=i;
@@ -196,7 +200,7 @@ static int enc_read(BIO *b, char *out, int outl)
196 { 200 {
197 EVP_CipherUpdate(&(ctx->cipher), 201 EVP_CipherUpdate(&(ctx->cipher),
198 (unsigned char *)ctx->buf,&ctx->buf_len, 202 (unsigned char *)ctx->buf,&ctx->buf_len,
199 (unsigned char *)&(ctx->buf[8]),i); 203 (unsigned char *)&(ctx->buf[BUF_OFFSET]),i);
200 ctx->cont=1; 204 ctx->cont=1;
201 /* Note: it is possible for EVP_CipherUpdate to 205 /* Note: it is possible for EVP_CipherUpdate to
202 * decrypt zero bytes because this is or looks like 206 * decrypt zero bytes because this is or looks like
@@ -294,7 +298,7 @@ static long enc_ctrl(BIO *b, int cmd, long num, void *ptr)
294 case BIO_CTRL_RESET: 298 case BIO_CTRL_RESET:
295 ctx->ok=1; 299 ctx->ok=1;
296 ctx->finished=0; 300 ctx->finished=0;
297 EVP_CipherInit(&(ctx->cipher),NULL,NULL,NULL, 301 EVP_CipherInit_ex(&(ctx->cipher),NULL,NULL,NULL,NULL,
298 ctx->cipher.encrypt); 302 ctx->cipher.encrypt);
299 ret=BIO_ctrl(b->next_bio,cmd,num,ptr); 303 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
300 break; 304 break;
@@ -331,7 +335,7 @@ again:
331 { 335 {
332 ctx->finished=1; 336 ctx->finished=1;
333 ctx->buf_off=0; 337 ctx->buf_off=0;
334 ret=EVP_CipherFinal(&(ctx->cipher), 338 ret=EVP_CipherFinal_ex(&(ctx->cipher),
335 (unsigned char *)ctx->buf, 339 (unsigned char *)ctx->buf,
336 &(ctx->buf_len)); 340 &(ctx->buf_len));
337 ctx->ok=(int)ret; 341 ctx->ok=(int)ret;
@@ -417,7 +421,7 @@ void BIO_set_cipher(BIO *b, const EVP_CIPHER *c, unsigned char *k,
417 421
418 b->init=1; 422 b->init=1;
419 ctx=(BIO_ENC_CTX *)b->ptr; 423 ctx=(BIO_ENC_CTX *)b->ptr;
420 EVP_CipherInit(&(ctx->cipher),c,k,i,e); 424 EVP_CipherInit_ex(&(ctx->cipher),c,NULL, k,i,e);
421 425
422 if (b->callback != NULL) 426 if (b->callback != NULL)
423 b->callback(b,BIO_CB_CTRL,(const char *)c,BIO_CTRL_SET,e,1L); 427 b->callback(b,BIO_CB_CTRL,(const char *)c,BIO_CTRL_SET,e,1L);