int main( int argc, char **argv ) { uint8_t key[BLAKE2B_KEYBYTES]; uint8_t buf[KAT_LENGTH]; for( size_t i = 0; i < BLAKE2B_KEYBYTES; ++i ) key[i] = ( uint8_t )i; for( size_t i = 0; i < KAT_LENGTH; ++i ) buf[i] = ( uint8_t )i; for( size_t i = 0; i < KAT_LENGTH; ++i ) { uint8_t hash[BLAKE2B_OUTBYTES]; //blake2bp( hash, buf, key, BLAKE2B_OUTBYTES, i, BLAKE2B_KEYBYTES ); blake2bp_state S[1]; blake2bp_init_key( S, BLAKE2B_OUTBYTES, key, BLAKE2B_KEYBYTES ); blake2bp_update( S, buf, i ); blake2bp_final( S, hash, BLAKE2B_OUTBYTES ); if( 0 != memcmp( hash, blake2bp_keyed_kat[i], BLAKE2B_OUTBYTES ) ) { puts( "error" ); return -1; } } puts( "ok" ); return 0; }
int blake2bp_stream( FILE *stream, void *resstream ) { int ret = -1; size_t sum, n; blake2bp_state S[1]; static const size_t buffer_length = 16 * ( 1UL << 20 ); uint8_t *buffer = ( uint8_t * )malloc( buffer_length ); if( !buffer ) return -1; blake2bp_init( S, BLAKE2B_OUTBYTES ); while( 1 ) { sum = 0; while( 1 ) { n = fread( buffer + sum, 1, buffer_length - sum, stream ); sum += n; if( buffer_length == sum ) break; if( 0 == n ) { if( ferror( stream ) ) goto cleanup_buffer; goto final_process; } if( feof( stream ) ) goto final_process; } blake2bp_update( S, buffer, buffer_length ); } final_process:; if( sum > 0 ) blake2bp_update( S, buffer, sum ); blake2bp_final( S, resstream, BLAKE2B_OUTBYTES ); ret = 0; cleanup_buffer: free( buffer ); return ret; }
void cryptonite_blake2bp_finalize(blake2bp_ctx *ctx, uint32_t hashlen, uint8_t *out) { blake2bp_final(ctx, out, hashlen / 8); }