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:
 - Example - Let’s test hashlib.shake_128: - >>> from crypto_condor.primitives import SHAKE >>> from hashlib import shake_128 - To return the digest, - shake_128requires a call to its- digestmethod so we wrap it in our own function to implement the- Xofprotocol.- >>> 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.03.12. 
- 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:
 - 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:
- msgis the input message to hash.
- outis the result.
 
 
 - Added in version 2025.03.12. 
- 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:
 - Deprecated since version 2025.03.12: 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.
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.