+#include "lib/blake2/ref/blake2.h"
+
+static int hash_file(int fd, char *hash) {
+ unsigned char buf[4096];
+ ssize_t bytes;
+ unsigned char tmp[32];
+ int j;
+
+#if 0
+ struct sha256_state md;
+ sha256_init(&md);
+ do {
+ bytes = read(fd, buf, sizeof buf);
+ if (bytes == -1) {
+ return 0;
+ }
+ sha256_process(&md, buf, bytes);
+ } while (bytes);
+ sha256_done(&md, tmp);
+ for (j=0;j<32;j++) {
+ sprintf(hash+j*2, "%02x", (unsigned)tmp[j]);
+ }
+ hash[64] = 0;
+
+#else
+ struct blake2b_state__ blake;
+ blake2b_init(&blake, sizeof tmp);
+ do {
+ bytes = read(fd, buf, sizeof buf);
+ if (bytes == -1) {
+ return 0;
+ }
+ blake2b_update(&blake, buf, bytes);
+ } while (bytes);
+ blake2b_final(&blake, tmp, sizeof tmp);
+ for (j=0;j<32;j++) {
+ sprintf(hash+j*2, "%02x", (unsigned)tmp[j]);
+ }
+ hash[64] = 0;
+#endif
+ return 1;
+}