b2sum.cc (579B)
1 #include <stdio.h> 2 3 #include "ggformat.h" 4 5 #include "libs/monocypher/monocypher.h" 6 7 int main() { 8 crypto_blake2b_ctx blake; 9 crypto_blake2b_general_init( &blake, 32, NULL, 0 ); 10 11 while( true ) { 12 u8 buf[ 8192 ]; 13 ssize_t n = fread( buf, 1, sizeof( buf ), stdin ); 14 if( n == 0 ) 15 break; 16 if( n < 0 ) { 17 perror( "" ); 18 return 1; 19 } 20 21 crypto_blake2b_update( &blake, buf, size_t( n ) ); 22 } 23 24 u8 digest[ 32 ]; 25 crypto_blake2b_final( &blake, digest ); 26 27 for( size_t i = 0; i < sizeof( digest ); i++ ) { 28 ggprint( "{02x}", digest[ i ] ); 29 } 30 ggprint( "\n" ); 31 32 return 0; 33 }