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

Function Syndrome

src/bech32.cpp:258–275  ·  view source on GitHub ↗

* Syndrome returns the three values s_997, s_998, and s_999 described above, * packed into a 30-bit integer, where each group of 10 bits encodes one value. */

Source from the content-addressed store, hash-verified

256 * packed into a 30-bit integer, where each group of 10 bits encodes one value.
257 */
258uint32_t Syndrome(const uint32_t residue) {
259 // low is the first 5 bits, corresponding to the r6 in the residue
260 // (the constant term of the polynomial).
261 uint32_t low = residue & 0x1f;
262
263 // We begin by setting s_j = low = r6 for all three values of j, because these are unconditional.
264 uint32_t result = low ^ (low << 10) ^ (low << 20);
265
266 // Then for each following bit, we add the corresponding precomputed constant if the bit is 1.
267 // For example, 0x31edd3c4 is 1100011110 1101110100 1111000100 when unpacked in groups of 10
268 // bits, corresponding exactly to a^999 || a^998 || a^997 (matching the corresponding values in
269 // GF1024_EXP above). In this way, we compute all three values of s_j for j in (997, 998, 999)
270 // simultaneously. Recall that XOR corresponds to addition in a characteristic 2 field.
271 for (int i = 0; i < 25; ++i) {
272 result ^= ((residue >> (5+i)) & 1 ? SYNDROME_CONSTS.at(i) : 0);
273 }
274 return result;
275}
276
277/** Convert to lower case. */
278inline unsigned char LowerCase(unsigned char c)

Callers 1

LocateErrorsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected