• Stars
    star
    265
  • Rank 154,577 (Top 4 %)
  • Language
    Rust
  • License
    Apache License 2.0
  • Created about 6 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Fast, SIMD-accelerated CRC32 (IEEE) checksum computation in Rust

crc32fast Build Status Crates.io Documentation

Fast, SIMD-accelerated CRC32 (IEEE) checksum computation

Usage

Simple usage

For simple use-cases, you can call the hash convenience function to directly compute the CRC32 checksum for a given byte slice:

let checksum = crc32fast::hash(b"foo bar baz");

Advanced usage

For use-cases that require more flexibility or performance, for example when processing large amounts of data, you can create and manipulate a Hasher:

use crc32fast::Hasher;

let mut hasher = Hasher::new();
hasher.update(b"foo bar baz");
let checksum = hasher.finalize();

Performance

This crate contains multiple CRC32 implementations:

  • A fast baseline implementation which processes up to 16 bytes per iteration
  • An optimized implementation for modern x86 using sse and pclmulqdq instructions
  • An optimized implementation for aarch64 using crc32 instructions

Calling the Hasher::new constructor at runtime will perform a feature detection to select the most optimal implementation for the current CPU feature set.

crate version variant ns/iter MB/s
crc 1.8.1 n/a 4,926 207
crc32fast (this crate) 1.0.0 baseline 683 1499
crc32fast (this crate) 1.0.0 pclmulqdq 140 7314

Memory Safety

Due to the use of SIMD intrinsics for the optimized implementations, this crate contains some amount of unsafe code.

In order to ensure memory safety, the relevant code has been fuzz tested using afl.rs with millions of iterations in both debug and release build settings. You can inspect the test setup in the fuzz sub-directory, which also has instructions on how to run the tests yourself.

On top of that, every commit is tested using an address sanitizer in CI to catch any out of bounds memory accesses.

Even though neither fuzzing nor sanitization has revealed any safety bugs yet, please don't hesitate to file an issue if you run into any crashes or other unexpected behaviour.

Available feature flags

std (default: enabled)

This library supports being built without the Rust std library, which is useful for low-level use-cases such as embedded where no operating system is available. To build the crate in a no_std context, disable the default std feature.

Note: Because runtime CPU feature detection requires OS support, the specialized SIMD implementations will be unavailable when the std feature is disabled.

nightly (default: disabled)

This feature flag enables unstable features that are only available on the nightly channel. Keep in mind that when enabling this feature flag, you might experience breaking changes when updating compiler versions.

Currently, enabling this feature flag will make the optimized aarch64 implementation available.

License

This project is licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this project by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

More Repositories

1

rust-aws-lambda

Support for running Rust programs on AWS Lambda
Rust
319
star
2

rusha

High-performance pure-javascript SHA1 implementation suitable for large binary data, reaching up to half the native speed.
JavaScript
274
star
3

rust-tokio-retry

Extensible, asynchronous retry behaviours for futures/tokio
Rust
127
star
4

rust-plumbum

Conduit-like data processing library for Rust
Rust
55
star
5

rust-gob

serialization and deserialization for the gob binary format
Rust
29
star
6

rust-copperline

Pure-Rust Command Line Editing Library
Rust
27
star
7

rpdf

Rust
22
star
8

rust-gearhash

Fast, SIMD-accelerated hash function for content-defined chunking
Rust
21
star
9

hwsl2-haskell

Hashing with SL2 for Haskell
Haskell
14
star
10

rust-serde-schema

Rust
12
star
11

muject

10 sloc, β…› kb, no-bullshit dependency injection micro-library
JavaScript
12
star
12

rust-futures-backoff

Extensible, asynchronous retry behaviours
Rust
9
star
13

rust-semaphore

Atomic counting semaphore
Rust
7
star
14

rust-cfn

Type-safe representation for AWS CloudFormation templates
Rust
7
star
15

git-build

Build a git repository with a Dockerfile.
Go
6
star
16

clam-js

Control a ClamAV daemon over TCP or Unix Domain Sockets.
JavaScript
6
star
17

hwsl2-scala

Hashing with SL2 for Scala
Scala
6
star
18

hwsl2-core

Hashing with SL2
C
6
star
19

haskell-lambda-term-zipper

Functional Pearl: Environmentally Aware Zippers
Haskell
6
star
20

node-aff

Asynchronous effect system for TypeScript
TypeScript
5
star
21

rust-try-future

Convenient short-hand for returning early from `futures`-based functions
Rust
5
star
22

node-arbitrator

Generative property testing for JavaScript
JavaScript
4
star
23

rust-follow-redirects

Extension for hyper to follow HTTP redirects
Rust
4
star
24

haskell-ndjson-conduit

Conduit-based parsing and serialization for newline delimited JSON
Haskell
4
star
25

hwsl2-node

Hashing with SL2 for Node.js
C++
4
star
26

haskell-aws-dynamodb-conduit

Conduit-based interface for AWS DynamoDB
Haskell
3
star
27

node-clam-engine

Native bindings for the clamav engine
C++
3
star
28

rustretto

Rust
3
star
29

node-lcg

Seedable and Splittable (LCG) Random Number Generator
TypeScript
3
star
30

vim-colors-rusty

Rust-inspired color scheme for vim
Vim Script
3
star
31

rust-coyoneda

Functor composition via the Co-Yoneda Lemma
Rust
3
star
32

haskell-result

Encode success or at least one error
Haskell
2
star
33

rust-simdop

SIMD operations for Rust, with traits and pixiedust
Rust
2
star
34

statistics-hypergeometric-genvar

Random variate generation for hypergeometric distributions
Haskell
2
star
35

rust-functor

Rust
2
star
36

rust-comonoid

Comonoid trait for Rust.
Rust
2
star
37

node-kung-fu

Functional Standard Library with TypeScript support
TypeScript
2
star
38

haskell-free-concurrent

Free monads suitable for concurrent computation
Haskell
2
star
39

udp-stats-redis-adapter

Small performant frontend to redis, receiving minimal statistics data via udp messaging.
C
2
star
40

rust-tagged

PhantomData's partner in crime!
Rust
1
star
41

node-buffer-indexof-fast

Fast .indexOf for the Buffer data type
C++
1
star
42

backtape

A doctape client for the truly paranoid.
JavaScript
1
star
43

haskell-json-togo

Incremental conduit-based parsing of JSON documents.
Haskell
1
star
44

random-hypergeometric

Random variate generation from hypergeometric distributions
Haskell
1
star
45

node-resumable-hash

Serializable and deserializable hashing implementations
C++
1
star
46

rust-operational

Operational Monad for Rust
Rust
1
star
47

talks

1
star
48

rust-ot

Operational Transformations in Rust
Rust
1
star
49

haskell-attoparsec-trans

Interleaved effects for attoparsec parsers
Haskell
1
star
50

haskell-zipkin

Haskell
1
star
51

rijckit

Handwritten, low-level lexer for c-like languages. Still in early development.
C
1
star
52

rust-backtrace-parser

A zero-copy parser for Rust backtraces
Rust
1
star
53

node-redis-function

Run transpiled Javascript functions on the Redis scripting engine.
JavaScript
1
star