Skip to content

althonos/pruefung

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pruefung

Checksums in pure Rust.

TravisCI Codecov Source Crate Documentation CargoMake Changelog SayThanks

THIS LIBRARY DOES NOT PROVIDE A STABLE API YET !

Usage

Add this crate to the Cargo.toml:

[dependencies]
pruefung = "^0.1.0"

Check out the Sums section to see the minimal required version you need depending on the algorithm you wish to use.

All the checksums are implemented using the same logic as the hashes crate of the RustCrypto project, implementing the digest::Digest, and the core::hasher::Hasher traits when possible (less than 64 bits in the output).

Then, to compute a hash, for instance a CRC32 (Ethernet standard):

extern crate pruefung;
use std::hash::Hasher;

let mut hasher = pruefung::crc32::CRC32();   // Instantiate a hasher
let data = b"Hello, world !";

hasher.write(data);                          // Feed the hasher
hasher.write("String data".as_bytes());      // (possibly multiple times)

let hash = hasher.finish();                  // Consume the hasher
println!("Result: {:x}", hash)               // print the result as native hex

Dependencies

The crate itself is no_std, but provides digest::Digest implementations for convenience and integration with the hashes crate. Those bindings can be scrapped off however by disabling the default features of the crates, adding the following line to yout Cargo.toml:

[dependencies.pruefung]
version = "^0.1.0"
default-features = false

Sums

Latest version of the crate implements the following checksums:

Algorithm since implemented as
Adler32 0.1.0 ::adler32::Adler32
BSD checksum 0.2.0 ::bsd::Bsd
CRC8 0.3.0 ::crc::crc8::Crc8
CRC16 0.3.0 ::crc::crc8::Crc16
CRC32 0.2.0 ::crc::crc32::Crc32
CRC32C 0.2.0 ::crc::crc32::Crc32c
CRC64 0.3.0 ::crc::crc64::Crc64
Fletcher16 0.1.0 ::fletcher16::Fletcher16
FNV0-32 0.2.0 ::fnv::fnv32::Fnv32z
FNV1-32 0.2.0 ::fnv::fnv32::Fnv32
FNV1a-32 0.2.0 ::fnv::fnv32::Fnv32a
FNV0-64 0.2.0 ::fnv::fnv64::Fnv64z
FNV1-64 0.2.0 ::fnv::fnv64::Fnv64
FNV1a-64 0.2.0 ::fnv::fnv64::Fnv64a
SysV checksum 0.1.0 ::sysv::SysV
UNIX checksum 0.2.0 ::unix::Unix

These checksums are NOT cryptographically secure. They should not be used for something else than data validation against accidental modifications: an attacker could easily forge a file to pass any of these checksums ! For secure checksums, look at the hashes implemented by the RustCrypto team.

Credits

Why pruefung ?

I was in Switzerland when I started this project. Yet, I don't really speak german. But a slug version of zyklische-redundanzprüfung seemed like a nice name, instead of another checksum, cksum, checksums, crc, etc. crate.