Skip to content

Commit

Permalink
Make sure we handle input NULL with length 0
Browse files Browse the repository at this point in the history
If we call EVP_EncryptUpdate/EVP_DecryptUpdate with length 0 we should
be able to handle it. Most importantly we shouldn't get different
results if we do this compared to if we don't!

An exception is made for CCM mode which has special handling for this in
the low level cipher function.

Fixes openssl#8675
  • Loading branch information
mattcaswell committed Nov 27, 2019
1 parent 76fde1d commit c2e54b0
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 0 deletions.
5 changes: 5 additions & 0 deletions providers/common/ciphers/cipher_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,11 @@ int cipher_generic_stream_update(void *vctx, unsigned char *out, size_t *outl,
{
PROV_CIPHER_CTX *ctx = (PROV_CIPHER_CTX *)vctx;

if (inl == 0) {
*outl = 0;
return 1;
}

if (outsize < inl) {
ERR_raise(ERR_LIB_PROV, PROV_R_OUTPUT_BUFFER_TOO_SMALL);
return 0;
Expand Down
5 changes: 5 additions & 0 deletions providers/common/ciphers/cipher_gcm.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,11 @@ int gcm_stream_update(void *vctx, unsigned char *out, size_t *outl,
{
PROV_GCM_CTX *ctx = (PROV_GCM_CTX *)vctx;

if (inl == 0) {
*outl = 0;
return 1;
}

if (outsize < inl) {
ERR_raise(ERR_LIB_PROV, PROV_R_OUTPUT_BUFFER_TOO_SMALL);
return -1;
Expand Down
5 changes: 5 additions & 0 deletions providers/implementations/ciphers/cipher_aes_ocb.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,11 @@ static int aes_ocb_block_update(void *vctx, unsigned char *out, size_t *outl,
if (!ctx->key_set || !update_iv(ctx))
return 0;

if (inl == 0) {
*outl = 0;
return 1;
}

/* Are we dealing with AAD or normal data here? */
if (out == NULL) {
buf = ctx->aad_buf;
Expand Down
5 changes: 5 additions & 0 deletions providers/implementations/ciphers/cipher_aes_siv.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ static int siv_cipher(void *vctx, unsigned char *out, size_t *outl,
{
PROV_AES_SIV_CTX *ctx = (PROV_AES_SIV_CTX *)vctx;

if (inl == 0) {
*outl = 0;
return 1;
}

if (outsize < inl) {
ERR_raise(ERR_LIB_PROV, PROV_R_OUTPUT_BUFFER_TOO_SMALL);
return 0;
Expand Down
5 changes: 5 additions & 0 deletions providers/implementations/ciphers/cipher_aes_wrp.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@ static int aes_wrap_cipher(void *vctx,
PROV_AES_WRAP_CTX *ctx = (PROV_AES_WRAP_CTX *)vctx;
size_t len;

if (inl == 0) {
*outl = 0;
return 1;
}

if (outsize < inl) {
ERR_raise(ERR_LIB_PROV, PROV_R_OUTPUT_BUFFER_TOO_SMALL);
return -1;
Expand Down
5 changes: 5 additions & 0 deletions providers/implementations/ciphers/cipher_chacha20_poly1305.c
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,11 @@ static int chacha20_poly1305_cipher(void *vctx, unsigned char *out,
PROV_CIPHER_HW_CHACHA20_POLY1305 *hw =
(PROV_CIPHER_HW_CHACHA20_POLY1305 *)ctx->hw;

if (inl == 0) {
*outl = 0;
return 1;
}

if (outsize < inl) {
ERR_raise(ERR_LIB_PROV, PROV_R_OUTPUT_BUFFER_TOO_SMALL);
return 0;
Expand Down
2 changes: 2 additions & 0 deletions providers/implementations/ciphers/cipher_tdes_wrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ static int tdes_wrap_update(void *vctx, unsigned char *out, size_t *outl,
size_t inl)
{
*outl = 0;
if (inl == 0)
return 1;
if (outsize < inl) {
PROVerr(0, PROV_R_OUTPUT_BUFFER_TOO_SMALL);
return 0;
Expand Down

0 comments on commit c2e54b0

Please sign in to comment.