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.
1// Copyright (c) 2011 The LevelDB Authors. All rights reserved.2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file. See the AUTHORS file for names of contributors.5#include "util/crc32c.h"6#include "util/testharness.h"8namespace leveldb {9namespace crc32c {11class CRC {};13TEST(CRC, StandardResults) {14// From rfc3720 section B.4.15char buf[32];17memset(buf, 0, sizeof(buf));18ASSERT_EQ(0x8a9136aa, Value(buf, sizeof(buf)));20memset(buf, 0xff, sizeof(buf));21ASSERT_EQ(0x62a8ab43, Value(buf, sizeof(buf)));23for (int i = 0; i < 32; i++) {24buf[i] = i;25}26ASSERT_EQ(0x46dd794e, Value(buf, sizeof(buf)));28for (int i = 0; i < 32; i++) {29buf[i] = 31 - i;30}31ASSERT_EQ(0x113fdb5c, Value(buf, sizeof(buf)));33uint8_t data[48] = {340x01, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,350x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00,360x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x18, 0x28, 0x00, 0x00, 0x00,370x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,38};39ASSERT_EQ(0xd9963a56, Value(reinterpret_cast<char*>(data), sizeof(data)));40}42TEST(CRC, Values) { ASSERT_NE(Value("a", 1), Value("foo", 3)); }44TEST(CRC, Extend) {45ASSERT_EQ(Value("hello world", 11), Extend(Value("hello ", 6), "world", 5));46}48TEST(CRC, Mask) {49uint32_t crc = Value("foo", 3);50ASSERT_NE(crc, Mask(crc));51ASSERT_NE(crc, Mask(Mask(crc)));52ASSERT_EQ(crc, Unmask(Mask(crc)));53ASSERT_EQ(crc, Unmask(Unmask(Mask(Mask(crc)))));54}56} // namespace crc32c57} // namespace leveldb59int main(int argc, char** argv) { return leveldb::test::RunAllTests(); }
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.