LIBKECCAK_...SED_SUM_FD(3)
π LIBKECCAK_...SED_SUM_FD(3) β¨
okay so this is a page from the Library Functions Manual and honestly? it's a glow-up for your hashing era. sit down, grab a strawberry drink π, we're learning about libkeccak_generalised_sum_fd.
πΈ NAME πΈ
libkeccak_generalised_sum_fd β literally just calculates the hash of a file, no cap π
π¦ SYNOPSIS π¦
#include <libkeccak.h>
int libkeccak_generalised_sum_fd(int fd, struct libkeccak_state *state, const struct libkeccak_spec *spec,
const char *suffix, void *hashsum);
and like, don't forget to link with -lkeccak or it's giving broken build energy π
π DESCRIPTION π
so libkeccak_generalised_sum_fd() hashes a file for you β the file is the one whose file descriptor you pass in as fd, and bestie, that descriptor should be at the beginning of the file before you start, mkay? π
the actual hash algorithm is picked by *spec and suffix, where *spec is the tuning of the algorithm and suffix is the bits appended to the message β or NULL if there are none, no pressure π«Ά
the hash gets stored in binary form into hashsum. and hashsum needs an allocation size of at least:
(((spec->output + 7) / 8) * sizeof(char))
don't skimp on the memory, it's not cute π
now the spicy part πΆοΈ β *state should not be initialised unless spec is NULL. libkeccak_generalised_sum_fd() initialises *state itself unless spec is NULL. so if *state is already initialised and spec is non-NULL, you get a memory leak. not the vibe, watch out for it π
β RETURN VALUES β
- returns
0when everything slays (successful completion) β¨ - on error it returns
-1anderrnogets set to describe the error, so you know exactly what went wrong π
π₯ ERRORS π₯
libkeccak_generalised_sum_fd() may fail for any reason β the only exceptions are those that would set errno to EINTR, as specified for the functions read(2), malloc(3), and realloc(3). so like, it's a whole spectrum of possible failure, iykyk π
π§ NOTES π§ (read these fr fr)
- be aware:
libkeccak_generalised_sum_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/devis therefore usually a bad idea π© libkeccak_generalised_sum_fd()does not check for the file length or file type before hashing, because that could limit what you can do and make the library more complex. freedom, but at what cost πlibkeccak_generalised_sum_fd()does not stop if interrupted (read(2)returnsEINTR). it's a stubborn icon, periodt.libkeccak_generalised_sum_fd()assumes all information is non-sensitive, and will therefore not perform any secure erasure of information π«£libkeccak_generalised_sum_fd()does not validate the tuning of the algorithm. it trusts you. main character energy, honestly π
π EXAMPLE π
this one calculates the Keccak[b = 1024, c = 576, n = 256] hash of the input from stdin, and prints the hash, in hexadecimal form, to stdout. iconic behaviour, look:
struct libkeccak_state state;
struct libkeccak_spec spec;
char binhash[256 / 8];
char hexhash[256 / 8 * 2 + 1];
spec.bitrate = 1024;
spec.capacity = 576;
spec.output = 256;
if (libkeccak_generalised_sum_fd(STDIN_FILENO, &state, &spec, NULL, binhash) < 0)
goto fail;
libkeccak_behex_lower(hexhash, binhash, sizeof(binhash));
printf("%s\n", hexhash);
libkeccak_state_destroy(&state);
copy it, run it, live it π
π SEE ALSO π
go read these next, bestie, they're all part of the same friend group:
libkeccak_behex_lower(3)libkeccak_behex_upper(3)libkeccak_keccaksum_fd(3)libkeccak_sha3sum_fd(3)libkeccak_rawshakesum_fd(3)libkeccak_shakesum_fd(3)libkeccak_spec_cshake(3)libkeccak_spec_sha3(3)libkeccak_spec_shake(3)libkeccak_spec_rawshake(3)libkeccak_spec_check(3)libkeccak_generalised_spec_initialise(3)libkeccak_state_initialise(3)
ok that's the whole page!! π this diva comes to you from LIBKECCAK, dated LIBKECCAK_...SED_SUM_FD(3) β stay hashing, stay hydrated, mwah ππβ¨
π¦ 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