01fe486b90dec22946df1d22300f3b69e1ba03f2
8 #include "../keccak-ref/Sources/KeccakSponge.c"
9 #include "../keccak-ref/Sources/KeccakF-1600-reference.c"
10 #include "../keccak-ref/Sources/displayIntermediateValues.c"
12 #define HI_NIBBLE(b) (((b) >> 4) & 0x0F)
13 #define LO_NIBBLE(b) ((b) & 0x0F)
15 int main(int argc
, char *argv
[]) {
21 struct stat input_stat
;
22 unsigned char *input_buf
, *output_buf
;
23 size_t input_bytes_read
;
27 printf("no input file provided\nUSAGE: %s <file>\n", argv
[0]);
30 } else if( ! (input
= fopen(argv
[1], "r"))) {
32 printf("error opening file '%s'\n", argv
[1]);
36 /* significant values */
40 state
= (spongeState
*) calloc(1, sizeof(spongeState
));
42 if(stat(argv
[1], &input_stat
) || input_stat
.st_size
<= 0) {
44 printf("failed to stat '%s'\n", argv
[1]);
47 } else if(InitSponge(state
, r
, c
) || !state
) {
49 printf("error during sponge construction\n");
52 } else if(input_stat
.st_size
> SIZE_MAX
) {
54 printf("large files not supported yet\n");
58 input_buf
= (unsigned char *) calloc(1, (size_t) input_stat
.st_size
);
59 output_buf
= (unsigned char *) calloc(1, (size_t) 64);
61 if( ! (input_bytes_read
= fread(input_buf
, 1, (size_t)input_stat
.st_size
, input
))) {
63 printf("error reading file\n");
69 if(Absorb(state
, input_buf
, (unsigned long long) (8 * input_stat
.st_size
))) {
71 printf("encryption failure\n");
74 } else if(Squeeze(state
, output_buf
, (unsigned long long) (8 * input_stat
.st_size
))) {
76 printf("decryption failure\n");
82 printf("%x%x", HI_NIBBLE(output_buf
[i
]), LO_NIBBLE(output_buf
[i
]));