├── src ├── constants │ ├── mod.rs │ ├── crc_u8.rs │ ├── crc_u64.rs │ ├── crc_u16.rs │ └── crc_u32.rs ├── lookup_table.rs ├── crc_u64.rs ├── crc_u8.rs ├── crc_u32.rs └── crc_u16.rs ├── .github ├── dependabot.yml └── workflows │ ├── ci-version.yml │ └── ci.yml ├── Cargo.toml ├── LICENSE ├── rustfmt.toml ├── tests ├── alloc.rs └── heapless.rs ├── .gitignore ├── README.md └── benches └── bench.rs /src/constants/mod.rs: -------------------------------------------------------------------------------- 1 | pub(crate) mod crc_u16; 2 | pub(crate) mod crc_u32; 3 | pub(crate) mod crc_u64; 4 | pub(crate) mod crc_u8; 5 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "github-actions" 4 | directory: "/" 5 | schedule: 6 | interval: "weekly" 7 | - package-ecosystem: "cargo" 8 | directory: "/" 9 | schedule: 10 | interval: "weekly" 11 | -------------------------------------------------------------------------------- /src/lookup_table.rs: -------------------------------------------------------------------------------- 1 | /// This enum hold lookup table for static know or dynamic created table 2 | pub(crate) enum LookUpTable { 3 | Static(&'static [T]), 4 | Dynamic([T; 256]), 5 | } 6 | 7 | impl core::ops::Deref for LookUpTable { 8 | type Target = [T]; 9 | 10 | fn deref(&self) -> &[T] { 11 | match *self { 12 | LookUpTable::Static(s) => s, 13 | LookUpTable::Dynamic(ref d) => d, 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "crc-any" 3 | version = "2.5.0" 4 | authors = ["Magic Len "] 5 | edition = "2021" 6 | rust-version = "1.60" 7 | repository = "https://github.com/magiclen/crc-any" 8 | homepage = "https://magiclen.org/crc-any" 9 | keywords = ["hash", "crc", "crc16", "crc32", "crc64"] 10 | categories = ["no-std", "algorithms"] 11 | description = "To compute CRC values by providing the length of bits, expression, reflection, an initial value and a final xor value. It has many built-in CRC functions." 12 | license = "MIT" 13 | include = ["src/**/*", "Cargo.toml", "README.md", "LICENSE", "benches/bench.rs"] 14 | 15 | [dependencies] 16 | 17 | [dependencies.debug-helper] 18 | version = "0.3" 19 | optional = true 20 | 21 | [dependencies.heapless] 22 | version = "0.8" 23 | optional = true 24 | 25 | [dev-dependencies] 26 | bencher = "0.1.5" 27 | 28 | [features] 29 | default = ["alloc"] 30 | alloc = ["debug-helper"] 31 | std = [] 32 | development = ["std"] 33 | 34 | [[bench]] 35 | name = "bench" 36 | harness = false 37 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 magiclen.org (Ron Li) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /.github/workflows/ci-version.yml: -------------------------------------------------------------------------------- 1 | name: CI-version 2 | 3 | on: 4 | push: 5 | tags: 6 | - "v*" 7 | 8 | env: 9 | CARGO_TERM_COLOR: always 10 | 11 | jobs: 12 | tests: 13 | strategy: 14 | fail-fast: false 15 | matrix: 16 | os: 17 | - ubuntu-latest 18 | - macos-latest 19 | - windows-latest 20 | toolchain: 21 | - stable 22 | - nightly 23 | features: 24 | - 25 | - --features heapless 26 | - --no-default-features 27 | - --no-default-features --features heapless 28 | name: Test ${{ matrix.toolchain }} on ${{ matrix.os }} (${{ matrix.features }}) 29 | runs-on: ${{ matrix.os }} 30 | steps: 31 | - uses: actions/checkout@v4 32 | - uses: actions-rust-lang/setup-rust-toolchain@v1 33 | with: 34 | toolchain: ${{ matrix.toolchain }} 35 | - run: cargo test --release ${{ matrix.features }} 36 | - run: cargo doc --release ${{ matrix.features }} 37 | 38 | MSRV: 39 | strategy: 40 | fail-fast: false 41 | matrix: 42 | os: 43 | - ubuntu-latest 44 | - macos-latest 45 | - windows-latest 46 | toolchain: 47 | - "1.60" 48 | features: 49 | - 50 | - --features heapless 51 | - --no-default-features 52 | - --no-default-features --features heapless 53 | name: Test ${{ matrix.toolchain }} on ${{ matrix.os }} (${{ matrix.features }}) 54 | runs-on: ${{ matrix.os }} 55 | steps: 56 | - uses: actions/checkout@v4 57 | - uses: actions-rust-lang/setup-rust-toolchain@v1 58 | with: 59 | toolchain: ${{ matrix.toolchain }} 60 | - run: cargo test --release --lib --bins ${{ matrix.features }} -------------------------------------------------------------------------------- /rustfmt.toml: -------------------------------------------------------------------------------- 1 | # array_width = 60 2 | # attr_fn_like_width = 70 3 | binop_separator = "Front" 4 | blank_lines_lower_bound = 0 5 | blank_lines_upper_bound = 1 6 | brace_style = "PreferSameLine" 7 | # chain_width = 60 8 | color = "Auto" 9 | # comment_width = 100 10 | condense_wildcard_suffixes = true 11 | control_brace_style = "AlwaysSameLine" 12 | empty_item_single_line = true 13 | enum_discrim_align_threshold = 80 14 | error_on_line_overflow = false 15 | error_on_unformatted = false 16 | # fn_call_width = 60 17 | fn_params_layout = "Tall" 18 | fn_single_line = false 19 | force_explicit_abi = true 20 | force_multiline_blocks = false 21 | format_code_in_doc_comments = true 22 | doc_comment_code_block_width = 80 23 | format_generated_files = true 24 | format_macro_matchers = true 25 | format_macro_bodies = true 26 | skip_macro_invocations = [] 27 | format_strings = true 28 | hard_tabs = false 29 | hex_literal_case = "Upper" 30 | imports_indent = "Block" 31 | imports_layout = "Mixed" 32 | indent_style = "Block" 33 | inline_attribute_width = 0 34 | match_arm_blocks = true 35 | match_arm_leading_pipes = "Never" 36 | match_block_trailing_comma = true 37 | max_width = 100 38 | merge_derives = true 39 | imports_granularity = "Crate" 40 | newline_style = "Unix" 41 | normalize_comments = false 42 | normalize_doc_attributes = true 43 | overflow_delimited_expr = true 44 | remove_nested_parens = true 45 | reorder_impl_items = true 46 | reorder_imports = true 47 | group_imports = "StdExternalCrate" 48 | reorder_modules = true 49 | short_array_element_width_threshold = 10 50 | # single_line_if_else_max_width = 50 51 | space_after_colon = true 52 | space_before_colon = false 53 | spaces_around_ranges = false 54 | struct_field_align_threshold = 80 55 | struct_lit_single_line = false 56 | # struct_lit_width = 18 57 | # struct_variant_width = 35 58 | tab_spaces = 4 59 | trailing_comma = "Vertical" 60 | trailing_semicolon = true 61 | type_punctuation_density = "Wide" 62 | use_field_init_shorthand = true 63 | use_small_heuristics = "Max" 64 | use_try_shorthand = true 65 | where_single_line = false 66 | wrap_comments = false -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: [push, pull_request] 4 | 5 | env: 6 | CARGO_TERM_COLOR: always 7 | 8 | jobs: 9 | rustfmt: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - uses: actions/checkout@v4 13 | - uses: actions-rust-lang/setup-rust-toolchain@v1 14 | with: 15 | toolchain: nightly 16 | components: rustfmt 17 | - uses: actions-rust-lang/rustfmt@v1 18 | 19 | clippy: 20 | runs-on: ubuntu-latest 21 | steps: 22 | - uses: actions/checkout@v4 23 | - uses: actions-rust-lang/setup-rust-toolchain@v1 24 | with: 25 | components: clippy 26 | - run: cargo clippy --all-targets --all-features -- -D warnings 27 | 28 | tests: 29 | strategy: 30 | fail-fast: false 31 | matrix: 32 | os: 33 | - ubuntu-latest 34 | - macos-latest 35 | - windows-latest 36 | toolchain: 37 | - stable 38 | - nightly 39 | features: 40 | - 41 | - --features heapless 42 | - --no-default-features 43 | - --no-default-features --features heapless 44 | name: Test ${{ matrix.toolchain }} on ${{ matrix.os }} (${{ matrix.features }}) 45 | runs-on: ${{ matrix.os }} 46 | steps: 47 | - uses: actions/checkout@v4 48 | - uses: actions-rust-lang/setup-rust-toolchain@v1 49 | with: 50 | toolchain: ${{ matrix.toolchain }} 51 | - run: cargo test ${{ matrix.features }} 52 | - run: cargo doc ${{ matrix.features }} 53 | 54 | MSRV: 55 | strategy: 56 | fail-fast: false 57 | matrix: 58 | os: 59 | - ubuntu-latest 60 | - macos-latest 61 | - windows-latest 62 | toolchain: 63 | - "1.60" 64 | features: 65 | - 66 | - --features heapless 67 | - --no-default-features 68 | - --no-default-features --features heapless 69 | name: Test ${{ matrix.toolchain }} on ${{ matrix.os }} (${{ matrix.features }}) 70 | runs-on: ${{ matrix.os }} 71 | steps: 72 | - uses: actions/checkout@v4 73 | - uses: actions-rust-lang/setup-rust-toolchain@v1 74 | with: 75 | toolchain: ${{ matrix.toolchain }} 76 | - run: cargo test --lib --bins ${{ matrix.features }} -------------------------------------------------------------------------------- /tests/alloc.rs: -------------------------------------------------------------------------------- 1 | #![cfg(feature = "alloc")] 2 | 3 | use crc_any::{CRCu16, CRCu32, CRCu64, CRC}; 4 | 5 | #[test] 6 | fn crc() { 7 | let mut crc = CRC::crc64we(); 8 | 9 | crc.digest(b"https://magiclen.org"); 10 | 11 | assert_eq!(vec![19, 252, 181, 71, 9, 46, 100, 182], crc.get_crc_vec_be()); 12 | assert_eq!(vec![182, 100, 46, 9, 71, 181, 252, 19], crc.get_crc_vec_le()); 13 | 14 | let mut crc = CRC::crc32c(); 15 | 16 | crc.digest(b"https://magiclen.org"); 17 | 18 | assert_eq!(vec![62, 60, 217, 231], crc.get_crc_vec_be()); 19 | assert_eq!(vec![231, 217, 60, 62], crc.get_crc_vec_le()); 20 | 21 | let mut crc = CRC::crc16cdma2000(); 22 | 23 | crc.digest(b"https://magiclen.org"); 24 | 25 | assert_eq!(vec![191, 108], crc.get_crc_vec_be()); 26 | assert_eq!(vec![108, 191], crc.get_crc_vec_le()); 27 | 28 | let mut crc = CRC::crc8cdma2000(); 29 | 30 | crc.digest(b"https://magiclen.org"); 31 | 32 | assert_eq!(vec![169], crc.get_crc_vec_be()); 33 | assert_eq!(vec![169], crc.get_crc_vec_le()); 34 | } 35 | 36 | #[test] 37 | fn crc_u16() { 38 | let mut crc = CRCu16::crc16(); 39 | 40 | crc.digest(b"https://magiclen.org"); 41 | 42 | assert_eq!(vec![77, 150], crc.get_crc_vec_be()); 43 | assert_eq!(vec![150, 77], crc.get_crc_vec_le()); 44 | } 45 | 46 | #[test] 47 | fn crc_u32() { 48 | let mut crc = CRCu32::crc32(); 49 | 50 | crc.digest(b"https://magiclen.org"); 51 | 52 | assert_eq!(vec![157, 140, 116, 114], crc.get_crc_vec_be()); 53 | assert_eq!(vec![114, 116, 140, 157], crc.get_crc_vec_le()); 54 | 55 | let mut crc = CRCu32::crc24(); 56 | 57 | crc.digest(b"https://magiclen.org"); 58 | 59 | assert_eq!(vec![59, 98, 20], crc.get_crc_vec_be()); 60 | assert_eq!(vec![20, 98, 59], crc.get_crc_vec_le()); 61 | } 62 | 63 | #[test] 64 | fn crc_u64() { 65 | let mut crc = CRCu64::crc64(); 66 | 67 | crc.digest(b"https://magiclen.org"); 68 | 69 | assert_eq!(vec![46, 219, 104, 85, 36, 10, 96, 248], crc.get_crc_vec_be()); 70 | assert_eq!(vec![248, 96, 10, 36, 85, 104, 219, 46], crc.get_crc_vec_le()); 71 | 72 | let mut crc = CRCu64::crc40gsm(); 73 | 74 | crc.digest(b"https://magiclen.org"); 75 | 76 | assert_eq!(vec![90, 94, 5, 195, 152], crc.get_crc_vec_be()); 77 | assert_eq!(vec![152, 195, 5, 94, 90], crc.get_crc_vec_le()); 78 | } 79 | -------------------------------------------------------------------------------- /tests/heapless.rs: -------------------------------------------------------------------------------- 1 | #![cfg(feature = "heapless")] 2 | 3 | use crc_any::{CRCu16, CRCu32, CRCu64, CRC}; 4 | 5 | #[test] 6 | fn crc() { 7 | let mut crc = CRC::crc64(); 8 | 9 | crc.digest(b"https://magiclen.org"); 10 | 11 | assert_eq!(vec![46, 219, 104, 85, 36, 10, 96, 248], crc.get_crc_heapless_vec_be().to_vec()); 12 | assert_eq!(vec![248, 96, 10, 36, 85, 104, 219, 46], crc.get_crc_heapless_vec_le().to_vec()); 13 | 14 | let mut crc = CRC::crc32(); 15 | 16 | crc.digest(b"https://magiclen.org"); 17 | 18 | assert_eq!(vec![157, 140, 116, 114], crc.get_crc_heapless_vec_be().to_vec()); 19 | assert_eq!(vec![114, 116, 140, 157], crc.get_crc_heapless_vec_le().to_vec()); 20 | 21 | let mut crc = CRC::crc16(); 22 | 23 | crc.digest(b"https://magiclen.org"); 24 | 25 | assert_eq!(vec![77, 150], crc.get_crc_heapless_vec_be().to_vec()); 26 | assert_eq!(vec![150, 77], crc.get_crc_heapless_vec_le().to_vec()); 27 | 28 | let mut crc = CRC::crc8(); 29 | 30 | crc.digest(b"https://magiclen.org"); 31 | 32 | assert_eq!(vec![45], crc.get_crc_heapless_vec_be().to_vec()); 33 | assert_eq!(vec![45], crc.get_crc_heapless_vec_le().to_vec()); 34 | } 35 | 36 | #[test] 37 | fn crc_u16() { 38 | let mut crc = CRCu16::crc16(); 39 | 40 | crc.digest(b"https://magiclen.org"); 41 | 42 | assert_eq!(vec![77, 150], crc.get_crc_heapless_vec_be().to_vec()); 43 | assert_eq!(vec![150, 77], crc.get_crc_heapless_vec_le().to_vec()); 44 | } 45 | 46 | #[test] 47 | fn crc_u32() { 48 | let mut crc = CRCu32::crc32(); 49 | 50 | crc.digest(b"https://magiclen.org"); 51 | 52 | assert_eq!(vec![157, 140, 116, 114], crc.get_crc_heapless_vec_be().to_vec()); 53 | assert_eq!(vec![114, 116, 140, 157], crc.get_crc_heapless_vec_le().to_vec()); 54 | 55 | let mut crc = CRCu32::crc24(); 56 | 57 | crc.digest(b"https://magiclen.org"); 58 | 59 | assert_eq!(vec![59, 98, 20], crc.get_crc_heapless_vec_be().to_vec()); 60 | assert_eq!(vec![20, 98, 59], crc.get_crc_heapless_vec_le().to_vec()); 61 | } 62 | 63 | #[test] 64 | fn crc_u64() { 65 | let mut crc = CRCu64::crc64(); 66 | 67 | crc.digest(b"https://magiclen.org"); 68 | 69 | assert_eq!(vec![46, 219, 104, 85, 36, 10, 96, 248], crc.get_crc_heapless_vec_be().to_vec()); 70 | assert_eq!(vec![248, 96, 10, 36, 85, 104, 219, 46], crc.get_crc_heapless_vec_le().to_vec()); 71 | 72 | let mut crc = CRCu64::crc40gsm(); 73 | 74 | crc.digest(b"https://magiclen.org"); 75 | 76 | assert_eq!(vec![90, 94, 5, 195, 152], crc.get_crc_heapless_vec_be().to_vec()); 77 | assert_eq!(vec![152, 195, 5, 94, 90], crc.get_crc_heapless_vec_le().to_vec()); 78 | } 79 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ### Intellij+all ### 2 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider 3 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 4 | 5 | # User-specific stuff 6 | .idea/**/workspace.xml 7 | .idea/**/tasks.xml 8 | .idea/**/usage.statistics.xml 9 | .idea/**/dictionaries 10 | .idea/**/shelf 11 | 12 | # AWS User-specific 13 | .idea/**/aws.xml 14 | 15 | # Generated files 16 | .idea/**/contentModel.xml 17 | 18 | # Sensitive or high-churn files 19 | .idea/**/dataSources/ 20 | .idea/**/dataSources.ids 21 | .idea/**/dataSources.local.xml 22 | .idea/**/sqlDataSources.xml 23 | .idea/**/dynamic.xml 24 | .idea/**/uiDesigner.xml 25 | .idea/**/dbnavigator.xml 26 | 27 | # Gradle 28 | .idea/**/gradle.xml 29 | .idea/**/libraries 30 | 31 | # Gradle and Maven with auto-import 32 | # When using Gradle or Maven with auto-import, you should exclude module files, 33 | # since they will be recreated, and may cause churn. Uncomment if using 34 | # auto-import. 35 | # .idea/artifacts 36 | # .idea/compiler.xml 37 | # .idea/jarRepositories.xml 38 | # .idea/modules.xml 39 | # .idea/*.iml 40 | # .idea/modules 41 | # *.iml 42 | # *.ipr 43 | 44 | # CMake 45 | cmake-build-*/ 46 | 47 | # Mongo Explorer plugin 48 | .idea/**/mongoSettings.xml 49 | 50 | # File-based project format 51 | *.iws 52 | 53 | # IntelliJ 54 | out/ 55 | 56 | # mpeltonen/sbt-idea plugin 57 | .idea_modules/ 58 | 59 | # JIRA plugin 60 | atlassian-ide-plugin.xml 61 | 62 | # Cursive Clojure plugin 63 | .idea/replstate.xml 64 | 65 | # SonarLint plugin 66 | .idea/sonarlint/ 67 | 68 | # Crashlytics plugin (for Android Studio and IntelliJ) 69 | com_crashlytics_export_strings.xml 70 | crashlytics.properties 71 | crashlytics-build.properties 72 | fabric.properties 73 | 74 | # Editor-based Rest Client 75 | .idea/httpRequests 76 | 77 | # Android studio 3.1+ serialized cache file 78 | .idea/caches/build_file_checksums.ser 79 | 80 | ### Intellij+all Patch ### 81 | # Ignore everything but code style settings and run configurations 82 | # that are supposed to be shared within teams. 83 | 84 | .idea/* 85 | 86 | !.idea/codeStyles 87 | !.idea/runConfigurations 88 | 89 | ### Rust ### 90 | # Generated by Cargo 91 | # will have compiled files and executables 92 | debug/ 93 | target/ 94 | 95 | # Remove Cargo.lock from gitignore if creating an executable, leave it for libraries 96 | # More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html 97 | Cargo.lock 98 | 99 | # These are backup files generated by rustfmt 100 | **/*.rs.bk 101 | 102 | # MSVC Windows builds of rustc generate these, which store debugging information 103 | *.pdb 104 | 105 | ### Vim ### 106 | # Swap 107 | [._]*.s[a-v][a-z] 108 | !*.svg # comment out if you don't need vector files 109 | [._]*.sw[a-p] 110 | [._]s[a-rt-v][a-z] 111 | [._]ss[a-gi-z] 112 | [._]sw[a-p] 113 | 114 | # Session 115 | Session.vim 116 | Sessionx.vim 117 | 118 | # Temporary 119 | .netrwhist 120 | *~ 121 | # Auto-generated tag files 122 | tags 123 | # Persistent undo 124 | [._]*.un~ 125 | 126 | ### VisualStudioCode ### 127 | .vscode/* 128 | !.vscode/settings.json 129 | !.vscode/tasks.json 130 | !.vscode/launch.json 131 | !.vscode/extensions.json 132 | !.vscode/*.code-snippets 133 | 134 | # Local History for Visual Studio Code 135 | .history/ 136 | 137 | # Built Visual Studio Code Extensions 138 | *.vsix 139 | 140 | ### VisualStudioCode Patch ### 141 | # Ignore all local history of files 142 | .history 143 | .ionide -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | CRC Any 2 | ==================== 3 | 4 | [![CI](https://github.com/magiclen/crc-any/actions/workflows/ci.yml/badge.svg)](https://github.com/magiclen/crc-any/actions/workflows/ci.yml) 5 | 6 | To compute CRC values by providing the length of bits, expression, reflection, an initial value and a final xor value. It has many built-in CRC functions. 7 | 8 | ## Usage 9 | 10 | You can use `create_crc` associated function to create a CRC instance by providing the length of bits, expression, reflection, an initial value and a final xor value. For example, if you want to compute a CRC-24 value. 11 | 12 | ```rust 13 | use crc_any::CRC; 14 | 15 | let mut crc24 = CRC::create_crc(0x0000000000864CFB, 24, 0x0000000000B704CE, 0x0000000000000000, false); 16 | 17 | crc24.digest(b"hello"); 18 | 19 | assert_eq!([71, 245, 138].to_vec(), crc24.get_crc_vec_be()); 20 | assert_eq!("0x47F58A", &crc24.to_string()); 21 | ``` 22 | 23 | To simplify the usage, there are several common versions of CRC whose computing functions are already built-in. 24 | 25 | * crc3gsm 26 | * crc4itu 27 | * crc4interlaken 28 | * crc5epc 29 | * crc5itu 30 | * crc5usb 31 | * crc6cdma2000_a 32 | * crc6cdma2000_b 33 | * crc6darc 34 | * crc6gsm 35 | * crc6itu 36 | * crc7 37 | * crc7umts 38 | * crc8 39 | * crc8cdma2000 40 | * crc8darc 41 | * crc8dvb_s2 42 | * crc8ebu 43 | * crc8icode 44 | * crc8itu 45 | * crc8maxim 46 | * crc8rohc 47 | * crc8wcdma 48 | * crc10 49 | * crc10cdma2000 50 | * crc10gsm 51 | * crc11 52 | * crc12 53 | * crc12cdma2000 54 | * crc12gsm 55 | * crc13bbc 56 | * crc14darc 57 | * crc14gsm 58 | * crc15can 59 | * crc15mpt1327 60 | * crc16 61 | * crc16ccitt_false 62 | * crc16aug_ccitt 63 | * crc16buypass 64 | * crc16cdma2000 65 | * crc16dds_110 66 | * crc16dect_r 67 | * crc16dect_x 68 | * crc16dnp 69 | * crc16en_13757 70 | * crc16genibus 71 | * crc16maxim 72 | * crc16mcrf4cc 73 | * crc16riello 74 | * crc16t10_dif 75 | * crc16teledisk 76 | * crc16tms13157 77 | * crc16usb 78 | * crc_a 79 | * crc16kermit 80 | * crc16modbus 81 | * crc16_x25 82 | * crc16xmodem 83 | * crc17can 84 | * crc21can 85 | * crc24 86 | * crc24ble 87 | * crc24flexray_a 88 | * crc24flexray_b 89 | * crc24lte_a 90 | * crc24lte_b 91 | * crc24os9 92 | * crc30cdma 93 | * crc32 94 | * It also called `crc32b` in `mhash`. 95 | * crc32mhash 96 | * `mhash` is a common library which has two weird versions of CRC32 called `crc32` and `crc32b`. `crc32` and `crc32mhash` in this module are `crc32b` and `crc32` in mhash respectively. 97 | * crc32bzip2 98 | * crc32c 99 | * crc32d 100 | * crc32mpeg2 101 | * crc32posix 102 | * crc32q 103 | * crc32jamcrc 104 | * crc32xfer 105 | * crc40gsm 106 | * crc64 107 | * crc64iso 108 | * crc64we 109 | * crc64jones 110 | 111 | For instance, 112 | 113 | ```rust 114 | use crc_any::CRC; 115 | 116 | let mut crc64 = CRC::crc64(); 117 | 118 | crc64.digest(b"hello"); 119 | 120 | assert_eq!([64, 84, 74, 48, 97, 55, 182, 236].to_vec(), crc64.get_crc_vec_be()); 121 | assert_eq!("0x40544A306137B6EC", &crc64.to_string()); 122 | ``` 123 | 124 | After getting a CRC value, you can still use the `digest` method to continue computing the next CRC values. 125 | 126 | ## Heapless Support 127 | 128 | To make sure this crate will not use heap memory allocation, you can disable the default features. 129 | 130 | ```toml 131 | [dependencies.crc-any] 132 | version = "*" 133 | default-features = false 134 | ``` 135 | 136 | After doing that, the `get_crc_vec_be` and `get_crc_vec_le` methods can not be used. But if you still need this crate to return a `Vec` without dynamic allocation, you can enable the `heapless` feature to make the `get_crc_heapless_vec_be` and `get_crc_heapless_vec_le` methods available. 137 | 138 | ```toml 139 | [dependencies.crc-any] 140 | version = "*" 141 | default-features = false 142 | features = ["heapless"] 143 | ``` 144 | 145 | ## Crates.io 146 | 147 | https://crates.io/crates/crc-any 148 | 149 | ## Documentation 150 | 151 | https://docs.rs/crc-any 152 | 153 | ## License 154 | 155 | [MIT](LICENSE) 156 | -------------------------------------------------------------------------------- /benches/bench.rs: -------------------------------------------------------------------------------- 1 | use bencher::{benchmark_group, benchmark_main, Bencher}; 2 | use crc_any::CRC; 3 | 4 | fn crc8_construct(bencher: &mut Bencher) { 5 | bencher.iter(|| CRC::create_crc(0x07, 8, 0x00, 0x00, false)) 6 | } 7 | 8 | fn crc8_update_megabytes(bencher: &mut Bencher) { 9 | let mut crc = CRC::crc8(); 10 | let mut bytes = Vec::with_capacity(1000000); 11 | 12 | #[allow(clippy::uninit_vec)] 13 | unsafe { 14 | bytes.set_len(1000000); 15 | } 16 | 17 | bencher.iter(|| { 18 | crc.digest(&bytes); 19 | 20 | crc.get_crc() 21 | }) 22 | } 23 | 24 | fn crc12_construct(bencher: &mut Bencher) { 25 | bencher.iter(|| CRC::create_crc(0x080F, 12, 0x0000, 0x0000, false)) 26 | } 27 | 28 | fn crc12_update_megabytes(bencher: &mut Bencher) { 29 | let mut crc = CRC::crc12(); 30 | let mut bytes = Vec::with_capacity(1000000); 31 | 32 | #[allow(clippy::uninit_vec)] 33 | unsafe { 34 | bytes.set_len(1000000); 35 | } 36 | 37 | bencher.iter(|| { 38 | crc.digest(&bytes); 39 | 40 | crc.get_crc() 41 | }) 42 | } 43 | 44 | fn crc16_construct(bencher: &mut Bencher) { 45 | bencher.iter(|| CRC::create_crc(0xA001, 16, 0x0000, 0x0000, true)) 46 | } 47 | 48 | fn crc16_update_megabytes(bencher: &mut Bencher) { 49 | let mut crc = CRC::crc16(); 50 | let mut bytes = Vec::with_capacity(1000000); 51 | 52 | #[allow(clippy::uninit_vec)] 53 | unsafe { 54 | bytes.set_len(1000000); 55 | } 56 | 57 | bencher.iter(|| { 58 | crc.digest(&bytes); 59 | 60 | crc.get_crc() 61 | }) 62 | } 63 | 64 | fn crc16_construct_wellknown(bencher: &mut Bencher) { 65 | bencher.iter(crc_any::CRCu16::crc16ccitt_false) 66 | } 67 | 68 | fn crc16_update_megabytes_wellknown(bencher: &mut Bencher) { 69 | let mut crc = crc_any::CRCu16::crc16ccitt_false(); 70 | let mut bytes = Vec::with_capacity(1000000); 71 | 72 | #[allow(clippy::uninit_vec)] 73 | unsafe { 74 | bytes.set_len(1000000); 75 | } 76 | 77 | bencher.iter(|| { 78 | crc.digest(&bytes); 79 | 80 | crc.get_crc() 81 | }) 82 | } 83 | 84 | fn crc32_construct(bencher: &mut Bencher) { 85 | bencher.iter(|| CRC::create_crc(0xEDB88320, 32, 0xFFFFFFFF, 0xFFFFFFFF, true)) 86 | } 87 | 88 | fn crc32_update_megabytes(bencher: &mut Bencher) { 89 | let mut crc = CRC::crc32(); 90 | let mut bytes = Vec::with_capacity(1000000); 91 | 92 | #[allow(clippy::uninit_vec)] 93 | unsafe { 94 | bytes.set_len(1000000); 95 | } 96 | 97 | bencher.iter(|| { 98 | crc.digest(&bytes); 99 | 100 | crc.get_crc() 101 | }) 102 | } 103 | 104 | fn crc64_construct(bencher: &mut Bencher) { 105 | bencher.iter(|| { 106 | CRC::create_crc(0x42F0E1EBA9EA3693, 64, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, false) 107 | }) 108 | } 109 | 110 | fn crc64_update_megabytes(bencher: &mut Bencher) { 111 | let mut crc = CRC::crc64(); 112 | let mut bytes = Vec::with_capacity(1000000); 113 | 114 | #[allow(clippy::uninit_vec)] 115 | unsafe { 116 | bytes.set_len(1000000); 117 | } 118 | 119 | bencher.iter(|| { 120 | crc.digest(&bytes); 121 | 122 | crc.get_crc() 123 | }) 124 | } 125 | 126 | fn crc64_construct_wellknown(bencher: &mut Bencher) { 127 | bencher.iter(crc_any::CRCu64::crc64iso) 128 | } 129 | 130 | fn crc64_update_megabytes_wellknown(bencher: &mut Bencher) { 131 | let mut crc = CRC::crc64(); 132 | let mut bytes = Vec::with_capacity(1000000); 133 | 134 | #[allow(clippy::uninit_vec)] 135 | unsafe { 136 | bytes.set_len(1000000); 137 | } 138 | 139 | bencher.iter(|| { 140 | crc.digest(&bytes); 141 | 142 | crc.get_crc() 143 | }) 144 | } 145 | 146 | benchmark_group!(crc8, crc8_construct, crc8_update_megabytes); 147 | benchmark_group!(crc12, crc12_construct, crc12_update_megabytes); 148 | benchmark_group!(crc16, crc16_construct, crc16_update_megabytes); 149 | benchmark_group!(crc16_wellknown, crc16_construct_wellknown, crc16_update_megabytes_wellknown); 150 | benchmark_group!(crc32, crc32_construct, crc32_update_megabytes); 151 | benchmark_group!(crc64, crc64_construct, crc64_update_megabytes); 152 | benchmark_group!(crc64_wellknown, crc64_construct_wellknown, crc64_update_megabytes_wellknown); 153 | 154 | benchmark_main!(crc8, crc12, crc16, crc16_wellknown, crc32, crc64, crc64_wellknown); 155 | -------------------------------------------------------------------------------- /src/constants/crc_u8.rs: -------------------------------------------------------------------------------- 1 | #[rustfmt::skip] 2 | #[allow(clippy::unreadable_literal)] 3 | pub(crate) const NO_REF_8_07: [u8; 256] = [0u8, 7u8, 14u8, 9u8, 28u8, 27u8, 18u8, 21u8, 56u8, 63u8, 54u8, 49u8, 36u8, 35u8, 42u8, 45u8, 112u8, 119u8, 126u8, 121u8, 108u8, 107u8, 98u8, 101u8, 72u8, 79u8, 70u8, 65u8, 84u8, 83u8, 90u8, 93u8, 224u8, 231u8, 238u8, 233u8, 252u8, 251u8, 242u8, 245u8, 216u8, 223u8, 214u8, 209u8, 196u8, 195u8, 202u8, 205u8, 144u8, 151u8, 158u8, 153u8, 140u8, 139u8, 130u8, 133u8, 168u8, 175u8, 166u8, 161u8, 180u8, 179u8, 186u8, 189u8, 199u8, 192u8, 201u8, 206u8, 219u8, 220u8, 213u8, 210u8, 255u8, 248u8, 241u8, 246u8, 227u8, 228u8, 237u8, 234u8, 183u8, 176u8, 185u8, 190u8, 171u8, 172u8, 165u8, 162u8, 143u8, 136u8, 129u8, 134u8, 147u8, 148u8, 157u8, 154u8, 39u8, 32u8, 41u8, 46u8, 59u8, 60u8, 53u8, 50u8, 31u8, 24u8, 17u8, 22u8, 3u8, 4u8, 13u8, 10u8, 87u8, 80u8, 89u8, 94u8, 75u8, 76u8, 69u8, 66u8, 111u8, 104u8, 97u8, 102u8, 115u8, 116u8, 125u8, 122u8, 137u8, 142u8, 135u8, 128u8, 149u8, 146u8, 155u8, 156u8, 177u8, 182u8, 191u8, 184u8, 173u8, 170u8, 163u8, 164u8, 249u8, 254u8, 247u8, 240u8, 229u8, 226u8, 235u8, 236u8, 193u8, 198u8, 207u8, 200u8, 221u8, 218u8, 211u8, 212u8, 105u8, 110u8, 103u8, 96u8, 117u8, 114u8, 123u8, 124u8, 81u8, 86u8, 95u8, 88u8, 77u8, 74u8, 67u8, 68u8, 25u8, 30u8, 23u8, 16u8, 5u8, 2u8, 11u8, 12u8, 33u8, 38u8, 47u8, 40u8, 61u8, 58u8, 51u8, 52u8, 78u8, 73u8, 64u8, 71u8, 82u8, 85u8, 92u8, 91u8, 118u8, 113u8, 120u8, 127u8, 106u8, 109u8, 100u8, 99u8, 62u8, 57u8, 48u8, 55u8, 34u8, 37u8, 44u8, 43u8, 6u8, 1u8, 8u8, 15u8, 26u8, 29u8, 20u8, 19u8, 174u8, 169u8, 160u8, 167u8, 178u8, 181u8, 188u8, 187u8, 150u8, 145u8, 152u8, 159u8, 138u8, 141u8, 132u8, 131u8, 222u8, 217u8, 208u8, 215u8, 194u8, 197u8, 204u8, 203u8, 230u8, 225u8, 232u8, 239u8, 250u8, 253u8, 244u8, 243u8]; 4 | 5 | #[rustfmt::skip] 6 | pub(crate) const NO_REF_8_1D: [u8; 256] = [0u8, 29u8, 58u8, 39u8, 116u8, 105u8, 78u8, 83u8, 232u8, 245u8, 210u8, 207u8, 156u8, 129u8, 166u8, 187u8, 205u8, 208u8, 247u8, 234u8, 185u8, 164u8, 131u8, 158u8, 37u8, 56u8, 31u8, 2u8, 81u8, 76u8, 107u8, 118u8, 135u8, 154u8, 189u8, 160u8, 243u8, 238u8, 201u8, 212u8, 111u8, 114u8, 85u8, 72u8, 27u8, 6u8, 33u8, 60u8, 74u8, 87u8, 112u8, 109u8, 62u8, 35u8, 4u8, 25u8, 162u8, 191u8, 152u8, 133u8, 214u8, 203u8, 236u8, 241u8, 19u8, 14u8, 41u8, 52u8, 103u8, 122u8, 93u8, 64u8, 251u8, 230u8, 193u8, 220u8, 143u8, 146u8, 181u8, 168u8, 222u8, 195u8, 228u8, 249u8, 170u8, 183u8, 144u8, 141u8, 54u8, 43u8, 12u8, 17u8, 66u8, 95u8, 120u8, 101u8, 148u8, 137u8, 174u8, 179u8, 224u8, 253u8, 218u8, 199u8, 124u8, 97u8, 70u8, 91u8, 8u8, 21u8, 50u8, 47u8, 89u8, 68u8, 99u8, 126u8, 45u8, 48u8, 23u8, 10u8, 177u8, 172u8, 139u8, 150u8, 197u8, 216u8, 255u8, 226u8, 38u8, 59u8, 28u8, 1u8, 82u8, 79u8, 104u8, 117u8, 206u8, 211u8, 244u8, 233u8, 186u8, 167u8, 128u8, 157u8, 235u8, 246u8, 209u8, 204u8, 159u8, 130u8, 165u8, 184u8, 3u8, 30u8, 57u8, 36u8, 119u8, 106u8, 77u8, 80u8, 161u8, 188u8, 155u8, 134u8, 213u8, 200u8, 239u8, 242u8, 73u8, 84u8, 115u8, 110u8, 61u8, 32u8, 7u8, 26u8, 108u8, 113u8, 86u8, 75u8, 24u8, 5u8, 34u8, 63u8, 132u8, 153u8, 190u8, 163u8, 240u8, 237u8, 202u8, 215u8, 53u8, 40u8, 15u8, 18u8, 65u8, 92u8, 123u8, 102u8, 221u8, 192u8, 231u8, 250u8, 169u8, 180u8, 147u8, 142u8, 248u8, 229u8, 194u8, 223u8, 140u8, 145u8, 182u8, 171u8, 16u8, 13u8, 42u8, 55u8, 100u8, 121u8, 94u8, 67u8, 178u8, 175u8, 136u8, 149u8, 198u8, 219u8, 252u8, 225u8, 90u8, 71u8, 96u8, 125u8, 46u8, 51u8, 20u8, 9u8, 127u8, 98u8, 69u8, 88u8, 11u8, 22u8, 49u8, 44u8, 151u8, 138u8, 173u8, 176u8, 227u8, 254u8, 217u8, 196u8]; 7 | 8 | #[rustfmt::skip] 9 | pub(crate) const NO_REF_8_D5: [u8; 256] = [0u8, 213u8, 127u8, 170u8, 254u8, 43u8, 129u8, 84u8, 41u8, 252u8, 86u8, 131u8, 215u8, 2u8, 168u8, 125u8, 82u8, 135u8, 45u8, 248u8, 172u8, 121u8, 211u8, 6u8, 123u8, 174u8, 4u8, 209u8, 133u8, 80u8, 250u8, 47u8, 164u8, 113u8, 219u8, 14u8, 90u8, 143u8, 37u8, 240u8, 141u8, 88u8, 242u8, 39u8, 115u8, 166u8, 12u8, 217u8, 246u8, 35u8, 137u8, 92u8, 8u8, 221u8, 119u8, 162u8, 223u8, 10u8, 160u8, 117u8, 33u8, 244u8, 94u8, 139u8, 157u8, 72u8, 226u8, 55u8, 99u8, 182u8, 28u8, 201u8, 180u8, 97u8, 203u8, 30u8, 74u8, 159u8, 53u8, 224u8, 207u8, 26u8, 176u8, 101u8, 49u8, 228u8, 78u8, 155u8, 230u8, 51u8, 153u8, 76u8, 24u8, 205u8, 103u8, 178u8, 57u8, 236u8, 70u8, 147u8, 199u8, 18u8, 184u8, 109u8, 16u8, 197u8, 111u8, 186u8, 238u8, 59u8, 145u8, 68u8, 107u8, 190u8, 20u8, 193u8, 149u8, 64u8, 234u8, 63u8, 66u8, 151u8, 61u8, 232u8, 188u8, 105u8, 195u8, 22u8, 239u8, 58u8, 144u8, 69u8, 17u8, 196u8, 110u8, 187u8, 198u8, 19u8, 185u8, 108u8, 56u8, 237u8, 71u8, 146u8, 189u8, 104u8, 194u8, 23u8, 67u8, 150u8, 60u8, 233u8, 148u8, 65u8, 235u8, 62u8, 106u8, 191u8, 21u8, 192u8, 75u8, 158u8, 52u8, 225u8, 181u8, 96u8, 202u8, 31u8, 98u8, 183u8, 29u8, 200u8, 156u8, 73u8, 227u8, 54u8, 25u8, 204u8, 102u8, 179u8, 231u8, 50u8, 152u8, 77u8, 48u8, 229u8, 79u8, 154u8, 206u8, 27u8, 177u8, 100u8, 114u8, 167u8, 13u8, 216u8, 140u8, 89u8, 243u8, 38u8, 91u8, 142u8, 36u8, 241u8, 165u8, 112u8, 218u8, 15u8, 32u8, 245u8, 95u8, 138u8, 222u8, 11u8, 161u8, 116u8, 9u8, 220u8, 118u8, 163u8, 247u8, 34u8, 136u8, 93u8, 214u8, 3u8, 169u8, 124u8, 40u8, 253u8, 87u8, 130u8, 255u8, 42u8, 128u8, 85u8, 1u8, 212u8, 126u8, 171u8, 132u8, 81u8, 251u8, 46u8, 122u8, 175u8, 5u8, 208u8, 173u8, 120u8, 210u8, 7u8, 83u8, 134u8, 44u8, 249u8]; 10 | 11 | #[rustfmt::skip] 12 | pub(crate) const NO_REF_8_9B: [u8; 256] = [0u8, 155u8, 173u8, 54u8, 193u8, 90u8, 108u8, 247u8, 25u8, 130u8, 180u8, 47u8, 216u8, 67u8, 117u8, 238u8, 50u8, 169u8, 159u8, 4u8, 243u8, 104u8, 94u8, 197u8, 43u8, 176u8, 134u8, 29u8, 234u8, 113u8, 71u8, 220u8, 100u8, 255u8, 201u8, 82u8, 165u8, 62u8, 8u8, 147u8, 125u8, 230u8, 208u8, 75u8, 188u8, 39u8, 17u8, 138u8, 86u8, 205u8, 251u8, 96u8, 151u8, 12u8, 58u8, 161u8, 79u8, 212u8, 226u8, 121u8, 142u8, 21u8, 35u8, 184u8, 200u8, 83u8, 101u8, 254u8, 9u8, 146u8, 164u8, 63u8, 209u8, 74u8, 124u8, 231u8, 16u8, 139u8, 189u8, 38u8, 250u8, 97u8, 87u8, 204u8, 59u8, 160u8, 150u8, 13u8, 227u8, 120u8, 78u8, 213u8, 34u8, 185u8, 143u8, 20u8, 172u8, 55u8, 1u8, 154u8, 109u8, 246u8, 192u8, 91u8, 181u8, 46u8, 24u8, 131u8, 116u8, 239u8, 217u8, 66u8, 158u8, 5u8, 51u8, 168u8, 95u8, 196u8, 242u8, 105u8, 135u8, 28u8, 42u8, 177u8, 70u8, 221u8, 235u8, 112u8, 11u8, 144u8, 166u8, 61u8, 202u8, 81u8, 103u8, 252u8, 18u8, 137u8, 191u8, 36u8, 211u8, 72u8, 126u8, 229u8, 57u8, 162u8, 148u8, 15u8, 248u8, 99u8, 85u8, 206u8, 32u8, 187u8, 141u8, 22u8, 225u8, 122u8, 76u8, 215u8, 111u8, 244u8, 194u8, 89u8, 174u8, 53u8, 3u8, 152u8, 118u8, 237u8, 219u8, 64u8, 183u8, 44u8, 26u8, 129u8, 93u8, 198u8, 240u8, 107u8, 156u8, 7u8, 49u8, 170u8, 68u8, 223u8, 233u8, 114u8, 133u8, 30u8, 40u8, 179u8, 195u8, 88u8, 110u8, 245u8, 2u8, 153u8, 175u8, 52u8, 218u8, 65u8, 119u8, 236u8, 27u8, 128u8, 182u8, 45u8, 241u8, 106u8, 92u8, 199u8, 48u8, 171u8, 157u8, 6u8, 232u8, 115u8, 69u8, 222u8, 41u8, 178u8, 132u8, 31u8, 167u8, 60u8, 10u8, 145u8, 102u8, 253u8, 203u8, 80u8, 190u8, 37u8, 19u8, 136u8, 127u8, 228u8, 210u8, 73u8, 149u8, 14u8, 56u8, 163u8, 84u8, 207u8, 249u8, 98u8, 140u8, 23u8, 33u8, 186u8, 77u8, 214u8, 224u8, 123u8]; 13 | 14 | #[rustfmt::skip] 15 | pub(crate) const REF_8_8C: [u8; 256] = [0u8, 94u8, 188u8, 226u8, 97u8, 63u8, 221u8, 131u8, 194u8, 156u8, 126u8, 32u8, 163u8, 253u8, 31u8, 65u8, 157u8, 195u8, 33u8, 127u8, 252u8, 162u8, 64u8, 30u8, 95u8, 1u8, 227u8, 189u8, 62u8, 96u8, 130u8, 220u8, 35u8, 125u8, 159u8, 193u8, 66u8, 28u8, 254u8, 160u8, 225u8, 191u8, 93u8, 3u8, 128u8, 222u8, 60u8, 98u8, 190u8, 224u8, 2u8, 92u8, 223u8, 129u8, 99u8, 61u8, 124u8, 34u8, 192u8, 158u8, 29u8, 67u8, 161u8, 255u8, 70u8, 24u8, 250u8, 164u8, 39u8, 121u8, 155u8, 197u8, 132u8, 218u8, 56u8, 102u8, 229u8, 187u8, 89u8, 7u8, 219u8, 133u8, 103u8, 57u8, 186u8, 228u8, 6u8, 88u8, 25u8, 71u8, 165u8, 251u8, 120u8, 38u8, 196u8, 154u8, 101u8, 59u8, 217u8, 135u8, 4u8, 90u8, 184u8, 230u8, 167u8, 249u8, 27u8, 69u8, 198u8, 152u8, 122u8, 36u8, 248u8, 166u8, 68u8, 26u8, 153u8, 199u8, 37u8, 123u8, 58u8, 100u8, 134u8, 216u8, 91u8, 5u8, 231u8, 185u8, 140u8, 210u8, 48u8, 110u8, 237u8, 179u8, 81u8, 15u8, 78u8, 16u8, 242u8, 172u8, 47u8, 113u8, 147u8, 205u8, 17u8, 79u8, 173u8, 243u8, 112u8, 46u8, 204u8, 146u8, 211u8, 141u8, 111u8, 49u8, 178u8, 236u8, 14u8, 80u8, 175u8, 241u8, 19u8, 77u8, 206u8, 144u8, 114u8, 44u8, 109u8, 51u8, 209u8, 143u8, 12u8, 82u8, 176u8, 238u8, 50u8, 108u8, 142u8, 208u8, 83u8, 13u8, 239u8, 177u8, 240u8, 174u8, 76u8, 18u8, 145u8, 207u8, 45u8, 115u8, 202u8, 148u8, 118u8, 40u8, 171u8, 245u8, 23u8, 73u8, 8u8, 86u8, 180u8, 234u8, 105u8, 55u8, 213u8, 139u8, 87u8, 9u8, 235u8, 181u8, 54u8, 104u8, 138u8, 212u8, 149u8, 203u8, 41u8, 119u8, 244u8, 170u8, 72u8, 22u8, 233u8, 183u8, 85u8, 11u8, 136u8, 214u8, 52u8, 106u8, 43u8, 117u8, 151u8, 201u8, 74u8, 20u8, 246u8, 168u8, 116u8, 42u8, 200u8, 150u8, 21u8, 75u8, 169u8, 247u8, 182u8, 232u8, 10u8, 84u8, 215u8, 137u8, 107u8, 53u8]; 16 | 17 | #[rustfmt::skip] 18 | pub(crate) const REF_8_9C: [u8; 256] = [0u8, 114u8, 228u8, 150u8, 241u8, 131u8, 21u8, 103u8, 219u8, 169u8, 63u8, 77u8, 42u8, 88u8, 206u8, 188u8, 143u8, 253u8, 107u8, 25u8, 126u8, 12u8, 154u8, 232u8, 84u8, 38u8, 176u8, 194u8, 165u8, 215u8, 65u8, 51u8, 39u8, 85u8, 195u8, 177u8, 214u8, 164u8, 50u8, 64u8, 252u8, 142u8, 24u8, 106u8, 13u8, 127u8, 233u8, 155u8, 168u8, 218u8, 76u8, 62u8, 89u8, 43u8, 189u8, 207u8, 115u8, 1u8, 151u8, 229u8, 130u8, 240u8, 102u8, 20u8, 78u8, 60u8, 170u8, 216u8, 191u8, 205u8, 91u8, 41u8, 149u8, 231u8, 113u8, 3u8, 100u8, 22u8, 128u8, 242u8, 193u8, 179u8, 37u8, 87u8, 48u8, 66u8, 212u8, 166u8, 26u8, 104u8, 254u8, 140u8, 235u8, 153u8, 15u8, 125u8, 105u8, 27u8, 141u8, 255u8, 152u8, 234u8, 124u8, 14u8, 178u8, 192u8, 86u8, 36u8, 67u8, 49u8, 167u8, 213u8, 230u8, 148u8, 2u8, 112u8, 23u8, 101u8, 243u8, 129u8, 61u8, 79u8, 217u8, 171u8, 204u8, 190u8, 40u8, 90u8, 156u8, 238u8, 120u8, 10u8, 109u8, 31u8, 137u8, 251u8, 71u8, 53u8, 163u8, 209u8, 182u8, 196u8, 82u8, 32u8, 19u8, 97u8, 247u8, 133u8, 226u8, 144u8, 6u8, 116u8, 200u8, 186u8, 44u8, 94u8, 57u8, 75u8, 221u8, 175u8, 187u8, 201u8, 95u8, 45u8, 74u8, 56u8, 174u8, 220u8, 96u8, 18u8, 132u8, 246u8, 145u8, 227u8, 117u8, 7u8, 52u8, 70u8, 208u8, 162u8, 197u8, 183u8, 33u8, 83u8, 239u8, 157u8, 11u8, 121u8, 30u8, 108u8, 250u8, 136u8, 210u8, 160u8, 54u8, 68u8, 35u8, 81u8, 199u8, 181u8, 9u8, 123u8, 237u8, 159u8, 248u8, 138u8, 28u8, 110u8, 93u8, 47u8, 185u8, 203u8, 172u8, 222u8, 72u8, 58u8, 134u8, 244u8, 98u8, 16u8, 119u8, 5u8, 147u8, 225u8, 245u8, 135u8, 17u8, 99u8, 4u8, 118u8, 224u8, 146u8, 46u8, 92u8, 202u8, 184u8, 223u8, 173u8, 59u8, 73u8, 122u8, 8u8, 158u8, 236u8, 139u8, 249u8, 111u8, 29u8, 161u8, 211u8, 69u8, 55u8, 80u8, 34u8, 180u8, 198u8]; 19 | 20 | #[rustfmt::skip] 21 | pub(crate) const REF_8_B8: [u8; 256] = [0u8, 100u8, 200u8, 172u8, 225u8, 133u8, 41u8, 77u8, 179u8, 215u8, 123u8, 31u8, 82u8, 54u8, 154u8, 254u8, 23u8, 115u8, 223u8, 187u8, 246u8, 146u8, 62u8, 90u8, 164u8, 192u8, 108u8, 8u8, 69u8, 33u8, 141u8, 233u8, 46u8, 74u8, 230u8, 130u8, 207u8, 171u8, 7u8, 99u8, 157u8, 249u8, 85u8, 49u8, 124u8, 24u8, 180u8, 208u8, 57u8, 93u8, 241u8, 149u8, 216u8, 188u8, 16u8, 116u8, 138u8, 238u8, 66u8, 38u8, 107u8, 15u8, 163u8, 199u8, 92u8, 56u8, 148u8, 240u8, 189u8, 217u8, 117u8, 17u8, 239u8, 139u8, 39u8, 67u8, 14u8, 106u8, 198u8, 162u8, 75u8, 47u8, 131u8, 231u8, 170u8, 206u8, 98u8, 6u8, 248u8, 156u8, 48u8, 84u8, 25u8, 125u8, 209u8, 181u8, 114u8, 22u8, 186u8, 222u8, 147u8, 247u8, 91u8, 63u8, 193u8, 165u8, 9u8, 109u8, 32u8, 68u8, 232u8, 140u8, 101u8, 1u8, 173u8, 201u8, 132u8, 224u8, 76u8, 40u8, 214u8, 178u8, 30u8, 122u8, 55u8, 83u8, 255u8, 155u8, 184u8, 220u8, 112u8, 20u8, 89u8, 61u8, 145u8, 245u8, 11u8, 111u8, 195u8, 167u8, 234u8, 142u8, 34u8, 70u8, 175u8, 203u8, 103u8, 3u8, 78u8, 42u8, 134u8, 226u8, 28u8, 120u8, 212u8, 176u8, 253u8, 153u8, 53u8, 81u8, 150u8, 242u8, 94u8, 58u8, 119u8, 19u8, 191u8, 219u8, 37u8, 65u8, 237u8, 137u8, 196u8, 160u8, 12u8, 104u8, 129u8, 229u8, 73u8, 45u8, 96u8, 4u8, 168u8, 204u8, 50u8, 86u8, 250u8, 158u8, 211u8, 183u8, 27u8, 127u8, 228u8, 128u8, 44u8, 72u8, 5u8, 97u8, 205u8, 169u8, 87u8, 51u8, 159u8, 251u8, 182u8, 210u8, 126u8, 26u8, 243u8, 151u8, 59u8, 95u8, 18u8, 118u8, 218u8, 190u8, 64u8, 36u8, 136u8, 236u8, 161u8, 197u8, 105u8, 13u8, 202u8, 174u8, 2u8, 102u8, 43u8, 79u8, 227u8, 135u8, 121u8, 29u8, 177u8, 213u8, 152u8, 252u8, 80u8, 52u8, 221u8, 185u8, 21u8, 113u8, 60u8, 88u8, 244u8, 144u8, 110u8, 10u8, 166u8, 194u8, 143u8, 235u8, 71u8, 35u8]; 22 | 23 | #[rustfmt::skip] 24 | pub(crate) const REF_8_E0: [u8; 256] = [0u8, 145u8, 227u8, 114u8, 7u8, 150u8, 228u8, 117u8, 14u8, 159u8, 237u8, 124u8, 9u8, 152u8, 234u8, 123u8, 28u8, 141u8, 255u8, 110u8, 27u8, 138u8, 248u8, 105u8, 18u8, 131u8, 241u8, 96u8, 21u8, 132u8, 246u8, 103u8, 56u8, 169u8, 219u8, 74u8, 63u8, 174u8, 220u8, 77u8, 54u8, 167u8, 213u8, 68u8, 49u8, 160u8, 210u8, 67u8, 36u8, 181u8, 199u8, 86u8, 35u8, 178u8, 192u8, 81u8, 42u8, 187u8, 201u8, 88u8, 45u8, 188u8, 206u8, 95u8, 112u8, 225u8, 147u8, 2u8, 119u8, 230u8, 148u8, 5u8, 126u8, 239u8, 157u8, 12u8, 121u8, 232u8, 154u8, 11u8, 108u8, 253u8, 143u8, 30u8, 107u8, 250u8, 136u8, 25u8, 98u8, 243u8, 129u8, 16u8, 101u8, 244u8, 134u8, 23u8, 72u8, 217u8, 171u8, 58u8, 79u8, 222u8, 172u8, 61u8, 70u8, 215u8, 165u8, 52u8, 65u8, 208u8, 162u8, 51u8, 84u8, 197u8, 183u8, 38u8, 83u8, 194u8, 176u8, 33u8, 90u8, 203u8, 185u8, 40u8, 93u8, 204u8, 190u8, 47u8, 224u8, 113u8, 3u8, 146u8, 231u8, 118u8, 4u8, 149u8, 238u8, 127u8, 13u8, 156u8, 233u8, 120u8, 10u8, 155u8, 252u8, 109u8, 31u8, 142u8, 251u8, 106u8, 24u8, 137u8, 242u8, 99u8, 17u8, 128u8, 245u8, 100u8, 22u8, 135u8, 216u8, 73u8, 59u8, 170u8, 223u8, 78u8, 60u8, 173u8, 214u8, 71u8, 53u8, 164u8, 209u8, 64u8, 50u8, 163u8, 196u8, 85u8, 39u8, 182u8, 195u8, 82u8, 32u8, 177u8, 202u8, 91u8, 41u8, 184u8, 205u8, 92u8, 46u8, 191u8, 144u8, 1u8, 115u8, 226u8, 151u8, 6u8, 116u8, 229u8, 158u8, 15u8, 125u8, 236u8, 153u8, 8u8, 122u8, 235u8, 140u8, 29u8, 111u8, 254u8, 139u8, 26u8, 104u8, 249u8, 130u8, 19u8, 97u8, 240u8, 133u8, 20u8, 102u8, 247u8, 168u8, 57u8, 75u8, 218u8, 175u8, 62u8, 76u8, 221u8, 166u8, 55u8, 69u8, 212u8, 161u8, 48u8, 66u8, 211u8, 180u8, 37u8, 87u8, 198u8, 179u8, 34u8, 80u8, 193u8, 186u8, 43u8, 89u8, 200u8, 189u8, 44u8, 94u8, 207u8]; 25 | 26 | #[rustfmt::skip] 27 | pub(crate) const REF_8_D9: [u8; 256] = [0u8, 208u8, 19u8, 195u8, 38u8, 246u8, 53u8, 229u8, 76u8, 156u8, 95u8, 143u8, 106u8, 186u8, 121u8, 169u8, 152u8, 72u8, 139u8, 91u8, 190u8, 110u8, 173u8, 125u8, 212u8, 4u8, 199u8, 23u8, 242u8, 34u8, 225u8, 49u8, 131u8, 83u8, 144u8, 64u8, 165u8, 117u8, 182u8, 102u8, 207u8, 31u8, 220u8, 12u8, 233u8, 57u8, 250u8, 42u8, 27u8, 203u8, 8u8, 216u8, 61u8, 237u8, 46u8, 254u8, 87u8, 135u8, 68u8, 148u8, 113u8, 161u8, 98u8, 178u8, 181u8, 101u8, 166u8, 118u8, 147u8, 67u8, 128u8, 80u8, 249u8, 41u8, 234u8, 58u8, 223u8, 15u8, 204u8, 28u8, 45u8, 253u8, 62u8, 238u8, 11u8, 219u8, 24u8, 200u8, 97u8, 177u8, 114u8, 162u8, 71u8, 151u8, 84u8, 132u8, 54u8, 230u8, 37u8, 245u8, 16u8, 192u8, 3u8, 211u8, 122u8, 170u8, 105u8, 185u8, 92u8, 140u8, 79u8, 159u8, 174u8, 126u8, 189u8, 109u8, 136u8, 88u8, 155u8, 75u8, 226u8, 50u8, 241u8, 33u8, 196u8, 20u8, 215u8, 7u8, 217u8, 9u8, 202u8, 26u8, 255u8, 47u8, 236u8, 60u8, 149u8, 69u8, 134u8, 86u8, 179u8, 99u8, 160u8, 112u8, 65u8, 145u8, 82u8, 130u8, 103u8, 183u8, 116u8, 164u8, 13u8, 221u8, 30u8, 206u8, 43u8, 251u8, 56u8, 232u8, 90u8, 138u8, 73u8, 153u8, 124u8, 172u8, 111u8, 191u8, 22u8, 198u8, 5u8, 213u8, 48u8, 224u8, 35u8, 243u8, 194u8, 18u8, 209u8, 1u8, 228u8, 52u8, 247u8, 39u8, 142u8, 94u8, 157u8, 77u8, 168u8, 120u8, 187u8, 107u8, 108u8, 188u8, 127u8, 175u8, 74u8, 154u8, 89u8, 137u8, 32u8, 240u8, 51u8, 227u8, 6u8, 214u8, 21u8, 197u8, 244u8, 36u8, 231u8, 55u8, 210u8, 2u8, 193u8, 17u8, 184u8, 104u8, 171u8, 123u8, 158u8, 78u8, 141u8, 93u8, 239u8, 63u8, 252u8, 44u8, 201u8, 25u8, 218u8, 10u8, 163u8, 115u8, 176u8, 96u8, 133u8, 85u8, 150u8, 70u8, 119u8, 167u8, 100u8, 180u8, 81u8, 129u8, 66u8, 146u8, 59u8, 235u8, 40u8, 248u8, 29u8, 205u8, 14u8, 222u8]; 28 | -------------------------------------------------------------------------------- /src/crc_u64.rs: -------------------------------------------------------------------------------- 1 | #[cfg(feature = "alloc")] 2 | use alloc::fmt::{self, Debug, Display, Formatter}; 3 | #[cfg(feature = "alloc")] 4 | use alloc::vec::Vec; 5 | 6 | #[cfg(feature = "heapless")] 7 | use heapless::Vec as HeaplessVec; 8 | 9 | use crate::{constants::crc_u64::*, lookup_table::LookUpTable}; 10 | 11 | #[allow(clippy::upper_case_acronyms)] 12 | /// This struct can help you compute a CRC-64 (or CRC-x where **x** is equal or less than `64`) value. 13 | pub struct CRCu64 { 14 | by_table: bool, 15 | poly: u64, 16 | lookup_table: LookUpTable, 17 | sum: u64, 18 | pub(crate) bits: u8, 19 | high_bit: u64, 20 | mask: u64, 21 | initial: u64, 22 | final_xor: u64, 23 | reflect: bool, 24 | reorder: bool, 25 | } 26 | 27 | #[cfg(feature = "alloc")] 28 | impl Debug for CRCu64 { 29 | #[inline] 30 | fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> { 31 | if self.by_table { 32 | debug_helper::impl_debug_for_struct!(CRCu64, f, self, let .lookup_table = self.lookup_table.as_ref(), (.sum, "0x{:016X}", self.sum), .bits, (.initial, "0x{:016X}", self.initial), (.final_xor, "0x{:016X}", self.final_xor), .reflect, .reorder); 33 | } else { 34 | debug_helper::impl_debug_for_struct!(CRCu64, f, self, (.poly, "0x{:016X}", self.poly), (.sum, "0x{:016X}", self.sum), .bits, (.initial, "0x{:016X}", self.initial), (.final_xor, "0x{:016X}", self.final_xor), .reflect, .reorder); 35 | } 36 | } 37 | } 38 | 39 | #[cfg(feature = "alloc")] 40 | impl Display for CRCu64 { 41 | #[inline] 42 | fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> { 43 | f.write_fmt(format_args!("0x{:01$X}", self.get_crc(), (self.bits as usize + 3) >> 2)) 44 | } 45 | } 46 | 47 | impl CRCu64 { 48 | /// Create a `CRCu64` instance by providing the length of bits, expression, reflection, an initial value and a final xor value. 49 | pub fn create_crc(poly: u64, bits: u8, initial: u64, final_xor: u64, reflect: bool) -> CRCu64 { 50 | debug_assert!(bits <= 64 && bits > 0); 51 | 52 | if bits % 8 == 0 { 53 | let lookup_table = if reflect { 54 | LookUpTable::Dynamic(Self::crc_reflect_table(poly)) 55 | } else { 56 | LookUpTable::Dynamic(Self::crc_table(poly, bits)) 57 | }; 58 | 59 | Self::create_crc_with_exists_lookup_table( 60 | lookup_table, 61 | bits, 62 | initial, 63 | final_xor, 64 | reflect, 65 | ) 66 | } else { 67 | Self::create( 68 | false, 69 | LookUpTable::Static(&[0u64; 256]), 70 | poly, 71 | bits, 72 | initial, 73 | final_xor, 74 | reflect, 75 | ) 76 | } 77 | } 78 | 79 | /// Create a `CRCu64` instance by providing an existing lookup table, the length of bits, expression, reflection, an initial value and a final xor value. 80 | pub(crate) fn create_crc_with_exists_lookup_table( 81 | lookup_table: LookUpTable, 82 | bits: u8, 83 | initial: u64, 84 | final_xor: u64, 85 | reflect: bool, 86 | ) -> CRCu64 { 87 | debug_assert!(bits % 8 == 0); 88 | 89 | Self::create(true, lookup_table, 0, bits, initial, final_xor, reflect) 90 | } 91 | 92 | #[inline] 93 | fn create( 94 | by_table: bool, 95 | lookup_table: LookUpTable, 96 | mut poly: u64, 97 | bits: u8, 98 | initial: u64, 99 | final_xor: u64, 100 | reflect: bool, 101 | ) -> CRCu64 { 102 | let high_bit = 1 << u64::from(bits - 1); 103 | let mask = ((high_bit - 1) << 1) | 1; 104 | 105 | let sum = if reflect { Self::reflect_function(high_bit, initial) } else { initial }; 106 | 107 | if !by_table && reflect { 108 | poly = Self::reflect_function(high_bit, poly); 109 | } 110 | 111 | CRCu64 { 112 | by_table, 113 | poly, 114 | lookup_table, 115 | sum, 116 | bits, 117 | high_bit, 118 | mask, 119 | initial, 120 | final_xor, 121 | reflect, 122 | reorder: false, 123 | } 124 | } 125 | 126 | #[inline] 127 | fn reflect_function(high_bit: u64, n: u64) -> u64 { 128 | let mut i = high_bit; 129 | let mut j = 1; 130 | let mut out = 0; 131 | 132 | while i != 0 { 133 | if n & i != 0 { 134 | out |= j; 135 | } 136 | 137 | j <<= 1; 138 | i >>= 1; 139 | } 140 | 141 | out 142 | } 143 | 144 | #[inline] 145 | fn reflect_method(&self, n: u64) -> u64 { 146 | Self::reflect_function(self.high_bit, n) 147 | } 148 | 149 | /// Digest some data. 150 | pub fn digest>(&mut self, data: &T) { 151 | if self.by_table { 152 | if self.bits == 8 { 153 | for n in data.as_ref().iter().copied() { 154 | let index = (self.sum as u8 ^ n) as usize; 155 | self.sum = self.lookup_table[index]; 156 | } 157 | } else if self.reflect { 158 | for n in data.as_ref().iter().copied() { 159 | let index = ((self.sum as u8) ^ n) as usize; 160 | self.sum = (self.sum >> 8) ^ self.lookup_table[index]; 161 | } 162 | } else { 163 | for n in data.as_ref().iter().copied() { 164 | let index = ((self.sum >> u64::from(self.bits - 8)) as u8 ^ n) as usize; 165 | self.sum = (self.sum << 8) ^ self.lookup_table[index]; 166 | } 167 | } 168 | } else if self.reflect { 169 | for n in data.as_ref().iter().copied() { 170 | let n = super::crc_u8::CRCu8::reflect_function(0x80, n); 171 | 172 | let mut i = 0x80; 173 | 174 | while i != 0 { 175 | let mut bit = self.sum & self.high_bit; 176 | 177 | self.sum <<= 1; 178 | 179 | if n & i != 0 { 180 | bit ^= self.high_bit; 181 | } 182 | 183 | if bit != 0 { 184 | self.sum ^= self.poly; 185 | } 186 | 187 | i >>= 1; 188 | } 189 | } 190 | } else { 191 | for n in data.as_ref().iter().copied() { 192 | let mut i = 0x80; 193 | 194 | while i != 0 { 195 | let mut bit = self.sum & self.high_bit; 196 | 197 | self.sum <<= 1; 198 | 199 | if n & i != 0 { 200 | bit ^= self.high_bit; 201 | } 202 | 203 | if bit != 0 { 204 | self.sum ^= self.poly; 205 | } 206 | 207 | i >>= 1; 208 | } 209 | } 210 | } 211 | } 212 | 213 | /// Reset the sum. 214 | pub fn reset(&mut self) { 215 | self.sum = self.initial; 216 | } 217 | 218 | /// Get the current CRC value (it always returns a `u64` value). You can continue calling `digest` method even after getting a CRC value. 219 | pub fn get_crc(&self) -> u64 { 220 | let sum = if self.by_table || !self.reflect { 221 | (self.sum ^ self.final_xor) & self.mask 222 | } else { 223 | (self.reflect_method(self.sum) ^ self.final_xor) & self.mask 224 | }; 225 | 226 | if self.reorder { 227 | let mut new_sum = 0; 228 | 229 | let e = (self.bits as u64 + 7) >> 3; 230 | 231 | let e_dec = e - 1; 232 | 233 | for i in 0..e { 234 | new_sum |= ((sum >> ((e_dec - i) * 8)) & 0xFF) << (i * 8); 235 | } 236 | 237 | new_sum 238 | } else { 239 | sum 240 | } 241 | } 242 | 243 | fn crc_reflect_table(poly_rev: u64) -> [u64; 256] { 244 | let mut lookup_table = [0u64; 256]; 245 | 246 | for (i, e) in lookup_table.iter_mut().enumerate() { 247 | let mut v = i as u64; 248 | 249 | #[allow(clippy::branches_sharing_code)] 250 | for _ in 0..8u8 { 251 | if v & 1 != 0 { 252 | v >>= 1; 253 | v ^= poly_rev; 254 | } else { 255 | v >>= 1; 256 | } 257 | } 258 | 259 | *e = v; 260 | } 261 | 262 | lookup_table 263 | } 264 | 265 | fn crc_table(poly: u64, bits: u8) -> [u64; 256] { 266 | let mut lookup_table = [0u64; 256]; 267 | 268 | let mask1 = 1u64 << u64::from(bits - 1); 269 | 270 | let mask2 = ((mask1 - 1) << 1) | 1; 271 | 272 | for (i, e) in lookup_table.iter_mut().enumerate() { 273 | let mut v = i as u64; 274 | 275 | #[allow(clippy::branches_sharing_code)] 276 | for _ in 0..bits { 277 | if v & mask1 == 0 { 278 | v <<= 1; 279 | } else { 280 | v <<= 1; 281 | v ^= poly; 282 | } 283 | } 284 | 285 | *e = v & mask2; 286 | } 287 | 288 | lookup_table 289 | } 290 | } 291 | 292 | #[cfg(feature = "alloc")] 293 | impl CRCu64 { 294 | /// Get the current CRC value (it always returns a vec instance with a length corresponding to the CRC bits). You can continue calling `digest` method even after getting a CRC value. 295 | #[inline] 296 | pub fn get_crc_vec_le(&mut self) -> Vec { 297 | let crc = self.get_crc(); 298 | 299 | let e = (self.bits as usize + 7) >> 3; 300 | 301 | crc.to_le_bytes()[..e].to_vec() 302 | } 303 | 304 | /// Get the current CRC value (it always returns a vec instance with a length corresponding to the CRC bits). You can continue calling `digest` method even after getting a CRC value. 305 | #[inline] 306 | pub fn get_crc_vec_be(&mut self) -> Vec { 307 | let crc = self.get_crc(); 308 | 309 | let e = (self.bits as usize + 7) >> 3; 310 | 311 | crc.to_be_bytes()[(8 - e)..].to_vec() 312 | } 313 | } 314 | 315 | #[cfg(feature = "heapless")] 316 | impl CRCu64 { 317 | /// Get the current CRC value (it always returns a heapless vec instance with a length corresponding to the CRC bits). You can continue calling `digest` method even after getting a CRC value. 318 | #[inline] 319 | pub fn get_crc_heapless_vec_le(&mut self) -> HeaplessVec { 320 | let crc = self.get_crc(); 321 | 322 | let e = (self.bits as usize + 7) >> 3; 323 | 324 | let mut vec = HeaplessVec::new(); 325 | 326 | vec.extend_from_slice(&crc.to_le_bytes()[..e]).unwrap(); 327 | 328 | vec 329 | } 330 | 331 | /// Get the current CRC value (it always returns a heapless vec instance with a length corresponding to the CRC bits). You can continue calling `digest` method even after getting a CRC value. 332 | #[inline] 333 | pub fn get_crc_heapless_vec_be(&mut self) -> HeaplessVec { 334 | let crc = self.get_crc(); 335 | 336 | let e = (self.bits as usize + 7) >> 3; 337 | 338 | let mut vec = HeaplessVec::new(); 339 | 340 | vec.extend_from_slice(&crc.to_be_bytes()[(8 - e)..]).unwrap(); 341 | 342 | vec 343 | } 344 | } 345 | 346 | impl CRCu64 { 347 | /// |Check|Poly|Init|Ref|XorOut| 348 | /// |---|---|---|---|---| 349 | /// |0xD4164FC646|0x0004820009|0x0000000000|false|0xFFFFFFFFFF| 350 | /// 351 | /// ``` 352 | /// # use crc_any::CRCu64; 353 | /// let mut crc = CRCu64::crc40gsm(); 354 | /// crc.digest(b"123456789"); 355 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0xD4164FC646\", &crc.to_string());")] 356 | /// ``` 357 | pub fn crc40gsm() -> CRCu64 { 358 | // Self::create_crc(0x0000000004820009u64, 40, 0x0000000000000000, 0x000000FFFFFFFFFF, false) 359 | 360 | let lookup_table = LookUpTable::Static(&NO_REF_40_0000000004820009); 361 | Self::create_crc_with_exists_lookup_table( 362 | lookup_table, 363 | 40, 364 | 0x0000000000000000, 365 | 0x000000FFFFFFFFFF, 366 | false, 367 | ) 368 | } 369 | 370 | /// |Check|Poly|Init|Ref|XorOut| 371 | /// |---|---|---|---|---| 372 | /// |0x6C40DF5F0B497347|0x42F0E1EBA9EA3693|0x0000000000000000|false|0x0000000000000000| 373 | /// 374 | /// ``` 375 | /// # use crc_any::CRCu64; 376 | /// let mut crc = CRCu64::crc64(); 377 | /// crc.digest(b"123456789"); 378 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0x6C40DF5F0B497347\", &crc.to_string());")] 379 | /// ``` 380 | pub fn crc64() -> CRCu64 { 381 | // Self::create_crc(0x42F0E1EBA9EA3693, 64, 0x0000000000000000, 0x0000000000000000, false) 382 | 383 | let lookup_table = LookUpTable::Static(&NO_REF_64_42F0E1EBA9EA3693); 384 | Self::create_crc_with_exists_lookup_table( 385 | lookup_table, 386 | 64, 387 | 0x0000000000000000, 388 | 0x0000000000000000, 389 | false, 390 | ) 391 | } 392 | 393 | /// |Check|Poly|Init|Ref|XorOut| 394 | /// |---|---|---|---|---| 395 | /// |0xB90956C775A41001|0x000000000000001B (rev: 0xD800000000000000)|0xFFFFFFFFFFFFFFFF|true|0xFFFFFFFFFFFFFFFF| 396 | /// 397 | /// ``` 398 | /// # use crc_any::CRCu64; 399 | /// let mut crc = CRCu64::crc64iso(); 400 | /// crc.digest(b"123456789"); 401 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0xB90956C775A41001\", &crc.to_string());")] 402 | /// ``` 403 | pub fn crc64iso() -> CRCu64 { 404 | // Self::create_crc(0xD800000000000000, 64, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, true) 405 | 406 | let lookup_table = LookUpTable::Static(&REF_64_D800000000000000); 407 | Self::create_crc_with_exists_lookup_table( 408 | lookup_table, 409 | 64, 410 | 0xFFFFFFFFFFFFFFFF, 411 | 0xFFFFFFFFFFFFFFFF, 412 | true, 413 | ) 414 | } 415 | 416 | /// |Check|Poly|Init|Ref|XorOut| 417 | /// |---|---|---|---|---| 418 | /// |0x62EC59E3F1A4F00A|0x42F0E1EBA9EA3693|0xFFFFFFFFFFFFFFFF|false|0xFFFFFFFFFFFFFFFF| 419 | /// 420 | /// ``` 421 | /// # use crc_any::CRCu64; 422 | /// let mut crc = CRCu64::crc64we(); 423 | /// crc.digest(b"123456789"); 424 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0x62EC59E3F1A4F00A\", &crc.to_string());")] 425 | /// ``` 426 | pub fn crc64we() -> CRCu64 { 427 | // Self::create_crc(0x42F0E1EBA9EA3693, 64, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, false) 428 | 429 | let lookup_table = LookUpTable::Static(&NO_REF_64_42F0E1EBA9EA3693); 430 | Self::create_crc_with_exists_lookup_table( 431 | lookup_table, 432 | 64, 433 | 0xFFFFFFFFFFFFFFFF, 434 | 0xFFFFFFFFFFFFFFFF, 435 | false, 436 | ) 437 | } 438 | 439 | /// |Check|Poly|Init|Ref|XorOut| 440 | /// |---|---|---|---|---| 441 | /// |0xE9C6D914C4B8D9CA|0xAD93D23594C935A9 (rev: 0x95AC9329AC4BC9B5)|0x0000000000000000|true|0x0000000000000000| 442 | /// 443 | /// ``` 444 | /// # use crc_any::CRCu64; 445 | /// let mut crc = CRCu64::crc64jones(); 446 | /// crc.digest(b"123456789"); 447 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0xE9C6D914C4B8D9CA\", &crc.to_string());")] 448 | /// ``` 449 | pub fn crc64jones() -> CRCu64 { 450 | // Self::create_crc(0x95AC9329AC4BC9B5, 64, 0x0000000000000000, 0x0000000000000000, true) 451 | 452 | let lookup_table = LookUpTable::Static(&REF_64_95AC9329AC4BC9B5); 453 | Self::create_crc_with_exists_lookup_table( 454 | lookup_table, 455 | 64, 456 | 0x0000000000000000, 457 | 0x0000000000000000, 458 | true, 459 | ) 460 | } 461 | } 462 | 463 | #[cfg(all(feature = "development", test))] 464 | mod tests { 465 | use alloc::{fmt::Write, string::String}; 466 | 467 | use super::CRCu64; 468 | 469 | #[test] 470 | fn print_lookup_table() { 471 | let crc = CRCu64::crc64jones(); 472 | 473 | let mut s = String::new(); 474 | 475 | for n in crc.lookup_table.iter().take(255) { 476 | s.write_fmt(format_args!("{}u64, ", n)).unwrap(); 477 | } 478 | 479 | s.write_fmt(format_args!("{}u64", crc.lookup_table[255])).unwrap(); 480 | 481 | println!("let lookup_table = [{}];", s); 482 | } 483 | } 484 | -------------------------------------------------------------------------------- /src/crc_u8.rs: -------------------------------------------------------------------------------- 1 | #[cfg(feature = "alloc")] 2 | use alloc::fmt::{self, Debug, Display, Formatter}; 3 | 4 | use crate::{constants::crc_u8::*, lookup_table::LookUpTable}; 5 | 6 | #[allow(clippy::upper_case_acronyms)] 7 | /// This struct can help you compute a CRC-8 (or CRC-x where **x** is equal or less than `8`) value. 8 | pub struct CRCu8 { 9 | by_table: bool, 10 | poly: u8, 11 | lookup_table: LookUpTable, 12 | sum: u8, 13 | #[cfg(any(feature = "alloc", feature = "heapless"))] 14 | pub(crate) bits: u8, 15 | high_bit: u8, 16 | mask: u8, 17 | initial: u8, 18 | final_xor: u8, 19 | reflect: bool, 20 | } 21 | 22 | #[cfg(feature = "alloc")] 23 | impl Debug for CRCu8 { 24 | #[inline] 25 | fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> { 26 | if self.by_table { 27 | debug_helper::impl_debug_for_struct!(CRCu64, f, self, let .lookup_table = self.lookup_table.as_ref(), (.sum, "0x{:02X}", self.sum), .bits, (.initial, "0x{:02X}", self.initial), (.final_xor, "0x{:02X}", self.final_xor), .reflect); 28 | } else { 29 | debug_helper::impl_debug_for_struct!(CRCu64, f, self, (.poly, "0x{:02X}", self.poly), (.sum, "0x{:02X}", self.sum), .bits, (.initial, "0x{:02X}", self.initial), (.final_xor, "0x{:02X}", self.final_xor), .reflect); 30 | } 31 | } 32 | } 33 | 34 | #[cfg(feature = "alloc")] 35 | impl Display for CRCu8 { 36 | #[inline] 37 | fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> { 38 | f.write_fmt(format_args!("0x{:01$X}", self.get_crc(), (self.bits as usize + 3) >> 2)) 39 | } 40 | } 41 | 42 | impl CRCu8 { 43 | /// Create a `CRCu8` instance by providing the length of bits, expression, reflection, an initial value and a final xor value. 44 | pub fn create_crc(poly: u8, bits: u8, initial: u8, final_xor: u8, reflect: bool) -> CRCu8 { 45 | debug_assert!(bits <= 8 && bits > 0); 46 | 47 | if bits % 8 == 0 { 48 | let lookup_table = if reflect { 49 | LookUpTable::Dynamic(Self::crc_reflect_table(poly)) 50 | } else { 51 | LookUpTable::Dynamic(Self::crc_table(poly)) 52 | }; 53 | 54 | Self::create_crc_with_exists_lookup_table( 55 | lookup_table, 56 | bits, 57 | initial, 58 | final_xor, 59 | reflect, 60 | ) 61 | } else { 62 | Self::create( 63 | false, 64 | LookUpTable::Static(&[0; 256]), 65 | poly, 66 | bits, 67 | initial, 68 | final_xor, 69 | reflect, 70 | ) 71 | } 72 | } 73 | 74 | #[inline] 75 | pub(crate) fn create_crc_with_exists_lookup_table( 76 | lookup_table: LookUpTable, 77 | bits: u8, 78 | initial: u8, 79 | final_xor: u8, 80 | reflect: bool, 81 | ) -> CRCu8 { 82 | debug_assert!(bits % 8 == 0); 83 | 84 | Self::create(true, lookup_table, 0, bits, initial, final_xor, reflect) 85 | } 86 | 87 | #[inline] 88 | fn create( 89 | by_table: bool, 90 | lookup_table: LookUpTable, 91 | mut poly: u8, 92 | bits: u8, 93 | initial: u8, 94 | final_xor: u8, 95 | reflect: bool, 96 | ) -> CRCu8 { 97 | let high_bit = 1 << (bits - 1); 98 | let mask = ((high_bit - 1) << 1) | 1; 99 | 100 | let sum = if reflect { Self::reflect_function(high_bit, initial) } else { initial }; 101 | 102 | if !by_table && reflect { 103 | poly = Self::reflect_function(high_bit, poly); 104 | } 105 | 106 | CRCu8 { 107 | by_table, 108 | poly, 109 | lookup_table, 110 | sum, 111 | #[cfg(any(feature = "alloc", feature = "heapless"))] 112 | bits, 113 | high_bit, 114 | mask, 115 | initial, 116 | final_xor, 117 | reflect, 118 | } 119 | } 120 | 121 | #[inline] 122 | pub(crate) fn reflect_function(high_bit: u8, n: u8) -> u8 { 123 | let mut i = high_bit; 124 | let mut j = 1; 125 | let mut out = 0; 126 | 127 | while i != 0 { 128 | if n & i != 0 { 129 | out |= j; 130 | } 131 | 132 | j <<= 1; 133 | i >>= 1; 134 | } 135 | 136 | out 137 | } 138 | 139 | #[inline] 140 | fn reflect_method(&self, n: u8) -> u8 { 141 | Self::reflect_function(self.high_bit, n) 142 | } 143 | 144 | /// Digest some data. 145 | pub fn digest>(&mut self, data: &T) { 146 | if self.by_table { 147 | for n in data.as_ref().iter().copied() { 148 | let index = (self.sum ^ n) as usize; 149 | self.sum = self.lookup_table[index]; 150 | } 151 | } else if self.reflect { 152 | for n in data.as_ref().iter().copied() { 153 | let n = Self::reflect_function(0x80, n); 154 | 155 | let mut i = 0x80; 156 | 157 | while i != 0 { 158 | let mut bit = self.sum & self.high_bit; 159 | 160 | self.sum <<= 1; 161 | 162 | if n & i != 0 { 163 | bit ^= self.high_bit; 164 | } 165 | 166 | if bit != 0 { 167 | self.sum ^= self.poly; 168 | } 169 | 170 | i >>= 1; 171 | } 172 | } 173 | } else { 174 | for n in data.as_ref().iter().copied() { 175 | let mut i = 0x80; 176 | 177 | while i != 0 { 178 | let mut bit = self.sum & self.high_bit; 179 | 180 | self.sum <<= 1; 181 | 182 | if n & i != 0 { 183 | bit ^= self.high_bit; 184 | } 185 | 186 | if bit != 0 { 187 | self.sum ^= self.poly; 188 | } 189 | 190 | i >>= 1; 191 | } 192 | } 193 | } 194 | } 195 | 196 | /// Reset the sum. 197 | #[inline] 198 | pub fn reset(&mut self) { 199 | self.sum = self.initial; 200 | } 201 | 202 | /// Get the current CRC value (it always returns a `u8` value). You can continue calling `digest` method even after getting a CRC value. 203 | #[inline] 204 | pub fn get_crc(&self) -> u8 { 205 | if self.by_table || !self.reflect { 206 | (self.sum ^ self.final_xor) & self.mask 207 | } else { 208 | (self.reflect_method(self.sum) ^ self.final_xor) & self.mask 209 | } 210 | } 211 | 212 | fn crc_reflect_table(poly_rev: u8) -> [u8; 256] { 213 | let mut lookup_table = [0u8; 256]; 214 | 215 | for (i, e) in lookup_table.iter_mut().enumerate() { 216 | let mut v = i as u8; 217 | 218 | #[allow(clippy::branches_sharing_code)] 219 | for _ in 0..8u8 { 220 | if v & 1 != 0 { 221 | v >>= 1; 222 | v ^= poly_rev; 223 | } else { 224 | v >>= 1; 225 | } 226 | } 227 | 228 | *e = v; 229 | } 230 | 231 | lookup_table 232 | } 233 | 234 | fn crc_table(poly: u8) -> [u8; 256] { 235 | let mut lookup_table = [0u8; 256]; 236 | 237 | for (i, e) in lookup_table.iter_mut().enumerate() { 238 | let mut v = i as u8; 239 | 240 | #[allow(clippy::branches_sharing_code)] 241 | for _ in 0..8 { 242 | if v & 0x80 == 0 { 243 | v <<= 1; 244 | } else { 245 | v <<= 1; 246 | v ^= poly; 247 | } 248 | } 249 | 250 | *e = v; 251 | } 252 | 253 | lookup_table 254 | } 255 | } 256 | 257 | impl CRCu8 { 258 | /// |Check|Poly|Init|Ref|XorOut| 259 | /// |---|---|---|---|---| 260 | /// |0x4|0x3|0x0|false|0x7| 261 | /// 262 | /// ``` 263 | /// # use crc_any::CRCu8; 264 | /// let mut crc = CRCu8::crc3gsm(); 265 | /// crc.digest(b"123456789"); 266 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0x4\", &crc.to_string());")] 267 | /// ``` 268 | #[inline] 269 | pub fn crc3gsm() -> CRCu8 { 270 | Self::create_crc(0x03, 3, 0x00, 0x07, false) 271 | } 272 | 273 | /// |Check|Poly|Init|Ref|XorOut| 274 | /// |---|---|---|---|---| 275 | /// |0x7|0x3 (rev: 0xC)|0x0|true|0x0| 276 | /// 277 | /// ``` 278 | /// # use crc_any::CRCu8; 279 | /// let mut crc = CRCu8::crc4itu(); 280 | /// crc.digest(b"123456789"); 281 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0x7\", &crc.to_string());")] 282 | /// ``` 283 | #[inline] 284 | pub fn crc4itu() -> CRCu8 { 285 | Self::create_crc(0x0C, 4, 0x00, 0x00, true) 286 | } 287 | 288 | /// |Check|Poly|Init|Ref|XorOut| 289 | /// |---|---|---|---|---| 290 | /// |0xB|0x3|0xF|false|0xF| 291 | /// 292 | /// ``` 293 | /// # use crc_any::CRCu8; 294 | /// let mut crc = CRCu8::crc4interlaken(); 295 | /// crc.digest(b"123456789"); 296 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0xB\", &crc.to_string());")] 297 | /// ``` 298 | #[inline] 299 | pub fn crc4interlaken() -> CRCu8 { 300 | Self::create_crc(0x03, 4, 0x0F, 0x0F, false) 301 | } 302 | 303 | /// |Check|Poly|Init|Ref|XorOut| 304 | /// |---|---|---|---|---| 305 | /// |0x00|0x09|0x09|false|0x00| 306 | /// 307 | /// ``` 308 | /// # use crc_any::CRCu8; 309 | /// let mut crc = CRCu8::crc5epc(); 310 | /// crc.digest(b"123456789"); 311 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0x00\", &crc.to_string());")] 312 | /// ``` 313 | #[inline] 314 | pub fn crc5epc() -> CRCu8 { 315 | Self::create_crc(0x09, 5, 0x09, 0x00, false) 316 | } 317 | 318 | /// |Check|Poly|Init|Ref|XorOut| 319 | /// |---|---|---|---|---| 320 | /// |0x07|0x15 (rev: 0x15)|0x00|true|0x00| 321 | /// 322 | /// ``` 323 | /// # use crc_any::CRCu8; 324 | /// let mut crc = CRCu8::crc5itu(); 325 | /// crc.digest(b"123456789"); 326 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0x07\", &crc.to_string());")] 327 | /// ``` 328 | #[inline] 329 | pub fn crc5itu() -> CRCu8 { 330 | Self::create_crc(0x15, 5, 0x00, 0x00, true) 331 | } 332 | 333 | /// |Check|Poly|Init|Ref|XorOut| 334 | /// |---|---|---|---|---| 335 | /// |0x19|0x05 (rev: 0x14)|0x1F|true|0x1F| 336 | /// 337 | /// ``` 338 | /// # use crc_any::CRCu8; 339 | /// let mut crc = CRCu8::crc5usb(); 340 | /// crc.digest(b"123456789"); 341 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0x19\", &crc.to_string());")] 342 | /// ``` 343 | #[inline] 344 | pub fn crc5usb() -> CRCu8 { 345 | Self::create_crc(0x14, 5, 0x1F, 0x1F, true) 346 | } 347 | 348 | /// |Check|Poly|Init|Ref|XorOut| 349 | /// |---|---|---|---|---| 350 | /// |0x0D|0x27|0x3F|false|0x00| 351 | /// 352 | /// ``` 353 | /// # use crc_any::CRCu8; 354 | /// let mut crc = CRCu8::crc6cdma2000_a(); 355 | /// crc.digest(b"123456789"); 356 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0x0D\", &crc.to_string());")] 357 | /// ``` 358 | #[inline] 359 | pub fn crc6cdma2000_a() -> CRCu8 { 360 | Self::create_crc(0x27, 6, 0x3F, 0x00, false) 361 | } 362 | 363 | /// |Check|Poly|Init|Ref|XorOut| 364 | /// |---|---|---|---|---| 365 | /// |0x3B|0x07|0x3F|false|0x00| 366 | /// 367 | /// ``` 368 | /// # use crc_any::CRCu8; 369 | /// let mut crc = CRCu8::crc6cdma2000_b(); 370 | /// crc.digest(b"123456789"); 371 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0x3B\", &crc.to_string());")] 372 | /// ``` 373 | #[inline] 374 | pub fn crc6cdma2000_b() -> CRCu8 { 375 | Self::create_crc(0x07, 6, 0x3F, 0x00, false) 376 | } 377 | 378 | /// |Check|Poly|Init|Ref|XorOut| 379 | /// |---|---|---|---|---| 380 | /// |0x26|0x19 (rev: 0x26)|0x00|true|0x00| 381 | /// 382 | /// ``` 383 | /// # use crc_any::CRCu8; 384 | /// let mut crc = CRCu8::crc6darc(); 385 | /// crc.digest(b"123456789"); 386 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0x26\", &crc.to_string());")] 387 | /// ``` 388 | #[inline] 389 | pub fn crc6darc() -> CRCu8 { 390 | Self::create_crc(0x26, 6, 0x00, 0x00, true) 391 | } 392 | 393 | /// |Check|Poly|Init|Ref|XorOut| 394 | /// |---|---|---|---|---| 395 | /// |0x13|0x2F|0x00|false|0x3F| 396 | /// 397 | /// ``` 398 | /// # use crc_any::CRCu8; 399 | /// let mut crc = CRCu8::crc6gsm(); 400 | /// crc.digest(b"123456789"); 401 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0x13\", &crc.to_string());")] 402 | /// ``` 403 | #[inline] 404 | pub fn crc6gsm() -> CRCu8 { 405 | Self::create_crc(0x2F, 6, 0x00, 0x3F, false) 406 | } 407 | 408 | /// |Check|Poly|Init|Ref|XorOut| 409 | /// |---|---|---|---|---| 410 | /// |0x06|0x03 (rev: 0x30)|0x00|true|0x00| 411 | /// 412 | /// ``` 413 | /// # use crc_any::CRCu8; 414 | /// let mut crc = CRCu8::crc6itu(); 415 | /// crc.digest(b"123456789"); 416 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0x06\", &crc.to_string());")] 417 | /// ``` 418 | #[inline] 419 | pub fn crc6itu() -> CRCu8 { 420 | Self::create_crc(0x30, 6, 0x00, 0x00, true) 421 | } 422 | 423 | /// |Check|Poly|Init|Ref|XorOut| 424 | /// |---|---|---|---|---| 425 | /// |0x75|0x09|0x00|false|0x00| 426 | /// 427 | /// ``` 428 | /// # use crc_any::CRCu8; 429 | /// let mut crc = CRCu8::crc7(); 430 | /// crc.digest(b"123456789"); 431 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0x75\", &crc.to_string());")] 432 | /// ``` 433 | #[inline] 434 | pub fn crc7() -> CRCu8 { 435 | Self::create_crc(0x09, 7, 0x00, 0x00, false) 436 | } 437 | 438 | /// |Check|Poly|Init|Ref|XorOut| 439 | /// |---|---|---|---|---| 440 | /// |0x61|0x45|0x00|false|0x00| 441 | /// 442 | /// ``` 443 | /// # use crc_any::CRCu8; 444 | /// let mut crc = CRCu8::crc7umts(); 445 | /// crc.digest(b"123456789"); 446 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0x61\", &crc.to_string());")] 447 | /// ``` 448 | #[inline] 449 | pub fn crc7umts() -> CRCu8 { 450 | Self::create_crc(0x45, 7, 0x00, 0x00, false) 451 | } 452 | 453 | /// |Check|Poly|Init|Ref|XorOut| 454 | /// |---|---|---|---|---| 455 | /// |0xF4|0x07|0x00|false|0x00| 456 | /// 457 | /// ``` 458 | /// # use crc_any::CRCu8; 459 | /// let mut crc = CRCu8::crc8(); 460 | /// crc.digest(b"123456789"); 461 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0xF4\", &crc.to_string());")] 462 | /// ``` 463 | #[inline] 464 | pub fn crc8() -> CRCu8 { 465 | // Self::create_crc(0x07, 8, 0x00, 0x00, false) 466 | 467 | let lookup_table = LookUpTable::Static(&NO_REF_8_07); 468 | Self::create_crc_with_exists_lookup_table(lookup_table, 8, 0x00, 0x00, false) 469 | } 470 | 471 | /// |Check|Poly|Init|Ref|XorOut| 472 | /// |---|---|---|---|---| 473 | /// |0xDA|0x9B|0xFF|false|0x00| 474 | /// 475 | /// ``` 476 | /// # use crc_any::CRCu8; 477 | /// let mut crc = CRCu8::crc8cdma2000(); 478 | /// crc.digest(b"123456789"); 479 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0xDA\", &crc.to_string());")] 480 | /// ``` 481 | #[inline] 482 | pub fn crc8cdma2000() -> CRCu8 { 483 | // Self::create_crc(0x9B, 8, 0xFF, 0x00, false) 484 | 485 | let lookup_table = LookUpTable::Static(&NO_REF_8_9B); 486 | Self::create_crc_with_exists_lookup_table(lookup_table, 8, 0xFF, 0x00, false) 487 | } 488 | 489 | /// |Check|Poly|Init|Ref|XorOut| 490 | /// |---|---|---|---|---| 491 | /// |0x15|0x39 (rev: 0x9C)|0x00|true|0x00| 492 | /// 493 | /// ``` 494 | /// # use crc_any::CRCu8; 495 | /// let mut crc = CRCu8::crc8darc(); 496 | /// crc.digest(b"123456789"); 497 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0x15\", &crc.to_string());")] 498 | /// ``` 499 | #[inline] 500 | pub fn crc8darc() -> CRCu8 { 501 | // Self::create_crc(0x9C, 8, 0x00, 0x00, true) 502 | 503 | let lookup_table = LookUpTable::Static(&REF_8_9C); 504 | Self::create_crc_with_exists_lookup_table(lookup_table, 8, 0x00, 0x00, true) 505 | } 506 | 507 | /// |Check|Poly|Init|Ref|XorOut| 508 | /// |---|---|---|---|---| 509 | /// |0xBC|0xD5|0x00|false|0x00| 510 | /// 511 | /// ``` 512 | /// # use crc_any::CRCu8; 513 | /// let mut crc = CRCu8::crc8dvb_s2(); 514 | /// crc.digest(b"123456789"); 515 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0xBC\", &crc.to_string());")] 516 | /// ``` 517 | #[inline] 518 | pub fn crc8dvb_s2() -> CRCu8 { 519 | // Self::create_crc(0xD5, 8, 0x00, 0x00, false) 520 | 521 | let lookup_table = LookUpTable::Static(&NO_REF_8_D5); 522 | Self::create_crc_with_exists_lookup_table(lookup_table, 8, 0x00, 0x00, false) 523 | } 524 | 525 | /// |Check|Poly|Init|Ref|XorOut| 526 | /// |---|---|---|---|---| 527 | /// |0x97|0x1D (rev: 0xB8)|0xFF|true|0x00| 528 | /// 529 | /// ``` 530 | /// # use crc_any::CRCu8; 531 | /// let mut crc = CRCu8::crc8ebu(); 532 | /// crc.digest(b"123456789"); 533 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0x97\", &crc.to_string());")] 534 | /// ``` 535 | #[inline] 536 | pub fn crc8ebu() -> CRCu8 { 537 | // Self::create_crc(0xB8, 8, 0xFF, 0x00, true) 538 | 539 | let lookup_table = LookUpTable::Static(&REF_8_B8); 540 | Self::create_crc_with_exists_lookup_table(lookup_table, 8, 0xFF, 0x00, true) 541 | } 542 | 543 | /// |Check|Poly|Init|Ref|XorOut| 544 | /// |---|---|---|---|---| 545 | /// |0x7E|0x1D|0xFD|false|0x00| 546 | /// 547 | /// ``` 548 | /// # use crc_any::CRCu8; 549 | /// let mut crc = CRCu8::crc8icode(); 550 | /// crc.digest(b"123456789"); 551 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0x7E\", &crc.to_string());")] 552 | /// ``` 553 | #[inline] 554 | pub fn crc8icode() -> CRCu8 { 555 | // Self::create_crc(0x1D, 8, 0xFD, 0x00, false) 556 | 557 | let lookup_table = LookUpTable::Static(&NO_REF_8_1D); 558 | Self::create_crc_with_exists_lookup_table(lookup_table, 8, 0xFD, 0x00, false) 559 | } 560 | 561 | /// |Check|Poly|Init|Ref|XorOut| 562 | /// |---|---|---|---|---| 563 | /// |0xA1|0x07|0x00|false|0x55| 564 | /// 565 | /// ``` 566 | /// # use crc_any::CRCu8; 567 | /// let mut crc = CRCu8::crc8itu(); 568 | /// crc.digest(b"123456789"); 569 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0xA1\", &crc.to_string());")] 570 | /// ``` 571 | #[inline] 572 | pub fn crc8itu() -> CRCu8 { 573 | // Self::create_crc(0x07, 8, 0x00, 0x55, false) 574 | 575 | let lookup_table = LookUpTable::Static(&NO_REF_8_07); 576 | Self::create_crc_with_exists_lookup_table(lookup_table, 8, 0x00, 0x55, false) 577 | } 578 | 579 | /// |Check|Poly|Init|Ref|XorOut| 580 | /// |---|---|---|---|---| 581 | /// |0xA1|0x31 (rev: 0x8C)|0x00|true|0x00| 582 | /// 583 | /// ``` 584 | /// # use crc_any::CRCu8; 585 | /// let mut crc = CRCu8::crc8maxim(); 586 | /// crc.digest(b"123456789"); 587 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0xA1\", &crc.to_string());")] 588 | /// ``` 589 | #[inline] 590 | pub fn crc8maxim() -> CRCu8 { 591 | // Self::create_crc(0x8C, 8, 0x00, 0x00, true) 592 | 593 | let lookup_table = LookUpTable::Static(&REF_8_8C); 594 | Self::create_crc_with_exists_lookup_table(lookup_table, 8, 0x00, 0x00, true) 595 | } 596 | 597 | /// |Check|Poly|Init|Ref|XorOut| 598 | /// |---|---|---|---|---| 599 | /// |0xD0|0x07 (rev: 0xE0)|0xFF|true|0x00| 600 | /// 601 | /// ``` 602 | /// # use crc_any::CRCu8; 603 | /// let mut crc = CRCu8::crc8rohc(); 604 | /// crc.digest(b"123456789"); 605 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0xD0\", &crc.to_string());")] 606 | /// ``` 607 | #[inline] 608 | pub fn crc8rohc() -> CRCu8 { 609 | // Self::create_crc(0xE0, 8, 0xFF, 0x00, true) 610 | 611 | let lookup_table = LookUpTable::Static(&REF_8_E0); 612 | Self::create_crc_with_exists_lookup_table(lookup_table, 8, 0xFF, 0x00, true) 613 | } 614 | 615 | /// |Check|Poly|Init|Ref|XorOut| 616 | /// |---|---|---|---|---| 617 | /// |0x25|0x9B (rev: 0xD9)|0x00|true|0x00| 618 | /// 619 | /// ``` 620 | /// # use crc_any::CRCu8; 621 | /// let mut crc = CRCu8::crc8wcdma(); 622 | /// crc.digest(b"123456789"); 623 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0x25\", &crc.to_string());")] 624 | /// ``` 625 | #[inline] 626 | pub fn crc8wcdma() -> CRCu8 { 627 | // Self::create_crc(0xD9, 8, 0x00, 0x00, true) 628 | 629 | let lookup_table = LookUpTable::Static(&REF_8_D9); 630 | Self::create_crc_with_exists_lookup_table(lookup_table, 8, 0x00, 0x00, true) 631 | } 632 | } 633 | 634 | #[cfg(all(feature = "development", test))] 635 | mod tests { 636 | use alloc::{fmt::Write, string::String}; 637 | 638 | use super::CRCu8; 639 | 640 | #[test] 641 | fn print_lookup_table() { 642 | let crc = CRCu8::crc4interlaken(); 643 | 644 | let mut s = String::new(); 645 | 646 | for n in crc.lookup_table.iter().take(255) { 647 | s.write_fmt(format_args!("{}u8, ", n)).unwrap(); 648 | } 649 | 650 | s.write_fmt(format_args!("{}u8", crc.lookup_table[255])).unwrap(); 651 | 652 | println!("let lookup_table = [{}];", s); 653 | } 654 | } 655 | -------------------------------------------------------------------------------- /src/constants/crc_u64.rs: -------------------------------------------------------------------------------- 1 | #[rustfmt::skip] 2 | pub(crate) const NO_REF_40_0000000004820009: [u64; 256] = [0u64, 75628553u64, 151257106u64, 226885659u64, 302514212u64, 378142765u64, 453771318u64, 529399871u64, 605028424u64, 546439233u64, 756285530u64, 697696339u64, 907542636u64, 848953445u64, 1058799742u64, 1000210551u64, 1210056848u64, 1285685401u64, 1092878466u64, 1168507019u64, 1512571060u64, 1588199613u64, 1395392678u64, 1471021231u64, 1815085272u64, 1756496081u64, 1697906890u64, 1639317699u64, 2117599484u64, 2059010293u64, 2000421102u64, 1941831911u64, 2420113696u64, 2495742249u64, 2571370802u64, 2646999355u64, 2185756932u64, 2261385485u64, 2337014038u64, 2412642591u64, 3025142120u64, 2966552929u64, 3176399226u64, 3117810035u64, 2790785356u64, 2732196165u64, 2942042462u64, 2883453271u64, 3630170544u64, 3705799097u64, 3512992162u64, 3588620715u64, 3395813780u64, 3471442333u64, 3278635398u64, 3354263951u64, 4235198968u64, 4176609777u64, 4118020586u64, 4059431395u64, 4000842204u64, 3942253013u64, 3883663822u64, 3825074631u64, 4840227392u64, 4899078729u64, 4991484498u64, 5050335835u64, 5142741604u64, 5201592941u64, 5293998710u64, 5352850047u64, 4371513864u64, 4296147457u64, 4522770970u64, 4447404563u64, 4674028076u64, 4598661669u64, 4825285182u64, 4749918775u64, 6050284240u64, 6109135577u64, 5933105858u64, 5991957195u64, 6352798452u64, 6411649789u64, 6235620070u64, 6294471407u64, 5581570712u64, 5506204305u64, 5464392330u64, 5389025923u64, 5884084924u64, 5808718517u64, 5766906542u64, 5691540135u64, 7260341088u64, 7319192425u64, 7411598194u64, 7470449531u64, 7025984324u64, 7084835661u64, 7177241430u64, 7236092767u64, 6791627560u64, 6716261153u64, 6942884666u64, 6867518259u64, 6557270796u64, 6481904389u64, 6708527902u64, 6633161495u64, 8470397936u64, 8529249273u64, 8353219554u64, 8412070891u64, 8236041172u64, 8294892509u64, 8118862790u64, 8177714127u64, 8001684408u64, 7926318001u64, 7884506026u64, 7809139619u64, 7767327644u64, 7691961237u64, 7650149262u64, 7574782855u64, 9680454784u64, 9756083337u64, 9798157458u64, 9873786011u64, 9982968996u64, 10058597549u64, 10100671670u64, 10176300223u64, 10285483208u64, 10226894017u64, 10403185882u64, 10344596691u64, 10587997420u64, 10529408229u64, 10705700094u64, 10647110903u64, 8743027728u64, 8818656281u64, 8592294914u64, 8667923467u64, 9045541940u64, 9121170493u64, 8894809126u64, 8970437679u64, 9348056152u64, 9289466961u64, 9197323338u64, 9138734147u64, 9650570364u64, 9591981173u64, 9499837550u64, 9441248359u64, 12100568480u64, 12176197033u64, 12218271154u64, 12293899707u64, 11866211716u64, 11941840269u64, 11983914390u64, 12059542943u64, 12705596904u64, 12647007713u64, 12823299578u64, 12764710387u64, 12471240140u64, 12412650949u64, 12588942814u64, 12530353623u64, 11163141424u64, 11238769977u64, 11012408610u64, 11088037163u64, 10928784660u64, 11004413213u64, 10778051846u64, 10853680399u64, 11768169848u64, 11709580657u64, 11617437034u64, 11558847843u64, 11533813084u64, 11475223893u64, 11383080270u64, 11324491079u64, 14520682176u64, 14579533513u64, 14638384850u64, 14697236187u64, 14823196388u64, 14882047725u64, 14940899062u64, 14999750399u64, 14051968648u64, 13976602241u64, 14169671322u64, 14094304915u64, 14354482860u64, 14279116453u64, 14472185534u64, 14396819127u64, 13583255120u64, 13642106457u64, 13432522306u64, 13491373643u64, 13885769332u64, 13944620669u64, 13735036518u64, 13793887855u64, 13114541592u64, 13039175185u64, 12963808778u64, 12888442371u64, 13417055804u64, 13341689397u64, 13266322990u64, 13190956583u64, 16940795872u64, 16999647209u64, 17058498546u64, 17117349883u64, 16706439108u64, 16765290445u64, 16824141782u64, 16882993119u64, 16472082344u64, 16396715937u64, 16589785018u64, 16514418611u64, 16237725580u64, 16162359173u64, 16355428254u64, 16280061847u64, 16003368816u64, 16062220153u64, 15852636002u64, 15911487339u64, 15769012052u64, 15827863389u64, 15618279238u64, 15677130575u64, 15534655288u64, 15459288881u64, 15383922474u64, 15308556067u64, 15300298524u64, 15224932117u64, 15149565710u64, 15074199303u64]; 3 | 4 | #[rustfmt::skip] 5 | pub(crate) const NO_REF_64_42F0E1EBA9EA3693: [u64; 256] = [0u64, 4823603603198064275u64, 9647207206396128550u64, 14344283933443513269u64, 5274672035359026399u64, 847670339082705484u64, 14759040976900489721u64, 10241823793177474922u64, 10549344070718052798u64, 15030250704074698541u64, 1695340678165410968u64, 6158653484774949387u64, 15804726273676621153u64, 11071337880091427826u64, 6824194888265062471u64, 2036903512645398228u64, 7367177604490692079u64, 2651944067726553980u64, 16419204125234161865u64, 11613757334439845466u64, 3390681356330821936u64, 7926053118503640995u64, 12317306969549898774u64, 16726154088988619397u64, 17607865585094646865u64, 13162708473643690690u64, 8194994013375312247u64, 3695931686473304036u64, 13648389776530124942u64, 18417527692557321757u64, 4073807025290796456u64, 8825348881154370363u64, 14734355208981384158u64, 10271039580541631821u64, 5303888135453107960u64, 822984195088142443u64, 9604374506261047041u64, 14391664176758772114u64, 47380625301539367u64, 4780770595170139316u64, 6781362712661643872u64, 2084283301222999283u64, 15852106237007281990u64, 11028505464239851989u64, 1670654249350217407u64, 6187869865390245932u64, 10578560694269006745u64, 15005564104267687178u64, 12269926345859042865u64, 16768987096479742114u64, 3433514057002836759u64, 7878672873577829764u64, 16389988026750624494u64, 11638443477897467005u64, 7391863372946608072u64, 2622728278751721819u64, 4044590402276644751u64, 8850035479350698268u64, 13673076206955870889u64, 18388311311405091898u64, 8147614050581592912u64, 3738764100714335683u64, 17650697762308740726u64, 13115328684529279205u64, 15709965168302367023u64, 11021966344253216700u64, 6909860770376862729u64, 2095335087373712026u64, 10607776270906215920u64, 15115916238825782115u64, 1645968390176284886u64, 6063892853452478021u64, 5216239979862816913u64, 762004938812542466u64, 14808413130408695223u64, 10336584279807992612u64, 94761250603078734u64, 4872975272980325085u64, 9561541190340278632u64, 14285852213486374907u64, 13562725425323287744u64, 18359094313119879763u64, 4168566602445998566u64, 8874722219015798645u64, 17657238303940757535u64, 13257468400305012364u64, 8136561383943382329u64, 3610266854770152362u64, 3341308498700434814u64, 7831293060043656173u64, 12375739730780491864u64, 16811819059476047563u64, 7452841817450123681u64, 2710377314828461874u64, 16324444680414493831u64, 11564384134825822740u64, 1621282580641819377u64, 6093108618008534114u64, 10636992411005044695u64, 15091230119249932612u64, 6867028114005673518u64, 2142715359940571325u64, 15757345747155659528u64, 10979133309658045851u64, 9518708972583580495u64, 14333231979791697372u64, 142141253402664553u64, 4830142882085382394u64, 14783726745893216144u64, 10365800689136969987u64, 5245456557503443638u64, 737318311902463013u64, 8089180804553289502u64, 3653099890976004493u64, 17700070958701396536u64, 13210088128275084459u64, 4139350461810230209u64, 8899408340202190162u64, 13587411233247080167u64, 18329878549100632180u64, 16295228101163185824u64, 11589070762272702515u64, 7477528201428671366u64, 2681160907110034709u64, 12328359726370364031u64, 16854651450907929836u64, 3384140715920324441u64, 7783913295349006794u64, 17796789492404876493u64, 12973186262895182430u64, 8294265019745835499u64, 3597188614796881784u64, 13819721540753725458u64, 18246723593521770113u64, 4190670174747424052u64, 8707887697765516199u64, 7249714899603402099u64, 2768808468102880224u64, 16248400991498780757u64, 11785088403942012614u64, 3291936780352569772u64, 8025325358597240639u64, 12127785706904956042u64, 16915077318774037017u64, 10432479959725633826u64, 15147713122803500977u64, 1524009877625084932u64, 6329456346323069591u64, 15705454305770282493u64, 11170082187107838830u64, 6635271944638132443u64, 2226424485906433608u64, 189522501206157468u64, 4634679410803088911u64, 9745950545960650170u64, 14245012653811987241u64, 5445476407655580739u64, 676338306971005648u64, 14876502445374089573u64, 10124960353263198198u64, 4215391513593610003u64, 8678706776937023872u64, 13790540925671641653u64, 18271444552530207910u64, 8337133204891997132u64, 3549843186494580063u64, 17749444438031597290u64, 13016054137459951737u64, 12170653315997410989u64, 16867732534171963454u64, 3244592164593781643u64, 8068192726900473112u64, 16273122767886764658u64, 11755906975779290337u64, 7220533709540304724u64, 2793530071884239303u64, 6682616997400869628u64, 2183556611878603887u64, 15662586120087312346u64, 11217427617020813641u64, 1553190491096487459u64, 6304735387851432112u64, 10407758620342516485u64, 15176894045242543510u64, 14905683634900247362u64, 10100238751092381137u64, 5420754629656923748u64, 705519735670536439u64, 9793295161182637981u64, 14202145287119436046u64, 146654890503152315u64, 4682024195942093864u64, 3242565161283638754u64, 7930564333232481137u64, 12186217236017068228u64, 17000743249723264599u64, 7335380351123765565u64, 2827240748300537774u64, 16153640314560107547u64, 11735716164790313608u64, 13734056228011347036u64, 18188291445129067215u64, 4285430719881142650u64, 8757259798139230185u64, 17846161249714921603u64, 13067947420601767440u64, 8235833358291897765u64, 3511522545606540086u64, 5387043107155988493u64, 590673871457609374u64, 14925875833148783915u64, 10219719885873843128u64, 284282506805329106u64, 4684052045342640705u64, 9660285764170764788u64, 14186579979835500391u64, 15610694155489642931u64, 11120709418076880672u64, 6720936860919424149u64, 2284857304564388358u64, 10490913115006887276u64, 15233377424362361855u64, 1474636623804926026u64, 6234696958930763481u64, 16178361609106579004u64, 11706535215248140463u64, 7306199781952008986u64, 2851961734412043657u64, 12229085463316509411u64, 16953397843693241456u64, 3195220067441434565u64, 7973432182840617302u64, 8278700923620460418u64, 3464177731752866065u64, 17798816680404380324u64, 13110814815472245815u64, 4310152537884486493u64, 8728078392784608718u64, 13704874997943502459u64, 18213013024491712744u64, 9707630858549910483u64, 14143712128616820032u64, 241414281116563189u64, 4731397450835853414u64, 14955056402857342732u64, 10194998898151653791u64, 5362321814220069418u64, 619854820462849209u64, 1503817855483314797u64, 6209975379031176446u64, 10466191297540353867u64, 15262558828106308056u64, 6768281431840648882u64, 2241989909157107745u64, 15567826590698013588u64, 11168054230320002311u64]; 6 | 7 | #[rustfmt::skip] 8 | pub(crate) const REF_64_D800000000000000: [u64; 256] = [0u64, 121597189939003392, 243194379878006784u64, 202661983231672320u64, 486388759756013568u64, 535928355657089024u64, 405323966463344640u64, 292733975779082240u64, 972777519512027136u64, 878201927337246720u64, 1071856711314178048u64, 1103381908705771520u64, 810647932926689280u64, 788129934789836800u64, 585467951558164480u64, 689050742987685888u64, 1945555039024054272u64, 1923037040887201792u64, 1756403854674493440u64, 1859986646104014848u64, 2143713422628356096u64, 2049137830453575680u64, 2206763817411543040u64, 2238289014803136512u64, 1621295865853378560u64, 1670835461754454016u64, 1576259869579673600u64, 1463669878895411200u64, 1170935903116328960u64, 1292533093055332352u64, 1378101485975371776u64, 1337569089329037312u64, 3891110078048108544u64, 4012707267987111936u64, 3846074081774403584u64, 3805541685128069120u64, 3512807709348986880u64, 3562347305250062336u64, 3719973292208029696u64, 3607383301523767296u64, 4287426845256712192u64, 4192851253081931776u64, 4098275660907151360u64, 4129800858298744832u64, 4413527634823086080u64, 4391009636686233600u64, 4476578029606273024u64, 4580160821035794432u64, 3242591731706757120u64, 3220073733569904640u64, 3341670923508908032u64, 3445253714938429440u64, 3152519739159347200u64, 3057944146984566784u64, 2927339757790822400u64, 2958864955182415872u64, 2341871806232657920u64, 2391411402133733376u64, 2585066186110664704u64, 2472476195426402304u64, 2756202971950743552u64, 2877800161889746944u64, 2675138178658074624u64, 2634605782011740160u64, 7782220156096217088u64, 7903817346035220480u64, 8025414535974223872u64, 7984882139327889408u64, 7692148163548807168u64, 7741687759449882624u64, 7611083370256138240u64, 7498493379571875840u64, 7025615418697973760u64, 6931039826523193344u64, 7124694610500124672u64, 7156219807891718144u64, 7439946584416059392u64, 7417428586279206912u64, 7214766603047534592u64, 7318349394477056000u64, 8574853690513424384u64, 8552335692376571904u64, 8385702506163863552u64, 8489285297593384960u64, 8196551321814302720u64, 8101975729639522304u64, 8259601716597489664u64, 8291126913989083136u64, 8827055269646172160u64, 8876594865547247616u64, 8782019273372467200u64, 8669429282688204800u64, 8953156059212546048u64, 9074753249151549440u64, 9160321642071588864u64, 9119789245425254400u64, 6485183463413514240u64, 6606780653352517632u64, 6440147467139809280u64, 6399615070493474816u64, 6683341847017816064u64, 6732881442918891520u64, 6890507429876858880u64, 6777917439192596480u64, 6305039478318694400u64, 6210463886143913984u64, 6115888293969133568u64, 6147413491360727040u64, 5854679515581644800u64, 5832161517444792320u64, 5917729910364831744u64, 6021312701794353152u64, 4683743612465315840u64, 4661225614328463360u64, 4782822804267466752u64, 4886405595696988160u64, 5170132372221329408u64, 5075556780046548992u64, 4944952390852804608u64, 4976477588244398080u64, 5512405943901487104u64, 5561945539802562560u64, 5755600323779493888u64, 5643010333095231488u64, 5350276357316149248u64, 5471873547255152640u64, 5269211564023480320u64, 5228679167377145856u64, 15564440312192434176u64, 15686037502131437568u64, 15807634692070440960u64, 15767102295424106496u64, 16050829071948447744u64, 16100368667849523200u64, 15969764278655778816u64, 15857174287971516416u64, 15384296327097614336u64, 15289720734922833920u64, 15483375518899765248u64, 15514900716291358720u64, 15222166740512276480u64, 15199648742375424000u64, 14996986759143751680u64, 15100569550573273088u64, 14051230837395947520u64, 14028712839259095040u64, 13862079653046386688u64, 13965662444475908096u64, 14249389221000249344u64, 14154813628825468928u64, 14312439615783436288u64, 14343964813175029760u64, 14879893168832118784u64, 14929432764733194240u64, 14834857172558413824u64, 14722267181874151424u64, 14429533206095069184u64, 14551130396034072576u64, 14636698788954112000u64, 14596166392307777536u64, 17149707381026848768u64, 17271304570965852160u64, 17104671384753143808u64, 17064138988106809344u64, 16771405012327727104u64, 16820944608228802560u64, 16978570595186769920u64, 16865980604502507520u64, 16393102643628605440u64, 16298527051453825024u64, 16203951459279044608u64, 16235476656670638080u64, 16519203433194979328u64, 16496685435058126848u64, 16582253827978166272u64, 16685836619407687680u64, 17654110539292344320u64, 17631592541155491840u64, 17753189731094495232u64, 17856772522524016640u64, 17564038546744934400u64, 17469462954570153984u64, 17338858565376409600u64, 17370383762768003072u64, 17906312118425092096u64, 17955851714326167552u64, 18149506498303098880u64, 18036916507618836480u64, 18320643284143177728u64, 18442240474082181120u64, 18239578490850508800u64, 18199046094204174336u64, 12970366926827028480u64, 13091964116766031872u64, 13213561306705035264u64, 13173028910058700800u64, 12880294934279618560u64, 12929834530180694016u64, 12799230140986949632u64, 12686640150302687232u64, 13366683694035632128u64, 13272108101860851712u64, 13465762885837783040u64, 13497288083229376512u64, 13781014859753717760u64, 13758496861616865280u64, 13555834878385192960u64, 13659417669814714368u64, 12610078956637388800u64, 12587560958500536320u64, 12420927772287827968u64, 12524510563717349376u64, 12231776587938267136u64, 12137200995763486720u64, 12294826982721454080u64, 12326352180113047552u64, 11709359031163289600u64, 11758898627064365056u64, 11664323034889584640u64, 11551733044205322240u64, 11835459820729663488u64, 11957057010668666880u64, 12042625403588706304u64, 12002093006942371840u64, 9367487224930631680u64, 9489084414869635072u64, 9322451228656926720u64, 9281918832010592256u64, 9565645608534933504u64, 9615185204436008960u64, 9772811191393976320u64, 9660221200709713920u64, 10340264744442658816u64, 10245689152267878400u64, 10151113560093097984u64, 10182638757484691456u64, 9889904781705609216u64, 9867386783568756736u64, 9952955176488796160u64, 10056537967918317568u64, 11024811887802974208u64, 11002293889666121728u64, 11123891079605125120u64, 11227473871034646528u64, 11511200647558987776u64, 11416625055384207360u64, 11286020666190462976u64, 11317545863582056448u64, 10700552714632298496u64, 10750092310533373952u64, 10943747094510305280u64, 10831157103826042880u64, 10538423128046960640u64, 10660020317985964032u64, 10457358334754291712u64, 10416825938107957248u64]; 9 | 10 | #[rustfmt::skip] 11 | pub(crate) const REF_64_95AC9329AC4BC9B5: [u64; 256] = [0u64, 8851949072701294969u64, 17703898145402589938u64, 10333669153493130123u64, 13851072938616403599u64, 13465927519055396854u64, 3857338458010461309u64, 5715195658523061508u64, 12333367839138578037u64, 15127763206205961996u64, 6816212484437830791u64, 2612226237385041406u64, 7714676916020922618u64, 1281407202545942915u64, 11430391317046123016u64, 16463076249205199729u64, 9009731685717012353u64, 563108230357313272u64, 9851657908567506291u64, 17465080730062222346u64, 13632424968875661582u64, 14404880506683019383u64, 5224452474770082812u64, 3627802401766982277u64, 15429353832041845236u64, 12463821128841762957u64, 2562814405091885830u64, 6433535930597116543u64, 1592294032496338811u64, 7836410910743637506u64, 16404387395731993993u64, 11056451039949864176u64, 18019463371434024706u64, 9280105458721969787u64, 1126216460714626544u64, 8464919223366468745u64, 4190910634541279629u64, 4679640014836523252u64, 14959263154764675967u64, 13060872525739979270u64, 5852729821509460343u64, 3161916214005835790u64, 11856275032257016709u64, 16019730051968187132u64, 10448904949540165624u64, 16994763621833383553u64, 7255604803533964554u64, 2191395843288271987u64, 9734813498046853251u64, 18285020776702097914u64, 8262382231073956465u64, 608425843627928328u64, 5125628810183771660u64, 4465764294926438261u64, 12867071861194233086u64, 14432195567501024647u64, 3184588064992677622u64, 6262709589572306831u64, 15672821821487275012u64, 11770576130456212861u64, 17008134862606432377u64, 10867599606483677440u64, 1853769023980628619u64, 7161174014982448114u64, 16103423924954344815u64, 11935289383220651030u64, 3083341959784644509u64, 5769757520242456292u64, 2252432921429253088u64, 7321251034957484697u64, 16929838446732937490u64, 10388307452745547883u64, 8381821269082559258u64, 1047727658635319907u64, 9359280029673046504u64, 18102965619612993681u64, 13000435797616977301u64, 14894146905688698092u64, 4745161141923116903u64, 4252033715651608094u64, 11705459643018920686u64, 15612384854998895511u64, 6323832428011671580u64, 3250108949404244325u64, 7082685524280996961u64, 1770671381070249240u64, 10951102161764411027u64, 17087309740654948330u64, 674072313427442843u64, 8323419547594995170u64, 18224423522563763817u64, 9669888565606754064u64, 14511209607067929108u64, 12950765422787986285u64, 4382791686576543974u64, 5047054248884015519u64, 2696289253709771373u64, 6895947823530343188u64, 15049839570318909599u64, 12250835051042597350u64, 16524764462147912930u64, 11496477575961038235u64, 1216851687255856656u64, 7654800921679748969u64, 10251257620367543320u64, 17625884659327141217u64, 8931528589852876522u64, 84259039178430355u64, 5655163293556783767u64, 3792978414742418414u64, 13532134484260726885u64, 13912670750543257884u64, 6369176129985355244u64, 2502782282785952917u64, 12525419179144613662u64, 15495561035627234919u64, 10978437246791527267u64, 16321975555527844378u64, 7920669638525335953u64, 1671873238255513832u64, 17531166746306175897u64, 9913345878835194592u64, 503231997654823275u64, 8945175932061546514u64, 3707538047961257238u64, 5308515798192249967u64, 14322348029964896228u64, 13554501644362141341u64, 10785157014839085493u64, 17254666630495879372u64, 6925536469308201799u64, 1928669229005230654u64, 6166683919569289018u64, 3408106242218915395u64, 11539515040484912584u64, 15779741191858611377u64, 4504865842858506176u64, 4925828954283753145u64, 14642502069914969394u64, 12820884771576065099u64, 18355716529793696079u64, 9540007361421969462u64, 796147016248169405u64, 8202193697865996996u64, 16763642538165118516u64, 10555343349626187597u64, 2095455317270639814u64, 7479631577382337983u64, 2926364910754730171u64, 5928137516128508354u64, 15937228569359352393u64, 12102324735718361904u64, 4867406749023426625u64, 4131191115536978232u64, 13131477498808912563u64, 14763945261529023434u64, 9490322283846233806u64, 17972763431062038455u64, 8504067431303216188u64, 926884511990314309u64, 8051711962477172407u64, 1541670979892322254u64, 11100683476643087429u64, 16201132341218348348u64, 12647664856023343160u64, 15374718365700663617u64, 6500217898808488650u64, 2372580570961558451u64, 14165371048561993922u64, 13712881572587659707u64, 3541342762140498480u64, 5475551080882205513u64, 337036156713721421u64, 9112211761281881908u64, 17374189211922025663u64, 10071726351451997638u64, 1348144626854885686u64, 7524919785159454799u64, 16646839095189990340u64, 11375251796044276413u64, 15171913658969673657u64, 12129609824107054784u64, 2827581646778391883u64, 6766067242130363442u64, 13374985906044110659u64, 14070668113165684282u64, 5489218623395763633u64, 3960334819262667976u64, 8765583373153087948u64, 251615998827411637u64, 10094108497768031038u64, 17783882574922426951u64, 5392578507419542746u64, 3462768234654100899u64, 13791895647060686376u64, 14249064643987996497u64, 10011129131143811669u64, 17309264314385947436u64, 9177858264896848039u64, 398073508124084702u64, 16284634862666717871u64, 11179858319785628630u64, 1463182455377365085u64, 7968614284679676196u64, 2433703374511713312u64, 6565738749404456281u64, 15309601843359497938u64, 12587227855704700843u64, 4025855981238586203u64, 5550341738321543714u64, 14010231419946703273u64, 13309869690798280912u64, 17863057179705753044u64, 10177610780853122221u64, 168518078356860710u64, 8687094605961012831u64, 11310326587113567534u64, 16586241563491499095u64, 7585956829484836828u64, 1413790823389195941u64, 6687492953022055329u64, 2744609311697881816u64, 12213303662187237715u64, 15250927976100943914u64, 12738352259970710488u64, 14564578711588090529u64, 5005564565571905834u64, 4588929132448424019u64, 8142317431333358935u64, 731591227688682542u64, 9606093343850471333u64, 18417404465172059868u64, 2012927990619293101u64, 7005115709973351636u64, 17176652871151048543u64, 10702745209522052646u64, 15841339277050671906u64, 11605722277885901403u64, 3343746476511027664u64, 6106651831093618857u64, 14830152191845028953u64, 13193075276920315168u64, 4071158715666679467u64, 4803046671925235666u64, 1006463995309646550u64, 8588326435575524271u64, 17890351864123093028u64, 9412308762883553629u64, 7415076095922514476u64, 2035579357833339733u64, 10617031596384499934u64, 16829728831969243559u64, 12024401134718426275u64, 15854695815076877786u64, 6012200567359213137u64, 3006100283679606568u64]; 12 | -------------------------------------------------------------------------------- /src/constants/crc_u16.rs: -------------------------------------------------------------------------------- 1 | #[rustfmt::skip] 2 | pub(crate) const NO_REF_16_0589: [u16; 256] = [0u16, 1417u16, 2834u16, 3739u16, 5668u16, 5037u16, 7478u16, 6335u16, 11336u16, 10689u16, 10074u16, 8915u16, 14956u16, 16357u16, 12670u16, 13559u16, 22672u16, 23833u16, 21378u16, 22027u16, 20148u16, 19261u16, 17830u16, 16431u16, 29912u16, 29009u16, 32714u16, 31299u16, 25340u16, 26485u16, 27118u16, 27751u16, 45344u16, 46249u16, 47666u16, 49083u16, 42756u16, 41613u16, 44054u16, 43423u16, 40296u16, 39137u16, 38522u16, 37875u16, 35660u16, 36549u16, 32862u16, 34263u16, 59824u16, 60473u16, 58018u16, 59179u16, 65428u16, 64029u16, 62598u16, 61711u16, 50680u16, 49265u16, 52970u16, 52067u16, 54236u16, 54869u16, 55502u16, 56647u16, 26569u16, 25152u16, 27867u16, 26962u16, 29165u16, 29796u16, 31487u16, 32630u16, 19329u16, 19976u16, 16531u16, 17690u16, 23973u16, 22572u16, 22199u16, 21310u16, 16217u16, 15056u16, 13387u16, 12738u16, 10621u16, 11508u16, 8815u16, 10214u16, 4881u16, 5784u16, 6147u16, 7562u16, 1333u16, 188u16, 3623u16, 2990u16, 55017u16, 54112u16, 56827u16, 55410u16, 49357u16, 50500u16, 52191u16, 52822u16, 64161u16, 65320u16, 61875u16, 62522u16, 60549u16, 59660u16, 59287u16, 57886u16, 36473u16, 35824u16, 34155u16, 32994u16, 39005u16, 40404u16, 37711u16, 38598u16, 41521u16, 42936u16, 43299u16, 44202u16, 46101u16, 45468u16, 48903u16, 47758u16, 53138u16, 51739u16, 50304u16, 49417u16, 55734u16, 56383u16, 53924u16, 55085u16, 58330u16, 58963u16, 59592u16, 60737u16, 62974u16, 61559u16, 65260u16, 64357u16, 38658u16, 37515u16, 39952u16, 39321u16, 33062u16, 33967u16, 35380u16, 36797u16, 47946u16, 48835u16, 45144u16, 46545u16, 44398u16, 43239u16, 42620u16, 41973u16, 32434u16, 31547u16, 30112u16, 28713u16, 26774u16, 27935u16, 25476u16, 26125u16, 21242u16, 22387u16, 23016u16, 23649u16, 17630u16, 16727u16, 20428u16, 19013u16, 9762u16, 9131u16, 11568u16, 10425u16, 12294u16, 13711u16, 15124u16, 16029u16, 2666u16, 4067u16, 376u16, 1265u16, 7246u16, 6599u16, 5980u16, 4821u16, 43099u16, 44498u16, 41801u16, 42688u16, 48767u16, 48118u16, 46445u16, 45284u16, 33811u16, 33178u16, 36609u16, 35464u16, 37431u16, 38846u16, 39205u16, 40108u16, 61643u16, 62786u16, 64473u16, 65104u16, 59119u16, 58214u16, 60925u16, 59508u16, 56451u16, 55562u16, 55185u16, 53784u16, 51879u16, 53038u16, 49589u16, 50236u16, 6523u16, 7410u16, 4713u16, 6112u16, 3935u16, 2774u16, 1101u16, 452u16, 13619u16, 12474u16, 15905u16, 15272u16, 8983u16, 9886u16, 10245u16, 11660u16, 16875u16, 17506u16, 19193u16, 20336u16, 22479u16, 21062u16, 23773u16, 22868u16, 28067u16, 26666u16, 26289u16, 25400u16, 31623u16, 32270u16, 28821u16, 29980u16]; 3 | 4 | #[rustfmt::skip] 5 | pub(crate) const NO_REF_16_1021: [u16; 256] = [0u16, 4129u16, 8258u16, 12387u16, 16516u16, 20645u16, 24774u16, 28903u16, 33032u16, 37161u16, 41290u16, 45419u16, 49548u16, 53677u16, 57806u16, 61935u16, 4657u16, 528u16, 12915u16, 8786u16, 21173u16, 17044u16, 29431u16, 25302u16, 37689u16, 33560u16, 45947u16, 41818u16, 54205u16, 50076u16, 62463u16, 58334u16, 9314u16, 13379u16, 1056u16, 5121u16, 25830u16, 29895u16, 17572u16, 21637u16, 42346u16, 46411u16, 34088u16, 38153u16, 58862u16, 62927u16, 50604u16, 54669u16, 13907u16, 9842u16, 5649u16, 1584u16, 30423u16, 26358u16, 22165u16, 18100u16, 46939u16, 42874u16, 38681u16, 34616u16, 63455u16, 59390u16, 55197u16, 51132u16, 18628u16, 22757u16, 26758u16, 30887u16, 2112u16, 6241u16, 10242u16, 14371u16, 51660u16, 55789u16, 59790u16, 63919u16, 35144u16, 39273u16, 43274u16, 47403u16, 23285u16, 19156u16, 31415u16, 27286u16, 6769u16, 2640u16, 14899u16, 10770u16, 56317u16, 52188u16, 64447u16, 60318u16, 39801u16, 35672u16, 47931u16, 43802u16, 27814u16, 31879u16, 19684u16, 23749u16, 11298u16, 15363u16, 3168u16, 7233u16, 60846u16, 64911u16, 52716u16, 56781u16, 44330u16, 48395u16, 36200u16, 40265u16, 32407u16, 28342u16, 24277u16, 20212u16, 15891u16, 11826u16, 7761u16, 3696u16, 65439u16, 61374u16, 57309u16, 53244u16, 48923u16, 44858u16, 40793u16, 36728u16, 37256u16, 33193u16, 45514u16, 41451u16, 53516u16, 49453u16, 61774u16, 57711u16, 4224u16, 161u16, 12482u16, 8419u16, 20484u16, 16421u16, 28742u16, 24679u16, 33721u16, 37784u16, 41979u16, 46042u16, 49981u16, 54044u16, 58239u16, 62302u16, 689u16, 4752u16, 8947u16, 13010u16, 16949u16, 21012u16, 25207u16, 29270u16, 46570u16, 42443u16, 38312u16, 34185u16, 62830u16, 58703u16, 54572u16, 50445u16, 13538u16, 9411u16, 5280u16, 1153u16, 29798u16, 25671u16, 21540u16, 17413u16, 42971u16, 47098u16, 34713u16, 38840u16, 59231u16, 63358u16, 50973u16, 55100u16, 9939u16, 14066u16, 1681u16, 5808u16, 26199u16, 30326u16, 17941u16, 22068u16, 55628u16, 51565u16, 63758u16, 59695u16, 39368u16, 35305u16, 47498u16, 43435u16, 22596u16, 18533u16, 30726u16, 26663u16, 6336u16, 2273u16, 14466u16, 10403u16, 52093u16, 56156u16, 60223u16, 64286u16, 35833u16, 39896u16, 43963u16, 48026u16, 19061u16, 23124u16, 27191u16, 31254u16, 2801u16, 6864u16, 10931u16, 14994u16, 64814u16, 60687u16, 56684u16, 52557u16, 48554u16, 44427u16, 40424u16, 36297u16, 31782u16, 27655u16, 23652u16, 19525u16, 15522u16, 11395u16, 7392u16, 3265u16, 61215u16, 65342u16, 53085u16, 57212u16, 44955u16, 49082u16, 36825u16, 40952u16, 28183u16, 32310u16, 20053u16, 24180u16, 11923u16, 16050u16, 3793u16, 7920u16]; 6 | 7 | #[rustfmt::skip] 8 | pub(crate) const NO_REF_16_3D65: [u16; 256] = [0u16, 15717u16, 31434u16, 18351u16, 62868u16, 51441u16, 36702u16, 45627u16, 54861u16, 60200u16, 44167u16, 37346u16, 9177u16, 7868u16, 22803u16, 25718u16, 37375u16, 44186u16, 60213u16, 54864u16, 25707u16, 22798u16, 7841u16, 9156u16, 18354u16, 31447u16, 15736u16, 29u16, 45606u16, 36675u16, 51436u16, 62857u16, 7835u16, 9214u16, 25681u16, 22836u16, 60175u16, 54890u16, 37317u16, 44192u16, 51414u16, 62899u16, 45596u16, 36729u16, 15682u16, 39u16, 18312u16, 31469u16, 36708u16, 45569u16, 62894u16, 51403u16, 31472u16, 18325u16, 58u16, 15711u16, 22825u16, 25676u16, 9187u16, 7814u16, 44221u16, 37336u16, 54903u16, 60178u16, 15670u16, 83u16, 18428u16, 31385u16, 51362u16, 62919u16, 45672u16, 36621u16, 60283u16, 54814u16, 37297u16, 44244u16, 7919u16, 9098u16, 25637u16, 22848u16, 44233u16, 37292u16, 54787u16, 60262u16, 22877u16, 25656u16, 9111u16, 7922u16, 31364u16, 18401u16, 78u16, 15659u16, 36624u16, 45685u16, 62938u16, 51391u16, 9133u16, 7880u16, 22887u16, 25602u16, 54841u16, 60252u16, 44275u16, 37270u16, 62944u16, 51333u16, 36650u16, 45647u16, 116u16, 15633u16, 31422u16, 18395u16, 45650u16, 36663u16, 51352u16, 62973u16, 18374u16, 31395u16, 15628u16, 105u16, 25631u16, 22906u16, 7893u16, 9136u16, 37259u16, 44270u16, 60225u16, 54820u16, 31340u16, 18185u16, 166u16, 15811u16, 36856u16, 45725u16, 62770u16, 51287u16, 44065u16, 37188u16, 55019u16, 60302u16, 22965u16, 25808u16, 9087u16, 7706u16, 60307u16, 55030u16, 37209u16, 44092u16, 7687u16, 9058u16, 25805u16, 22952u16, 15838u16, 187u16, 18196u16, 31345u16, 51274u16, 62767u16, 45696u16, 36837u16, 25847u16, 22930u16, 7741u16, 9048u16, 37219u16, 44038u16, 60329u16, 54988u16, 45754u16, 36831u16, 51312u16, 62741u16, 18222u16, 31307u16, 15844u16, 129u16, 62728u16, 51309u16, 36802u16, 45735u16, 156u16, 15865u16, 31318u16, 18227u16, 9029u16, 7712u16, 22927u16, 25834u16, 54993u16, 60340u16, 44059u16, 37246u16, 18266u16, 31295u16, 15760u16, 245u16, 45774u16, 36779u16, 51204u16, 62817u16, 37143u16, 44146u16, 60381u16, 54968u16, 25731u16, 23014u16, 7753u16, 9004u16, 54949u16, 60352u16, 44143u16, 37130u16, 9009u16, 7764u16, 23035u16, 25758u16, 232u16, 15757u16, 31266u16, 18247u16, 62844u16, 51225u16, 36790u16, 45779u16, 22977u16, 25764u16, 8971u16, 7790u16, 44117u16, 37168u16, 54943u16, 60410u16, 36748u16, 45801u16, 62790u16, 51235u16, 31256u16, 18301u16, 210u16, 15799u16, 51262u16, 62811u16, 45812u16, 36753u16, 15786u16, 207u16, 18272u16, 31237u16, 7795u16, 8982u16, 25785u16, 23004u16, 60391u16, 54914u16, 37165u16, 44104u16]; 9 | 10 | #[rustfmt::skip] 11 | pub(crate) const NO_REF_16_8005: [u16; 256] = [0u16, 32773u16, 32783u16, 10u16, 32795u16, 30u16, 20u16, 32785u16, 32819u16, 54u16, 60u16, 32825u16, 40u16, 32813u16, 32807u16, 34u16, 32867u16, 102u16, 108u16, 32873u16, 120u16, 32893u16, 32887u16, 114u16, 80u16, 32853u16, 32863u16, 90u16, 32843u16, 78u16, 68u16, 32833u16, 32963u16, 198u16, 204u16, 32969u16, 216u16, 32989u16, 32983u16, 210u16, 240u16, 33013u16, 33023u16, 250u16, 33003u16, 238u16, 228u16, 32993u16, 160u16, 32933u16, 32943u16, 170u16, 32955u16, 190u16, 180u16, 32945u16, 32915u16, 150u16, 156u16, 32921u16, 136u16, 32909u16, 32903u16, 130u16, 33155u16, 390u16, 396u16, 33161u16, 408u16, 33181u16, 33175u16, 402u16, 432u16, 33205u16, 33215u16, 442u16, 33195u16, 430u16, 420u16, 33185u16, 480u16, 33253u16, 33263u16, 490u16, 33275u16, 510u16, 500u16, 33265u16, 33235u16, 470u16, 476u16, 33241u16, 456u16, 33229u16, 33223u16, 450u16, 320u16, 33093u16, 33103u16, 330u16, 33115u16, 350u16, 340u16, 33105u16, 33139u16, 374u16, 380u16, 33145u16, 360u16, 33133u16, 33127u16, 354u16, 33059u16, 294u16, 300u16, 33065u16, 312u16, 33085u16, 33079u16, 306u16, 272u16, 33045u16, 33055u16, 282u16, 33035u16, 270u16, 260u16, 33025u16, 33539u16, 774u16, 780u16, 33545u16, 792u16, 33565u16, 33559u16, 786u16, 816u16, 33589u16, 33599u16, 826u16, 33579u16, 814u16, 804u16, 33569u16, 864u16, 33637u16, 33647u16, 874u16, 33659u16, 894u16, 884u16, 33649u16, 33619u16, 854u16, 860u16, 33625u16, 840u16, 33613u16, 33607u16, 834u16, 960u16, 33733u16, 33743u16, 970u16, 33755u16, 990u16, 980u16, 33745u16, 33779u16, 1014u16, 1020u16, 33785u16, 1000u16, 33773u16, 33767u16, 994u16, 33699u16, 934u16, 940u16, 33705u16, 952u16, 33725u16, 33719u16, 946u16, 912u16, 33685u16, 33695u16, 922u16, 33675u16, 910u16, 900u16, 33665u16, 640u16, 33413u16, 33423u16, 650u16, 33435u16, 670u16, 660u16, 33425u16, 33459u16, 694u16, 700u16, 33465u16, 680u16, 33453u16, 33447u16, 674u16, 33507u16, 742u16, 748u16, 33513u16, 760u16, 33533u16, 33527u16, 754u16, 720u16, 33493u16, 33503u16, 730u16, 33483u16, 718u16, 708u16, 33473u16, 33347u16, 582u16, 588u16, 33353u16, 600u16, 33373u16, 33367u16, 594u16, 624u16, 33397u16, 33407u16, 634u16, 33387u16, 622u16, 612u16, 33377u16, 544u16, 33317u16, 33327u16, 554u16, 33339u16, 574u16, 564u16, 33329u16, 33299u16, 534u16, 540u16, 33305u16, 520u16, 33293u16, 33287u16, 514u16]; 12 | 13 | #[rustfmt::skip] 14 | pub(crate) const NO_REF_16_8BB7: [u16; 256] = [0u16, 35767u16, 40153u16, 5998u16, 45573u16, 14770u16, 11996u16, 42347u16, 61373u16, 25610u16, 29540u16, 63699u16, 23992u16, 54799u16, 49505u16, 19158u16, 21709u16, 57210u16, 51220u16, 17315u16, 59080u16, 28031u16, 31249u16, 61862u16, 47984u16, 12487u16, 10153u16, 44062u16, 2421u16, 33474u16, 38316u16, 7707u16, 43418u16, 8749u16, 13635u16, 48884u16, 7071u16, 36904u16, 34630u16, 3313u16, 17959u16, 52624u16, 56062u16, 20809u16, 62498u16, 32661u16, 26875u16, 58188u16, 64855u16, 30432u16, 24974u16, 59961u16, 20306u16, 50405u16, 54155u16, 22588u16, 4842u16, 39261u16, 36403u16, 1412u16, 41199u16, 11096u16, 15414u16, 46977u16, 55427u16, 21300u16, 17498u16, 53229u16, 27270u16, 57649u16, 63071u16, 32232u16, 14142u16, 48265u16, 44007u16, 8272u16, 34107u16, 3724u16, 6626u16, 37461u16, 35918u16, 2041u16, 4247u16, 39712u16, 15947u16, 46588u16, 41618u16, 10533u16, 25587u16, 59460u16, 65322u16, 29853u16, 53750u16, 23105u16, 19759u16, 50840u16, 28953u16, 64174u16, 60864u16, 26231u16, 49948u16, 18603u16, 24517u16, 54386u16, 40612u16, 5395u16, 637u16, 35274u16, 11425u16, 42774u16, 45176u16, 15311u16, 9684u16, 44643u16, 47373u16, 12986u16, 38865u16, 7270u16, 2824u16, 32959u16, 51817u16, 16862u16, 22192u16, 56583u16, 30828u16, 62427u16, 58549u16, 28418u16, 15025u16, 45318u16, 42600u16, 11743u16, 34996u16, 771u16, 5229u16, 40922u16, 54540u16, 24251u16, 18901u16, 49762u16, 26377u16, 60606u16, 64464u16, 28775u16, 28284u16, 58827u16, 62117u16, 30994u16, 56441u16, 22478u16, 16544u16, 51991u16, 33217u16, 2678u16, 7448u16, 38575u16, 13252u16, 47219u16, 44829u16, 9386u16, 37675u16, 6300u16, 4082u16, 33861u16, 8494u16, 43673u16, 48631u16, 13888u16, 31894u16, 63265u16, 57423u16, 27640u16, 52883u16, 17700u16, 21066u16, 55805u16, 51174u16, 19537u16, 23359u16, 53384u16, 30179u16, 65108u16, 59706u16, 25229u16, 10331u16, 41964u16, 46210u16, 16181u16, 39518u16, 4585u16, 1671u16, 36144u16, 57906u16, 27013u16, 32491u16, 62812u16, 20535u16, 56192u16, 52462u16, 18265u16, 3471u16, 34360u16, 37206u16, 6881u16, 49034u16, 13373u16, 9043u16, 43236u16, 46847u16, 15688u16, 10790u16, 41361u16, 1274u16, 36685u16, 38947u16, 5012u16, 22850u16, 54005u16, 50587u16, 20012u16, 60231u16, 24816u16, 30622u16, 64553u16, 19368u16, 49183u16, 55153u16, 23750u16, 63917u16, 29210u16, 25972u16, 61123u16, 42005u16, 12194u16, 14540u16, 45947u16, 5648u16, 40359u16, 35529u16, 382u16, 8037u16, 38098u16, 33724u16, 2059u16, 44384u16, 9943u16, 12729u16, 47630u16, 61656u16, 31599u16, 27649u16, 59318u16, 17117u16, 51562u16, 56836u16, 21939u16]; 15 | 16 | #[rustfmt::skip] 17 | pub(crate) const NO_REF_16_C867: [u16; 256] = [0u16, 51303u16, 22697u16, 37070u16, 45394u16, 31029u16, 59899u16, 8604u16, 43715u16, 25252u16, 62058u16, 14861u16, 7057u16, 54262u16, 17208u16, 35679u16, 40417u16, 21894u16, 50504u16, 3375u16, 11443u16, 58580u16, 29722u16, 48253u16, 14114u16, 65349u16, 28555u16, 42988u16, 34416u16, 19991u16, 57049u16, 5822u16, 62373u16, 15298u16, 43788u16, 25451u16, 17143u16, 35472u16, 6750u16, 53817u16, 22886u16, 37121u16, 463u16, 51624u16, 59444u16, 8275u16, 45213u16, 30970u16, 28228u16, 42531u16, 14061u16, 65162u16, 57110u16, 6001u16, 34751u16, 20440u16, 50311u16, 3296u16, 39982u16, 21577u16, 30165u16, 48562u16, 11644u16, 58651u16, 12077u16, 59210u16, 30596u16, 49123u16, 40575u16, 22040u16, 50902u16, 3761u16, 34286u16, 19849u16, 56647u16, 5408u16, 13500u16, 64731u16, 27669u16, 42098u16, 45772u16, 31403u16, 60005u16, 8706u16, 926u16, 52217u16, 23351u16, 37712u16, 6159u16, 53352u16, 16550u16, 35009u16, 43357u16, 24890u16, 61940u16, 14739u16, 56456u16, 5359u16, 33825u16, 19526u16, 28122u16, 42429u16, 13683u16, 64788u16, 30283u16, 48684u16, 12002u16, 59013u16, 50969u16, 3966u16, 40880u16, 22487u16, 16745u16, 35086u16, 6592u16, 53671u16, 61499u16, 14428u16, 43154u16, 24821u16, 60330u16, 9165u16, 45827u16, 31588u16, 23288u16, 37535u16, 593u16, 51766u16, 24154u16, 38461u16, 1779u16, 52884u16, 61192u16, 10095u16, 47009u16, 32710u16, 62617u16, 15614u16, 44080u16, 25687u16, 17867u16, 36268u16, 7522u16, 54533u16, 50107u16, 3036u16, 39698u16, 21365u16, 29417u16, 47758u16, 10816u16, 57895u16, 27000u16, 41247u16, 12753u16, 63926u16, 55338u16, 4173u16, 32899u16, 18660u16, 44543u16, 26008u16, 62806u16, 15665u16, 7341u16, 54474u16, 17412u16, 35939u16, 1852u16, 53083u16, 24469u16, 38898u16, 46702u16, 32265u16, 61127u16, 9888u16, 12318u16, 63609u16, 26807u16, 41168u16, 33100u16, 18731u16, 55781u16, 4482u16, 39645u16, 21178u16, 49780u16, 2579u16, 11151u16, 58344u16, 29478u16, 47937u16, 29047u16, 47376u16, 10718u16, 57785u16, 49189u16, 2114u16, 39052u16, 20715u16, 56244u16, 5075u16, 33565u16, 19322u16, 27366u16, 41601u16, 12879u16, 64040u16, 60566u16, 9457u16, 46143u16, 31832u16, 24004u16, 38307u16, 1389u16, 52490u16, 18005u16, 36402u16, 7932u16, 54939u16, 63239u16, 16224u16, 44974u16, 26569u16, 33490u16, 19125u16, 55931u16, 4636u16, 13184u16, 64487u16, 27433u16, 41806u16, 10257u16, 57462u16, 28856u16, 47327u16, 39235u16, 20772u16, 49642u16, 2445u16, 7987u16, 55124u16, 18330u16, 36861u16, 44641u16, 26118u16, 63176u16, 16047u16, 46576u16, 32151u16, 60761u16, 9534u16, 1186u16, 52421u16, 23563u16, 37996u16]; 18 | 19 | #[rustfmt::skip] 20 | pub(crate) const REF_16_8408: [u16; 256] = [0u16, 4489u16, 8978u16, 12955u16, 17956u16, 22445u16, 25910u16, 29887u16, 35912u16, 40385u16, 44890u16, 48851u16, 51820u16, 56293u16, 59774u16, 63735u16, 4225u16, 264u16, 13203u16, 8730u16, 22181u16, 18220u16, 30135u16, 25662u16, 40137u16, 36160u16, 49115u16, 44626u16, 56045u16, 52068u16, 63999u16, 59510u16, 8450u16, 12427u16, 528u16, 5017u16, 26406u16, 30383u16, 17460u16, 21949u16, 44362u16, 48323u16, 36440u16, 40913u16, 60270u16, 64231u16, 51324u16, 55797u16, 12675u16, 8202u16, 4753u16, 792u16, 30631u16, 26158u16, 21685u16, 17724u16, 48587u16, 44098u16, 40665u16, 36688u16, 64495u16, 60006u16, 55549u16, 51572u16, 16900u16, 21389u16, 24854u16, 28831u16, 1056u16, 5545u16, 10034u16, 14011u16, 52812u16, 57285u16, 60766u16, 64727u16, 34920u16, 39393u16, 43898u16, 47859u16, 21125u16, 17164u16, 29079u16, 24606u16, 5281u16, 1320u16, 14259u16, 9786u16, 57037u16, 53060u16, 64991u16, 60502u16, 39145u16, 35168u16, 48123u16, 43634u16, 25350u16, 29327u16, 16404u16, 20893u16, 9506u16, 13483u16, 1584u16, 6073u16, 61262u16, 65223u16, 52316u16, 56789u16, 43370u16, 47331u16, 35448u16, 39921u16, 29575u16, 25102u16, 20629u16, 16668u16, 13731u16, 9258u16, 5809u16, 1848u16, 65487u16, 60998u16, 56541u16, 52564u16, 47595u16, 43106u16, 39673u16, 35696u16, 33800u16, 38273u16, 42778u16, 46739u16, 49708u16, 54181u16, 57662u16, 61623u16, 2112u16, 6601u16, 11090u16, 15067u16, 20068u16, 24557u16, 28022u16, 31999u16, 38025u16, 34048u16, 47003u16, 42514u16, 53933u16, 49956u16, 61887u16, 57398u16, 6337u16, 2376u16, 15315u16, 10842u16, 24293u16, 20332u16, 32247u16, 27774u16, 42250u16, 46211u16, 34328u16, 38801u16, 58158u16, 62119u16, 49212u16, 53685u16, 10562u16, 14539u16, 2640u16, 7129u16, 28518u16, 32495u16, 19572u16, 24061u16, 46475u16, 41986u16, 38553u16, 34576u16, 62383u16, 57894u16, 53437u16, 49460u16, 14787u16, 10314u16, 6865u16, 2904u16, 32743u16, 28270u16, 23797u16, 19836u16, 50700u16, 55173u16, 58654u16, 62615u16, 32808u16, 37281u16, 41786u16, 45747u16, 19012u16, 23501u16, 26966u16, 30943u16, 3168u16, 7657u16, 12146u16, 16123u16, 54925u16, 50948u16, 62879u16, 58390u16, 37033u16, 33056u16, 46011u16, 41522u16, 23237u16, 19276u16, 31191u16, 26718u16, 7393u16, 3432u16, 16371u16, 11898u16, 59150u16, 63111u16, 50204u16, 54677u16, 41258u16, 45219u16, 33336u16, 37809u16, 27462u16, 31439u16, 18516u16, 23005u16, 11618u16, 15595u16, 3696u16, 8185u16, 63375u16, 58886u16, 54429u16, 50452u16, 45483u16, 40994u16, 37561u16, 33584u16, 31687u16, 27214u16, 22741u16, 18780u16, 15843u16, 11370u16, 7921u16, 3960u16]; 21 | 22 | #[rustfmt::skip] 23 | pub(crate) const REF_16_A001: [u16; 256] = [0u16, 49345u16, 49537u16, 320u16, 49921u16, 960u16, 640u16, 49729u16, 50689u16, 1728u16, 1920u16, 51009u16, 1280u16, 50625u16, 50305u16, 1088u16, 52225u16, 3264u16, 3456u16, 52545u16, 3840u16, 53185u16, 52865u16, 3648u16, 2560u16, 51905u16, 52097u16, 2880u16, 51457u16, 2496u16, 2176u16, 51265u16, 55297u16, 6336u16, 6528u16, 55617u16, 6912u16, 56257u16, 55937u16, 6720u16, 7680u16, 57025u16, 57217u16, 8000u16, 56577u16, 7616u16, 7296u16, 56385u16, 5120u16, 54465u16, 54657u16, 5440u16, 55041u16, 6080u16, 5760u16, 54849u16, 53761u16, 4800u16, 4992u16, 54081u16, 4352u16, 53697u16, 53377u16, 4160u16, 61441u16, 12480u16, 12672u16, 61761u16, 13056u16, 62401u16, 62081u16, 12864u16, 13824u16, 63169u16, 63361u16, 14144u16, 62721u16, 13760u16, 13440u16, 62529u16, 15360u16, 64705u16, 64897u16, 15680u16, 65281u16, 16320u16, 16000u16, 65089u16, 64001u16, 15040u16, 15232u16, 64321u16, 14592u16, 63937u16, 63617u16, 14400u16, 10240u16, 59585u16, 59777u16, 10560u16, 60161u16, 11200u16, 10880u16, 59969u16, 60929u16, 11968u16, 12160u16, 61249u16, 11520u16, 60865u16, 60545u16, 11328u16, 58369u16, 9408u16, 9600u16, 58689u16, 9984u16, 59329u16, 59009u16, 9792u16, 8704u16, 58049u16, 58241u16, 9024u16, 57601u16, 8640u16, 8320u16, 57409u16, 40961u16, 24768u16, 24960u16, 41281u16, 25344u16, 41921u16, 41601u16, 25152u16, 26112u16, 42689u16, 42881u16, 26432u16, 42241u16, 26048u16, 25728u16, 42049u16, 27648u16, 44225u16, 44417u16, 27968u16, 44801u16, 28608u16, 28288u16, 44609u16, 43521u16, 27328u16, 27520u16, 43841u16, 26880u16, 43457u16, 43137u16, 26688u16, 30720u16, 47297u16, 47489u16, 31040u16, 47873u16, 31680u16, 31360u16, 47681u16, 48641u16, 32448u16, 32640u16, 48961u16, 32000u16, 48577u16, 48257u16, 31808u16, 46081u16, 29888u16, 30080u16, 46401u16, 30464u16, 47041u16, 46721u16, 30272u16, 29184u16, 45761u16, 45953u16, 29504u16, 45313u16, 29120u16, 28800u16, 45121u16, 20480u16, 37057u16, 37249u16, 20800u16, 37633u16, 21440u16, 21120u16, 37441u16, 38401u16, 22208u16, 22400u16, 38721u16, 21760u16, 38337u16, 38017u16, 21568u16, 39937u16, 23744u16, 23936u16, 40257u16, 24320u16, 40897u16, 40577u16, 24128u16, 23040u16, 39617u16, 39809u16, 23360u16, 39169u16, 22976u16, 22656u16, 38977u16, 34817u16, 18624u16, 18816u16, 35137u16, 19200u16, 35777u16, 35457u16, 19008u16, 19968u16, 36545u16, 36737u16, 20288u16, 36097u16, 19904u16, 19584u16, 35905u16, 17408u16, 33985u16, 34177u16, 17728u16, 34561u16, 18368u16, 18048u16, 34369u16, 33281u16, 17088u16, 17280u16, 33601u16, 16640u16, 33217u16, 32897u16, 16448u16]; 24 | 25 | #[rustfmt::skip] 26 | pub(crate) const REF_16_A097: [u16; 256] = [0u16, 41111u16, 57785u16, 16686u16, 25573u16, 50034u16, 33372u16, 8907u16, 51146u16, 26461u16, 9843u16, 34532u16, 42031u16, 1208u16, 17814u16, 58625u16, 12035u16, 36756u16, 52922u16, 28205u16, 19686u16, 60529u16, 44383u16, 3528u16, 59593u16, 18526u16, 2416u16, 43495u16, 35628u16, 11195u16, 27285u16, 51714u16, 24070u16, 65169u16, 49087u16, 7976u16, 15843u16, 40308u16, 56410u16, 31949u16, 39372u16, 14683u16, 30837u16, 55522u16, 64041u16, 23230u16, 7056u16, 47879u16, 28933u16, 53650u16, 37052u16, 12331u16, 4832u16, 45687u16, 62297u16, 21454u16, 46799u16, 5720u16, 22390u16, 63457u16, 54570u16, 30141u16, 13459u16, 37892u16, 48140u16, 7323u16, 23989u16, 64802u16, 57321u16, 32638u16, 15952u16, 40647u16, 31686u16, 56145u16, 39551u16, 15080u16, 6179u16, 47284u16, 63898u16, 22797u16, 37647u16, 13208u16, 29366u16, 53793u16, 61674u16, 20605u16, 4435u16, 45508u16, 21701u16, 62546u16, 46460u16, 5611u16, 14112u16, 38839u16, 54937u16, 30222u16, 57866u16, 17053u16, 947u16, 41764u16, 33263u16, 8568u16, 24662u16, 49345u16, 9664u16, 34135u16, 50297u16, 25838u16, 17957u16, 59058u16, 42908u16, 1803u16, 52489u16, 28062u16, 11440u16, 35879u16, 44780u16, 3707u16, 20309u16, 61378u16, 2755u16, 43604u16, 60282u16, 19437u16, 26918u16, 51633u16, 34975u16, 10248u16, 55439u16, 30744u16, 14646u16, 39329u16, 47978u16, 7165u16, 23251u16, 64068u16, 8005u16, 49106u16, 65276u16, 24171u16, 31904u16, 56375u16, 40217u16, 15758u16, 63372u16, 22299u16, 5685u16, 46754u16, 37993u16, 13566u16, 30160u16, 54599u16, 12358u16, 37073u16, 53759u16, 29032u16, 21411u16, 62260u16, 45594u16, 4749u16, 34441u16, 9758u16, 26416u16, 51111u16, 58732u16, 17915u16, 1237u16, 42050u16, 16707u16, 57812u16, 41210u16, 109u16, 8870u16, 33329u16, 49951u16, 25480u16, 43402u16, 2333u16, 18483u16, 59556u16, 51823u16, 27384u16, 11222u16, 35649u16, 28224u16, 52951u16, 36857u16, 12142u16, 3493u16, 44338u16, 60444u16, 19595u16, 25731u16, 50196u16, 34106u16, 9645u16, 1894u16, 42993u16, 59103u16, 17992u16, 41801u16, 990u16, 17136u16, 57959u16, 49324u16, 24635u16, 8469u16, 33154u16, 19328u16, 60183u16, 43577u16, 2734u16, 10341u16, 35058u16, 51676u16, 26955u16, 35914u16, 11485u16, 28147u16, 52580u16, 61359u16, 20280u16, 3606u16, 44673u16, 14981u16, 39442u16, 56124u16, 31659u16, 22880u16, 63991u16, 47321u16, 6222u16, 64847u16, 24024u16, 7414u16, 48225u16, 40618u16, 15933u16, 32531u16, 57220u16, 5510u16, 46353u16, 62527u16, 21672u16, 30307u16, 55028u16, 38874u16, 14157u16, 53836u16, 29403u16, 13301u16, 37730u16, 45481u16, 4414u16, 20496u16, 61575u16]; 27 | 28 | #[rustfmt::skip] 29 | pub(crate) const REF_16_A6BC: [u16; 256] = [0u16, 13918u16, 27836u16, 23266u16, 55672u16, 61222u16, 46532u16, 33690u16, 65417u16, 51671u16, 37685u16, 42347u16, 9969u16, 4271u16, 19021u16, 31763u16, 45675u16, 33845u16, 57047u16, 59529u16, 27411u16, 23885u16, 1967u16, 12785u16, 19938u16, 31676u16, 8542u16, 5888u16, 38042u16, 41668u16, 63526u16, 52856u16, 10671u16, 8177u16, 17683u16, 29517u16, 61655u16, 50825u16, 40043u16, 43573u16, 54822u16, 57464u16, 47770u16, 36036u16, 3934u16, 14592u16, 25570u16, 21948u16, 39876u16, 44442u16, 63352u16, 49446u16, 17084u16, 29922u16, 11776u16, 6238u16, 25677u16, 21011u16, 2289u16, 16047u16, 48437u16, 35691u16, 53641u16, 59351u16, 21342u16, 25856u16, 16354u16, 2492u16, 35366u16, 48248u16, 59034u16, 53444u16, 44247u16, 39561u16, 49259u16, 63029u16, 30127u16, 17393u16, 6419u16, 12109u16, 57653u16, 55147u16, 36233u16, 48087u16, 14413u16, 3603u16, 21745u16, 25263u16, 7868u16, 10466u16, 29184u16, 17502u16, 51140u16, 61850u16, 43896u16, 40230u16, 31473u16, 19631u16, 5709u16, 8211u16, 41865u16, 38359u16, 53045u16, 63851u16, 34168u16, 45862u16, 59844u16, 57242u16, 23552u16, 27230u16, 12476u16, 1762u16, 51354u16, 65220u16, 42022u16, 37496u16, 4578u16, 10172u16, 32094u16, 19200u16, 14099u16, 333u16, 23471u16, 28145u16, 61035u16, 55349u16, 33495u16, 46217u16, 42684u16, 37090u16, 51712u16, 64606u16, 32708u16, 18842u16, 4984u16, 9510u16, 22837u16, 28523u16, 13705u16, 983u16, 32845u16, 46611u16, 60657u16, 55983u16, 5335u16, 8841u16, 30827u16, 20021u16, 52655u16, 64497u16, 41235u16, 38733u16, 60254u16, 56576u16, 34786u16, 45500u16, 12838u16, 1144u16, 24218u16, 26820u16, 36627u16, 47437u16, 58287u16, 54769u16, 22123u16, 24629u16, 15063u16, 3209u16, 28826u16, 18116u16, 7206u16, 10872u16, 43490u16, 40892u16, 50526u16, 62208u16, 15736u16, 2854u16, 20932u16, 26522u16, 58368u16, 53854u16, 35004u16, 48866u16, 49905u16, 62639u16, 44621u16, 38931u16, 7049u16, 11735u16, 30517u16, 16747u16, 62946u16, 50108u16, 39262u16, 44800u16, 11418u16, 6852u16, 16422u16, 30328u16, 2667u16, 15413u16, 26327u16, 20617u16, 54035u16, 58701u16, 49071u16, 35313u16, 18313u16, 29143u16, 11061u16, 7531u16, 40689u16, 43183u16, 62029u16, 50195u16, 47104u16, 36446u16, 54460u16, 58082u16, 24952u16, 22310u16, 3524u16, 15258u16, 56397u16, 59923u16, 45297u16, 34479u16, 1333u16, 13163u16, 27017u16, 24535u16, 9156u16, 5530u16, 20344u16, 31014u16, 64188u16, 52450u16, 38400u16, 41054u16, 28198u16, 22648u16, 666u16, 13508u16, 46942u16, 33024u16, 56290u16, 60860u16, 37295u16, 42993u16, 64787u16, 52045u16, 18647u16, 32393u16, 9323u16, 4661u16]; 30 | -------------------------------------------------------------------------------- /src/crc_u32.rs: -------------------------------------------------------------------------------- 1 | #[cfg(feature = "alloc")] 2 | use alloc::fmt::{self, Debug, Display, Formatter}; 3 | #[cfg(feature = "alloc")] 4 | use alloc::vec::Vec; 5 | 6 | #[cfg(feature = "heapless")] 7 | use heapless::Vec as HeaplessVec; 8 | 9 | use crate::{constants::crc_u32::*, lookup_table::LookUpTable}; 10 | 11 | #[allow(clippy::upper_case_acronyms)] 12 | /// This struct can help you compute a CRC-32 (or CRC-x where **x** is equal or less than `32`) value. 13 | pub struct CRCu32 { 14 | by_table: bool, 15 | poly: u32, 16 | lookup_table: LookUpTable, 17 | sum: u32, 18 | pub(crate) bits: u8, 19 | high_bit: u32, 20 | mask: u32, 21 | initial: u32, 22 | final_xor: u32, 23 | reflect: bool, 24 | reorder: bool, 25 | } 26 | 27 | #[cfg(feature = "alloc")] 28 | impl Debug for CRCu32 { 29 | #[inline] 30 | fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> { 31 | if self.by_table { 32 | debug_helper::impl_debug_for_struct!(CRCu64, f, self, let .lookup_table = self.lookup_table.as_ref(), (.sum, "0x{:08X}", self.sum), .bits, (.initial, "0x{:08X}", self.initial), (.final_xor, "0x{:08X}", self.final_xor), .reflect, .reorder); 33 | } else { 34 | debug_helper::impl_debug_for_struct!(CRCu64, f, self, (.poly, "0x{:08X}", self.poly), (.sum, "0x{:08X}", self.sum), .bits, (.initial, "0x{:08X}", self.initial), (.final_xor, "0x{:08X}", self.final_xor), .reflect, .reorder); 35 | } 36 | } 37 | } 38 | 39 | #[cfg(feature = "alloc")] 40 | impl Display for CRCu32 { 41 | #[inline] 42 | fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> { 43 | f.write_fmt(format_args!("0x{:01$X}", self.get_crc(), (self.bits as usize + 3) >> 2)) 44 | } 45 | } 46 | 47 | impl CRCu32 { 48 | /// Create a `CRCu32` instance by providing the length of bits, expression, reflection, an initial value and a final xor value. 49 | pub fn create_crc(poly: u32, bits: u8, initial: u32, final_xor: u32, reflect: bool) -> CRCu32 { 50 | debug_assert!(bits <= 32 && bits > 0); 51 | 52 | if bits % 8 == 0 { 53 | let lookup_table = if reflect { 54 | LookUpTable::Dynamic(Self::crc_reflect_table(poly)) 55 | } else { 56 | LookUpTable::Dynamic(Self::crc_table(poly, bits)) 57 | }; 58 | 59 | Self::create_crc_with_exists_lookup_table( 60 | lookup_table, 61 | bits, 62 | initial, 63 | final_xor, 64 | reflect, 65 | ) 66 | } else { 67 | Self::create( 68 | false, 69 | LookUpTable::Static(&[0u32; 256]), 70 | poly, 71 | bits, 72 | initial, 73 | final_xor, 74 | reflect, 75 | ) 76 | } 77 | } 78 | 79 | #[inline] 80 | pub(crate) fn create_crc_with_exists_lookup_table( 81 | lookup_table: LookUpTable, 82 | bits: u8, 83 | initial: u32, 84 | final_xor: u32, 85 | reflect: bool, 86 | ) -> CRCu32 { 87 | debug_assert!(bits % 8 == 0); 88 | 89 | Self::create(true, lookup_table, 0, bits, initial, final_xor, reflect) 90 | } 91 | 92 | #[inline] 93 | fn create( 94 | by_table: bool, 95 | lookup_table: LookUpTable, 96 | mut poly: u32, 97 | bits: u8, 98 | initial: u32, 99 | final_xor: u32, 100 | reflect: bool, 101 | ) -> CRCu32 { 102 | let high_bit = 1 << u32::from(bits - 1); 103 | let mask = ((high_bit - 1) << 1) | 1; 104 | 105 | let sum = if reflect { Self::reflect_function(high_bit, initial) } else { initial }; 106 | 107 | if !by_table && reflect { 108 | poly = Self::reflect_function(high_bit, poly); 109 | } 110 | 111 | CRCu32 { 112 | by_table, 113 | poly, 114 | lookup_table, 115 | sum, 116 | bits, 117 | high_bit, 118 | mask, 119 | initial, 120 | final_xor, 121 | reflect, 122 | reorder: false, 123 | } 124 | } 125 | 126 | #[inline] 127 | fn reflect_function(high_bit: u32, n: u32) -> u32 { 128 | let mut i = high_bit; 129 | let mut j = 1; 130 | let mut out = 0; 131 | 132 | while i != 0 { 133 | if n & i != 0 { 134 | out |= j; 135 | } 136 | 137 | j <<= 1; 138 | i >>= 1; 139 | } 140 | 141 | out 142 | } 143 | 144 | #[inline] 145 | fn reflect_method(&self, n: u32) -> u32 { 146 | Self::reflect_function(self.high_bit, n) 147 | } 148 | 149 | /// Digest some data. 150 | pub fn digest>(&mut self, data: &T) { 151 | if self.by_table { 152 | if self.bits == 8 { 153 | for n in data.as_ref().iter().copied() { 154 | let index = (self.sum as u8 ^ n) as usize; 155 | self.sum = self.lookup_table[index]; 156 | } 157 | } else if self.reflect { 158 | for n in data.as_ref().iter().copied() { 159 | let index = ((self.sum as u8) ^ n) as usize; 160 | self.sum = (self.sum >> 8) ^ self.lookup_table[index]; 161 | } 162 | } else { 163 | for n in data.as_ref().iter().copied() { 164 | let index = ((self.sum >> u32::from(self.bits - 8)) as u8 ^ n) as usize; 165 | self.sum = (self.sum << 8) ^ self.lookup_table[index]; 166 | } 167 | } 168 | } else if self.reflect { 169 | for n in data.as_ref().iter().copied() { 170 | let n = super::crc_u8::CRCu8::reflect_function(0x80, n); 171 | 172 | let mut i = 0x80; 173 | 174 | while i != 0 { 175 | let mut bit = self.sum & self.high_bit; 176 | 177 | self.sum <<= 1; 178 | 179 | if n & i != 0 { 180 | bit ^= self.high_bit; 181 | } 182 | 183 | if bit != 0 { 184 | self.sum ^= self.poly; 185 | } 186 | 187 | i >>= 1; 188 | } 189 | } 190 | } else { 191 | for n in data.as_ref().iter().copied() { 192 | let mut i = 0x80; 193 | 194 | while i != 0 { 195 | let mut bit = self.sum & self.high_bit; 196 | 197 | self.sum <<= 1; 198 | 199 | if n & i != 0 { 200 | bit ^= self.high_bit; 201 | } 202 | 203 | if bit != 0 { 204 | self.sum ^= self.poly; 205 | } 206 | 207 | i >>= 1; 208 | } 209 | } 210 | } 211 | } 212 | 213 | /// Reset the sum. 214 | pub fn reset(&mut self) { 215 | self.sum = self.initial; 216 | } 217 | 218 | /// Get the current CRC value (it always returns a `u32` value). You can continue calling `digest` method even after getting a CRC value. 219 | pub fn get_crc(&self) -> u32 { 220 | let sum = if self.by_table || !self.reflect { 221 | (self.sum ^ self.final_xor) & self.mask 222 | } else { 223 | (self.reflect_method(self.sum) ^ self.final_xor) & self.mask 224 | }; 225 | 226 | if self.reorder { 227 | let mut new_sum = 0; 228 | 229 | let e = (self.bits as u32 + 7) >> 3; 230 | 231 | let e_dec = e - 1; 232 | 233 | for i in 0..e { 234 | new_sum |= ((sum >> ((e_dec - i) * 8)) & 0xFF) << (i * 8); 235 | } 236 | 237 | new_sum 238 | } else { 239 | sum 240 | } 241 | } 242 | 243 | fn crc_reflect_table(poly_rev: u32) -> [u32; 256] { 244 | let mut lookup_table = [0u32; 256]; 245 | 246 | for (i, e) in lookup_table.iter_mut().enumerate() { 247 | let mut v = i as u32; 248 | 249 | #[allow(clippy::branches_sharing_code)] 250 | for _ in 0..8u8 { 251 | if v & 1 != 0 { 252 | v >>= 1; 253 | v ^= poly_rev; 254 | } else { 255 | v >>= 1; 256 | } 257 | } 258 | 259 | *e = v; 260 | } 261 | 262 | lookup_table 263 | } 264 | 265 | fn crc_table(poly: u32, bits: u8) -> [u32; 256] { 266 | let mut lookup_table = [0u32; 256]; 267 | 268 | let mask1 = 1u32 << u32::from(bits - 1); 269 | 270 | let mask2 = ((mask1 - 1) << 1) | 1; 271 | 272 | for (i, e) in lookup_table.iter_mut().enumerate() { 273 | let mut v = i as u32; 274 | 275 | #[allow(clippy::branches_sharing_code)] 276 | for _ in 0..bits { 277 | if v & mask1 == 0 { 278 | v <<= 1; 279 | } else { 280 | v <<= 1; 281 | v ^= poly; 282 | } 283 | } 284 | 285 | *e = v & mask2; 286 | } 287 | 288 | lookup_table 289 | } 290 | } 291 | 292 | #[cfg(feature = "alloc")] 293 | impl CRCu32 { 294 | /// Get the current CRC value (it always returns a vec instance with a length corresponding to the CRC bits). You can continue calling `digest` method even after getting a CRC value. 295 | #[inline] 296 | pub fn get_crc_vec_le(&mut self) -> Vec { 297 | let crc = self.get_crc(); 298 | 299 | let e = (self.bits as usize + 7) >> 3; 300 | 301 | crc.to_le_bytes()[..e].to_vec() 302 | } 303 | 304 | /// Get the current CRC value (it always returns a vec instance with a length corresponding to the CRC bits). You can continue calling `digest` method even after getting a CRC value. 305 | #[inline] 306 | pub fn get_crc_vec_be(&mut self) -> Vec { 307 | let crc = self.get_crc(); 308 | 309 | let e = (self.bits as usize + 7) >> 3; 310 | 311 | crc.to_be_bytes()[(4 - e)..].to_vec() 312 | } 313 | } 314 | 315 | #[cfg(feature = "heapless")] 316 | impl CRCu32 { 317 | /// Get the current CRC value (it always returns a heapless vec instance with a length corresponding to the CRC bits). You can continue calling `digest` method even after getting a CRC value. 318 | #[inline] 319 | pub fn get_crc_heapless_vec_le(&mut self) -> HeaplessVec { 320 | let crc = self.get_crc(); 321 | 322 | let e = (self.bits as usize + 7) >> 3; 323 | 324 | let mut vec = HeaplessVec::new(); 325 | 326 | vec.extend_from_slice(&crc.to_le_bytes()[..e]).unwrap(); 327 | 328 | vec 329 | } 330 | 331 | /// Get the current CRC value (it always returns a heapless vec instance with a length corresponding to the CRC bits). You can continue calling `digest` method even after getting a CRC value. 332 | #[inline] 333 | pub fn get_crc_heapless_vec_be(&mut self) -> HeaplessVec { 334 | let crc = self.get_crc(); 335 | 336 | let e = (self.bits as usize + 7) >> 3; 337 | 338 | let mut vec = HeaplessVec::new(); 339 | 340 | vec.extend_from_slice(&crc.to_be_bytes()[(4 - e)..]).unwrap(); 341 | 342 | vec 343 | } 344 | } 345 | 346 | impl CRCu32 { 347 | /// |Check|Poly|Init|Ref|XorOut| 348 | /// |---|---|---|---|---| 349 | /// |0x04F03|0x1685B|0x00000|false|0x00000| 350 | /// 351 | /// ``` 352 | /// # use crc_any::CRCu32; 353 | /// let mut crc = CRCu32::crc17can(); 354 | /// crc.digest(b"123456789"); 355 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0x04F03\", &crc.to_string());")] 356 | /// ``` 357 | pub fn crc17can() -> CRCu32 { 358 | Self::create_crc(0x0001685B, 17, 0x00000000, 0x00000000, false) 359 | } 360 | 361 | /// |Check|Poly|Init|Ref|XorOut| 362 | /// |---|---|---|---|---| 363 | /// |0x0ED841|0x102899|0x000000|false|0x000000| 364 | /// 365 | /// ``` 366 | /// # use crc_any::CRCu32; 367 | /// let mut crc = CRCu32::crc21can(); 368 | /// crc.digest(b"123456789"); 369 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0x0ED841\", &crc.to_string());")] 370 | /// ``` 371 | pub fn crc21can() -> CRCu32 { 372 | Self::create_crc(0x00102899, 21, 0x00000000, 0x00000000, false) 373 | } 374 | 375 | /// |Check|Poly|Init|Ref|XorOut| 376 | /// |---|---|---|---|---| 377 | /// |0x21CF02|0x864CFB|0xB704CE|false|0x000000| 378 | /// 379 | /// ``` 380 | /// # use crc_any::CRCu32; 381 | /// let mut crc = CRCu32::crc24(); 382 | /// crc.digest(b"123456789"); 383 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0x21CF02\", &crc.to_string());")] 384 | /// ``` 385 | pub fn crc24() -> CRCu32 { 386 | // Self::create_crc(0x00864CFB, 24, 0x00B704CE, 0x00000000, false) 387 | 388 | let lookup_table = LookUpTable::Static(&NO_REF_24_00864CFB); 389 | Self::create_crc_with_exists_lookup_table(lookup_table, 24, 0x00B704CE, 0x00000000, false) 390 | } 391 | 392 | /// |Check|Poly|Init|Ref|XorOut| 393 | /// |---|---|---|---|---| 394 | /// |0xC25A56|0x00065B (rev: 0xDA6000)|0x555555|true|0x000000| 395 | /// 396 | /// ``` 397 | /// # use crc_any::CRCu32; 398 | /// let mut crc = CRCu32::crc24ble(); 399 | /// crc.digest(b"123456789"); 400 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0xC25A56\", &crc.to_string());")] 401 | /// ``` 402 | pub fn crc24ble() -> CRCu32 { 403 | // Self::create_crc(0x00DA6000, 24, 0x00555555, 0x00000000, true) 404 | 405 | let lookup_table = LookUpTable::Static(&REF_24_00DA6000); 406 | Self::create_crc_with_exists_lookup_table(lookup_table, 24, 0x00555555, 0x00000000, true) 407 | } 408 | 409 | /// |Check|Poly|Init|Ref|XorOut| 410 | /// |---|---|---|---|---| 411 | /// |0x7979BD|0x5D6DCB|0xFEDCBA|false|0x000000| 412 | /// 413 | /// ``` 414 | /// # use crc_any::CRCu32; 415 | /// let mut crc = CRCu32::crc24flexray_a(); 416 | /// crc.digest(b"123456789"); 417 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0x7979BD\", &crc.to_string());")] 418 | /// ``` 419 | pub fn crc24flexray_a() -> CRCu32 { 420 | // Self::create_crc(0x005D6DCB, 24, 0x00FEDCBA, 0x00000000, false) 421 | 422 | let lookup_table = LookUpTable::Static(&NO_REF_24_005D6DCB); 423 | Self::create_crc_with_exists_lookup_table(lookup_table, 24, 0x00FEDCBA, 0x00000000, false) 424 | } 425 | 426 | /// |Check|Poly|Init|Ref|XorOut| 427 | /// |---|---|---|---|---| 428 | /// |0x1F23B8|0x5D6DCB|0xABCDEF|false|0x000000| 429 | /// 430 | /// ``` 431 | /// # use crc_any::CRCu32; 432 | /// let mut crc = CRCu32::crc24flexray_b(); 433 | /// crc.digest(b"123456789"); 434 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0x1F23B8\", &crc.to_string());")] 435 | /// ``` 436 | pub fn crc24flexray_b() -> CRCu32 { 437 | // Self::create_crc(0x005D6DCB, 24, 0x00ABCDEF, 0x00000000, false) 438 | 439 | let lookup_table = LookUpTable::Static(&NO_REF_24_005D6DCB); 440 | Self::create_crc_with_exists_lookup_table(lookup_table, 24, 0x00ABCDEF, 0x00000000, false) 441 | } 442 | 443 | /// |Check|Poly|Init|Ref|XorOut| 444 | /// |---|---|---|---|---| 445 | /// |0xCDE703|0x864CFB|0x000000|false|0x000000| 446 | /// 447 | /// ``` 448 | /// # use crc_any::CRCu32; 449 | /// let mut crc = CRCu32::crc24lte_a(); 450 | /// crc.digest(b"123456789"); 451 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0xCDE703\", &crc.to_string());")] 452 | /// ``` 453 | pub fn crc24lte_a() -> CRCu32 { 454 | // Self::create_crc(0x00864CFB, 24, 0x00000000, 0x00000000, false) 455 | 456 | let lookup_table = LookUpTable::Static(&NO_REF_24_00864CFB); 457 | Self::create_crc_with_exists_lookup_table(lookup_table, 24, 0x00000000, 0x00000000, false) 458 | } 459 | 460 | /// |Check|Poly|Init|Ref|XorOut| 461 | /// |---|---|---|---|---| 462 | /// |0x23EF52|0x800063|0x000000|false|0x000000| 463 | /// 464 | /// ``` 465 | /// # use crc_any::CRCu32; 466 | /// let mut crc = CRCu32::crc24lte_b(); 467 | /// crc.digest(b"123456789"); 468 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0x23EF52\", &crc.to_string());")] 469 | /// ``` 470 | pub fn crc24lte_b() -> CRCu32 { 471 | // Self::create_crc(0x00800063, 24, 0x00000000, 0x00000000, false) 472 | 473 | let lookup_table = LookUpTable::Static(&NO_REF_24_00800063); 474 | Self::create_crc_with_exists_lookup_table(lookup_table, 24, 0x00000000, 0x00000000, false) 475 | } 476 | 477 | /// |Check|Poly|Init|Ref|XorOut| 478 | /// |---|---|---|---|---| 479 | /// |0x200FA5|0x800063|0xFFFFFF|false|0xFFFFFF| 480 | /// 481 | /// ``` 482 | /// # use crc_any::CRCu32; 483 | /// let mut crc = CRCu32::crc24os9(); 484 | /// crc.digest(b"123456789"); 485 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0x200FA5\", &crc.to_string());")] 486 | /// ``` 487 | pub fn crc24os9() -> CRCu32 { 488 | // Self::create_crc(0x00800063, 24, 0x00FFFFFF, 0x00FFFFFF, false) 489 | 490 | let lookup_table = LookUpTable::Static(&NO_REF_24_00800063); 491 | Self::create_crc_with_exists_lookup_table(lookup_table, 24, 0x00FFFFFF, 0x00FFFFFF, false) 492 | } 493 | 494 | /// |Check|Poly|Init|Ref|XorOut| 495 | /// |---|---|---|---|---| 496 | /// |0x04C34ABF|0x2030B9C7|0x3FFFFFFF|false|0x3FFFFFFF| 497 | /// 498 | /// ``` 499 | /// # use crc_any::CRCu32; 500 | /// let mut crc = CRCu32::crc30cdma(); 501 | /// crc.digest(b"123456789"); 502 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0x04C34ABF\", &crc.to_string());")] 503 | /// ``` 504 | pub fn crc30cdma() -> CRCu32 { 505 | Self::create_crc(0x2030B9C7, 30, 0x3FFFFFFF, 0x3FFFFFFF, false) 506 | } 507 | 508 | /// |Check|Poly|Init|Ref|XorOut| 509 | /// |---|---|---|---|---| 510 | /// |0xCBF43926|0x04C11DB7 (rev: 0xEDB88320)|0xFFFFFFFF|true|0xFFFFFFFF| 511 | /// 512 | /// ``` 513 | /// # use crc_any::CRCu32; 514 | /// let mut crc = CRCu32::crc32(); 515 | /// crc.digest(b"123456789"); 516 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0xCBF43926\", &crc.to_string());")] 517 | /// ``` 518 | pub fn crc32() -> CRCu32 { 519 | // Self::create_crc(0xEDB88320, 32, 0xFFFFFFFF, 0xFFFFFFFF, true) 520 | 521 | let lookup_table = LookUpTable::Static(&REF_32_EDB88320); 522 | Self::create_crc_with_exists_lookup_table(lookup_table, 32, 0xFFFFFFFF, 0xFFFFFFFF, true) 523 | } 524 | 525 | /// |Check|Poly|Init|Ref|XorOut| 526 | /// |---|---|---|---|---| 527 | /// |0x181989FC|0x04C11DB7|0xFFFFFFFF|false|0xFFFFFFFF| 528 | /// 529 | /// **Output will be reversed by bytes.** 530 | /// 531 | /// ``` 532 | /// # use crc_any::CRCu32; 533 | /// let mut crc = CRCu32::crc32mhash(); 534 | /// crc.digest(b"123456789"); 535 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0x181989FC\", &crc.to_string());")] 536 | /// ``` 537 | pub fn crc32mhash() -> CRCu32 { 538 | // let mut crc = Self::create_crc(0x04C11DB7, 32, 0xFFFFFFFF, 0xFFFFFFFF, false); 539 | 540 | let lookup_table = LookUpTable::Static(&NO_REF_32_04C11DB7); 541 | 542 | let mut crc = Self::create_crc_with_exists_lookup_table( 543 | lookup_table, 544 | 32, 545 | 0xFFFFFFFF, 546 | 0xFFFFFFFF, 547 | false, 548 | ); 549 | 550 | crc.reorder = true; 551 | 552 | crc 553 | } 554 | 555 | /// |Check|Poly|Init|Ref|XorOut| 556 | /// |---|---|---|---|---| 557 | /// |0xFC891918|0x04C11DB7|0xFFFFFFFF|false|0xFFFFFFFF| 558 | /// 559 | /// ``` 560 | /// # use crc_any::CRCu32; 561 | /// let mut crc = CRCu32::crc32bzip2(); 562 | /// crc.digest(b"123456789"); 563 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0xFC891918\", &crc.to_string());")] 564 | /// ``` 565 | pub fn crc32bzip2() -> CRCu32 { 566 | // Self::create_crc(0x04C11DB7, 32, 0xFFFFFFFF, 0xFFFFFFFF, false) 567 | 568 | let lookup_table = LookUpTable::Static(&NO_REF_32_04C11DB7); 569 | Self::create_crc_with_exists_lookup_table(lookup_table, 32, 0xFFFFFFFF, 0xFFFFFFFF, false) 570 | } 571 | 572 | /// |Check|Poly|Init|Ref|XorOut| 573 | /// |---|---|---|---|---| 574 | /// |0xE3069283|0x1EDC6F41 (rev: 0x82F63B78)|0xFFFFFFFF|true|0xFFFFFFFF| 575 | /// 576 | /// ``` 577 | /// # use crc_any::CRCu32; 578 | /// let mut crc = CRCu32::crc32c(); 579 | /// crc.digest(b"123456789"); 580 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0xE3069283\", &crc.to_string());")] 581 | /// ``` 582 | pub fn crc32c() -> CRCu32 { 583 | // Self::create_crc(0x82F63B78, 32, 0xFFFFFFFF, 0xFFFFFFFF, true) 584 | 585 | let lookup_table = LookUpTable::Static(&REF_32_82F63B78); 586 | Self::create_crc_with_exists_lookup_table(lookup_table, 32, 0xFFFFFFFF, 0xFFFFFFFF, true) 587 | } 588 | 589 | /// |Check|Poly|Init|Ref|XorOut| 590 | /// |---|---|---|---|---| 591 | /// |0x87315576|0xA833982B (rev: 0xD419CC15)|0xFFFFFFFF|true|0xFFFFFFFF| 592 | /// 593 | /// ``` 594 | /// # use crc_any::CRCu32; 595 | /// let mut crc = CRCu32::crc32d(); 596 | /// crc.digest(b"123456789"); 597 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0x87315576\", &crc.to_string());")] 598 | /// ``` 599 | pub fn crc32d() -> CRCu32 { 600 | // Self::create_crc(0xD419CC15, 32, 0xFFFFFFFF, 0xFFFFFFFF, true) 601 | 602 | let lookup_table = LookUpTable::Static(&REF_32_D419CC15); 603 | Self::create_crc_with_exists_lookup_table(lookup_table, 32, 0xFFFFFFFF, 0xFFFFFFFF, true) 604 | } 605 | 606 | /// |Check|Poly|Init|Ref|XorOut| 607 | /// |---|---|---|---|---| 608 | /// |0x0376E6E7|0x04C11DB7|0xFFFFFFFF|false|0x00000000| 609 | /// 610 | /// ``` 611 | /// # use crc_any::CRCu32; 612 | /// let mut crc = CRCu32::crc32mpeg2(); 613 | /// crc.digest(b"123456789"); 614 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0x0376E6E7\", &crc.to_string());")] 615 | /// ``` 616 | pub fn crc32mpeg2() -> CRCu32 { 617 | // Self::create_crc(0x04C11DB7, 32, 0xFFFFFFFF, 0x00000000, false) 618 | 619 | let lookup_table = LookUpTable::Static(&NO_REF_32_04C11DB7); 620 | Self::create_crc_with_exists_lookup_table(lookup_table, 32, 0xFFFFFFFF, 0x00000000, false) 621 | } 622 | 623 | /// |Check|Poly|Init|Ref|XorOut| 624 | /// |---|---|---|---|---| 625 | /// |0x765E7680|0x04C11DB7|0x00000000|false|0xFFFFFFFF| 626 | /// 627 | /// ``` 628 | /// # use crc_any::CRCu32; 629 | /// let mut crc = CRCu32::crc32posix(); 630 | /// crc.digest(b"123456789"); 631 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0x765E7680\", &crc.to_string());")] 632 | /// ``` 633 | pub fn crc32posix() -> CRCu32 { 634 | // Self::create_crc(0x04C11DB7, 32, 0x00000000, 0xFFFFFFFF, false) 635 | 636 | let lookup_table = LookUpTable::Static(&NO_REF_32_04C11DB7); 637 | Self::create_crc_with_exists_lookup_table(lookup_table, 32, 0x00000000, 0xFFFFFFFF, false) 638 | } 639 | 640 | /// |Check|Poly|Init|Ref|XorOut| 641 | /// |---|---|---|---|---| 642 | /// |0x3010BF7F|0x814141AB|0x00000000|false|0x00000000| 643 | /// 644 | /// ``` 645 | /// # use crc_any::CRCu32; 646 | /// let mut crc = CRCu32::crc32q(); 647 | /// crc.digest(b"123456789"); 648 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0x3010BF7F\", &crc.to_string());")] 649 | /// ``` 650 | pub fn crc32q() -> CRCu32 { 651 | // Self::create_crc(0x814141AB, 32, 0x00000000, 0x00000000, false) 652 | 653 | let lookup_table = LookUpTable::Static(&NO_REF_32_814141AB); 654 | Self::create_crc_with_exists_lookup_table(lookup_table, 32, 0x00000000, 0x00000000, false) 655 | } 656 | 657 | /// |Check|Poly|Init|Ref|XorOut| 658 | /// |---|---|---|---|---| 659 | /// |0x340BC6D9|0x04C11DB7 (rev: 0xEDB88320)|0xFFFFFFFF|true|0x00000000| 660 | /// 661 | /// ``` 662 | /// # use crc_any::CRCu32; 663 | /// let mut crc = CRCu32::crc32jamcrc(); 664 | /// crc.digest(b"123456789"); 665 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0x340BC6D9\", &crc.to_string());")] 666 | /// ``` 667 | pub fn crc32jamcrc() -> CRCu32 { 668 | // Self::create_crc(0xEDB88320, 32, 0xFFFFFFFF, 0x00000000, true) 669 | 670 | let lookup_table = LookUpTable::Static(&REF_32_EDB88320); 671 | Self::create_crc_with_exists_lookup_table(lookup_table, 32, 0xFFFFFFFF, 0x00000000, true) 672 | } 673 | 674 | /// |Check|Poly|Init|Ref|XorOut| 675 | /// |---|---|---|---|---| 676 | /// |0xBD0BE338|0x000000AF|0x00000000|false|0x00000000| 677 | /// 678 | /// ``` 679 | /// # use crc_any::CRCu32; 680 | /// let mut crc = CRCu32::crc32xfer(); 681 | /// crc.digest(b"123456789"); 682 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0xBD0BE338\", &crc.to_string());")] 683 | /// ``` 684 | pub fn crc32xfer() -> CRCu32 { 685 | // Self::create_crc(0x000000AF, 32, 0x00000000, 0x00000000, false) 686 | 687 | let lookup_table = LookUpTable::Static(&NO_REF_32_000000AF); 688 | Self::create_crc_with_exists_lookup_table(lookup_table, 32, 0x00000000, 0x00000000, false) 689 | } 690 | } 691 | 692 | #[cfg(all(feature = "development", test))] 693 | mod tests { 694 | use alloc::{fmt::Write, string::String}; 695 | 696 | use super::CRCu32; 697 | 698 | #[test] 699 | fn print_lookup_table() { 700 | let crc = CRCu32::crc24ble(); 701 | 702 | let mut s = String::new(); 703 | 704 | for n in crc.lookup_table.iter().take(255) { 705 | s.write_fmt(format_args!("{}u32, ", n)).unwrap(); 706 | } 707 | 708 | s.write_fmt(format_args!("{}u32", crc.lookup_table[255])).unwrap(); 709 | 710 | println!("let lookup_table = [{}];", s); 711 | } 712 | } 713 | -------------------------------------------------------------------------------- /src/constants/crc_u32.rs: -------------------------------------------------------------------------------- 1 | #[rustfmt::skip] 2 | pub(crate) const NO_REF_24_005D6DCB: [u32; 256] = [0u32, 6122955u32, 12245910u32, 15185501u32, 2677479u32, 7714604u32, 9568625u32, 13593786u32, 5354958u32, 841733u32, 15429208u32, 11928467u32, 7958313u32, 2360034u32, 12825791u32, 10410356u32, 10709916u32, 16647767u32, 1683466u32, 4513217u32, 9154939u32, 14081200u32, 3238637u32, 7079718u32, 15916626u32, 11514777u32, 4720068u32, 1402895u32, 14288053u32, 8874366u32, 6348579u32, 4043496u32, 1817331u32, 4642616u32, 10576229u32, 16518318u32, 3366932u32, 7212511u32, 9026434u32, 13948489u32, 4853565u32, 1532662u32, 15783083u32, 11385184u32, 6477274u32, 4175889u32, 14159436u32, 8741767u32, 12112239u32, 15056036u32, 133881u32, 6252338u32, 9440136u32, 13461059u32, 2805790u32, 7847381u32, 15295649u32, 11798890u32, 5488439u32, 971516u32, 12697158u32, 10277773u32, 8086992u32, 2492443u32, 3634662u32, 6953005u32, 9285232u32, 13681595u32, 2076417u32, 4375242u32, 10843287u32, 16259420u32, 6733864u32, 3911139u32, 14425022u32, 8484469u32, 5118671u32, 1275652u32, 16040281u32, 11119762u32, 9707130u32, 13202353u32, 3065324u32, 7579687u32, 12371101u32, 14788950u32, 401163u32, 5993152u32, 12954548u32, 10012287u32, 8351778u32, 2235881u32, 15561043u32, 11541656u32, 5745349u32, 706318u32, 2936597u32, 7447262u32, 9835651u32, 13334856u32, 267762u32, 5863481u32, 12504676u32, 14918575u32, 8223451u32, 2103056u32, 13082957u32, 10144902u32, 5611580u32, 577015u32, 15694762u32, 11671137u32, 9413769u32, 13814082u32, 3505951u32, 6820564u32, 10976878u32, 16389029u32, 1943032u32, 4245555u32, 14553415u32, 8617100u32, 6605521u32, 3778330u32, 16173984u32, 11249259u32, 4984886u32, 1146365u32, 7269324u32, 3376647u32, 13906010u32, 9002385u32, 4600107u32, 1793248u32, 16575165u32, 10585974u32, 4152834u32, 6435785u32, 8750484u32, 14215263u32, 1541349u32, 4909358u32, 11362163u32, 15741624u32, 13467728u32, 9498011u32, 7822278u32, 2766349u32, 15030967u32, 12072828u32, 6258977u32, 191722u32, 10237342u32, 12671061u32, 2551304u32, 8094659u32, 11857785u32, 15303346u32, 931055u32, 5462308u32, 7688511u32, 2637044u32, 13601449u32, 9627490u32, 6130648u32, 58899u32, 15159374u32, 12205445u32, 2417905u32, 7964986u32, 10370919u32, 12800684u32, 802326u32, 5329885u32, 11986304u32, 15435851u32, 14039715u32, 9131880u32, 7135541u32, 3247358u32, 16703556u32, 10718607u32, 4471762u32, 1660441u32, 8884077u32, 14344870u32, 4019451u32, 6306096u32, 11490698u32, 15874113u32, 1412636u32, 4776919u32, 5873194u32, 324577u32, 14894524u32, 12462199u32, 7423181u32, 2894086u32, 13344603u32, 9892496u32, 535524u32, 5588527u32, 11726962u32, 15703481u32, 2158851u32, 8232136u32, 10103445u32, 13059934u32, 16446902u32, 10983549u32, 4206112u32, 1917931u32, 13774673u32, 9388698u32, 6878407u32, 3512588u32, 11223160u32, 16133555u32, 1154030u32, 5043749u32, 8624799u32, 14612308u32, 3752201u32, 6565058u32, 4334809u32, 2050322u32, 16318287u32, 10850948u32, 7011902u32, 3642357u32, 13641128u32, 9259107u32, 1282327u32, 5176540u32, 11094657u32, 16000842u32, 3886064u32, 6694459u32, 8491110u32, 14482861u32, 14765893u32, 12329614u32, 6001875u32, 456984u32, 13211042u32, 9762921u32, 7556660u32, 3023871u32, 11598475u32, 15570752u32, 663837u32, 5721302u32, 9969772u32, 12930471u32, 2292730u32, 8361521u32]; 3 | 4 | #[rustfmt::skip] 5 | pub(crate) const NO_REF_24_00800063: [u32; 256] = [0u32, 8388707u32, 8388773u32, 198u32, 8388905u32, 330u32, 396u32, 8389103u32, 8389169u32, 594u32, 660u32, 8389367u32, 792u32, 8389499u32, 8389565u32, 990u32, 8389633u32, 1122u32, 1188u32, 8389831u32, 1320u32, 8389963u32, 8390029u32, 1518u32, 1584u32, 8390227u32, 8390293u32, 1782u32, 8390425u32, 1914u32, 1980u32, 8390623u32, 8390753u32, 2050u32, 2244u32, 8390823u32, 2376u32, 8390955u32, 8391149u32, 2446u32, 2640u32, 8391219u32, 8391413u32, 2710u32, 8391545u32, 2842u32, 3036u32, 8391615u32, 3168u32, 8391683u32, 8391877u32, 3238u32, 8392009u32, 3370u32, 3564u32, 8392079u32, 8392273u32, 3634u32, 3828u32, 8392343u32, 3960u32, 8392475u32, 8392669u32, 4030u32, 8392865u32, 4290u32, 4100u32, 8392807u32, 4488u32, 8393195u32, 8393005u32, 4430u32, 4752u32, 8393459u32, 8393269u32, 4694u32, 8393657u32, 5082u32, 4892u32, 8393599u32, 5280u32, 8393923u32, 8393733u32, 5222u32, 8394121u32, 5610u32, 5420u32, 8394063u32, 8394385u32, 5874u32, 5684u32, 8394327u32, 6072u32, 8394715u32, 8394525u32, 6014u32, 6336u32, 8394915u32, 8394853u32, 6150u32, 8395241u32, 6538u32, 6476u32, 8395055u32, 8395505u32, 6802u32, 6740u32, 8395319u32, 7128u32, 8395707u32, 8395645u32, 6942u32, 8395969u32, 7330u32, 7268u32, 8395783u32, 7656u32, 8396171u32, 8396109u32, 7470u32, 7920u32, 8396435u32, 8396373u32, 7734u32, 8396761u32, 8122u32, 8060u32, 8396575u32, 8397089u32, 8514u32, 8580u32, 8397287u32, 8200u32, 8396907u32, 8396973u32, 8398u32, 8976u32, 8397683u32, 8397749u32, 9174u32, 8397369u32, 8794u32, 8860u32, 8397567u32, 9504u32, 8398147u32, 8398213u32, 9702u32, 8397833u32, 9322u32, 9388u32, 8398031u32, 8398609u32, 10098u32, 10164u32, 8398807u32, 9784u32, 8398427u32, 8398493u32, 9982u32, 10560u32, 8399139u32, 8399333u32, 10630u32, 8398953u32, 10250u32, 10444u32, 8399023u32, 8399729u32, 11026u32, 11220u32, 8399799u32, 10840u32, 8399419u32, 8399613u32, 10910u32, 8400193u32, 11554u32, 11748u32, 8400263u32, 11368u32, 8399883u32, 8400077u32, 11438u32, 12144u32, 8400659u32, 8400853u32, 12214u32, 8400473u32, 11834u32, 12028u32, 8400543u32, 12672u32, 8401379u32, 8401189u32, 12614u32, 8401065u32, 12490u32, 12300u32, 8401007u32, 8401841u32, 13266u32, 13076u32, 8401783u32, 12952u32, 8401659u32, 8401469u32, 12894u32, 8402305u32, 13794u32, 13604u32, 8402247u32, 13480u32, 8402123u32, 8401933u32, 13422u32, 14256u32, 8402899u32, 8402709u32, 14198u32, 8402585u32, 14074u32, 13884u32, 8402527u32, 8403425u32, 14722u32, 14660u32, 8403239u32, 14536u32, 8403115u32, 8403053u32, 14350u32, 15312u32, 8403891u32, 8403829u32, 15126u32, 8403705u32, 15002u32, 14940u32, 8403519u32, 15840u32, 8404355u32, 8404293u32, 15654u32, 8404169u32, 15530u32, 15468u32, 8403983u32, 8404945u32, 16306u32, 16244u32, 8404759u32, 16120u32, 8404635u32, 8404573u32, 15934u32]; 6 | 7 | #[rustfmt::skip] 8 | pub(crate) const NO_REF_24_00864CFB: [u32; 256] = [0u32, 8801531u32, 9098509u32, 825846u32, 9692897u32, 1419802u32, 1651692u32, 10452759u32, 10584377u32, 2608578u32, 2839604u32, 11344079u32, 3303384u32, 11807523u32, 12104405u32, 4128302u32, 12930697u32, 4391538u32, 5217156u32, 13227903u32, 5679208u32, 13690003u32, 14450021u32, 5910942u32, 6606768u32, 14844747u32, 15604413u32, 6837830u32, 16197969u32, 7431594u32, 8256604u32, 16494759u32, 840169u32, 9084178u32, 8783076u32, 18463u32, 10434312u32, 1670131u32, 1434117u32, 9678590u32, 11358416u32, 2825259u32, 2590173u32, 10602790u32, 4109873u32, 12122826u32, 11821884u32, 3289031u32, 13213536u32, 5231515u32, 4409965u32, 12912278u32, 5929345u32, 14431610u32, 13675660u32, 5693559u32, 6823513u32, 15618722u32, 14863188u32, 6588335u32, 16513208u32, 8238147u32, 7417269u32, 16212302u32, 1680338u32, 10481449u32, 9664223u32, 1391140u32, 9061683u32, 788936u32, 36926u32, 8838341u32, 12067563u32, 4091408u32, 3340262u32, 11844381u32, 2868234u32, 11372785u32, 10555655u32, 2579964u32, 14478683u32, 5939616u32, 5650518u32, 13661357u32, 5180346u32, 13190977u32, 12967607u32, 4428364u32, 8219746u32, 16457881u32, 16234863u32, 7468436u32, 15633027u32, 6866552u32, 6578062u32, 14816117u32, 1405499u32, 9649856u32, 10463030u32, 1698765u32, 8819930u32, 55329u32, 803287u32, 9047340u32, 11858690u32, 3325945u32, 4072975u32, 12086004u32, 2561507u32, 10574104u32, 11387118u32, 2853909u32, 13647026u32, 5664841u32, 5958079u32, 14460228u32, 4446803u32, 12949160u32, 13176670u32, 5194661u32, 7454091u32, 16249200u32, 16476294u32, 8201341u32, 14834538u32, 6559633u32, 6852199u32, 15647388u32, 3360676u32, 11864927u32, 12161705u32, 4185682u32, 10527045u32, 2551230u32, 2782280u32, 11286707u32, 9619101u32, 1346150u32, 1577872u32, 10379115u32, 73852u32, 8875143u32, 9172337u32, 899466u32, 16124205u32, 7357910u32, 8182816u32, 16421083u32, 6680524u32, 14918455u32, 15678145u32, 6911546u32, 5736468u32, 13747439u32, 14507289u32, 5968354u32, 12873461u32, 4334094u32, 5159928u32, 13170435u32, 4167245u32, 12180150u32, 11879232u32, 3346363u32, 11301036u32, 2767959u32, 2532769u32, 10545498u32, 10360692u32, 1596303u32, 1360505u32, 9604738u32, 913813u32, 9157998u32, 8856728u32, 92259u32, 16439492u32, 8164415u32, 7343561u32, 16138546u32, 6897189u32, 15692510u32, 14936872u32, 6662099u32, 5986813u32, 14488838u32, 13733104u32, 5750795u32, 13156124u32, 5174247u32, 4352529u32, 12855018u32, 2810998u32, 11315341u32, 10498427u32, 2522496u32, 12124823u32, 4148844u32, 3397530u32, 11901793u32, 9135439u32, 862644u32, 110658u32, 8912057u32, 1606574u32, 10407765u32, 9590435u32, 1317464u32, 15706879u32, 6940164u32, 6651890u32, 14889737u32, 8145950u32, 16384229u32, 16161043u32, 7394792u32, 5123014u32, 13133629u32, 12910283u32, 4370992u32, 14535975u32, 5997020u32, 5707818u32, 13718737u32, 2504095u32, 10516836u32, 11329682u32, 2796649u32, 11916158u32, 3383173u32, 4130419u32, 12143240u32, 8893606u32, 129117u32, 876971u32, 9121104u32, 1331783u32, 9576124u32, 10389322u32, 1625009u32, 14908182u32, 6633453u32, 6925851u32, 15721184u32, 7380471u32, 16175372u32, 16402682u32, 8127489u32, 4389423u32, 12891860u32, 13119266u32, 5137369u32, 13704398u32, 5722165u32, 6015427u32, 14517560u32]; 9 | 10 | #[rustfmt::skip] 11 | pub(crate) const NO_REF_32_000000AF: [u32; 256] = [0u32, 175u32, 350u32, 497u32, 700u32, 531u32, 994u32, 845u32, 1400u32, 1495u32, 1062u32, 1161u32, 1988u32, 1899u32, 1690u32, 1589u32, 2800u32, 2655u32, 2990u32, 2817u32, 2124u32, 2275u32, 2322u32, 2493u32, 3976u32, 3879u32, 3798u32, 3705u32, 3380u32, 3483u32, 3178u32, 3269u32, 5600u32, 5455u32, 5310u32, 5137u32, 5980u32, 6131u32, 5634u32, 5805u32, 4248u32, 4151u32, 4550u32, 4457u32, 4644u32, 4747u32, 4986u32, 5077u32, 7952u32, 8127u32, 7758u32, 7905u32, 7596u32, 7427u32, 7410u32, 7261u32, 6760u32, 6855u32, 6966u32, 7065u32, 6356u32, 6267u32, 6538u32, 6437u32, 11200u32, 11119u32, 10910u32, 10801u32, 10620u32, 10707u32, 10274u32, 10381u32, 11960u32, 11799u32, 12262u32, 12105u32, 11268u32, 11435u32, 11610u32, 11765u32, 8496u32, 8607u32, 8302u32, 8385u32, 9100u32, 8995u32, 8914u32, 8829u32, 9288u32, 9447u32, 9494u32, 9657u32, 9972u32, 9819u32, 10154u32, 9989u32, 15904u32, 16015u32, 16254u32, 16337u32, 15516u32, 15411u32, 15810u32, 15725u32, 15192u32, 15351u32, 14854u32, 15017u32, 14820u32, 14667u32, 14522u32, 14357u32, 13520u32, 13439u32, 13710u32, 13601u32, 13932u32, 14019u32, 14130u32, 14237u32, 12712u32, 12551u32, 12534u32, 12377u32, 13076u32, 13243u32, 12874u32, 13029u32, 22400u32, 22319u32, 22238u32, 22129u32, 21820u32, 21907u32, 21602u32, 21709u32, 21240u32, 21079u32, 21414u32, 21257u32, 20548u32, 20715u32, 20762u32, 20917u32, 23920u32, 24031u32, 23598u32, 23681u32, 24524u32, 24419u32, 24210u32, 24125u32, 22536u32, 22695u32, 22870u32, 23033u32, 23220u32, 23067u32, 23530u32, 23365u32, 16992u32, 17103u32, 17214u32, 17297u32, 16604u32, 16499u32, 16770u32, 16685u32, 18200u32, 18359u32, 17990u32, 18153u32, 17828u32, 17675u32, 17658u32, 17493u32, 18576u32, 18495u32, 18894u32, 18785u32, 18988u32, 19075u32, 19314u32, 19421u32, 19944u32, 19783u32, 19638u32, 19481u32, 20308u32, 20475u32, 19978u32, 20133u32, 31808u32, 31983u32, 32030u32, 32177u32, 32508u32, 32339u32, 32674u32, 32525u32, 31032u32, 31127u32, 30822u32, 30921u32, 31620u32, 31531u32, 31450u32, 31349u32, 30384u32, 30239u32, 30702u32, 30529u32, 29708u32, 29859u32, 30034u32, 30205u32, 29640u32, 29543u32, 29334u32, 29241u32, 29044u32, 29147u32, 28714u32, 28805u32, 27040u32, 26895u32, 26878u32, 26705u32, 27420u32, 27571u32, 27202u32, 27373u32, 27864u32, 27767u32, 28038u32, 27945u32, 28260u32, 28363u32, 28474u32, 28565u32, 25424u32, 25599u32, 25102u32, 25249u32, 25068u32, 24899u32, 24754u32, 24605u32, 26152u32, 26247u32, 26486u32, 26585u32, 25748u32, 25659u32, 26058u32, 25957u32]; 12 | 13 | #[rustfmt::skip] 14 | pub(crate) const NO_REF_32_04C11DB7: [u32; 256] = [0u32, 79764919u32, 159529838u32, 222504665u32, 319059676u32, 398814059u32, 445009330u32, 507990021u32, 638119352u32, 583659535u32, 797628118u32, 726387553u32, 890018660u32, 835552979u32, 1015980042u32, 944750013u32, 1276238704u32, 1221641927u32, 1167319070u32, 1095957929u32, 1595256236u32, 1540665371u32, 1452775106u32, 1381403509u32, 1780037320u32, 1859660671u32, 1671105958u32, 1733955601u32, 2031960084u32, 2111593891u32, 1889500026u32, 1952343757u32, 2552477408u32, 2632100695u32, 2443283854u32, 2506133561u32, 2334638140u32, 2414271883u32, 2191915858u32, 2254759653u32, 3190512472u32, 3135915759u32, 3081330742u32, 3009969537u32, 2905550212u32, 2850959411u32, 2762807018u32, 2691435357u32, 3560074640u32, 3505614887u32, 3719321342u32, 3648080713u32, 3342211916u32, 3287746299u32, 3467911202u32, 3396681109u32, 4063920168u32, 4143685023u32, 4223187782u32, 4286162673u32, 3779000052u32, 3858754371u32, 3904687514u32, 3967668269u32, 881225847u32, 809987520u32, 1023691545u32, 969234094u32, 662832811u32, 591600412u32, 771767749u32, 717299826u32, 311336399u32, 374308984u32, 453813921u32, 533576470u32, 25881363u32, 88864420u32, 134795389u32, 214552010u32, 2023205639u32, 2086057648u32, 1897238633u32, 1976864222u32, 1804852699u32, 1867694188u32, 1645340341u32, 1724971778u32, 1587496639u32, 1516133128u32, 1461550545u32, 1406951526u32, 1302016099u32, 1230646740u32, 1142491917u32, 1087903418u32, 2896545431u32, 2825181984u32, 2770861561u32, 2716262478u32, 3215044683u32, 3143675388u32, 3055782693u32, 3001194130u32, 2326604591u32, 2389456536u32, 2200899649u32, 2280525302u32, 2578013683u32, 2640855108u32, 2418763421u32, 2498394922u32, 3769900519u32, 3832873040u32, 3912640137u32, 3992402750u32, 4088425275u32, 4151408268u32, 4197601365u32, 4277358050u32, 3334271071u32, 3263032808u32, 3476998961u32, 3422541446u32, 3585640067u32, 3514407732u32, 3694837229u32, 3640369242u32, 1762451694u32, 1842216281u32, 1619975040u32, 1682949687u32, 2047383090u32, 2127137669u32, 1938468188u32, 2001449195u32, 1325665622u32, 1271206113u32, 1183200824u32, 1111960463u32, 1543535498u32, 1489069629u32, 1434599652u32, 1363369299u32, 622672798u32, 568075817u32, 748617968u32, 677256519u32, 907627842u32, 853037301u32, 1067152940u32, 995781531u32, 51762726u32, 131386257u32, 177728840u32, 240578815u32, 269590778u32, 349224269u32, 429104020u32, 491947555u32, 4046411278u32, 4126034873u32, 4172115296u32, 4234965207u32, 3794477266u32, 3874110821u32, 3953728444u32, 4016571915u32, 3609705398u32, 3555108353u32, 3735388376u32, 3664026991u32, 3290680682u32, 3236090077u32, 3449943556u32, 3378572211u32, 3174993278u32, 3120533705u32, 3032266256u32, 2961025959u32, 2923101090u32, 2868635157u32, 2813903052u32, 2742672763u32, 2604032198u32, 2683796849u32, 2461293480u32, 2524268063u32, 2284983834u32, 2364738477u32, 2175806836u32, 2238787779u32, 1569362073u32, 1498123566u32, 1409854455u32, 1355396672u32, 1317987909u32, 1246755826u32, 1192025387u32, 1137557660u32, 2072149281u32, 2135122070u32, 1912620623u32, 1992383480u32, 1753615357u32, 1816598090u32, 1627664531u32, 1707420964u32, 295390185u32, 358241886u32, 404320391u32, 483945776u32, 43990325u32, 106832002u32, 186451547u32, 266083308u32, 932423249u32, 861060070u32, 1041341759u32, 986742920u32, 613929101u32, 542559546u32, 756411363u32, 701822548u32, 3316196985u32, 3244833742u32, 3425377559u32, 3370778784u32, 3601682597u32, 3530312978u32, 3744426955u32, 3689838204u32, 3819031489u32, 3881883254u32, 3928223919u32, 4007849240u32, 4037393693u32, 4100235434u32, 4180117107u32, 4259748804u32, 2310601993u32, 2373574846u32, 2151335527u32, 2231098320u32, 2596047829u32, 2659030626u32, 2470359227u32, 2550115596u32, 2947551409u32, 2876312838u32, 2788305887u32, 2733848168u32, 3165939309u32, 3094707162u32, 3040238851u32, 2985771188u32]; 15 | 16 | #[rustfmt::skip] 17 | pub(crate) const NO_REF_32_814141AB: [u32; 256] = [0u32, 2168537515u32, 2210644733u32, 42107734u32, 2261173329u32, 126322170u32, 84215468u32, 2219067143u32, 2362231049u32, 227379362u32, 252644340u32, 2387495519u32, 168430936u32, 2336967923u32, 2311704485u32, 143166990u32, 2564346809u32, 429494802u32, 454758724u32, 2589610223u32, 505288680u32, 2673825347u32, 2648560917u32, 480023742u32, 336861872u32, 2505399067u32, 2547505229u32, 378968550u32, 2463293153u32, 328441674u32, 286333980u32, 2421185975u32, 2968577753u32, 833726322u32, 858989604u32, 2993841551u32, 909517448u32, 3078054691u32, 3052789877u32, 884253150u32, 1010577360u32, 3179114107u32, 3221220653u32, 1052683398u32, 3137006465u32, 1002154538u32, 960047484u32, 3094898903u32, 673723744u32, 2842260683u32, 2884368285u32, 715830838u32, 2934894897u32, 800043162u32, 757937100u32, 2892788327u32, 2766470249u32, 631619010u32, 656883348u32, 2791735103u32, 572667960u32, 2741205395u32, 2715941573u32, 547404654u32, 3768618009u32, 1642188210u32, 1667452644u32, 3793882959u32, 1717979208u32, 3878095331u32, 3852831413u32, 1692715806u32, 1819034896u32, 3979150523u32, 4021258221u32, 1861142086u32, 3937042753u32, 1810612458u32, 1768506300u32, 3894936087u32, 2021154720u32, 4181270027u32, 4223376733u32, 2063260918u32, 4273904625u32, 2147474010u32, 2105366796u32, 4231796903u32, 4105475753u32, 1979045634u32, 2004309076u32, 4130739711u32, 1920094968u32, 4080210771u32, 4054945797u32, 1894830510u32, 1347447488u32, 3507563371u32, 3549669437u32, 1389554070u32, 3600199313u32, 1473769274u32, 1431661676u32, 3558092231u32, 3701253065u32, 1574822498u32, 1600086324u32, 3726516383u32, 1515874200u32, 3675989555u32, 3650725221u32, 1490609358u32, 3364403577u32, 1237973202u32, 1263238020u32, 3389667887u32, 1313766696u32, 3473882243u32, 3448618965u32, 1288502910u32, 1145335920u32, 3305451995u32, 3347559053u32, 1187443494u32, 3263345697u32, 1136915850u32, 1094809308u32, 3221239671u32, 1073764761u32, 3242268722u32, 3284376420u32, 1115871951u32, 3334905288u32, 1200086115u32, 1157979957u32, 3292798622u32, 3435958416u32, 1301139771u32, 1326404205u32, 3461223366u32, 1242191041u32, 3410695530u32, 3385431612u32, 1216927639u32, 3638069792u32, 1503251339u32, 1528514781u32, 3663333750u32, 1579044465u32, 3747549146u32, 3722284172u32, 1553780007u32, 1410614057u32, 3579118210u32, 3621224916u32, 1452720255u32, 3537012600u32, 1402193619u32, 1360086405u32, 3494904878u32, 4042309440u32, 1907490539u32, 1932754365u32, 4067572758u32, 1983281937u32, 4151786170u32, 4126521836u32, 1958017095u32, 2084337225u32, 4252841954u32, 4294948020u32, 2126443807u32, 4210733592u32, 2075915187u32, 2033807589u32, 4168626510u32, 1747479801u32, 3915984210u32, 3958091268u32, 1789587375u32, 4008618152u32, 1873799427u32, 1831692885u32, 3966512126u32, 3840189936u32, 1705370715u32, 1730635533u32, 3865454246u32, 1646420385u32, 3814924298u32, 3789661020u32, 1621156599u32, 2694894976u32, 568431659u32, 593696637u32, 2720159446u32, 644223441u32, 2804371578u32, 2779108140u32, 618959495u32, 745282697u32, 2905431330u32, 2947538548u32, 787390431u32, 2863323352u32, 736860531u32, 694753829u32, 2821217166u32, 947390009u32, 3107538834u32, 3149644996u32, 989496687u32, 3200172648u32, 1073710019u32, 1031602325u32, 3158065470u32, 3031748400u32, 905285275u32, 930549197u32, 3057011814u32, 846334817u32, 3006483146u32, 2981218716u32, 821069879u32, 273691481u32, 2433839858u32, 2475946404u32, 315797519u32, 2526476040u32, 400012963u32, 357905909u32, 2484368478u32, 2627533392u32, 501070843u32, 526334125u32, 2652797190u32, 442121729u32, 2602270634u32, 2577005820u32, 416857431u32, 2290671840u32, 164208971u32, 189473309u32, 2315936694u32, 240002225u32, 2400150810u32, 2374886988u32, 214738919u32, 71576041u32, 2231724098u32, 2273831700u32, 113683135u32, 2189618616u32, 63155219u32, 21049157u32, 2147512046u32]; 18 | 19 | #[rustfmt::skip] 20 | pub(crate) const REF_24_00DA6000: [u32; 256] = [0u32, 111808u32, 223616u32, 187712u32, 447232u32, 485312u32, 375424u32, 265792u32, 894464u32, 791232u32, 970624u32, 1014592u32, 750848u32, 704960u32, 531584u32, 632896u32, 1788928u32, 1767616u32, 1582464u32, 1675584u32, 1941248u32, 1846208u32, 2029184u32, 2048576u32, 1501696u32, 1531584u32, 1409920u32, 1324864u32, 1063168u32, 1150400u32, 1265792u32, 1238080u32, 3577856u32, 3615936u32, 3535232u32, 3425600u32, 3164928u32, 3276736u32, 3351168u32, 3315264u32, 3882496u32, 3836608u32, 3692416u32, 3793728u32, 4058368u32, 3955136u32, 4097152u32, 4141120u32, 3003392u32, 2908352u32, 3063168u32, 3082560u32, 2819840u32, 2798528u32, 2649728u32, 2742848u32, 2126336u32, 2213568u32, 2300800u32, 2273088u32, 2531584u32, 2561472u32, 2476160u32, 2391104u32, 7155712u32, 7111872u32, 7231872u32, 7335232u32, 7070464u32, 6969280u32, 6851200u32, 6897216u32, 6329856u32, 6365888u32, 6553472u32, 6441792u32, 6702336u32, 6812096u32, 6630528u32, 6592576u32, 7764992u32, 7850176u32, 7673216u32, 7643456u32, 7384832u32, 7412672u32, 7587456u32, 7500352u32, 8116736u32, 8023744u32, 7910272u32, 7931712u32, 8194304u32, 8175040u32, 8282240u32, 8377408u32, 6006784u32, 5905600u32, 5816704u32, 5862720u32, 6126336u32, 6082496u32, 6165120u32, 6268480u32, 5639680u32, 5749440u32, 5597056u32, 5559104u32, 5299456u32, 5335488u32, 5485696u32, 5374016u32, 4252672u32, 4280512u32, 4427136u32, 4340032u32, 4601600u32, 4686784u32, 4546176u32, 4516416u32, 5063168u32, 5043904u32, 5122944u32, 5218112u32, 4952320u32, 4859328u32, 4782208u32, 4803648u32, 14311424u32, 14406848u32, 14223744u32, 14204224u32, 14463744u32, 14485440u32, 14670464u32, 14577216u32, 14140928u32, 14054080u32, 13938560u32, 13966144u32, 13702400u32, 13672896u32, 13794432u32, 13879360u32, 12659712u32, 12622016u32, 12731776u32, 12841280u32, 13106944u32, 12995520u32, 12883584u32, 12919360u32, 13404672u32, 13450944u32, 13624192u32, 13522752u32, 13261056u32, 13364672u32, 13185152u32, 13141056u32, 15529984u32, 15551680u32, 15700352u32, 15607104u32, 15346432u32, 15441856u32, 15286912u32, 15267392u32, 14769664u32, 14740160u32, 14825344u32, 14910272u32, 15174912u32, 15088064u32, 15000704u32, 15028288u32, 16233472u32, 16122048u32, 16047488u32, 16083264u32, 15820544u32, 15782848u32, 15863424u32, 15972928u32, 16388608u32, 16492224u32, 16350080u32, 16305984u32, 16564480u32, 16610752u32, 16754816u32, 16653376u32, 12013568u32, 11986112u32, 11811200u32, 11898176u32, 11633408u32, 11548608u32, 11725440u32, 11755072u32, 12252672u32, 12272320u32, 12164992u32, 12069696u32, 12330240u32, 12423616u32, 12536960u32, 12515392u32, 11279360u32, 11380928u32, 11498880u32, 11452736u32, 11194112u32, 11238336u32, 11118208u32, 11014720u32, 10598912u32, 10489536u32, 10670976u32, 10708800u32, 10971392u32, 10935744u32, 10748032u32, 10859584u32, 8505344u32, 8420544u32, 8561024u32, 8590656u32, 8854272u32, 8826816u32, 8680064u32, 8767040u32, 9203200u32, 9296576u32, 9373568u32, 9352000u32, 9092352u32, 9112000u32, 9032832u32, 8937536u32, 10126336u32, 10170560u32, 10087808u32, 9984320u32, 10245888u32, 10347456u32, 10436224u32, 10390080u32, 9904640u32, 9868992u32, 9718656u32, 9830208u32, 9564416u32, 9455040u32, 9607296u32, 9645120u32]; 21 | 22 | #[rustfmt::skip] 23 | pub(crate) const REF_32_82F63B78: [u32; 256] = [0u32, 4067132163u32, 3778769143u32, 324072436u32, 3348797215u32, 904991772u32, 648144872u32, 3570033899u32, 2329499855u32, 2024987596u32, 1809983544u32, 2575936315u32, 1296289744u32, 3207089363u32, 2893594407u32, 1578318884u32, 274646895u32, 3795141740u32, 4049975192u32, 51262619u32, 3619967088u32, 632279923u32, 922689671u32, 3298075524u32, 2592579488u32, 1760304291u32, 2075979607u32, 2312596564u32, 1562183871u32, 2943781820u32, 3156637768u32, 1313733451u32, 549293790u32, 3537243613u32, 3246849577u32, 871202090u32, 3878099393u32, 357341890u32, 102525238u32, 4101499445u32, 2858735121u32, 1477399826u32, 1264559846u32, 3107202533u32, 1845379342u32, 2677391885u32, 2361733625u32, 2125378298u32, 820201905u32, 3263744690u32, 3520608582u32, 598981189u32, 4151959214u32, 85089709u32, 373468761u32, 3827903834u32, 3124367742u32, 1213305469u32, 1526817161u32, 2842354314u32, 2107672161u32, 2412447074u32, 2627466902u32, 1861252501u32, 1098587580u32, 3004210879u32, 2688576843u32, 1378610760u32, 2262928035u32, 1955203488u32, 1742404180u32, 2511436119u32, 3416409459u32, 969524848u32, 714683780u32, 3639785095u32, 205050476u32, 4266873199u32, 3976438427u32, 526918040u32, 1361435347u32, 2739821008u32, 2954799652u32, 1114974503u32, 2529119692u32, 1691668175u32, 2005155131u32, 2247081528u32, 3690758684u32, 697762079u32, 986182379u32, 3366744552u32, 476452099u32, 3993867776u32, 4250756596u32, 255256311u32, 1640403810u32, 2477592673u32, 2164122517u32, 1922457750u32, 2791048317u32, 1412925310u32, 1197962378u32, 3037525897u32, 3944729517u32, 427051182u32, 170179418u32, 4165941337u32, 746937522u32, 3740196785u32, 3451792453u32, 1070968646u32, 1905808397u32, 2213795598u32, 2426610938u32, 1657317369u32, 3053634322u32, 1147748369u32, 1463399397u32, 2773627110u32, 4215344322u32, 153784257u32, 444234805u32, 3893493558u32, 1021025245u32, 3467647198u32, 3722505002u32, 797665321u32, 2197175160u32, 1889384571u32, 1674398607u32, 2443626636u32, 1164749927u32, 3070701412u32, 2757221520u32, 1446797203u32, 137323447u32, 4198817972u32, 3910406976u32, 461344835u32, 3484808360u32, 1037989803u32, 781091935u32, 3705997148u32, 2460548119u32, 1623424788u32, 1939049696u32, 2180517859u32, 1429367560u32, 2807687179u32, 3020495871u32, 1180866812u32, 410100952u32, 3927582683u32, 4182430767u32, 186734380u32, 3756733383u32, 763408580u32, 1053836080u32, 3434856499u32, 2722870694u32, 1344288421u32, 1131464017u32, 2971354706u32, 1708204729u32, 2545590714u32, 2229949006u32, 1988219213u32, 680717673u32, 3673779818u32, 3383336350u32, 1002577565u32, 4010310262u32, 493091189u32, 238226049u32, 4233660802u32, 2987750089u32, 1082061258u32, 1395524158u32, 2705686845u32, 1972364758u32, 2279892693u32, 2494862625u32, 1725896226u32, 952904198u32, 3399985413u32, 3656866545u32, 731699698u32, 4283874585u32, 222117402u32, 510512622u32, 3959836397u32, 3280807620u32, 837199303u32, 582374963u32, 3504198960u32, 68661723u32, 4135334616u32, 3844915500u32, 390545967u32, 1230274059u32, 3141532936u32, 2825850620u32, 1510247935u32, 2395924756u32, 2091215383u32, 1878366691u32, 2644384480u32, 3553878443u32, 565732008u32, 854102364u32, 3229815391u32, 340358836u32, 3861050807u32, 4117890627u32, 119113024u32, 1493875044u32, 2875275879u32, 3090270611u32, 1247431312u32, 2660249211u32, 1828433272u32, 2141937292u32, 2378227087u32, 3811616794u32, 291187481u32, 34330861u32, 4032846830u32, 615137029u32, 3603020806u32, 3314634738u32, 939183345u32, 1776939221u32, 2609017814u32, 2295496738u32, 2058945313u32, 2926798794u32, 1545135305u32, 1330124605u32, 3173225534u32, 4084100981u32, 17165430u32, 307568514u32, 3762199681u32, 888469610u32, 3332340585u32, 3587147933u32, 665062302u32, 2042050490u32, 2346497209u32, 2559330125u32, 1793573966u32, 3190661285u32, 1279665062u32, 1595330642u32, 2910671697u32]; 24 | 25 | #[rustfmt::skip] 26 | pub(crate) const REF_32_EDB88320: [u32; 256] = [0u32, 1996959894u32, 3993919788u32, 2567524794u32, 124634137u32, 1886057615u32, 3915621685u32, 2657392035u32, 249268274u32, 2044508324u32, 3772115230u32, 2547177864u32, 162941995u32, 2125561021u32, 3887607047u32, 2428444049u32, 498536548u32, 1789927666u32, 4089016648u32, 2227061214u32, 450548861u32, 1843258603u32, 4107580753u32, 2211677639u32, 325883990u32, 1684777152u32, 4251122042u32, 2321926636u32, 335633487u32, 1661365465u32, 4195302755u32, 2366115317u32, 997073096u32, 1281953886u32, 3579855332u32, 2724688242u32, 1006888145u32, 1258607687u32, 3524101629u32, 2768942443u32, 901097722u32, 1119000684u32, 3686517206u32, 2898065728u32, 853044451u32, 1172266101u32, 3705015759u32, 2882616665u32, 651767980u32, 1373503546u32, 3369554304u32, 3218104598u32, 565507253u32, 1454621731u32, 3485111705u32, 3099436303u32, 671266974u32, 1594198024u32, 3322730930u32, 2970347812u32, 795835527u32, 1483230225u32, 3244367275u32, 3060149565u32, 1994146192u32, 31158534u32, 2563907772u32, 4023717930u32, 1907459465u32, 112637215u32, 2680153253u32, 3904427059u32, 2013776290u32, 251722036u32, 2517215374u32, 3775830040u32, 2137656763u32, 141376813u32, 2439277719u32, 3865271297u32, 1802195444u32, 476864866u32, 2238001368u32, 4066508878u32, 1812370925u32, 453092731u32, 2181625025u32, 4111451223u32, 1706088902u32, 314042704u32, 2344532202u32, 4240017532u32, 1658658271u32, 366619977u32, 2362670323u32, 4224994405u32, 1303535960u32, 984961486u32, 2747007092u32, 3569037538u32, 1256170817u32, 1037604311u32, 2765210733u32, 3554079995u32, 1131014506u32, 879679996u32, 2909243462u32, 3663771856u32, 1141124467u32, 855842277u32, 2852801631u32, 3708648649u32, 1342533948u32, 654459306u32, 3188396048u32, 3373015174u32, 1466479909u32, 544179635u32, 3110523913u32, 3462522015u32, 1591671054u32, 702138776u32, 2966460450u32, 3352799412u32, 1504918807u32, 783551873u32, 3082640443u32, 3233442989u32, 3988292384u32, 2596254646u32, 62317068u32, 1957810842u32, 3939845945u32, 2647816111u32, 81470997u32, 1943803523u32, 3814918930u32, 2489596804u32, 225274430u32, 2053790376u32, 3826175755u32, 2466906013u32, 167816743u32, 2097651377u32, 4027552580u32, 2265490386u32, 503444072u32, 1762050814u32, 4150417245u32, 2154129355u32, 426522225u32, 1852507879u32, 4275313526u32, 2312317920u32, 282753626u32, 1742555852u32, 4189708143u32, 2394877945u32, 397917763u32, 1622183637u32, 3604390888u32, 2714866558u32, 953729732u32, 1340076626u32, 3518719985u32, 2797360999u32, 1068828381u32, 1219638859u32, 3624741850u32, 2936675148u32, 906185462u32, 1090812512u32, 3747672003u32, 2825379669u32, 829329135u32, 1181335161u32, 3412177804u32, 3160834842u32, 628085408u32, 1382605366u32, 3423369109u32, 3138078467u32, 570562233u32, 1426400815u32, 3317316542u32, 2998733608u32, 733239954u32, 1555261956u32, 3268935591u32, 3050360625u32, 752459403u32, 1541320221u32, 2607071920u32, 3965973030u32, 1969922972u32, 40735498u32, 2617837225u32, 3943577151u32, 1913087877u32, 83908371u32, 2512341634u32, 3803740692u32, 2075208622u32, 213261112u32, 2463272603u32, 3855990285u32, 2094854071u32, 198958881u32, 2262029012u32, 4057260610u32, 1759359992u32, 534414190u32, 2176718541u32, 4139329115u32, 1873836001u32, 414664567u32, 2282248934u32, 4279200368u32, 1711684554u32, 285281116u32, 2405801727u32, 4167216745u32, 1634467795u32, 376229701u32, 2685067896u32, 3608007406u32, 1308918612u32, 956543938u32, 2808555105u32, 3495958263u32, 1231636301u32, 1047427035u32, 2932959818u32, 3654703836u32, 1088359270u32, 936918000u32, 2847714899u32, 3736837829u32, 1202900863u32, 817233897u32, 3183342108u32, 3401237130u32, 1404277552u32, 615818150u32, 3134207493u32, 3453421203u32, 1423857449u32, 601450431u32, 3009837614u32, 3294710456u32, 1567103746u32, 711928724u32, 3020668471u32, 3272380065u32, 1510334235u32, 755167117u32]; 27 | 28 | #[rustfmt::skip] 29 | pub(crate) const REF_32_D419CC15: [u32; 256] = [0u32, 735957071u32, 1471914142u32, 2087088337u32, 2943828284u32, 2225770867u32, 4174176674u32, 3541119469u32, 4141685331u32, 3707816476u32, 2707864269u32, 2327538306u32, 1504336751u32, 1920437024u32, 236059633u32, 634137534u32, 1166650509u32, 1851030722u32, 305269779u32, 972020828u32, 3942575537u32, 3240312318u32, 3175435567u32, 2526584160u32, 3008673502u32, 2559141521u32, 3840874048u32, 3476211215u32, 472119266u32, 939403181u32, 1268275068u32, 1615169331u32, 2333301018u32, 2697890133u32, 3702061444u32, 4151650763u32, 610539558u32, 263833705u32, 1944041656u32, 1476552951u32, 2110669641u32, 1444123398u32, 712369111u32, 27800472u32, 3535340149u32, 4184134202u32, 2231542507u32, 2933879460u32, 3466261911u32, 3846645208u32, 2569098505u32, 3002893638u32, 1642968235u32, 1244685540u32, 911610933u32, 495699066u32, 944238532u32, 328875915u32, 1878806362u32, 1143054101u32, 2536550136u32, 3169681079u32, 3230338662u32, 3948338729u32, 3189058079u32, 2512976464u32, 3920530049u32, 3262339790u32, 291662627u32, 985643884u32, 1188678589u32, 1828985842u32, 1221079116u32, 1662377987u32, 527667410u32, 883835037u32, 3888083312u32, 3429015871u32, 2953105902u32, 2614690209u32, 4221339282u32, 3493943005u32, 2888246796u32, 2281371203u32, 1424738222u32, 2134251489u32, 55600944u32, 680376191u32, 222403777u32, 647777422u32, 1526348895u32, 1898441744u32, 2721504765u32, 2313883058u32, 4119690595u32, 3729829164u32, 889615109u32, 517710666u32, 1656607643u32, 1231029204u32, 2591109689u32, 2980897398u32, 3452605095u32, 3860284136u32, 3285936470u32, 3892754713u32, 2489371080u32, 3216841095u32, 1823221866u32, 1198651429u32, 991398132u32, 281696443u32, 1888477064u32, 1532104647u32, 657751830u32, 216641369u32, 3757612724u32, 4096085755u32, 2286108202u32, 2745101925u32, 2253571547u32, 2911835540u32, 3521733957u32, 4197758218u32, 690324711u32, 49829032u32, 2124293241u32, 1430516790u32, 3558460437u32, 4291042394u32, 2208459915u32, 2826943684u32, 2070842665u32, 1353932134u32, 752168375u32, 118029816u32, 583325254u32, 152634889u32, 1971287768u32, 1587717783u32, 2377357178u32, 2792245045u32, 3657971684u32, 4057327531u32, 2442158232u32, 3125653719u32, 3324755974u32, 3992326217u32, 1055334820u32, 356184555u32, 1767670074u32, 1115771253u32, 1733130955u32, 1284549252u32, 821484117u32, 455805466u32, 3359259639u32, 3823627192u32, 2676071273u32, 3025947430u32, 1594529039u32, 1960265024u32, 145831313u32, 594339294u32, 4034778163u32, 3684697212u32, 2814801069u32, 2350621922u32, 2849476444u32, 2181717779u32, 4268502978u32, 3585212301u32, 111201888u32, 763174447u32, 1360752382u32, 2059845297u32, 444807554u32, 828303821u32, 1295554844u32, 1726302547u32, 3052697790u32, 2653530353u32, 3796883488u32, 3381790831u32, 3965592529u32, 3347313566u32, 3152380751u32, 2419610368u32, 1126785773u32, 1760866978u32, 345162355u32, 1062146620u32, 1779230218u32, 1104229957u32, 1035421332u32, 376084187u32, 3313215286u32, 4003886969u32, 2462058408u32, 3105740775u32, 2631007321u32, 3071028246u32, 3412745415u32, 3770125448u32, 866565477u32, 410742058u32, 1679629819u32, 1338035636u32, 797264519u32, 72915656u32, 2017389081u32, 1407400534u32, 2163346363u32, 2872040436u32, 3611929381u32, 4237589354u32, 3646443732u32, 4068835483u32, 2397302858u32, 2772312069u32, 1982796264u32, 1576190375u32, 563392886u32, 172581177u32, 3776954128u32, 3401740127u32, 3064209294u32, 2642005953u32, 1315503660u32, 1706372707u32, 433282738u32, 839814909u32, 398632259u32, 1008694540u32, 1081673181u32, 1805964690u32, 3098928255u32, 2473079856u32, 4010689761u32, 3302200494u32, 2761298845u32, 2404107218u32, 4079858435u32, 3639632716u32, 199316129u32, 540836590u32, 1549464127u32, 2005344880u32, 1380649422u32, 2039929217u32, 99658064u32, 774732063u32, 4248586482u32, 3605108925u32, 2861033580u32, 2170173475u32]; 30 | -------------------------------------------------------------------------------- /src/crc_u16.rs: -------------------------------------------------------------------------------- 1 | #[cfg(feature = "alloc")] 2 | use alloc::fmt::{self, Debug, Display, Formatter}; 3 | #[cfg(feature = "alloc")] 4 | use alloc::vec::Vec; 5 | 6 | #[cfg(feature = "heapless")] 7 | use heapless::Vec as HeaplessVec; 8 | 9 | use crate::{constants::crc_u16::*, lookup_table::LookUpTable}; 10 | 11 | #[allow(clippy::upper_case_acronyms)] 12 | /// This struct can help you compute a CRC-16 (or CRC-x where **x** is equal or less than `16`) value. 13 | pub struct CRCu16 { 14 | by_table: bool, 15 | poly: u16, 16 | lookup_table: LookUpTable, 17 | sum: u16, 18 | pub(crate) bits: u8, 19 | high_bit: u16, 20 | mask: u16, 21 | initial: u16, 22 | final_xor: u16, 23 | reflect: bool, 24 | reorder: bool, 25 | } 26 | 27 | #[cfg(feature = "alloc")] 28 | impl Debug for CRCu16 { 29 | #[inline] 30 | fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> { 31 | if self.by_table { 32 | debug_helper::impl_debug_for_struct!(CRCu64, f, self, let .lookup_table = self.lookup_table.as_ref(), (.sum, "0x{:04X}", self.sum), .bits, (.initial, "0x{:04X}", self.initial), (.final_xor, "0x{:04X}", self.final_xor), .reflect, .reorder); 33 | } else { 34 | debug_helper::impl_debug_for_struct!(CRCu64, f, self, (.poly, "0x{:04X}", self.poly), (.sum, "0x{:04X}", self.sum), .bits, (.initial, "0x{:04X}", self.initial), (.final_xor, "0x{:04X}", self.final_xor), .reflect, .reorder); 35 | } 36 | } 37 | } 38 | 39 | #[cfg(feature = "alloc")] 40 | impl Display for CRCu16 { 41 | #[inline] 42 | fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> { 43 | f.write_fmt(format_args!("0x{:01$X}", self.get_crc(), (self.bits as usize + 3) >> 2)) 44 | } 45 | } 46 | 47 | impl CRCu16 { 48 | /// Create a `CRCu16` instance by providing the length of bits, expression, reflection, an initial value and a final xor value. 49 | pub fn create_crc(poly: u16, bits: u8, initial: u16, final_xor: u16, reflect: bool) -> CRCu16 { 50 | debug_assert!(bits <= 16 && bits > 0); 51 | 52 | if bits % 8 == 0 { 53 | let lookup_table = if reflect { 54 | LookUpTable::Dynamic(Self::crc_reflect_table(poly)) 55 | } else { 56 | LookUpTable::Dynamic(Self::crc_table(poly, bits)) 57 | }; 58 | 59 | Self::create_crc_with_exists_lookup_table( 60 | lookup_table, 61 | bits, 62 | initial, 63 | final_xor, 64 | reflect, 65 | ) 66 | } else { 67 | Self::create( 68 | false, 69 | LookUpTable::Static(&[0u16; 256]), 70 | poly, 71 | bits, 72 | initial, 73 | final_xor, 74 | reflect, 75 | ) 76 | } 77 | } 78 | 79 | #[inline] 80 | pub(crate) fn create_crc_with_exists_lookup_table( 81 | lookup_table: LookUpTable, 82 | bits: u8, 83 | initial: u16, 84 | final_xor: u16, 85 | reflect: bool, 86 | ) -> CRCu16 { 87 | debug_assert!(bits % 8 == 0); 88 | 89 | Self::create(true, lookup_table, 0, bits, initial, final_xor, reflect) 90 | } 91 | 92 | #[inline] 93 | fn create( 94 | by_table: bool, 95 | lookup_table: LookUpTable, 96 | mut poly: u16, 97 | bits: u8, 98 | initial: u16, 99 | final_xor: u16, 100 | reflect: bool, 101 | ) -> CRCu16 { 102 | let high_bit = 1 << u16::from(bits - 1); 103 | let mask = ((high_bit - 1) << 1) | 1; 104 | 105 | let sum = if reflect { Self::reflect_function(high_bit, initial) } else { initial }; 106 | 107 | if !by_table && reflect { 108 | poly = Self::reflect_function(high_bit, poly); 109 | } 110 | 111 | CRCu16 { 112 | by_table, 113 | poly, 114 | lookup_table, 115 | sum, 116 | bits, 117 | high_bit, 118 | mask, 119 | initial, 120 | final_xor, 121 | reflect, 122 | reorder: false, 123 | } 124 | } 125 | 126 | #[inline] 127 | fn reflect_function(high_bit: u16, n: u16) -> u16 { 128 | let mut i = high_bit; 129 | let mut j = 1; 130 | let mut out = 0; 131 | 132 | while i != 0 { 133 | if n & i != 0 { 134 | out |= j; 135 | } 136 | 137 | j <<= 1; 138 | i >>= 1; 139 | } 140 | 141 | out 142 | } 143 | 144 | #[inline] 145 | fn reflect_method(&self, n: u16) -> u16 { 146 | Self::reflect_function(self.high_bit, n) 147 | } 148 | 149 | /// Digest some data. 150 | pub fn digest>(&mut self, data: &T) { 151 | if self.by_table { 152 | if self.bits == 8 { 153 | for n in data.as_ref().iter().copied() { 154 | let index = (self.sum as u8 ^ n) as usize; 155 | self.sum = self.lookup_table[index]; 156 | } 157 | } else if self.reflect { 158 | for n in data.as_ref().iter().copied() { 159 | let index = ((self.sum as u8) ^ n) as usize; 160 | self.sum = (self.sum >> 8) ^ self.lookup_table[index]; 161 | } 162 | } else { 163 | for n in data.as_ref().iter().copied() { 164 | let index = ((self.sum >> u16::from(self.bits - 8)) as u8 ^ n) as usize; 165 | self.sum = (self.sum << 8) ^ self.lookup_table[index]; 166 | } 167 | } 168 | } else if self.reflect { 169 | for n in data.as_ref().iter().copied() { 170 | let n = super::crc_u8::CRCu8::reflect_function(0x80, n); 171 | 172 | let mut i = 0x80; 173 | 174 | while i != 0 { 175 | let mut bit = self.sum & self.high_bit; 176 | 177 | self.sum <<= 1; 178 | 179 | if n & i != 0 { 180 | bit ^= self.high_bit; 181 | } 182 | 183 | if bit != 0 { 184 | self.sum ^= self.poly; 185 | } 186 | 187 | i >>= 1; 188 | } 189 | } 190 | } else { 191 | for n in data.as_ref().iter().copied() { 192 | let mut i = 0x80; 193 | 194 | while i != 0 { 195 | let mut bit = self.sum & self.high_bit; 196 | 197 | self.sum <<= 1; 198 | 199 | if n & i != 0 { 200 | bit ^= self.high_bit; 201 | } 202 | 203 | if bit != 0 { 204 | self.sum ^= self.poly; 205 | } 206 | 207 | i >>= 1; 208 | } 209 | } 210 | } 211 | } 212 | 213 | /// Reset the sum. 214 | pub fn reset(&mut self) { 215 | self.sum = self.initial; 216 | } 217 | 218 | /// Get the current CRC value (it always returns a `u16` value). You can continue calling `digest` method even after getting a CRC value. 219 | pub fn get_crc(&self) -> u16 { 220 | let sum = if self.by_table || !self.reflect { 221 | (self.sum ^ self.final_xor) & self.mask 222 | } else { 223 | (self.reflect_method(self.sum) ^ self.final_xor) & self.mask 224 | }; 225 | 226 | if self.reorder { 227 | let mut new_sum = 0; 228 | 229 | let e = (self.bits as u16 + 7) >> 3; 230 | 231 | let e_dec = e - 1; 232 | 233 | for i in 0..e { 234 | new_sum |= ((sum >> ((e_dec - i) << 3)) & 0xFF) << (i << 3); 235 | } 236 | 237 | new_sum 238 | } else { 239 | sum 240 | } 241 | } 242 | 243 | fn crc_reflect_table(poly_rev: u16) -> [u16; 256] { 244 | let mut lookup_table = [0u16; 256]; 245 | 246 | for (i, e) in lookup_table.iter_mut().enumerate() { 247 | let mut v = i as u16; 248 | 249 | #[allow(clippy::branches_sharing_code)] 250 | for _ in 0..8u8 { 251 | if v & 1 != 0 { 252 | v >>= 1; 253 | v ^= poly_rev; 254 | } else { 255 | v >>= 1; 256 | } 257 | } 258 | 259 | *e = v; 260 | } 261 | 262 | lookup_table 263 | } 264 | 265 | fn crc_table(poly: u16, bits: u8) -> [u16; 256] { 266 | let mut lookup_table = [0u16; 256]; 267 | 268 | let mask1 = 1u16 << u16::from(bits - 1); 269 | 270 | let mask2 = ((mask1 - 1) << 1) | 1; 271 | 272 | for (i, e) in lookup_table.iter_mut().enumerate() { 273 | let mut v = i as u16; 274 | 275 | #[allow(clippy::branches_sharing_code)] 276 | for _ in 0..bits { 277 | if v & mask1 == 0 { 278 | v <<= 1; 279 | } else { 280 | v <<= 1; 281 | v ^= poly; 282 | } 283 | } 284 | 285 | *e = v & mask2; 286 | } 287 | 288 | lookup_table 289 | } 290 | } 291 | 292 | #[cfg(feature = "alloc")] 293 | impl CRCu16 { 294 | /// Get the current CRC value (it always returns a vec instance with a length corresponding to the CRC bits). You can continue calling `digest` method even after getting a CRC value. 295 | #[inline] 296 | pub fn get_crc_vec_le(&mut self) -> Vec { 297 | let crc = self.get_crc(); 298 | 299 | let e = (self.bits as usize + 7) >> 3; 300 | 301 | crc.to_le_bytes()[..e].to_vec() 302 | } 303 | 304 | /// Get the current CRC value (it always returns a vec instance with a length corresponding to the CRC bits). You can continue calling `digest` method even after getting a CRC value. 305 | #[inline] 306 | pub fn get_crc_vec_be(&mut self) -> Vec { 307 | let crc = self.get_crc(); 308 | 309 | let e = (self.bits as usize + 7) >> 3; 310 | 311 | crc.to_be_bytes()[(2 - e)..].to_vec() 312 | } 313 | } 314 | 315 | #[cfg(feature = "heapless")] 316 | impl CRCu16 { 317 | /// Get the current CRC value (it always returns a heapless vec instance with a length corresponding to the CRC bits). You can continue calling `digest` method even after getting a CRC value. 318 | #[inline] 319 | pub fn get_crc_heapless_vec_le(&mut self) -> HeaplessVec { 320 | let crc = self.get_crc(); 321 | 322 | let e = (self.bits as usize + 7) >> 3; 323 | 324 | let mut vec = HeaplessVec::new(); 325 | 326 | vec.extend_from_slice(&crc.to_le_bytes()[..e]).unwrap(); 327 | 328 | vec 329 | } 330 | 331 | /// Get the current CRC value (it always returns a heapless vec instance with a length corresponding to the CRC bits). You can continue calling `digest` method even after getting a CRC value. 332 | #[inline] 333 | pub fn get_crc_heapless_vec_be(&mut self) -> HeaplessVec { 334 | let crc = self.get_crc(); 335 | 336 | let e = (self.bits as usize + 7) >> 3; 337 | 338 | let mut vec = HeaplessVec::new(); 339 | 340 | vec.extend_from_slice(&crc.to_be_bytes()[(2 - e)..]).unwrap(); 341 | 342 | vec 343 | } 344 | } 345 | 346 | impl CRCu16 { 347 | /// |Check|Poly|Init|Ref|XorOut| 348 | /// |---|---|---|---|---| 349 | /// |0x199|0x233|0x000|false|0x000| 350 | /// 351 | /// ``` 352 | /// # use crc_any::CRCu16; 353 | /// let mut crc = CRCu16::crc10(); 354 | /// crc.digest(b"123456789"); 355 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0x199\", &crc.to_string());")] 356 | /// ``` 357 | pub fn crc10() -> CRCu16 { 358 | Self::create_crc(0x0233, 10, 0x0000, 0x0000, false) 359 | } 360 | 361 | /// |Check|Poly|Init|Ref|XorOut| 362 | /// |---|---|---|---|---| 363 | /// |0x233|0x3D9|0x3FF|false|0x000| 364 | /// 365 | /// ``` 366 | /// # use crc_any::CRCu16; 367 | /// let mut crc = CRCu16::crc10cdma2000(); 368 | /// crc.digest(b"123456789"); 369 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0x233\", &crc.to_string());")] 370 | /// ``` 371 | pub fn crc10cdma2000() -> CRCu16 { 372 | Self::create_crc(0x03D9, 10, 0x03FF, 0x0000, false) 373 | } 374 | 375 | /// |Check|Poly|Init|Ref|XorOut| 376 | /// |---|---|---|---|---| 377 | /// |0x12A|0x175|0x000|false|0x3FF| 378 | /// 379 | /// ``` 380 | /// # use crc_any::CRCu16; 381 | /// let mut crc = CRCu16::crc10gsm(); 382 | /// crc.digest(b"123456789"); 383 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0x12A\", &crc.to_string());")] 384 | /// ``` 385 | pub fn crc10gsm() -> CRCu16 { 386 | Self::create_crc(0x0175, 10, 0x0000, 0x03FF, false) 387 | } 388 | 389 | /// |Check|Poly|Init|Ref|XorOut| 390 | /// |---|---|---|---|---| 391 | /// |0x5A3|0x385|0x01a|false|0x000| 392 | /// 393 | /// ``` 394 | /// # use crc_any::CRCu16; 395 | /// let mut crc = CRCu16::crc11(); 396 | /// crc.digest(b"123456789"); 397 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0x5A3\", &crc.to_string());")] 398 | /// ``` 399 | pub fn crc11() -> CRCu16 { 400 | Self::create_crc(0x0385, 11, 0x001A, 0x0000, false) 401 | } 402 | 403 | /// |Check|Poly|Init|Ref|XorOut| 404 | /// |---|---|---|---|---| 405 | /// |0xF5B|0x80F|0x000|false|0x000| 406 | /// 407 | /// ``` 408 | /// # use crc_any::CRCu16; 409 | /// let mut crc = CRCu16::crc12(); 410 | /// crc.digest(b"123456789"); 411 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0xF5B\", &crc.to_string());")] 412 | /// ``` 413 | pub fn crc12() -> CRCu16 { 414 | Self::create_crc(0x080F, 12, 0x0000, 0x0000, false) 415 | } 416 | 417 | /// |Check|Poly|Init|Ref|XorOut| 418 | /// |---|---|---|---|---| 419 | /// |0xD4D|0xF13|0xFFF|false|0x000| 420 | /// 421 | /// ``` 422 | /// # use crc_any::CRCu16; 423 | /// let mut crc = CRCu16::crc12cdma2000(); 424 | /// crc.digest(b"123456789"); 425 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0xD4D\", &crc.to_string());")] 426 | /// ``` 427 | pub fn crc12cdma2000() -> CRCu16 { 428 | Self::create_crc(0x0F13, 12, 0x0FFF, 0x0000, false) 429 | } 430 | 431 | /// |Check|Poly|Init|Ref|XorOut| 432 | /// |---|---|---|---|---| 433 | /// |0xB34|0xD31|0x000|false|0xFFF| 434 | /// 435 | /// ``` 436 | /// # use crc_any::CRCu16; 437 | /// let mut crc = CRCu16::crc12gsm(); 438 | /// crc.digest(b"123456789"); 439 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0xB34\", &crc.to_string());")] 440 | /// ``` 441 | pub fn crc12gsm() -> CRCu16 { 442 | Self::create_crc(0x0D31, 12, 0x0000, 0x0FFF, false) 443 | } 444 | 445 | /// |Check|Poly|Init|Ref|XorOut| 446 | /// |---|---|---|---|---| 447 | /// |0x04FA|0x1CF5|0x0000|false|0x0000| 448 | /// 449 | /// ``` 450 | /// # use crc_any::CRCu16; 451 | /// let mut crc = CRCu16::crc13bbc(); 452 | /// crc.digest(b"123456789"); 453 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0x04FA\", &crc.to_string());")] 454 | /// ``` 455 | pub fn crc13bbc() -> CRCu16 { 456 | Self::create_crc(0x1CF5, 13, 0x0000, 0x0000, false) 457 | } 458 | 459 | /// |Check|Poly|Init|Ref|XorOut| 460 | /// |---|---|---|---|---| 461 | /// |0x082D|0x0805 (rev: 0x2804)|0x0000|true|0x0000| 462 | /// 463 | /// ``` 464 | /// # use crc_any::CRCu16; 465 | /// let mut crc = CRCu16::crc14darc(); 466 | /// crc.digest(b"123456789"); 467 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0x082D\", &crc.to_string());")] 468 | /// ``` 469 | pub fn crc14darc() -> CRCu16 { 470 | Self::create_crc(0x2804, 14, 0x0000, 0x0000, true) 471 | } 472 | 473 | /// |Check|Poly|Init|Ref|XorOut| 474 | /// |---|---|---|---|---| 475 | /// |0x30AE|0x202D|0x0000|false|0x3FFF| 476 | /// 477 | /// ``` 478 | /// # use crc_any::CRCu16; 479 | /// let mut crc = CRCu16::crc14gsm(); 480 | /// crc.digest(b"123456789"); 481 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0x30AE\", &crc.to_string());")] 482 | /// ``` 483 | pub fn crc14gsm() -> CRCu16 { 484 | Self::create_crc(0x202D, 14, 0x0000, 0x3FFF, false) 485 | } 486 | 487 | /// |Check|Poly|Init|Ref|XorOut| 488 | /// |---|---|---|---|---| 489 | /// |0x059E|0x4599|0x0000|false|0x0000| 490 | /// 491 | /// ``` 492 | /// # use crc_any::CRCu16; 493 | /// let mut crc = CRCu16::crc15can(); 494 | /// crc.digest(b"123456789"); 495 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0x059E\", &crc.to_string());")] 496 | /// ``` 497 | pub fn crc15can() -> CRCu16 { 498 | Self::create_crc(0x4599, 15, 0x0000, 0x0000, false) 499 | } 500 | 501 | /// |Check|Poly|Init|Ref|XorOut| 502 | /// |---|---|---|---|---| 503 | /// |0x2566|0x6815|0x0000|false|0x0001| 504 | /// 505 | /// ``` 506 | /// # use crc_any::CRCu16; 507 | /// let mut crc = CRCu16::crc15mpt1327(); 508 | /// crc.digest(b"123456789"); 509 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0x2566\", &crc.to_string());")] 510 | /// ``` 511 | pub fn crc15mpt1327() -> CRCu16 { 512 | Self::create_crc(0x6815, 15, 0x0000, 0x0001, false) 513 | } 514 | 515 | /// |Check|Poly|Init|Ref|XorOut| 516 | /// |---|---|---|---|---| 517 | /// |0xBB3D|0x8005 (rev: 0xA001)|0x0000|true|0x0000| 518 | /// 519 | /// ``` 520 | /// # use crc_any::CRCu16; 521 | /// let mut crc = CRCu16::crc16(); 522 | /// crc.digest(b"123456789"); 523 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0xBB3D\", &crc.to_string());")] 524 | /// ``` 525 | pub fn crc16() -> CRCu16 { 526 | // Self::create_crc(0xA001, 16, 0x0000, 0x0000, true) 527 | 528 | let lookup_table = LookUpTable::Static(&REF_16_A001); 529 | Self::create_crc_with_exists_lookup_table(lookup_table, 16, 0x0000, 0x0000, true) 530 | } 531 | 532 | /// |Check|Poly|Init|Ref|XorOut| 533 | /// |---|---|---|---|---| 534 | /// |0x29B1|0x1021|0xFFFF|false|0x0000| 535 | /// 536 | /// ``` 537 | /// # use crc_any::CRCu16; 538 | /// let mut crc = CRCu16::crc16ccitt_false(); 539 | /// crc.digest(b"123456789"); 540 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0x29B1\", &crc.to_string());")] 541 | /// ``` 542 | pub fn crc16ccitt_false() -> CRCu16 { 543 | // Self::create_crc(0x1021, 16, 0xFFFF, 0x0000, false) 544 | 545 | let lookup_table = LookUpTable::Static(&NO_REF_16_1021); 546 | Self::create_crc_with_exists_lookup_table(lookup_table, 16, 0xFFFF, 0x0000, false) 547 | } 548 | 549 | /// |Check|Poly|Init|Ref|XorOut| 550 | /// |---|---|---|---|---| 551 | /// |0xE5CC|0x1021|0x1D0F|false|0x0000| 552 | /// 553 | /// ``` 554 | /// # use crc_any::CRCu16; 555 | /// let mut crc = CRCu16::crc16aug_ccitt(); 556 | /// crc.digest(b"123456789"); 557 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0xE5CC\", &crc.to_string());")] 558 | /// ``` 559 | pub fn crc16aug_ccitt() -> CRCu16 { 560 | // Self::create_crc(0x1021, 16, 0x1D0F, 0x0000, false) 561 | 562 | let lookup_table = LookUpTable::Static(&NO_REF_16_1021); 563 | Self::create_crc_with_exists_lookup_table(lookup_table, 16, 0x1D0F, 0x0000, false) 564 | } 565 | 566 | /// |Check|Poly|Init|Ref|XorOut| 567 | /// |---|---|---|---|---| 568 | /// |0xFEE8|0x8005|0x0000|false|0x0000| 569 | /// 570 | /// ``` 571 | /// # use crc_any::CRCu16; 572 | /// let mut crc = CRCu16::crc16buypass(); 573 | /// crc.digest(b"123456789"); 574 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0xFEE8\", &crc.to_string());")] 575 | /// ``` 576 | pub fn crc16buypass() -> CRCu16 { 577 | // Self::create_crc(0x8005, 16, 0x0000, 0x0000, false) 578 | 579 | let lookup_table = LookUpTable::Static(&NO_REF_16_8005); 580 | Self::create_crc_with_exists_lookup_table(lookup_table, 16, 0x0000, 0x0000, false) 581 | } 582 | 583 | /// |Check|Poly|Init|Ref|XorOut| 584 | /// |---|---|---|---|---| 585 | /// |0x4C06|0xC867|0xFFFF|false|0x0000| 586 | /// 587 | /// ``` 588 | /// # use crc_any::CRCu16; 589 | /// let mut crc = CRCu16::crc16cdma2000(); 590 | /// crc.digest(b"123456789"); 591 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0x4C06\", &crc.to_string());")] 592 | /// ``` 593 | pub fn crc16cdma2000() -> CRCu16 { 594 | // Self::create_crc(0xC867, 16, 0xFFFF, 0x0000, false) 595 | 596 | let lookup_table = LookUpTable::Static(&NO_REF_16_C867); 597 | Self::create_crc_with_exists_lookup_table(lookup_table, 16, 0xFFFF, 0x0000, false) 598 | } 599 | 600 | /// |Check|Poly|Init|Ref|XorOut| 601 | /// |---|---|---|---|---| 602 | /// |0x9ECF|0x8005|0x800D|false|0x0000| 603 | /// 604 | /// ``` 605 | /// # use crc_any::CRCu16; 606 | /// let mut crc = CRCu16::crc16dds_110(); 607 | /// crc.digest(b"123456789"); 608 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0x9ECF\", &crc.to_string());")] 609 | /// ``` 610 | pub fn crc16dds_110() -> CRCu16 { 611 | // Self::create_crc(0x8005, 16, 0x800D, 0x0000, false) 612 | 613 | let lookup_table = LookUpTable::Static(&NO_REF_16_8005); 614 | Self::create_crc_with_exists_lookup_table(lookup_table, 16, 0x800D, 0x0000, false) 615 | } 616 | 617 | /// |Check|Poly|Init|Ref|XorOut| 618 | /// |---|---|---|---|---| 619 | /// |0x007E|0x0589|0x0000|false|0x0001| 620 | /// 621 | /// ``` 622 | /// # use crc_any::CRCu16; 623 | /// let mut crc = CRCu16::crc16dect_r(); 624 | /// crc.digest(b"123456789"); 625 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0x007E\", &crc.to_string());")] 626 | /// ``` 627 | pub fn crc16dect_r() -> CRCu16 { 628 | // Self::create_crc(0x0589, 16, 0x0000, 0x0001, false) 629 | 630 | let lookup_table = LookUpTable::Static(&NO_REF_16_0589); 631 | Self::create_crc_with_exists_lookup_table(lookup_table, 16, 0x0000, 0x0001, false) 632 | } 633 | 634 | /// |Check|Poly|Init|Ref|XorOut| 635 | /// |---|---|---|---|---| 636 | /// |0x007F|0x0589|0x0000|false|0x0000| 637 | /// 638 | /// ``` 639 | /// # use crc_any::CRCu16; 640 | /// let mut crc = CRCu16::crc16dect_r(); 641 | /// crc.digest(b"123456789"); 642 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0x007E\", &crc.to_string());")] 643 | /// ``` 644 | pub fn crc16dect_x() -> CRCu16 { 645 | // Self::create_crc(0x0589, 16, 0x0000, 0x0000, false) 646 | 647 | let lookup_table = LookUpTable::Static(&NO_REF_16_0589); 648 | Self::create_crc_with_exists_lookup_table(lookup_table, 16, 0x0000, 0x0000, false) 649 | } 650 | 651 | /// |Check|Poly|Init|Ref|XorOut| 652 | /// |---|---|---|---|---| 653 | /// |0xEA82|0x3D65 (rev: 0xA6BC)|0x0000|true|0xFFFF| 654 | /// 655 | /// ``` 656 | /// # use crc_any::CRCu16; 657 | /// let mut crc = CRCu16::crc16dnp(); 658 | /// crc.digest(b"123456789"); 659 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0xEA82\", &crc.to_string());")] 660 | /// ``` 661 | pub fn crc16dnp() -> CRCu16 { 662 | // Self::create_crc(0xA6BC, 16, 0x0000, 0xFFFF, true) 663 | 664 | let lookup_table = LookUpTable::Static(&REF_16_A6BC); 665 | Self::create_crc_with_exists_lookup_table(lookup_table, 16, 0x0000, 0xFFFF, true) 666 | } 667 | 668 | /// |Check|Poly|Init|Ref|XorOut| 669 | /// |---|---|---|---|---| 670 | /// |0xC2B7|0x3D65|0x0000|false|0xFFFF| 671 | /// 672 | /// ``` 673 | /// # use crc_any::CRCu16; 674 | /// let mut crc = CRCu16::crc16en_13757(); 675 | /// crc.digest(b"123456789"); 676 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0xC2B7\", &crc.to_string());")] 677 | /// ``` 678 | pub fn crc16en_13757() -> CRCu16 { 679 | // Self::create_crc(0x3D65, 16, 0x0000, 0xFFFF, false) 680 | 681 | let lookup_table = LookUpTable::Static(&NO_REF_16_3D65); 682 | Self::create_crc_with_exists_lookup_table(lookup_table, 16, 0x0000, 0xFFFF, false) 683 | } 684 | 685 | /// |Check|Poly|Init|Ref|XorOut| 686 | /// |---|---|---|---|---| 687 | /// |0xD64E|0x1021|0xFFFF|false|0xFFFF| 688 | /// 689 | /// ``` 690 | /// # use crc_any::CRCu16; 691 | /// let mut crc = CRCu16::crc16genibus(); 692 | /// crc.digest(b"123456789"); 693 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0xD64E\", &crc.to_string());")] 694 | /// ``` 695 | pub fn crc16genibus() -> CRCu16 { 696 | // Self::create_crc(0x1021, 16, 0xFFFF, 0xFFFF, false) 697 | 698 | let lookup_table = LookUpTable::Static(&NO_REF_16_1021); 699 | Self::create_crc_with_exists_lookup_table(lookup_table, 16, 0xFFFF, 0xFFFF, false) 700 | } 701 | 702 | /// |Check|Poly|Init|Ref|XorOut| 703 | /// |---|---|---|---|---| 704 | /// |0x44C2|0x8005 (rev: 0xA001)|0xFFFF|true|0xFFFF| 705 | /// 706 | /// ``` 707 | /// # use crc_any::CRCu16; 708 | /// let mut crc = CRCu16::crc16maxim(); 709 | /// crc.digest(b"123456789"); 710 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0x44C2\", &crc.to_string());")] 711 | /// ``` 712 | pub fn crc16maxim() -> CRCu16 { 713 | // Self::create_crc(0xA001, 16, 0x0000, 0xFFFF, true) 714 | 715 | let lookup_table = LookUpTable::Static(&REF_16_A001); 716 | Self::create_crc_with_exists_lookup_table(lookup_table, 16, 0x0000, 0xFFFF, true) 717 | } 718 | 719 | /// |Check|Poly|Init|Ref|XorOut| 720 | /// |---|---|---|---|---| 721 | /// |0x6F91|0x1021 (rev: 0x8408)|0xFFFF|true|0x0000| 722 | /// 723 | /// ``` 724 | /// # use crc_any::CRCu16; 725 | /// let mut crc = CRCu16::crc16mcrf4cc(); 726 | /// crc.digest(b"123456789"); 727 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0x6F91\", &crc.to_string());")] 728 | /// ``` 729 | pub fn crc16mcrf4cc() -> CRCu16 { 730 | // Self::create_crc(0x8408, 16, 0xFFFF, 0x0000, true) 731 | 732 | let lookup_table = LookUpTable::Static(&REF_16_8408); 733 | Self::create_crc_with_exists_lookup_table(lookup_table, 16, 0xFFFF, 0x0000, true) 734 | } 735 | 736 | /// |Check|Poly|Init|Ref|XorOut| 737 | /// |---|---|---|---|---| 738 | /// |0x63D0|0x1021 (rev: 0x8408)|0xB2AA|true|0x0000| 739 | /// 740 | /// ``` 741 | /// # use crc_any::CRCu16; 742 | /// let mut crc = CRCu16::crc16riello(); 743 | /// crc.digest(b"123456789"); 744 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0x63D0\", &crc.to_string());")] 745 | /// ``` 746 | pub fn crc16riello() -> CRCu16 { 747 | // Self::create_crc(0x8408, 16, 0xB2AA, 0x0000, true) 748 | 749 | let lookup_table = LookUpTable::Static(&REF_16_8408); 750 | Self::create_crc_with_exists_lookup_table(lookup_table, 16, 0xB2AA, 0x0000, true) 751 | } 752 | 753 | /// |Check|Poly|Init|Ref|XorOut| 754 | /// |---|---|---|---|---| 755 | /// |0xD0DB|0x8BB7|0x0000|false|0x0000| 756 | /// 757 | /// ``` 758 | /// # use crc_any::CRCu16; 759 | /// let mut crc = CRCu16::crc16t10_dif(); 760 | /// crc.digest(b"123456789"); 761 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0xD0DB\", &crc.to_string());")] 762 | /// ``` 763 | pub fn crc16t10_dif() -> CRCu16 { 764 | // Self::create_crc(0x8BB7, 16, 0x0000, 0x0000, false) 765 | 766 | let lookup_table = LookUpTable::Static(&NO_REF_16_8BB7); 767 | Self::create_crc_with_exists_lookup_table(lookup_table, 16, 0x0000, 0x0000, false) 768 | } 769 | 770 | /// |Check|Poly|Init|Ref|XorOut| 771 | /// |---|---|---|---|---| 772 | /// |0x0FB3|0xA097|0x0000|false|0x0000| 773 | /// 774 | /// ``` 775 | /// # use crc_any::CRCu16; 776 | /// let mut crc = CRCu16::crc16teledisk(); 777 | /// crc.digest(b"123456789"); 778 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0x0FB3\", &crc.to_string());")] 779 | /// ``` 780 | pub fn crc16teledisk() -> CRCu16 { 781 | // Self::create_crc(0xA097, 16, 0x0000, 0x0000, false) 782 | 783 | let lookup_table = LookUpTable::Static(&REF_16_A097); 784 | Self::create_crc_with_exists_lookup_table(lookup_table, 16, 0x0000, 0x0000, false) 785 | } 786 | 787 | /// |Check|Poly|Init|Ref|XorOut| 788 | /// |---|---|---|---|---| 789 | /// |0x26B1|0x1021 (rev: 0x8408)|0x89EC|true|0x0000| 790 | /// 791 | /// ``` 792 | /// # use crc_any::CRCu16; 793 | /// let mut crc = CRCu16::crc16tms13157(); 794 | /// crc.digest(b"123456789"); 795 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0x26B1\", &crc.to_string());")] 796 | /// ``` 797 | pub fn crc16tms13157() -> CRCu16 { 798 | // Self::create_crc(0x8408, 16, 0x89EC, 0x0000, true) 799 | 800 | let lookup_table = LookUpTable::Static(&REF_16_8408); 801 | Self::create_crc_with_exists_lookup_table(lookup_table, 16, 0x89EC, 0x0000, true) 802 | } 803 | 804 | /// |Check|Poly|Init|Ref|XorOut| 805 | /// |---|---|---|---|---| 806 | /// |0xB4C8|0x8005 (rev: 0xA001)|0xFFFF|true|0xFFFF| 807 | /// 808 | /// ``` 809 | /// # use crc_any::CRCu16; 810 | /// let mut crc = CRCu16::crc16usb(); 811 | /// crc.digest(b"123456789"); 812 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0xB4C8\", &crc.to_string());")] 813 | /// ``` 814 | pub fn crc16usb() -> CRCu16 { 815 | // Self::create_crc(0xA001, 16, 0xFFFF, 0xFFFF, true) 816 | 817 | let lookup_table = LookUpTable::Static(&REF_16_A001); 818 | Self::create_crc_with_exists_lookup_table(lookup_table, 16, 0xFFFF, 0xFFFF, true) 819 | } 820 | 821 | /// |Check|Poly|Init|Ref|XorOut| 822 | /// |---|---|---|---|---| 823 | /// |0xBF05|0x1021 (rev: 0x8408)|0xC6C6|true|0x0000| 824 | /// 825 | /// ``` 826 | /// # use crc_any::CRCu16; 827 | /// let mut crc = CRCu16::crc_a(); 828 | /// crc.digest(b"123456789"); 829 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0xBF05\", &crc.to_string());")] 830 | /// ``` 831 | pub fn crc_a() -> CRCu16 { 832 | // Self::create_crc(0x8408, 16, 0xC6C6, 0x0000, true) 833 | 834 | let lookup_table = LookUpTable::Static(&REF_16_8408); 835 | Self::create_crc_with_exists_lookup_table(lookup_table, 16, 0xC6C6, 0x0000, true) 836 | } 837 | 838 | /// |Check|Poly|Init|Ref|XorOut| 839 | /// |---|---|---|---|---| 840 | /// |0x2189|0x1021 (rev: 0x8408)|0x0000|true|0x0000| 841 | /// 842 | /// ``` 843 | /// # use crc_any::CRCu16; 844 | /// let mut crc = CRCu16::crc16kermit(); 845 | /// crc.digest(b"123456789"); 846 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0x2189\", &crc.to_string());")] 847 | /// ``` 848 | pub fn crc16kermit() -> CRCu16 { 849 | // Self::create_crc(0x8408, 16, 0x0000, 0x0000, true) 850 | 851 | let lookup_table = LookUpTable::Static(&REF_16_8408); 852 | Self::create_crc_with_exists_lookup_table(lookup_table, 16, 0x0000, 0x0000, true) 853 | } 854 | 855 | /// |Check|Poly|Init|Ref|XorOut| 856 | /// |---|---|---|---|---| 857 | /// |0x4B37|0x8005 (rev: 0xA001)|0xFFFF|true|0x0000| 858 | /// 859 | /// ``` 860 | /// # use crc_any::CRCu16; 861 | /// let mut crc = CRCu16::crc16modbus(); 862 | /// crc.digest(b"123456789"); 863 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0x4B37\", &crc.to_string());")] 864 | /// ``` 865 | pub fn crc16modbus() -> CRCu16 { 866 | // Self::create_crc(0xA001, 16, 0xFFFF, 0x0000, true) 867 | 868 | let lookup_table = LookUpTable::Static(&REF_16_A001); 869 | Self::create_crc_with_exists_lookup_table(lookup_table, 16, 0xFFFF, 0x0000, true) 870 | } 871 | 872 | /// |Check|Poly|Init|Ref|XorOut| 873 | /// |---|---|---|---|---| 874 | /// |0x906E|0x8005 (rev: 0xA001)|0xFFFF|true|0xFFFF| 875 | /// 876 | /// ``` 877 | /// # use crc_any::CRCu16; 878 | /// let mut crc = CRCu16::crc16_x25(); 879 | /// crc.digest(b"123456789"); 880 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0x906E\", &crc.to_string());")] 881 | /// ``` 882 | pub fn crc16_x25() -> CRCu16 { 883 | // Self::create_crc(0x8408, 16, 0xFFFF, 0xFFFF, true) 884 | 885 | let lookup_table = LookUpTable::Static(&REF_16_8408); 886 | Self::create_crc_with_exists_lookup_table(lookup_table, 16, 0xFFFF, 0xFFFF, true) 887 | } 888 | 889 | /// |Check|Poly|Init|Ref|XorOut| 890 | /// |---|---|---|---|---| 891 | /// |0x31C3|0x1021|0x0000|false|0x0000| 892 | /// 893 | /// ``` 894 | /// # use crc_any::CRCu16; 895 | /// let mut crc = CRCu16::crc16xmodem(); 896 | /// crc.digest(b"123456789"); 897 | #[cfg_attr(feature = "alloc", doc = "assert_eq!(\"0x31C3\", &crc.to_string());")] 898 | /// ``` 899 | pub fn crc16xmodem() -> CRCu16 { 900 | // Self::create_crc(0x1021, 16, 0x0000, 0x0000, false) 901 | 902 | let lookup_table = LookUpTable::Static(&NO_REF_16_1021); 903 | Self::create_crc_with_exists_lookup_table(lookup_table, 16, 0x0000, 0x0000, false) 904 | } 905 | } 906 | 907 | #[cfg(all(feature = "development", test))] 908 | mod tests { 909 | use alloc::{fmt::Write, string::String}; 910 | 911 | use super::CRCu16; 912 | 913 | #[test] 914 | fn print_lookup_table() { 915 | let crc = CRCu16::crc16kermit(); 916 | 917 | let mut s = String::new(); 918 | 919 | for n in crc.lookup_table.iter().take(255) { 920 | s.write_fmt(format_args!("{}u16, ", n)).unwrap(); 921 | } 922 | 923 | s.write_fmt(format_args!("{}u16", crc.lookup_table[255])).unwrap(); 924 | 925 | println!("let lookup_table = [{}];", s); 926 | } 927 | } 928 | --------------------------------------------------------------------------------