LIBKECCAK_SHAKESUM_FD(3)
π LIBKECCAK_SHAKESUM_FD(3) β like, the SHAKE hashsum of a file, bestie β¨
okay so you found the libkeccak_shakesum_fd page in the Library Functions Manual and you're like "what is this" β don't worry, I got you π«Ά this one function will take a whole file and turn it into a SHAKE hashsum, and yes it's as iconic as it sounds.
β¨ NAME β¨
libkeccak_shakesum_fd β calculate a SHAKE hashsum of a file πΈ
π SYNOPSIS π
#include <libkeccak.h>
int libkeccak_shakesum_fd(int fd, struct libkeccak_state *state, long int semicapacity, long int output, void *hashsum);
and like, link with -lkeccak obviously π
π¦ DESCRIPTION π¦
So libkeccak_shakesum_fd() computes a SHAKE hashsum of a file β and the file is specified by its file descriptor fd, which lowkey should be at the beginning of the file, just saying π
The hash algorithm gets tuned by two params, semicapacity and output: they're the half of the capacity and the output size, respectively, both in bits. That's it, that's the vibe check π
The hash lands in hashsum, in binary form, no hex prettiness here. And hashsum needs an allocation size of at least (((output + 7) / 8) * sizeof(char)) β no cap, size it right π
bestie listen β*stateshould not be initialised.libkeccak_shakesum_fd()initialises*stateitself. So if*stateis already initialised, you get a memory leak. not cute. π
π§ RETURN VALUES π§
- Returns
0when everything slays β¨ - On error, returns
-1and setserrnoto describe the error π₯
π ERRORS π
libkeccak_shakesum_fd() may fail for any reason β except those that result in errno being set to EINTR, which are specified for the functions read(2), malloc(3), and realloc(3). So yeah, it can fail, just not that way π
π NOTES π (read these fr fr)
- Be aware:
libkeccak_shakesum_fd()hashes the file until the end has been reached π For pipes and sockets, that means until the file has been closed. But for character devices? That usually means never. So attempting to hash files in/devis usually a bad idea β like, genuinely, don't π libkeccak_shakesum_fd()does not check for the file length or file type before hashing, because that could limit what you can do and would make the library more complex. main character energy: it trusts you β¨libkeccak_shakesum_fd()does not stop if interrupted (read(2)returnsEINTR). it's committed to the bit πlibkeccak_shakesum_fd()assumes all information is non-sensitive, and will therefore not perform any secure erasure of information. so don't put your secrets in there π«Άlibkeccak_shakesum_fd()does not validate the tuning of the algorithm. you're on your own for that one π
π EXAMPLE π
This example calculates the SHAKE256(, 512) hash of the input from stdin, and prints the hash, in hexadecimal form, to stdout. iconic behaviour honestly π
struct libkeccak_state state;
if (libkeccak_shakesum_fd(STDIN_FILENO, &state, 256, 512, binhash) < 0)
goto fail;
libkeccak_behex_lower(hexhash, binhash, sizeof(binhash));
printf("%s\n", hexhash);
libkeccak_state_destroy(&state);
β SEE ALSO β
libkeccak_behex_lower(3), libkeccak_behex_upper(3), libkeccak_generalised_sum_fd(3), libkeccak_keccaksum_fd(3), libkeccak_sha3sum_fd(3), libkeccak_rawshakesum_fd(3), libkeccak_spec_shake(3), libkeccak_spec_check(3), libkeccak_generalised_spec_initialise(3), libkeccak_state_initialise(3)
and that's the whole page bestie π this one comes from the LIBKECCAK library, and it's literally pages 3 of the Library Functions Manual β the same LIBKECCAK_SHAKESUM_FD(3) you started with, wrapped up with a bow π go forth and hash, ily, bye! π
β¨
π¦ 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