chibipub

experimental activitypub node in C
git clone git://jb55.com/chibipub
Log | Files | Refs | README | LICENSE

example.c (661B)


      1 #include "blake3.h"
      2 #include <stdio.h>
      3 #include <unistd.h>
      4 
      5 int main() {
      6   // Initialize the hasher.
      7   blake3_hasher hasher;
      8   blake3_hasher_init(&hasher);
      9 
     10   // Read input bytes from stdin.
     11   unsigned char buf[65536];
     12   ssize_t n;
     13   while ((n = read(STDIN_FILENO, buf, sizeof(buf))) > 0) {
     14     blake3_hasher_update(&hasher, buf, n);
     15   }
     16 
     17   // Finalize the hash. BLAKE3_OUT_LEN is the default output length, 32 bytes.
     18   uint8_t output[BLAKE3_OUT_LEN];
     19   blake3_hasher_finalize(&hasher, output, BLAKE3_OUT_LEN);
     20 
     21   // Print the hash as hexadecimal.
     22   for (size_t i = 0; i < BLAKE3_OUT_LEN; i++) {
     23     printf("%02x", output[i]);
     24   }
     25   printf("\n");
     26   return 0;
     27 }