LIBKECCAK_KECCAKSUM_FD(3)

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

πŸ’– LIBKECCAK_KECCAKSUM_FD(3) β€” straight from the LIBKECCAK manual, bestie πŸ’–

✨ NAME ✨

libkeccak_keccaksum_fd β€” Calculate a Keccak hashsum of a file. That’s the whole name, and honestly it ate πŸ’…

🌸 SYNOPSIS 🌸

#include <libkeccak.h>

int libkeccak_keccaksum_fd(int fd, struct libkeccak_state *state, const struct libkeccak_spec *spec, void *hashsum);

Link with -lkeccak.

πŸ¦‹ DESCRIPTION πŸ¦‹

Okay so libkeccak_keccaksum_fd() calculates a Keccak hashsum of a file. The file descriptor is fd, and bestie, it should be at the beginning of the file. The hash algorithm tuning is specified by *spec.

The hash is stored in binary form to hashsum. hashsum should have an allocation size of at least (((spec->output + 7) / 8) * sizeof(char)).

πŸ’… Do not initialise *state first! libkeccak_keccaksum_fd() initialises *state itself. Therefore there would be a memory leak if *state is already initialised. Not iconic, bestie 😭

πŸ’œ RETURN VALUES πŸ’œ

The libkeccak_keccaksum_fd() function returns 0 upon successful completion. On error, -1 is returned and errno is set to describe the error.

πŸŽ€ ERRORS πŸŽ€

libkeccak_keccaksum_fd() may fail for literally any reason, except those resulting in errno being set to EINTR, specified for the functions read(2), malloc(3), and realloc(3).

πŸ”₯ NOTES πŸ”₯

  • Be aware: libkeccak_keccaksum_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, this usually means never. Attempting to hash files in /dev is therefore usually a bad idea. libkeccak_keccaksum_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.
  • libkeccak_keccaksum_fd() does not stop if interrupted (read(2) returns EINTR.)
  • libkeccak_keccaksum_fd() assumes all information is non-sensitive, and will therefore not perform any secure erasure of information.
  • libkeccak_keccaksum_fd() does not validate the tuning of the algorithm.

🌈 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.

       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_keccaksum_fd(STDIN_FILENO, &state, &spec, binhash) < 0)
            goto fail;
       libkeccak_behex_lower(hexhash, binhash, sizeof(binhash));
       printf("%s\n", hexhash);
       libkeccak_state_destroy(&state);

πŸ’« SEE ALSO πŸ’«


source/version: LIBKECCAK; date: not listed, so it’s timeless β€” xoxo, bestie πŸ’–

πŸ“¦ where this page comes from