From d4b2d07c6e579c6f8a7f22d8bbdd9ace07b8c189 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juhani=20Krekel=C3=A4?= Date: Thu, 8 Apr 2021 20:26:59 +0300 Subject: [PATCH] Actually encode the number of bits in big endian --- puer.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/puer.c b/puer.c index e809a51..ca01f2b 100644 --- a/puer.c +++ b/puer.c @@ -200,10 +200,15 @@ void finalize_hash(struct hashstate *state, unsigned char hash[32]) { } // Add the number of bits, and do one last compression - word2bytes(&state->buffer[state->length], state->totalbits>>32); - state->length += 4; - word2bytes(&state->buffer[state->length], state->totalbits & 0xffffffffUL); - state->length += 4; + state->buffer[8] = state->totalbits >> 56; + state->buffer[9] = state->totalbits >> 48; + state->buffer[10] = state->totalbits >> 40; + state->buffer[11] = state->totalbits >> 32; + state->buffer[12] = state->totalbits >> 24; + state->buffer[13] = state->totalbits >> 16; + state->buffer[14] = state->totalbits >> 8; + state->buffer[15] = state->totalbits; + state->length += 8; compress_hash(state); // Extract the hash state