LIBKECCAK_UPDATE(3)
β¨ 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, anderrnois 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 π«
libkeccak_state_initialise(3)libkeccak_cshake_initialise(3)libkeccak_fast_update(3)libkeccak_zerocopy_update(3)libkeccak_fast_digest(3)libkeccak_zerocopy_digest(3)libkeccak_digest(3)
and that's the page, bestie π«Ά source: LIBKECCAK; page: LIBKECCAK_UPDATE(3). go hash something cute πβ¨
π¦ where this page comes from
- arch rolling: libkeccak 1.4.3-1 Β· custom:ISC
- opensuse-leap 16.0: libkeccak-devel 1.4-bp160.1.13 Β· ISC
- opensuse-leap 16.0: libkeccak-devel 1.4-bp160.1.13 Β· ISC
- opensuse-leap 16.0: libkeccak-devel 1.4-bp160.1.13 Β· ISC
- opensuse-leap 16.0: libkeccak-devel 1.4-bp160.1.13 Β· ISC
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms