Make CTR mode behaviour consistent with other modes:
authorBodo Möller <bodo@openssl.org>
Thu, 13 Oct 2011 13:41:34 +0000 (13:41 +0000)
committerBodo Möller <bodo@openssl.org>
Thu, 13 Oct 2011 13:41:34 +0000 (13:41 +0000)
- clear ctx->num in EVP_CipherInit_ex
- adapt e_eas.c changes from http://cvs.openssl.org/chngview?cn=19816
  for eng_aesni.c

Submitted by: Emilia Kasper

crypto/engine/eng_aesni.c
crypto/evp/evp.h
crypto/evp/evp_enc.c

index 327a49c53eb5b39b438df9d4a9ab7c12be880900..1ea65e3f8fe543d8a1ec9a090e552f5b2daf785b 100644 (file)
@@ -301,16 +301,6 @@ aesni_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *user_key,
                return 0;
        }
 
-       if (ctx->cipher->flags&EVP_CIPH_CUSTOM_IV)
-               {
-               if (iv!=NULL)
-                       memcpy (ctx->iv,iv,ctx->cipher->iv_len);
-               else    {
-                       EVPerr(EVP_F_AESNI_INIT_KEY,EVP_R_AES_IV_SETUP_FAILED);
-                       return 0;
-                       }
-               }
-
        return 1;
 }
 
@@ -413,7 +403,7 @@ static int aesni_counter(EVP_CIPHER_CTX *ctx, unsigned char *out,
 static const EVP_CIPHER aesni_128_ctr=
        {
        NID_aes_128_ctr,1,16,16,
-       EVP_CIPH_CUSTOM_IV,
+       EVP_CIPH_CTR_MODE,
        aesni_init_key,
        aesni_counter,
        NULL,
@@ -427,7 +417,7 @@ static const EVP_CIPHER aesni_128_ctr=
 static const EVP_CIPHER aesni_192_ctr=
        {
        NID_aes_192_ctr,1,24,16,
-       EVP_CIPH_CUSTOM_IV,
+       EVP_CIPH_CTR_MODE,
        aesni_init_key,
        aesni_counter,
        NULL,
@@ -441,7 +431,7 @@ static const EVP_CIPHER aesni_192_ctr=
 static const EVP_CIPHER aesni_256_ctr=
        {
        NID_aes_256_ctr,1,32,16,
-       EVP_CIPH_CUSTOM_IV,
+       EVP_CIPH_CTR_MODE,
        aesni_init_key,
        aesni_counter,
        NULL,
index 2557ad3ab707c42fa8bb62aa38fda26b9b1df78d..3b38ecd6e6cdabf7b4e8325b931abf83e2a161ff 100644 (file)
@@ -418,7 +418,7 @@ struct evp_cipher_ctx_st
        unsigned char  oiv[EVP_MAX_IV_LENGTH];  /* original iv */
        unsigned char  iv[EVP_MAX_IV_LENGTH];   /* working iv */
        unsigned char buf[EVP_MAX_BLOCK_LENGTH];/* saved partial block */
-       int num;                                /* used by cfb/ofb mode */
+       int num;                                /* used by cfb/ofb/ctr mode */
 
        void *app_data;         /* application stuff */
        int key_len;            /* May change for variable length cipher */
index 87af9c4931ca6b353e33f4fcb4ba0fc746161952..8d57d204d60e7c6969b07d3dc61f47fa214f7f21 100644 (file)
@@ -215,6 +215,7 @@ skip_to_init:
                        break;
 
                        case EVP_CIPH_CTR_MODE:
+                       ctx->num = 0;
                        /* Don't reuse IV for CTR mode */
                        if(iv)
                                memcpy(ctx->iv, iv, EVP_CIPHER_CTX_iv_length(ctx));