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#ifndef STORAGE_LEVELDB_UTIL_CRC32C_H_6#define STORAGE_LEVELDB_UTIL_CRC32C_H_8#include <stddef.h>9#include <stdint.h>11namespace leveldb {12namespace crc32c {14// Return the crc32c of concat(A, data[0,n-1]) where init_crc is the15// crc32c of some string A. Extend() is often used to maintain the16// crc32c of a stream of data.17uint32_t Extend(uint32_t init_crc, const char* data, size_t n);19// Return the crc32c of data[0,n-1]20inline uint32_t Value(const char* data, size_t n) { return Extend(0, data, n); }22static const uint32_t kMaskDelta = 0xa282ead8ul;24// Return a masked representation of crc.25//26// Motivation: it is problematic to compute the CRC of a string that27// contains embedded CRCs. Therefore we recommend that CRCs stored28// somewhere (e.g., in files) should be masked before being stored.29inline uint32_t Mask(uint32_t crc) {30// Rotate right by 15 bits and add a constant.31return ((crc >> 15) | (crc << 17)) + kMaskDelta;32}34// Return the crc whose masked representation is masked_crc.35inline uint32_t Unmask(uint32_t masked_crc) {36uint32_t rot = masked_crc - kMaskDelta;37return ((rot >> 17) | (rot << 15));38}40} // namespace crc32c41} // namespace leveldb43#endif // STORAGE_LEVELDB_UTIL_CRC32C_H_
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.