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

Method Load

src/crypto/sha256.cpp:780–804  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

778}
779
780bool CSHA256::Load(const std::vector<unsigned char>& vch) {
781 if (vch.size() < 40) return false;
782
783 uint64_t bits = ReadLE64(&vch[32]);
784 size_t buf_size = (bits >> 3) % 64;
785
786 if ((bits & 0x07) != 0 || vch.size() != 40 + buf_size) return false;
787
788 // We want to leave the internal state of the object unchanged if false is returned.
789 // So no member variables can be modified until now.
790
791 s[0] = ReadBE32(&vch[ 0]);
792 s[1] = ReadBE32(&vch[ 4]);
793 s[2] = ReadBE32(&vch[ 8]);
794 s[3] = ReadBE32(&vch[12]);
795 s[4] = ReadBE32(&vch[16]);
796 s[5] = ReadBE32(&vch[20]);
797 s[6] = ReadBE32(&vch[24]);
798 s[7] = ReadBE32(&vch[28]);
799
800 bytes = bits >> 3;
801 if (buf_size) memcpy(buf, &vch[40], buf_size);
802
803 return true;
804}
805
806bool CSHA256::SafeWrite(const unsigned char* data, size_t len) {
807 const uint64_t SHA256_MAX = 0x1FFFFFFFFFFFFFFF; // SHA256's maximum allowed message length in bytes.

Callers 3

walletdb.cppFile · 0.45
BOOST_AUTO_TEST_CASEFunction · 0.45
FUZZ_TARGET_INITFunction · 0.45

Calls 3

ReadLE64Function · 0.85
ReadBE32Function · 0.70
sizeMethod · 0.45

Tested by 2

BOOST_AUTO_TEST_CASEFunction · 0.36
FUZZ_TARGET_INITFunction · 0.36