From 29f7826b1e3c578a914dc1e6d3b83dd894c211b8 Mon Sep 17 00:00:00 2001 From: Tom Li Date: Thu, 3 Jan 2019 21:18:21 +0800 Subject: [PATCH] cubehash_impl.h: finalize without an incomplete block. Currently, process_final_incomplete_block() will perform the round R calculation with the remaining data, then finalize CubeHash. It is not possible to finalize CubeHash if there's no incomplete block. Here, we define the call of process_final_incomplete_block(NULL, 0) as a way to directly finalize CubeHash when input is a multiple of block size and there is no remaining data for round R. Also, in this case, any call of process_final_incomplete_block(), but only with a single NULL pointer, or only with n == 0, is an indication of bug. We assert both to be zero/nonzero. Signed-off-by: Tom Li --- src/cubehash_impl.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/cubehash_impl.h b/src/cubehash_impl.h index 8480372..f4696ad 100644 --- a/src/cubehash_impl.h +++ b/src/cubehash_impl.h @@ -23,6 +23,7 @@ #include "types.h" +#include #include #define ROT(a,b,n) (((a) << (b)) | ((a) >> (n - b))) @@ -99,6 +100,13 @@ public: void process_final_incomplete_block (const byte*data, int n) { int i; + if (data == NULL && n == 0) { + //empty block, finalize + X[31] ^= 1; + rounds (F); + return; + } + assert(data != NULL && n != 0); // if only one is NULL/0, it's a bug for (i = 0; i + 4 <= n; i += 4) #if __BYTE_ORDER__==__ORDER_LITTLE_ENDIAN__