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

Function CreateChecksum

src/blech32.cpp:156–167  ·  view source on GitHub ↗

Create a checksum. */

Source from the content-addressed store, hash-verified

154
155/** Create a checksum. */
156data CreateChecksum(Encoding encoding, const std::string& hrp, const data& values)
157{
158 data enc = Cat(ExpandHRP(hrp), values);
159 enc.resize(enc.size() + 12); // ELEMENTS: Append 6->12 zeroes
160 uint64_t mod = PolyMod(enc) ^ EncodingConstant(encoding); // Determine what to XOR into those 6 zeroes.
161 data ret(12); // ELEMENTS: 6->12
162 for (size_t i = 0; i < 12; ++i) { // ELEMENTS: 6->12
163 // Convert the 5-bit groups in mod to checksum values.
164 ret[i] = (mod >> (5 * (11 - i))) & 31; // ELEMENTS: 5->11
165 }
166 return ret;
167}
168
169/** Encode a Blech32 or Blech32m string. */
170std::string Encode(Encoding encoding, const std::string& hrp, const data& values) {

Callers 1

EncodeFunction · 0.70

Calls 6

CatFunction · 0.70
ExpandHRPFunction · 0.70
PolyModFunction · 0.70
EncodingConstantFunction · 0.70
resizeMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected