Keccak¶
Keccak is a family of cryptographic hash algorithms that won the SHA-3 competition organized by NIST. What eventually became SHA-3 (FIPS 202) is a slight variant: though incompatible to Keccak, the security principles and margins remain the same.
If you are interested in writing SHA-3 compliant code, you must use
the modules Crypto.Hash.SHA3_224
,
Crypto.Hash.SHA3_256
, Crypto.Hash.SHA3_384
or Crypto.Hash.SHA3_512
.
This module implements the Keccak hash functions for the 64 bit word
length (b=1600
) and the fixed digest sizes of 224, 256, 384 and 512 bits.
This is an example:
>>> from Crypto.Hash import keccak
>>>
>>> keccak_hash = keccak.new(digest_bits=512)
>>> keccak_hash.update(b'Some data')
>>> print keccak_hash.hexdigest()
-
class
Crypto.Hash.keccak.
Keccak_Hash
(data, digest_bytes, update_after_digest)¶ A Keccak hash object. Do not instantiate directly. Use the
new()
function.Variables: digest_size (integer) – the size in bytes of the resulting hash -
digest
()¶ Return the binary (non-printable) digest of the message that has been hashed so far.
Returns: The hash digest, computed over the data processed so far. Binary form. Return type: byte string
-
hexdigest
()¶ Return the printable digest of the message that has been hashed so far.
Returns: The hash digest, computed over the data processed so far. Hexadecimal encoded. Return type: string
-
new
(**kwargs)¶ Create a fresh Keccak hash object.
-
update
(data)¶ Continue hashing of a message by consuming the next chunk of data.
Parameters: data (byte string/byte array/memoryview) – The next chunk of the message being hashed.
-
-
Crypto.Hash.keccak.
new
(**kwargs)¶ Create a new hash object.
Parameters: - data (bytes/bytearray/memoryview) – The very first chunk of the message to hash.
It is equivalent to an early call to
Keccak_Hash.update()
. - digest_bytes (integer) – The size of the digest, in bytes (28, 32, 48, 64).
- digest_bits (integer) – The size of the digest, in bits (224, 256, 384, 512).
- update_after_digest (boolean) – Whether
Keccak.digest()
can be followed by anotherKeccak.update()
(default:False
).
Return: A
Keccak_Hash
hash object- data (bytes/bytearray/memoryview) – The very first chunk of the message to hash.
It is equivalent to an early call to