LIBKECCAK_SHAKESUM_FD(3)

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

πŸ’… 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 β€” *state should not be initialised. libkeccak_shakesum_fd() initialises *state itself. So if *state is already initialised, you get a memory leak. not cute. πŸ’€

🧚 RETURN VALUES 🧚

  • Returns 0 when everything slays ✨
  • On error, returns -1 and sets errno to 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 /dev is 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) returns EINTR). 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