-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsha3.c
42 lines (33 loc) · 1.29 KB
/
sha3.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
/* A generic interface for any NIST SHA-3 contest entry.
Written for use with the GNU Coreutils md5sum program.
Copyright (C) 2008 Sam Fredrickson <kinghajj@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <stddef.h>
#include <stdio.h>
#include "SHA3api_ref.h"
#include "sha3.h"
#define BUFFER_SIZE 4096
int sha3_stream(FILE *stream, void *resblock)
{
unsigned char buffer[BUFFER_SIZE];
hashState state;
HashReturn r;
size_t read;
r = Init(&state, HASH_ALGO_SHA3_BLOCK_SIZE * 8);
if(r == SUCCESS) {
while(r == SUCCESS &&
(read = fread(buffer, 1, BUFFER_SIZE, stream)))
r = Update(&state, buffer, read * 8);
Final(&state, resblock);
}
return r == SUCCESS ? 0 : 1;
}