SHA¶
How to use the crypto_condor.primitives.SHA module to test implementations of the
SHA-1, SHA-2, and SHA-3 families of hash functions.
Supported parameters¶
The supported algorithms are defined by the Algorithm enum.
- enum crypto_condor.primitives.SHA.Algorithm(value)¶
- Supported hash algorithms. - Member Type:
- str
 - Valid values are as follows: - SHA_1 = <Algorithm.SHA_1: 'SHA-1'>¶
 - SHA_224 = <Algorithm.SHA_224: 'SHA-224'>¶
 - SHA_256 = <Algorithm.SHA_256: 'SHA-256'>¶
 - SHA_384 = <Algorithm.SHA_384: 'SHA-384'>¶
 - SHA_512 = <Algorithm.SHA_512: 'SHA-512'>¶
 - SHA_512_224 = <Algorithm.SHA_512_224: 'SHA-512/224'>¶
 - SHA_512_256 = <Algorithm.SHA_512_256: 'SHA-512/256'>¶
 - SHA3_224 = <Algorithm.SHA3_224: 'SHA3-224'>¶
 - SHA3_256 = <Algorithm.SHA3_256: 'SHA3-256'>¶
 - SHA3_384 = <Algorithm.SHA3_384: 'SHA3-384'>¶
 - SHA3_512 = <Algorithm.SHA3_512: 'SHA3-512'>¶
 
Test an implementation directly¶
- crypto_condor.primitives.SHA.test(hash_function, hash_algorithm, *, compliance=True, resilience=False)¶
- Tests a SHA implementation. - Runs NIST test vectors on the given function. The function to test must conform to the - HashFunctionprotocol.- Parameters:
- hash_function (HashFunction) – The implementation to test. 
- hash_algorithm (Algorithm) – The hash algorithm implemented by - hash_function.
 
- Keyword Arguments:
- compliance – Whether to use compliance test vectors. 
- resilience – Whether to use resilience test vectors. 
 
- Returns:
- A dictionary of results. 
- Return type:
 - Changed in version 2025.03.12: Removed the - Orientationargument, added the- complianceand- resiliencekeywork arguments.- Deprecated since version 2025.03.12: Will be removed in a future version, use - test_digest()instead.
Test the output of an implementation¶
- crypto_condor.primitives.SHA.verify_file(filename, hash_algorithm)¶
- Verifies SHA hashes. - Tests hashes from a file. The file must follow the format described below. - Format:
- One set of arguments per line. 
- Lines are separated by newlines ( - \n).
- Lines that start with ‘#’ are counted as comments and ignored. 
- Arguments are written in hexadecimal and separated by slashes. 
- The order of arguments is: 
 - message/hash 
 - Parameters:
- filename (str) – Name of the file to test. 
- hash_algorithm (Algorithm) – Hash algorithm used to generate the hashes. 
 
- Returns:
- A dictionary of results. 
- Return type:
 - Changed in version 2025.03.12: Returns a - ResultsDictinstead of- Results.- Deprecated since version 2025.03.12: Will be removed in a future version, use - test_output_digest()instead.
Test a wrapper¶
- crypto_condor.primitives.SHA.test_wrapper(wrapper, compliance, resilience)¶
- Tests a SHA wrapper. - Calls the corresponding - test_wrapperfunction based on the wrapper’s extension.- Parameters:
- wrapper (Path) – A path to the wrapper to test. 
- compliance (bool) – Whether to use compliance test vectors. 
- resilience (bool) – Whether to use resilience test vectors. 
 
- Raises:
- FileNotFoundError – If the wrapper is not found. 
 - Added in version 2025.03.12: Replaces - run_wrapper.
- crypto_condor.primitives.SHA.test_wrapper_python(wrapper, compliance, resilience)¶
- Tests a Python SHA wrapper. - Parameters:
- wrapper (Path) – A path to the wrapper to test. 
- compliance (bool) – Whether to use compliance test vectors. 
- resilience (bool) – Whether to use resilience test vectors. 
 
 - Added in version 2025.03.12. 
Protocols¶
- protocol crypto_condor.primitives.SHA.HashFunction¶
- Represents a hash function. - Hash functions must behave like - __call__to be tested with this module.- Classes that implement this protocol must have the following methods / attributes: - __call__(data)¶
- Hashes the given data. - Parameters:
- data (bytes) – The input data. 
- Returns:
- The resulting hash. 
- Return type:
- bytes