]> git.ipfire.org Git - thirdparty/nettle.git/commitdiff
Use one's complement of index to indicate shake is initialized.
authorNiels Möller <nisse@lysator.liu.se>
Sun, 24 Mar 2024 13:18:01 +0000 (14:18 +0100)
committerNiels Möller <nisse@lysator.liu.se>
Sun, 24 Mar 2024 13:18:01 +0000 (14:18 +0100)
ChangeLog
sha3-shake.c

index e975efb85205b04235e7a10d42e9accdadd64254..ae2675da784e95b9403823ff49ca2046f12e2813 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -3,6 +3,9 @@
        * sha3-shake.c (_nettle_sha3_shake, _nettle_sha3_shake_output):
        New file, new functions. Generalizations of sha3_256_shake and
        sha3_256_shake_output, respectively.
+       (_nettle_sha3_shake_output): Use one's complement of index,
+       instead of just setting high bit.
+
        * shake256.c (sha3_256_shake, sha3_256_shake_output): Implement in
        terms of calls to the new functions.
        * Makefile.in (nettle_SOURCES): Add sha3-shake.c.
index d52d011d5b9ab31cebe9601a278707a3c6ea8fef..467a6d42bbfa29ff0a00f40a374ecbc8df19ded9 100644 (file)
@@ -36,7 +36,6 @@
 #endif
 
 #include <assert.h>
-#include <limits.h>
 #include <string.h>
 
 #include "sha3.h"
@@ -44,8 +43,6 @@
 
 #include "nettle-write.h"
 
-#define INDEX_HIGH_BIT (~((UINT_MAX) >> 1))
-
 void
 _nettle_sha3_shake (struct sha3_state *state,
                    unsigned block_size, uint8_t *block,
@@ -74,7 +71,8 @@ _nettle_sha3_shake_output (struct sha3_state *state,
 {
   unsigned left;
 
-  /* We use the leftmost bit as a flag to indicate SHAKE is initialized. */
+  /* We use one's complement of the index value to indicate SHAKE is
+     initialized. */
   if (index < block_size)
     {
       /* This is the first call of _shake_output.  */
@@ -83,7 +81,7 @@ _nettle_sha3_shake_output (struct sha3_state *state,
       index = block_size;
     }
   else
-    index &= ~INDEX_HIGH_BIT;
+    index = ~index;
 
   assert (index <= block_size);
 
@@ -92,7 +90,7 @@ _nettle_sha3_shake_output (struct sha3_state *state,
   if (length <= left)
     {
       memcpy (dst, block + index, length);
-      return (index + length) | INDEX_HIGH_BIT;
+      return ~(index + length);
     }
   else
     {
@@ -114,5 +112,5 @@ _nettle_sha3_shake_output (struct sha3_state *state,
   /* Fill in the buffer for next call.  */
   _nettle_write_le64 (block_size, block, state->a);
   memcpy (dst, block, length);
-  return length | INDEX_HIGH_BIT;
+  return ~length;
 }