* 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.
#endif
#include <assert.h>
-#include <limits.h>
#include <string.h>
#include "sha3.h"
#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,
{
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. */
index = block_size;
}
else
- index &= ~INDEX_HIGH_BIT;
+ index = ~index;
assert (index <= block_size);
if (length <= left)
{
memcpy (dst, block + index, length);
- return (index + length) | INDEX_HIGH_BIT;
+ return ~(index + length);
}
else
{
/* 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;
}