Changeset View
Changeset View
Standalone View
Standalone View
src/cashaddr.cpp
// Copyright (c) 2017 Pieter Wuille | // Copyright (c) 2017 Pieter Wuille | ||||
// Copyright (c) 2017-2019 The Bitcoin developers | // Copyright (c) 2017-2019 The Bitcoin developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include <cashaddr.h> | #include <cashaddr.h> | ||||
#include <util/vector.h> | |||||
namespace { | namespace { | ||||
typedef std::vector<uint8_t> data; | typedef std::vector<uint8_t> data; | ||||
/** | /** | ||||
* The cashaddr character set for encoding. | * The cashaddr character set for encoding. | ||||
*/ | */ | ||||
const char *CHARSET = "qpzry9x8gf2tvdw0s3jn54khce6mua7l"; | const char *CHARSET = "qpzry9x8gf2tvdw0s3jn54khce6mua7l"; | ||||
/** | /** | ||||
* The cashaddr character set for decoding. | * The cashaddr character set for decoding. | ||||
*/ | */ | ||||
const int8_t CHARSET_REV[128] = { | const int8_t CHARSET_REV[128] = { | ||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 15, -1, 10, 17, 21, 20, 26, 30, 7, | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 15, -1, 10, 17, 21, 20, 26, 30, 7, | ||||
5, -1, -1, -1, -1, -1, -1, -1, 29, -1, 24, 13, 25, 9, 8, 23, -1, 18, 22, | 5, -1, -1, -1, -1, -1, -1, -1, 29, -1, 24, 13, 25, 9, 8, 23, -1, 18, 22, | ||||
31, 27, 19, -1, 1, 0, 3, 16, 11, 28, 12, 14, 6, 4, 2, -1, -1, -1, -1, | 31, 27, 19, -1, 1, 0, 3, 16, 11, 28, 12, 14, 6, 4, 2, -1, -1, -1, -1, | ||||
-1, -1, 29, -1, 24, 13, 25, 9, 8, 23, -1, 18, 22, 31, 27, 19, -1, 1, 0, | -1, -1, 29, -1, 24, 13, 25, 9, 8, 23, -1, 18, 22, 31, 27, 19, -1, 1, 0, | ||||
3, 16, 11, 28, 12, 14, 6, 4, 2, -1, -1, -1, -1, -1}; | 3, 16, 11, 28, 12, 14, 6, 4, 2, -1, -1, -1, -1, -1}; | ||||
/** | /** | ||||
* Concatenate two byte arrays. | |||||
*/ | |||||
data Cat(data x, const data &y) { | |||||
x.insert(x.end(), y.begin(), y.end()); | |||||
return x; | |||||
} | |||||
/** | |||||
* This function will compute what 8 5-bit values to XOR into the last 8 input | * This function will compute what 8 5-bit values to XOR into the last 8 input | ||||
* values, in order to make the checksum 0. These 8 values are packed together | * values, in order to make the checksum 0. These 8 values are packed together | ||||
* in a single 40-bit integer. The higher bits correspond to earlier values. | * in a single 40-bit integer. The higher bits correspond to earlier values. | ||||
*/ | */ | ||||
uint64_t PolyMod(const data &v) { | uint64_t PolyMod(const data &v) { | ||||
/** | /** | ||||
* The input is interpreted as a list of coefficients of a polynomial over F | * The input is interpreted as a list of coefficients of a polynomial over F | ||||
* = GF(32), with an implicit 1 in front. If the input is [v0,v1,v2,v3,v4], | * = GF(32), with an implicit 1 in front. If the input is [v0,v1,v2,v3,v4], | ||||
▲ Show 20 Lines • Show All 254 Lines • Show Last 20 Lines |