X-Git-Url: http://wagner.pp.ru/gitweb/?a=blobdiff_plain;f=gost_grasshopper_cipher.c;h=a045a92d754eb780692150649aed8beea50bacdc;hb=ebb91ec8c33ce9f259d455605a884ffbd72996db;hp=2818e8636bc9669a196d84a75104ed1769448d86;hpb=0097737ac987e4cfa4de161202da6f4f93c7a5d0;p=openssl-gost%2Fengine.git diff --git a/gost_grasshopper_cipher.c b/gost_grasshopper_cipher.c index 2818e86..a045a92 100644 --- a/gost_grasshopper_cipher.c +++ b/gost_grasshopper_cipher.c @@ -365,11 +365,14 @@ int gost_grasshopper_cipher_do_cbc(EVP_CIPHER_CTX *ctx, unsigned char *out, currentOutputBlock, &c->buffer); grasshopper_copy128(currentBlock, currentOutputBlock); } else { + grasshopper_w128_t tmp; + + grasshopper_copy128(&tmp, currentInputBlock); grasshopper_decrypt_block(&c->decrypt_round_keys, currentInputBlock, currentOutputBlock, &c->buffer); grasshopper_append128(currentOutputBlock, currentBlock); - grasshopper_copy128(currentBlock, currentInputBlock); + grasshopper_copy128(currentBlock, &tmp); } } @@ -418,14 +421,16 @@ int gost_grasshopper_cipher_do_ctr(EVP_CIPHER_CTX *ctx, unsigned char *out, size_t blocks = inl / GRASSHOPPER_BLOCK_SIZE; grasshopper_w128_t *iv_buffer = (grasshopper_w128_t *) iv; + grasshopper_w128_t tmp; // full parts for (i = 0; i < blocks; i++) { currentInputBlock = (grasshopper_w128_t *) current_in; currentOutputBlock = (grasshopper_w128_t *) current_out; grasshopper_encrypt_block(&c->c.encrypt_round_keys, iv_buffer, - currentOutputBlock, &c->c.buffer); - grasshopper_append128(currentOutputBlock, currentInputBlock); + &c->partial_buffer, &c->c.buffer); + grasshopper_plus128(&tmp, &c->partial_buffer, currentInputBlock); + grasshopper_copy128(currentOutputBlock, &tmp); ctr128_inc(iv_buffer->b); current_in += GRASSHOPPER_BLOCK_SIZE; current_out += GRASSHOPPER_BLOCK_SIZE; @@ -476,15 +481,16 @@ int gost_grasshopper_cipher_do_ctracpkm(EVP_CIPHER_CTX *ctx, } size_t blocks = inl / GRASSHOPPER_BLOCK_SIZE; size_t i; + grasshopper_w128_t tmp; // full parts for (i = 0; i < blocks; i++) { apply_acpkm_grasshopper(c, &num); grasshopper_encrypt_block(&c->c.encrypt_round_keys, (grasshopper_w128_t *) iv, - (grasshopper_w128_t *) out, &c->c.buffer); - grasshopper_append128((grasshopper_w128_t *) out, - (grasshopper_w128_t *) in); + (grasshopper_w128_t *) &c->partial_buffer, &c->c.buffer); + grasshopper_plus128(&tmp, &c->partial_buffer, (grasshopper_w128_t *) in); + grasshopper_copy128((grasshopper_w128_t *) out, &tmp); ctr128_inc(iv); in += GRASSHOPPER_BLOCK_SIZE; out += GRASSHOPPER_BLOCK_SIZE;