Ensures that EVP encryption & decryption operations check the encrypt flag on the context. #172

Closed
wants to merge 1 commit into
from

Projects

None yet

4 participants

@alokmenghrajani
Contributor

I'm new to this codebase, so sorry if I made any style mistakes. Also, I have a couple questions:

  1. do we need to set EVPerr before returning 0;
  2. should we unittest this case?

I believe EVP should make it hard to shoot yourself in the foot, so this change ensures that a user cannot accidentally decrypt data with an encryption context or vice-versa. For example, without the check, if an encryption context is used to decrypt EVP_aes_256_gcm encrypted data, the code will fail to validate the TAG.

Example code availabe at: http://quaxio.com/wtf/openssl_wtf.html

@alokmenghrajani alokmenghrajani Ensures that EVP encryption & decryption operations check the encrypt…
… flag on the context.

This change ensures that a user cannot accidentally decrypt data with an encryption context
or vice-versa. Without the check, if an encryption context is used to decrypt
EVP_aes_256_gcm encrypted data, the code will fail to validate the TAG.

Example code availabe at: http://quaxio.com/wtf/openssl_wtf.html
4181057
@richsalz
Contributor

I like the concept, but I think returning 0 without setting an error code isn't a good idea.

@alokmenghrajani
Contributor

Agree. Feel free to modify the PR and merge it.

@levitte levitte commented on the diff May 3, 2016
crypto/evp/evp_enc.c
@@ -295,7 +295,7 @@ int EVP_DecryptInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *im
return EVP_CipherInit_ex(ctx, cipher, impl, key, iv, 0);
}
-int EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,
+int EVP_EncryptOrDecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,
@levitte
levitte May 3, 2016 edited Member

This should be made static and with lowercase prefix (i.e. evp_ rather than EVP_)

@levitte
Member
levitte commented May 3, 2016

It's unfortunate that this hasn't been looked at for so long. The code looks correct (apart from the nit I picked), but it needs a rebase to a fresher master.

@levitte levitte self-assigned this May 3, 2016
@levitte levitte added the reviewed label May 6, 2016
@mattcaswell mattcaswell added this to the 1.1.0 milestone May 16, 2016
@mattcaswell
Member

This PR is from pre-reformat times. Either we should bring it up to date and fix the nit, or abandon it. @levitte?

@levitte
Member
levitte commented May 18, 2016

Like I said, "it needs a rebase to a fresher master"

@mattcaswell
Member

Ok. So I suggest unless @alokmenghrajani feels like bringing this up to date, we should close this PR.

@levitte
Member
levitte commented May 18, 2016

Agreed

@alokmenghrajani
Contributor

Not psyched to go over this ~2 years later.

@alokmenghrajani alokmenghrajani deleted the alokmenghrajani:alok/evp_check_ctx_encrypt branch May 18, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment