SHAKE wrappers¶
Digest¶
digest
is a single operation equivalent to:
h = SHAKE.init()
h.update(some_data)
h.digest(length) # or h.finalize() or h.squeeze()
Naming convention¶
To test a function that implements digest
, create a function with one of the
following names:
CC_SHAKE_128_digest
CC_SHAKE_256_digest
Protocol¶
The function must implement the following protocol:
- protocol crypto_condor.primitives.SHAKE.Xof
Represents a XOF.
XOFs must behave like
__call__
to be tested with this module.Classes that implement this protocol must have the following methods / attributes:
- __call__(data, output_length)
Produces digests of any desired length.
- Parameters:
data (bytes) – The input data.
output_length (int) – The desired length of the digest in bytes.
- Returns:
The digest of the desired length.
- Return type:
bytes
Example¶
We use PyCryptodome for the wrapper example:
"""Wrapper template for SHAKE implementations.
Usage:
crypto-condor-cli test wrapper SHAKE shake_wrapper_example.py
"""
from Crypto.Hash import SHAKE128, SHAKE256
def CC_SHAKE_128_digest(data: bytes, output_length: int) -> bytes:
"""Hashes with SHAKE128."""
return SHAKE128.new(data).read(output_length)
def CC_SHAKE_256_digest(data: bytes, output_length: int) -> bytes:
"""Hashes with SHAKE256."""
return SHAKE256.new(data).read(output_length)