Crate ssdeep

source ·
Expand description

A Rust wrapper for ssdeep by Jesse Kornblum, which is a C library for computing context triggered piecewise hashes (CTPH). Also called fuzzy hashes, CTPH can match inputs that have homologies. Such inputs have sequences of identical bytes in the same order, although bytes in between these sequences may be different in both content and length. In contrast to standard hashing algorithms, CTPH can be used to identify files that are highly similar but not identical.

Usage

To compute the fuzzy hash of the given bytes, use hash():

extern crate ssdeep;

let h = ssdeep::hash(b"Hello there!").unwrap();
assert_eq!(h, "3:aNRn:aNRn");

To obtain the fuzzy hash of the contents of a file, use hash_from_file():

let h = ssdeep::hash_from_file("tests/file.txt").unwrap();

To compare two fuzzy hashes, use compare(), which returns an integer between 0 (no match) and 100:

let h1 = "3:AXGBicFlgVNhBGcL6wCrFQEv:AXGHsNhxLsr2C";
let h2 = "3:AXGBicFlIHBGcL6wCrFQEv:AXGH6xLsr2Cx";
let score = ssdeep::compare(h1, h2).unwrap();
assert_eq!(score, 22);

Each of these functions returns a Result, where an error is returned when the underlying C function fails.

Enums

  • An enum containing errors that the library might return.

Functions

  • Computes the match score between two fuzzy hashes.
  • Computes the fuzzy hash of bytes.
  • Computes the fuzzy hash of the contents of a file.

Type Aliases

  • The result type used by the library.