API Reference

Classes

class ssdeep.Hash[source]

Hashlib like object. It is only supported with ssdeep/libfuzzy >= 2.10.

Raises:
  • InternalError -- If lib returns internal error
  • NotImplementedError -- Required functions are not available
block_size

The block size used to calculate the hash. This depends on the length of the source string.

Returns:block size
copy()[source]

Create a copy of this hash object.

Returns:Return a copy of the hash object.
Return type:Hash
Raises:InternalError -- If the lib returns an internal error
digest(elimseq=False, notrunc=False)[source]

Obtain the fuzzy hash.

This operation does not change the state at all. It reports the hash for the concatenation of the data previously fed using update().

Returns:The fuzzy hash
Return type:String
Raises:InternalError -- If lib returns an internal error
name

The canonical name of this hash

Returns:ssdeep
update(buf, encoding='utf-8')[source]
Feed the data contained in the given buffer to the state.
Parameters:
  • buf (String|Byte) -- The data to be hashed
  • encoding (String) -- Encoding is used if buf is String
Raises:
  • InternalError -- If lib returns an internal error
  • TypeError -- If buf is not Bytes, String or Unicode
class ssdeep.PseudoHash[source]

Hashlib like object. Use this class only if Hash() isn't supported by your ssdeep/libfuzzy library. This class stores the provided data in memory, so be careful when hashing large files.

block_size

The block size used to calculate the hash. This depends on the length of the source string.

Returns:block size
copy()[source]

Create a copy of this hash object.

Returns:Return a copy of the hash object.
Return type:PseudoHash
Raises:InternalError -- If the lib returns an internal error
digest(elimseq=False, notrunc=False)[source]

Obtain the fuzzy hash.

This operation does not change the state at all. It reports the hash for the concatenation of the data previously fed using update().

Returns:The fuzzy hash
Return type:String
name

The canonical name of this hash

Returns:ssdeep
update(buf, encoding='utf-8')[source]
Feed the data contained in the given buffer to the state.
Parameters:
  • buf (String|Byte) -- The data to be hashed
  • encoding (String) -- Encoding is used if buf is String
Raises:

TypeError -- If buf is not Bytes, String or Unicode

Functions

ssdeep.compare(sig1, sig2)[source]

Computes the match score between two fuzzy hash signatures.

Returns a value from zero to 100 indicating the match score of the two signatures. A match score of zero indicates the signatures did not match.

Parameters:
  • sig1 (Bytes|String) -- First fuzzy hash signature
  • sig2 (Bytes|String) -- Second fuzzy hash signature
Returns:

Match score (0-100)

Return type:

Integer

Raises:
  • InternalError -- If lib returns an internal error
  • TypeError -- If sig is not String, Unicode or Bytes
ssdeep.hash(buf, encoding='utf-8')[source]

Compute the fuzzy hash of a buffer

Parameters:

buf (String|Bytes) -- The data to be fuzzy hashed

Returns:

The fuzzy hash

Return type:

String

Raises:
  • InternalError -- If lib returns an internal error
  • TypeError -- If buf is not String or Bytes
ssdeep.hash_from_file(filename)[source]

Compute the fuzzy hash of a file.

Opens, reads, and hashes the contents of the file 'filename'

Parameters:

filename (String|Bytes) -- The name of the file to be hashed

Returns:

The fuzzy hash of the file

Return type:

String

Raises:
  • IOError -- If Python is unable to read the file
  • InternalError -- If lib returns an internal error

Exceptions

exception ssdeep.BaseError[source]

The base for all other Exceptions

exception ssdeep.InternalError[source]

Raised if lib returns internal error