MCPcopy Create free account
hub / github.com/argotorg/solidity / chunkHash

Function chunkHash

libsolutil/SwarmHash.cpp:77–101  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

75}
76
77h256 chunkHash(bytesConstRef const _data, bool _forceHigherLevel = false)
78{
79 bytes dataToHash;
80 if (_data.size() < 0x1000)
81 dataToHash = _data.toBytes();
82 else if (_data.size() == 0x1000 && !_forceHigherLevel)
83 dataToHash = _data.toBytes();
84 else
85 {
86 size_t maxRepresentedSize = 0x1000;
87 while (maxRepresentedSize * (0x1000 / 32) < _data.size())
88 maxRepresentedSize *= (0x1000 / 32);
89 // If remaining size is 0x1000, but maxRepresentedSize is not,
90 // we have to still do one level of the chunk hashes.
91 bool forceHigher = maxRepresentedSize > 0x1000;
92 for (size_t i = 0; i < _data.size(); i += maxRepresentedSize)
93 {
94 size_t size = std::min(maxRepresentedSize, _data.size() - i);
95 dataToHash += chunkHash(_data.cropped(i, size), forceHigher).asBytes();
96 }
97 }
98
99 dataToHash.resize(0x1000, 0);
100 return keccak256(toLittleEndian(_data.size()) + bmtHash(&dataToHash).asBytes());
101}
102
103
104}

Callers 1

bzzr1HashMethod · 0.85

Calls 7

toLittleEndianFunction · 0.85
bmtHashFunction · 0.85
toBytesMethod · 0.80
asBytesMethod · 0.80
croppedMethod · 0.80
keccak256Function · 0.70
sizeMethod · 0.45

Tested by

no test coverage detected