MCPcopy Create free account
hub / github.com/ElementsProject/elements / TestSHA3_256

Function TestSHA3_256

src/test/crypto_tests.cpp:756–776  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

754}
755
756static void TestSHA3_256(const std::string& input, const std::string& output)
757{
758 const auto in_bytes = ParseHex(input);
759 const auto out_bytes = ParseHex(output);
760
761 SHA3_256 sha;
762 // Hash the whole thing.
763 unsigned char out[SHA3_256::OUTPUT_SIZE];
764 sha.Write(in_bytes).Finalize(out);
765 assert(out_bytes.size() == sizeof(out));
766 BOOST_CHECK(std::equal(std::begin(out_bytes), std::end(out_bytes), out));
767
768 // Reset and split randomly in 3
769 sha.Reset();
770 int s1 = InsecureRandRange(in_bytes.size() + 1);
771 int s2 = InsecureRandRange(in_bytes.size() + 1 - s1);
772 int s3 = in_bytes.size() - s1 - s2;
773 sha.Write(Span{in_bytes}.first(s1)).Write(Span{in_bytes}.subspan(s1, s2));
774 sha.Write(Span{in_bytes}.last(s3)).Finalize(out);
775 BOOST_CHECK(std::equal(std::begin(out_bytes), std::end(out_bytes), out));
776}
777
778BOOST_AUTO_TEST_CASE(keccak_tests)
779{

Callers 1

BOOST_AUTO_TEST_CASEFunction · 0.85

Calls 8

ParseHexFunction · 0.85
beginFunction · 0.85
endFunction · 0.85
InsecureRandRangeFunction · 0.85
FinalizeMethod · 0.45
WriteMethod · 0.45
sizeMethod · 0.45
ResetMethod · 0.45

Tested by

no test coverage detected