SHAKE

How to use the crypto_condor.primitives.SHAKE module to test implementations of SHAKE128 and SHAKE256.

Test an implementation

crypto_condor.primitives.SHAKE.test_digest(
xof,
algorithm,
orientation=Orientation.BYTE,
*,
compliance=True,
resilience=False,
)

Tests a SHAKE implementation.

Parameters:
  • xof (Xof) – The function to test.

  • algorithm (Algorithm) – The algorithm of the XOF to test.

  • orientation (Orientation) – The orientation of the implementation, either bit- or byte-oriented. Byte-oriented by default.

Keyword Arguments:
  • compliance – Whether to use compliance test vectors.

  • resilience – Whether to use resilience test vectors.

Returns:

A dictionary of results.

Return type:

ResultsDict

Example

Let’s test hashlib.shake_128:

>>> from crypto_condor.primitives import SHAKE
>>> from hashlib import shake_128

To return the digest, shake_128 requires a call to its digest method so we wrap it in our own function to implement the Xof protocol.

>>> def my_shake128(data: bytes, output_length: int) -> bytes:
...     h = shake_128(data)
...     return h.digest(output_length)

Now we test this implementation.

>>> res = SHAKE.test_digest(my_shake128, SHAKE.Algorithm.SHAKE128)
[SHAKE128][NIST CAVP] ...
>>> assert res.check()

Added in version 2025.02.13.

crypto_condor.primitives.SHAKE.test_output_digest(output, algorithm)

Tests the output of a SHAKE implementation.

Parameters:
  • output (Path) – A path to the output file.

  • algorithm (Algorithm) – The algorithm to test.

Returns:

A dictionary of results.

Return type:

ResultsDict

Format:
  • One line per operation, separated by newlines \n.

  • Lines starting with # are considered comments and ignored.

  • Values are written in hexadecimal.

  • Values are separated by forward slashes /.

  • The order of the values is:

msg/out
Where:
  • msg is the input message to hash.

  • out is the result.

Added in version 2025.02.13.

crypto_condor.primitives.SHAKE.test(
xof,
algorithm,
orientation=Orientation.BYTE,
*,
compliance=True,
resilience=False,
)

Tests a SHAKE implementation.

Parameters:
  • xof (Xof) – The function to test.

  • algorithm (Algorithm) – The algorithm of the XOF to test.

  • orientation (Orientation) – The orientation of the implementation, either bit- or byte-oriented. Byte-oriented by default.

Keyword Arguments:
  • compliance – Whether to use compliance test vectors.

  • resilience – Whether to use resilience test vectors.

Returns:

A dictionary of results.

Return type:

ResultsDict

Deprecated since version 2025.02.13: Will be removed in a future version, use test_digest() instead.

Parameters

This module can test implementations of both SHAKE128 and SHAKE256, as indicated by the Algorithm enum.

Implementations can be either bit- or byte-oriented. To select an orientation use the Orientation enum.

enum crypto_condor.primitives.SHAKE.Algorithm(value)

Supported extensible output functions.

Member Type:

str

Valid values are as follows:

SHAKE128 = <Algorithm.SHAKE128: 'SHAKE128'>
SHAKE256 = <Algorithm.SHAKE256: 'SHAKE256'>
enum crypto_condor.primitives.SHAKE.Orientation(value)

Orientation of the implementation.

Member Type:

str

Valid values are as follows:

BIT = <Orientation.BIT: 'bit'>
BYTE = <Orientation.BYTE: 'byte'>

Protocols

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

Run a wrapper

crypto_condor.primitives.SHAKE.run_python_wrapper(wrapper, compliance, resilience)

Runs the Python SHAKE wrapper.

Parameters:
  • wrapper (Path) – A path to wrapper to run.

  • compliance (bool) – Whether to use compliance test vectors.

  • resilience (bool) – Whether to use resilience test vectors.