From fcbf81a3d4f42989a45a6528d93b2ba493358487 Mon Sep 17 00:00:00 2001 From: orignal Date: Mon, 20 Mar 2017 11:33:45 -0400 Subject: [PATCH] correct implementation of L for GOST R 34.11-2012 --- Gost.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Gost.cpp b/Gost.cpp index 41f52b7c..665df2e2 100644 --- a/Gost.cpp +++ b/Gost.cpp @@ -337,17 +337,23 @@ namespace crypto { for (int i = 0; i < 8; i++) { - uint64_t c = 0; + union + { + uint8_t b[8]; + uint64_t ll; + } c; + c.ll = 0; for (int j = 0; j < 8; j++) { uint8_t bit = 0x80; for (int k = 0; k < 8; k++) { - if (buf[i*8+j] & bit) c ^= A_[j*8+k]; + if (buf[i*8+j] & bit) c.ll ^= A_[j*8+k]; bit >>= 1; } } - ll[i] = c; + for (int j = 0; j < 8; j++) + buf[i*8+j] = c.b[7-j]; // invert } } @@ -405,7 +411,7 @@ namespace crypto h= gN (N, h, m); N.Add (512); s = m + s; - len -= 64; + l -= 64; } // stage 3 size_t padding = 64 - l;