LiteBCH is a dependency-free C++ header library for BCH Error Correction. It combines the mathematical rigor of aff3ct with the extreme performance optimization of the Linux Kernel (~850 Mbps), all in a single 570-line file that compiles instantly.
High-performance, byte-oriented API. No dependencies.
#include <litebch/LiteBCH.h>
// 1. Initialize (N=1023 bits, Correct up to 50 errors)
lite::LiteBCH bch(1023, 50);
// 2. Prepare Data (K message bits, N-K parity bits)
std::vector<uint8_t> data(bch.get_K() / 8);
std::vector<uint8_t> ecc(bch.ecc_bytes);
// 3. Fast Encode
bch.encode(data.data(), data.size(), ecc.data());
// 4. Decode / Correct
bch.decode(corrupted_data, len, corrupted_ecc);Run native C++ speeds in the browser.
const Module = require('./litebch.js');
Module().then(lib => {
// 1. Initialize
const bch = new lib.LiteBCH(1023, 50);
// 2. Encode (Direct Memory Access for Speed)
bch.encode_raw_ptr(dataPtr, len, eccPtr);
});- Fast by Default: Uses 8-bit Parallel Look-Up Tables (LUT). faster than standard bit-serial implementations and safer than 32-bit kernel ports (no alignment crashes).
- Micro Footprint: ~570 lines of code. Compiles in milliseconds. Zero external dependencies.
- Production Verified: Validated bit-for-bit against the industry-standard
aff3ctlibrary across billions of test vectors. - Universal: Runs on x86, ARM, RISC-V, and WASM. Endian-neutral and alignment-safe.
LiteBCH provides a compatibility header that mimics the aff3ct API. This allows you to switch libraries by changing just one line of code.
1. Change the Include:
-#include <aff3ct.hpp>
+#include <litebch/aff3ct_compat.h>2. Recompile. That's it. Your existing code works without modification:
using namespace aff3ct;
// Your existing factory and modules continue to work:
tools::BCH_polynomial_generator<int> poly(N, t);
module::Encoder_BCH<int> enc(K, N, poly);
module::Decoder_BCH_std<int> dec(K, N, poly);
// Use exactly the same signatures:
enc.encode(message_bits, codeword);
dec.decode_hiho(corrupted, decoded);Note: This wrapper routes your calls to the high-performance
LiteBCHbackend. You get the standard API ergonomics with the ~19x speedup of our optimized kernel.
LiteBCH includes a unified verification suite that benchmarks against both the Native C++ implementation and the aff3ct reference, ensuring 100% correctness.
| Config | Code | Method | Encode (Mbps) | Decode (Mbps) | Checksum | Status |
|---|---|---|---|---|---|---|
| Small | (31, 21, t=2) | LiteBCH | 269.4 | 59.2 | 64b1f50a |
PASS |
| aff3ct | 18.7 | 61.6 | 64b1f50a |
Reference | ||
| Medium | (1023, 523, t=50) | LiteBCH | 198.9 | 23.4 | 55dcc166 |
PASS |
| aff3ct | 22.8 | 11.2 | 55dcc166 |
Reference | ||
| Large | (8191, 7411, t=60) | LiteBCH | 334.6 | 26.0 | 5f255101 |
PASS |
| aff3ct | 5.8 | 6.0 | 5f255101 |
Reference | ||
| X-Large | (16383, 14703, t=120) | LiteBCH | 168.6 | 12.3 | 74920925 |
PASS |
| aff3ct | 2.7 | 1.6 | 74920925 |
Reference |
Note: Both implementations produced identical checksums for every test configuration.
# 1. Build Verification Suite
cmake -S . -B build && cmake --build build
# 2. Run Comprehensive Test
./build/tests/comprehensive_test --verify-wasm tests/wasm_comprehensive_test.js --verify-aff3ctBy default, the build uses maximum compiler optimizations (-O3, -funroll-loops).
SIMD Support (Optional): You can enable SIMD instructions (AVX/SSE on Native, 128-bit SIMD on WASM) for significant performance gains (see benchmarks above).
Native Build with SIMD:
cmake .. -DLITEBCH_ENABLE_SIMD=ON
makeWASM Build with SIMD:
emcmake cmake .. -DLITEBCH_BUILD_WASM=ON -DLITEBCH_ENABLE_SIMD=ON
emmake makeTo disable default high-performance optimizations (e.g. for debugging):
cmake .. -DLITEBCH_MAX_PERFORMANCE=OFFSimply copy the header and source into your project.
include/litebch/LiteBCH.hsrc/LiteBCH.cpp
add_subdirectory(litebch)
target_link_libraries(your_app PRIVATE litebch::litebch)Compatible with legacy hardware or standards like DVB-S2.
// Example: x^10 + x^3 + 1
std::vector<int> poly = {1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1};
lite::LiteBCH bch(1023, 50, poly);Useful for bit-level simulation pipelines.
std::vector<int> bits_in = ...; // 0s and 1s
std::vector<int> bits_out = bch.encode(bits_in);MIT License. Free for commercial and private use.
Copyright (c) 2025 Will Ackerly