Commit 7b65c329 authored by Dr. Stephen Henson's avatar Dr. Stephen Henson
Browse files

Fix for a bug which meant encrypting BIOs sometimes wouldn't read the final

block.
parent 13066cee
Loading
Loading
Loading
Loading
+7 −0
Original line number Original line Diff line number Diff line
@@ -4,6 +4,13 @@


 Changes between 0.9.4 and 0.9.5  [xx XXX 1999]
 Changes between 0.9.4 and 0.9.5  [xx XXX 1999]


  *) Fix a horrible bug in enc_read() in crypto/evp/bio_enc.c: if the first data
     read consists of only the final block it would not decrypted because
     EVP_CipherUpdate() would correctly report zero bytes had been decrypted.
     A misplaced 'break' also meant the decrypted final block might not be
     copied until the next read.
     [Steve Henson]

  *) Initial support for DH_METHOD. Again based on RSA_METHOD. Also added
  *) Initial support for DH_METHOD. Again based on RSA_METHOD. Also added
     a few extra parameters to the DH structure: these will be useful if
     a few extra parameters to the DH structure: these will be useful if
     for example we want the value of 'q' or implement X9.42 DH.
     for example we want the value of 'q' or implement X9.42 DH.
+11 −3
Original line number Original line Diff line number Diff line
@@ -185,22 +185,30 @@ static int enc_read(BIO *b, char *out, int outl)
				ctx->buf_off=0;
				ctx->buf_off=0;
				}
				}
			else 
			else 
				{
				ret=(ret == 0)?i:ret;
				ret=(ret == 0)?i:ret;
				break;
				break;
				}
				}
			}
		else
		else
			{
			{
			EVP_CipherUpdate(&(ctx->cipher),
			EVP_CipherUpdate(&(ctx->cipher),
				(unsigned char *)ctx->buf,&ctx->buf_len,
				(unsigned char *)ctx->buf,&ctx->buf_len,
				(unsigned char *)&(ctx->buf[8]),i);
				(unsigned char *)&(ctx->buf[8]),i);
			ctx->cont=1;
			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)
		if (ctx->buf_len <= outl)
			i=ctx->buf_len;
			i=ctx->buf_len;
		else
		else
			i=outl;
			i=outl;

		if (i <= 0) break;
		if (i <= 0) break;
		memcpy(out,ctx->buf,i);
		memcpy(out,ctx->buf,i);
		ret+=i;
		ret+=i;