From d0d651241fd66d9d56addaf331d153b933134b06 Mon Sep 17 00:00:00 2001 From: Paul Selkirk Date: Mon, 7 Jun 2021 15:47:39 -0400 Subject: Add mode bits for the various flavors of SHA-3, so that the software driver doesn't have to know that the core's internal block size is actually 1600 bits. --- hash.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'hash.c') diff --git a/hash.c b/hash.c index 06227af..527c095 100644 --- a/hash.c +++ b/hash.c @@ -176,8 +176,20 @@ static const hal_hash_driver_t sha512_driver = { SHA512_LENGTH_LEN, SHA512_ADDR_BLOCK, SHA512_ADDR_DIGEST, SHA512_MODE_SHA_512, sw_hash_core_sha512, sizeof(uint64_t) }; -static const hal_hash_driver_t sha3_driver = { - SHA3_LENGTH_LEN, SHA3_ADDR_BLOCK, SHA3_ADDR_DIGEST, 0, NULL, 0 +static const hal_hash_driver_t sha3_224_driver = { + SHA3_LENGTH_LEN, SHA3_ADDR_BLOCK, SHA3_ADDR_DIGEST, SHA3_MODE_SHA3_224, NULL, 0 +}; + +static const hal_hash_driver_t sha3_256_driver = { + SHA3_LENGTH_LEN, SHA3_ADDR_BLOCK, SHA3_ADDR_DIGEST, SHA3_MODE_SHA3_256, NULL, 0 +}; + +static const hal_hash_driver_t sha3_384_driver = { + SHA3_LENGTH_LEN, SHA3_ADDR_BLOCK, SHA3_ADDR_DIGEST, SHA3_MODE_SHA3_384, NULL, 0 +}; + +static const hal_hash_driver_t sha3_512_driver = { + SHA3_LENGTH_LEN, SHA3_ADDR_BLOCK, SHA3_ADDR_DIGEST, SHA3_MODE_SHA3_512, NULL, 0 }; /* @@ -275,7 +287,7 @@ const hal_hash_descriptor_t hal_hash_sha3_224[1] = {{ SHA3_224_BLOCK_LEN, SHA3_224_DIGEST_LEN, SHA3_STATE_LEN, sizeof(hal_hash_state_t), sizeof(hal_hmac_state_t), dalgid_sha3_224, sizeof(dalgid_sha3_224), - &sha3_driver, SHA3_NAME, 1 + &sha3_224_driver, SHA3_NAME, 1 }}; const hal_hash_descriptor_t hal_hash_sha3_256[1] = {{ @@ -283,7 +295,7 @@ const hal_hash_descriptor_t hal_hash_sha3_256[1] = {{ SHA3_256_BLOCK_LEN, SHA3_256_DIGEST_LEN, SHA3_STATE_LEN, sizeof(hal_hash_state_t), sizeof(hal_hmac_state_t), dalgid_sha3_256, sizeof(dalgid_sha3_256), - &sha3_driver, SHA3_NAME, 1 + &sha3_256_driver, SHA3_NAME, 1 }}; const hal_hash_descriptor_t hal_hash_sha3_384[1] = {{ @@ -291,7 +303,7 @@ const hal_hash_descriptor_t hal_hash_sha3_384[1] = {{ SHA3_384_BLOCK_LEN, SHA3_384_DIGEST_LEN, SHA3_STATE_LEN, sizeof(hal_hash_state_t), sizeof(hal_hmac_state_t), dalgid_sha3_384, sizeof(dalgid_sha3_384), - &sha3_driver, SHA3_NAME, 1 + &sha3_384_driver, SHA3_NAME, 1 }}; const hal_hash_descriptor_t hal_hash_sha3_512[1] = {{ @@ -299,7 +311,7 @@ const hal_hash_descriptor_t hal_hash_sha3_512[1] = {{ SHA3_512_BLOCK_LEN, SHA3_512_DIGEST_LEN, SHA3_STATE_LEN, sizeof(hal_hash_state_t), sizeof(hal_hmac_state_t), dalgid_sha3_512, sizeof(dalgid_sha3_512), - &sha3_driver, SHA3_NAME, 1 + &sha3_512_driver, SHA3_NAME, 1 }}; static inline int is_sha3(hal_hash_state_t *state) @@ -611,7 +623,6 @@ static hal_error_t hash_write_block(hal_hash_state_t * const state) return err; if ((err = hal_io_write(state->core, state->driver->block_addr, state->block, - is_sha3(state) ? state->descriptor->state_length : state->descriptor->block_length)) != HAL_OK) return err; -- cgit v1.2.3