From c3c479537eb06cf2e0e7b5b48558800d1d002edf Mon Sep 17 00:00:00 2001 From: wyhong <30567533+wy-hh@users.noreply.github.com> Date: Thu, 3 Aug 2023 13:17:55 +0800 Subject: [PATCH] Add macro to set alignment of sha256 context (#28426) --- src/crypto/CHIPCryptoPAL.h | 2 +- src/lib/core/CHIPConfig.h | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/crypto/CHIPCryptoPAL.h b/src/crypto/CHIPCryptoPAL.h index 88abc189b5b06f..65511668b1d5fd 100644 --- a/src/crypto/CHIPCryptoPAL.h +++ b/src/crypto/CHIPCryptoPAL.h @@ -803,7 +803,7 @@ CHIP_ERROR Hash_SHA1(const uint8_t * data, size_t data_length, uint8_t * out_buf * All implementations must check for std::is_trivially_copyable. **/ -struct alignas(size_t) HashSHA256OpaqueContext +struct alignas(CHIP_CONFIG_SHA256_CONTEXT_ALIGN) HashSHA256OpaqueContext { uint8_t mOpaque[kMAX_Hash_SHA256_Context_Size]; }; diff --git a/src/lib/core/CHIPConfig.h b/src/lib/core/CHIPConfig.h index 80b3d18cfe410f..2aba0915a2d52d 100644 --- a/src/lib/core/CHIPConfig.h +++ b/src/lib/core/CHIPConfig.h @@ -185,6 +185,15 @@ #define CHIP_CONFIG_SHA256_CONTEXT_SIZE ((sizeof(unsigned int) * (8 + 2 + 16 + 2)) + sizeof(uint64_t)) #endif // CHIP_CONFIG_SHA256_CONTEXT_SIZE +/** + * @def CHIP_CONFIG_SHA256_CONTEXT_ALIGN + * + * @brief The alignment of SHA256 context buffer. + */ +#ifndef CHIP_CONFIG_SHA256_CONTEXT_ALIGN +#define CHIP_CONFIG_SHA256_CONTEXT_ALIGN size_t +#endif // CHIP_CONFIG_SHA256_CONTEXT_ALIGN + /** * @def CHIP_CONFIG_MAX_UNSOLICITED_MESSAGE_HANDLERS *