LIBKECCAK_UPDATE(3)

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

✨ NAME ✨

okay so we're in the LIBKECCAK manual, page LIBKECCAK_UPDATE(3), and the main character is libkeccak_update β€” partially hash a message with erasure. no cap, that's the whole vibe πŸ’…


🌸 SYNOPSIS 🌸

#include <libkeccak.h>

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

link it up with -lkeccak, bestie 🫢


πŸ¦‹ DESCRIPTION πŸ¦‹

so libkeccak_update() continues β€” or starts β€” hashing a message. the current state of the hashing lives in *state, and yeah, it gets updated. the message you pass in msg, with the byte-size you pass in msglen, is what gets hashed. periodt ✨

also important: libkeccak_update() may reallocate the state's message chunk buffer. when it does that, it tries to do it as securely as possible rather than as fast as possible. it's giving safety over speed, and honestly? iconic πŸ”₯


πŸ‘‘ RETURN VALUES πŸ‘‘

  • 0 β€” slayed, successful completion πŸ’–
  • -1 β€” something went wrong, and errno is set to describe the error 😭

🌈 ERRORS 🌈

libkeccak_update() may fail for any reason specified by the function malloc(3). that's the whole list, no extras, fr fr.


πŸŽ€ NOTES πŸŽ€

neither parameter may be NULL or 0. literally neither. don't do it πŸ™ˆ


πŸ“ EXAMPLE πŸ“

this example calculates the Keccak[b = 1024, c = 576, n = 256] hash of the input from stdin, and prints the hash, in hexadecimal form, to stdout. it's giving main character energy ⭐

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_update(&state, chunk, (size_t)len) < 0)
          goto fail;
}
if (libkeccak_digest(&state, NULL, 0, 0, "", binhash) < 0)
     goto fail;

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

🧚 NOTES (the cSHAKE one) 🧚

for cSHAKE, you gotta call libkeccak_cshake_initialise(3) once, immediately after state initialisation β€” before the first call to libkeccak_update(). don't skip it, bestie, iykyk πŸ’œ


πŸ’« SEE ALSO πŸ’«


and that's the page, bestie 🫢 source: LIBKECCAK; page: LIBKECCAK_UPDATE(3). go hash something cute πŸ’–βœ¨

πŸ“¦ where this page comes from