├── cmake ├── PostInstall.cmake ├── GitRevision.cmake ├── ElfInterp.cmake ├── FindPCSC.cmake └── Uninstall.cmake ├── .editorconfig ├── aribb25 ├── simd_instruction_type.h ├── multi2_error_code.h ├── aribb25.pc.in ├── libaribb1.pc.in ├── libaribb25.pc.in ├── b_cas_card_error_code.h ├── ts_section_parser_error_code.h ├── version_b1.c ├── version_b25.c ├── config.h.in ├── multi2_compat.h ├── multi2.h ├── ts_section_parser.h ├── arib_std_b25_error_code.h ├── B25Decoder.h ├── ts_common_types.h ├── version_b1.rc.in ├── version_b25.rc.in ├── arib_std_b25.h ├── b_cas_card.h ├── multi2_block.h ├── libaribb25.h ├── portable.h ├── IB25Decoder.h ├── b1.vcxproj.filters ├── b25.vcxproj.filters ├── arib-b1-stream-test.vcxproj.filters ├── arib-b25-stream-test.vcxproj.filters ├── libaribb1.vcxproj.filters ├── libaribb25.vcxproj.filters ├── multi2_neon.h ├── multi2_ymm.h ├── multi2_simd.h ├── B25Decoder.cpp ├── multi2_cipher.h ├── multi2_neon2.h ├── multi2_xmm.h ├── multi2_ymm2.h ├── multi2.cc ├── libaribb25.cpp ├── libaribb25.vcxproj ├── libaribb1.vcxproj ├── b25.vcxproj ├── b1.vcxproj ├── arib-b25-stream-test.vcxproj └── arib-b1-stream-test.vcxproj ├── NOTICE ├── .github └── workflows │ ├── Dockerfile │ ├── build-package.yml │ └── build.yml ├── .gitignore ├── arib_std_b25.sln └── LICENSE /cmake/PostInstall.cmake: -------------------------------------------------------------------------------- 1 | if(LDCONFIG_EXECUTABLE) 2 | message(STATUS "Running: ldconfig") 3 | execute_process(COMMAND ${LDCONFIG_EXECUTABLE} RESULT_VARIABLE ldconfig_result) 4 | if (NOT ldconfig_result EQUAL 0) 5 | message(WARNING "ldconfig failed") 6 | endif() 7 | endif() 8 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | end_of_line = lf 5 | charset = utf-8 6 | indent_style = tab 7 | indent_size = 2 8 | trim_trailing_whitespace = true 9 | 10 | [*.yml] 11 | indent_style = space 12 | indent_size = 2 13 | 14 | [*.md] 15 | trim_trailing_whitespace = false 16 | -------------------------------------------------------------------------------- /aribb25/simd_instruction_type.h: -------------------------------------------------------------------------------- 1 | #ifndef SIMD_INSTRUCTION_TYPE_H 2 | #define SIMD_INSTRUCTION_TYPE_H 3 | 4 | enum INSTRUCTION_TYPE 5 | { 6 | INSTRUCTION_NORMAL, 7 | INSTRUCTION_SSE2, 8 | INSTRUCTION_SSSE3, 9 | INSTRUCTION_AVX2 10 | }; 11 | 12 | #endif /* SIMD_INSTRUCTION_TYPE_H */ 13 | -------------------------------------------------------------------------------- /aribb25/multi2_error_code.h: -------------------------------------------------------------------------------- 1 | #ifndef MULTI2_ERROR_CODE_H 2 | #define MULTI2_ERROR_CODE_H 3 | 4 | #define MULTI2_ERROR_INVALID_PARAMETER -1 5 | #define MULTI2_ERROR_UNSET_SYSTEM_KEY -2 6 | #define MULTI2_ERROR_UNSET_CBC_INIT -3 7 | #define MULTI2_ERROR_UNSET_SCRAMBLE_KEY -4 8 | 9 | #endif /* MULTI2_ERROR_CODE_H */ 10 | -------------------------------------------------------------------------------- /aribb25/aribb25.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@CMAKE_INSTALL_PREFIX@ 2 | exec_prefix=${prefix} 3 | libdir=@CMAKE_INSTALL_FULL_LIBDIR@ 4 | includedir=${prefix}/include 5 | 6 | Name: @ARIBB25_LIB_NAME@ 7 | Description: @ARIBB25_DESCRIPTION@ 8 | URL: @ARIBB25_URL@ 9 | Version: @ARIBB25_VERSION_STRING@ 10 | Libs: -L${libdir} -l@ARIBB25_LIB_NAME@ 11 | Cflags: -I${includedir} 12 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | stz2012 - libaribb25 2 | 3 | Copyright (c)2012 stz2012 4 | 5 | This product include software from MARUMO Manufacturing libaribb25 project. 6 | * Copyright (c)2007-2012 MOGI, Kazuhiro ; All rights reserved. 7 | MARUMO Manufacturing (https://www.marumo.ne.jp/) 8 | Special Thanks: 2ch NoNames, eternalharvest, eru. 9 | -------------------------------------------------------------------------------- /aribb25/libaribb1.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@CMAKE_INSTALL_PREFIX@ 2 | exec_prefix=${prefix} 3 | libdir=@CMAKE_INSTALL_FULL_LIBDIR@ 4 | includedir=${prefix}/include 5 | 6 | Name: @CMAKE_SHARED_LIBRARY_PREFIX@@ARIBB1_LIB_NAME@ 7 | Description: @ARIBB1_DESCRIPTION@ 8 | URL: @ARIBB1_URL@ 9 | Version: @ARIBB1_VERSION_STRING@ 10 | Libs: -L${libdir} -l@ARIBB1_LIB_NAME@ 11 | Cflags: -I${includedir} 12 | -------------------------------------------------------------------------------- /aribb25/libaribb25.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@CMAKE_INSTALL_PREFIX@ 2 | exec_prefix=${prefix} 3 | libdir=@CMAKE_INSTALL_FULL_LIBDIR@ 4 | includedir=${prefix}/include 5 | 6 | Name: @CMAKE_SHARED_LIBRARY_PREFIX@@ARIBB25_LIB_NAME@ 7 | Description: @ARIBB25_DESCRIPTION@ 8 | URL: @ARIBB25_URL@ 9 | Version: @ARIBB25_VERSION_STRING@ 10 | Libs: -L${libdir} -l@ARIBB25_LIB_NAME@ 11 | Cflags: -I${includedir} 12 | -------------------------------------------------------------------------------- /.github/workflows/Dockerfile: -------------------------------------------------------------------------------- 1 | ARG IMAGE 2 | FROM ${IMAGE} 3 | ENV DEBIAN_FRONTEND=noninteractive 4 | RUN apt-get update && apt-get install -y build-essential ca-certificates libpcsclite-dev pkg-config wget 5 | RUN wget https://github.com/Kitware/CMake/releases/download/v3.27.4/cmake-3.27.4-linux-aarch64.sh && \ 6 | sh ./cmake-3.27.4-linux-aarch64.sh --prefix=/usr/local --skip-license && \ 7 | rm ./cmake-3.27.4-linux-aarch64.sh 8 | -------------------------------------------------------------------------------- /aribb25/b_cas_card_error_code.h: -------------------------------------------------------------------------------- 1 | #ifndef B_CAS_CARD_ERROR_CODE_H 2 | #define B_CAS_CARD_ERROR_CODE_H 3 | 4 | #define B_CAS_CARD_ERROR_INVALID_PARAMETER -1 5 | #define B_CAS_CARD_ERROR_NOT_INITIALIZED -2 6 | #define B_CAS_CARD_ERROR_NO_SMART_CARD_READER -3 7 | #define B_CAS_CARD_ERROR_ALL_READERS_CONNECTION_FAILED -4 8 | #define B_CAS_CARD_ERROR_NO_ENOUGH_MEMORY -5 9 | #define B_CAS_CARD_ERROR_TRANSMIT_FAILED -6 10 | 11 | #endif /* B_CAS_CARD_ERROR_CODE_H */ 12 | -------------------------------------------------------------------------------- /aribb25/ts_section_parser_error_code.h: -------------------------------------------------------------------------------- 1 | #ifndef TS_SECTION_PARSER_ERROR_CODE_H 2 | #define TS_SECTION_PARSER_ERROR_CODE_H 3 | 4 | #define TS_SECTION_PARSER_ERROR_INVALID_PARAM -1 5 | #define TS_SECTION_PARSER_ERROR_NO_ENOUGH_MEMORY -2 6 | #define TS_SECTION_PARSER_ERROR_INVALID_TS_PID -3 7 | #define TS_SECTION_PARSER_ERROR_NO_SECTION_DATA -4 8 | 9 | #define TS_SECTION_PARSER_WARN_CRC_MISSMATCH 1 10 | #define TS_SECTION_PARSER_WARN_LENGTH_MISSMATCH 2 11 | 12 | #endif /* TS_SECTION_PARSER_ERROR_CODE_H */ 13 | -------------------------------------------------------------------------------- /aribb25/version_b1.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | // See https://github.com/open62541/open62541/commit/ea258bc825e7b01bc92544ac83d8215fe0c72a07 5 | #if defined(_WIN32) 6 | #include 7 | #else 8 | #include 9 | #endif 10 | #if defined(__GNUC__) || defined(__clang__) 11 | # if !defined(__APPLE__) 12 | const char elf_interp[] __attribute__((section(".interp"))) = ELF_INTERP; 13 | # endif 14 | 15 | void show_version(void) 16 | { 17 | fprintf(stderr, "libaribb1.so - ARIB STD-B1 shared library version %s (%s)\n", ARIBB1_VERSION_STRING, BUILD_GIT_REVISION); 18 | fprintf(stderr, " built with %s %s on %s\n", BUILD_CC_NAME, BUILD_CC_VERSION, BUILD_OS_NAME); 19 | _exit(0); 20 | } 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /aribb25/version_b25.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | // See https://github.com/open62541/open62541/commit/ea258bc825e7b01bc92544ac83d8215fe0c72a07 5 | #if defined(_WIN32) 6 | #include 7 | #else 8 | #include 9 | #endif 10 | #if defined(__GNUC__) || defined(__clang__) 11 | # if !defined(__APPLE__) 12 | const char elf_interp[] __attribute__((section(".interp"))) = ELF_INTERP; 13 | # endif 14 | 15 | void show_version(void) 16 | { 17 | fprintf(stderr, "libaribb25.so - ARIB STD-B25 shared library version %s (%s)\n", ARIBB25_VERSION_STRING, BUILD_GIT_REVISION); 18 | fprintf(stderr, " built with %s %s on %s\n", BUILD_CC_NAME, BUILD_CC_VERSION, BUILD_OS_NAME); 19 | _exit(0); 20 | } 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /cmake/GitRevision.cmake: -------------------------------------------------------------------------------- 1 | find_package(Git) 2 | if(GIT_FOUND AND IS_DIRECTORY ${CMAKE_SOURCE_DIR}/.git) 3 | execute_process( 4 | COMMAND ${GIT_EXECUTABLE} describe --always --tags 5 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} 6 | OUTPUT_VARIABLE GIT_REVISION 7 | OUTPUT_STRIP_TRAILING_WHITESPACE 8 | ) 9 | 10 | execute_process( 11 | COMMAND ${GIT_EXECUTABLE} diff --shortstat --exit-code --quiet 12 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} 13 | RESULT_VARIABLE GIT_IS_DIRTY 14 | ) 15 | 16 | if(GIT_IS_DIRTY) 17 | set(GIT_REVISION "${GIT_REVISION} dirty") 18 | endif() 19 | else() 20 | if (EXISTS ${CMAKE_SOURCE_DIR}/.tarball-version) 21 | file(STRINGS ${CMAKE_SOURCE_DIR}/.tarball-version GIT_REVISION LIMIT_COUNT 1) 22 | else() 23 | set(GIT_REVISION "Unknown Source") 24 | endif() 25 | set(GIT_IS_DIRTY False) 26 | endif() 27 | -------------------------------------------------------------------------------- /cmake/ElfInterp.cmake: -------------------------------------------------------------------------------- 1 | 2 | find_program(OBJCOPY_EXECUTABLE "objcopy") 3 | if(OBJCOPY_EXECUTABLE) 4 | set(ELF_INTERP_BIN ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/elf_interp) 5 | set(ELF_INTERP_SRC ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/elf_interp.c) 6 | set(ELF_INTERP_DAT ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/elf_interp.dat) 7 | 8 | file(WRITE ${ELF_INTERP_SRC} "int main(int argc, char **argv) { return 0; }") 9 | 10 | execute_process(COMMAND ${CMAKE_C_COMPILER} ${CMAKE_C_FLAGS} -o ${ELF_INTERP_BIN} ${ELF_INTERP_SRC}) 11 | execute_process(COMMAND ${OBJCOPY_EXECUTABLE} -O binary --only-section=.interp ${ELF_INTERP_BIN} ${ELF_INTERP_DAT}) 12 | 13 | if(EXISTS ${ELF_INTERP_DAT}) 14 | file(READ ${ELF_INTERP_DAT} ELF_INTERP) 15 | string(STRIP ${ELF_INTERP} ELF_INTERP) 16 | endif() 17 | endif() 18 | 19 | message(STATUS "ELF Interpreter: ${ELF_INTERP}") 20 | -------------------------------------------------------------------------------- /aribb25/config.h.in: -------------------------------------------------------------------------------- 1 | #ifndef CONFIG_H 2 | #define CONFIG_H 3 | 4 | #define ARIBB1_MAJOR_VERSION @ARIBB1_MAJOR_VERSION@ 5 | #define ARIBB1_MINOR_VERSION @ARIBB1_MINOR_VERSION@ 6 | #define ARIBB1_PATCH_VERSION @ARIBB1_PATCH_VERSION@ 7 | #define ARIBB1_VERSION_NUMBER "@ARIBB1_VERSION_NUMBER@" 8 | #define ARIBB1_VERSION_STRING "@ARIBB1_VERSION_STRING@" 9 | 10 | #define ARIBB25_MAJOR_VERSION @ARIBB25_MAJOR_VERSION@ 11 | #define ARIBB25_MINOR_VERSION @ARIBB25_MINOR_VERSION@ 12 | #define ARIBB25_PATCH_VERSION @ARIBB25_PATCH_VERSION@ 13 | #define ARIBB25_VERSION_NUMBER "@ARIBB25_VERSION_NUMBER@" 14 | #define ARIBB25_VERSION_STRING "@ARIBB25_VERSION_STRING@" 15 | 16 | #define BUILD_OS_NAME "@CMAKE_SYSTEM@" 17 | #define BUILD_CC_NAME "@CMAKE_C_COMPILER_ID@" 18 | #define BUILD_CC_VERSION "@CMAKE_C_COMPILER_VERSION@" 19 | #define BUILD_GIT_REVISION "@GIT_REVISION@" 20 | 21 | #define ELF_INTERP "@ELF_INTERP@" 22 | 23 | #endif /* CONFIG_H */ 24 | -------------------------------------------------------------------------------- /cmake/FindPCSC.cmake: -------------------------------------------------------------------------------- 1 | find_package(PkgConfig) 2 | if(PKG_CONFIG_FOUND AND WITH_PCSC_PACKAGE AND NOT CMAKE_CROSSCOMPILING) 3 | if(WITH_PCSC_PACKAGE STREQUAL "libpcsclite") 4 | pkg_check_modules(PCSC ${WITH_PCSC_PACKAGE}) 5 | else() 6 | pkg_check_modules(PCSC REQUIRED ${WITH_PCSC_PACKAGE}) 7 | endif() 8 | endif() 9 | 10 | if(NOT PCSC_FOUND) 11 | find_path(PCSC_INCLUDE_DIRS NAMES WinSCard.h winscard.h PATH_SUFFIXES PCSC) 12 | if(WITH_PCSC_LIBRARY) 13 | find_library(PCSC_LIBRARIES NAMES ${WITH_PCSC_LIBRARY}) 14 | else() 15 | find_library(PCSC_LIBRARIES NAMES pcsclite PCSC WinSCard winscard) 16 | endif() 17 | 18 | if(PCSC_LIBRARIES) 19 | set(PCSC_FOUND True) 20 | endif() 21 | endif() 22 | 23 | if(NOT PCSC_FOUND AND NOT WITH_PCSC_LIBRARY AND WIN32) 24 | set(PCSC_LIBRARIES winscard) 25 | set(PCSC_FOUND True) 26 | endif() 27 | 28 | include(FindPackageHandleStandardArgs) 29 | find_package_handle_standard_args(PCSC DEFAULT_MSG PCSC_LIBRARIES) 30 | 31 | mark_as_advanced(PCSC_INCLUDE_DIRS PCSC_LIBRARIES) 32 | -------------------------------------------------------------------------------- /aribb25/multi2_compat.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace multi2 { 6 | 7 | template 8 | class array { 9 | T v[N]; 10 | 11 | inline const T *begin() const { return &v[0]; } 12 | inline const T *end() const { return &v[N]; } 13 | 14 | public: 15 | inline size_t size() { return N; } 16 | 17 | inline bool operator!=(const array &other) const { 18 | return !std::equal(begin(), end(), other.begin()); 19 | } 20 | inline T &operator[](size_t n) { return v[n]; } 21 | inline const T &operator[](size_t n) const { return v[n]; } 22 | }; 23 | 24 | template 25 | class optional { 26 | T v; 27 | bool has; 28 | 29 | public: 30 | inline optional() : has(false) { } 31 | 32 | inline optional &operator=(const T &other) { 33 | v = other; 34 | has = true; 35 | return *this; 36 | } 37 | inline void reset() { has = false; } 38 | inline operator bool() const { return has; } 39 | inline T &operator*() { return v; } 40 | }; 41 | 42 | } 43 | -------------------------------------------------------------------------------- /aribb25/multi2.h: -------------------------------------------------------------------------------- 1 | #ifndef MULTI2_H 2 | #define MULTI2_H 3 | 4 | #include "portable.h" 5 | #include "simd_instruction_type.h" 6 | 7 | typedef struct { 8 | 9 | void *private_data; 10 | 11 | void (* release)(void *m2); 12 | int (* add_ref)(void *m2); 13 | 14 | int (* set_round)(void *m2, int32_t val); 15 | int (* set_simd)(void *m2, enum INSTRUCTION_TYPE); 16 | 17 | int (* set_system_key)(void *m2, uint8_t *val); 18 | int (* set_init_cbc)(void *m2, uint8_t *val); 19 | int (* set_scramble_key)(void *m2, uint8_t *val); 20 | int (* clear_scramble_key)(void *m2); 21 | 22 | int (* encrypt)(void *m2, int32_t type, uint8_t *buf, int32_t size); 23 | #if defined(_MSC_VER) 24 | int (* decrypt)(void *m2, int32_t type, uint8_t *buf, intptr_t size); 25 | #else 26 | int (* decrypt)(void *m2, int32_t type, uint8_t *buf, int32_t size); 27 | #endif 28 | 29 | } MULTI2; 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | extern MULTI2 *create_multi2(void); 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | 41 | #endif /* MULTI2_H */ 42 | -------------------------------------------------------------------------------- /aribb25/ts_section_parser.h: -------------------------------------------------------------------------------- 1 | #ifndef TS_SECTION_PARSER_H 2 | #define TS_SECTION_PARSER_H 3 | 4 | #include "ts_common_types.h" 5 | 6 | typedef struct { 7 | int64_t total; /* total received section count */ 8 | int64_t unique; /* unique section count */ 9 | int64_t error; /* crc and other error section count */ 10 | } TS_SECTION_PARSER_STAT; 11 | 12 | typedef struct { 13 | 14 | void *private_data; 15 | 16 | void (* release)(void *parser); 17 | 18 | int (* reset)(void *parser); 19 | 20 | int (* put)(void *parser, TS_HEADER *hdr, uint8_t *data, intptr_t size); 21 | int (* get)(void *parser, TS_SECTION *sect); 22 | int (* ret)(void *parser, TS_SECTION *sect); 23 | 24 | int (* get_count)(void *parser); 25 | 26 | int (* get_stat)(void *parser, TS_SECTION_PARSER_STAT *stat); 27 | 28 | } TS_SECTION_PARSER; 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | extern TS_SECTION_PARSER *create_ts_section_parser(void); 35 | 36 | #ifdef __cplusplus 37 | } 38 | #endif 39 | 40 | #endif /* TS_SECTION_PARSER_H */ 41 | -------------------------------------------------------------------------------- /aribb25/arib_std_b25_error_code.h: -------------------------------------------------------------------------------- 1 | #ifndef ARIB_STD_B25_ERROR_CODE_H 2 | #define ARIB_STD_B25_ERROR_CODE_H 3 | 4 | #define ARIB_STD_B25_ERROR_INVALID_PARAM -1 5 | #define ARIB_STD_B25_ERROR_NO_ENOUGH_MEMORY -2 6 | #define ARIB_STD_B25_ERROR_NON_TS_INPUT_STREAM -3 7 | #define ARIB_STD_B25_ERROR_NO_PAT_IN_HEAD_16M -4 8 | #define ARIB_STD_B25_ERROR_NO_PMT_IN_HEAD_32M -5 9 | #define ARIB_STD_B25_ERROR_NO_ECM_IN_HEAD_32M -6 10 | #define ARIB_STD_B25_ERROR_EMPTY_B_CAS_CARD -7 11 | #define ARIB_STD_B25_ERROR_INVALID_B_CAS_STATUS -8 12 | #define ARIB_STD_B25_ERROR_ECM_PROC_FAILURE -9 13 | #define ARIB_STD_B25_ERROR_DECRYPT_FAILURE -10 14 | #define ARIB_STD_B25_ERROR_PAT_PARSE_FAILURE -11 15 | #define ARIB_STD_B25_ERROR_PMT_PARSE_FAILURE -12 16 | #define ARIB_STD_B25_ERROR_ECM_PARSE_FAILURE -13 17 | #define ARIB_STD_B25_ERROR_CAT_PARSE_FAILURE -14 18 | #define ARIB_STD_B25_ERROR_EMM_PARSE_FAILURE -15 19 | #define ARIB_STD_B25_ERROR_EMM_PROC_FAILURE -16 20 | 21 | #define ARIB_STD_B25_WARN_UNPURCHASED_ECM 1 22 | #define ARIB_STD_B25_WARN_TS_SECTION_ID_MISSMATCH 2 23 | #define ARIB_STD_B25_WARN_BROKEN_TS_SECTION 3 24 | #define ARIB_STD_B25_WARN_PAT_NOT_COMPLETE 4 25 | #define ARIB_STD_B25_WARN_PMT_NOT_COMPLETE 5 26 | #define ARIB_STD_B25_WARN_ECM_NOT_COMPLETE 6 27 | 28 | #endif /* ARIB_STD_B25_ERROR_CODE_H */ 29 | -------------------------------------------------------------------------------- /aribb25/B25Decoder.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // B25Decoder.h 3 | //////////////////////////////////////////////////////////////////////////////// 4 | #ifndef __B25DECODER_H__ 5 | #define __B25DECODER_H__ 6 | 7 | #include 8 | #include 9 | 10 | #if defined(_WIN32) 11 | #include 12 | #include "arib_std_b25.h" 13 | #include "arib_std_b25_error_code.h" 14 | #else 15 | #include 16 | #include 17 | #include "typedef.h" 18 | #endif 19 | 20 | #define RETRY_INTERVAL 10 // 10sec interval 21 | 22 | class B25Decoder 23 | { 24 | public: 25 | B25Decoder(); 26 | ~B25Decoder(); 27 | int init(); 28 | void release(); 29 | void decode(BYTE *pSrc, DWORD dwSrcSize, BYTE **ppDst, DWORD *pdwDstSize); 30 | 31 | // libaribb25 wrapper 32 | int set_strip(int32_t strip); 33 | int set_emm_proc(int32_t on); 34 | int set_multi2_round(int32_t round); 35 | int set_unit_size(int size); 36 | int reset(); 37 | int flush(); 38 | int put(BYTE *pSrc, DWORD dwSrcSize); 39 | int get(BYTE **ppDst, DWORD *pdwDstSize); 40 | 41 | // initialize parameter 42 | static int strip; 43 | static int emm_proc; 44 | static int multi2_round; 45 | 46 | private: 47 | std::mutex _mtx; 48 | B_CAS_CARD *_bcas; 49 | ARIB_STD_B25 *_b25; 50 | BYTE *_data; 51 | time_t _errtime; 52 | }; 53 | 54 | #endif // __B25DECODER_H__ 55 | -------------------------------------------------------------------------------- /cmake/Uninstall.cmake: -------------------------------------------------------------------------------- 1 | set(MANIFEST "${CMAKE_CURRENT_BINARY_DIR}/install_manifest.txt") 2 | 3 | if(NOT EXISTS ${MANIFEST}) 4 | message(FATAL_ERROR "Cannot find install manifest: '${MANIFEST}'") 5 | endif() 6 | 7 | file(STRINGS ${MANIFEST} files) 8 | set(dirs "") 9 | 10 | foreach(file ${files}) 11 | if(EXISTS ${file} OR IS_SYMLINK ${file}) 12 | message(STATUS "Removing file: '${file}'") 13 | 14 | exec_program( 15 | ${CMAKE_COMMAND} ARGS "-E remove ${file}" 16 | OUTPUT_VARIABLE stdout 17 | RETURN_VALUE result 18 | ) 19 | 20 | if(NOT "${result}" STREQUAL 0) 21 | message(FATAL_ERROR "Failed to remove file: '${file}'.") 22 | endif() 23 | 24 | # Get the directory of the file and add it to the list 25 | get_filename_component(dir ${file} DIRECTORY) 26 | set(dirs ${dirs} ${dir}) 27 | endif() 28 | endforeach(file) 29 | 30 | # Remove empty directories 31 | list(REMOVE_DUPLICATES dirs) 32 | list(SORT dirs) 33 | list(REVERSE dirs) # Start from the deepest directory 34 | 35 | foreach(dir ${dirs}) 36 | if(IS_DIRECTORY ${dir}) 37 | file(GLOB children RELATIVE ${dir} ${dir}/*) 38 | 39 | if(NOT children) 40 | message(STATUS "Removing empty directory: '${dir}'") 41 | exec_program( 42 | ${CMAKE_COMMAND} ARGS "-E remove_directory ${dir}" 43 | OUTPUT_VARIABLE stdout 44 | RETURN_VALUE result 45 | ) 46 | 47 | if(NOT "${result}" STREQUAL 0) 48 | message(FATAL_ERROR "Failed to remove directory: '${dir}'.") 49 | endif() 50 | endif() 51 | endif() 52 | endforeach(dir) 53 | -------------------------------------------------------------------------------- /aribb25/ts_common_types.h: -------------------------------------------------------------------------------- 1 | #ifndef TS_COMMON_TYPES_H 2 | #define TS_COMMON_TYPES_H 3 | 4 | #include "portable.h" 5 | 6 | typedef struct { 7 | int32_t sync; /* 0- 7 : 8 bits */ 8 | int32_t transport_error_indicator; /* 8- 8 : 1 bit */ 9 | int32_t payload_unit_start_indicator; /* 9- 9 : 1 bit */ 10 | int32_t transport_priority; /* 10-10 : 1 bits */ 11 | int32_t pid; /* 11-23 : 13 bits */ 12 | int32_t transport_scrambling_control; /* 24-25 : 2 bits */ 13 | int32_t adaptation_field_control; /* 26-27 : 2 bits */ 14 | int32_t continuity_counter; /* 28-31 : 4 bits */ 15 | } TS_HEADER; 16 | 17 | typedef struct { 18 | int32_t table_id; /* 0- 7 : 8 bits */ 19 | int32_t section_syntax_indicator; /* 8- 8 : 1 bit */ 20 | int32_t private_indicator; /* 9- 9 : 1 bit */ 21 | int32_t section_length; /* 12-23 : 12 bits */ 22 | int32_t table_id_extension; /* 24-39 : 16 bits */ 23 | int32_t version_number; /* 42-46 : 5 bits */ 24 | int32_t current_next_indicator; /* 47-57 : 1 bit */ 25 | int32_t section_number; /* 48-55 : 8 bits */ 26 | int32_t last_section_number; /* 56-63 : 8 bits */ 27 | } TS_SECTION_HEADER; 28 | 29 | typedef struct { 30 | TS_SECTION_HEADER hdr; 31 | uint8_t *raw; 32 | uint8_t *data; 33 | uint8_t *tail; 34 | } TS_SECTION; 35 | 36 | #endif /* TS_COMMON_TYPES_H */ 37 | -------------------------------------------------------------------------------- /aribb25/version_b1.rc.in: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #pragma code_page(65001) 4 | 5 | VS_VERSION_INFO VERSIONINFO 6 | FILEVERSION @ARIBB1_MAJOR_VERSION@,@ARIBB1_MINOR_VERSION@,@ARIBB1_PATCH_VERSION@,0 7 | PRODUCTVERSION @ARIBB1_MAJOR_VERSION@,@ARIBB1_MINOR_VERSION@,@ARIBB1_PATCH_VERSION@,0 8 | FILEFLAGSMASK VS_FFI_FILEFLAGSMASK 9 | #ifdef DEBUG 10 | FILEFLAGS VS_FF_DEBUG | VS_FF_PRERELEASE 11 | #else 12 | FILEFLAGS 0 13 | #endif 14 | FILEOS VOS_NT_WINDOWS32 15 | #ifdef ARIBB1_DLL 16 | FILETYPE VFT_DLL 17 | #else 18 | FILETYPE VFT_APP 19 | #endif 20 | FILESUBTYPE VFT2_UNKNOWN 21 | BEGIN 22 | BLOCK "StringFileInfo" 23 | BEGIN 24 | BLOCK "080904b0" 25 | BEGIN 26 | VALUE "CompanyName", "@ARIBB1_COMPANY@" 27 | VALUE "FileDescription", "@ARIBB1_PRODUCT@ built with @CMAKE_C_COMPILER_ID@ @CMAKE_C_COMPILER_VERSION@ on @CMAKE_SYSTEM@" 28 | VALUE "FileVersion", "@ARIBB1_VERSION_STRING@" 29 | VALUE "InternalName", "@PROJECT_NAME@" 30 | VALUE "LegalCopyright", "@ARIBB1_COPYRIGHT@" 31 | #if defined(ARIBB1_DLL) 32 | VALUE "OriginalFilename", "@CMAKE_SHARED_LIBRARY_PREFIX@@ARIBB1_LIB_NAME@@CMAKE_SHARED_LIBRARY_SUFFIX@" 33 | #else 34 | VALUE "OriginalFilename", "@ARIBB1_CMD_NAME@@CMAKE_EXECUTABLE_SUFFIX@" 35 | #endif 36 | #if defined(UNICODE) 37 | VALUE "ProductName", "@ARIBB1_PRODUCT@ UNICODE" 38 | #else 39 | VALUE "ProductName", "@ARIBB1_PRODUCT@" 40 | #endif 41 | VALUE "ProductVersion", "@ARIBB1_VERSION_STRING@ (" BUILD_GIT_REVISION ")" 42 | END 43 | END 44 | BLOCK "VarFileInfo" 45 | BEGIN 46 | VALUE "Translation", 0x809, 1200 47 | END 48 | END 49 | -------------------------------------------------------------------------------- /aribb25/version_b25.rc.in: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #pragma code_page(65001) 4 | 5 | VS_VERSION_INFO VERSIONINFO 6 | FILEVERSION @ARIBB25_MAJOR_VERSION@,@ARIBB25_MINOR_VERSION@,@ARIBB25_PATCH_VERSION@,0 7 | PRODUCTVERSION @ARIBB25_MAJOR_VERSION@,@ARIBB25_MINOR_VERSION@,@ARIBB25_PATCH_VERSION@,0 8 | FILEFLAGSMASK VS_FFI_FILEFLAGSMASK 9 | #ifdef DEBUG 10 | FILEFLAGS VS_FF_DEBUG | VS_FF_PRERELEASE 11 | #else 12 | FILEFLAGS 0 13 | #endif 14 | FILEOS VOS_NT_WINDOWS32 15 | #ifdef ARIBB25_DLL 16 | FILETYPE VFT_DLL 17 | #else 18 | FILETYPE VFT_APP 19 | #endif 20 | FILESUBTYPE VFT2_UNKNOWN 21 | BEGIN 22 | BLOCK "StringFileInfo" 23 | BEGIN 24 | BLOCK "080904b0" 25 | BEGIN 26 | VALUE "CompanyName", "@ARIBB25_COMPANY@" 27 | VALUE "FileDescription", "@ARIBB25_PRODUCT@ built with @CMAKE_C_COMPILER_ID@ @CMAKE_C_COMPILER_VERSION@ on @CMAKE_SYSTEM@" 28 | VALUE "FileVersion", "@ARIBB25_VERSION_STRING@" 29 | VALUE "InternalName", "@PROJECT_NAME@" 30 | VALUE "LegalCopyright", "@ARIBB25_COPYRIGHT@" 31 | #if defined(ARIBB25_DLL) 32 | VALUE "OriginalFilename", "@CMAKE_SHARED_LIBRARY_PREFIX@@ARIBB25_LIB_NAME@@CMAKE_SHARED_LIBRARY_SUFFIX@" 33 | #else 34 | VALUE "OriginalFilename", "@ARIBB25_CMD_NAME@@CMAKE_EXECUTABLE_SUFFIX@" 35 | #endif 36 | #if defined(UNICODE) 37 | VALUE "ProductName", "@ARIBB25_PRODUCT@ UNICODE" 38 | #else 39 | VALUE "ProductName", "@ARIBB25_PRODUCT@" 40 | #endif 41 | VALUE "ProductVersion", "@ARIBB25_VERSION_STRING@ (" BUILD_GIT_REVISION ")" 42 | END 43 | END 44 | BLOCK "VarFileInfo" 45 | BEGIN 46 | VALUE "Translation", 0x809, 1200 47 | END 48 | END 49 | -------------------------------------------------------------------------------- /aribb25/arib_std_b25.h: -------------------------------------------------------------------------------- 1 | #ifndef ARIB_STD_B25_H 2 | #define ARIB_STD_B25_H 3 | 4 | #include "portable.h" 5 | #include "b_cas_card.h" 6 | 7 | typedef struct { 8 | uint8_t *data; 9 | uint32_t size; 10 | } ARIB_STD_B25_BUFFER; 11 | 12 | typedef struct { 13 | 14 | int32_t program_number; /* channel */ 15 | 16 | int32_t ecm_unpurchased_count; 17 | int32_t last_ecm_error_code; 18 | 19 | int32_t padding; 20 | 21 | int64_t total_packet_count; 22 | int64_t undecrypted_packet_count; 23 | 24 | } ARIB_STD_B25_PROGRAM_INFO; 25 | 26 | typedef struct { 27 | 28 | void *private_data; 29 | 30 | void (* release)(void *std_b25); 31 | 32 | int (* set_multi2_round)(void *std_b25, int32_t round); 33 | int (* set_strip)(void *std_b25, int32_t strip); 34 | int (* set_emm_proc)(void *std_b25, int32_t on); 35 | int (* set_simd_mode)(void *std_b25, int32_t instructin); 36 | int32_t (* get_simd_mode)(void *std_b25); 37 | 38 | int (* set_b_cas_card)(void *std_b25, B_CAS_CARD *bcas); 39 | 40 | int (* set_unit_size)(void *std_b25, int size); 41 | 42 | int (* reset)(void *std_b25); 43 | int (* flush)(void *std_b25); 44 | 45 | int (* put)(void *std_b25, ARIB_STD_B25_BUFFER *buf); 46 | int (* get)(void *std_b25, ARIB_STD_B25_BUFFER *buf); 47 | 48 | int (* get_program_count)(void *std_b25); 49 | int (* get_program_info)(void *std_b25, ARIB_STD_B25_PROGRAM_INFO *info, int32_t idx); 50 | 51 | int (*withdraw)(void *std_b25, ARIB_STD_B25_BUFFER *buf); 52 | 53 | } ARIB_STD_B25; 54 | 55 | #define ARIB_STD_B25_TS_PROBING_MIN_DATA (320 * 9 - 1) 56 | 57 | #ifdef __cplusplus 58 | extern "C" { 59 | #endif 60 | 61 | extern ARIB_STD_B25 *create_arib_std_b25(void); 62 | 63 | #ifdef USE_BENCHMARK 64 | extern int test_multi2_decryption(void *std_b25, int64_t *time, int32_t instructin, int32_t round); 65 | #endif 66 | 67 | #ifdef __cplusplus 68 | } 69 | #endif 70 | 71 | #endif /* ARIB_STD_B25_H */ 72 | -------------------------------------------------------------------------------- /aribb25/b_cas_card.h: -------------------------------------------------------------------------------- 1 | #ifndef B_CAS_CARD_H 2 | #define B_CAS_CARD_H 3 | 4 | #include "portable.h" 5 | 6 | typedef struct { 7 | uint8_t system_key[32]; 8 | uint8_t init_cbc[8]; 9 | int64_t bcas_card_id; 10 | int32_t card_status; 11 | int32_t ca_system_id; 12 | } B_CAS_INIT_STATUS; 13 | 14 | typedef struct { 15 | int64_t *data; 16 | int32_t count; 17 | } B_CAS_ID; 18 | 19 | typedef struct { 20 | 21 | int32_t s_yy; /* start date : year */ 22 | int32_t s_mm; /* start date : month */ 23 | int32_t s_dd; /* start date : day */ 24 | 25 | int32_t l_yy; /* limit date : year */ 26 | int32_t l_mm; /* limit date : month */ 27 | int32_t l_dd; /* limit date : day */ 28 | 29 | int32_t hold_time; /* in hour unit */ 30 | 31 | int32_t broadcaster_group_id; 32 | 33 | int32_t network_id; 34 | int32_t transport_id; 35 | 36 | } B_CAS_PWR_ON_CTRL; 37 | 38 | typedef struct { 39 | B_CAS_PWR_ON_CTRL *data; 40 | int32_t count; 41 | } B_CAS_PWR_ON_CTRL_INFO; 42 | 43 | typedef struct { 44 | uint8_t scramble_key[16]; 45 | uint32_t return_code; 46 | } B_CAS_ECM_RESULT; 47 | 48 | typedef struct { 49 | 50 | void *private_data; 51 | 52 | void (* release)(void *bcas); 53 | 54 | int (* init)(void *bcas); 55 | 56 | int (* get_init_status)(void *bcas, B_CAS_INIT_STATUS *stat); 57 | int (* get_id)(void *bcas, B_CAS_ID *dst); 58 | int (* get_pwr_on_ctrl)(void *bcas, B_CAS_PWR_ON_CTRL_INFO *dst); 59 | 60 | int (* proc_ecm)(void *bcas, B_CAS_ECM_RESULT *dst, uint8_t *src, int len); 61 | int (* proc_emm)(void *bcas, uint8_t *src, int len); 62 | 63 | } B_CAS_CARD; 64 | 65 | #ifdef __cplusplus 66 | extern "C" { 67 | #endif 68 | 69 | #if defined(_WIN32) 70 | # include 71 | #else 72 | # define TCHAR char 73 | #endif 74 | extern B_CAS_CARD *create_b_cas_card(void); 75 | extern int override_card_reader_name_pattern(const TCHAR * name); 76 | 77 | #ifdef __cplusplus 78 | } 79 | #endif 80 | 81 | #endif /* B_CAS_CARD_H */ 82 | -------------------------------------------------------------------------------- /aribb25/multi2_block.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "portable.h" 6 | 7 | namespace multi2 { 8 | 9 | inline uint32_t load_be(const uint8_t *p) { 10 | return (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]; 11 | } 12 | 13 | inline void store_be(uint8_t *p, uint32_t v) { 14 | p[0] = (v >> 24) & 0xff; 15 | p[1] = (v >> 16) & 0xff; 16 | p[2] = (v >> 8) & 0xff; 17 | p[3] = v & 0xff; 18 | } 19 | 20 | template 21 | struct block { 22 | T left; 23 | T right; 24 | 25 | inline block() { } 26 | inline block(const T &l, const T &r) : left(l), right(r) { } 27 | 28 | void load(const uint8_t *p); 29 | void store(uint8_t *p) const; 30 | 31 | block operator^(const block &other) const; 32 | 33 | std::pair, block > cbc_post_decrypt(const block &ciphertext, const block &state) const; 34 | }; 35 | 36 | template 37 | inline size_t block_size() { 38 | return sizeof(T) * 2; 39 | } 40 | 41 | typedef block cbc_state;; 42 | 43 | template<> 44 | inline void block::load(const uint8_t *p) { 45 | left = load_be(p); 46 | right = load_be(p + 4); 47 | } 48 | 49 | template<> 50 | inline void block::store(uint8_t *p) const { 51 | store_be(p, left); 52 | store_be(p + 4, right); 53 | } 54 | 55 | template<> 56 | inline block block::operator^(const block &other) const { 57 | return block(left ^ other.left, right ^ other.right); 58 | } 59 | 60 | template<> 61 | inline std::pair, cbc_state> block::cbc_post_decrypt(const block &c, const cbc_state &state) const { 62 | block p = *this ^ state; 63 | return std::make_pair(p, c); 64 | } 65 | 66 | template 67 | inline T rot(const T &v) { 68 | return (v << N) | (v >> (32 - N)); 69 | } 70 | 71 | template 72 | inline T rot1_sub(const T &v) { 73 | return v + (v >> 31); 74 | } 75 | 76 | template 77 | inline T rot1_add_dec(const T &v) { 78 | return rot<1>(v) + v - T(1); 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /aribb25/libaribb25.h: -------------------------------------------------------------------------------- 1 | // libaribb25.h: CB25Decoder クラスのインターフェイス 2 | // 3 | ////////////////////////////////////////////////////////////////////// 4 | #pragma once 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #include "IB25Decoder.h" 11 | #include "arib_std_b25.h" 12 | #include "arib_std_b25_error_code.h" 13 | 14 | #define RETRY_INTERVAL 10 // 10sec interval 15 | 16 | class CB25Decoder : public IB25Decoder2 17 | { 18 | public: 19 | // IB25Decoder 20 | virtual const BOOL Initialize(DWORD dwRound = 4); 21 | virtual const BOOL Decode(BYTE *pSrcBuf, const DWORD dwSrcSize, BYTE **ppDstBuf, DWORD *pdwDstSize); 22 | virtual const BOOL Flush(BYTE **ppDstBuf, DWORD *pdwDstSize); 23 | virtual const BOOL Reset(void); 24 | 25 | // IB25Decoder2 26 | virtual void DiscardNullPacket(const bool bEnable = true); 27 | virtual void DiscardScramblePacket(const bool bEnable = true); 28 | virtual void EnableEmmProcess(const bool bEnable = true); 29 | virtual void SetMulti2Round(const int32_t round = 4); 30 | virtual void SetSimdMode(const int32_t instruction = 2); 31 | virtual const DWORD GetDescramblingState(const WORD wProgramID); 32 | virtual void ResetStatistics(void); 33 | virtual const DWORD GetPacketStride(void); 34 | virtual const DWORD GetInputPacketNum(const WORD wPID = TS_INVALID_PID); 35 | virtual const DWORD GetOutputPacketNum(const WORD wPID = TS_INVALID_PID); 36 | virtual const DWORD GetSyncErrNum(void); 37 | virtual const DWORD GetFormatErrNum(void); 38 | virtual const DWORD GetTransportErrNum(void); 39 | virtual const DWORD GetContinuityErrNum(const WORD wPID = TS_INVALID_PID); 40 | virtual const DWORD GetScramblePacketNum(const WORD wPID = TS_INVALID_PID); 41 | virtual const DWORD GetEcmProcessNum(void); 42 | virtual const DWORD GetEmmProcessNum(void); 43 | 44 | // CB25Decoder 45 | CB25Decoder(void); 46 | virtual ~CB25Decoder(void); 47 | void Release(void); 48 | static CB25Decoder *m_pThis; 49 | 50 | private: 51 | std::mutex _mtx; 52 | B_CAS_CARD *_bcas; 53 | ARIB_STD_B25 *_b25; 54 | BYTE *_data; 55 | time_t _errtime; 56 | }; 57 | -------------------------------------------------------------------------------- /aribb25/portable.h: -------------------------------------------------------------------------------- 1 | #ifndef PORTABLE_H 2 | #define PORTABLE_H 3 | 4 | #include 5 | 6 | #if !defined(_WIN32) 7 | 8 | #define _open open 9 | #define _close close 10 | #define _read read 11 | #define _write write 12 | #define _lseeki64 lseek 13 | #define _telli64(fd) (lseek(fd,0,SEEK_CUR)) 14 | #define _O_BINARY (0) 15 | #define _O_RDONLY (O_RDONLY) 16 | #define _O_WRONLY (O_WRONLY) 17 | #define _O_SEQUENTIAL (0) 18 | #define _O_CREAT (O_CREAT) 19 | #define _O_TRUNC (O_TRUNC) 20 | #define _S_IREAD (S_IRUSR|S_IRGRP|S_IROTH) 21 | #define _S_IWRITE (S_IWUSR|S_IWGRP|S_IWOTH) 22 | 23 | #ifndef __forceinline 24 | #define __forceinline __attribute__((always_inline)) 25 | #endif 26 | 27 | #ifndef __restrict 28 | #define __restrict __restrict__ 29 | #endif 30 | 31 | #ifdef __i386__ 32 | #define _M_IX86 __i386__ 33 | #endif 34 | 35 | #ifdef __x86_64__ 36 | #define _M_X64 __x86_64__ 37 | #define _M_AMD64 __x86_64__ 38 | #endif 39 | 40 | #if defined(__APPLE__) 41 | 42 | #include 43 | #define _byteswap_ulong(x) OSSwapInt32(x) 44 | #define _byteswap_uint64(x) OSSwapInt64(x) 45 | 46 | #elif defined(__sun) || defined(sun) 47 | 48 | #include 49 | #define _byteswap_ulong(x) BSWAP_32(x) 50 | #define _byteswap_uint64(x) BSWAP_64(x) 51 | 52 | #elif defined(__FreeBSD__) 53 | 54 | #include 55 | #define _byteswap_ulong(x) bswap32(x) 56 | #define _byteswap_uint64(x) bswap64(x) 57 | 58 | #elif defined(__OpenBSD__) 59 | 60 | #include 61 | #define _byteswap_ulong(x) swap32(x) 62 | #define _byteswap_uint64(x) swap64(x) 63 | 64 | #elif defined(__NetBSD__) 65 | 66 | #include 67 | #include 68 | #if defined(__BSWAP_RENAME) && !defined(_byteswap_ulong) 69 | #define _byteswap_ulong(x) bswap32(x) 70 | #define _byteswap_uint64(x) bswap64(x) 71 | #endif 72 | 73 | #else 74 | 75 | #include 76 | #define _byteswap_ulong(x) bswap_32(x) 77 | #define _byteswap_uint64(x) bswap_64(x) 78 | 79 | #endif /* defined(__APPLE__) */ 80 | 81 | #define mem_aligned_alloc(s) aligned_alloc(s, 32) 82 | #define mem_aligned_free free 83 | 84 | #define ALIGNAS(s) __attribute__((aligned(s))) 85 | 86 | #else /* !defined(_WIN32) */ 87 | 88 | #define mem_aligned_alloc(s) _aligned_malloc(s, 32) 89 | #define mem_aligned_free _aligned_free 90 | 91 | #define ALIGNAS(s) __declspec(align(s)) 92 | 93 | #endif /* !defined(_WIN32) */ 94 | 95 | #endif /* PORTABLE_H */ 96 | -------------------------------------------------------------------------------- /aribb25/IB25Decoder.h: -------------------------------------------------------------------------------- 1 | // IB25Decoder.h: IB25Decoder クラスのインターフェイス 2 | // 3 | ////////////////////////////////////////////////////////////////////// 4 | 5 | 6 | #pragma once 7 | 8 | #include 9 | 10 | ///////////////////////////////////////////////////////////////////////////// 11 | // 定数定義 12 | ///////////////////////////////////////////////////////////////////////////// 13 | 14 | #define TS_INVALID_PID 0xFFFFU // 無効PID 15 | 16 | 17 | ///////////////////////////////////////////////////////////////////////////// 18 | // B25デコーダインタフェース 19 | ///////////////////////////////////////////////////////////////////////////// 20 | 21 | class IB25Decoder 22 | { 23 | public: 24 | virtual const BOOL Initialize(DWORD dwRound = 4) = 0; 25 | virtual void Release(void) = 0; 26 | 27 | virtual const BOOL Decode(BYTE *pSrcBuf, const DWORD dwSrcSize, BYTE **ppDstBuf, DWORD *pdwDstSize) = 0; 28 | virtual const BOOL Flush(BYTE **ppDstBuf, DWORD *pdwDstSize) = 0; 29 | virtual const BOOL Reset(void) = 0; 30 | }; 31 | 32 | 33 | ///////////////////////////////////////////////////////////////////////////// 34 | // B25デコーダインタフェース2 35 | ///////////////////////////////////////////////////////////////////////////// 36 | 37 | class IB25Decoder2 : public IB25Decoder 38 | { 39 | public: 40 | enum // GetDescramblerState() リターンコード 41 | { 42 | DS_NO_ERROR = 0x00000000UL, // エラーなし正常 43 | DS_BCAS_ERROR = 0x00000001UL, // B-CASカードエラー 44 | DS_NOT_CONTRACTED = 0x00000002UL // 視聴未契約 45 | }; 46 | 47 | virtual void DiscardNullPacket(const bool bEnable = true) = 0; 48 | virtual void DiscardScramblePacket(const bool bEnable = true) = 0; 49 | virtual void EnableEmmProcess(const bool bEnable = true) = 0; 50 | virtual void SetMulti2Round(const int32_t round = 4) = 0; // オリジナルに追加 51 | virtual void SetSimdMode(const int32_t instruction = 3) = 0; // オリジナルに追加 52 | 53 | virtual const DWORD GetDescramblingState(const WORD wProgramID) = 0; 54 | 55 | virtual void ResetStatistics(void) = 0; 56 | 57 | virtual const DWORD GetPacketStride(void) = 0; 58 | virtual const DWORD GetInputPacketNum(const WORD wPID = TS_INVALID_PID) = 0; 59 | virtual const DWORD GetOutputPacketNum(const WORD wPID = TS_INVALID_PID) = 0; 60 | virtual const DWORD GetSyncErrNum(void) = 0; 61 | virtual const DWORD GetFormatErrNum(void) = 0; 62 | virtual const DWORD GetTransportErrNum(void) = 0; 63 | virtual const DWORD GetContinuityErrNum(const WORD wPID = TS_INVALID_PID) = 0; 64 | virtual const DWORD GetScramblePacketNum(const WORD wPID = TS_INVALID_PID) = 0; 65 | virtual const DWORD GetEcmProcessNum(void) = 0; 66 | virtual const DWORD GetEmmProcessNum(void) = 0; 67 | }; 68 | -------------------------------------------------------------------------------- /aribb25/b1.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav 15 | 16 | 17 | 18 | 19 | ソース ファイル 20 | 21 | 22 | ソース ファイル 23 | 24 | 25 | ソース ファイル 26 | 27 | 28 | ソース ファイル 29 | 30 | 31 | ソース ファイル 32 | 33 | 34 | ソース ファイル 35 | 36 | 37 | 38 | 39 | ヘッダー ファイル 40 | 41 | 42 | ヘッダー ファイル 43 | 44 | 45 | ヘッダー ファイル 46 | 47 | 48 | ヘッダー ファイル 49 | 50 | 51 | ヘッダー ファイル 52 | 53 | 54 | ヘッダー ファイル 55 | 56 | 57 | ヘッダー ファイル 58 | 59 | 60 | ヘッダー ファイル 61 | 62 | 63 | ヘッダー ファイル 64 | 65 | 66 | ヘッダー ファイル 67 | 68 | 69 | ヘッダー ファイル 70 | 71 | 72 | ヘッダー ファイル 73 | 74 | 75 | -------------------------------------------------------------------------------- /aribb25/b25.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav 15 | 16 | 17 | 18 | 19 | ソース ファイル 20 | 21 | 22 | ソース ファイル 23 | 24 | 25 | ソース ファイル 26 | 27 | 28 | ソース ファイル 29 | 30 | 31 | ソース ファイル 32 | 33 | 34 | ソース ファイル 35 | 36 | 37 | 38 | 39 | ヘッダー ファイル 40 | 41 | 42 | ヘッダー ファイル 43 | 44 | 45 | ヘッダー ファイル 46 | 47 | 48 | ヘッダー ファイル 49 | 50 | 51 | ヘッダー ファイル 52 | 53 | 54 | ヘッダー ファイル 55 | 56 | 57 | ヘッダー ファイル 58 | 59 | 60 | ヘッダー ファイル 61 | 62 | 63 | ヘッダー ファイル 64 | 65 | 66 | ヘッダー ファイル 67 | 68 | 69 | ヘッダー ファイル 70 | 71 | 72 | ヘッダー ファイル 73 | 74 | 75 | -------------------------------------------------------------------------------- /aribb25/arib-b1-stream-test.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav 15 | 16 | 17 | 18 | 19 | ソース ファイル 20 | 21 | 22 | ソース ファイル 23 | 24 | 25 | ソース ファイル 26 | 27 | 28 | ソース ファイル 29 | 30 | 31 | ソース ファイル 32 | 33 | 34 | ソース ファイル 35 | 36 | 37 | 38 | 39 | ヘッダー ファイル 40 | 41 | 42 | ヘッダー ファイル 43 | 44 | 45 | ヘッダー ファイル 46 | 47 | 48 | ヘッダー ファイル 49 | 50 | 51 | ヘッダー ファイル 52 | 53 | 54 | ヘッダー ファイル 55 | 56 | 57 | ヘッダー ファイル 58 | 59 | 60 | ヘッダー ファイル 61 | 62 | 63 | ヘッダー ファイル 64 | 65 | 66 | ヘッダー ファイル 67 | 68 | 69 | ヘッダー ファイル 70 | 71 | 72 | ヘッダー ファイル 73 | 74 | 75 | -------------------------------------------------------------------------------- /aribb25/arib-b25-stream-test.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav 15 | 16 | 17 | 18 | 19 | ソース ファイル 20 | 21 | 22 | ソース ファイル 23 | 24 | 25 | ソース ファイル 26 | 27 | 28 | ソース ファイル 29 | 30 | 31 | ソース ファイル 32 | 33 | 34 | ソース ファイル 35 | 36 | 37 | 38 | 39 | ヘッダー ファイル 40 | 41 | 42 | ヘッダー ファイル 43 | 44 | 45 | ヘッダー ファイル 46 | 47 | 48 | ヘッダー ファイル 49 | 50 | 51 | ヘッダー ファイル 52 | 53 | 54 | ヘッダー ファイル 55 | 56 | 57 | ヘッダー ファイル 58 | 59 | 60 | ヘッダー ファイル 61 | 62 | 63 | ヘッダー ファイル 64 | 65 | 66 | ヘッダー ファイル 67 | 68 | 69 | ヘッダー ファイル 70 | 71 | 72 | ヘッダー ファイル 73 | 74 | 75 | -------------------------------------------------------------------------------- /aribb25/libaribb1.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | ソース ファイル 20 | 21 | 22 | ソース ファイル 23 | 24 | 25 | ソース ファイル 26 | 27 | 28 | ソース ファイル 29 | 30 | 31 | ソース ファイル 32 | 33 | 34 | ソース ファイル 35 | 36 | 37 | 38 | 39 | ヘッダー ファイル 40 | 41 | 42 | ヘッダー ファイル 43 | 44 | 45 | ヘッダー ファイル 46 | 47 | 48 | ヘッダー ファイル 49 | 50 | 51 | ヘッダー ファイル 52 | 53 | 54 | ヘッダー ファイル 55 | 56 | 57 | ヘッダー ファイル 58 | 59 | 60 | ヘッダー ファイル 61 | 62 | 63 | ヘッダー ファイル 64 | 65 | 66 | ヘッダー ファイル 67 | 68 | 69 | ヘッダー ファイル 70 | 71 | 72 | ヘッダー ファイル 73 | 74 | 75 | ヘッダー ファイル 76 | 77 | 78 | ヘッダー ファイル 79 | 80 | 81 | -------------------------------------------------------------------------------- /aribb25/libaribb25.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | ソース ファイル 20 | 21 | 22 | ソース ファイル 23 | 24 | 25 | ソース ファイル 26 | 27 | 28 | ソース ファイル 29 | 30 | 31 | ソース ファイル 32 | 33 | 34 | ソース ファイル 35 | 36 | 37 | 38 | 39 | ヘッダー ファイル 40 | 41 | 42 | ヘッダー ファイル 43 | 44 | 45 | ヘッダー ファイル 46 | 47 | 48 | ヘッダー ファイル 49 | 50 | 51 | ヘッダー ファイル 52 | 53 | 54 | ヘッダー ファイル 55 | 56 | 57 | ヘッダー ファイル 58 | 59 | 60 | ヘッダー ファイル 61 | 62 | 63 | ヘッダー ファイル 64 | 65 | 66 | ヘッダー ファイル 67 | 68 | 69 | ヘッダー ファイル 70 | 71 | 72 | ヘッダー ファイル 73 | 74 | 75 | ヘッダー ファイル 76 | 77 | 78 | ヘッダー ファイル 79 | 80 | 81 | -------------------------------------------------------------------------------- /aribb25/multi2_neon.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #if defined(__ARM_NEON__) || defined(__ARM_NEON) 4 | 5 | #if !defined(__BYTE_ORDER__) || !defined(__ORDER_LITTLE_ENDIAN__) || (__BYTE_ORDER__) != (__ORDER_LITTLE_ENDIAN__) 6 | #error "Currently, USE_NEON is only for little-endian." 7 | #endif 8 | 9 | #include 10 | #include 11 | 12 | #include "portable.h" 13 | 14 | #include "multi2_block.h" 15 | 16 | namespace multi2 { 17 | 18 | namespace arm { 19 | 20 | class neon { 21 | private: 22 | uint32x4_t v; 23 | 24 | public: 25 | inline neon() { } 26 | inline neon(uint32_t n) { v = vdupq_n_u32(n); } 27 | inline neon(const uint32x4_t &r) { v = r; } 28 | 29 | inline neon &operator=(const neon &other) { 30 | v = other.v; 31 | return *this; 32 | } 33 | 34 | inline neon operator+(const neon &other) const { return vaddq_u32(v, other.v); } 35 | inline neon operator-(const neon &other) const { return vsubq_u32(v, other.v); } 36 | inline neon operator^(const neon &other) const { return veorq_u32(v, other.v); } 37 | inline neon operator|(const neon &other) const { return vorrq_u32(v, other.v); } 38 | 39 | inline const uint32x4_t &value() const { return v; } 40 | }; 41 | 42 | } 43 | 44 | template<> 45 | inline void block::load(const uint8_t *p) { 46 | const uint32_t *q = reinterpret_cast(p); 47 | uint32x4x2_t a = vld2q_u32(q); 48 | 49 | left = vreinterpretq_u32_u8(vrev32q_u8(vreinterpretq_u8_u32(a.val[0]))); 50 | right = vreinterpretq_u32_u8(vrev32q_u8(vreinterpretq_u8_u32(a.val[1]))); 51 | } 52 | 53 | template<> 54 | inline void block::store(uint8_t *p) const { 55 | uint32x4_t a0 = left.value(); 56 | uint32x4_t a1 = right.value(); 57 | 58 | uint32x4_t b0 = vreinterpretq_u32_u8(vrev32q_u8(vreinterpretq_u8_u32(a0))); 59 | uint32x4_t b1 = vreinterpretq_u32_u8(vrev32q_u8(vreinterpretq_u8_u32(a1))); 60 | 61 | uint32_t *q = reinterpret_cast(p); 62 | uint32x4x2_t d = { b0, b1 }; 63 | vst2q_u32(q, d); 64 | } 65 | 66 | template<> 67 | inline std::pair, cbc_state> block::cbc_post_decrypt(const block &c, const cbc_state &state) const { 68 | uint32x4_t c0 = c.left.value(); // 3 2 1 0 69 | uint32x4_t c1 = c.right.value(); 70 | 71 | uint32_t s0 = vgetq_lane_u32(c0, 3); // 3 72 | uint32_t s1 = vgetq_lane_u32(c1, 3); 73 | 74 | uint32x4_t b0 = vextq_u32(c0, c0, 3); // 2 1 0 3 75 | uint32x4_t b1 = vextq_u32(c1, c1, 3); 76 | 77 | uint32x4_t x0 = vsetq_lane_u32(state.left, b0, 0); // 2 1 0 s 78 | uint32x4_t x1 = vsetq_lane_u32(state.right, b1, 0); 79 | 80 | uint32x4_t d0 = left.value(); // 3 2 1 0 81 | uint32x4_t d1 = right.value(); 82 | 83 | uint32x4_t p0 = veorq_u32(d0, x0); 84 | uint32x4_t p1 = veorq_u32(d1, x1); 85 | 86 | return std::make_pair(block(p0, p1), cbc_state(s0, s1)); 87 | } 88 | 89 | template 90 | inline arm::neon rot(const arm::neon &v) { 91 | uint32x4_t a = v.value(); 92 | if (N == 16) { 93 | return vreinterpretq_u32_u16(vrev32q_u16(vreinterpretq_u16_u32(a))); 94 | } else { 95 | return vsliq_n_u32(vshrq_n_u32(a, 32 - N), a, N); 96 | } 97 | } 98 | 99 | template<> 100 | inline arm::neon rot1_sub(const arm::neon &v) { 101 | uint32x4_t a = v.value(); 102 | return vsraq_n_u32(a, a, 31); 103 | } 104 | 105 | template<> 106 | inline arm::neon rot1_add_dec(const arm::neon &v) { 107 | uint32x4_t d = vcgeq_s32(vreinterpretq_s32_u32(v.value()), vdupq_n_s32(0)); 108 | return v + v + v + arm::neon(d); 109 | } 110 | 111 | } 112 | 113 | #endif /* __ARM_NEON__ || __ARM_NEON */ 114 | -------------------------------------------------------------------------------- /.github/workflows/build-package.yml: -------------------------------------------------------------------------------- 1 | name: Package 2 | on: push 3 | 4 | jobs: 5 | windows: 6 | name: Windows Package 7 | runs-on: windows-2019 8 | steps: 9 | - name: setup msbuild 10 | uses: microsoft/setup-msbuild@v2 11 | - uses: actions/checkout@v4 12 | - name: build 13 | run: | 14 | msbuild arib_std_b25.sln /t:Build /p:Configuration=Release /p:Platform=Win32 /p:PlatformToolset=v142 15 | msbuild arib_std_b25.sln /t:Build /p:Configuration=Release /p:Platform=x64 /p:PlatformToolset=v142 16 | - name: get output name 17 | id: get_output_name 18 | run: | 19 | $version = (Get-Content aribb25/td.c | Select-String -Pattern '#define VERSION_STRING "(.*)"').Matches.Groups[1].Value 20 | echo "archive_path=libaribb25_${version}_windows.zip" >> $ENV:GITHUB_OUTPUT 21 | - name: package 22 | run: | 23 | mkdir libaribb25/ 24 | mkdir libaribb25/32bit/ 25 | mkdir libaribb25/64bit/ 26 | Copy-Item -Path ".\Win32\Release\*" -Destination ".\libaribb25\32bit\" -Recurse -Force 27 | Copy-Item -Path ".\x64\Release\*" -Destination ".\libaribb25\64bit\" -Recurse -Force 28 | Copy-Item -Path libaribb25\32bit\libaribb1.dll -Destination libaribb25\32bit\B1Decoder.dll -Force 29 | Copy-Item -Path libaribb25\64bit\libaribb1.dll -Destination libaribb25\64bit\B1Decoder.dll -Force 30 | Copy-Item -Path libaribb25\32bit\libaribb25.dll -Destination libaribb25\32bit\B25Decoder.dll -Force 31 | Copy-Item -Path libaribb25\64bit\libaribb25.dll -Destination libaribb25\64bit\B25Decoder.dll -Force 32 | 7z a -tzip ${{ steps.get_output_name.outputs.archive_path }} libaribb25 33 | - name: save artifacts 34 | uses: actions/upload-artifact@v4 35 | with: 36 | name: ${{ steps.get_output_name.outputs.archive_path }} 37 | path: ${{ steps.get_output_name.outputs.archive_path }} 38 | 39 | deb-package: 40 | name: Debian Package 41 | runs-on: ubuntu-20.04 42 | steps: 43 | - uses: actions/checkout@v4 44 | - name: setup 45 | run: sudo apt-get install -y build-essential cmake cmake-data libpcsclite-dev pkg-config 46 | - name: build 47 | run: | 48 | cmake -B build -DUSE_AVX2=on -DCMAKE_INSTALL_PREFIX=/usr 49 | cd build 50 | sudo make package 51 | - name: get output name 52 | id: get_output_name 53 | run: | 54 | echo "deb_path=$(ls build/libaribb25_*.deb)" >> "$GITHUB_OUTPUT" 55 | echo "deb_file=$(basename $(ls build/libaribb25_*.deb))" >> "$GITHUB_OUTPUT" 56 | - name: save artifacts 57 | uses: actions/upload-artifact@v4 58 | with: 59 | name: ${{ steps.get_output_name.outputs.deb_file }} 60 | path: ${{ steps.get_output_name.outputs.deb_path }} 61 | 62 | deb-package-arm: 63 | name: Debian Package (ARM) 64 | runs-on: ubuntu-latest 65 | steps: 66 | - uses: actions/checkout@v4 67 | - uses: docker/setup-qemu-action@v3 68 | - uses: docker/setup-buildx-action@v3 69 | - name: setup 70 | uses: docker/build-push-action@v5 71 | with: 72 | context: .github/workflows/ 73 | tags: arm64v8/ubuntu:build 74 | build-args: IMAGE=arm64v8/ubuntu:20.04 75 | cache-from: type=gha,scope=arm64v8/ubuntu 76 | cache-to: type=gha,scope=arm64v8/ubuntu,mode=max 77 | load: true 78 | - name: build 79 | run: | 80 | docker run --rm -i -v $(pwd):/work -w /work -e CLICOLOR_FORCE=1 arm64v8/ubuntu:build bash -c \ 81 | 'cmake -B build -DCMAKE_INSTALL_PREFIX=/usr && cd build && make package' 82 | - name: get output name 83 | id: get_output_name 84 | run: | 85 | echo "deb_path=$(ls build/libaribb25_*.deb)" >> "$GITHUB_OUTPUT" 86 | echo "deb_file=$(basename $(ls build/libaribb25_*.deb))" >> "$GITHUB_OUTPUT" 87 | - name: save artifacts 88 | uses: actions/upload-artifact@v4 89 | with: 90 | name: ${{ steps.get_output_name.outputs.deb_file }} 91 | path: ${{ steps.get_output_name.outputs.deb_path }} 92 | -------------------------------------------------------------------------------- /aribb25/multi2_ymm.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #if defined(__AVX2__) 4 | 5 | #include 6 | 7 | #if defined(_WIN32) 8 | # include 9 | #else 10 | # include 11 | #endif 12 | 13 | #include "portable.h" 14 | 15 | #include "multi2_block.h" 16 | 17 | namespace multi2 { 18 | 19 | namespace x86 { 20 | 21 | class ymm { 22 | private: 23 | __m256i v; 24 | 25 | public: 26 | inline ymm() { 27 | #if !defined(NO_MM_UNDEFINED) 28 | v = _mm256_undefined_si256(); 29 | #endif 30 | } 31 | inline ymm(uint32_t n) { v = _mm256_set1_epi32(n); } 32 | inline ymm(const __m256i &r) { v = r; } 33 | 34 | inline ymm &operator=(const ymm &other) { 35 | v = other.v; 36 | return *this; 37 | } 38 | 39 | inline ymm operator+(const ymm &other) const { return _mm256_add_epi32(v, other.v); } 40 | inline ymm operator-(const ymm &other) const { return _mm256_sub_epi32(v, other.v); } 41 | inline ymm operator^(const ymm &other) const { return _mm256_xor_si256(v, other.v); } 42 | inline ymm operator|(const ymm &other) const { return _mm256_or_si256(v, other.v); } 43 | inline ymm operator<<(int n) const { return _mm256_slli_epi32(v, n); } 44 | inline ymm operator>>(int n) const { return _mm256_srli_epi32(v, n); } 45 | 46 | inline const __m256i &value() const { return v; } 47 | }; 48 | 49 | } 50 | 51 | template<> 52 | inline void block::load(const uint8_t *p) { 53 | const __m256i *q = reinterpret_cast(p); 54 | 55 | __m256i a0 = _mm256_loadu_si256(q); // 7 6 5 4 3 2 1 0 - DCBA 56 | __m256i a1 = _mm256_loadu_si256(q + 1); // f e d c b a 9 8 - DCBA 57 | 58 | __m256i s = _mm256_set_epi8( 59 | 12, 13, 14, 15, 4, 5, 6, 7, 8, 9, 10, 11, 0, 1, 2, 3, 60 | 12, 13, 14, 15, 4, 5, 6, 7, 8, 9, 10, 11, 0, 1, 2, 3 61 | ); 62 | __m256i b0 = _mm256_shuffle_epi8(a0, s); // 7 5 6 4 3 1 2 0 - ABCD 63 | __m256i b1 = _mm256_shuffle_epi8(a1, s); // f d e c b 9 a 8 - ABCD 64 | 65 | left = _mm256_unpacklo_epi32(b0, b1); // e 6 c 4 a 2 8 0 - ABCD 66 | right = _mm256_unpackhi_epi32(b0, b1); // f 7 d 5 b 3 9 1 - ABCD 67 | } 68 | 69 | template<> 70 | inline void block::store(uint8_t *p) const { 71 | __m256i a0 = left.value(); // e 6 c 4 a 2 8 0 - ABCD 72 | __m256i a1 = right.value(); // f 7 d 5 b 3 9 1 - ABCD 73 | 74 | __m256i s = _mm256_set_epi8( 75 | 12, 13, 14, 15, 4, 5, 6, 7, 8, 9, 10, 11, 0, 1, 2, 3, 76 | 12, 13, 14, 15, 4, 5, 6, 7, 8, 9, 10, 11, 0, 1, 2, 3 77 | ); 78 | __m256i b0 = _mm256_shuffle_epi8(a0, s); // e c 6 4 a 8 2 0 - DCBA 79 | __m256i b1 = _mm256_shuffle_epi8(a1, s); // f d 7 5 b 9 3 1 - DCBA 80 | 81 | __m256i c0 = _mm256_unpacklo_epi32(b0, b1); // 7 6 5 4 3 2 1 0 - DCBA 82 | __m256i c1 = _mm256_unpackhi_epi32(b0, b1); // f e d c 7 6 5 4 - DCBA 83 | 84 | __m256i *q = reinterpret_cast<__m256i *>(p); 85 | _mm256_storeu_si256(q, c0); 86 | _mm256_storeu_si256(q + 1, c1); 87 | } 88 | 89 | template<> 90 | inline std::pair, cbc_state> block::cbc_post_decrypt(const block &c, const cbc_state &state) const { 91 | __m256i c0 = c.left.value(); // 7 3 6 2 5 1 4 0 92 | __m256i c1 = c.right.value(); 93 | 94 | uint32_t s0 = _mm256_extract_epi32(c0, 7); // 7 95 | uint32_t s1 = _mm256_extract_epi32(c1, 7); 96 | 97 | __m256i s = _mm256_set_epi32(5, 4, 3, 2, 1, 0, 6, 7); 98 | __m256i a0 = _mm256_permutevar8x32_epi32(c0, s); // 6 2 5 1 4 0 3 7 99 | __m256i a1 = _mm256_permutevar8x32_epi32(c1, s); 100 | 101 | __m256i x0 = _mm256_insert_epi32(a0, state.left, 0); // 6 2 5 1 4 0 3 s 102 | __m256i x1 = _mm256_insert_epi32(a1, state.right, 0); 103 | 104 | __m256i d0 = left.value(); // 7 3 6 2 5 1 4 0 105 | __m256i d1 = right.value(); 106 | 107 | __m256i p0 = _mm256_xor_si256(d0, x0); 108 | __m256i p1 = _mm256_xor_si256(d1, x1); 109 | 110 | return std::make_pair(block(p0, p1), cbc_state(s0, s1)); 111 | } 112 | 113 | 114 | template<> 115 | inline x86::ymm rot<8, x86::ymm>(const x86::ymm &v) { 116 | __m256i s = _mm256_set_epi8( 117 | 14, 13, 12, 15, 10, 9, 8, 11, 6, 5, 4, 7, 2, 1, 0, 3, 118 | 14, 13, 12, 15, 10, 9, 8, 11, 6, 5, 4, 7, 2, 1, 0, 3 119 | ); 120 | return _mm256_shuffle_epi8(v.value(), s); 121 | } 122 | 123 | template<> 124 | inline x86::ymm rot<16, x86::ymm>(const x86::ymm &v) { 125 | __m256i s = _mm256_set_epi8( 126 | 13, 12, 15, 14, 9, 8, 11, 10, 5, 4, 7, 6, 1, 0, 3, 2, 127 | 13, 12, 15, 14, 9, 8, 11, 10, 5, 4, 7, 6, 1, 0, 3, 2 128 | ); 129 | return _mm256_shuffle_epi8(v.value(), s); 130 | } 131 | 132 | template<> 133 | inline x86::ymm rot1_add_dec(const x86::ymm &v) { 134 | __m256i d = _mm256_cmpgt_epi32(v.value(), _mm256_set1_epi32(-1)); 135 | return v + v + v + x86::ymm(d); 136 | } 137 | 138 | } 139 | 140 | #endif /* __AVX2__ */ 141 | -------------------------------------------------------------------------------- /aribb25/multi2_simd.h: -------------------------------------------------------------------------------- 1 | #ifndef MULTI2_SIMD_H 2 | #define MULTI2_SIMD_H 3 | 4 | #include 5 | #include 6 | #ifdef _MSC_VER 7 | #include 8 | #else 9 | #include 10 | #endif 11 | 12 | #include "portable.h" 13 | #include "simd_instruction_type.h" 14 | 15 | #define USE_MULTI2_INTRINSIC // use intrinsic functions 16 | // #define ENABLE_MULTI2_SIMD // enable SIMD instructions 17 | 18 | #ifdef ENABLE_MULTI2_SIMD 19 | 20 | #define ENABLE_MULTI2_SSE2 // enable SSE2 instructions 21 | #define ENABLE_MULTI2_SSSE3 // enable SSSE3 instructions 22 | 23 | #ifdef ENABLE_MULTI2_SSSE3 24 | #define ENABLE_MULTI2_AVX2 // enable AVX2 instructions 25 | #endif 26 | 27 | //#define USE_MULTI2_SIMD_ICC // use Intel C++ Compiler 28 | 29 | #endif // ENABLE_MULTI2_SIMD 30 | 31 | 32 | #ifdef ENABLE_MULTI2_AVX2 33 | 34 | typedef union { 35 | __m256i key256[8]; 36 | __m128i key[8]; 37 | } MULTI2_SIMD_WORK_KEY; 38 | 39 | #else 40 | 41 | typedef struct { 42 | __m128i key[8]; 43 | } MULTI2_SIMD_WORK_KEY; 44 | 45 | #endif 46 | 47 | typedef struct { 48 | union { 49 | //#if !defined(USE_MULTI2_INTRINSIC) || !defined(_M_X64) 50 | #if defined(_M_X64) || !defined(USE_MULTI2_INTRINSIC) || !defined(_M_X64) 51 | struct { 52 | uint32_t key1, key2, key3, key4, key5, key6, key7, key8; 53 | }; 54 | #else 55 | struct { 56 | uint32_t key2, key1, key4, key3, key6, key5, key8, key7; 57 | }; 58 | uint64_t data64[4]; 59 | #endif 60 | uint8_t data[32]; 61 | }; 62 | } MULTI2_SIMD_SYS_KEY /* system key(Sk), expanded key(Wk) 256bit */; 63 | 64 | typedef struct { 65 | union { 66 | struct { 67 | uint32_t right, left; 68 | }; 69 | uint64_t data64; 70 | uint8_t data[8]; 71 | }; 72 | } MULTI2_SIMD_DATA_KEY /* data key(Dk) 64bit */; 73 | 74 | typedef struct { 75 | 76 | MULTI2_SIMD_WORK_KEY wrk[2]; /* 0: odd, 1: even */ 77 | void (* decrypt)(uint8_t * __restrict data, const uint32_t size, 78 | const MULTI2_SIMD_SYS_KEY * __restrict work_key, 79 | const MULTI2_SIMD_WORK_KEY * __restrict packed_work_key, 80 | const MULTI2_SIMD_DATA_KEY * __restrict cbc_init); 81 | 82 | } MULTI2_SIMD_DATA /* data set for SIMD */; 83 | 84 | 85 | #ifdef __cplusplus 86 | extern "C" { 87 | #endif 88 | 89 | extern bool is_simd_enabled(); 90 | extern bool is_sse2_available(); 91 | extern bool is_ssse3_available(); 92 | extern bool is_avx2_available(); 93 | extern bool initialize_multi2_simd(enum INSTRUCTION_TYPE instruction, void* m2); 94 | 95 | extern void set_simd_instruction(enum INSTRUCTION_TYPE instruction); 96 | extern enum INSTRUCTION_TYPE get_simd_instruction(); 97 | extern enum INSTRUCTION_TYPE get_supported_simd_instruction(); 98 | 99 | extern void alloc_work_key_for_simd(MULTI2_SIMD_WORK_KEY **work_key_odd, MULTI2_SIMD_WORK_KEY **work_key_even); 100 | extern void free_work_key_for_simd(MULTI2_SIMD_WORK_KEY **work_key_odd, MULTI2_SIMD_WORK_KEY **work_key_even); 101 | extern void set_work_key_for_simd(MULTI2_SIMD_WORK_KEY *work_key, const MULTI2_SIMD_SYS_KEY *src_key); 102 | extern void set_work_key_for_avx2(MULTI2_SIMD_WORK_KEY *work_key, const MULTI2_SIMD_SYS_KEY *src_key); 103 | extern void set_round_for_simd(const uint32_t round); 104 | extern void set_system_key_with_bswap(MULTI2_SIMD_SYS_KEY *sys_key, const uint8_t *hex_data); 105 | extern void get_system_key_with_bswap(const MULTI2_SIMD_SYS_KEY *sys_key, uint8_t *hex_data); 106 | extern void set_data_key_with_bswap(MULTI2_SIMD_DATA_KEY *data_key, const uint8_t *hex_data); 107 | extern void get_data_key_with_bswap(const MULTI2_SIMD_DATA_KEY *data_key, uint8_t *hex_data); 108 | 109 | extern void decrypt_multi2_without_simd(uint8_t * __restrict data, const uint32_t size, 110 | const MULTI2_SIMD_SYS_KEY * __restrict work_key, 111 | const MULTI2_SIMD_WORK_KEY * __restrict packed_work_key, 112 | const MULTI2_SIMD_DATA_KEY * __restrict cbc_init); 113 | #ifdef ENABLE_MULTI2_SSE2 114 | extern void decrypt_multi2_with_sse2(uint8_t * __restrict data, const uint32_t size, 115 | const MULTI2_SIMD_SYS_KEY * __restrict work_key, 116 | const MULTI2_SIMD_WORK_KEY * __restrict packed_work_key, 117 | const MULTI2_SIMD_DATA_KEY * __restrict cbc_init); 118 | #endif 119 | #ifdef ENABLE_MULTI2_SSSE3 120 | extern void decrypt_multi2_with_ssse3(uint8_t * __restrict data, const uint32_t size, 121 | const MULTI2_SIMD_SYS_KEY * __restrict work_key, 122 | const MULTI2_SIMD_WORK_KEY * __restrict packed_work_key, 123 | const MULTI2_SIMD_DATA_KEY * __restrict cbc_init); 124 | #endif 125 | #ifdef ENABLE_MULTI2_AVX2 126 | extern void decrypt_multi2_with_avx2(uint8_t * __restrict data, const uint32_t size, 127 | const MULTI2_SIMD_SYS_KEY * __restrict work_key, 128 | const MULTI2_SIMD_WORK_KEY * __restrict packed_work_key, 129 | const MULTI2_SIMD_DATA_KEY * __restrict cbc_init); 130 | #endif 131 | 132 | #ifdef __cplusplus 133 | } 134 | #endif 135 | 136 | #endif /* MULTI2_SIMD_H */ 137 | -------------------------------------------------------------------------------- /aribb25/B25Decoder.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // B25Decoder.cpp 3 | //////////////////////////////////////////////////////////////////////////////// 4 | #include "B25Decoder.h" 5 | 6 | int B25Decoder::strip = 1; 7 | int B25Decoder::emm_proc = 0; 8 | int B25Decoder::multi2_round = 4; 9 | 10 | B25Decoder::B25Decoder() : _bcas(nullptr), _b25(nullptr), _data(nullptr) 11 | { 12 | } 13 | 14 | B25Decoder::~B25Decoder() 15 | { 16 | release(); 17 | } 18 | 19 | int B25Decoder::init() 20 | { 21 | int rc; 22 | 23 | std::lock_guard lock(_mtx); 24 | 25 | if (_b25) 26 | return -2; 27 | 28 | _bcas = create_b_cas_card(); 29 | if (!_bcas) 30 | return -3; 31 | 32 | rc = _bcas->init(_bcas); 33 | if (rc < 0) { 34 | rc = -4; 35 | goto err; 36 | } 37 | 38 | _b25 = create_arib_std_b25(); 39 | if (!_b25) { 40 | rc = -5; 41 | goto err; 42 | } 43 | 44 | if (_b25->set_b_cas_card(_b25, _bcas) < 0) { 45 | rc = -6; 46 | goto err; 47 | } 48 | 49 | _b25->set_strip(_b25, strip); 50 | _b25->set_emm_proc(_b25, emm_proc); 51 | _b25->set_multi2_round(_b25, multi2_round); 52 | 53 | return 0; // success 54 | 55 | err: 56 | if (_b25) { 57 | _b25->release(_b25); 58 | _b25 = nullptr; 59 | } 60 | 61 | if (_bcas) { 62 | _bcas->release(_bcas); 63 | _bcas = nullptr; 64 | } 65 | 66 | _errtime = time(nullptr); 67 | return rc; // error 68 | } 69 | 70 | void B25Decoder::release() 71 | { 72 | if (_data) { 73 | ::free(_data); 74 | _data = nullptr; 75 | } 76 | 77 | std::lock_guard lock(_mtx); 78 | 79 | if (_b25) { 80 | _b25->release(_b25); 81 | _b25 = nullptr; 82 | } 83 | 84 | if (_bcas) { 85 | _bcas->release(_bcas); 86 | _bcas = nullptr; 87 | } 88 | } 89 | 90 | void B25Decoder::decode(BYTE *pSrc, DWORD dwSrcSize, BYTE **ppDst, DWORD *pdwDstSize) 91 | { 92 | if (!_b25) { 93 | time_t now = time(nullptr); 94 | if (difftime(now, _errtime) > RETRY_INTERVAL) { 95 | if (init() < 0) 96 | _errtime = now; 97 | } 98 | 99 | if (!_b25) { 100 | if (*ppDst != pSrc) { 101 | *ppDst = pSrc; 102 | *pdwDstSize = dwSrcSize; 103 | } 104 | return; 105 | } 106 | } 107 | 108 | if (_data) { 109 | ::free(_data); 110 | _data = nullptr; 111 | } 112 | 113 | ARIB_STD_B25_BUFFER buf; 114 | buf.data = pSrc; 115 | buf.size = dwSrcSize; 116 | const int rc = _b25->put(_b25, &buf); 117 | if (rc < 0) { 118 | if (rc >= ARIB_STD_B25_ERROR_NO_ECM_IN_HEAD_32M) { 119 | // pass through 120 | _b25->release(_b25); 121 | _b25 = nullptr; 122 | _bcas->release(_bcas); 123 | _bcas = nullptr; 124 | if (*ppDst != pSrc) { 125 | *ppDst = pSrc; 126 | *pdwDstSize = dwSrcSize; 127 | } 128 | } else { 129 | BYTE *p = nullptr; 130 | _b25->withdraw(_b25, &buf); // withdraw src buffer 131 | if (buf.size > 0) 132 | p = (BYTE *)::malloc(buf.size + dwSrcSize); 133 | 134 | if (p) { 135 | ::memcpy(p, buf.data, buf.size); 136 | ::memcpy(p + buf.size, pSrc, dwSrcSize); 137 | *ppDst = p; 138 | *pdwDstSize = buf.size + dwSrcSize; 139 | _data = p; 140 | } else { 141 | if (*ppDst != pSrc) { 142 | *ppDst = pSrc; 143 | *pdwDstSize = dwSrcSize; 144 | } 145 | } 146 | 147 | if (rc == ARIB_STD_B25_ERROR_ECM_PROC_FAILURE) { 148 | // pass through 149 | _b25->release(_b25); 150 | _b25 = nullptr; 151 | _bcas->release(_bcas); 152 | _bcas = nullptr; 153 | } 154 | } 155 | _errtime = time(nullptr); 156 | return; // error 157 | } 158 | _b25->get(_b25, &buf); 159 | *ppDst = buf.data; 160 | *pdwDstSize = buf.size; 161 | return; // success 162 | } 163 | 164 | int B25Decoder::set_strip(int32_t strip) 165 | { 166 | int rc = 0; 167 | if (_b25) 168 | rc = _b25->set_strip(_b25, strip); 169 | return rc; 170 | } 171 | 172 | int B25Decoder::set_emm_proc(int32_t on) 173 | { 174 | int rc = 0; 175 | if (_b25) 176 | rc = _b25->set_emm_proc(_b25, on); 177 | return rc; 178 | } 179 | 180 | int B25Decoder::set_multi2_round(int32_t round) 181 | { 182 | int rc = 0; 183 | if (_b25) 184 | rc = _b25->set_multi2_round(_b25, round); 185 | return rc; 186 | } 187 | 188 | int B25Decoder::set_unit_size(int size) 189 | { 190 | int rc = 0; 191 | if (_b25) 192 | rc = _b25->set_unit_size(_b25, size); 193 | return rc; 194 | } 195 | 196 | int B25Decoder::reset() 197 | { 198 | int rc = 0; 199 | if (_b25) 200 | rc = _b25->reset(_b25); 201 | return rc; 202 | } 203 | 204 | int B25Decoder::flush() 205 | { 206 | int rc = 0; 207 | if (_b25) 208 | rc = _b25->flush(_b25); 209 | return rc; 210 | } 211 | 212 | int B25Decoder::put(BYTE *pSrc, DWORD dwSrcSize) 213 | { 214 | ARIB_STD_B25_BUFFER buf; 215 | buf.data = pSrc; 216 | buf.size = dwSrcSize; 217 | return _b25->put(_b25, &buf); 218 | } 219 | 220 | int B25Decoder::get(BYTE **ppDst, DWORD *pdwDstSize) 221 | { 222 | ARIB_STD_B25_BUFFER buf; 223 | int rc = _b25->get(_b25, &buf); 224 | *ppDst = buf.data; 225 | *pdwDstSize = buf.size; 226 | return rc; 227 | } 228 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: Build 2 | on: push 3 | 4 | jobs: 5 | ubuntu: 6 | name: Ubuntu 7 | strategy: 8 | matrix: 9 | os: 10 | - ubuntu-20.04 11 | - ubuntu-22.04 12 | cc: [gcc, clang] 13 | include: 14 | - cc: gcc 15 | cxx: g++ 16 | - cc: clang 17 | cxx: clang++ 18 | runs-on: ${{ matrix.os }} 19 | env: 20 | CLICOLOR_FORCE: 1 21 | steps: 22 | - uses: actions/checkout@v4 23 | - name: setup 24 | run: sudo apt-get install -y build-essential clang cmake cmake-data libpcsclite-dev 25 | - name: configure 26 | run: | 27 | cmake --version 28 | cmake -B build -DCMAKE_C_COMPILER=${{ matrix.cc }} -DCMAKE_CXX_COMPILER=${{ matrix.cxx }} 29 | - name: build 30 | run: cmake --build build 31 | - name: test 32 | run: | 33 | ./build/b1 2>&1 | grep --color=always "ARIB STD-B1" 34 | ./build/b25 2>&1 | grep --color=always "ARIB STD-B25" 35 | ./build/arib-b1-stream-test --help 2>&1 | grep --color=always "ARIB STD-B1" 36 | ./build/arib-b25-stream-test --help 2>&1 | grep --color=always "ARIB STD-B25" 37 | 38 | arm: 39 | name: ARM 40 | strategy: 41 | matrix: 42 | image: 43 | - arm64v8/ubuntu 44 | - arm64v8/debian 45 | runs-on: ubuntu-latest 46 | steps: 47 | - uses: actions/checkout@v4 48 | - uses: docker/setup-qemu-action@v3 49 | - uses: docker/setup-buildx-action@v3 50 | - name: setup 51 | uses: docker/build-push-action@v5 52 | with: 53 | context: .github/workflows/ 54 | tags: ${{ matrix.image }}:build 55 | build-args: IMAGE=${{ matrix.image }} 56 | cache-from: type=gha,scope=${{ matrix.image }} 57 | cache-to: type=gha,scope=${{ matrix.image }},mode=max 58 | load: true 59 | - name: configure 60 | run: | 61 | mkdir build 62 | docker run --rm -i -v $(pwd):/work -w /work/build -e CLICOLOR_FORCE=1 ${{ matrix.image }}:build bash -c 'cmake --version && cmake ..' 63 | - name: build 64 | run: docker run --rm -i -v $(pwd):/work -w /work/build -e CLICOLOR_FORCE=1 ${{ matrix.image }}:build cmake --build . 65 | - name: test 66 | run: | 67 | docker run --rm -i -v $(pwd):/work -w /work/build -e CLICOLOR_FORCE=1 ${{ matrix.image }}:build bash -c './b1 2>&1 | grep --color=always "ARIB STD-B1"' 68 | docker run --rm -i -v $(pwd):/work -w /work/build -e CLICOLOR_FORCE=1 ${{ matrix.image }}:build bash -c './b25 2>&1 | grep --color=always "ARIB STD-B25"' 69 | docker run --rm -i -v $(pwd):/work -w /work/build -e CLICOLOR_FORCE=1 ${{ matrix.image }}:build bash -c './arib-b1-stream-test --help 2>&1 | grep --color=always "ARIB STD-B1"' 70 | docker run --rm -i -v $(pwd):/work -w /work/build -e CLICOLOR_FORCE=1 ${{ matrix.image }}:build bash -c './arib-b25-stream-test --help 2>&1 | grep --color=always "ARIB STD-B25"' 71 | 72 | macos: 73 | name: macOS 74 | strategy: 75 | matrix: 76 | os: 77 | - macos-12 78 | - macos-13 79 | runs-on: ${{ matrix.os }} 80 | env: 81 | CLICOLOR_FORCE: 1 82 | steps: 83 | - uses: actions/checkout@v4 84 | - name: configure 85 | run: | 86 | cmake --version 87 | cmake -B build 88 | - name: build 89 | run: cmake --build build 90 | - name: test 91 | run: | 92 | ./build/b1 2>&1 | grep --color=always "ARIB STD-B1" 93 | ./build/b25 2>&1 | grep --color=always "ARIB STD-B25" 94 | ./build/arib-b1-stream-test --help 2>&1 | grep --color=always "ARIB STD-B1" 95 | ./build/arib-b25-stream-test --help 2>&1 | grep --color=always "ARIB STD-B25" 96 | 97 | windows: 98 | name: Windows 99 | strategy: 100 | matrix: 101 | os: 102 | - windows-2019 103 | - windows-2022 104 | runs-on: ${{ matrix.os }} 105 | steps: 106 | - name: setup msbuild 107 | uses: microsoft/setup-msbuild@v2 108 | - uses: actions/checkout@v4 109 | - name: build 110 | run: | 111 | msbuild arib_std_b25.sln /t:Build /p:Configuration=Release /p:Platform=Win32 /p:PlatformToolset=v142 112 | msbuild arib_std_b25.sln /t:Build /p:Configuration=Release /p:Platform=x64 /p:PlatformToolset=v142 113 | - name: test 114 | run: | 115 | Win32\Release\b1.exe 2>&1 | findstr "ARIB STD-B1" 116 | x64\Release\b1.exe 2>&1 | findstr "ARIB STD-B1" 117 | Win32\Release\b25.exe 2>&1 | findstr "ARIB STD-B25" 118 | x64\Release\b25.exe 2>&1 | findstr "ARIB STD-B25" 119 | Win32\Release\arib-b1-stream-test.exe --help 2>&1 | findstr "ARIB STD-B1" 120 | x64\Release\arib-b1-stream-test.exe --help 2>&1 | findstr "ARIB STD-B1" 121 | Win32\Release\arib-b25-stream-test.exe --help 2>&1 | findstr "ARIB STD-B25" 122 | x64\Release\arib-b25-stream-test.exe --help 2>&1 | findstr "ARIB STD-B25" 123 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.sln.docstates 8 | 9 | # User-specific directories 10 | /.vs/ 11 | 12 | # Build results 13 | [Dd]ebug/ 14 | [Dd]ebugPublic/ 15 | [Rr]elease/ 16 | Win32/ 17 | x64/ 18 | # armeabi/ 19 | # armeabi-v7a/ 20 | # arm64-v8a/ 21 | # x86/ 22 | # x86_64/ 23 | build/ 24 | bld/ 25 | [Bb]in/ 26 | [Oo]bj/ 27 | 28 | # Roslyn cache directories 29 | *.ide/ 30 | 31 | # MSTest test Results 32 | [Tt]est[Rr]esult*/ 33 | [Bb]uild[Ll]og.* 34 | 35 | #NUNIT 36 | *.VisualState.xml 37 | TestResult.xml 38 | 39 | # Build Results of an ATL Project 40 | [Dd]ebugPS/ 41 | [Rr]eleasePS/ 42 | dlldata.c 43 | 44 | *_i.c 45 | *_p.c 46 | *_i.h 47 | *.ilk 48 | *.meta 49 | *.obj 50 | *.pch 51 | *.pdb 52 | *.pgc 53 | *.pgd 54 | *.rsp 55 | *.sbr 56 | *.tlb 57 | *.tli 58 | *.tlh 59 | *.tmp 60 | *.tmp_proj 61 | *.log 62 | *.vspscc 63 | *.vssscc 64 | .builds 65 | *.pidb 66 | *.svclog 67 | *.scc 68 | 69 | *.a 70 | *.so 71 | 72 | *.ii 73 | *.bc 74 | #*.s 75 | 76 | # Chutzpah Test files 77 | _Chutzpah* 78 | 79 | # Visual C++ cache files 80 | ipch/ 81 | *.aps 82 | *.ncb 83 | *.opensdf 84 | *.sdf 85 | *.cachefile 86 | 87 | # Visual Studio profiler 88 | *.psess 89 | *.vsp 90 | *.vspx 91 | 92 | # TFS 2012 Local Workspace 93 | $tf/ 94 | 95 | # Guidance Automation Toolkit 96 | *.gpState 97 | 98 | # ReSharper is a .NET coding add-in 99 | _ReSharper*/ 100 | *.[Rr]e[Ss]harper 101 | *.DotSettings.user 102 | 103 | # JustCode is a .NET coding addin-in 104 | .JustCode 105 | 106 | # TeamCity is a build add-in 107 | _TeamCity* 108 | 109 | # DotCover is a Code Coverage Tool 110 | *.dotCover 111 | 112 | # NCrunch 113 | _NCrunch_* 114 | .*crunch*.local.xml 115 | 116 | # MightyMoose 117 | *.mm.* 118 | AutoTest.Net/ 119 | 120 | # Web workbench (sass) 121 | .sass-cache/ 122 | 123 | # Installshield output folder 124 | [Ee]xpress/ 125 | 126 | # DocProject is a documentation generator add-in 127 | DocProject/buildhelp/ 128 | DocProject/Help/*.HxT 129 | DocProject/Help/*.HxC 130 | DocProject/Help/*.hhc 131 | DocProject/Help/*.hhk 132 | DocProject/Help/*.hhp 133 | DocProject/Help/Html2 134 | DocProject/Help/html 135 | 136 | # Click-Once directory 137 | publish/ 138 | 139 | # Publish Web Output 140 | *.[Pp]ublish.xml 141 | *.azurePubxml 142 | ## TODO: Comment the next line if you want to checkin your 143 | ## web deploy settings but do note that will include unencrypted 144 | ## passwords 145 | #*.pubxml 146 | 147 | # NuGet Packages Directory 148 | packages/* 149 | ## TODO: If the tool you use requires repositories.config 150 | ## uncomment the next line 151 | #!packages/repositories.config 152 | 153 | # Enable "build/" folder in the NuGet Packages folder since 154 | # NuGet packages use it for MSBuild targets. 155 | # This line needs to be after the ignore of the build folder 156 | # (and the packages folder if the line above has been uncommented) 157 | !packages/build/ 158 | 159 | # Windows Azure Build Output 160 | csx/ 161 | *.build.csdef 162 | 163 | # Windows Store app package directory 164 | AppPackages/ 165 | 166 | # Others 167 | sql/ 168 | *.Cache 169 | ClientBin/ 170 | [Ss]tyle[Cc]op.* 171 | ~$* 172 | *~ 173 | *.dbmdl 174 | *.dbproj.schemaview 175 | *.pfx 176 | *.publishsettings 177 | node_modules/ 178 | 179 | # RIA/Silverlight projects 180 | Generated_Code/ 181 | 182 | # Backup & report files from converting an old project file 183 | # to a newer Visual Studio version. Backup files are not needed, 184 | # because we have git ;-) 185 | _UpgradeReport_Files/ 186 | Backup*/ 187 | UpgradeLog*.XML 188 | UpgradeLog*.htm 189 | 190 | # SQL Server files 191 | *.mdf 192 | *.ldf 193 | 194 | # Business Intelligence projects 195 | *.rdl.data 196 | *.bim.layout 197 | *.bim_*.settings 198 | 199 | # Microsoft Fakes 200 | FakesAssemblies/ 201 | 202 | # LightSwitch generated files 203 | GeneratedArtifacts/ 204 | _Pvt_Extensions/ 205 | ModelManifest.xml 206 | 207 | # Xcode 208 | ## Build generated 209 | build/ 210 | DerivedData/ 211 | 212 | ## User settings 213 | xcuserdata/ 214 | 215 | # Mac 216 | ## General 217 | .DS_Store 218 | .AppleDouble 219 | .LSOverride 220 | 221 | ## Icon must end with two \r 222 | Icon 223 | 224 | ## Thumbnails 225 | ._* 226 | 227 | ## Files that might appear in the root of a volume 228 | .DocumentRevisions-V100 229 | .fseventsd 230 | .Spotlight-V100 231 | .TemporaryItems 232 | .Trashes 233 | .VolumeIcon.icns 234 | .com.apple.timemachine.donotpresent 235 | 236 | ## Directories potentially created on remote AFP share 237 | .AppleDB 238 | .AppleDesktop 239 | Network Trash Folder 240 | Temporary Items 241 | .apdisk 242 | 243 | # CMake 244 | CMakeLists.txt.user 245 | CMakeCache.txt 246 | CMakeFiles 247 | CMakeScripts 248 | cmake_install.cmake 249 | Makefile 250 | Makefile.dep 251 | config.h 252 | b1 253 | b25 254 | libaribb1.so* 255 | libaribb25.so* 256 | version_b1.rc 257 | version_b25.rc 258 | *.o 259 | *.pc 260 | -------------------------------------------------------------------------------- /arib_std_b25.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.31702.278 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "arib-b1-stream-test", "aribb25\arib-b1-stream-test.vcxproj", "{DE5EB7E1-56B9-440C-B3C6-5014E94FBC62}" 7 | EndProject 8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "b1", "aribb25\b1.vcxproj", "{26304970-9A5E-4DF0-AF69-8E01B9DEDDAE}" 9 | EndProject 10 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libaribb1", "aribb25\libaribb1.vcxproj", "{92B17263-5DE9-49F5-8B3C-7A89F7561ED5}" 11 | EndProject 12 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "arib-b25-stream-test", "aribb25\arib-b25-stream-test.vcxproj", "{06BCA6CD-77A7-441B-BEEA-63A6561D6CDE}" 13 | EndProject 14 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "b25", "aribb25\b25.vcxproj", "{6E77C1AC-A31A-49B9-9A52-9FE1E03B8FEC}" 15 | EndProject 16 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libaribb25", "aribb25\libaribb25.vcxproj", "{32FCD075-2C1D-4796-926B-A0009ECCD1E8}" 17 | EndProject 18 | Global 19 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 20 | Debug|Win32 = Debug|Win32 21 | Debug|x64 = Debug|x64 22 | Release|Win32 = Release|Win32 23 | Release|x64 = Release|x64 24 | EndGlobalSection 25 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 26 | {6E77C1AC-A31A-49B9-9A52-9FE1E03B8FEC}.Debug|Win32.ActiveCfg = Debug|Win32 27 | {6E77C1AC-A31A-49B9-9A52-9FE1E03B8FEC}.Debug|Win32.Build.0 = Debug|Win32 28 | {6E77C1AC-A31A-49B9-9A52-9FE1E03B8FEC}.Debug|x64.ActiveCfg = Debug|x64 29 | {6E77C1AC-A31A-49B9-9A52-9FE1E03B8FEC}.Debug|x64.Build.0 = Debug|x64 30 | {6E77C1AC-A31A-49B9-9A52-9FE1E03B8FEC}.Release|Win32.ActiveCfg = Release|Win32 31 | {6E77C1AC-A31A-49B9-9A52-9FE1E03B8FEC}.Release|Win32.Build.0 = Release|Win32 32 | {6E77C1AC-A31A-49B9-9A52-9FE1E03B8FEC}.Release|x64.ActiveCfg = Release|x64 33 | {6E77C1AC-A31A-49B9-9A52-9FE1E03B8FEC}.Release|x64.Build.0 = Release|x64 34 | {32FCD075-2C1D-4796-926B-A0009ECCD1E8}.Debug|Win32.ActiveCfg = Debug|Win32 35 | {32FCD075-2C1D-4796-926B-A0009ECCD1E8}.Debug|Win32.Build.0 = Debug|Win32 36 | {32FCD075-2C1D-4796-926B-A0009ECCD1E8}.Debug|x64.ActiveCfg = Debug|x64 37 | {32FCD075-2C1D-4796-926B-A0009ECCD1E8}.Debug|x64.Build.0 = Debug|x64 38 | {32FCD075-2C1D-4796-926B-A0009ECCD1E8}.Release|Win32.ActiveCfg = Release|Win32 39 | {32FCD075-2C1D-4796-926B-A0009ECCD1E8}.Release|Win32.Build.0 = Release|Win32 40 | {32FCD075-2C1D-4796-926B-A0009ECCD1E8}.Release|x64.ActiveCfg = Release|x64 41 | {32FCD075-2C1D-4796-926B-A0009ECCD1E8}.Release|x64.Build.0 = Release|x64 42 | {26304970-9A5E-4DF0-AF69-8E01B9DEDDAE}.Debug|Win32.ActiveCfg = Debug|Win32 43 | {26304970-9A5E-4DF0-AF69-8E01B9DEDDAE}.Debug|Win32.Build.0 = Debug|Win32 44 | {26304970-9A5E-4DF0-AF69-8E01B9DEDDAE}.Debug|x64.ActiveCfg = Debug|x64 45 | {26304970-9A5E-4DF0-AF69-8E01B9DEDDAE}.Debug|x64.Build.0 = Debug|x64 46 | {26304970-9A5E-4DF0-AF69-8E01B9DEDDAE}.Release|Win32.ActiveCfg = Release|Win32 47 | {26304970-9A5E-4DF0-AF69-8E01B9DEDDAE}.Release|Win32.Build.0 = Release|Win32 48 | {26304970-9A5E-4DF0-AF69-8E01B9DEDDAE}.Release|x64.ActiveCfg = Release|x64 49 | {26304970-9A5E-4DF0-AF69-8E01B9DEDDAE}.Release|x64.Build.0 = Release|x64 50 | {92B17263-5DE9-49F5-8B3C-7A89F7561ED5}.Debug|Win32.ActiveCfg = Debug|Win32 51 | {92B17263-5DE9-49F5-8B3C-7A89F7561ED5}.Debug|Win32.Build.0 = Debug|Win32 52 | {92B17263-5DE9-49F5-8B3C-7A89F7561ED5}.Debug|x64.ActiveCfg = Debug|x64 53 | {92B17263-5DE9-49F5-8B3C-7A89F7561ED5}.Debug|x64.Build.0 = Debug|x64 54 | {92B17263-5DE9-49F5-8B3C-7A89F7561ED5}.Release|Win32.ActiveCfg = Release|Win32 55 | {92B17263-5DE9-49F5-8B3C-7A89F7561ED5}.Release|Win32.Build.0 = Release|Win32 56 | {92B17263-5DE9-49F5-8B3C-7A89F7561ED5}.Release|x64.ActiveCfg = Release|x64 57 | {92B17263-5DE9-49F5-8B3C-7A89F7561ED5}.Release|x64.Build.0 = Release|x64 58 | {DE5EB7E1-56B9-440C-B3C6-5014E94FBC62}.Debug|Win32.ActiveCfg = Debug|Win32 59 | {DE5EB7E1-56B9-440C-B3C6-5014E94FBC62}.Debug|Win32.Build.0 = Debug|Win32 60 | {DE5EB7E1-56B9-440C-B3C6-5014E94FBC62}.Debug|x64.ActiveCfg = Debug|x64 61 | {DE5EB7E1-56B9-440C-B3C6-5014E94FBC62}.Debug|x64.Build.0 = Debug|x64 62 | {DE5EB7E1-56B9-440C-B3C6-5014E94FBC62}.Release|Win32.ActiveCfg = Release|Win32 63 | {DE5EB7E1-56B9-440C-B3C6-5014E94FBC62}.Release|Win32.Build.0 = Release|Win32 64 | {DE5EB7E1-56B9-440C-B3C6-5014E94FBC62}.Release|x64.ActiveCfg = Release|x64 65 | {DE5EB7E1-56B9-440C-B3C6-5014E94FBC62}.Release|x64.Build.0 = Release|x64 66 | {06BCA6CD-77A7-441B-BEEA-63A6561D6CDE}.Debug|Win32.ActiveCfg = Debug|Win32 67 | {06BCA6CD-77A7-441B-BEEA-63A6561D6CDE}.Debug|Win32.Build.0 = Debug|Win32 68 | {06BCA6CD-77A7-441B-BEEA-63A6561D6CDE}.Debug|x64.ActiveCfg = Debug|x64 69 | {06BCA6CD-77A7-441B-BEEA-63A6561D6CDE}.Debug|x64.Build.0 = Debug|x64 70 | {06BCA6CD-77A7-441B-BEEA-63A6561D6CDE}.Release|Win32.ActiveCfg = Release|Win32 71 | {06BCA6CD-77A7-441B-BEEA-63A6561D6CDE}.Release|Win32.Build.0 = Release|Win32 72 | {06BCA6CD-77A7-441B-BEEA-63A6561D6CDE}.Release|x64.ActiveCfg = Release|x64 73 | {06BCA6CD-77A7-441B-BEEA-63A6561D6CDE}.Release|x64.Build.0 = Release|x64 74 | EndGlobalSection 75 | GlobalSection(SolutionProperties) = preSolution 76 | HideSolutionNode = FALSE 77 | EndGlobalSection 78 | GlobalSection(ExtensibilityGlobals) = postSolution 79 | SolutionGuid = {0F37AEF8-7E0B-410F-8933-3AB6C5A8B836} 80 | EndGlobalSection 81 | EndGlobal 82 | -------------------------------------------------------------------------------- /aribb25/multi2_cipher.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "portable.h" 6 | 7 | #include "multi2_block.h" 8 | #include "multi2_ymm2.h" 9 | #include "multi2_ymm.h" 10 | #include "multi2_xmm.h" 11 | #include "multi2_neon2.h" 12 | #include "multi2_neon.h" 13 | 14 | #if defined(__GNUC__) || defined(__clang__) 15 | # define MULTI2_ALWAYS_INLINE __attribute__((always_inline)) 16 | # define MULTI2_LIKELY(x) __builtin_expect(!!(x), 1) 17 | #else 18 | # define MULTI2_ALWAYS_INLINE 19 | # define MULTI2_LIKELY(x) (x) 20 | #endif 21 | 22 | namespace multi2 { 23 | 24 | typedef array system_key_type; 25 | typedef array iv_type; 26 | typedef array data_key_type; 27 | typedef array work_key_type; 28 | 29 | template 30 | struct pi { 31 | typedef block block_type; 32 | 33 | static inline block_type pi1(const block_type &p) { 34 | return block_type(p.left, p.right ^ p.left); 35 | } 36 | 37 | static inline block_type pi2(const block_type &p, uint32_t k1) { 38 | T x = p.right; 39 | T y = x + T(k1); 40 | T z = rot1_add_dec(y); 41 | return block_type(p.left ^ rot<4>(z) ^ z, p.right); 42 | } 43 | 44 | static inline block_type pi3(const block_type &p, uint32_t k2, uint32_t k3) { 45 | T x = p.left; 46 | T y = x + T(k2); 47 | T z = rot<2>(y) + y + T(1); 48 | T a = rot<8>(z) ^ z; 49 | T b = a + T(k3); 50 | T c = rot1_sub(b); 51 | return block_type(p.left, p.right ^ rot<16>(c) ^ (c | x)); 52 | } 53 | 54 | static inline block_type pi4(const block_type &p, uint32_t k4) { 55 | T x = p.right; 56 | T y = x + T(k4); 57 | return block_type(p.left ^ (rot<2>(y) + y + T(1)), p.right); 58 | } 59 | }; 60 | 61 | template 62 | struct cipher { 63 | typedef block block_type; 64 | typedef pi p; 65 | 66 | static inline block_type encrypt(const block_type &b, const work_key_type &wk, int n) { 67 | block_type t = b; 68 | 69 | for (int i = 0; i < n; ++i) { 70 | t = p::pi1(t); 71 | t = p::pi2(t, wk[0]); 72 | t = p::pi3(t, wk[1], wk[2]); 73 | t = p::pi4(t, wk[3]); 74 | t = p::pi1(t); 75 | t = p::pi2(t, wk[4]); 76 | t = p::pi3(t, wk[5], wk[6]); 77 | t = p::pi4(t, wk[7]); 78 | } 79 | return t; 80 | } 81 | 82 | static inline block_type decrypt(const block_type &b, const work_key_type &wk, int n) { 83 | block_type t = b; 84 | 85 | for (int i = 0; i < n; ++i) { 86 | t = p::pi4(t, wk[7]); 87 | t = p::pi3(t, wk[5], wk[6]); 88 | t = p::pi2(t, wk[4]); 89 | t = p::pi1(t); 90 | t = p::pi4(t, wk[3]); 91 | t = p::pi3(t, wk[1], wk[2]); 92 | t = p::pi2(t, wk[0]); 93 | t = p::pi1(t); 94 | } 95 | return t; 96 | } 97 | }; 98 | 99 | 100 | inline work_key_type schedule(const data_key_type &dk, const system_key_type &sk) { 101 | typedef pi p; 102 | 103 | block a0 = p::pi1(block(dk[0], dk[1])); 104 | block a1 = p::pi2(a0, sk[0]); 105 | block a2 = p::pi3(a1, sk[1], sk[2]); 106 | block a3 = p::pi4(a2, sk[3]); 107 | block a4 = p::pi1(a3); 108 | block a5 = p::pi2(a4, sk[4]); 109 | block a6 = p::pi3(a5, sk[5], sk[6]); 110 | block a7 = p::pi4(a6, sk[7]); 111 | block a8 = p::pi1(a7); 112 | 113 | work_key_type w; 114 | w[0] = a1.left; 115 | w[1] = a2.right; 116 | w[2] = a3.left; 117 | w[3] = a4.right; 118 | w[4] = a5.left; 119 | w[5] = a6.right; 120 | w[6] = a7.left; 121 | w[7] = a8.right; 122 | 123 | return w; 124 | } 125 | 126 | inline void encrypt_cbc_ofb(uint8_t *buf, size_t n, const iv_type &iv, const work_key_type &key, int round) { 127 | 128 | cbc_state state(iv[0], iv[1]); 129 | 130 | while (block_size() <= n) { 131 | block p; 132 | p.load(buf); 133 | 134 | block c = cipher::encrypt(p ^ state, key, round); 135 | c.store(buf); 136 | 137 | state = c; 138 | buf += block_size(); 139 | n -= block_size(); 140 | } 141 | if (0 < n) { 142 | array t; 143 | memcpy(&t[0], buf, n); 144 | memset(&t[n], 0, 8 - n); 145 | 146 | block p; 147 | p.load(&t[0]); 148 | 149 | block c = p ^ cipher::encrypt(state, key, round); 150 | c.store(&t[0]); 151 | memcpy(buf, &t[0], n); 152 | } 153 | } 154 | 155 | template 156 | MULTI2_ALWAYS_INLINE 157 | static inline void decrypt_block(uint8_t *&buf, size_t &n, cbc_state &state, const work_key_type &key, int round) { 158 | block c; 159 | c.load(buf); 160 | 161 | block d = cipher::decrypt(c, key, round); 162 | std::pair, cbc_state> ps = d.cbc_post_decrypt(c, state); 163 | ps.first.store(buf); 164 | 165 | state = ps.second; 166 | buf += block_size(); 167 | n -= block_size(); 168 | } 169 | 170 | inline void decrypt_cbc_ofb(uint8_t *buf, size_t n, const iv_type &iv, const work_key_type &key, int round) { 171 | 172 | cbc_state state(iv[0], iv[1]); 173 | 174 | #if defined(__AVX2__) 175 | if (MULTI2_LIKELY(n == 184)) { 176 | decrypt_block(buf, n, state, key, round); 177 | decrypt_block(buf, n, state, key, round); 178 | return; 179 | } 180 | if (block_size() <= n) { 181 | decrypt_block(buf, n, state, key, round); 182 | } 183 | if (block_size() <= n) { 184 | decrypt_block(buf, n, state, key, round); 185 | } 186 | #if defined(__SSE2__) 187 | if (block_size() <= n) { 188 | decrypt_block(buf, n, state, key, round); 189 | } 190 | #endif 191 | 192 | #elif defined(__SSE2__) 193 | while (block_size() <= n) { 194 | decrypt_block(buf, n, state, key, round); 195 | } 196 | 197 | #elif defined(__ARM_NEON__) || defined(__ARM_NEON) 198 | if (MULTI2_LIKELY(n == 184)) { 199 | decrypt_block >(buf, n, state, key, round); 200 | decrypt_block >(buf, n, state, key, round); 201 | decrypt_block >(buf, n, state, key, round); 202 | return; 203 | } 204 | while (block_size >() <= n) { 205 | decrypt_block >(buf, n, state, key, round); 206 | } 207 | if (block_size() <= n) { 208 | decrypt_block(buf, n, state, key, round); 209 | } 210 | 211 | #endif 212 | 213 | while (block_size() <= n) { 214 | decrypt_block(buf, n, state, key, round); 215 | } 216 | if (0 < n) { 217 | array t; 218 | memcpy(&t[0], buf, n); 219 | memset(&t[n], 0, 8 - n); 220 | 221 | block c; 222 | c.load(&t[0]); 223 | 224 | block p = c ^ cipher::encrypt(state, key, round); 225 | p.store(&t[0]); 226 | memcpy(buf, &t[0], n); 227 | } 228 | } 229 | 230 | } 231 | 232 | #undef MULTI2_ALWAYS_INLINE 233 | #undef MULTI2_LIKELY 234 | -------------------------------------------------------------------------------- /aribb25/multi2_neon2.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #if defined(__ARM_NEON__) || defined(__ARM_NEON) 4 | 5 | #include 6 | #include 7 | 8 | #include "portable.h" 9 | 10 | #include "multi2_block.h" 11 | 12 | namespace multi2 { 13 | 14 | namespace arm { 15 | 16 | template 17 | class neon2 { 18 | private: 19 | uint32x4_t v0; 20 | uint32x4_t v1; 21 | 22 | public: 23 | inline neon2() { } 24 | inline neon2(uint32_t n) { v0 = v1 = vdupq_n_u32(n); } 25 | inline neon2(const uint32x4_t &r0, const uint32x4_t &r1) { 26 | v0 = r0; 27 | v1 = r1; 28 | } 29 | 30 | inline neon2 &operator=(const neon2 &other) { 31 | v0 = other.v0; 32 | v1 = other.v1; 33 | return *this; 34 | } 35 | 36 | inline neon2 operator+(const neon2 &other) const { 37 | return neon2(vaddq_u32(v0, other.v0), vaddq_u32(v1, other.v1)); 38 | } 39 | inline neon2 operator-(const neon2 &other) const { 40 | return neon2(vsubq_u32(v0, other.v0), vsubq_u32(v1, other.v1)); 41 | } 42 | inline neon2 operator^(const neon2 &other) const { 43 | return neon2(veorq_u32(v0, other.v0), veorq_u32(v1, other.v1)); 44 | } 45 | inline neon2 operator|(const neon2 &other) const { 46 | return neon2(vorrq_u32(v0, other.v0), vorrq_u32(v1, other.v1)); 47 | } 48 | 49 | inline const uint32x4_t &value0() const { return v0; } 50 | inline const uint32x4_t &value1() const { return v1; } 51 | 52 | static inline void load_block(block &b, const uint8_t *p) { 53 | size_t d = 8 - (8 - S) * 2; 54 | const uint32_t *q = reinterpret_cast(p); 55 | uint32x4x2_t a0 = vld2q_u32(q); 56 | uint32x4x2_t a1 = vld2q_u32(q + d); 57 | 58 | uint32x4_t b0 = vreinterpretq_u32_u8(vrev32q_u8(vreinterpretq_u8_u32(a0.val[0]))); 59 | uint32x4_t b1 = vreinterpretq_u32_u8(vrev32q_u8(vreinterpretq_u8_u32(a0.val[1]))); 60 | uint32x4_t b2 = vreinterpretq_u32_u8(vrev32q_u8(vreinterpretq_u8_u32(a1.val[0]))); 61 | uint32x4_t b3 = vreinterpretq_u32_u8(vrev32q_u8(vreinterpretq_u8_u32(a1.val[1]))); 62 | 63 | b.left = neon2(b0, b2); 64 | b.right = neon2(b1, b3); 65 | } 66 | 67 | static inline void store_block(uint8_t *p, const block &b) { 68 | uint32x4_t a0 = b.left.value0(); 69 | uint32x4_t a1 = b.right.value0(); 70 | uint32x4_t a2 = b.left.value1(); 71 | uint32x4_t a3 = b.right.value1(); 72 | 73 | uint32x4_t b0 = vreinterpretq_u32_u8(vrev32q_u8(vreinterpretq_u8_u32(a0))); 74 | uint32x4_t b1 = vreinterpretq_u32_u8(vrev32q_u8(vreinterpretq_u8_u32(a1))); 75 | uint32x4_t b2 = vreinterpretq_u32_u8(vrev32q_u8(vreinterpretq_u8_u32(a2))); 76 | uint32x4_t b3 = vreinterpretq_u32_u8(vrev32q_u8(vreinterpretq_u8_u32(a3))); 77 | 78 | size_t d = 8 - (8 - S) * 2; 79 | uint32_t *q = reinterpret_cast(p); 80 | uint32x4x2_t e0 = { b0, b1 }; 81 | uint32x4x2_t e1 = { b2, b3 }; 82 | vst2q_u32(q + d, e1); 83 | vst2q_u32(q, e0); 84 | } 85 | 86 | static inline std::pair, cbc_state> cbc_post_decrypt(const block &d, const block &c, const cbc_state &state) { 87 | uint32x4_t c0 = c.left.value0(); // 3 2 1 0 88 | uint32x4_t c1 = c.right.value0(); 89 | uint32x4_t c2 = c.left.value1(); // d c b a 90 | uint32x4_t c3 = c.right.value1(); 91 | 92 | uint32_t s2 = vgetq_lane_u32(c2, 3); // d 93 | uint32_t s3 = vgetq_lane_u32(c3, 3); 94 | 95 | uint32x4_t b0 = vextq_u32(c0, c0, 3); // 2 1 0 3 96 | uint32x4_t b1 = vextq_u32(c1, c1, 3); 97 | uint32x4_t b2 = vextq_u32(c0, c2, 3); // c b a 3 98 | uint32x4_t b3 = vextq_u32(c1, c3, 3); 99 | 100 | uint32x4_t x0 = vsetq_lane_u32(state.left, b0, 0); // 2 1 0 s 101 | uint32x4_t x1 = vsetq_lane_u32(state.right, b1, 0); 102 | uint32x4_t x2 = b2; // c b a 3 103 | uint32x4_t x3 = b3; 104 | 105 | uint32x4_t d0 = d.left.value0(); // 3 2 1 0 106 | uint32x4_t d1 = d.right.value0(); 107 | uint32x4_t d2 = d.left.value1(); // d c b a 108 | uint32x4_t d3 = d.right.value1(); 109 | 110 | uint32x4_t p0 = veorq_u32(d0, x0); // 3 2 1 0 111 | uint32x4_t p1 = veorq_u32(d1, x1); 112 | uint32x4_t p2 = veorq_u32(d2, x2); // d c b a? 113 | uint32x4_t p3 = veorq_u32(d3, x3); 114 | 115 | return std::make_pair(block(neon2(p0, p2), neon2(p1, p3)), cbc_state(s2, s3)); 116 | } 117 | }; 118 | 119 | } 120 | 121 | template<> 122 | inline size_t block_size >() { 123 | return 56; 124 | } 125 | 126 | template<> 127 | inline size_t block_size >() { 128 | return 64; 129 | } 130 | 131 | template<> 132 | inline void block >::load(const uint8_t *p) { 133 | arm::neon2<7>::load_block(*this, p); 134 | } 135 | 136 | template<> 137 | inline void block >::load(const uint8_t *p) { 138 | arm::neon2<8>::load_block(*this, p); 139 | } 140 | 141 | template<> 142 | inline void block >::store(uint8_t *p) const { 143 | arm::neon2<7>::store_block(p, *this); 144 | } 145 | 146 | template<> 147 | inline void block >::store(uint8_t *p) const { 148 | arm::neon2<8>::store_block(p, *this); 149 | } 150 | 151 | template<> 152 | inline std::pair >, cbc_state> block >::cbc_post_decrypt(const block > &c, const cbc_state &state) const { 153 | return arm::neon2<7>::cbc_post_decrypt(*this, c, state); 154 | } 155 | 156 | template<> 157 | inline std::pair >, cbc_state> block >::cbc_post_decrypt(const block > &c, const cbc_state &state) const { 158 | return arm::neon2<8>::cbc_post_decrypt(*this, c, state); 159 | } 160 | 161 | template 162 | inline arm::neon2 rot(const arm::neon2 &v) { 163 | uint32x4_t a0 = v.value0(); 164 | uint32x4_t a1 = v.value1(); 165 | if (N == 16) { 166 | uint32x4_t b0 = vreinterpretq_u32_u16(vrev32q_u16(vreinterpretq_u16_u32(a0))); 167 | uint32x4_t b1 = vreinterpretq_u32_u16(vrev32q_u16(vreinterpretq_u16_u32(a1))); 168 | return arm::neon2(b0, b1); 169 | } else { 170 | uint32x4_t b0 = vshrq_n_u32(a0, 32 - N); 171 | uint32x4_t b1 = vshrq_n_u32(a1, 32 - N); 172 | 173 | uint32x4_t c0 = vsliq_n_u32(b0, a0, N); 174 | uint32x4_t c1 = vsliq_n_u32(b1, a1, N); 175 | return arm::neon2(c0, c1); 176 | } 177 | } 178 | 179 | template 180 | inline arm::neon2 rot1_sub(const arm::neon2 &v) { 181 | uint32x4_t a0 = v.value0(); 182 | uint32x4_t a1 = v.value1(); 183 | 184 | uint32x4_t b0 = vsraq_n_u32(a0, a0, 31); 185 | uint32x4_t b1 = vsraq_n_u32(a1, a1, 31); 186 | return arm::neon2(b0, b1); 187 | } 188 | 189 | template 190 | inline arm::neon2 rot1_add_dec(const arm::neon2 &v) { 191 | uint32x4_t a0 = v.value0(); 192 | uint32x4_t a1 = v.value1(); 193 | 194 | uint32x4_t d0 = vcgeq_s32(vreinterpretq_s32_u32(a0), vdupq_n_s32(0)); 195 | uint32x4_t d1 = vcgeq_s32(vreinterpretq_s32_u32(a1), vdupq_n_s32(0)); 196 | return v + v + v + arm::neon2(d0, d1); 197 | } 198 | 199 | } 200 | 201 | #endif /* __ARM_NEON__ || __ARM_NEON */ 202 | -------------------------------------------------------------------------------- /aribb25/multi2_xmm.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #if defined(__SSE2__) 4 | 5 | #include 6 | 7 | #if defined(_WIN32) 8 | # include 9 | #else 10 | # include 11 | #endif 12 | 13 | #include "portable.h" 14 | 15 | #include "multi2_block.h" 16 | 17 | namespace multi2 { 18 | 19 | namespace x86 { 20 | 21 | class xmm { 22 | private: 23 | __m128i v; 24 | 25 | public: 26 | inline xmm() { 27 | #if !defined(NO_MM_UNDEFINED) 28 | v = _mm_undefined_si128(); 29 | #endif 30 | } 31 | inline xmm(uint32_t n) { v = _mm_set1_epi32(n); } 32 | inline xmm(const __m128i &r) { v = r; } 33 | 34 | inline xmm &operator=(const xmm &other) { 35 | v = other.v; 36 | return *this; 37 | } 38 | 39 | inline xmm operator+(const xmm &other) const { return _mm_add_epi32(v, other.v); } 40 | inline xmm operator-(const xmm &other) const { return _mm_sub_epi32(v, other.v); } 41 | inline xmm operator^(const xmm &other) const { return _mm_xor_si128(v, other.v); } 42 | inline xmm operator|(const xmm &other) const { return _mm_or_si128(v, other.v); } 43 | inline xmm operator<<(int n) const { return _mm_slli_epi32(v, n); } 44 | inline xmm operator>>(int n) const { return _mm_srli_epi32(v, n); } 45 | 46 | inline const __m128i &value() const { return v; } 47 | }; 48 | 49 | } 50 | 51 | #if defined(__SSSE3__) 52 | 53 | template<> 54 | inline void block::load(const uint8_t *p) { 55 | const __m128i *q = reinterpret_cast(p); 56 | 57 | __m128i a0 = _mm_loadu_si128(q); // 3 2 1 0 - DCBA 58 | __m128i a1 = _mm_loadu_si128(q + 1); // 7 6 5 4 - DCBA 59 | 60 | __m128i s = _mm_set_epi8(12, 13, 14, 15, 4, 5, 6, 7, 8, 9, 10, 11, 0, 1, 2, 3); 61 | __m128i b0 = _mm_shuffle_epi8(a0, s); // 3 1 2 0 - ABCD 62 | __m128i b1 = _mm_shuffle_epi8(a1, s); // 7 5 6 4 - ABCD 63 | 64 | left = _mm_unpacklo_epi32(b0, b1); // 6 2 4 0 - ABCD 65 | right = _mm_unpackhi_epi32(b0, b1); // 7 3 5 1 - ABCD 66 | } 67 | 68 | template<> 69 | inline void block::store(uint8_t *p) const { 70 | __m128i a0 = left.value(); // 6 2 4 0 - ABCD 71 | __m128i a1 = right.value(); // 7 3 5 1 - ABCD 72 | 73 | __m128i s = _mm_set_epi8(12, 13, 14, 15, 4, 5, 6, 7, 8, 9, 10, 11, 0, 1, 2, 3); 74 | __m128i b0 = _mm_shuffle_epi8(a0, s); // 6 4 2 0 - DCBA 75 | __m128i b1 = _mm_shuffle_epi8(a1, s); // 7 5 3 1 - DCBA 76 | 77 | __m128i c0 = _mm_unpacklo_epi32(b0, b1); // 3 2 1 0 - DCBA 78 | __m128i c1 = _mm_unpackhi_epi32(b0, b1); // 7 6 5 4 - DCBA 79 | 80 | __m128i *q = reinterpret_cast<__m128i *>(p); 81 | _mm_storeu_si128(q, c0); 82 | _mm_storeu_si128(q + 1, c1); 83 | } 84 | 85 | template<> 86 | inline x86::xmm rot<8, x86::xmm>(const x86::xmm &v) { 87 | __m128i s = _mm_set_epi8(14, 13, 12, 15, 10, 9, 8, 11, 6, 5, 4, 7, 2, 1, 0, 3); 88 | return _mm_shuffle_epi8(v.value(), s); 89 | } 90 | 91 | template<> 92 | inline x86::xmm rot<16, x86::xmm>(const x86::xmm &v) { 93 | __m128i s = _mm_set_epi8(13, 12, 15, 14, 9, 8, 11, 10, 5, 4, 7, 6, 1, 0, 3, 2); 94 | return _mm_shuffle_epi8(v.value(), s); 95 | } 96 | 97 | #else /* __SSSE3__ */ 98 | 99 | template<> 100 | inline void block::load(const uint8_t *p) { 101 | const __m128i *q = reinterpret_cast(p); 102 | 103 | __m128i a0 = _mm_loadu_si128(q); // 3 2 1 0 104 | __m128i a1 = _mm_loadu_si128(q + 1); // 7 6 5 4 105 | 106 | __m128i b0 = _mm_unpacklo_epi32(a0, a1); // 5 1 4 0 107 | __m128i b1 = _mm_unpackhi_epi32(a0, a1); // 7 3 6 2 108 | 109 | __m128i c0 = _mm_unpacklo_epi32(b0, b1); // 6 4 2 0 - DCBA 110 | __m128i c1 = _mm_unpackhi_epi32(b0, b1); // 7 5 3 1 - DCBA 111 | 112 | __m128i d0 = _mm_shufflehi_epi16(_mm_shufflelo_epi16(c0, _MM_SHUFFLE(2, 3, 0, 1)), _MM_SHUFFLE(2, 3, 0, 1)); // BADC 113 | __m128i d1 = _mm_shufflehi_epi16(_mm_shufflelo_epi16(c1, _MM_SHUFFLE(2, 3, 0, 1)), _MM_SHUFFLE(2, 3, 0, 1)); // BADC 114 | 115 | left = _mm_or_si128(_mm_srli_epi16(d0, 8), _mm_slli_epi16(d0, 8)); // ABCD 116 | right = _mm_or_si128(_mm_srli_epi16(d1, 8), _mm_slli_epi16(d1, 8)); // ABCD 117 | } 118 | 119 | template<> 120 | inline void block::store(uint8_t *p) const { 121 | __m128i a0 = left.value(); // ABCD 122 | __m128i a1 = right.value(); // ABCD 123 | 124 | __m128i b0 = _mm_or_si128(_mm_srli_epi16(a0, 8), _mm_slli_epi16(a0, 8)); // BADC 125 | __m128i b1 = _mm_or_si128(_mm_srli_epi16(a1, 8), _mm_slli_epi16(a1, 8)); // BADC 126 | 127 | __m128i c0 = _mm_shufflehi_epi16(_mm_shufflelo_epi16(b0, _MM_SHUFFLE(2, 3, 0, 1)), _MM_SHUFFLE(2, 3, 0, 1)); // 6 4 2 0 - DCBA 128 | __m128i c1 = _mm_shufflehi_epi16(_mm_shufflelo_epi16(b1, _MM_SHUFFLE(2, 3, 0, 1)), _MM_SHUFFLE(2, 3, 0, 1)); // 7 5 3 1 - DCBA 129 | 130 | __m128i d0 = _mm_unpacklo_epi32(c0, c1); // 3 2 1 0 131 | __m128i d1 = _mm_unpackhi_epi32(c0, c1); // 7 6 5 4 132 | 133 | __m128i *q = reinterpret_cast<__m128i *>(p); 134 | _mm_storeu_si128(q, d0); 135 | _mm_storeu_si128(q + 1, d1); 136 | } 137 | 138 | #endif /* __SSSE3__ */ 139 | 140 | #if defined(__SSE4_1__) 141 | 142 | template<> 143 | inline std::pair, cbc_state> block::cbc_post_decrypt(const block &c, const cbc_state &state) const { 144 | __m128i c0 = c.left.value(); // 3 1 2 0 145 | __m128i c1 = c.right.value(); 146 | 147 | uint32_t s0 = _mm_extract_epi32(c0, 3); // 3 148 | uint32_t s1 = _mm_extract_epi32(c1, 3); 149 | 150 | __m128i b0 = _mm_shuffle_epi32(c0, _MM_SHUFFLE(1, 0, 2, 3)); // 2 0 1 3 151 | __m128i b1 = _mm_shuffle_epi32(c1, _MM_SHUFFLE(1, 0, 2, 3)); 152 | 153 | __m128i x0 = _mm_insert_epi32(b0, state.left, 0); // 2 0 1 s 154 | __m128i x1 = _mm_insert_epi32(b1, state.right, 0); 155 | 156 | __m128i d0 = left.value(); // 3 1 2 0 157 | __m128i d1 = right.value(); 158 | 159 | __m128i p0 = _mm_xor_si128(d0, x0); 160 | __m128i p1 = _mm_xor_si128(d1, x1); 161 | 162 | return std::make_pair(block(p0, p1), cbc_state(s0, s1)); 163 | } 164 | 165 | #else /* __SSE4_1__ */ 166 | 167 | template<> 168 | inline std::pair, cbc_state> block::cbc_post_decrypt(const block &c, const cbc_state &state) const { 169 | __m128i c0 = c.left.value(); // 3 1 2 0 / 3 2 1 0 170 | __m128i c1 = c.right.value(); 171 | 172 | #if defined(__SSSE3__) 173 | const int s = _MM_SHUFFLE(1, 0, 2, 3); 174 | #else 175 | const int s = _MM_SHUFFLE(2, 1, 0, 3); 176 | #endif 177 | __m128i b0 = _mm_shuffle_epi32(c0, s); // 2 0 1 3 / 2 1 0 3 178 | __m128i b1 = _mm_shuffle_epi32(c1, s); 179 | 180 | uint32_t s0 = _mm_cvtsi128_si32(b0); // 3 181 | uint32_t s1 = _mm_cvtsi128_si32(b1); 182 | 183 | __m128i i0 = _mm_cvtsi32_si128(state.left); // - - - s 184 | __m128i i1 = _mm_cvtsi32_si128(state.right); 185 | 186 | __m128i x0 = _mm_castps_si128(_mm_move_ss(_mm_castsi128_ps(b0), _mm_castsi128_ps(i0))); // 2 0 1 s / 2 1 0 s 187 | __m128i x1 = _mm_castps_si128(_mm_move_ss(_mm_castsi128_ps(b1), _mm_castsi128_ps(i1))); 188 | 189 | __m128i d0 = left.value(); // 3 1 2 0 / 3 2 1 0 190 | __m128i d1 = right.value(); 191 | 192 | __m128i p0 = _mm_xor_si128(d0, x0); 193 | __m128i p1 = _mm_xor_si128(d1, x1); 194 | 195 | return std::make_pair(block(p0, p1), cbc_state(s0, s1)); 196 | } 197 | 198 | #endif /* __SSE4_1__ */ 199 | 200 | template<> 201 | inline x86::xmm rot1_add_dec(const x86::xmm &v) { 202 | __m128i d = _mm_cmpgt_epi32(v.value(), _mm_set1_epi32(-1)); 203 | return v + v + v + x86::xmm(d); 204 | } 205 | 206 | } 207 | 208 | #endif /* __SSE2__ */ 209 | -------------------------------------------------------------------------------- /aribb25/multi2_ymm2.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #if defined(__AVX2__) 4 | 5 | #include 6 | 7 | #if defined(_WIN32) 8 | # include 9 | #else 10 | # include 11 | #endif 12 | 13 | #include "portable.h" 14 | 15 | #include "multi2_block.h" 16 | 17 | namespace multi2 { 18 | 19 | namespace x86 { 20 | 21 | class ymm2 { 22 | private: 23 | __m256i v0; 24 | __m256i v1; 25 | 26 | public: 27 | inline ymm2() { 28 | #if !defined(NO_MM_UNDEFINED) 29 | v0 = v1 = _mm256_undefined_si256(); 30 | #endif 31 | } 32 | inline ymm2(uint32_t n) { v0 = v1 = _mm256_set1_epi32(n); } 33 | inline ymm2(const __m256i &r0, const __m256i &r1) { 34 | v0 = r0; 35 | v1 = r1; 36 | } 37 | 38 | inline ymm2 &operator=(const ymm2 &other) { 39 | v0 = other.v0; 40 | v1 = other.v1; 41 | return *this; 42 | } 43 | 44 | inline ymm2 operator+(const ymm2 &other) const { 45 | return x86::ymm2(_mm256_add_epi32(v0, other.v0), _mm256_add_epi32(v1, other.v1)); 46 | } 47 | inline ymm2 operator-(const ymm2 &other) const { 48 | return x86::ymm2(_mm256_sub_epi32(v0, other.v0), _mm256_sub_epi32(v1, other.v1)); 49 | } 50 | inline ymm2 operator^(const ymm2 &other) const { 51 | return x86::ymm2(_mm256_xor_si256(v0, other.v0), _mm256_xor_si256(v1, other.v1)); 52 | } 53 | inline ymm2 operator|(const ymm2 &other) const { 54 | return x86::ymm2(_mm256_or_si256(v0, other.v0), _mm256_or_si256(v1, other.v1)); 55 | } 56 | inline ymm2 operator<<(int n) const { 57 | return x86::ymm2(_mm256_slli_epi32(v0, n), _mm256_slli_epi32(v1, n)); 58 | } 59 | inline ymm2 operator>>(int n) const { 60 | return x86::ymm2(_mm256_srli_epi32(v0, n), _mm256_srli_epi32(v1, n)); 61 | } 62 | 63 | inline const __m256i &value0() const { return v0; } 64 | inline const __m256i &value1() const { return v1; } 65 | }; 66 | 67 | } 68 | 69 | template<> 70 | inline size_t block_size() { 71 | return 120; 72 | } 73 | 74 | template<> 75 | inline void block::load(const uint8_t *p) { 76 | const __m256i *q0 = reinterpret_cast(p); 77 | const __m256i *q1 = reinterpret_cast(p + 56); 78 | 79 | __m256i a0 = _mm256_loadu_si256(q0); // 07 06 05 04 03 02 01 00 - DCBA 80 | __m256i a1 = _mm256_loadu_si256(q0 + 1); // 0f 0e 0d 0c 0b 0a 09 08 - DCBA 81 | __m256i a2 = _mm256_loadu_si256(q1); // 15 14 13 12 11 10 0f 0e - DCBA 82 | __m256i a3 = _mm256_loadu_si256(q1 + 1); // 1d 1c 1b 1a 19 18 17 16 - DCBA 83 | 84 | __m256i s = _mm256_set_epi8( 85 | 12, 13, 14, 15, 4, 5, 6, 7, 8, 9, 10, 11, 0, 1, 2, 3, 86 | 12, 13, 14, 15, 4, 5, 6, 7, 8, 9, 10, 11, 0, 1, 2, 3 87 | ); 88 | __m256i b0 = _mm256_shuffle_epi8(a0, s); // 07 05 06 04 03 01 02 00 - ABCD 89 | __m256i b1 = _mm256_shuffle_epi8(a1, s); // 0f 0d 0e 0c 0b 09 0a 08 - ABCD 90 | __m256i b2 = _mm256_shuffle_epi8(a2, s); // 15 13 14 12 11 0f 10 0e - ABCD 91 | __m256i b3 = _mm256_shuffle_epi8(a3, s); // 1d 1b 1c 1a 19 17 18 16 - ABCD 92 | 93 | __m256i c0 = _mm256_unpacklo_epi32(b0, b1); // 0e 06 0c 04 0a 02 08 00 - ABCD 94 | __m256i c1 = _mm256_unpackhi_epi32(b0, b1); // 0f 07 0d 05 0b 03 09 01 - ABCD 95 | __m256i c2 = _mm256_unpacklo_epi32(b2, b3); // 1c 14 1a 12 18 10 16 0e - ABCD 96 | __m256i c3 = _mm256_unpackhi_epi32(b2, b3); // 1d 15 1b 13 19 11 17 0f - ABCD 97 | 98 | left = x86::ymm2(c0, c2); // 0e 06 0c 04 0a 02 08 00 - 1c 14 1a 12 18 10 16 0e 99 | right = x86::ymm2(c1, c3); // 0f 07 0d 05 0b 03 09 01 - 1d 15 1b 13 19 11 17 0f 100 | } 101 | 102 | template<> 103 | inline void block::store(uint8_t *p) const { 104 | __m256i a0 = left.value0(); // 0e 06 0c 04 0a 02 08 00 - ABCD 105 | __m256i a1 = right.value0(); // 0f 07 0d 05 0b 03 09 01 - ABCD 106 | __m256i a2 = left.value1(); // 1c 14 1a 12 18 10 16 -- - ABCD 107 | __m256i a3 = right.value1(); // 1d 15 1b 13 19 11 17 -- - ABCD 108 | 109 | __m256i s = _mm256_set_epi8( 110 | 12, 13, 14, 15, 4, 5, 6, 7, 8, 9, 10, 11, 0, 1, 2, 3, 111 | 12, 13, 14, 15, 4, 5, 6, 7, 8, 9, 10, 11, 0, 1, 2, 3 112 | ); 113 | __m256i b0 = _mm256_shuffle_epi8(a0, s); // 0e 0c 06 04 0a 08 02 00 - DCBA 114 | __m256i b1 = _mm256_shuffle_epi8(a1, s); // 0f 0d 07 05 0b 09 03 01 - DCBA 115 | __m256i b2 = _mm256_shuffle_epi8(a2, s); // 1c 1a 14 12 18 16 10 -- - DCBA 116 | __m256i b3 = _mm256_shuffle_epi8(a3, s); // 1d 1b 15 13 19 17 11 -- - DCBA 117 | 118 | __m256i c0 = _mm256_unpacklo_epi32(b0, b1); // 07 06 05 04 03 02 01 00 - DCBA 119 | __m256i c1 = _mm256_unpackhi_epi32(b0, b1); // 0f 0e 0d 0c 07 06 05 04 - DCBA 120 | __m256i c2 = _mm256_unpacklo_epi32(b2, b3); // 15 14 13 12 11 10 -- -- - DCBA 121 | __m256i c3 = _mm256_unpackhi_epi32(b2, b3); // 1d 1c 1b 1a 19 18 17 16 - DCBA 122 | 123 | __m256i *q0 = reinterpret_cast<__m256i *>(p); 124 | __m256i *q1 = reinterpret_cast<__m256i *>(p + 56); 125 | _mm256_storeu_si256(q0, c0); 126 | _mm256_storeu_si256(q1, c2); 127 | _mm256_storeu_si256(q0 + 1, c1); 128 | _mm256_storeu_si256(q1 + 1, c3); 129 | } 130 | 131 | template<> 132 | inline std::pair, cbc_state> block::cbc_post_decrypt(const block &c, const cbc_state &state) const { 133 | __m256i c0 = c.left.value0(); // 7 3 6 2 5 1 4 0 134 | __m256i c1 = c.right.value0(); 135 | __m256i c2 = c.left.value1(); // e a d 9 c 8 b 7 136 | __m256i c3 = c.right.value1(); 137 | 138 | uint32_t s2 = _mm256_extract_epi32(c2, 7); // e 139 | uint32_t s3 = _mm256_extract_epi32(c3, 7); 140 | 141 | __m256i s = _mm256_set_epi32(5, 4, 3, 2, 1, 0, 6, 7); 142 | __m256i a0 = _mm256_permutevar8x32_epi32(c0, s); // 6 2 5 1 4 0 3 7 143 | __m256i a1 = _mm256_permutevar8x32_epi32(c1, s); 144 | __m256i a2 = _mm256_permutevar8x32_epi32(c2, s); // d 9 c 8 b 7 a e 145 | __m256i a3 = _mm256_permutevar8x32_epi32(c3, s); 146 | 147 | __m256i x0 = _mm256_insert_epi32(a0, state.left, 0); // 6 2 5 1 4 0 3 s 148 | __m256i x1 = _mm256_insert_epi32(a1, state.right, 0); 149 | __m256i x2 = a2; // d 9 c 8 b 7 a e 150 | __m256i x3 = a3; 151 | 152 | __m256i d0 = left.value0(); // 7 3 6 2 5 1 4 0 153 | __m256i d1 = right.value0(); 154 | __m256i d2 = left.value1(); // e a d 9 c 8 b 7 155 | __m256i d3 = right.value1(); 156 | 157 | __m256i p0 = _mm256_xor_si256(d0, x0); 158 | __m256i p1 = _mm256_xor_si256(d1, x1); 159 | __m256i p2 = _mm256_xor_si256(d2, x2); 160 | __m256i p3 = _mm256_xor_si256(d3, x3); 161 | 162 | return std::make_pair(block(x86::ymm2(p0, p2), x86::ymm2(p1, p3)), cbc_state(s2, s3)); 163 | } 164 | 165 | template<> 166 | inline x86::ymm2 rot<8, x86::ymm2>(const x86::ymm2 &v) { 167 | __m256i s = _mm256_set_epi8( 168 | 14, 13, 12, 15, 10, 9, 8, 11, 6, 5, 4, 7, 2, 1, 0, 3, 169 | 14, 13, 12, 15, 10, 9, 8, 11, 6, 5, 4, 7, 2, 1, 0, 3 170 | ); 171 | return x86::ymm2(_mm256_shuffle_epi8(v.value0(), s), _mm256_shuffle_epi8(v.value1(), s)); 172 | } 173 | 174 | template<> 175 | inline x86::ymm2 rot<16, x86::ymm2>(const x86::ymm2 &v) { 176 | __m256i s = _mm256_set_epi8( 177 | 13, 12, 15, 14, 9, 8, 11, 10, 5, 4, 7, 6, 1, 0, 3, 2, 178 | 13, 12, 15, 14, 9, 8, 11, 10, 5, 4, 7, 6, 1, 0, 3, 2 179 | ); 180 | return x86::ymm2(_mm256_shuffle_epi8(v.value0(), s), _mm256_shuffle_epi8(v.value1(), s)); 181 | } 182 | 183 | template<> 184 | inline x86::ymm2 rot1_add_dec(const x86::ymm2 &v) { 185 | __m256i d0 = _mm256_cmpgt_epi32(v.value0(), _mm256_set1_epi32(-1)); 186 | __m256i d1 = _mm256_cmpgt_epi32(v.value1(), _mm256_set1_epi32(-1)); 187 | return v + v + v + x86::ymm2(d0, d1); 188 | } 189 | 190 | } 191 | 192 | #endif /* __AVX2__ */ 193 | -------------------------------------------------------------------------------- /aribb25/multi2.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "multi2.h" 5 | #include "multi2_error_code.h" 6 | #include "portable.h" 7 | 8 | #include "multi2_compat.h" 9 | #include "multi2_cipher.h" 10 | 11 | namespace multi2 { 12 | 13 | struct multi2 : public MULTI2 { 14 | uint32_t ref_count; 15 | uint32_t round; 16 | 17 | optional system_key; 18 | optional iv; 19 | 20 | array, 2> data_key; 21 | array, 2> work_key; 22 | 23 | inline void set_system_key(uint8_t *p) { 24 | system_key_type s; 25 | for (size_t i = 0; i < s.size(); ++i) { 26 | s[i] = load_be(p + i * 4); 27 | } 28 | system_key = s; 29 | } 30 | 31 | inline void set_iv(uint8_t *p) { 32 | iv_type v; 33 | v[0] = load_be(p); 34 | v[1] = load_be(p + 4); 35 | iv = v; 36 | } 37 | 38 | inline void set_work_keys(uint8_t *p) { 39 | array k; 40 | k[0][0] = load_be(p); 41 | k[0][1] = load_be(p + 4); 42 | k[1][0] = load_be(p + 8); 43 | k[1][1] = load_be(p + 12); 44 | 45 | for (int i = 0; i < 2; ++i) { 46 | if (!data_key[i] || *data_key[i] != k[i]) { 47 | data_key[i] = k[i]; 48 | work_key[i].reset(); 49 | } 50 | } 51 | } 52 | 53 | inline void clear_work_keys() { 54 | for (int i = 0; i < 2; ++i) { 55 | data_key[i].reset(); 56 | work_key[i].reset(); 57 | } 58 | } 59 | 60 | inline int encrypt(int32_t type, uint8_t *b, size_t n) { 61 | int i = (type == 0x02); 62 | 63 | if (!iv) { 64 | return MULTI2_ERROR_UNSET_CBC_INIT; 65 | } 66 | 67 | if (!work_key[i]) { 68 | if (!system_key) { 69 | return MULTI2_ERROR_UNSET_SYSTEM_KEY; 70 | } 71 | if (!data_key[i]) { 72 | return MULTI2_ERROR_UNSET_SCRAMBLE_KEY; 73 | } 74 | work_key[i] = schedule(*data_key[i], *system_key); 75 | } 76 | 77 | encrypt_cbc_ofb(b, n, *iv, *work_key[i], round); 78 | return 0; 79 | } 80 | 81 | inline int decrypt(int32_t type, uint8_t *b, size_t n) { 82 | int i = (type == 0x02); 83 | 84 | if (!iv) { 85 | return MULTI2_ERROR_UNSET_CBC_INIT; 86 | } 87 | 88 | if (!work_key[i]) { 89 | if (!system_key) { 90 | return MULTI2_ERROR_UNSET_SYSTEM_KEY; 91 | } 92 | if (!data_key[i]) { 93 | return MULTI2_ERROR_UNSET_SCRAMBLE_KEY; 94 | } 95 | work_key[i] = schedule(*data_key[i], *system_key); 96 | } 97 | 98 | decrypt_cbc_ofb(b, n, *iv, *work_key[i], round); 99 | return 0; 100 | } 101 | }; 102 | 103 | } 104 | 105 | /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 106 | function prototypes (interface method) 107 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ 108 | static void release_multi2(void *m2); 109 | static int add_ref_multi2(void *m2); 110 | static int set_round_multi2(void *m2, int32_t val); 111 | static int set_system_key_multi2(void *m2, uint8_t *val); 112 | static int set_init_cbc_multi2(void *m2, uint8_t *val); 113 | static int set_scramble_key_multi2(void *m2, uint8_t *val); 114 | static int clear_scramble_key_multi2(void *m2); 115 | static int encrypt_multi2(void *m2, int32_t type, uint8_t *buf, int32_t size); 116 | static int decrypt_multi2(void *m2, int32_t type, uint8_t *buf, int32_t size); 117 | 118 | /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 119 | global function implementation 120 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ 121 | MULTI2 *create_multi2() 122 | { 123 | multi2::multi2 *m2; 124 | try { 125 | m2 = new multi2::multi2(); 126 | } catch (std::bad_alloc &e) { 127 | return NULL; 128 | } 129 | 130 | m2->ref_count = 1; 131 | m2->round = 4; 132 | 133 | MULTI2 *r = static_cast(m2); 134 | r->private_data = m2; 135 | 136 | r->release = release_multi2; 137 | r->add_ref = add_ref_multi2; 138 | r->set_round = set_round_multi2; 139 | r->set_system_key = set_system_key_multi2; 140 | r->set_init_cbc = set_init_cbc_multi2; 141 | r->set_scramble_key = set_scramble_key_multi2; 142 | r->clear_scramble_key = clear_scramble_key_multi2; 143 | r->encrypt = encrypt_multi2; 144 | r->decrypt = decrypt_multi2; 145 | 146 | return r; 147 | } 148 | 149 | /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 150 | function prototypes (private method) 151 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ 152 | static multi2::multi2 *private_data(void *m2); 153 | 154 | /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 155 | interface method implementation 156 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ 157 | static void release_multi2(void *m2) 158 | { 159 | multi2::multi2 *prv = private_data(m2); 160 | if (!prv) { 161 | return; 162 | } 163 | 164 | --prv->ref_count; 165 | if (!prv->ref_count) { 166 | delete prv; 167 | } 168 | } 169 | 170 | static int add_ref_multi2(void *m2) 171 | { 172 | multi2::multi2 *prv = private_data(m2); 173 | if (!prv) { 174 | return MULTI2_ERROR_INVALID_PARAMETER; 175 | } 176 | 177 | ++prv->ref_count; 178 | return 0; 179 | } 180 | 181 | static int set_round_multi2(void *m2, int32_t val) 182 | { 183 | multi2::multi2 *prv = private_data(m2); 184 | if (!prv) { 185 | return MULTI2_ERROR_INVALID_PARAMETER; 186 | } 187 | 188 | prv->round = val; 189 | return 0; 190 | } 191 | 192 | static int set_system_key_multi2(void *m2, uint8_t *val) 193 | { 194 | multi2::multi2 *prv = private_data(m2); 195 | if (!prv || !val) { 196 | return MULTI2_ERROR_INVALID_PARAMETER; 197 | } 198 | 199 | prv->set_system_key(val); 200 | return 0; 201 | } 202 | 203 | static int set_init_cbc_multi2(void *m2, uint8_t *val) 204 | { 205 | multi2::multi2 *prv = private_data(m2); 206 | if (!prv || !val) { 207 | return MULTI2_ERROR_INVALID_PARAMETER; 208 | } 209 | 210 | prv->set_iv(val); 211 | return 0; 212 | } 213 | 214 | static int set_scramble_key_multi2(void *m2, uint8_t *val) 215 | { 216 | multi2::multi2 *prv = private_data(m2); 217 | if (!prv || !val) { 218 | return MULTI2_ERROR_INVALID_PARAMETER; 219 | } 220 | 221 | prv->set_work_keys(val); 222 | return 0; 223 | } 224 | 225 | static int clear_scramble_key_multi2(void *m2) 226 | { 227 | multi2::multi2 *prv = private_data(m2); 228 | if (!prv) { 229 | return MULTI2_ERROR_INVALID_PARAMETER; 230 | } 231 | 232 | prv->clear_work_keys(); 233 | return 0; 234 | } 235 | 236 | static int encrypt_multi2(void *m2, int32_t type, uint8_t *buf, int32_t size) 237 | { 238 | multi2::multi2 *prv = private_data(m2); 239 | if (!prv || !buf || size < 1) { 240 | return MULTI2_ERROR_INVALID_PARAMETER; 241 | } 242 | 243 | return prv->encrypt(type, buf, size); 244 | } 245 | 246 | static int decrypt_multi2(void *m2, int32_t type, uint8_t *buf, int32_t size) 247 | { 248 | multi2::multi2 *prv = private_data(m2); 249 | if (!prv || !buf || size < 1) { 250 | return MULTI2_ERROR_INVALID_PARAMETER; 251 | } 252 | 253 | return prv->decrypt(type, buf, size); 254 | } 255 | 256 | /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 257 | private method implementation 258 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ 259 | static multi2::multi2 *private_data(void *m2) 260 | { 261 | if (!m2) { 262 | return NULL; 263 | } 264 | MULTI2 *p = static_cast(m2); 265 | multi2::multi2 *r = static_cast(p->private_data); 266 | if (static_cast(r) != p) { 267 | return NULL; 268 | } 269 | 270 | return r; 271 | } 272 | -------------------------------------------------------------------------------- /aribb25/libaribb25.cpp: -------------------------------------------------------------------------------- 1 | // libaribb25.cpp: CB25Decoder クラスのインプリメンテーション 2 | // 3 | ////////////////////////////////////////////////////////////////////// 4 | #include "libaribb25.h" 5 | 6 | BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) 7 | { 8 | if (fdwReason == DLL_PROCESS_ATTACH) { 9 | DisableThreadLibraryCalls(hinstDLL); 10 | } else if (fdwReason == DLL_PROCESS_DETACH) { 11 | // 未開放の場合はインスタンス開放 12 | if (CB25Decoder::m_pThis) { 13 | CB25Decoder::m_pThis->Release(); 14 | } 15 | } 16 | return TRUE; 17 | } 18 | 19 | ////////////////////////////////////////////////////////////////////// 20 | // インスタンス生成メソッド 21 | ////////////////////////////////////////////////////////////////////// 22 | 23 | extern "C" 24 | { 25 | 26 | __declspec(dllexport) IB25Decoder * CreateB25Decoder() 27 | { 28 | // インスタンス生成 29 | return dynamic_cast(new CB25Decoder()); 30 | } 31 | 32 | __declspec(dllexport) IB25Decoder2 * CreateB25Decoder2() 33 | { 34 | // インスタンス生成 35 | return dynamic_cast(new CB25Decoder()); 36 | } 37 | 38 | } 39 | 40 | ////////////////////////////////////////////////////////////////////// 41 | // 構築/消滅 42 | ////////////////////////////////////////////////////////////////////// 43 | 44 | // 静的メンバ初期化 45 | CB25Decoder * CB25Decoder::m_pThis = nullptr; 46 | 47 | CB25Decoder::CB25Decoder(void) : _bcas(nullptr), _b25(nullptr), _data(nullptr) 48 | { 49 | m_pThis = this; 50 | } 51 | 52 | CB25Decoder::~CB25Decoder(void) 53 | { 54 | m_pThis = nullptr; 55 | } 56 | 57 | void CB25Decoder::Release() 58 | { 59 | // インスタンス開放 60 | if (_data) 61 | ::free(_data); 62 | 63 | std::lock_guard lock(_mtx); 64 | 65 | if (_b25) 66 | _b25->release(_b25); 67 | 68 | if (_bcas) 69 | _bcas->release(_bcas); 70 | 71 | delete this; 72 | } 73 | 74 | const BOOL CB25Decoder::Initialize(DWORD dwRound) 75 | { 76 | std::lock_guard lock(_mtx); 77 | 78 | if (_b25) 79 | return Reset(); 80 | 81 | _bcas = create_b_cas_card(); 82 | if (!_bcas) 83 | return FALSE; 84 | 85 | if (_bcas->init(_bcas) < 0) 86 | goto err; 87 | 88 | _b25 = create_arib_std_b25(); 89 | if (!_b25) 90 | goto err; 91 | 92 | if (_b25->set_b_cas_card(_b25, _bcas) < 0) 93 | goto err; 94 | 95 | _b25->set_strip(_b25, 1); 96 | _b25->set_emm_proc(_b25, 1); 97 | _b25->set_multi2_round(_b25, dwRound); 98 | 99 | return TRUE; // success 100 | 101 | err: 102 | if (_b25) { 103 | _b25->release(_b25); 104 | _b25 = nullptr; 105 | } 106 | 107 | if (_bcas) { 108 | _bcas->release(_bcas); 109 | _bcas = nullptr; 110 | } 111 | 112 | _errtime = time(nullptr); 113 | return FALSE; // error 114 | } 115 | 116 | const BOOL CB25Decoder::Decode(BYTE *pSrcBuf, const DWORD dwSrcSize, BYTE **ppDstBuf, DWORD *pdwDstSize) 117 | { 118 | if (!pSrcBuf || !dwSrcSize || !ppDstBuf || !pdwDstSize) { 119 | // 引数が不正 120 | return FALSE; 121 | } 122 | 123 | if (!_b25) { 124 | time_t now = time(nullptr); 125 | if (difftime(now, _errtime) > RETRY_INTERVAL) { 126 | if (Initialize() < 0) 127 | _errtime = now; 128 | } 129 | 130 | if (!_b25) { 131 | if (*ppDstBuf != pSrcBuf) { 132 | *ppDstBuf = pSrcBuf; 133 | *pdwDstSize = dwSrcSize; 134 | } 135 | return FALSE; 136 | } 137 | } 138 | 139 | if (_data) { 140 | ::free(_data); 141 | _data = nullptr; 142 | } 143 | 144 | ARIB_STD_B25_BUFFER buf; 145 | buf.data = pSrcBuf; 146 | buf.size = dwSrcSize; 147 | const int rc = _b25->put(_b25, &buf); 148 | if (rc == ARIB_STD_B25_WARN_PAT_NOT_COMPLETE) { 149 | if (*ppDstBuf != pSrcBuf) { 150 | *ppDstBuf = pSrcBuf; 151 | *pdwDstSize = dwSrcSize; 152 | } 153 | return TRUE; // success 154 | } else if (rc < 0) { 155 | if (rc >= ARIB_STD_B25_ERROR_NO_ECM_IN_HEAD_32M) { 156 | // pass through 157 | _b25->release(_b25); 158 | _b25 = nullptr; 159 | _bcas->release(_bcas); 160 | _bcas = nullptr; 161 | if (*ppDstBuf != pSrcBuf) { 162 | *ppDstBuf = pSrcBuf; 163 | *pdwDstSize = dwSrcSize; 164 | } 165 | } else { 166 | BYTE *p = nullptr; 167 | _b25->withdraw(_b25, &buf); // withdraw src buffer 168 | if (buf.size > 0) 169 | p = (BYTE *)::malloc(buf.size + dwSrcSize); 170 | 171 | if (p) { 172 | ::memcpy(p, buf.data, buf.size); 173 | ::memcpy(p + buf.size, pSrcBuf, dwSrcSize); 174 | *ppDstBuf = p; 175 | *pdwDstSize = buf.size + dwSrcSize; 176 | _data = p; 177 | } else { 178 | if (*ppDstBuf != pSrcBuf) { 179 | *ppDstBuf = pSrcBuf; 180 | *pdwDstSize = dwSrcSize; 181 | } 182 | } 183 | 184 | if (rc == ARIB_STD_B25_ERROR_ECM_PROC_FAILURE) { 185 | // pass through 186 | _b25->release(_b25); 187 | _b25 = nullptr; 188 | _bcas->release(_bcas); 189 | _bcas = nullptr; 190 | } 191 | } 192 | _errtime = time(nullptr); 193 | return FALSE; // error 194 | } 195 | _b25->get(_b25, &buf); 196 | *ppDstBuf = buf.data; 197 | *pdwDstSize = buf.size; 198 | return TRUE; // success 199 | } 200 | 201 | const BOOL CB25Decoder::Flush(BYTE **ppDstBuf, DWORD *pdwDstSize) 202 | { 203 | BOOL ret = TRUE; 204 | 205 | if (_b25) { 206 | int rc = _b25->flush(_b25); 207 | ret = (rc < 0) ? FALSE : TRUE; 208 | } 209 | 210 | *ppDstBuf = nullptr; 211 | *pdwDstSize = 0; 212 | 213 | return ret; 214 | } 215 | 216 | const BOOL CB25Decoder::Reset(void) 217 | { 218 | BOOL ret = TRUE; 219 | 220 | if (_b25) { 221 | int rc = _b25->reset(_b25); 222 | ret = (rc < 0) ? FALSE : TRUE; 223 | } 224 | 225 | return ret; 226 | } 227 | 228 | void CB25Decoder::DiscardNullPacket(const bool bEnable) 229 | { 230 | // NULLパケット破棄の有無を設定 231 | _b25->set_strip(_b25, bEnable); 232 | } 233 | 234 | void CB25Decoder::DiscardScramblePacket(const bool bEnable) 235 | { 236 | // 復号漏れパケット破棄の有無を設定 237 | } 238 | 239 | void CB25Decoder::EnableEmmProcess(const bool bEnable) 240 | { 241 | // EMM処理の有効/無効を設定 242 | _b25->set_emm_proc(_b25, bEnable); 243 | } 244 | 245 | void CB25Decoder::SetMulti2Round(const int32_t round) 246 | { 247 | // ラウンド段数を設定 248 | _b25->set_multi2_round(_b25, round); 249 | } 250 | 251 | void CB25Decoder::SetSimdMode(const int32_t instruction) 252 | { 253 | _b25->set_simd_mode(_b25, instruction); 254 | } 255 | 256 | const DWORD CB25Decoder::GetDescramblingState(const WORD wProgramID) 257 | { 258 | // 指定したプログラムIDの復号状態を返す 259 | return 0; 260 | } 261 | 262 | void CB25Decoder::ResetStatistics(void) 263 | { 264 | } 265 | 266 | const DWORD CB25Decoder::GetPacketStride(void) 267 | { 268 | // パケット周期を返す 269 | return 0; 270 | } 271 | 272 | const DWORD CB25Decoder::GetInputPacketNum(const WORD wPID) 273 | { 274 | // 入力パケット数を返す ※TS_INVALID_PID指定時は全PIDの合計を返す 275 | return 0; 276 | } 277 | 278 | const DWORD CB25Decoder::GetOutputPacketNum(const WORD wPID) 279 | { 280 | // 出力パケット数を返す ※TS_INVALID_PID指定時は全PIDの合計を返す 281 | return 0; 282 | } 283 | 284 | const DWORD CB25Decoder::GetSyncErrNum(void) 285 | { 286 | // 同期エラー数を返す 287 | return 0; 288 | } 289 | 290 | const DWORD CB25Decoder::GetFormatErrNum(void) 291 | { 292 | // フォーマットエラー数を返す 293 | return 0; 294 | } 295 | 296 | const DWORD CB25Decoder::GetTransportErrNum(void) 297 | { 298 | // ビットエラー数を返す 299 | return 0; 300 | } 301 | 302 | const DWORD CB25Decoder::GetContinuityErrNum(const WORD wPID) 303 | { 304 | // ドロップパケット数を返す 305 | return 0; 306 | } 307 | 308 | const DWORD CB25Decoder::GetScramblePacketNum(const WORD wPID) 309 | { 310 | // 復号漏れパケット数を返す 311 | return 0; 312 | } 313 | 314 | const DWORD CB25Decoder::GetEcmProcessNum(void) 315 | { 316 | // ECM処理数を返す(B-CASカードアクセス回数) 317 | return 0; 318 | } 319 | 320 | const DWORD CB25Decoder::GetEmmProcessNum(void) 321 | { 322 | // EMM処理数を返す(B-CASカードアクセス回数) 323 | return 0; 324 | } 325 | -------------------------------------------------------------------------------- /aribb25/libaribb25.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | {32FCD075-2C1D-4796-926B-A0009ECCD1E8} 23 | libaribb25 24 | 10.0 25 | 26 | 27 | 28 | DynamicLibrary 29 | true 30 | v142 31 | Unicode 32 | 33 | 34 | DynamicLibrary 35 | false 36 | v142 37 | true 38 | Unicode 39 | 40 | 41 | DynamicLibrary 42 | true 43 | v142 44 | Unicode 45 | 46 | 47 | DynamicLibrary 48 | false 49 | v142 50 | true 51 | Unicode 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | $(SolutionDir)Intermediate\$(ProjectName)\$(Platform)\$(Configuration)\ 73 | 74 | 75 | $(SolutionDir)Intermediate\$(ProjectName)\$(Platform)\$(Configuration)\ 76 | $(SolutionDir)$(Platform)\$(Configuration)\ 77 | 78 | 79 | $(SolutionDir)Intermediate\$(ProjectName)\$(Platform)\$(Configuration)\ 80 | $(SolutionDir)$(Platform)\$(Configuration)\ 81 | 82 | 83 | $(SolutionDir)Intermediate\$(ProjectName)\$(Platform)\$(Configuration)\ 84 | 85 | 86 | 87 | Level3 88 | Disabled 89 | 90 | 91 | ENABLE_MULTI2_SIMD;_WINDLL;%(PreprocessorDefinitions) 92 | /source-charset:utf-8 %(AdditionalOptions) 93 | 94 | 95 | winscard.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) 96 | $(IntDir)$(TargetName).lib 97 | 98 | 99 | 100 | 101 | Level3 102 | Disabled 103 | 104 | 105 | ENABLE_MULTI2_SIMD;_WINDLL;%(PreprocessorDefinitions) 106 | /source-charset:utf-8 %(AdditionalOptions) 107 | 108 | 109 | winscard.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) 110 | $(IntDir)$(TargetName).lib 111 | 112 | 113 | 114 | 115 | Level3 116 | MaxSpeed 117 | true 118 | true 119 | 120 | 121 | AnySuitable 122 | Speed 123 | true 124 | false 125 | Fast 126 | ENABLE_MULTI2_SIMD;_WINDLL;%(PreprocessorDefinitions) 127 | /source-charset:utf-8 %(AdditionalOptions) 128 | 129 | 130 | true 131 | true 132 | winscard.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) 133 | false 134 | UseLinkTimeCodeGeneration 135 | $(IntDir)$(TargetName).lib 136 | 137 | 138 | 139 | 140 | Level3 141 | MaxSpeed 142 | true 143 | true 144 | 145 | 146 | AnySuitable 147 | Speed 148 | true 149 | false 150 | Fast 151 | ENABLE_MULTI2_SIMD;_WINDLL;%(PreprocessorDefinitions) 152 | /source-charset:utf-8 %(AdditionalOptions) 153 | 154 | 155 | true 156 | true 157 | winscard.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) 158 | false 159 | UseLinkTimeCodeGeneration 160 | $(IntDir)$(TargetName).lib 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | -------------------------------------------------------------------------------- /aribb25/libaribb1.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | {92B17263-5DE9-49F5-8B3C-7A89F7561ED5} 23 | libaribb1 24 | 10.0 25 | 26 | 27 | 28 | DynamicLibrary 29 | true 30 | v142 31 | Unicode 32 | 33 | 34 | DynamicLibrary 35 | false 36 | v142 37 | true 38 | Unicode 39 | 40 | 41 | DynamicLibrary 42 | true 43 | v142 44 | Unicode 45 | 46 | 47 | DynamicLibrary 48 | false 49 | v142 50 | true 51 | Unicode 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | $(SolutionDir)Intermediate\$(ProjectName)\$(Platform)\$(Configuration)\ 73 | 74 | 75 | $(SolutionDir)Intermediate\$(ProjectName)\$(Platform)\$(Configuration)\ 76 | $(SolutionDir)$(Platform)\$(Configuration)\ 77 | 78 | 79 | $(SolutionDir)Intermediate\$(ProjectName)\$(Platform)\$(Configuration)\ 80 | $(SolutionDir)$(Platform)\$(Configuration)\ 81 | 82 | 83 | $(SolutionDir)Intermediate\$(ProjectName)\$(Platform)\$(Configuration)\ 84 | 85 | 86 | 87 | Level3 88 | Disabled 89 | 90 | 91 | ENABLE_ARIB_STD_B1;ENABLE_MULTI2_SIMD;_WINDLL;%(PreprocessorDefinitions) 92 | /source-charset:utf-8 %(AdditionalOptions) 93 | 94 | 95 | winscard.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) 96 | $(IntDir)$(TargetName).lib 97 | 98 | 99 | 100 | 101 | Level3 102 | Disabled 103 | 104 | 105 | ENABLE_ARIB_STD_B1;ENABLE_MULTI2_SIMD;_WINDLL;%(PreprocessorDefinitions) 106 | /source-charset:utf-8 %(AdditionalOptions) 107 | 108 | 109 | winscard.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) 110 | $(IntDir)$(TargetName).lib 111 | 112 | 113 | 114 | 115 | Level3 116 | MaxSpeed 117 | true 118 | true 119 | 120 | 121 | AnySuitable 122 | Speed 123 | true 124 | false 125 | Fast 126 | ENABLE_ARIB_STD_B1;ENABLE_MULTI2_SIMD;_WINDLL;%(PreprocessorDefinitions) 127 | /source-charset:utf-8 %(AdditionalOptions) 128 | 129 | 130 | true 131 | true 132 | winscard.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) 133 | false 134 | UseLinkTimeCodeGeneration 135 | $(IntDir)$(TargetName).lib 136 | 137 | 138 | 139 | 140 | Level3 141 | MaxSpeed 142 | true 143 | true 144 | 145 | 146 | AnySuitable 147 | Speed 148 | true 149 | false 150 | Fast 151 | ENABLE_ARIB_STD_B1;ENABLE_MULTI2_SIMD;_WINDLL;%(PreprocessorDefinitions) 152 | /source-charset:utf-8 %(AdditionalOptions) 153 | 154 | 155 | true 156 | true 157 | winscard.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) 158 | false 159 | UseLinkTimeCodeGeneration 160 | $(IntDir)$(TargetName).lib 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | -------------------------------------------------------------------------------- /aribb25/b25.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Debug 10 | x64 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | {6E77C1AC-A31A-49B9-9A52-9FE1E03B8FEC} 23 | arib_std_b25 24 | Win32Proj 25 | 10.0 26 | 27 | 28 | 29 | Application 30 | v142 31 | Unicode 32 | true 33 | 34 | 35 | Application 36 | v142 37 | Unicode 38 | true 39 | 40 | 41 | Application 42 | v142 43 | Unicode 44 | 45 | 46 | Application 47 | v142 48 | Unicode 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | <_ProjectFileVersion>12.0.30501.0 68 | 69 | 70 | $(SolutionDir)$(Platform)\$(Configuration)\ 71 | $(SolutionDir)Intermediate\$(ProjectName)\$(Platform)\$(Configuration)\ 72 | true 73 | $(ProjectName) 74 | 75 | 76 | true 77 | $(ProjectName) 78 | $(SolutionDir)Intermediate\$(ProjectName)\$(Platform)\$(Configuration)\ 79 | 80 | 81 | $(SolutionDir)$(Platform)\$(Configuration)\ 82 | $(SolutionDir)Intermediate\$(ProjectName)\$(Platform)\$(Configuration)\ 83 | false 84 | $(ProjectName) 85 | 86 | 87 | false 88 | $(ProjectName) 89 | $(SolutionDir)Intermediate\$(ProjectName)\$(Platform)\$(Configuration)\ 90 | 91 | 92 | 93 | Disabled 94 | ENABLE_MULTI2_SIMD;USE_BENCHMARK;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 95 | true 96 | EnableFastChecks 97 | MultiThreadedDebug 98 | 99 | Level3 100 | EditAndContinue 101 | /source-charset:utf-8 %(AdditionalOptions) 102 | 103 | 104 | winscard.lib;%(AdditionalDependencies) 105 | $(OutDir)$(TargetName)$(TargetExt) 106 | Debug 107 | Console 108 | MachineX86 109 | 110 | 111 | 112 | 113 | 114 | Disabled 115 | ENABLE_MULTI2_SIMD;USE_BENCHMARK;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 116 | EnableFastChecks 117 | MultiThreadedDebug 118 | 119 | 120 | Level3 121 | ProgramDatabase 122 | /source-charset:utf-8 %(AdditionalOptions) 123 | 124 | 125 | winscard.lib;%(AdditionalDependencies) 126 | $(OutDir)$(TargetName)$(TargetExt) 127 | Debug 128 | Console 129 | 130 | 131 | 132 | 133 | ENABLE_MULTI2_SIMD;USE_BENCHMARK;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 134 | MultiThreadedDLL 135 | 136 | Level3 137 | ProgramDatabase 138 | MaxSpeed 139 | AnySuitable 140 | true 141 | Speed 142 | true 143 | false 144 | true 145 | Fast 146 | /source-charset:utf-8 %(AdditionalOptions) 147 | 148 | 149 | winscard.lib;%(AdditionalDependencies) 150 | $(OutDir)$(TargetName)$(TargetExt) 151 | false 152 | Console 153 | true 154 | true 155 | MachineX86 156 | UseLinkTimeCodeGeneration 157 | 158 | 159 | 160 | 161 | ENABLE_MULTI2_SIMD;USE_BENCHMARK;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 162 | MultiThreadedDLL 163 | 164 | 165 | Level3 166 | ProgramDatabase 167 | MaxSpeed 168 | AnySuitable 169 | true 170 | Speed 171 | true 172 | false 173 | true 174 | Fast 175 | /source-charset:utf-8 %(AdditionalOptions) 176 | 177 | 178 | winscard.lib;%(AdditionalDependencies) 179 | $(OutDir)$(TargetName)$(TargetExt) 180 | false 181 | Console 182 | true 183 | true 184 | UseLinkTimeCodeGeneration 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2012 stz2012, MARUMO Manufacturing, 2ch NoNames. 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /aribb25/b1.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Debug 10 | x64 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | {26304970-9A5E-4DF0-AF69-8E01B9DEDDAE} 23 | arib_std_b1 24 | Win32Proj 25 | 10.0 26 | 27 | 28 | 29 | Application 30 | v142 31 | Unicode 32 | true 33 | 34 | 35 | Application 36 | v142 37 | Unicode 38 | true 39 | 40 | 41 | Application 42 | v142 43 | Unicode 44 | 45 | 46 | Application 47 | v142 48 | Unicode 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | <_ProjectFileVersion>12.0.30501.0 68 | 69 | 70 | $(SolutionDir)$(Platform)\$(Configuration)\ 71 | $(SolutionDir)Intermediate\$(ProjectName)\$(Platform)\$(Configuration)\ 72 | true 73 | $(ProjectName) 74 | 75 | 76 | true 77 | $(ProjectName) 78 | $(SolutionDir)Intermediate\$(ProjectName)\$(Platform)\$(Configuration)\ 79 | 80 | 81 | $(SolutionDir)$(Platform)\$(Configuration)\ 82 | $(SolutionDir)Intermediate\$(ProjectName)\$(Platform)\$(Configuration)\ 83 | false 84 | $(ProjectName) 85 | 86 | 87 | false 88 | $(ProjectName) 89 | $(SolutionDir)Intermediate\$(ProjectName)\$(Platform)\$(Configuration)\ 90 | 91 | 92 | 93 | Disabled 94 | ENABLE_ARIB_STD_B1;ENABLE_MULTI2_SIMD;USE_BENCHMARK;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 95 | true 96 | EnableFastChecks 97 | MultiThreadedDebug 98 | 99 | Level3 100 | EditAndContinue 101 | /source-charset:utf-8 %(AdditionalOptions) 102 | 103 | 104 | winscard.lib;%(AdditionalDependencies) 105 | $(OutDir)$(TargetName)$(TargetExt) 106 | Debug 107 | Console 108 | MachineX86 109 | 110 | 111 | 112 | 113 | 114 | Disabled 115 | ENABLE_ARIB_STD_B1;ENABLE_MULTI2_SIMD;USE_BENCHMARK;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 116 | EnableFastChecks 117 | MultiThreadedDebug 118 | 119 | 120 | Level3 121 | ProgramDatabase 122 | /source-charset:utf-8 %(AdditionalOptions) 123 | 124 | 125 | winscard.lib;%(AdditionalDependencies) 126 | $(OutDir)$(TargetName)$(TargetExt) 127 | Debug 128 | Console 129 | 130 | 131 | 132 | 133 | ENABLE_ARIB_STD_B1;ENABLE_MULTI2_SIMD;USE_BENCHMARK;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 134 | MultiThreadedDLL 135 | 136 | Level3 137 | ProgramDatabase 138 | MaxSpeed 139 | AnySuitable 140 | true 141 | Speed 142 | true 143 | false 144 | true 145 | Fast 146 | /source-charset:utf-8 %(AdditionalOptions) 147 | 148 | 149 | winscard.lib;%(AdditionalDependencies) 150 | $(OutDir)$(TargetName)$(TargetExt) 151 | false 152 | Console 153 | true 154 | true 155 | MachineX86 156 | UseLinkTimeCodeGeneration 157 | 158 | 159 | 160 | 161 | ENABLE_ARIB_STD_B1;ENABLE_MULTI2_SIMD;USE_BENCHMARK;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 162 | MultiThreadedDLL 163 | 164 | 165 | Level3 166 | ProgramDatabase 167 | MaxSpeed 168 | AnySuitable 169 | true 170 | Speed 171 | true 172 | false 173 | true 174 | Fast 175 | /source-charset:utf-8 %(AdditionalOptions) 176 | 177 | 178 | winscard.lib;%(AdditionalDependencies) 179 | $(OutDir)$(TargetName)$(TargetExt) 180 | false 181 | Console 182 | true 183 | true 184 | UseLinkTimeCodeGeneration 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | -------------------------------------------------------------------------------- /aribb25/arib-b25-stream-test.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Debug 10 | x64 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | {06BCA6CD-77A7-441B-BEEA-63A6561D6CDE} 23 | arib-b25-stream-test 24 | Win32Proj 25 | 10.0 26 | 27 | 28 | 29 | Application 30 | v142 31 | Unicode 32 | true 33 | 34 | 35 | Application 36 | v142 37 | Unicode 38 | true 39 | 40 | 41 | Application 42 | v142 43 | Unicode 44 | 45 | 46 | Application 47 | v142 48 | Unicode 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | <_ProjectFileVersion>12.0.30501.0 68 | 69 | 70 | $(SolutionDir)$(Platform)\$(Configuration)\ 71 | $(SolutionDir)Intermediate\$(ProjectName)\$(Platform)\$(Configuration)\ 72 | true 73 | $(ProjectName) 74 | 75 | 76 | true 77 | $(ProjectName) 78 | $(SolutionDir)Intermediate\$(ProjectName)\$(Platform)\$(Configuration)\ 79 | 80 | 81 | $(SolutionDir)$(Platform)\$(Configuration)\ 82 | $(SolutionDir)Intermediate\$(ProjectName)\$(Platform)\$(Configuration)\ 83 | false 84 | $(ProjectName) 85 | 86 | 87 | false 88 | $(ProjectName) 89 | $(SolutionDir)Intermediate\$(ProjectName)\$(Platform)\$(Configuration)\ 90 | 91 | 92 | 93 | Disabled 94 | ENABLE_ARIB_STREAM_TEST;ENABLE_MULTI2_SIMD;USE_BENCHMARK;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 95 | true 96 | EnableFastChecks 97 | MultiThreadedDebug 98 | 99 | Level3 100 | EditAndContinue 101 | /source-charset:utf-8 %(AdditionalOptions) 102 | 103 | 104 | winscard.lib;%(AdditionalDependencies) 105 | $(OutDir)$(TargetName)$(TargetExt) 106 | Debug 107 | Console 108 | MachineX86 109 | 110 | 111 | 112 | 113 | 114 | Disabled 115 | ENABLE_ARIB_STREAM_TEST;ENABLE_MULTI2_SIMD;USE_BENCHMARK;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 116 | EnableFastChecks 117 | MultiThreadedDebug 118 | 119 | 120 | Level3 121 | ProgramDatabase 122 | /source-charset:utf-8 %(AdditionalOptions) 123 | 124 | 125 | winscard.lib;%(AdditionalDependencies) 126 | $(OutDir)$(TargetName)$(TargetExt) 127 | Debug 128 | Console 129 | 130 | 131 | 132 | 133 | ENABLE_ARIB_STREAM_TEST;ENABLE_MULTI2_SIMD;USE_BENCHMARK;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 134 | MultiThreadedDLL 135 | 136 | Level3 137 | ProgramDatabase 138 | MaxSpeed 139 | AnySuitable 140 | true 141 | Speed 142 | true 143 | false 144 | true 145 | Fast 146 | /source-charset:utf-8 %(AdditionalOptions) 147 | 148 | 149 | winscard.lib;%(AdditionalDependencies) 150 | $(OutDir)$(TargetName)$(TargetExt) 151 | false 152 | Console 153 | true 154 | true 155 | MachineX86 156 | UseLinkTimeCodeGeneration 157 | 158 | 159 | 160 | 161 | ENABLE_ARIB_STREAM_TEST;ENABLE_MULTI2_SIMD;USE_BENCHMARK;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 162 | MultiThreadedDLL 163 | 164 | 165 | Level3 166 | ProgramDatabase 167 | MaxSpeed 168 | AnySuitable 169 | true 170 | Speed 171 | true 172 | false 173 | true 174 | Fast 175 | /source-charset:utf-8 %(AdditionalOptions) 176 | 177 | 178 | winscard.lib;%(AdditionalDependencies) 179 | $(OutDir)$(TargetName)$(TargetExt) 180 | false 181 | Console 182 | true 183 | true 184 | UseLinkTimeCodeGeneration 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | -------------------------------------------------------------------------------- /aribb25/arib-b1-stream-test.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Debug 10 | x64 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | {DE5EB7E1-56B9-440C-B3C6-5014E94FBC62} 23 | arib-b1-stream-test 24 | Win32Proj 25 | 10.0 26 | 27 | 28 | 29 | Application 30 | v142 31 | Unicode 32 | true 33 | 34 | 35 | Application 36 | v142 37 | Unicode 38 | true 39 | 40 | 41 | Application 42 | v142 43 | Unicode 44 | 45 | 46 | Application 47 | v142 48 | Unicode 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | <_ProjectFileVersion>12.0.30501.0 68 | 69 | 70 | $(SolutionDir)$(Platform)\$(Configuration)\ 71 | $(SolutionDir)Intermediate\$(ProjectName)\$(Platform)\$(Configuration)\ 72 | true 73 | $(ProjectName) 74 | 75 | 76 | true 77 | $(ProjectName) 78 | $(SolutionDir)Intermediate\$(ProjectName)\$(Platform)\$(Configuration)\ 79 | 80 | 81 | $(SolutionDir)$(Platform)\$(Configuration)\ 82 | $(SolutionDir)Intermediate\$(ProjectName)\$(Platform)\$(Configuration)\ 83 | false 84 | $(ProjectName) 85 | 86 | 87 | false 88 | $(ProjectName) 89 | $(SolutionDir)Intermediate\$(ProjectName)\$(Platform)\$(Configuration)\ 90 | 91 | 92 | 93 | Disabled 94 | ENABLE_ARIB_STD_B1;ENABLE_ARIB_STREAM_TEST;ENABLE_MULTI2_SIMD;USE_BENCHMARK;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 95 | true 96 | EnableFastChecks 97 | MultiThreadedDebug 98 | 99 | Level3 100 | EditAndContinue 101 | /source-charset:utf-8 %(AdditionalOptions) 102 | 103 | 104 | winscard.lib;%(AdditionalDependencies) 105 | $(OutDir)$(TargetName)$(TargetExt) 106 | Debug 107 | Console 108 | MachineX86 109 | 110 | 111 | 112 | 113 | 114 | Disabled 115 | ENABLE_ARIB_STD_B1;ENABLE_ARIB_STREAM_TEST;ENABLE_MULTI2_SIMD;USE_BENCHMARK;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 116 | EnableFastChecks 117 | MultiThreadedDebug 118 | 119 | 120 | Level3 121 | ProgramDatabase 122 | /source-charset:utf-8 %(AdditionalOptions) 123 | 124 | 125 | winscard.lib;%(AdditionalDependencies) 126 | $(OutDir)$(TargetName)$(TargetExt) 127 | Debug 128 | Console 129 | 130 | 131 | 132 | 133 | ENABLE_ARIB_STD_B1;ENABLE_ARIB_STREAM_TEST;ENABLE_MULTI2_SIMD;USE_BENCHMARK;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 134 | MultiThreadedDLL 135 | 136 | Level3 137 | ProgramDatabase 138 | MaxSpeed 139 | AnySuitable 140 | true 141 | Speed 142 | true 143 | false 144 | true 145 | Fast 146 | /source-charset:utf-8 %(AdditionalOptions) 147 | 148 | 149 | winscard.lib;%(AdditionalDependencies) 150 | $(OutDir)$(TargetName)$(TargetExt) 151 | false 152 | Console 153 | true 154 | true 155 | MachineX86 156 | UseLinkTimeCodeGeneration 157 | 158 | 159 | 160 | 161 | ENABLE_ARIB_STD_B1;ENABLE_ARIB_STREAM_TEST;ENABLE_MULTI2_SIMD;USE_BENCHMARK;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 162 | MultiThreadedDLL 163 | 164 | 165 | Level3 166 | ProgramDatabase 167 | MaxSpeed 168 | AnySuitable 169 | true 170 | Speed 171 | true 172 | false 173 | true 174 | Fast 175 | /source-charset:utf-8 %(AdditionalOptions) 176 | 177 | 178 | winscard.lib;%(AdditionalDependencies) 179 | $(OutDir)$(TargetName)$(TargetExt) 180 | false 181 | Console 182 | true 183 | true 184 | UseLinkTimeCodeGeneration 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | --------------------------------------------------------------------------------