-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.c
82 lines (69 loc) · 1.99 KB
/
main.c
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
#include <err.h>
#include <errno.h>
#include <getopt.h>
#include <limits.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "cubehash.h"
static void usage(char *error)
{
bool iserror = error || errno;
if (iserror && strlen(error))
warn(error);
fprintf(
iserror ? stderr : stdout,
"%s"
"Usage: cubehash [OPTIONS] [PARAMETERS] \n"
" \n"
"OPTIONS \n"
" -2 Use the second revision of proposed CubeHash parameters, implementing \n"
" CubeHash160+16/32+160-h for hash length h. \n"
" -3 Use the third revision of proposed CubeHash parameters, implementing \n"
" CubeHash16+16/32+32-h for hash length h. This is the default. \n"
" -l HASHLEN \n"
" Set the hash length in bits (default: 256). The hash length must be \n"
" positive, evenly divisible by 8, and not greater than 512. \n"
" -h Show this help text and exit. \n",
iserror ? "\n" : ""
);
exit(iserror);
}
int main(int argc, char *argv[])
{
bool done = false;
int hashlen = 256, revision = 3;
char *endptr;
while (!done)
switch (getopt(argc, argv, "23l:h")) {
case '2':
revision = 2;
break;
case '3':
revision = 3;
break;
case 'l':
hashlen = (int) strtol(optarg, &endptr, 0);
if (&optarg[strlen(optarg)] != endptr)
{
errno = EINVAL;
usage("-l HASHLEN");
}
break;
case 'h':
usage(NULL);
break;
case -1:
done = true;
break;
default:
usage("");
}
uint8_t *hash = cubehash(stdin, revision, hashlen);
if (errno == EDOM)
usage("-l HASHLEN");
for (int i = 0; i < hashlen / 8; i++)
printf("%02x", hash[i]);
puts("");
}