Make CTR mode behaviour consistent with other modes:
authorBodo Möller <bodo@openssl.org>
Thu, 13 Oct 2011 13:42:29 +0000 (13:42 +0000)
committerBodo Möller <bodo@openssl.org>
Thu, 13 Oct 2011 13:42:29 +0000 (13:42 +0000)
clear ctx->num in EVP_CipherInit_ex

Submitted by: Emilia Kasper

crypto/evp/evp.h
crypto/evp/evp_enc.c

index 49d2240883b7e99371f910cbdd519ab80577f8e6..0d1b20a7d38a7353ae9413fcda868fb4f0db03fb 100644 (file)
@@ -419,7 +419,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 a816eb76b1808edea94a16a8e1504c35d4d08ff7..8828327d92674d48742719e1a86b2b1ca5384cfc 100644 (file)
@@ -232,6 +232,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));