From 2b79bbba6aed4e69b1d2d0c04da00f121c69799d Mon Sep 17 00:00:00 2001 From: Dmitry Belyavskiy Date: Fri, 28 Dec 2018 02:34:46 +0300 Subject: [PATCH] Bugfix of seq decrement --- gost_grasshopper_cipher.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/gost_grasshopper_cipher.c b/gost_grasshopper_cipher.c index 050ec7a..b6d044f 100644 --- a/gost_grasshopper_cipher.c +++ b/gost_grasshopper_cipher.c @@ -785,7 +785,7 @@ int gost_grasshopper_cipher_ctl(EVP_CIPHER_CTX *ctx, int type, int arg, memcpy(seq, ptr, 8); if (EVP_CIPHER_CTX_encrypting(ctx)) { /* - * OpenSSL increments seq on after mac calculation + * OpenSSL increments seq after mac calculation. * As we have Mac-Then-Encrypt, we need decrement it here on encryption * to derive the key correctly. * */ @@ -793,7 +793,8 @@ int gost_grasshopper_cipher_ctl(EVP_CIPHER_CTX *ctx, int type, int arg, { for(j=7; j>=0; j--) { - if (seq[j] != 0) {seq[j]--; break;}; + if (seq[j] != 0) {seq[j]--; break;} + else seq[j] = 0xFF; } } } -- 2.39.2