[openssl-commits] [openssl] master update
Andy Polyakov
appro at openssl.org
Sun Jul 31 15:04:43 UTC 2016
The branch master has been updated
via abdb460d8abe68fedcf00b52d2ba4bf4b7c1725c (commit)
via 382bb0b294582c9d7f39ebfb96cd8849071687e0 (commit)
via 83151b73a4736bca1797f8edc2b0ad4cf7ac9146 (commit)
from e1f02308aeb124168d8a6655e5c822c3b0126260 (commit)
- Log -----------------------------------------------------------------
commit abdb460d8abe68fedcf00b52d2ba4bf4b7c1725c
Author: Andy Polyakov <appro at openssl.org>
Date: Mon Jul 25 15:04:33 2016 +0200
evp/bio_enc.c: perform enc_read operation without using overlapping buffers.
Reviewed-by: Stephen Henson <steve at openssl.org>
commit 382bb0b294582c9d7f39ebfb96cd8849071687e0
Author: Andy Polyakov <appro at openssl.org>
Date: Mon Jul 25 15:03:43 2016 +0200
test/smcont.txt: trigger assertion in bio_enc.c.
Reviewed-by: Stephen Henson <steve at openssl.org>
commit 83151b73a4736bca1797f8edc2b0ad4cf7ac9146
Author: Andy Polyakov <appro at openssl.org>
Date: Mon Jul 25 15:02:26 2016 +0200
evp/evp_enc.c: make assert error message more readable
and add EVPerr(PARTIALLY_OVERLAPPED)
Reviewed-by: Stephen Henson <steve at openssl.org>
-----------------------------------------------------------------------
Summary of changes:
crypto/evp/bio_enc.c | 36 +++++++++++++++++++++++++++---------
crypto/evp/evp_enc.c | 28 +++++++++++++++++++---------
crypto/evp/evp_err.c | 3 +++
include/openssl/evp.h | 3 +++
test/smcont.txt | 2 +-
5 files changed, 53 insertions(+), 19 deletions(-)
diff --git a/crypto/evp/bio_enc.c b/crypto/evp/bio_enc.c
index 5bc5d65..47d0384 100644
--- a/crypto/evp/bio_enc.c
+++ b/crypto/evp/bio_enc.c
@@ -40,7 +40,7 @@ typedef struct enc_struct {
* buf is larger than ENC_BLOCK_SIZE because EVP_DecryptUpdate can return
* up to a block more data than is presented to it
*/
- char buf[ENC_BLOCK_SIZE + BUF_OFFSET + 2];
+ unsigned char buf[ENC_BLOCK_SIZE + BUF_OFFSET + 2];
} BIO_ENC_CTX;
static const BIO_METHOD methods_enc = {
@@ -136,32 +136,50 @@ static int enc_read(BIO *b, char *out, int outl)
*/
while (outl > 0) {
+ int buf_len;
+
if (ctx->cont <= 0)
break;
+ buf_len = outl + EVP_MAX_BLOCK_LENGTH - 1;
+ buf_len -= buf_len % EVP_MAX_BLOCK_LENGTH;
+ if (buf_len > ENC_BLOCK_SIZE) {
+ buf_len = ENC_BLOCK_SIZE;
+ }
+
/*
* read in at IV offset, read the EVP_Cipher documentation about why
*/
- i = BIO_read(next, &(ctx->buf[BUF_OFFSET]), ENC_BLOCK_SIZE);
+ i = BIO_read(next, &(ctx->buf[BUF_OFFSET]), buf_len);
if (i <= 0) {
/* Should be continue next time we are called? */
if (!BIO_should_retry(next)) {
ctx->cont = i;
i = EVP_CipherFinal_ex(ctx->cipher,
- (unsigned char *)ctx->buf,
- &(ctx->buf_len));
+ ctx->buf, &(ctx->buf_len));
ctx->ok = i;
ctx->buf_off = 0;
} else {
ret = (ret == 0) ? i : ret;
break;
}
+ } else if (outl >= EVP_MAX_BLOCK_LENGTH) {
+ if (!EVP_CipherUpdate(ctx->cipher,
+ (unsigned char *)out, &buf_len,
+ &(ctx->buf[BUF_OFFSET]), i)) {
+ BIO_clear_retry_flags(b);
+ return 0;
+ }
+ ret += buf_len;
+ outl -= buf_len;
+ out += buf_len;
+
+ continue;
} else {
if (!EVP_CipherUpdate(ctx->cipher,
- (unsigned char *)ctx->buf, &ctx->buf_len,
- (unsigned char *)&(ctx->buf[BUF_OFFSET]),
- i)) {
+ ctx->buf, &ctx->buf_len,
+ &(ctx->buf[BUF_OFFSET]), i)) {
BIO_clear_retry_flags(b);
ctx->ok = 0;
return 0;
@@ -228,8 +246,8 @@ static int enc_write(BIO *b, const char *in, int inl)
while (inl > 0) {
n = (inl > ENC_BLOCK_SIZE) ? ENC_BLOCK_SIZE : inl;
if (!EVP_CipherUpdate(ctx->cipher,
- (unsigned char *)ctx->buf, &ctx->buf_len,
- (unsigned char *)in, n)) {
+ ctx->buf, &ctx->buf_len,
+ (const unsigned char *)in, n)) {
BIO_clear_retry_flags(b);
ctx->ok = 0;
return 0;
diff --git a/crypto/evp/evp_enc.c b/crypto/evp/evp_enc.c
index e43a5d2..bedc964 100644
--- a/crypto/evp/evp_enc.c
+++ b/crypto/evp/evp_enc.c
@@ -285,10 +285,10 @@ static int is_partially_overlapping(const void *ptr1, const void *ptr2,
* operations are used instead of boolean to minimize number
* of conditional branches.]
*/
- int condition = (len > 0) & (diff != 0) & ((diff < (PTRDIFF_T)len) |
- (diff > (0 - (PTRDIFF_T)len)));
- assert(!condition);
- return condition;
+ int overlapped = (len > 0) & (diff != 0) & ((diff < (PTRDIFF_T)len) |
+ (diff > (0 - (PTRDIFF_T)len)));
+ assert(!overlapped);
+ return overlapped;
}
int EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,
@@ -297,8 +297,10 @@ int EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,
int i, j, bl;
if (ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_CIPHER) {
- if (is_partially_overlapping(out, in, inl))
+ if (is_partially_overlapping(out, in, inl)) {
+ EVPerr(EVP_F_EVP_ENCRYPTUPDATE, EVP_R_PARTIALLY_OVERLAPPING);
return 0;
+ }
i = ctx->cipher->do_cipher(ctx, out, in, inl);
if (i < 0)
@@ -312,8 +314,10 @@ int EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,
*outl = 0;
return inl == 0;
}
- if (is_partially_overlapping(out, in, inl))
+ if (is_partially_overlapping(out, in, inl)) {
+ EVPerr(EVP_F_EVP_ENCRYPTUPDATE, EVP_R_PARTIALLY_OVERLAPPING);
return 0;
+ }
if (ctx->buf_len == 0 && (inl & (ctx->block_mask)) == 0) {
if (ctx->cipher->do_cipher(ctx, out, in, inl)) {
@@ -338,8 +342,10 @@ int EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,
memcpy(&(ctx->buf[i]), in, j);
inl -= j;
in += j;
- if (is_partially_overlapping(out, in, bl))
+ if (is_partially_overlapping(out, in, bl)) {
+ EVPerr(EVP_F_EVP_ENCRYPTUPDATE, EVP_R_PARTIALLY_OVERLAPPING);
return 0;
+ }
if (!ctx->cipher->do_cipher(ctx, out, ctx->buf, bl))
return 0;
out += bl;
@@ -417,8 +423,10 @@ int EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,
unsigned int b;
if (ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_CIPHER) {
- if (is_partially_overlapping(out, in, inl))
+ if (is_partially_overlapping(out, in, inl)) {
+ EVPerr(EVP_F_EVP_DECRYPTUPDATE, EVP_R_PARTIALLY_OVERLAPPING);
return 0;
+ }
fix_len = ctx->cipher->do_cipher(ctx, out, in, inl);
if (fix_len < 0) {
@@ -443,8 +451,10 @@ int EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,
if (ctx->final_used) {
/* see comment about PTRDIFF_T comparison above */
if (((PTRDIFF_T)out == (PTRDIFF_T)in)
- || is_partially_overlapping(out, in, b))
+ || is_partially_overlapping(out, in, b)) {
+ EVPerr(EVP_F_EVP_DECRYPTUPDATE, EVP_R_PARTIALLY_OVERLAPPING);
return 0;
+ }
memcpy(out, ctx->final, b);
out += b;
fix_len = 1;
diff --git a/crypto/evp/evp_err.c b/crypto/evp/evp_err.c
index bde5e31..a0d2250 100644
--- a/crypto/evp/evp_err.c
+++ b/crypto/evp/evp_err.c
@@ -33,8 +33,10 @@ static ERR_STRING_DATA EVP_str_functs[] = {
{ERR_FUNC(EVP_F_EVP_CIPHER_CTX_SET_KEY_LENGTH),
"EVP_CIPHER_CTX_set_key_length"},
{ERR_FUNC(EVP_F_EVP_DECRYPTFINAL_EX), "EVP_DecryptFinal_ex"},
+ {ERR_FUNC(EVP_F_EVP_DECRYPTUPDATE), "EVP_DecryptUpdate"},
{ERR_FUNC(EVP_F_EVP_DIGESTINIT_EX), "EVP_DigestInit_ex"},
{ERR_FUNC(EVP_F_EVP_ENCRYPTFINAL_EX), "EVP_EncryptFinal_ex"},
+ {ERR_FUNC(EVP_F_EVP_ENCRYPTUPDATE), "EVP_EncryptUpdate"},
{ERR_FUNC(EVP_F_EVP_MD_CTX_COPY_EX), "EVP_MD_CTX_copy_ex"},
{ERR_FUNC(EVP_F_EVP_MD_SIZE), "EVP_MD_size"},
{ERR_FUNC(EVP_F_EVP_OPENINIT), "EVP_OpenInit"},
@@ -133,6 +135,7 @@ static ERR_STRING_DATA EVP_str_reasons[] = {
{ERR_REASON(EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE),
"operation not supported for this keytype"},
{ERR_REASON(EVP_R_OPERATON_NOT_INITIALIZED), "operaton not initialized"},
+ {ERR_REASON(EVP_R_PARTIALLY_OVERLAPPING), "partially overlapping buffers"},
{ERR_REASON(EVP_R_PRIVATE_KEY_DECODE_ERROR), "private key decode error"},
{ERR_REASON(EVP_R_PRIVATE_KEY_ENCODE_ERROR), "private key encode error"},
{ERR_REASON(EVP_R_PUBLIC_KEY_NOT_RSA), "public key not rsa"},
diff --git a/include/openssl/evp.h b/include/openssl/evp.h
index 10e048a..3671bd0 100644
--- a/include/openssl/evp.h
+++ b/include/openssl/evp.h
@@ -1459,8 +1459,10 @@ int ERR_load_EVP_strings(void);
# define EVP_F_EVP_CIPHER_CTX_CTRL 124
# define EVP_F_EVP_CIPHER_CTX_SET_KEY_LENGTH 122
# define EVP_F_EVP_DECRYPTFINAL_EX 101
+# define EVP_F_EVP_DECRYPTUPDATE 166
# define EVP_F_EVP_DIGESTINIT_EX 128
# define EVP_F_EVP_ENCRYPTFINAL_EX 127
+# define EVP_F_EVP_ENCRYPTUPDATE 167
# define EVP_F_EVP_MD_CTX_COPY_EX 110
# define EVP_F_EVP_MD_SIZE 162
# define EVP_F_EVP_OPENINIT 102
@@ -1551,6 +1553,7 @@ int ERR_load_EVP_strings(void);
# define EVP_R_NO_OPERATION_SET 149
# define EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE 150
# define EVP_R_OPERATON_NOT_INITIALIZED 151
+# define EVP_R_PARTIALLY_OVERLAPPING 162
# define EVP_R_PRIVATE_KEY_DECODE_ERROR 145
# define EVP_R_PRIVATE_KEY_ENCODE_ERROR 146
# define EVP_R_PUBLIC_KEY_NOT_RSA 106
diff --git a/test/smcont.txt b/test/smcont.txt
index e837c0b..9b09746 100644
--- a/test/smcont.txt
+++ b/test/smcont.txt
@@ -1 +1 @@
-Some test content for OpenSSL CMS
\ No newline at end of file
+Somewhat longer test content for OpenSSL CMS utility to handle, and a bit longer...
\ No newline at end of file
More information about the openssl-commits
mailing list