How tsukumijima/libaribb25 works
1. Repository purpose
- This repo is a unified codebase for ARIB STD-B1 and ARIB STD-B25 TS decryption libraries and tools.
- It merges multiple historical forks into one buildable project for both Windows and Linux.
2. Top-level architecture
- The code splits into:
- a transport-stream parser/orchestrator
- a smart-card/CAS access layer
- a MULTI2 cipher layer
- thin public API / compatibility wrappers
- CLI tools and stream-based test tools
- The same core logic is reused for both B1 and B25, with preprocessor switches selecting the target variant.
3. Core orchestration layer
- arib_std_b25.c/.h is the main controller.
- It owns the end-to-end workflow: packet sizing, PAT/PMT/ECM/CAT/EMM discovery, cipher setup, and packet pass-through or decryption.
- Architecturally, this is the central hub that connects all other modules.
4. Transport stream parsing boundary
- ts_section_parser.c/.h handles MPEG-2 TS section reconstruction.
- It converts fragmented TS packets into usable PSI/SI sections such as PAT, PMT, ECM, CAT, and EMM.
- This is the parsing boundary between raw TS input and higher-level CAS logic.
5. CAS / smart-card integration
- b_cas_card.c/.h implements the card-facing part of the system.
- On Windows it relies on Win32 smart-card APIs; on Linux the build is geared toward PC/SC through libpcsclite.
- This module is responsible for card initialization and for sending ECM/EMM-related requests to the card to obtain scrambling keys.
6. Cipher/decryption layer
- multi2.c, multi2.cc, and related headers implement the MULTI2 cipher used for broadcast TS scrambling.
- The repo contains two main implementation lineages:
- a C-based path closer to the HaijinW fork
- a C++ rewrite from the stz2012 lineage
- The orchestrator feeds system keys, CBC state, and scrambling keys into this layer, and receives decrypted payloads back.
7. Platform-specific SIMD split
- SIMD support is not uniform across platforms.
- Windows builds use the HaijinW-derived SIMD path with selectable instruction sets such as SSE2/SSSE3/AVX2.
- Linux builds use the stz2012-derived SIMD path, selected automatically when available.
- This is an important architectural fork because decryption performance and available code paths differ by platform.
8. Public library interfaces
- libaribb25.* and libaribb1.* expose the reusable library surfaces.
- libaribb25 is the B-CAS/B25-facing API; libaribb1 is the analogous B1-facing API for SkyPerfecTV Premium Service.
- The README also notes DLL compatibility naming for existing software ecosystems, especially on Windows.
9. Compatibility and legacy boundary
- B25Decoder.cpp/.h exists in the tree but is not part of the build; the functional compatibility layer lives in libaribb25.cpp/.h.
- On Windows, the project can also emulate legacy B25Decoder.dll / B1Decoder.dll interfaces for external applications such as EDCB.
- This is a boundary layer for drop-in compatibility rather than core decoding logic.
10. Executable tools and data flow
- b25 / b1 are file-based command-line programs that read scrambled TS and write decrypted TS.
- arib-b25-stream-test / arib-b1-stream-test are stream-based variants that use stdin/stdout instead of files.
- The data flow is: input TS → parse PSI/sections → obtain keys from card → initialize MULTI2 → decrypt scrambled packets → emit TS.
11. CAS workflow modeled in the code
- The core workflow is driven by TS metadata:
- detect packet size
- find PAT
- resolve PMTs
- identify ECMs and associated streams
- optionally process CAT/EMM
- Decryption is only enabled once the relevant ECM and card-derived keys are available.
- This makes the architecture event-driven around broadcast table updates, not a simple linear file transform.
12. Windows-only configuration path
- The README describes .ini-based card-reader selection for Windows builds.
- This is a deployment-time override layer, useful when multiple readers or virtual readers are present.
- It affects how the smart-card boundary is resolved, but not the TS parsing or cipher layers.
13. Build and packaging architecture
- The repo supports two build systems:
- Visual Studio solution/project files for Windows
- CMake for Linux
- CMake helper modules handle installation, uninstall, revision stamping, and PC/SC discovery.
- pkg-config templates indicate the libraries are intended to be installed and consumed by other software, not only run as standalone binaries.
14. External dependencies and runtime assumptions
- The key runtime dependency is a smart-card environment: B-CAS/ACAS/SPHD cards and compatible readers.
- Linux builds depend on PC/SC development packages.
- The project is fundamentally a broadcast TS decryption library/tooling stack, not a generic multimedia application.
Main entry points: arib_std_b25.c Orchestrator · libaribb25.h B25 API · arib_std_b25.sln VS solution · multi2_simd.c SIMD layer
Components 17
Core decryption
End-to-end TS control, parsing, card access, and cipher execution.
- Orchestrator · Coordinates packet sizing, PSI/section discovery, card workflow, and MULTI2 setup for B1/B25 variants.
aribb25/arib_std_b25.c - TS parser · Reassembles fragmented MPEG-2 TS packets into PAT, PMT, ECM, CAT, and EMM sections.
aribb25/ts_section_parser.c - Card access · Handles reader selection, card initialization, and ECM/EMM requests to obtain scrambling keys.
aribb25/b_cas_card.c - MULTI2 C · C-based MULTI2 implementation lineage used for broadcast TS decryption.
aribb25/multi2.c - MULTI2 C++ · C++ MULTI2 implementation lineage and rewrite path used by the shared cipher layer.
aribb25/multi2.cc - SIMD layer · Instruction-set dispatch and optimized cipher paths, differing between Windows and Linux builds.
aribb25/multi2_simd.c
Public APIs
Reusable library surfaces and compatibility boundaries.
- B25 API · Primary reusable API surface for B-CAS/B25 decryption consumers.
aribb25/libaribb25.h - B1 API · Analogous API surface for B1/SkyPerfecTV Premium Service consumers.
aribb25/libaribb1.vcxproj - Legacy API · Legacy B25Decoder compatibility boundary present in-tree but not part of the main build.
aribb25/B25Decoder.h
CLI tools
File-based and stream-based executables built on the core library.
- b25 tool · File-based command-line decryptor that reads scrambled TS and writes decrypted TS.
aribb25/b25.vcxproj - b1 tool · File-based command-line decryptor for the B1 variant.
aribb25/b1.vcxproj - B25 stream test · stdin/stdout variant of the B25 workflow for pipeline use.
aribb25/arib-b25-stream-test.vcxproj - B1 stream test · stdin/stdout variant of the B1 workflow for pipeline use.
aribb25/arib-b1-stream-test.vcxproj
Build system
Cross-platform build, packaging, and installation support.
- CMake build · Cross-platform build and install system for Linux and packaging workflows.
CMakeLists.txt - VS solution · Visual Studio solution and project graph for Windows builds.
arib_std_b25.sln - PC/SC find · CMake helper for discovering PC/SC development dependencies on Linux.
cmake/FindPCSC.cmake - Revision stamp · Build metadata helper for revision stamping and packaging support.
cmake/GitRevision.cmake
Connections 21
- Orchestrator → TS parser: parses · Reconstructs TS sections before higher-level CAS decisions.
- Orchestrator → Card access: requests keys · Uses card access to obtain scrambling keys from ECM/EMM workflow.
- Orchestrator → MULTI2 C: decrypts via · Feeds system and scrambling keys into the cipher layer.
- Orchestrator → MULTI2 C++: decrypts via · Alternative MULTI2 implementation lineage used by the shared core.
- Orchestrator → SIMD layer: selects · Dispatches to optimized SIMD implementations when available.
- TS parser → Orchestrator: feeds tables · Supplies PAT/PMT/ECM/CAT/EMM discovery results to the orchestrator.
- Card access → Orchestrator: returns keys · Provides card-derived keys used to enable decryption.
- SIMD layer → MULTI2 C: accelerates · Optimized execution path for the C cipher implementation.
- SIMD layer → MULTI2 C++: accelerates · Optimized execution path for the C++ cipher implementation.
- B25 API → Orchestrator: wraps · Public B25 API delegates core work to the orchestrator.
- B1 API → Orchestrator: wraps · Public B1 API reuses the same controller with variant selection.
- Legacy API → B25 API: compatibility · Legacy interface boundary replaced in practice by libaribb25.
- b25 tool → B25 API: uses · File-based tool is built on the reusable B25 API.
- b1 tool → B1 API: uses · File-based tool is built on the reusable B1 API.
- B25 stream test → B25 API: uses · Stream-based B25 tool uses the same library surface.
- B1 stream test → B1 API: uses · Stream-based B1 tool uses the same library surface.
- CMake build → PC/SC find: includes · Build configuration locates PC/SC on Linux.
- CMake build → Revision stamp: includes · Build configuration stamps revision and packaging metadata.
- VS solution → B25 API: builds · Windows solution builds the main B25 library and related targets.
- VS solution → b25 tool: builds · Windows solution builds the command-line tools.
- VS solution → B25 stream test: builds · Windows solution builds stream-based test executables.