Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mrhooray/crc-rs
Rust implementation of CRC(16, 32, 64) with support of various standards
https://github.com/mrhooray/crc-rs
checksum crc crc16 crc32 crc64 hash rust
Last synced: about 1 month ago
JSON representation
Rust implementation of CRC(16, 32, 64) with support of various standards
- Host: GitHub
- URL: https://github.com/mrhooray/crc-rs
- Owner: mrhooray
- License: apache-2.0
- Created: 2015-03-15T09:22:04.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2024-04-08T17:19:53.000Z (about 2 months ago)
- Last Synced: 2024-04-16T01:00:42.242Z (about 2 months ago)
- Topics: checksum, crc, crc16, crc32, crc64, hash, rust
- Language: Rust
- Homepage:
- Size: 144 KB
- Stars: 178
- Watchers: 10
- Forks: 48
- Open Issues: 18
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Lists
- awesome-rust - mrhooray/crc-rs
- awesome-rust-zh - mrhooray/crc-rs - [<img src="https://api.travis-ci.org/mrhooray/crc-rs.svg?branch=master">](https://travis-ci.org/mrhooray/crc-rs) (库 / 编码(Encoding))
- awesome-rust - mrhooray/crc-rs - ci.org/mrhooray/crc-rs.svg?branch=master)](https://travis-ci.org/mrhooray/crc-rs) (Libraries / Encoding)
- awesome-rust - mrhooray/crc-rs - ci.org/mrhooray/crc-rs.svg?branch=master">](https://travis-ci.org/mrhooray/crc-rs) (Libraries / Encoding)
- awesome-rust - mrhooray/crc-rs - ci.org/mrhooray/crc-rs.svg?branch=master">](https://travis-ci.org/mrhooray/crc-rs) (库 Libraries / 加密 Encoding)
- awesome-rust - mrhooray/crc-rs - ci.org/mrhooray/crc-rs.svg?branch=master">](https://travis-ci.org/mrhooray/crc-rs) (Libraries / Encoding)
- awesome-rust-cn - mrhooray/crc-rs - ci.org/mrhooray/crc-rs.svg?branch=master">](https://travis-ci.org/mrhooray/crc-rs) (Libraries / Encoding)
- awesome-rust-cn - mrhooray/crc-rs
- awesome-rust - mrhooray/crc-rs - ci.org/mrhooray/crc-rs.svg?branch=master">](https://travis-ci.org/mrhooray/crc-rs) (Libraries / Encoding)
- awesome-rust - mrhooray/crc-rs - ci.org/mrhooray/crc-rs.svg?branch=master)](https://travis-ci.org/mrhooray/crc-rs) (Libraries / Encoding)
README
# crc
Rust implementation of CRC.
[![ci](https://github.com/mrhooray/crc-rs/actions/workflows/ci.yaml/badge.svg)](https://github.com/mrhooray/crc-rs/actions/workflows/ci.yaml)
[![Crate](https://img.shields.io/crates/v/crc.svg)](https://crates.io/crates/crc)
[![Docs](https://docs.rs/crc/badge.svg)](https://docs.rs/crc)
[![License](https://img.shields.io/crates/l/crc.svg?maxAge=2592000)](https://github.com/mrhooray/crc-rs#license)### Usage
Add `crc` to `Cargo.toml`
```toml
[dependencies]
crc = "3.0"
```### Examples
Using a well-known algorithm:
```rust
const X25: crc::Crc = crc::Crc::::new(&crc::CRC_16_IBM_SDLC);
assert_eq!(X25.checksum(b"123456789"), 0x906e);
```Using a custom algorithm:
```rust
const CUSTOM_ALG: crc::Algorithm = crc::Algorithm {
width: 16,
poly: 0x8005,
init: 0xffff,
refin: false,
refout: false,
xorout: 0x0000,
check: 0xaee7,
residue: 0x0000
};
let crc = crc::Crc::::new(&CUSTOM_ALG);
let mut digest = crc.digest();
digest.update(b"123456789");
assert_eq!(digest.finalize(), 0xaee7);
```### Minimum supported Rust version (MSRV)
This crate's MSRV is 1.56.
At a minimum, the MSRV will be <= the oldest stable release in the last 12 months. MSRV may be bumped in minor version releases.
### Lookup table flavors
This crate offers three flavors of lookup tables providing a tradeoff between computation speed and used memory.
See the benchmark section for hints, but do benchmarks on your target hardware to decide if the tradeoff is worth it to you.1. `NoTable` provides an implementation that uses no additional memory
2. `Bytewise` provides an implementation that uses a lookup table that uses 256 entries of the used width (e.g. for u32 thats 256 * 4 bytes)
3. `Slice16` provides an implementation that uses a lookup table that uses 16 * 256 entries of the used width (e.g. for u32 thats 16 * 256 * 4 bytes)These can be used by substituting `Crc` with e.g. `Crc>`. The flavor for `Crc` is chosen based on three crate features:
* no-table-mem-limit: Takes precedence over "bytewise-mem-limit" or "slice16-mem-limit"
* bytewise-mem-limit: Takes precedence over "slice16-mem-limit" and can be overridden by setting "no-table-mem-limit"
* slice16-mem-limit: Can be overridden by setting "bytewise-mem-limit" or "no-table-mem-limit"If no feature is selected, the `Bytewise` flavor is used.
Note that these tables can bloat your binary size if you precalculate them at compiletime (this happens in `Crc::new`).
Choosing a crate like oncecell or lazystatic to compute them once at runtime may be preferable where binary size is a concern.### Benchmark
`cargo bench` with AMD Ryzen 7 3800X ([comparison](http://create.stephan-brumme.com/crc32/)).
#### Throughput (GiB/s)
| Width | NoTable | Bytewise | Slice16 |
|-------|---------|----------|---------|
| 8 | 0.113 | 0.585 | 3.11 |
| 16 | 0.105 | 0.483 | 3.23 |
| 32 | 0.111 | 0.516 | 3.30 |
| 64 | 0.139 | 0.517 | 2.92 |
| 82 | 0.091 | 0.438 | 0.623 |### 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.