aboutsummaryrefslogtreecommitdiff
path: root/hash.c
diff options
context:
space:
mode:
authorPaul Selkirk <paul@psgd.org>2021-06-07 15:47:39 -0400
committerPaul Selkirk <paul@psgd.org>2021-06-07 15:47:39 -0400
commitd0d651241fd66d9d56addaf331d153b933134b06 (patch)
tree91133960a8b8cc0ad8f79b30845cccc8cd6af91e /hash.c
parent8ef2a4e5f54c8623c98c396e378ec093629b849b (diff)
Add mode bits for the various flavors of SHA-3, so that the softwaresha3_mode
driver doesn't have to know that the core's internal block size is actually 1600 bits.
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c25
1 files changed, 18 insertions, 7 deletions
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;