477d4a
diff -up openssl-1.0.1e/crypto/evp/bio_enc.c.enc-fail openssl-1.0.1e/crypto/evp/bio_enc.c
477d4a
--- openssl-1.0.1e/crypto/evp/bio_enc.c.enc-fail	2013-02-11 16:26:04.000000000 +0100
477d4a
+++ openssl-1.0.1e/crypto/evp/bio_enc.c	2014-03-04 15:21:12.185821738 +0100
477d4a
@@ -198,10 +198,15 @@ static int enc_read(BIO *b, char *out, i
477d4a
 			}
477d4a
 		else
477d4a
 			{
477d4a
-			EVP_CipherUpdate(&(ctx->cipher),
477d4a
+			if (!EVP_CipherUpdate(&(ctx->cipher),
477d4a
 				(unsigned char *)ctx->buf,&ctx->buf_len,
477d4a
-				(unsigned char *)&(ctx->buf[BUF_OFFSET]),i);
477d4a
-			ctx->cont=1;
477d4a
+				(unsigned char *)&(ctx->buf[BUF_OFFSET]),i))
477d4a
+				{
477d4a
+				ctx->ok = 0;
477d4a
+				ctx->cont = 0;
477d4a
+				}
477d4a
+			else
477d4a
+				ctx->cont=1;
477d4a
 			/* Note: it is possible for EVP_CipherUpdate to
477d4a
 			 * decrypt zero bytes because this is or looks like
477d4a
 			 * the final block: if this happens we should retry
477d4a
@@ -257,9 +262,14 @@ static int enc_write(BIO *b, const char
477d4a
 	while (inl > 0)
477d4a
 		{
477d4a
 		n=(inl > ENC_BLOCK_SIZE)?ENC_BLOCK_SIZE:inl;
477d4a
-		EVP_CipherUpdate(&(ctx->cipher),
477d4a
+		if (!EVP_CipherUpdate(&(ctx->cipher),
477d4a
 			(unsigned char *)ctx->buf,&ctx->buf_len,
477d4a
-			(unsigned char *)in,n);
477d4a
+			(unsigned char *)in,n))
477d4a
+			{
477d4a
+			BIO_copy_next_retry(b);
477d4a
+			ctx->ok = 0;
477d4a
+			return ret - inl;
477d4a
+			}
477d4a
 		inl-=n;
477d4a
 		in+=n;
477d4a