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

Function VerifyChecksum

src/blech32.cpp:143–153  ·  view source on GitHub ↗

Verify a checksum. */

Source from the content-addressed store, hash-verified

141
142/** Verify a checksum. */
143Encoding VerifyChecksum(const std::string& hrp, const data& values)
144{
145 // PolyMod computes what value to xor into the final values to make the checksum 0. However,
146 // if we required that the checksum was 0, it would be the case that appending a 0 to a valid
147 // list of values would result in a new valid list. For that reason, Blech32 requires the
148 // resulting checksum to be 1 instead. In Blech32m, this constant was amended.
149 const uint64_t check = PolyMod(Cat(ExpandHRP(hrp), values));
150 if (check == EncodingConstant(Encoding::BLECH32)) return Encoding::BLECH32;
151 if (check == EncodingConstant(Encoding::BLECH32M)) return Encoding::BLECH32M;
152 return Encoding::INVALID;
153}
154
155/** Create a checksum. */
156data CreateChecksum(Encoding encoding, const std::string& hrp, const data& values)

Callers 1

DecodeFunction · 0.70

Calls 4

PolyModFunction · 0.70
CatFunction · 0.70
ExpandHRPFunction · 0.70
EncodingConstantFunction · 0.70

Tested by

no test coverage detected