// Copyright 2017, 2018 Peter Dimov. // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt #include #include #include #include #include #include #include #include #include #include #include #include #include template void test( bool is_blake2 = false ) { char const * s = "xxxx"; { H h; h.update( s, 4 ); h.result(); unsigned char const * p = reinterpret_cast( &h ); std::size_t n = sizeof( h ); BOOST_TEST_EQ( std::search( p, p + n, s, s + 4 ) - p, n ); } { H h; unsigned char buffer[ 1024 ] = {}; h.update( buffer, 1024 ); h.update( s, 4 ); h.result(); unsigned char const * p = reinterpret_cast( &h ); std::size_t n = sizeof( h ); BOOST_TEST_EQ( std::search( p, p + n, s, s + 4 ) - p, n ); } if( !is_blake2 ) { // A 4 byte seed is sufficient to be treated as keyed construction for BLAKE2. // This means that the internal buffer will contain the seed here as it's // incorrect to transform the input without knowing if we have the last block // or not. // https://datatracker.ietf.org/doc/html/rfc7693#section-3.3 H h( s, 4 ); unsigned char const * p = reinterpret_cast( &h ); std::size_t n = sizeof( h ); BOOST_TEST_EQ( std::search( p, p + n, s, s + 4 ) - p, n ); } } int main() { test(); test(); test(); test(); test(); test(); test(); test(); test(); test(); test(); test(); test(); test(); test(); test(); test(); test(); test(); test(); test(); test(); test(); test( true ); test( true ); test(); test(); test(); test(); test(); test(); test(); test(); test(); test(); test(); test(); test(); test(); return boost::report_errors(); }