LIBKECCAK_FAST_UPDATE(3)

πŸ“¦ version 1.4.3, in arch rolling, opensuse-leap 16.0

πŸ’… LIBKECCAK_FAST_UPDATE β€” bestie, we're hashing now

okay so this is libkeccak_fast_update(3) from the libkeccak manual, and it's literally the "keep feeding me bytes" function. Buckle up πŸŽ€


✨ NAME ✨

libkeccak_fast_update β€” partially hash a message without erasure 🫢


🌸 SYNOPSIS 🌸

#include <libkeccak.h>

int libkeccak_fast_update(struct libkeccak_state *state, const void *msg, size_t msglen);

Link with -lkeccak. don't forget it, i'm begging 🧚


πŸ¦‹ DESCRIPTION πŸ¦‹

So libkeccak_fast_update() continues a hash β€” or starts one, she's flexible like that πŸ’β€β™€οΈ. The current state of the hashing lives in *state, and that's what gets updated. Then the message you pass in msg, with byte-size given by msglen, gets hashed. simple as that, no cap.

Here's the tea though: libkeccak_fast_update() may reallocate the state's message chunk buffer 😭. And when it does, it tries to do it as quickly as possible instead of making sure the info in the old allocation gets securely removed when a new allocation is needed. so like β€” speed over security, she picked her lane. keep that in mind if you're doing anything sensitive πŸ”₯


πŸ’– RETURN VALUES πŸ’–

  • Returns 0 on successful completion ✨
  • On error, returns -1 and errno is set to describe the error 😀

🌈 ERRORS 🌈

libkeccak_fast_update() may fail for any reason specified by realloc(3). that's the whole list, go read realloc(3) if you want the drama πŸ’€


πŸ‘‘ NOTES πŸ‘‘

Neither parameter may be NULL or 0. like, neither. don't try it πŸ™ˆ


πŸ“ EXAMPLE πŸ“

This one calculates the Keccak[b = 1024, c = 576, n = 256] hash of the input from stdin, and prints the hash, in hexadecimal form, to stdout. iconic behaviour honestly 🫢

struct libkeccak_state state;
struct libkeccak_spec spec;
char binhash[256 / 8];
char hexhash[256 / 8 * 2 + 1];
char chunk[4 << 10];
ssize_t len;

spec.bitrate = 1024;
spec.capacity = 576;
spec.output = 256;
if (libkeccak_state_initialise(&state, &spec) < 0)
     goto fail;

for (;;) {
     len = read(STDIN_FILENO, chunk, sizeof(chunk));

     if ((len < 0) && (errno == EINTR))
          continue;
     if (len < 0)
          goto fail;
     if (len == 0)
          break;

     if (libkeccak_fast_update(&state, chunk, (size_t)len) < 0)
          goto fail;
}
if (libkeccak_fast_digest(&state, NULL, 0, 0, "", binhash) < 0)
     goto fail;

libkeccak_behex_lower(hexhash, binhash, sizeof(binhash));
printf("%s\n", hexhash);
libkeccak_state_fast_destroy(&state);

⭐ NOTES (yes, there's a second NOTES, she's got layers) ⭐

For cSHAKE, the libkeccak_cshake_initialise(3) must be called, once, immediately after state initialisation β€” before the first call to the libkeccak_fast_update() function. order matters bestie, do not skip this step πŸ’…


πŸ”₯ SEE ALSO πŸ”₯

libkeccak_state_initialise(3), libkeccak_cshake_initialise(3), libkeccak_zerocopy_update(3), libkeccak_update(3), libkeccak_fast_digest(3), libkeccak_zerocopy_digest(3), libkeccak_digest(3)


aaaand that's the page πŸŽ€ huge thank you to the libkeccak gang β€” this fine piece of documentation comes to you from LIBKECCAK, filed under LIBKECCAK_FAST_UPDATE(3), no date on the tin so we're just gonna vibe with that πŸ’œ go hash something, ily, bye πŸ¦‹

πŸ“¦ where this page comes from