aboutsummaryrefslogtreecommitdiffstats
path: root/common.h
blob: f11603552606c4b1021b09cdff69e88309aee200 (plain) (blame)
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
/* See LICENSE file for copyright and license details. */
#include <libkeccak.h>


#define COMMON_MAIN(CONFIGURATION, SUFFIX)\
	int main(int argc, char *argv[]) {\
		struct libkeccak_generalised_spec spec;\
		libkeccak_generalised_spec_initialise(&spec);\
		CONFIGURATION;\
		return run(argc, argv, &spec, SUFFIX);\
	}
#define KECCAK_MAIN(N)\
	COMMON_MAIN(libkeccak_spec_sha3((struct libkeccak_spec *)&spec, N), "")
#define SHA3_MAIN(N)\
	COMMON_MAIN(libkeccak_spec_sha3((struct libkeccak_spec *)&spec, N), LIBKECCAK_SHA3_SUFFIX)
#define RAWSHAKE_MAIN(N)\
	COMMON_MAIN(libkeccak_spec_rawshake((struct libkeccak_spec *)&spec, N, N), LIBKECCAK_RAWSHAKE_SUFFIX)
#define SHAKE_MAIN(N)\
	COMMON_MAIN(libkeccak_spec_shake((struct libkeccak_spec *)&spec, N, N), LIBKECCAK_SHAKE_SUFFIX)


/**
 * Message digest representation formats
 */
enum representation {
	/**
	 * Print the checksum in binary
	 */
	REPRESENTATION_BINARY,

	/**
	 * Print the checksum in upper case hexadecimal
	 */
	REPRESENTATION_UPPER_CASE,

	/**
	 * Print the checksum in lower case hexadecimal
	 */
	REPRESENTATION_LOWER_CASE
};


/**
 * Parse the command line and calculate the hashes of the selected files
 * 
 * @param   argc    The first argument from `main`
 * @param   argv    The second argument from `main`
 * @param   gspec   The default algorithm parameters
 * @param   suffix  Message suffix
 * @return          An appropriate exit value
 */
int run(int argc, char *argv[], struct libkeccak_generalised_spec *restrict gspec, const char *restrict suffix);