>From 4a67a8f633c7f1b7eb12279be90326ca6062389f Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Wed, 15 May 2019 12:57:53 -0700 Subject: [PATCH 2/2] b2sum: sync better with upstream * src/blake2/b2sum.c: Reorder source code to minimize diffs from: https://github.com/BLAKE2/BLAKE2/blob/master/b2sum/b2sum.c --- src/blake2/b2sum.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/blake2/b2sum.c b/src/blake2/b2sum.c index 5cb25b86a..9f1108137 100644 --- a/src/blake2/b2sum.c +++ b/src/blake2/b2sum.c @@ -30,18 +30,19 @@ #include "blake2.h" +#if 0 /* This will help compatibility with coreutils */ -int blake2b_stream( FILE *stream, void *resstream, size_t outbytes ) +int blake2s_stream( FILE *stream, void *resstream, size_t outbytes ) { int ret = -1; size_t sum, n; - blake2b_state S[1]; + blake2s_state S[1]; static const size_t buffer_length = 32768; uint8_t *buffer = ( uint8_t * )malloc( buffer_length ); if( !buffer ) return -1; - blake2b_init( S, outbytes ); + blake2s_init( S, outbytes ); while( 1 ) { @@ -67,32 +68,32 @@ int blake2b_stream( FILE *stream, void *resstream, size_t outbytes ) goto final_process; } - blake2b_update( S, buffer, buffer_length ); + blake2s_update( S, buffer, buffer_length ); } final_process:; - if( sum > 0 ) blake2b_update( S, buffer, sum ); + if( sum > 0 ) blake2s_update( S, buffer, sum ); - blake2b_final( S, resstream, outbytes ); + blake2s_final( S, resstream, outbytes ); ret = 0; cleanup_buffer: free( buffer ); return ret; } +#endif -#if 0 -int blake2s_stream( FILE *stream, void *resstream, size_t outbytes ) +int blake2b_stream( FILE *stream, void *resstream, size_t outbytes ) { int ret = -1; size_t sum, n; - blake2s_state S[1]; + blake2b_state S[1]; static const size_t buffer_length = 32768; uint8_t *buffer = ( uint8_t * )malloc( buffer_length ); if( !buffer ) return -1; - blake2s_init( S, outbytes ); + blake2b_init( S, outbytes ); while( 1 ) { @@ -118,20 +119,21 @@ int blake2s_stream( FILE *stream, void *resstream, size_t outbytes ) goto final_process; } - blake2s_update( S, buffer, buffer_length ); + blake2b_update( S, buffer, buffer_length ); } final_process:; - if( sum > 0 ) blake2s_update( S, buffer, sum ); + if( sum > 0 ) blake2b_update( S, buffer, sum ); - blake2s_final( S, resstream, outbytes ); + blake2b_final( S, resstream, outbytes ); ret = 0; cleanup_buffer: free( buffer ); return ret; } +#if 0 int blake2sp_stream( FILE *stream, void *resstream, size_t outbytes ) { @@ -253,6 +255,7 @@ static void usage( char **argv, int errcode ) exit( errcode ); } + int main( int argc, char **argv ) { blake2fn blake2_stream = blake2b_stream; -- 2.21.0