10 #include "lib/blake2/ref/blake2.h"
12 static int hash_file(int fd, char *hash) {
13 unsigned char buf[4096];
15 unsigned char tmp[32];
19 struct sha256_state md;
22 bytes = read(fd, buf, sizeof buf);
26 sha256_process(&md, buf, bytes);
28 sha256_done(&md, tmp);
30 sprintf(hash+j*2, "%02x", (unsigned)tmp[j]);
35 struct blake2b_state__ blake;
36 blake2b_init(&blake, sizeof tmp);
38 bytes = read(fd, buf, sizeof buf);
42 blake2b_update(&blake, buf, bytes);
44 blake2b_final(&blake, tmp, sizeof tmp);
46 sprintf(hash+j*2, "%02x", (unsigned)tmp[j]);
53 int main(int ac, char **av){
60 for (i=1; i < ac; i++) {
62 if (strcmp(filename, "-") == 0) {
65 input = open(filename, O_RDONLY);
67 fprintf(stderr, "%s ", filename);
72 rv = hash_file(input, hash);
83 rv = hash_file(0, hash);