Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
501if (this->IsOverflow()) this->FullReduce();503Num3072 inv{};504if (a.IsOverflow()) {505Num3072 b = a;506b.FullReduce();507inv = b.GetInverse();508} else {509inv = a.GetInverse();510}512this->Multiply(inv);513if (this->IsOverflow()) this->FullReduce();514}516Num3072::Num3072(const unsigned char (&data)[BYTE_SIZE]) {517for (int i = 0; i < LIMBS; ++i) {518if (sizeof(limb_t) == 4) {519this->limbs[i] = ReadLE32(data + 4 * i);520} else if (sizeof(limb_t) == 8) {521this->limbs[i] = ReadLE64(data + 8 * i);522}523}524}526void Num3072::ToBytes(unsigned char (&out)[BYTE_SIZE]) {527for (int i = 0; i < LIMBS; ++i) {528if (sizeof(limb_t) == 4) {529WriteLE32(out + i * 4, this->limbs[i]);530} else if (sizeof(limb_t) == 8) {531WriteLE64(out + i * 8, this->limbs[i]);532}533}534}536Num3072 MuHash3072::ToNum3072(std::span<const unsigned char> in) {537unsigned char tmp[Num3072::BYTE_SIZE];539uint256 hashed_in{(HashWriter{} << in).GetSHA256()};540static_assert(sizeof(tmp) % ChaCha20Aligned::BLOCKLEN == 0);541ChaCha20Aligned{MakeByteSpan(hashed_in)}.Keystream(MakeWritableByteSpan(tmp));542Num3072 out{tmp};544return out;545}547MuHash3072::MuHash3072(std::span<const unsigned char> in) noexcept548{549m_numerator = ToNum3072(in);550}552void MuHash3072::Finalize(uint256& out) noexcept553{554m_numerator.Divide(m_denominator);555m_denominator.SetToOne(); // Needed to keep the MuHash object valid557unsigned char data[Num3072::BYTE_SIZE];558m_numerator.ToBytes(data);560out = (HashWriter{} << data).GetSHA256();561}563MuHash3072& MuHash3072::operator*=(const MuHash3072& mul) noexcept564{565m_numerator.Multiply(mul.m_numerator);566m_denominator.Multiply(mul.m_denominator);567return *this;568}570MuHash3072& MuHash3072::operator/=(const MuHash3072& div) noexcept571{572m_numerator.Multiply(div.m_denominator);573m_denominator.Multiply(div.m_numerator);574return *this;575}577MuHash3072& MuHash3072::Insert(std::span<const unsigned char> in) noexcept {578m_numerator.Multiply(ToNum3072(in));579return *this;580}582MuHash3072& MuHash3072::Remove(std::span<const unsigned char> in) noexcept {583m_denominator.Multiply(ToNum3072(in));584return *this;585}
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.