From ff6364a8907b15684e685e8d7984088cfb4c74b4 Mon Sep 17 00:00:00 2001 From: Vitaly Chikunov Date: Thu, 13 Sep 2018 03:26:19 +0300 Subject: [PATCH] Fix in-place decryption for CBC mode --- gost_grasshopper_cipher.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/gost_grasshopper_cipher.c b/gost_grasshopper_cipher.c index 0d0eacb..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); } } -- 2.39.2