From: Dmitry Belyavskiy Date: Fri, 9 Sep 2016 21:23:20 +0000 (+0300) Subject: Merge pull request #21 from MaXaMaR/openssl_1_1_0 X-Git-Tag: v1.1.0.2~22^2~2 X-Git-Url: https://wagner.pp.ru/gitweb/?a=commitdiff_plain;h=1348ef1c9df11185556614eae37059f98fc8c0e0;hp=5f30387f2fa0d016f61c102e090a7eba591c774f;p=openssl-gost%2Fengine.git Merge pull request #21 from MaXaMaR/openssl_1_1_0 Fix grasshopper-ctr memory corruption --- diff --git a/gost_grasshopper_cipher.c b/gost_grasshopper_cipher.c index 24e389a..b3aa4b9 100644 --- a/gost_grasshopper_cipher.c +++ b/gost_grasshopper_cipher.c @@ -96,7 +96,7 @@ static struct GRASSHOPPER_CIPHER_PARAMS gost_cipher_params[5] = { gost_grasshopper_cipher_do_ctr, gost_grasshopper_cipher_destroy_ctr, 1, - sizeof(gost_grasshopper_cipher_ctx), + sizeof(gost_grasshopper_cipher_ctx_ctr), 8, false }, @@ -293,18 +293,20 @@ static int gost_grasshopper_cipher_do_ctr(EVP_CIPHER_CTX* ctx, unsigned char* ou grasshopper_w128_t* currentInputBlock; grasshopper_w128_t* currentOutputBlock; size_t lasted; - size_t i; + size_t i; memcpy(&c->iv_buffer, iv, 8); // full parts - for (i = 0; i < blocks; i++, current_in += GRASSHOPPER_BLOCK_SIZE, current_out += GRASSHOPPER_BLOCK_SIZE) { + for (i = 0; i < blocks; i++) { currentInputBlock = (grasshopper_w128_t*) current_in; currentOutputBlock = (grasshopper_w128_t*) current_out; memcpy(c->iv_buffer.b + 8, &c->counter, 8); grasshopper_encrypt_block(&c->c.encrypt_round_keys, &c->iv_buffer, currentOutputBlock, &c->c.buffer); grasshopper_append128(currentOutputBlock, currentInputBlock); c->counter += 1; + current_in += GRASSHOPPER_BLOCK_SIZE; + current_out += GRASSHOPPER_BLOCK_SIZE; } // last part