aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--hal_internal.h2
-rw-r--r--hash.c25
-rw-r--r--verilog_constants.h5
3 files changed, 24 insertions, 8 deletions
diff --git a/hal_internal.h b/hal_internal.h
index d757027..1724807 100644
--- a/hal_internal.h
+++ b/hal_internal.h
@@ -156,7 +156,7 @@ extern hal_error_t hal_free_static_memory(const void * const ptr);
* Longest hash block and digest we support at the moment.
*/
-#define HAL_MAX_HASH_BLOCK_LENGTH SHA3_STATE_LEN
+#define HAL_MAX_HASH_BLOCK_LENGTH SHA3_224_BLOCK_LEN
#define HAL_MAX_HASH_DIGEST_LENGTH SHA3_512_DIGEST_LEN
#define HAL_MAX_HASH_STATE_LENGTH SHA3_STATE_LEN
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;
diff --git a/verilog_constants.h b/verilog_constants.h
index 8db5e29..80ff27d 100644
--- a/verilog_constants.h
+++ b/verilog_constants.h
@@ -102,6 +102,11 @@
#define SHA3_256_DIGEST_LEN bitsToBytes(256)
#define SHA3_384_DIGEST_LEN bitsToBytes(384)
#define SHA3_512_DIGEST_LEN bitsToBytes(512)
+#define SHA3_MODE_SHA3_224 (0 << 2)
+#define SHA3_MODE_SHA3_256 (1 << 2)
+#define SHA3_MODE_SHA3_384 (2 << 2)
+#define SHA3_MODE_SHA3_512 (3 << 2)
+#define SHA3_MODE_MASK (3 << 2)
/*
* RNG cores.