LIBKECCAK_RAWSHAKESUM_FD(3)

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

πŸ’– LIBKECCAK_RAWSHAKESUM_FD(3) πŸ’–

okay bestie, this one is from the Library Functions Manual, and it’s giving β€œtiny C function, very specific job” energy ✨


🌸 NAME 🌸

libkeccak_rawshakesum_fd β€” Calculate a RawSHAKE hashsum of a file, periodt πŸ’…


✨ SYNOPSIS ✨

#include <libkeccak.h>

int libkeccak_rawshakesum_fd(int fd, struct libkeccak_state *state, long int semicapacity, long int output, void *hashsum);

Link with -lkeccak. 🫢


πŸ’… DESCRIPTION πŸ’…

okay so libkeccak_rawshakesum_fd() calculates a RawSHAKE hashsum of a file. The file descriptor is fd, and fr fr it should be at the beginning of the file. πŸ‘‘

The hash algorithm is tuned by the semicapacity and output parameters; they specify the half of the capacity and the output size, respectively, in bits:

  • semicapacity β€” half of the capacity, in bits.
  • output β€” output size, in bits.

The hash is stored in binary form to hashsum. hashsum should have an allocation size of at least (((output + 7) / 8) * sizeof(char)). no cap, that formula matters 😭

⚠️ *state should not be initialised. libkeccak_rawshakesum_fd() initialises *state itself. Therefore there would be a memory leak if *state is already initialised. bestie please do not pre-initialise it πŸ’€

🫢 RETURN VALUES 🫢

The libkeccak_rawshakesum_fd() function returns 0 upon successful completion. On error, -1 is returned and errno is set to describe the error. simple as that ✨


😭 ERRORS 😭

The libkeccak_rawshakesum_fd() function may fail for any reason, except those resulting in errno being set to EINTR, specified for the functions read(2), malloc(3), and realloc(3). that’s the exception list, iykyk 🧚


🧚 NOTES 🧚

Be aware, libkeccak_rawshakesum_fd() hashes the file until the end has been reached. For pipes and sockets, this means until the file has been closed. But for character devices, this usually means never. 😭

⚠️ Attempting to hash files in /dev is therefore usually a bad idea. like, highkey do not do that πŸ’€

libkeccak_rawshakesum_fd() does not check for the file length or file type before hashing as this could limit what you can do, and make the library more complex. it’s giving β€œwe trust you, main character” energy πŸ¦‹

libkeccak_rawshakesum_fd() does not stop if interrupted (read(2) returns EINTR.) 🫢

libkeccak_rawshakesum_fd() assumes all information is non-sensitive, and will therefore not perform any secure erasure of information. πŸ”₯

libkeccak_rawshakesum_fd() does not validate the tuning of the algorithm. πŸ‘‘


πŸ”₯ EXAMPLE πŸ”₯

This example calculates the RawSHAKE256(, 512) hash of the input from stdin, and prints the hash, in hexadecimal form, to stdout.

struct libkeccak_state state;
if (libkeccak_rawshakesum_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);

slay, that’s the whole example πŸ’–


🌈 SEE ALSO 🌈


xoxo, your LIBKECCAK bestie πŸ’– β€” source/version vibes: LIBKECCAK; page: LIBKECCAK_RAWSHAKESUM_FD(3); date: the original footer doesn’t give me one, so I’m not inventing it, periodt πŸ’…

πŸ“¦ where this page comes from