From 2948fbab3acf853e0f61c559009dce7e0f876b62 Mon Sep 17 00:00:00 2001 From: "Dr. Stephen Henson" Date: Wed, 28 Jul 2010 16:53:28 +0000 Subject: [PATCH] Fix ctr mode properly this time.... --- crypto/evp/evp_enc.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/crypto/evp/evp_enc.c b/crypto/evp/evp_enc.c index a35621a2ec..99e6b200c2 100644 --- a/crypto/evp/evp_enc.c +++ b/crypto/evp/evp_enc.c @@ -206,14 +206,17 @@ skip_to_init: ctx->num = 0; case EVP_CIPH_CBC_MODE: - case EVP_CIPH_CTR_MODE: OPENSSL_assert(EVP_CIPHER_CTX_iv_length(ctx) <= (int)sizeof(ctx->iv)); if(iv) memcpy(ctx->oiv, iv, EVP_CIPHER_CTX_iv_length(ctx)); + memcpy(ctx->iv, ctx->oiv, EVP_CIPHER_CTX_iv_length(ctx)); + break; + + case EVP_CIPH_CTR_MODE: /* Don't reuse IV for CTR mode */ - if (EVP_CIPHER_CTX_mode(ctx) != EVP_CIPH_CTR_MODE) - memcpy(ctx->iv, ctx->oiv, EVP_CIPHER_CTX_iv_length(ctx)); + if(iv) + memcpy(ctx->iv, iv, EVP_CIPHER_CTX_iv_length(ctx)); break; default: -- 2.40.0