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# CRC32C3[](https://github.com/google/crc32c/actions/workflows/build.yml)5New file format authors should consider6[HighwayHash](https://github.com/google/highwayhash). The initial version of7this code was extracted from [LevelDB](https://github.com/google/leveldb), which8is a stable key-value store that is widely used at Google.10This project collects a few CRC32C implementations under an umbrella that11dispatches to a suitable implementation based on the host computer's hardware12capabilities.14CRC32C is specified as the CRC that uses the iSCSI polynomial in15[RFC 3720](https://tools.ietf.org/html/rfc3720#section-12.1). The polynomial was16introduced by G. Castagnoli, S. Braeuer and M. Herrmann. CRC32C is used in17software such as Btrfs, ext4, Ceph and leveldb.20## Usage22```cpp23#include "crc32c/crc32c.h"25int main() {26const std::uint8_t buffer[] = {0, 0, 0, 0};27std::uint32_t result;29// Process a raw buffer.30result = crc32c::Crc32c(buffer, 4);32// Process a std::string.33std::string string;34string.resize(4);35result = crc32c::Crc32c(string);37// If you have C++17 support, process a std::string_view.38std::string_view string_view(string);39result = crc32c::Crc32c(string_view);41return 0;42}43```46## Prerequisites48This project uses [CMake](https://cmake.org/) for building and testing. CMake is49available in all popular Linux distributions, as well as in50[Homebrew](https://brew.sh/).52This project uses submodules for dependency management.54```bash55git submodule update --init --recursive56```58If you're using [Atom](https://atom.io/), the following packages can help.60```bash61apm install autocomplete-clang build build-cmake clang-format language-cmake \62linter linter-clang63```65If you don't mind more setup in return for more speed, replace66`autocomplete-clang` and `linter-clang` with `you-complete-me`. This requires67[setting up ycmd](https://github.com/ycm-core/ycmd#building).69```bash70apm install autocomplete-plus build build-cmake clang-format language-cmake \71linter you-complete-me72```74## Building76The following commands build and install the project.78```bash79mkdir build80cd build81cmake -DCRC32C_BUILD_TESTS=0 -DCRC32C_BUILD_BENCHMARKS=0 .. && make all install82```85## Development87The following command (when executed from `build/`) (re)builds the project and88runs the tests.90```bash91cmake .. && cmake --build . && ctest --output-on-failure92```95### Android testing97The following command builds the project against the Android NDK, which is98useful for benchmarking against ARM processors.100```bash101cmake .. -DCMAKE_SYSTEM_NAME=Android -DCMAKE_ANDROID_ARCH_ABI=arm64-v8a \102-DCMAKE_ANDROID_NDK=$HOME/Library/Android/sdk/ndk-bundle \103-DCMAKE_ANDROID_NDK_TOOLCHAIN_VERSION=clang \104-DCMAKE_ANDROID_STL_TYPE=c++_static -DCRC32C_USE_GLOG=0 \105-DCMAKE_BUILD_TYPE=Release && cmake --build .106```108The following commands install and run the benchmarks.110```bash111adb push crc32c_bench /data/local/tmp112adb shell chmod +x /data/local/tmp/crc32c_bench113adb shell 'cd /data/local/tmp && ./crc32c_bench'114adb shell rm /data/local/tmp/crc32c_bench115```117The following commands install and run the tests.119```bash120adb push crc32c_tests /data/local/tmp121adb shell chmod +x /data/local/tmp/crc32c_tests122adb shell 'cd /data/local/tmp && ./crc32c_tests'123adb shell rm /data/local/tmp/crc32c_tests124```
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.