From ecf259579a52eaf748a46a6d0e83cf147c3791dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikolai=20G=C3=BCtschow?= Date: Thu, 21 Dec 2023 13:49:01 +0100 Subject: [PATCH] sys/psa_crypto: support for SHA-{384,512-{224,256}} --- features.yaml | 6 + makefiles/features_existing.inc.mk | 3 + makefiles/features_modules.inc.mk | 3 + makefiles/pseudomodules.inc.mk | 3 + sys/hashes/psa_riot_hashes/sha_384.c | 47 +++++++ sys/hashes/psa_riot_hashes/sha_512_224.c | 47 +++++++ sys/hashes/psa_riot_hashes/sha_512_256.c | 47 +++++++ sys/include/hashes/psa/riot_hashes.h | 18 +++ sys/include/psa_crypto/psa/crypto_contexts.h | 9 ++ sys/include/psa_crypto/psa/crypto_includes.h | 8 +- sys/psa_crypto/Makefile.dep | 73 ++++++++++ sys/psa_crypto/Makefile.include | 36 +++++ sys/psa_crypto/doc.txt | 23 +++- sys/psa_crypto/include/psa_hashes.h | 127 +++++++++++++++++- .../psa_crypto_algorithm_dispatch.c | 48 +++++++ 15 files changed, 490 insertions(+), 8 deletions(-) create mode 100644 sys/hashes/psa_riot_hashes/sha_384.c create mode 100644 sys/hashes/psa_riot_hashes/sha_512_224.c create mode 100644 sys/hashes/psa_riot_hashes/sha_512_256.c diff --git a/features.yaml b/features.yaml index 5608438a4d..2acf51145c 100644 --- a/features.yaml +++ b/features.yaml @@ -835,8 +835,14 @@ groups: help: SHA-224 hardware acceleration present. - name: periph_hash_sha_256 help: SHA-256 hardware acceleration present. + - name: periph_hash_sha_384 + help: SHA-384 hardware acceleration present. - name: periph_hash_sha_512 help: SHA-512 hardware acceleration present. + - name: periph_hash_sha_512_224 + help: SHA-512/224 hardware acceleration present. + - name: periph_hash_sha_512_256 + help: SHA-512/256 hardware acceleration present. - name: periph_hmac_sha_256 help: HMAC SHA-256 hardware acceleration present. - name: periph_hwrng diff --git a/makefiles/features_existing.inc.mk b/makefiles/features_existing.inc.mk index 17c6a8cc1e..efa9453602 100644 --- a/makefiles/features_existing.inc.mk +++ b/makefiles/features_existing.inc.mk @@ -182,7 +182,10 @@ FEATURES_EXISTING := \ periph_hash_sha_1 \ periph_hash_sha_224 \ periph_hash_sha_256 \ + periph_hash_sha_384 \ periph_hash_sha_512 \ + periph_hash_sha_512_224 \ + periph_hash_sha_512_256 \ periph_hmac_sha_256 \ periph_hwrng \ periph_i2c \ diff --git a/makefiles/features_modules.inc.mk b/makefiles/features_modules.inc.mk index 49bd2b9ccb..3b999311d2 100644 --- a/makefiles/features_modules.inc.mk +++ b/makefiles/features_modules.inc.mk @@ -29,7 +29,10 @@ PERIPH_IGNORE_MODULES := \ periph_hash_sha_1 \ periph_hash_sha_224 \ periph_hash_sha_256 \ + periph_hash_sha_384 \ periph_hash_sha_512 \ + periph_hash_sha_512_224 \ + periph_hash_sha_512_256 \ periph_hmac_sha_256 \ periph_i2c_hw \ periph_i2c_sw \ diff --git a/makefiles/pseudomodules.inc.mk b/makefiles/pseudomodules.inc.mk index a59b3cb89e..b87ee1c964 100644 --- a/makefiles/pseudomodules.inc.mk +++ b/makefiles/pseudomodules.inc.mk @@ -361,7 +361,10 @@ PSEUDOMODULES += psa_riot_hashes_md5 PSEUDOMODULES += psa_riot_hashes_sha_1 PSEUDOMODULES += psa_riot_hashes_sha_224 PSEUDOMODULES += psa_riot_hashes_sha_256 +PSEUDOMODULES += psa_riot_hashes_sha_384 PSEUDOMODULES += psa_riot_hashes_sha_512 +PSEUDOMODULES += psa_riot_hashes_sha_512_224 +PSEUDOMODULES += psa_riot_hashes_sha_512_256 PSEUDOMODULES += psa_riot_hashes_hmac_sha256 PSEUDOMODULES += fortuna_reseed PSEUDOMODULES += riotboot_% diff --git a/sys/hashes/psa_riot_hashes/sha_384.c b/sys/hashes/psa_riot_hashes/sha_384.c new file mode 100644 index 0000000000..6e3cf870cc --- /dev/null +++ b/sys/hashes/psa_riot_hashes/sha_384.c @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2023 TU Dresden + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup sys_psa_crypto + * @{ + * + * @brief Glue code translating between PSA Crypto and the RIOT Hash module + * + * @author Mikolai Gütschow + * + * @} + */ + +#include "psa/crypto.h" +#include "hashes/psa/riot_hashes.h" + +psa_status_t psa_hashes_sha384_setup(psa_hashes_sha384_ctx_t *ctx) +{ + sha384_init((sha384_context_t *)ctx); + return PSA_SUCCESS; +} + +psa_status_t psa_hashes_sha384_update(psa_hashes_sha384_ctx_t *ctx, + const uint8_t *input, + size_t input_length) +{ + sha384_update((sha384_context_t *)ctx, input, input_length); + return PSA_SUCCESS; +} + +psa_status_t psa_hashes_sha384_finish(psa_hashes_sha384_ctx_t *ctx, + uint8_t *hash, + size_t hash_size, + size_t *hash_length) +{ + sha384_final((sha384_context_t *)ctx, hash); + + (void)hash_size; + (void)hash_length; + return PSA_SUCCESS; +} diff --git a/sys/hashes/psa_riot_hashes/sha_512_224.c b/sys/hashes/psa_riot_hashes/sha_512_224.c new file mode 100644 index 0000000000..33b561fdce --- /dev/null +++ b/sys/hashes/psa_riot_hashes/sha_512_224.c @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2023 TU Dresden + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup sys_psa_crypto + * @{ + * + * @brief Glue code translating between PSA Crypto and the RIOT Hash module + * + * @author Mikolai Gütschow + * + * @} + */ + +#include "psa/crypto.h" +#include "hashes/psa/riot_hashes.h" + +psa_status_t psa_hashes_sha512_224_setup(psa_hashes_sha512_224_ctx_t *ctx) +{ + sha512_224_init((sha512_224_context_t *)ctx); + return PSA_SUCCESS; +} + +psa_status_t psa_hashes_sha512_224_update(psa_hashes_sha512_224_ctx_t *ctx, + const uint8_t *input, + size_t input_length) +{ + sha512_224_update((sha512_224_context_t *)ctx, input, input_length); + return PSA_SUCCESS; +} + +psa_status_t psa_hashes_sha512_224_finish(psa_hashes_sha512_224_ctx_t *ctx, + uint8_t *hash, + size_t hash_size, + size_t *hash_length) +{ + sha512_224_final((sha512_224_context_t *)ctx, hash); + + (void)hash_size; + (void)hash_length; + return PSA_SUCCESS; +} diff --git a/sys/hashes/psa_riot_hashes/sha_512_256.c b/sys/hashes/psa_riot_hashes/sha_512_256.c new file mode 100644 index 0000000000..2ef17f792e --- /dev/null +++ b/sys/hashes/psa_riot_hashes/sha_512_256.c @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2023 TU Dresden + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup sys_psa_crypto + * @{ + * + * @brief Glue code translating between PSA Crypto and the RIOT Hash module + * + * @author Mikolai Gütschow + * + * @} + */ + +#include "psa/crypto.h" +#include "hashes/psa/riot_hashes.h" + +psa_status_t psa_hashes_sha512_256_setup(psa_hashes_sha512_256_ctx_t *ctx) +{ + sha512_256_init((sha512_256_context_t *)ctx); + return PSA_SUCCESS; +} + +psa_status_t psa_hashes_sha512_256_update(psa_hashes_sha512_256_ctx_t *ctx, + const uint8_t *input, + size_t input_length) +{ + sha512_256_update((sha512_256_context_t *)ctx, input, input_length); + return PSA_SUCCESS; +} + +psa_status_t psa_hashes_sha512_256_finish(psa_hashes_sha512_256_ctx_t *ctx, + uint8_t *hash, + size_t hash_size, + size_t *hash_length) +{ + sha512_256_final((sha512_256_context_t *)ctx, hash); + + (void)hash_size; + (void)hash_length; + return PSA_SUCCESS; +} diff --git a/sys/include/hashes/psa/riot_hashes.h b/sys/include/hashes/psa/riot_hashes.h index 73de39a854..b5754c48ed 100644 --- a/sys/include/hashes/psa/riot_hashes.h +++ b/sys/include/hashes/psa/riot_hashes.h @@ -49,12 +49,30 @@ typedef sha224_context_t psa_hashes_sha224_ctx_t; typedef sha256_context_t psa_hashes_sha256_ctx_t; #endif +#if (IS_USED(MODULE_PSA_RIOT_HASHES_SHA_384)) +#include "hashes/sha384.h" + +typedef sha384_context_t psa_hashes_sha384_ctx_t; +#endif + #if (IS_USED(MODULE_PSA_RIOT_HASHES_SHA_512)) #include "hashes/sha512.h" typedef sha512_context_t psa_hashes_sha512_ctx_t; #endif +#if (IS_USED(MODULE_PSA_RIOT_HASHES_SHA_512_224)) +#include "hashes/sha512_224.h" + +typedef sha512_224_context_t psa_hashes_sha512_224_ctx_t; +#endif + +#if (IS_USED(MODULE_PSA_RIOT_HASHES_SHA_512_256)) +#include "hashes/sha512_256.h" + +typedef sha512_256_context_t psa_hashes_sha512_256_ctx_t; +#endif + #if (IS_USED(MODULE_PSA_RIOT_HASHES_HMAC_SHA256)) #include "hashes/sha256.h" #endif diff --git a/sys/include/psa_crypto/psa/crypto_contexts.h b/sys/include/psa_crypto/psa/crypto_contexts.h index 246116316a..e0bafb0d40 100644 --- a/sys/include/psa_crypto/psa/crypto_contexts.h +++ b/sys/include/psa_crypto/psa/crypto_contexts.h @@ -46,9 +46,18 @@ typedef union { #if IS_USED(MODULE_PSA_HASH_SHA_256) || defined(DOXYGEN) psa_hashes_sha256_ctx_t sha256; /**< SHA-256 context */ #endif +#if IS_USED(MODULE_PSA_HASH_SHA_384) || defined(DOXYGEN) + psa_hashes_sha384_ctx_t sha384; /**< SHA-384 context */ +#endif #if IS_USED(MODULE_PSA_HASH_SHA_512) || defined(DOXYGEN) psa_hashes_sha512_ctx_t sha512; /**< SHA-512 context */ #endif +#if IS_USED(MODULE_PSA_HASH_SHA_512_224) || defined(DOXYGEN) + psa_hashes_sha512_224_ctx_t sha512_224; /**< SHA-512/224 context */ +#endif +#if IS_USED(MODULE_PSA_HASH_SHA_512_256) || defined(DOXYGEN) + psa_hashes_sha512_256_ctx_t sha512_256; /**< SHA-512/256 context */ +#endif } psa_hash_context_t; #endif diff --git a/sys/include/psa_crypto/psa/crypto_includes.h b/sys/include/psa_crypto/psa/crypto_includes.h index 011e41ff12..b7360c9fd2 100644 --- a/sys/include/psa_crypto/psa/crypto_includes.h +++ b/sys/include/psa_crypto/psa/crypto_includes.h @@ -31,7 +31,9 @@ extern "C" { #if IS_USED(MODULE_PSA_RIOT_HASHES_HMAC_SHA256) || IS_USED(MODULE_PSA_RIOT_HASHES_MD5) || \ IS_USED(MODULE_PSA_RIOT_HASHES_SHA_1) || IS_USED(MODULE_PSA_RIOT_HASHES_SHA_224) || \ - IS_USED(MODULE_PSA_RIOT_HASHES_SHA_256) || IS_USED(MODULE_PSA_RIOT_HASHES_SHA_512) + IS_USED(MODULE_PSA_RIOT_HASHES_SHA_256) || IS_USED(MODULE_PSA_RIOT_HASHES_SHA_384) || \ + IS_USED(MODULE_PSA_RIOT_HASHES_SHA_512) || IS_USED(MODULE_PSA_RIOT_HASHES_SHA_512_224) || \ + IS_USED(MODULE_PSA_RIOT_HASHES_SHA_512_256) #include "hashes/psa/riot_hashes.h" #endif @@ -40,7 +42,9 @@ extern "C" { #endif #if IS_USED(MODULE_PERIPH_HASH_SHA_1) || IS_USED(MODULE_PERIPH_HASH_SHA_224) || \ - IS_USED(MODULE_PERIPH_HASH_SHA_256) || IS_USED(MODULE_PERIPH_HASH_SHA_512) + IS_USED(MODULE_PERIPH_HASH_SHA_256) || IS_USED(MODULE_PERIPH_HASH_SHA_384) || \ + IS_USED(MODULE_PERIPH_HASH_SHA_512) || IS_USED(MODULE_PERIPH_HASH_SHA_512_224) || \ + IS_USED(MODULE_PERIPH_HASH_SHA_512_256) #include "psa_periph_hashes_ctx.h" #endif diff --git a/sys/psa_crypto/Makefile.dep b/sys/psa_crypto/Makefile.dep index a46fc0c7e3..2bb76124b1 100644 --- a/sys/psa_crypto/Makefile.dep +++ b/sys/psa_crypto/Makefile.dep @@ -228,6 +228,30 @@ ifneq (,$(filter psa_hash_sha_256_backend_riot,$(USEMODULE))) USEMODULE += psa_riot_hashes_sha_256 endif +## SHA-384 +ifneq (,$(filter psa_hash_sha_384,$(USEMODULE))) + ifeq (,$(filter psa_hash_sha_384_custom_backend,$(USEMODULE))) + FEATURES_OPTIONAL += periph_hash_sha_384 + include $(RIOTMAKE)/features_check.inc.mk + # HACK: Due to kconfig migration, may cause problems + ifneq (,$(filter periph_hash_sha_384,$(FEATURES_USED))) + USEMODULE += psa_hash_sha_384_backend_periph + else + USEMODULE += psa_hash_sha_384_backend_riot + endif + endif +endif + +ifneq (,$(filter psa_hash_sha_384_backend_periph,$(USEMODULE))) + FEATURES_REQUIRED += periph_hash_sha_384 +endif + +ifneq (,$(filter psa_hash_sha_384_backend_riot,$(USEMODULE))) + USEMODULE += hashes + USEMODULE += psa_riot_hashes + USEMODULE += psa_riot_hashes_sha_384 +endif + ## SHA-512 ifneq (,$(filter psa_hash_sha_512,$(USEMODULE))) ifeq (,$(filter psa_hash_sha_512_custom_backend,$(USEMODULE))) @@ -251,6 +275,55 @@ ifneq (,$(filter psa_hash_sha_512_backend_riot,$(USEMODULE))) USEMODULE += psa_riot_hashes USEMODULE += psa_riot_hashes_sha_512 endif + +## SHA-512/224 +ifneq (,$(filter psa_hash_sha_512_224,$(USEMODULE))) + ifeq (,$(filter psa_hash_sha_512_224_custom_backend,$(USEMODULE))) + FEATURES_OPTIONAL += periph_hash_sha_512_224 + include $(RIOTMAKE)/features_check.inc.mk + # HACK: Due to kconfig migration, may cause problems + ifneq (,$(filter periph_hash_sha_512_224,$(FEATURES_USED))) + USEMODULE += psa_hash_sha_512_224_backend_periph + else + USEMODULE += psa_hash_sha_512_224_backend_riot + endif + endif +endif + +ifneq (,$(filter psa_hash_sha_512_224_backend_periph,$(USEMODULE))) + FEATURES_REQUIRED += periph_hash_sha_512_224 +endif + +ifneq (,$(filter psa_hash_sha_512_224_backend_riot,$(USEMODULE))) + USEMODULE += hashes + USEMODULE += psa_riot_hashes + USEMODULE += psa_riot_hashes_sha_512_224 +endif + +## SHA-512/256 +ifneq (,$(filter psa_hash_sha_512_256,$(USEMODULE))) + ifeq (,$(filter psa_hash_sha_512_256_custom_backend,$(USEMODULE))) + FEATURES_OPTIONAL += periph_hash_sha_512_256 + include $(RIOTMAKE)/features_check.inc.mk + # HACK: Due to kconfig migration, may cause problems + ifneq (,$(filter periph_hash_sha_512_256,$(FEATURES_USED))) + USEMODULE += psa_hash_sha_512_256_backend_periph + else + USEMODULE += psa_hash_sha_512_256_backend_riot + endif + endif +endif + +ifneq (,$(filter psa_hash_sha_512_256_backend_periph,$(USEMODULE))) + FEATURES_REQUIRED += periph_hash_sha_512_256 +endif + +ifneq (,$(filter psa_hash_sha_512_256_backend_riot,$(USEMODULE))) + USEMODULE += hashes + USEMODULE += psa_riot_hashes + USEMODULE += psa_riot_hashes_sha_512_256 +endif + # Key Management ifneq (,$(filter psa_key_management,$(USEMODULE))) USEMODULE += psa_key_slot_mgmt diff --git a/sys/psa_crypto/Makefile.include b/sys/psa_crypto/Makefile.include index 569eff42bc..d7ba3521d7 100644 --- a/sys/psa_crypto/Makefile.include +++ b/sys/psa_crypto/Makefile.include @@ -134,6 +134,18 @@ ifneq (,$(filter psa_hash_sha_256,$(USEMODULE))) endif endif +PSEUDOMODULES += psa_hash_sha_384 +PSEUDOMODULES += psa_hash_sha_384_backend_periph +PSEUDOMODULES += psa_hash_sha_384_backend_riot +PSEUDOMODULES += psa_hash_sha_384_custom_backend + +# check that one and only one backend has been selected +ifneq (,$(filter psa_hash_sha_384,$(USEMODULE))) + ifneq (1,$(call backends,psa_hash_sha_384)) + $(error "One (and only one) backend should be selected for psa_hash_sha_384") + endif +endif + PSEUDOMODULES += psa_hash_sha_512 PSEUDOMODULES += psa_hash_sha_512_backend_periph PSEUDOMODULES += psa_hash_sha_512_backend_riot @@ -146,6 +158,30 @@ ifneq (,$(filter psa_hash_sha_512,$(USEMODULE))) endif endif +PSEUDOMODULES += psa_hash_sha_512_224 +PSEUDOMODULES += psa_hash_sha_512_224_backend_periph +PSEUDOMODULES += psa_hash_sha_512_224_backend_riot +PSEUDOMODULES += psa_hash_sha_512_224_custom_backend + +# check that one and only one backend has been selected +ifneq (,$(filter psa_hash_sha_512_224,$(USEMODULE))) + ifneq (1,$(call backends,psa_hash_sha_512_224)) + $(error "One (and only one) backend should be selected for psa_hash_sha_512_224") + endif +endif + +PSEUDOMODULES += psa_hash_sha_512_256 +PSEUDOMODULES += psa_hash_sha_512_256_backend_periph +PSEUDOMODULES += psa_hash_sha_512_256_backend_riot +PSEUDOMODULES += psa_hash_sha_512_256_custom_backend + +# check that one and only one backend has been selected +ifneq (,$(filter psa_hash_sha_512_256,$(USEMODULE))) + ifneq (1,$(call backends,psa_hash_sha_512_256)) + $(error "One (and only one) backend should be selected for psa_hash_sha_512_256") + endif +endif + ## Key Management PSEUDOMODULES += psa_key_management diff --git a/sys/psa_crypto/doc.txt b/sys/psa_crypto/doc.txt index 63111d2bff..ec2e40b09d 100644 --- a/sys/psa_crypto/doc.txt +++ b/sys/psa_crypto/doc.txt @@ -312,12 +312,30 @@ * - psa_hash_sha_256_custom_backend * - psa_hash_sha_256_backend_riot * + * #### SHA 384 + * - psa_hash_sha_384 + * - psa_hash_sha_384_backend_periph + * - psa_hash_sha_384_custom_backend + * - psa_hash_sha_384_backend_riot + * * #### SHA 512 * - psa_hash_sha_512 * - psa_hash_sha_512_backend_periph * - psa_hash_sha_512_custom_backend * - psa_hash_sha_512_backend_riot * + * #### SHA 512/224 + * - psa_hash_sha_512_224 + * - psa_hash_sha_512_224_backend_periph + * - psa_hash_sha_512_224_custom_backend + * - psa_hash_sha_512_224_backend_riot + * + * #### SHA 512/256 + * - psa_hash_sha_512_256 + * - psa_hash_sha_512_256_backend_periph + * - psa_hash_sha_512_256_custom_backend + * - psa_hash_sha_512_256_backend_riot + * * ### MAC * - Base: psa_mac * @@ -469,7 +487,7 @@ * USEMODULE += psa_riot_hashes_sha_256 * * will build the file at `sys/hashes/psa_riot_hashes/sha_256.c`, but none of the other files in - * the directory). + * the directory. * * To enable submodules for your implementation add the following to the directory makefile: * @code @@ -568,7 +586,10 @@ * - `psa_hashes_sha1_ctx_t` * - `psa_hashes_sha224_ctx_t` * - `psa_hashes_sha256_ctx_t` + * - `psa_hashes_sha384_ctx_t` * - `psa_hashes_sha512_ctx_t` + * - `psa_hashes_sha512_224_ctx_t` + * - `psa_hashes_sha512_256_ctx_t` * * #### Ciphers * - `psa_cipher_aes_128_ctx_t` diff --git a/sys/psa_crypto/include/psa_hashes.h b/sys/psa_crypto/include/psa_hashes.h index 98a7f23867..f30c1df987 100644 --- a/sys/psa_crypto/include/psa_hashes.h +++ b/sys/psa_crypto/include/psa_hashes.h @@ -66,7 +66,7 @@ psa_status_t psa_hashes_md5_finish(psa_hashes_md5_ctx_t *ctx, uint8_t *hash, size_t hash_size, size_t *hash_length); -#endif /* CONFIG_HASHES_MD5 */ +#endif /* MODULE_PSA_HASH_MD5 */ #if IS_USED(MODULE_PSA_HASH_SHA_1) || defined(DOXYGEN) /** @@ -105,7 +105,7 @@ psa_status_t psa_hashes_sha1_finish(psa_hashes_sha1_ctx_t *ctx, uint8_t *hash, size_t hash_size, size_t *hash_length); -#endif /* CONFIG_HASHES_SHA1 */ +#endif /* MODULE_PSA_HASH_SHA_1 */ #if IS_USED(MODULE_PSA_HASH_SHA_224) || defined(DOXYGEN) /** @@ -144,7 +144,7 @@ psa_status_t psa_hashes_sha224_finish(psa_hashes_sha224_ctx_t *ctx, uint8_t *hash, size_t hash_size, size_t *hash_length); -#endif /* CONFIG_HASHES_SHA224 */ +#endif /* MODULE_PSA_HASH_SHA_224 */ #if IS_USED(MODULE_PSA_HASH_SHA_256) || defined(DOXYGEN) /** @@ -183,7 +183,46 @@ psa_status_t psa_hashes_sha256_finish(psa_hashes_sha256_ctx_t *ctx, uint8_t *hash, size_t hash_size, size_t *hash_length); -#endif /* CONFIG_HASHES_SHA256 */ +#endif /* MODULE_PSA_HASH_SHA_256 */ + +#if IS_USED(MODULE_PSA_HASH_SHA_384) || defined(DOXYGEN) +/** + * @brief Low level wrapper function to call a driver for an SHA384 hash setup + * See @ref psa_hash_setup() + * + * @param ctx + * @return psa_status_t + */ +psa_status_t psa_hashes_sha384_setup(psa_hashes_sha384_ctx_t *ctx); + +/** + * @brief Low level wrapper function to call a driver for an SHA384 hash update + * See @ref psa_hash_update() + * + * @param ctx + * @param input + * @param input_length + * @return psa_status_t + */ +psa_status_t psa_hashes_sha384_update(psa_hashes_sha384_ctx_t *ctx, + const uint8_t *input, + size_t input_length); + +/** + * @brief Low level wrapper function to call a driver for an SHA384 hash finish + * See @ref psa_hash_finish() + * + * @param ctx + * @param hash + * @param hash_size + * @param hash_length + * @return psa_status_t + */ +psa_status_t psa_hashes_sha384_finish(psa_hashes_sha384_ctx_t *ctx, + uint8_t *hash, + size_t hash_size, + size_t *hash_length); +#endif /* MODULE_PSA_HASH_SHA_384 */ #if IS_USED(MODULE_PSA_HASH_SHA_512) || defined(DOXYGEN) /** @@ -222,7 +261,85 @@ psa_status_t psa_hashes_sha512_finish(psa_hashes_sha512_ctx_t *ctx, uint8_t *hash, size_t hash_size, size_t *hash_length); -#endif /* CONFIG_HASHES_SHA512 */ +#endif /* MODULE_PSA_HASH_SHA_512 */ + +#if IS_USED(MODULE_PSA_HASH_SHA_512_224) || defined(DOXYGEN) +/** + * @brief Low level wrapper function to call a driver for an SHA512/224 hash setup + * See @ref psa_hash_setup() + * + * @param ctx + * @return psa_status_t + */ +psa_status_t psa_hashes_sha512_224_setup(psa_hashes_sha512_224_ctx_t *ctx); + +/** + * @brief Low level wrapper function to call a driver for an SHA512/224 hash update + * See @ref psa_hash_update() + * + * @param ctx + * @param input + * @param input_length + * @return psa_status_t + */ +psa_status_t psa_hashes_sha512_224_update(psa_hashes_sha512_224_ctx_t *ctx, + const uint8_t *input, + size_t input_length); + +/** + * @brief Low level wrapper function to call a driver for an SHA512/224 hash finish + * See @ref psa_hash_finish() + * + * @param ctx + * @param hash + * @param hash_size + * @param hash_length + * @return psa_status_t + */ +psa_status_t psa_hashes_sha512_224_finish(psa_hashes_sha512_224_ctx_t *ctx, + uint8_t *hash, + size_t hash_size, + size_t *hash_length); +#endif /* MODULE_PSA_HASH_SHA_512_224 */ + +#if IS_USED(MODULE_PSA_HASH_SHA_512_256) || defined(DOXYGEN) +/** + * @brief Low level wrapper function to call a driver for an SHA512/256 hash setup + * See @ref psa_hash_setup() + * + * @param ctx + * @return psa_status_t + */ +psa_status_t psa_hashes_sha512_256_setup(psa_hashes_sha512_256_ctx_t *ctx); + +/** + * @brief Low level wrapper function to call a driver for an SHA512/256 hash update + * See @ref psa_hash_update() + * + * @param ctx + * @param input + * @param input_length + * @return psa_status_t + */ +psa_status_t psa_hashes_sha512_256_update(psa_hashes_sha512_256_ctx_t *ctx, + const uint8_t *input, + size_t input_length); + +/** + * @brief Low level wrapper function to call a driver for an SHA512/256 hash finish + * See @ref psa_hash_finish() + * + * @param ctx + * @param hash + * @param hash_size + * @param hash_length + * @return psa_status_t + */ +psa_status_t psa_hashes_sha512_256_finish(psa_hashes_sha512_256_ctx_t *ctx, + uint8_t *hash, + size_t hash_size, + size_t *hash_length); +#endif /* MODULE_PSA_HASH_SHA_512_256 */ #ifdef __cplusplus } diff --git a/sys/psa_crypto/psa_crypto_algorithm_dispatch.c b/sys/psa_crypto/psa_crypto_algorithm_dispatch.c index 46cfbb58d5..064a2ba46b 100644 --- a/sys/psa_crypto/psa_crypto_algorithm_dispatch.c +++ b/sys/psa_crypto/psa_crypto_algorithm_dispatch.c @@ -81,6 +81,14 @@ psa_status_t psa_algorithm_dispatch_hash_setup(psa_hash_operation_t *operation, } break; #endif + #if (IS_USED(MODULE_PSA_HASH_SHA_384)) + case PSA_ALG_SHA_384: + status = psa_hashes_sha384_setup(&operation->ctx.sha384); + if (status != PSA_SUCCESS) { + return status; + } + break; + #endif #if (IS_USED(MODULE_PSA_HASH_SHA_512)) case PSA_ALG_SHA_512: status = psa_hashes_sha512_setup(&operation->ctx.sha512); @@ -89,6 +97,22 @@ psa_status_t psa_algorithm_dispatch_hash_setup(psa_hash_operation_t *operation, } break; #endif + #if (IS_USED(MODULE_PSA_HASH_SHA_512_224)) + case PSA_ALG_SHA_512_224: + status = psa_hashes_sha512_224_setup(&operation->ctx.sha512_224); + if (status != PSA_SUCCESS) { + return status; + } + break; + #endif + #if (IS_USED(MODULE_PSA_HASH_SHA_512_256)) + case PSA_ALG_SHA_512_256: + status = psa_hashes_sha512_256_setup(&operation->ctx.sha512_256); + if (status != PSA_SUCCESS) { + return status; + } + break; + #endif default: (void)status; (void)operation; @@ -120,10 +144,22 @@ psa_status_t psa_algorithm_dispatch_hash_update(psa_hash_operation_t *operation, case PSA_ALG_SHA_256: return psa_hashes_sha256_update(&operation->ctx.sha256, input, input_length); #endif + #if (IS_USED(MODULE_PSA_HASH_SHA_384)) + case PSA_ALG_SHA_384: + return psa_hashes_sha384_update(&operation->ctx.sha384, input, input_length); + #endif #if (IS_USED(MODULE_PSA_HASH_SHA_512)) case PSA_ALG_SHA_512: return psa_hashes_sha512_update(&operation->ctx.sha512, input, input_length); #endif + #if (IS_USED(MODULE_PSA_HASH_SHA_512_224)) + case PSA_ALG_SHA_512_224: + return psa_hashes_sha512_224_update(&operation->ctx.sha512_224, input, input_length); + #endif + #if (IS_USED(MODULE_PSA_HASH_SHA_512_256)) + case PSA_ALG_SHA_512_256: + return psa_hashes_sha512_256_update(&operation->ctx.sha512_256, input, input_length); + #endif default: (void)operation; (void)input; @@ -154,10 +190,22 @@ psa_status_t psa_algorithm_dispatch_hash_finish(psa_hash_operation_t *operation, case PSA_ALG_SHA_256: return psa_hashes_sha256_finish(&operation->ctx.sha256, hash, hash_size, hash_length); #endif + #if (IS_USED(MODULE_PSA_HASH_SHA_384)) + case PSA_ALG_SHA_384: + return psa_hashes_sha384_finish(&operation->ctx.sha384, hash, hash_size, hash_length); + #endif #if (IS_USED(MODULE_PSA_HASH_SHA_512)) case PSA_ALG_SHA_512: return psa_hashes_sha512_finish(&operation->ctx.sha512, hash, hash_size, hash_length); #endif + #if (IS_USED(MODULE_PSA_HASH_SHA_512_224)) + case PSA_ALG_SHA_512_224: + return psa_hashes_sha512_224_finish(&operation->ctx.sha512_224, hash, hash_size, hash_length); + #endif + #if (IS_USED(MODULE_PSA_HASH_SHA_512_256)) + case PSA_ALG_SHA_512_256: + return psa_hashes_sha512_256_finish(&operation->ctx.sha512_256, hash, hash_size, hash_length); + #endif default: (void)operation; (void)hash;