Actually encode the number of bits in big endian

This commit is contained in:
Juhani Krekelä 2021-04-08 20:26:59 +03:00
parent cf2b617b39
commit d4b2d07c6e
1 changed files with 9 additions and 4 deletions

13
puer.c
View File

@ -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