MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / VerifyChecksum

Function VerifyChecksum

src/bech32.cpp:327–339  ·  view source on GitHub ↗

Verify a checksum. */

Source from the content-addressed store, hash-verified

325
326/** Verify a checksum. */
327Encoding VerifyChecksum(const std::string& hrp, const data& values)
328{
329 // PolyMod computes what value to xor into the final values to make the checksum 0. However,
330 // if we required that the checksum was 0, it would be the case that appending a 0 to a valid
331 // list of values would result in a new valid list. For that reason, Bech32 requires the
332 // resulting checksum to be 1 instead. In Bech32m, this constant was amended. See
333 // https://gist.github.com/sipa/14c248c288c3880a3b191f978a34508e for details.
334 auto enc = PreparePolynomialCoefficients(hrp, values);
335 const uint32_t check = PolyMod(enc);
336 if (check == EncodingConstant(Encoding::BECH32)) return Encoding::BECH32;
337 if (check == EncodingConstant(Encoding::BECH32M)) return Encoding::BECH32M;
338 return Encoding::INVALID;
339}
340
341/** Create a checksum. */
342data CreateChecksum(Encoding encoding, const std::string& hrp, const data& values)

Callers 1

DecodeFunction · 0.85

Calls 3

EncodingConstantFunction · 0.85
PolyModFunction · 0.70

Tested by

no test coverage detected