SHA wrappers¶
Digest¶
digest is a single operation equivalent to the following pseudo-code:
def digest(data: bytes) -> bytes:
    h = sha.init()
    h.update(data)
    return h.digest()
Naming convention¶
To test an implementation of digest, create a function with the following
name:
CC_<algorithm>_digest
Where algorithm is one of:
- SHA_1
- SHA_224,- SHA_256,- SHA_384,- SHA_512
- SHA_512_224,- SHA_512_256
- SHA_3_224,- SHA_3_256,- SHA_3_384,- SHA_3_512
Protocol¶
The function must implement the following protocol:
- 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 
 
 
Example¶
We use PyCryptodome for the wrapper example:
"""SHA wrapper example using PyCryptodome.
Usage:
    crypto-condor-cli test wrapper SHA sha_wrapper_example.py
"""
from Crypto.Hash import SHA3_384, SHA256, SHA512
def CC_SHA_256_digest(data: bytes) -> bytes:
    """Test SHA-256."""
    return SHA256.new(data).digest()
def CC_SHA_3_384_digest(data: bytes) -> bytes:
    """Test SHA3-384."""
    return SHA3_384.new(data).digest()
def CC_SHA_512_224_digest(data: bytes) -> bytes:
    """Test SHA-512/224."""
    return SHA512.new(data, "224").digest()