From a6ed0385abc705b751a6460e2d63d9526477ac22 Mon Sep 17 00:00:00 2001
From: Timothy Tur <tvtur@edu.hse.ru>
Date: Tue, 4 Feb 2025 15:59:16 +0300
Subject: [PATCH] bug + r fix

---
 source/ak_belt_hash.c | 11 +++++++----
 source/ak_hash.c      |  2 +-
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/source/ak_belt_hash.c b/source/ak_belt_hash.c
index 30ee30b2..ccd3fab9 100644
--- a/source/ak_belt_hash.c
+++ b/source/ak_belt_hash.c
@@ -356,6 +356,7 @@ static int ak_hash_context_belt_hash_clean( ak_pointer bctx ) {
   const ak_uint8* dt = (const ak_uint8*) in;
   //ak_uint8 m[32];
   struct belt_hash bx[1]; /* структура для хранения копии текущего состояния контекста */
+  ak_uint32 carry = size << 3;
 
   if( cx == NULL ) return ak_error_message( ak_error_null_pointer, __func__,
                                                "using null pointer to internal streebog context" );
@@ -363,10 +364,12 @@ static int ak_hash_context_belt_hash_clean( ak_pointer bctx ) {
                                                    "using null pointer to externl result buffer" );
   if( size >= 32 ) return ak_error_message( ak_error_wrong_length, __func__,
                                                                        "input length is too huge" );
-  // /* формируем временный текст */
-  //memset(m, 0, 32);
-  //if(in != NULL)
-  //  memcpy(m, dt, ( ak_uint32 )size);
+  
+  // обновить длину
+  carry = (cx->ls[0] += carry) < carry;
+  carry = (cx->ls[1] += carry) < carry;
+  carry = (cx->ls[2] += carry) < carry;
+  cx->ls[3] += carry;
 
   memcpy( bx, cx, sizeof( struct belt_hash ));
 
diff --git a/source/ak_hash.c b/source/ak_hash.c
index e813114d..f4897037 100644
--- a/source/ak_hash.c
+++ b/source/ak_hash.c
@@ -1513,7 +1513,7 @@
                                                        "destroying null pointer to hash context" );
   hctx->oid = NULL;
   memset( &hctx->data.sctx, 0,
-    ak_max(sizeof( struct streebog ), sizeof( struct belt_hash ));
+    ak_max(sizeof( struct streebog ), sizeof( struct belt_hash )));
   // memset( &hctx->data.bctx, 0, sizeof( struct belt_hash ));
   if( ak_mac_destroy( &hctx->mctx ) != ak_error_ok )
     ak_error_message( ak_error_get_value(), __func__,
-- 
GitLab