1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
/* See LICENSE file for copyright and license details. */
#ifndef LIBKECCAK_FILES_H
#define LIBKECCAK_FILES_H 1
#include "../libkeccak.h"
#include "internal.h"
/**
* Calculate a Keccak-family hashsum of a file,
* the content of the file is assumed non-sensitive
*
* @param fd The file descriptor of the file to hash
* @param state The hashing state, should not be initialised (memory leak otherwise)
* @param spec Specifications for the hashing algorithm
* @param suffix The data suffix, see `libkeccak_digest`
* @param hashsum Output array for the hashsum, have an allocation size of
* at least `((spec->output + 7) / 8) * sizeof(char)`, may be `NULL`
* @return Zero on success, -1 on error
*/
LIBKECCAK_GCC_ONLY(__attribute__((nonnull(2, 3))))
int libkeccak_generalised_sum_fd(int fd, libkeccak_state_t *restrict state,
const libkeccak_spec_t *restrict spec,
const char *restrict suffix, char *restrict hashsum);
/**
* Calculate the Keccak hashsum of a file,
* the content of the file is assumed non-sensitive
*
* @param fd The file descriptor of the file to hash
* @param state The hashing state, should not be initialised (memory leak otherwise)
* @param spec Specifications for the hashing algorithm
* @param hashsum Output array for the hashsum, have an allocation size of
* at least `((spec->output + 7) / 8) * sizeof(char)`, may be `NULL`
* @return Zero on success, -1 on error
*/
LIBKECCAK_GCC_ONLY(__attribute__((nonnull(2, 3), artificial, gnu_inline)))
static inline int
libkeccak_keccaksum_fd(int fd, libkeccak_state_t *restrict state,
const libkeccak_spec_t *restrict spec, char *restrict hashsum)
{
return libkeccak_generalised_sum_fd(fd, state, spec, NULL, hashsum);
}
/**
* Calculate the SHA3 hashsum of a file,
* the content of the file is assumed non-sensitive
*
* @param fd The file descriptor of the file to hash
* @param state The hashing state, should not be initialised (memory leak otherwise)
* @param output The output size parameter for the hashing algorithm
* @param hashsum Output array for the hashsum, have an allocation size of
* at least `((output + 7) / 8) * sizeof(char)`, may be `NULL`
* @return Zero on success, -1 on error
*/
LIBKECCAK_GCC_ONLY(__attribute__((nonnull(2), artificial, gnu_inline)))
static inline int
libkeccak_sha3sum_fd(int fd, libkeccak_state_t *restrict state,
long output, char *restrict hashsum)
{
libkeccak_spec_t spec;
libkeccak_spec_sha3(&spec, output);
return libkeccak_generalised_sum_fd(fd, state, &spec, LIBKECCAK_SHA3_SUFFIX, hashsum);
}
/**
* Calculate the RawSHAKE hashsum of a file,
* the content of the file is assumed non-sensitive
*
* @param fd The file descriptor of the file to hash
* @param state The hashing state, should not be initialised (memory leak otherwise)
* @param semicapacity The semicapacity parameter for the hashing algorithm
* @param output The output size parameter for the hashing algorithm
* @param hashsum Output array for the hashsum, have an allocation size of
* at least `((output + 7) / 8) * sizeof(char)`, may be `NULL`
* @return Zero on success, -1 on error
*/
LIBKECCAK_GCC_ONLY(__attribute__((nonnull(2), artificial, gnu_inline)))
static inline int
libkeccak_rawshakesum_fd(int fd, libkeccak_state_t *restrict state,
long semicapacity, long output, char *restrict hashsum)
{
libkeccak_spec_t spec;
libkeccak_spec_rawshake(&spec, semicapacity, output);
return libkeccak_generalised_sum_fd(fd, state, &spec, LIBKECCAK_RAWSHAKE_SUFFIX, hashsum);
}
/**
* Calculate the SHAKE hashsum of a file,
* the content of the file is assumed non-sensitive
*
* @param fd The file descriptor of the file to hash
* @param state The hashing state, should not be initialised (memory leak otherwise)
* @param semicapacity The semicapacity parameter for the hashing algorithm
* @param output The output size parameter for the hashing algorithm
* @param hashsum Output array for the hashsum, have an allocation size of
* at least `((output + 7) / 8) * sizeof(char)`, may be `NULL`
* @return Zero on success, -1 on error
*/
LIBKECCAK_GCC_ONLY(__attribute__((nonnull(2), artificial, gnu_inline)))
static inline int
libkeccak_shakesum_fd(int fd, libkeccak_state_t *restrict state,
long semicapacity, long output, char *restrict hashsum)
{
libkeccak_spec_t spec;
libkeccak_spec_shake(&spec, semicapacity, output);
return libkeccak_generalised_sum_fd(fd, state, &spec, LIBKECCAK_SHAKE_SUFFIX, hashsum);
}
#endif
|