crc-catalog-2.2.0/.cargo_vcs_info.json0000644000000001360000000000100132140ustar { "git": { "sha1": "d18d9fb4f613f58724111403b39ae7a1f6bc9c3e" }, "path_in_vcs": "" }crc-catalog-2.2.0/.github/workflows/rust.yaml000064400000000000000000000020371046102023000172640ustar 00000000000000name: rust on: push: branches: [ master ] pull_request: branches: [ master ] env: CARGO_TERM_COLOR: always jobs: lint: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - uses: actions-rs/toolchain@v1 with: profile: minimal toolchain: stable components: rustfmt, clippy override: true - uses: actions-rs/cargo@v1 with: command: clippy args: -- -D warnings - uses: actions-rs/cargo@v1 with: command: fmt args: --all -- --check test: runs-on: ubuntu-latest strategy: matrix: rust: - 1.46.0 - stable - beta steps: - uses: actions/checkout@v2 - uses: actions-rs/toolchain@v1 with: profile: minimal toolchain: ${{ matrix.rust }} override: true - uses: actions-rs/cargo@v1 with: command: check - uses: actions-rs/cargo@v1 with: command: test crc-catalog-2.2.0/.gitignore000064400000000000000000000000231046102023000137670ustar 00000000000000Cargo.lock target/ crc-catalog-2.2.0/Cargo.toml0000644000000017710000000000100112200ustar # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g., crates.io) dependencies. # # If you are reading this file be aware that the original Cargo.toml # will likely look very different (and much more reasonable). # See Cargo.toml.orig for the original contents. [package] edition = "2018" name = "crc-catalog" version = "2.2.0" authors = ["Akhil Velagapudi "] exclude = ["generate_catalog.sh"] description = "Catalog of CRC algorithms (generated from http://reveng.sourceforge.net/crc-catalogue) expressed as simple Rust structs." readme = "README.md" keywords = ["crc"] categories = [ "no-std", "network-programming", ] license = "MIT OR Apache-2.0" repository = "https://github.com/akhilles/crc-catalog.git" [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] crc-catalog-2.2.0/Cargo.toml.orig000064400000000000000000000010341046102023000146710ustar 00000000000000[package] name = "crc-catalog" version = "2.2.0" authors = ["Akhil Velagapudi "] edition = "2018" description = "Catalog of CRC algorithms (generated from http://reveng.sourceforge.net/crc-catalogue) expressed as simple Rust structs." repository = "https://github.com/akhilles/crc-catalog.git" readme = "README.md" keywords = ["crc"] categories = ["no-std", "network-programming"] license = "MIT OR Apache-2.0" exclude = ["generate_catalog.sh"] [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] crc-catalog-2.2.0/LICENSE-APACHE000064400000000000000000000261221046102023000137330ustar 00000000000000 Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright 2019 Akhil Velagapudi Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. crc-catalog-2.2.0/LICENSE-MIT000064400000000000000000000020611046102023000134370ustar 00000000000000MIT License Copyright (c) 2019 Akhil Velagapudi Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. crc-catalog-2.2.0/README.md000064400000000000000000000021631046102023000132650ustar 00000000000000# crc-catalog [![rust](https://github.com/akhilles/crc-catalog/actions/workflows/rust.yaml/badge.svg)](https://github.com/akhilles/crc-catalog/actions/workflows/rust.yaml) [![Crate](https://img.shields.io/crates/v/crc-catalog.svg)](https://crates.io/crates/crc-catalog) [![Docs](https://docs.rs/crc-catalog/badge.svg)](https://docs.rs/crc-catalog) MSRV is 1.46. Catalog of CRC algorithms expressed as simple Rust structs. The Rust code is generated from the "[Catalogue of parametrised CRC algorithms](http://reveng.sourceforge.net/crc-catalogue)" using the `generate_catalog.sh` script: ``` $ ./generate_catalog.sh > src/catalog.rs ``` ## License Licensed under either of * Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) * MIT License ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) at your option. ### Contribution Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions. crc-catalog-2.2.0/src/catalog.rs000064400000000000000000000461201046102023000145560ustar 00000000000000use crate::Algorithm; pub const CRC_3_GSM: Algorithm = Algorithm { width: 3, poly: 0x3, init: 0x0, refin: false, refout: false, xorout: 0x7, check: 0x4, residue: 0x2 }; pub const CRC_3_ROHC: Algorithm = Algorithm { width: 3, poly: 0x3, init: 0x7, refin: true, refout: true, xorout: 0x0, check: 0x6, residue: 0x0 }; pub const CRC_4_G_704: Algorithm = Algorithm { width: 4, poly: 0x3, init: 0x0, refin: true, refout: true, xorout: 0x0, check: 0x7, residue: 0x0 }; pub const CRC_4_INTERLAKEN: Algorithm = Algorithm { width: 4, poly: 0x3, init: 0xf, refin: false, refout: false, xorout: 0xf, check: 0xb, residue: 0x2 }; pub const CRC_5_EPC_C1G2: Algorithm = Algorithm { width: 5, poly: 0x09, init: 0x09, refin: false, refout: false, xorout: 0x00, check: 0x00, residue: 0x00 }; pub const CRC_5_G_704: Algorithm = Algorithm { width: 5, poly: 0x15, init: 0x00, refin: true, refout: true, xorout: 0x00, check: 0x07, residue: 0x00 }; pub const CRC_5_USB: Algorithm = Algorithm { width: 5, poly: 0x05, init: 0x1f, refin: true, refout: true, xorout: 0x1f, check: 0x19, residue: 0x06 }; pub const CRC_6_CDMA2000_A: Algorithm = Algorithm { width: 6, poly: 0x27, init: 0x3f, refin: false, refout: false, xorout: 0x00, check: 0x0d, residue: 0x00 }; pub const CRC_6_CDMA2000_B: Algorithm = Algorithm { width: 6, poly: 0x07, init: 0x3f, refin: false, refout: false, xorout: 0x00, check: 0x3b, residue: 0x00 }; pub const CRC_6_DARC: Algorithm = Algorithm { width: 6, poly: 0x19, init: 0x00, refin: true, refout: true, xorout: 0x00, check: 0x26, residue: 0x00 }; pub const CRC_6_G_704: Algorithm = Algorithm { width: 6, poly: 0x03, init: 0x00, refin: true, refout: true, xorout: 0x00, check: 0x06, residue: 0x00 }; pub const CRC_6_GSM: Algorithm = Algorithm { width: 6, poly: 0x2f, init: 0x00, refin: false, refout: false, xorout: 0x3f, check: 0x13, residue: 0x3a }; pub const CRC_7_MMC: Algorithm = Algorithm { width: 7, poly: 0x09, init: 0x00, refin: false, refout: false, xorout: 0x00, check: 0x75, residue: 0x00 }; pub const CRC_7_ROHC: Algorithm = Algorithm { width: 7, poly: 0x4f, init: 0x7f, refin: true, refout: true, xorout: 0x00, check: 0x53, residue: 0x00 }; pub const CRC_7_UMTS: Algorithm = Algorithm { width: 7, poly: 0x45, init: 0x00, refin: false, refout: false, xorout: 0x00, check: 0x61, residue: 0x00 }; pub const CRC_8_AUTOSAR: Algorithm = Algorithm { width: 8, poly: 0x2f, init: 0xff, refin: false, refout: false, xorout: 0xff, check: 0xdf, residue: 0x42 }; pub const CRC_8_BLUETOOTH: Algorithm = Algorithm { width: 8, poly: 0xa7, init: 0x00, refin: true, refout: true, xorout: 0x00, check: 0x26, residue: 0x00 }; pub const CRC_8_CDMA2000: Algorithm = Algorithm { width: 8, poly: 0x9b, init: 0xff, refin: false, refout: false, xorout: 0x00, check: 0xda, residue: 0x00 }; pub const CRC_8_DARC: Algorithm = Algorithm { width: 8, poly: 0x39, init: 0x00, refin: true, refout: true, xorout: 0x00, check: 0x15, residue: 0x00 }; pub const CRC_8_DVB_S2: Algorithm = Algorithm { width: 8, poly: 0xd5, init: 0x00, refin: false, refout: false, xorout: 0x00, check: 0xbc, residue: 0x00 }; pub const CRC_8_GSM_A: Algorithm = Algorithm { width: 8, poly: 0x1d, init: 0x00, refin: false, refout: false, xorout: 0x00, check: 0x37, residue: 0x00 }; pub const CRC_8_GSM_B: Algorithm = Algorithm { width: 8, poly: 0x49, init: 0x00, refin: false, refout: false, xorout: 0xff, check: 0x94, residue: 0x53 }; pub const CRC_8_HITAG: Algorithm = Algorithm { width: 8, poly: 0x1d, init: 0xff, refin: false, refout: false, xorout: 0x00, check: 0xb4, residue: 0x00 }; pub const CRC_8_I_432_1: Algorithm = Algorithm { width: 8, poly: 0x07, init: 0x00, refin: false, refout: false, xorout: 0x55, check: 0xa1, residue: 0xac }; pub const CRC_8_I_CODE: Algorithm = Algorithm { width: 8, poly: 0x1d, init: 0xfd, refin: false, refout: false, xorout: 0x00, check: 0x7e, residue: 0x00 }; pub const CRC_8_LTE: Algorithm = Algorithm { width: 8, poly: 0x9b, init: 0x00, refin: false, refout: false, xorout: 0x00, check: 0xea, residue: 0x00 }; pub const CRC_8_MAXIM_DOW: Algorithm = Algorithm { width: 8, poly: 0x31, init: 0x00, refin: true, refout: true, xorout: 0x00, check: 0xa1, residue: 0x00 }; pub const CRC_8_MIFARE_MAD: Algorithm = Algorithm { width: 8, poly: 0x1d, init: 0xc7, refin: false, refout: false, xorout: 0x00, check: 0x99, residue: 0x00 }; pub const CRC_8_NRSC_5: Algorithm = Algorithm { width: 8, poly: 0x31, init: 0xff, refin: false, refout: false, xorout: 0x00, check: 0xf7, residue: 0x00 }; pub const CRC_8_OPENSAFETY: Algorithm = Algorithm { width: 8, poly: 0x2f, init: 0x00, refin: false, refout: false, xorout: 0x00, check: 0x3e, residue: 0x00 }; pub const CRC_8_ROHC: Algorithm = Algorithm { width: 8, poly: 0x07, init: 0xff, refin: true, refout: true, xorout: 0x00, check: 0xd0, residue: 0x00 }; pub const CRC_8_SAE_J1850: Algorithm = Algorithm { width: 8, poly: 0x1d, init: 0xff, refin: false, refout: false, xorout: 0xff, check: 0x4b, residue: 0xc4 }; pub const CRC_8_SMBUS: Algorithm = Algorithm { width: 8, poly: 0x07, init: 0x00, refin: false, refout: false, xorout: 0x00, check: 0xf4, residue: 0x00 }; pub const CRC_8_TECH_3250: Algorithm = Algorithm { width: 8, poly: 0x1d, init: 0xff, refin: true, refout: true, xorout: 0x00, check: 0x97, residue: 0x00 }; pub const CRC_8_WCDMA: Algorithm = Algorithm { width: 8, poly: 0x9b, init: 0x00, refin: true, refout: true, xorout: 0x00, check: 0x25, residue: 0x00 }; pub const CRC_10_ATM: Algorithm = Algorithm { width: 10, poly: 0x233, init: 0x000, refin: false, refout: false, xorout: 0x000, check: 0x199, residue: 0x000 }; pub const CRC_10_CDMA2000: Algorithm = Algorithm { width: 10, poly: 0x3d9, init: 0x3ff, refin: false, refout: false, xorout: 0x000, check: 0x233, residue: 0x000 }; pub const CRC_10_GSM: Algorithm = Algorithm { width: 10, poly: 0x175, init: 0x000, refin: false, refout: false, xorout: 0x3ff, check: 0x12a, residue: 0x0c6 }; pub const CRC_11_FLEXRAY: Algorithm = Algorithm { width: 11, poly: 0x385, init: 0x01a, refin: false, refout: false, xorout: 0x000, check: 0x5a3, residue: 0x000 }; pub const CRC_11_UMTS: Algorithm = Algorithm { width: 11, poly: 0x307, init: 0x000, refin: false, refout: false, xorout: 0x000, check: 0x061, residue: 0x000 }; pub const CRC_12_CDMA2000: Algorithm = Algorithm { width: 12, poly: 0xf13, init: 0xfff, refin: false, refout: false, xorout: 0x000, check: 0xd4d, residue: 0x000 }; pub const CRC_12_DECT: Algorithm = Algorithm { width: 12, poly: 0x80f, init: 0x000, refin: false, refout: false, xorout: 0x000, check: 0xf5b, residue: 0x000 }; pub const CRC_12_GSM: Algorithm = Algorithm { width: 12, poly: 0xd31, init: 0x000, refin: false, refout: false, xorout: 0xfff, check: 0xb34, residue: 0x178 }; pub const CRC_12_UMTS: Algorithm = Algorithm { width: 12, poly: 0x80f, init: 0x000, refin: false, refout: true, xorout: 0x000, check: 0xdaf, residue: 0x000 }; pub const CRC_13_BBC: Algorithm = Algorithm { width: 13, poly: 0x1cf5, init: 0x0000, refin: false, refout: false, xorout: 0x0000, check: 0x04fa, residue: 0x0000 }; pub const CRC_14_DARC: Algorithm = Algorithm { width: 14, poly: 0x0805, init: 0x0000, refin: true, refout: true, xorout: 0x0000, check: 0x082d, residue: 0x0000 }; pub const CRC_14_GSM: Algorithm = Algorithm { width: 14, poly: 0x202d, init: 0x0000, refin: false, refout: false, xorout: 0x3fff, check: 0x30ae, residue: 0x031e }; pub const CRC_15_CAN: Algorithm = Algorithm { width: 15, poly: 0x4599, init: 0x0000, refin: false, refout: false, xorout: 0x0000, check: 0x059e, residue: 0x0000 }; pub const CRC_15_MPT1327: Algorithm = Algorithm { width: 15, poly: 0x6815, init: 0x0000, refin: false, refout: false, xorout: 0x0001, check: 0x2566, residue: 0x6815 }; pub const CRC_16_ARC: Algorithm = Algorithm { width: 16, poly: 0x8005, init: 0x0000, refin: true, refout: true, xorout: 0x0000, check: 0xbb3d, residue: 0x0000 }; pub const CRC_16_CDMA2000: Algorithm = Algorithm { width: 16, poly: 0xc867, init: 0xffff, refin: false, refout: false, xorout: 0x0000, check: 0x4c06, residue: 0x0000 }; pub const CRC_16_CMS: Algorithm = Algorithm { width: 16, poly: 0x8005, init: 0xffff, refin: false, refout: false, xorout: 0x0000, check: 0xaee7, residue: 0x0000 }; pub const CRC_16_DDS_110: Algorithm = Algorithm { width: 16, poly: 0x8005, init: 0x800d, refin: false, refout: false, xorout: 0x0000, check: 0x9ecf, residue: 0x0000 }; pub const CRC_16_DECT_R: Algorithm = Algorithm { width: 16, poly: 0x0589, init: 0x0000, refin: false, refout: false, xorout: 0x0001, check: 0x007e, residue: 0x0589 }; pub const CRC_16_DECT_X: Algorithm = Algorithm { width: 16, poly: 0x0589, init: 0x0000, refin: false, refout: false, xorout: 0x0000, check: 0x007f, residue: 0x0000 }; pub const CRC_16_DNP: Algorithm = Algorithm { width: 16, poly: 0x3d65, init: 0x0000, refin: true, refout: true, xorout: 0xffff, check: 0xea82, residue: 0x66c5 }; pub const CRC_16_EN_13757: Algorithm = Algorithm { width: 16, poly: 0x3d65, init: 0x0000, refin: false, refout: false, xorout: 0xffff, check: 0xc2b7, residue: 0xa366 }; pub const CRC_16_GENIBUS: Algorithm = Algorithm { width: 16, poly: 0x1021, init: 0xffff, refin: false, refout: false, xorout: 0xffff, check: 0xd64e, residue: 0x1d0f }; pub const CRC_16_GSM: Algorithm = Algorithm { width: 16, poly: 0x1021, init: 0x0000, refin: false, refout: false, xorout: 0xffff, check: 0xce3c, residue: 0x1d0f }; pub const CRC_16_IBM_3740: Algorithm = Algorithm { width: 16, poly: 0x1021, init: 0xffff, refin: false, refout: false, xorout: 0x0000, check: 0x29b1, residue: 0x0000 }; pub const CRC_16_IBM_SDLC: Algorithm = Algorithm { width: 16, poly: 0x1021, init: 0xffff, refin: true, refout: true, xorout: 0xffff, check: 0x906e, residue: 0xf0b8 }; pub const CRC_16_ISO_IEC_14443_3_A: Algorithm = Algorithm { width: 16, poly: 0x1021, init: 0xc6c6, refin: true, refout: true, xorout: 0x0000, check: 0xbf05, residue: 0x0000 }; pub const CRC_16_KERMIT: Algorithm = Algorithm { width: 16, poly: 0x1021, init: 0x0000, refin: true, refout: true, xorout: 0x0000, check: 0x2189, residue: 0x0000 }; pub const CRC_16_LJ1200: Algorithm = Algorithm { width: 16, poly: 0x6f63, init: 0x0000, refin: false, refout: false, xorout: 0x0000, check: 0xbdf4, residue: 0x0000 }; pub const CRC_16_M17: Algorithm = Algorithm { width: 16, poly: 0x5935, init: 0xffff, refin: false, refout: false, xorout: 0x0000, check: 0x772b, residue: 0x0000 }; pub const CRC_16_MAXIM_DOW: Algorithm = Algorithm { width: 16, poly: 0x8005, init: 0x0000, refin: true, refout: true, xorout: 0xffff, check: 0x44c2, residue: 0xb001 }; pub const CRC_16_MCRF4XX: Algorithm = Algorithm { width: 16, poly: 0x1021, init: 0xffff, refin: true, refout: true, xorout: 0x0000, check: 0x6f91, residue: 0x0000 }; pub const CRC_16_MODBUS: Algorithm = Algorithm { width: 16, poly: 0x8005, init: 0xffff, refin: true, refout: true, xorout: 0x0000, check: 0x4b37, residue: 0x0000 }; pub const CRC_16_NRSC_5: Algorithm = Algorithm { width: 16, poly: 0x080b, init: 0xffff, refin: true, refout: true, xorout: 0x0000, check: 0xa066, residue: 0x0000 }; pub const CRC_16_OPENSAFETY_A: Algorithm = Algorithm { width: 16, poly: 0x5935, init: 0x0000, refin: false, refout: false, xorout: 0x0000, check: 0x5d38, residue: 0x0000 }; pub const CRC_16_OPENSAFETY_B: Algorithm = Algorithm { width: 16, poly: 0x755b, init: 0x0000, refin: false, refout: false, xorout: 0x0000, check: 0x20fe, residue: 0x0000 }; pub const CRC_16_PROFIBUS: Algorithm = Algorithm { width: 16, poly: 0x1dcf, init: 0xffff, refin: false, refout: false, xorout: 0xffff, check: 0xa819, residue: 0xe394 }; pub const CRC_16_RIELLO: Algorithm = Algorithm { width: 16, poly: 0x1021, init: 0xb2aa, refin: true, refout: true, xorout: 0x0000, check: 0x63d0, residue: 0x0000 }; pub const CRC_16_SPI_FUJITSU: Algorithm = Algorithm { width: 16, poly: 0x1021, init: 0x1d0f, refin: false, refout: false, xorout: 0x0000, check: 0xe5cc, residue: 0x0000 }; pub const CRC_16_T10_DIF: Algorithm = Algorithm { width: 16, poly: 0x8bb7, init: 0x0000, refin: false, refout: false, xorout: 0x0000, check: 0xd0db, residue: 0x0000 }; pub const CRC_16_TELEDISK: Algorithm = Algorithm { width: 16, poly: 0xa097, init: 0x0000, refin: false, refout: false, xorout: 0x0000, check: 0x0fb3, residue: 0x0000 }; pub const CRC_16_TMS37157: Algorithm = Algorithm { width: 16, poly: 0x1021, init: 0x89ec, refin: true, refout: true, xorout: 0x0000, check: 0x26b1, residue: 0x0000 }; pub const CRC_16_UMTS: Algorithm = Algorithm { width: 16, poly: 0x8005, init: 0x0000, refin: false, refout: false, xorout: 0x0000, check: 0xfee8, residue: 0x0000 }; pub const CRC_16_USB: Algorithm = Algorithm { width: 16, poly: 0x8005, init: 0xffff, refin: true, refout: true, xorout: 0xffff, check: 0xb4c8, residue: 0xb001 }; pub const CRC_16_XMODEM: Algorithm = Algorithm { width: 16, poly: 0x1021, init: 0x0000, refin: false, refout: false, xorout: 0x0000, check: 0x31c3, residue: 0x0000 }; pub const CRC_17_CAN_FD: Algorithm = Algorithm { width: 17, poly: 0x1685b, init: 0x00000, refin: false, refout: false, xorout: 0x00000, check: 0x04f03, residue: 0x00000 }; pub const CRC_21_CAN_FD: Algorithm = Algorithm { width: 21, poly: 0x102899, init: 0x000000, refin: false, refout: false, xorout: 0x000000, check: 0x0ed841, residue: 0x000000 }; pub const CRC_24_BLE: Algorithm = Algorithm { width: 24, poly: 0x00065b, init: 0x555555, refin: true, refout: true, xorout: 0x000000, check: 0xc25a56, residue: 0x000000 }; pub const CRC_24_FLEXRAY_A: Algorithm = Algorithm { width: 24, poly: 0x5d6dcb, init: 0xfedcba, refin: false, refout: false, xorout: 0x000000, check: 0x7979bd, residue: 0x000000 }; pub const CRC_24_FLEXRAY_B: Algorithm = Algorithm { width: 24, poly: 0x5d6dcb, init: 0xabcdef, refin: false, refout: false, xorout: 0x000000, check: 0x1f23b8, residue: 0x000000 }; pub const CRC_24_INTERLAKEN: Algorithm = Algorithm { width: 24, poly: 0x328b63, init: 0xffffff, refin: false, refout: false, xorout: 0xffffff, check: 0xb4f3e6, residue: 0x144e63 }; pub const CRC_24_LTE_A: Algorithm = Algorithm { width: 24, poly: 0x864cfb, init: 0x000000, refin: false, refout: false, xorout: 0x000000, check: 0xcde703, residue: 0x000000 }; pub const CRC_24_LTE_B: Algorithm = Algorithm { width: 24, poly: 0x800063, init: 0x000000, refin: false, refout: false, xorout: 0x000000, check: 0x23ef52, residue: 0x000000 }; pub const CRC_24_OPENPGP: Algorithm = Algorithm { width: 24, poly: 0x864cfb, init: 0xb704ce, refin: false, refout: false, xorout: 0x000000, check: 0x21cf02, residue: 0x000000 }; pub const CRC_24_OS_9: Algorithm = Algorithm { width: 24, poly: 0x800063, init: 0xffffff, refin: false, refout: false, xorout: 0xffffff, check: 0x200fa5, residue: 0x800fe3 }; pub const CRC_30_CDMA: Algorithm = Algorithm { width: 30, poly: 0x2030b9c7, init: 0x3fffffff, refin: false, refout: false, xorout: 0x3fffffff, check: 0x04c34abf, residue: 0x34efa55a }; pub const CRC_31_PHILIPS: Algorithm = Algorithm { width: 31, poly: 0x04c11db7, init: 0x7fffffff, refin: false, refout: false, xorout: 0x7fffffff, check: 0x0ce9e46c, residue: 0x4eaf26f1 }; pub const CRC_32_AIXM: Algorithm = Algorithm { width: 32, poly: 0x814141ab, init: 0x00000000, refin: false, refout: false, xorout: 0x00000000, check: 0x3010bf7f, residue: 0x00000000 }; pub const CRC_32_AUTOSAR: Algorithm = Algorithm { width: 32, poly: 0xf4acfb13, init: 0xffffffff, refin: true, refout: true, xorout: 0xffffffff, check: 0x1697d06a, residue: 0x904cddbf }; pub const CRC_32_BASE91_D: Algorithm = Algorithm { width: 32, poly: 0xa833982b, init: 0xffffffff, refin: true, refout: true, xorout: 0xffffffff, check: 0x87315576, residue: 0x45270551 }; pub const CRC_32_BZIP2: Algorithm = Algorithm { width: 32, poly: 0x04c11db7, init: 0xffffffff, refin: false, refout: false, xorout: 0xffffffff, check: 0xfc891918, residue: 0xc704dd7b }; pub const CRC_32_CD_ROM_EDC: Algorithm = Algorithm { width: 32, poly: 0x8001801b, init: 0x00000000, refin: true, refout: true, xorout: 0x00000000, check: 0x6ec2edc4, residue: 0x00000000 }; pub const CRC_32_CKSUM: Algorithm = Algorithm { width: 32, poly: 0x04c11db7, init: 0x00000000, refin: false, refout: false, xorout: 0xffffffff, check: 0x765e7680, residue: 0xc704dd7b }; pub const CRC_32_ISCSI: Algorithm = Algorithm { width: 32, poly: 0x1edc6f41, init: 0xffffffff, refin: true, refout: true, xorout: 0xffffffff, check: 0xe3069283, residue: 0xb798b438 }; pub const CRC_32_ISO_HDLC: Algorithm = Algorithm { width: 32, poly: 0x04c11db7, init: 0xffffffff, refin: true, refout: true, xorout: 0xffffffff, check: 0xcbf43926, residue: 0xdebb20e3 }; pub const CRC_32_JAMCRC: Algorithm = Algorithm { width: 32, poly: 0x04c11db7, init: 0xffffffff, refin: true, refout: true, xorout: 0x00000000, check: 0x340bc6d9, residue: 0x00000000 }; pub const CRC_32_MEF: Algorithm = Algorithm { width: 32, poly: 0x741b8cd7, init: 0xffffffff, refin: true, refout: true, xorout: 0x00000000, check: 0xd2c22f51, residue: 0x00000000 }; pub const CRC_32_MPEG_2: Algorithm = Algorithm { width: 32, poly: 0x04c11db7, init: 0xffffffff, refin: false, refout: false, xorout: 0x00000000, check: 0x0376e6e7, residue: 0x00000000 }; pub const CRC_32_XFER: Algorithm = Algorithm { width: 32, poly: 0x000000af, init: 0x00000000, refin: false, refout: false, xorout: 0x00000000, check: 0xbd0be338, residue: 0x00000000 }; pub const CRC_40_GSM: Algorithm = Algorithm { width: 40, poly: 0x0004820009, init: 0x0000000000, refin: false, refout: false, xorout: 0xffffffffff, check: 0xd4164fc646, residue: 0xc4ff8071ff }; pub const CRC_64_ECMA_182: Algorithm = Algorithm { width: 64, poly: 0x42f0e1eba9ea3693, init: 0x0000000000000000, refin: false, refout: false, xorout: 0x0000000000000000, check: 0x6c40df5f0b497347, residue: 0x0000000000000000 }; pub const CRC_64_GO_ISO: Algorithm = Algorithm { width: 64, poly: 0x000000000000001b, init: 0xffffffffffffffff, refin: true, refout: true, xorout: 0xffffffffffffffff, check: 0xb90956c775a41001, residue: 0x5300000000000000 }; pub const CRC_64_MS: Algorithm = Algorithm { width: 64, poly: 0x259c84cba6426349, init: 0xffffffffffffffff, refin: true, refout: true, xorout: 0x0000000000000000, check: 0x75d4b74f024eceea, residue: 0x0000000000000000 }; pub const CRC_64_REDIS: Algorithm = Algorithm { width: 64, poly: 0xad93d23594c935a9, init: 0x0000000000000000, refin: true, refout: true, xorout: 0x0000000000000000, check: 0xe9c6d914c4b8d9ca, residue: 0x0000000000000000 }; pub const CRC_64_WE: Algorithm = Algorithm { width: 64, poly: 0x42f0e1eba9ea3693, init: 0xffffffffffffffff, refin: false, refout: false, xorout: 0xffffffffffffffff, check: 0x62ec59e3f1a4f00a, residue: 0xfcacbebd5931a992 }; pub const CRC_64_XZ: Algorithm = Algorithm { width: 64, poly: 0x42f0e1eba9ea3693, init: 0xffffffffffffffff, refin: true, refout: true, xorout: 0xffffffffffffffff, check: 0x995dc9bbdf1939fa, residue: 0x49958c9abd7d353f }; pub const CRC_82_DARC: Algorithm = Algorithm { width: 82, poly: 0x0308c0111011401440411, init: 0x000000000000000000000, refin: true, refout: true, xorout: 0x000000000000000000000, check: 0x09ea83f625023801fd612, residue: 0x000000000000000000000 }; crc-catalog-2.2.0/src/lib.rs000064400000000000000000000064071046102023000137160ustar 00000000000000#![no_std] #[rustfmt::skip] mod catalog; pub use catalog::*; pub trait Width: Sized + 'static {} impl Width for u8 {} impl Width for u16 {} impl Width for u32 {} impl Width for u64 {} impl Width for u128 {} /// This struct describes a CRC algorithm using the fields specified by the [Catalogue of /// parametrised CRC algorithms](https://reveng.sourceforge.io/crc-catalogue/all.htm). pub struct Algorithm { /// The number of bit cells in the linear feedback shift register; the degree of the generator /// polynomial, minus one. pub width: u8, /// The generator polynomial that sets the feedback tap positions of the shift register. The /// least significant bit corresponds to the inward end of the shift register, and is always /// set. The highest-order term is omitted. pub poly: W, /// The settings of the bit cells at the start of each calculation, before reading the first /// message bit. The least significant bit corresponds to the inward end of the shift register. pub init: W, /// If equal to `false`, specifies that the characters of the message are read bit-by-bit, most /// significant bit (MSB) first; if equal to `true`, the characters are read bit-by-bit, least /// significant bit (LSB) first. Each sampled message bit is then XORed with the bit being /// simultaneously shifted out of the register at the most significant end, and the result is /// passed to the feedback taps. pub refin: bool, /// If equal to `false`, specifies that the contents of the register after reading the last /// message bit are unreflected before presentation; if equal to `true`, it specifies that they /// are reflected, character-by-character, before presentation. For the purpose of this /// definition, the reflection is performed by swapping the content of each cell with that of /// the cell an equal distance from the opposite end of the register; the characters of the CRC /// are then true images of parts of the reflected register, the character containing the /// original MSB always appearing first. pub refout: bool, /// The XOR value applied to the contents of the register after the last message bit has been /// read and after the optional reflection. It has the same endianness as the CRC such that its /// true image appears in the characters of the CRC. pub xorout: W, /// The contents of the register after initialising, reading the UTF-8 string `"123456789"` (as /// 8-bit characters), optionally reflecting, and applying the final XOR. pub check: W, /// The contents of the register after initialising, reading an error-free codeword and /// optionally reflecting the register (if [`refout`](Algorithm::refout)=`true`), but not /// applying the final XOR. This is mathematically equivalent to initialising the register with /// the xorout parameter, reflecting it as described (if [`refout`](Algorithm::refout)=`true`), /// reading as many zero bits as there are cells in the register, and reflecting the result (if /// [`refin`](Algorithm::refin)=`true`). The residue of a crossed-endian model is calculated /// assuming that the characters of the received CRC are specially reflected before submitting /// the codeword. pub residue: W, }