diff --git a/IDE/include.am b/IDE/include.am index ec6bcd532..5cb88e187 100644 --- a/IDE/include.am +++ b/IDE/include.am @@ -54,6 +54,7 @@ include IDE/MCUEXPRESSO/include.am include IDE/Espressif/include.am include IDE/STARCORE/include.am include IDE/MDK5-ARM/include.am +include IDE/SimplicityStudio/include.am EXTRA_DIST+= IDE/IAR-EWARM IDE/MDK-ARM IDE/MYSQL IDE/LPCXPRESSO IDE/HEXIWEAR IDE/Espressif EXTRA_DIST+= IDE/OPENSTM32/README.md diff --git a/wolfcrypt/src/port/silabs/silabs_hash.c b/wolfcrypt/src/port/silabs/silabs_hash.c index 46ff84a37..f0bb1110a 100644 --- a/wolfcrypt/src/port/silabs/silabs_hash.c +++ b/wolfcrypt/src/port/silabs/silabs_hash.c @@ -35,58 +35,52 @@ #include +static sl_se_hash_type_t wc_silabs_gethashtype(enum wc_HashType type) +{ + /* set init state */ + switch (type) { + case WC_HASH_TYPE_SHA: + return SL_SE_HASH_SHA1; + break; + case WC_HASH_TYPE_SHA224: + return SL_SE_HASH_SHA224; + break; + case WC_HASH_TYPE_SHA256: + return SL_SE_HASH_SHA256; +#ifdef WOLFSSL_SILABS_SHA384 + case WC_HASH_TYPE_SHA384: + return SL_SE_HASH_SHA384; +#endif +#ifdef WOLFSSL_SILABS_SHA512 + case WC_HASH_TYPE_SHA512: + return SL_SE_HASH_SHA512; +#endif + default: + break; + } + return SL_SE_HASH_NONE; +} + int wc_silabs_se_hash_init (wc_silabs_sha_t* sha, enum wc_HashType type) { int ret = 0; - sl_status_t rr; + sl_status_t rr; + sl_se_hash_type_t ht = wc_silabs_gethashtype(type); + + if (ht == SL_SE_HASH_NONE) { + return NOT_COMPILED_IN; + } /* set sizes and state */ XMEMSET(sha, 0, sizeof(wc_silabs_sha_t)); /* set init state */ - switch(type) { - case WC_HASH_TYPE_SHA: - rr = sl_se_hash_starts(&sha->hash_ctx, - &sha->cmd_ctx, - SL_SE_HASH_SHA1, - &sha->hash_type_ctx); - break; - case WC_HASH_TYPE_SHA224: - rr = sl_se_hash_starts(&sha->hash_ctx, - &sha->cmd_ctx, - SL_SE_HASH_SHA224, - &sha->hash_type_ctx); - break; - case WC_HASH_TYPE_SHA256: - rr = sl_se_hash_starts(&sha->hash_ctx, - &sha->cmd_ctx, - SL_SE_HASH_SHA256, - &sha->hash_type_ctx); - break; - -#ifdef WOLFSSL_SILABS_SHA384 - case WC_HASH_TYPE_SHA384: - rr = sl_se_hash_starts(&sha->hash_ctx, - &sha->cmd_ctx, - SL_SE_HASH_SHA384, - &sha->hash_type_ctx); - break; +#ifdef WOLFSSL_SILABS_SE_ACCEL_3 + rr = sl_se_hash_starts(&sha->hash_ctx, &sha->cmd_ctx, ht, + &sha->hash_type_ctx); +#else + rr = sl_se_hash_multipart_starts(&sha->hash_type_ctx, &sha->cmd_ctx, ht); #endif - -#ifdef WOLFSSL_SILABS_SHA512 - case WC_HASH_TYPE_SHA512: - rr = sl_se_hash_starts(&sha->hash_ctx, - &sha->cmd_ctx, - SL_SE_HASH_SHA512, - &sha->hash_type_ctx); - break; -#endif - - default: - ret = BAD_FUNC_ARG; - break; - } - if (rr != SL_STATUS_OK) { ret = WC_HW_E; } @@ -98,18 +92,31 @@ int wc_silabs_se_hash_update(wc_silabs_sha_t* sha, const byte* data, word32 len) { int ret = 0; - sl_status_t status = sl_se_hash_update(&sha->hash_ctx, data, len); + sl_status_t status; + +#ifdef WOLFSSL_SILABS_SE_ACCEL_3 + status = sl_se_hash_update(&sha->hash_ctx, data, len); +#else + status = sl_se_hash_multipart_update(&sha->hash_type_ctx, &sha->cmd_ctx, + data, len); +#endif if (status != SL_STATUS_OK) { ret = WC_HW_E; } return ret; } -int wc_silabs_se_hash_final(wc_silabs_sha_t* sha, byte* hash) +int wc_silabs_se_hash_final(wc_silabs_sha_t* sha, byte* hash, word32 len) { int ret = 0; - sl_status_t status = sl_se_hash_finish(&sha->hash_ctx, hash, - sha->hash_ctx.size); + sl_status_t status; + +#ifdef WOLFSSL_SILABS_SE_ACCEL_3 + status = sl_se_hash_finish(&sha->hash_ctx, hash, len); +#else + status = sl_se_hash_multipart_finish(&sha->hash_type_ctx, &sha->cmd_ctx, + hash, len); +#endif if (status != SL_STATUS_OK) { ret = WC_HW_E; } @@ -117,7 +124,7 @@ int wc_silabs_se_hash_final(wc_silabs_sha_t* sha, byte* hash) } -int wc_HashUpdate_ex(wc_silabs_sha_t* sha, const byte* data, word32 len) +static int wc_HashUpdate_ex(wc_silabs_sha_t* sha, const byte* data, word32 len) { int ret = 0; @@ -133,7 +140,7 @@ int wc_HashUpdate_ex(wc_silabs_sha_t* sha, const byte* data, word32 len) return ret; } -int wc_HashFinal_ex(wc_silabs_sha_t* sha, byte* hash) +static int wc_HashFinal_ex(wc_silabs_sha_t* sha, byte* hash, word32 len) { int ret = 0; @@ -143,7 +150,7 @@ int wc_HashFinal_ex(wc_silabs_sha_t* sha, byte* hash) ret = wolfSSL_CryptHwMutexLock(); if (ret == 0) { - ret = wc_silabs_se_hash_final(sha, hash); + ret = wc_silabs_se_hash_final(sha, hash, len); wolfSSL_CryptHwMutexUnLock(); } @@ -161,17 +168,17 @@ int wc_InitSha_ex(wc_Sha* sha, void* heap, int devId) (void)devId; (void)heap; - return wc_silabs_se_hash_init(&(sha->silabsCtx), WC_HASH_TYPE_SHA); + return wc_silabs_se_hash_init(&sha->silabsCtx, WC_HASH_TYPE_SHA); } int wc_ShaUpdate(wc_Sha* sha, const byte* data, word32 len) { - return wc_HashUpdate_ex(&(sha->silabsCtx), data, len); + return wc_HashUpdate_ex(&sha->silabsCtx, data, len); } int wc_ShaFinal(wc_Sha* sha, byte* hash) { - int ret = wc_HashFinal_ex(&(sha->silabsCtx), hash); + int ret = wc_HashFinal_ex(&sha->silabsCtx, hash, WC_SHA_DIGEST_SIZE); (void)wc_InitSha(sha); /* reset state */ @@ -190,18 +197,18 @@ int wc_InitSha256_ex(wc_Sha256* sha, void* heap, int devId) (void)devId; (void)heap; - return wc_silabs_se_hash_init(&(sha->silabsCtx), WC_HASH_TYPE_SHA256); + return wc_silabs_se_hash_init(&sha->silabsCtx, WC_HASH_TYPE_SHA256); } int wc_Sha256Update(wc_Sha256* sha, const byte* data, word32 len) { - return wc_HashUpdate_ex(&(sha->silabsCtx), data, len); + return wc_HashUpdate_ex(&sha->silabsCtx, data, len); } int wc_Sha256Final(wc_Sha256* sha, byte* hash) { - int ret = wc_HashFinal_ex(&(sha->silabsCtx), hash); + int ret = wc_HashFinal_ex(&sha->silabsCtx, hash, WC_SHA256_DIGEST_SIZE); (void)wc_InitSha256(sha); /* reset state */ @@ -219,18 +226,18 @@ int wc_InitSha224_ex(wc_Sha224* sha, void* heap, int devId) (void)devId; (void)heap; - return wc_silabs_se_hash_init(&(sha->silabsCtx), WC_HASH_TYPE_SHA224); + return wc_silabs_se_hash_init(&sha->silabsCtx, WC_HASH_TYPE_SHA224); } int wc_Sha224Update(wc_Sha224* sha, const byte* data, word32 len) { - return wc_HashUpdate_ex(&(sha->silabsCtx), data, len); + return wc_HashUpdate_ex(&sha->silabsCtx, data, len); } int wc_Sha224Final(wc_Sha224* sha, byte* hash) { - int ret = wc_HashFinal_ex(&(sha->silabsCtx), hash); + int ret = wc_HashFinal_ex(&sha->silabsCtx, hash, WC_SHA224_DIGEST_SIZE); (void)wc_InitSha224(sha); /* reset state */ @@ -248,18 +255,18 @@ int wc_InitSha384_ex(wc_Sha384* sha, void* heap, int devId) (void)devId; (void)heap; - return wc_silabs_se_hash_init(&(sha->silabsCtx), WC_HASH_TYPE_SHA384); + return wc_silabs_se_hash_init(&sha->silabsCtx, WC_HASH_TYPE_SHA384); } int wc_Sha384Update(wc_Sha384* sha, const byte* data, word32 len) { - return wc_HashUpdate_ex(&(sha->silabsCtx), data, len); + return wc_HashUpdate_ex(&sha->silabsCtx, data, len); } int wc_Sha384Final(wc_Sha384* sha, byte* hash) { - int ret = wc_HashFinal_ex(&(sha->silabsCtx), hash); + int ret = wc_HashFinal_ex(&sha->silabsCtx, hash, WC_SHA384_DIGEST_SIZE); (void)wc_InitSha384(sha); /* reset state */ @@ -277,18 +284,18 @@ int wc_InitSha512_ex(wc_Sha512* sha, void* heap, int devId) (void)devId; (void)heap; - return wc_silabs_se_hash_init(&(sha->silabsCtx), WC_HASH_TYPE_SHA512); + return wc_silabs_se_hash_init(&sha->silabsCtx, WC_HASH_TYPE_SHA512); } int wc_Sha512Update(wc_Sha512* sha, const byte* data, word32 len) { - return wc_HashUpdate_ex(&(sha->silabsCtx), data, len); + return wc_HashUpdate_ex(&sha->silabsCtx, data, len); } int wc_Sha512Final(wc_Sha512* sha, byte* hash) { - int ret = wc_HashFinal_ex(&(sha->silabsCtx), hash); + int ret = wc_HashFinal_ex(&sha->silabsCtx, hash, WC_SHA512_DIGEST_SIZE); (void)wc_InitSha512(sha); /* reset state */ diff --git a/wolfcrypt/src/sha.c b/wolfcrypt/src/sha.c index 4c560cc4b..40ab968f0 100644 --- a/wolfcrypt/src/sha.c +++ b/wolfcrypt/src/sha.c @@ -995,9 +995,9 @@ int wc_ShaCopy(wc_Sha* src, wc_Sha* dst) XMEMCPY(dst, src, sizeof(wc_Sha)); -#ifdef WOLFSSL_SILABS_SE_ACCEL - dst->silabsCtx.hash_ctx.cmd_ctx = &(dst->silabsCtx.cmd_ctx); - dst->silabsCtx.hash_ctx.hash_type_ctx = &(dst->silabsCtx.hash_type_ctx); +#if defined(WOLFSSL_SILABS_SE_ACCEL) && defined(WOLFSSL_SILABS_SE_ACCEL_3) + dst->silabsCtx.hash_ctx.cmd_ctx = &dst->silabsCtx.cmd_ctx; + dst->silabsCtx.hash_ctx.hash_type_ctx = &dst->silabsCtx.hash_type_ctx; #endif #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_SHA) diff --git a/wolfcrypt/src/sha256.c b/wolfcrypt/src/sha256.c index ffdd4019a..98c8d7594 100644 --- a/wolfcrypt/src/sha256.c +++ b/wolfcrypt/src/sha256.c @@ -1933,9 +1933,9 @@ int wc_Sha224_Grow(wc_Sha224* sha224, const byte* in, int inSz) dst->W = NULL; #endif - #ifdef WOLFSSL_SILABS_SE_ACCEL - dst->silabsCtx.hash_ctx.cmd_ctx = &(dst->silabsCtx.cmd_ctx); - dst->silabsCtx.hash_ctx.hash_type_ctx = &(dst->silabsCtx.hash_type_ctx); + #if defined(WOLFSSL_SILABS_SE_ACCEL) && defined(WOLFSSL_SILABS_SE_ACCEL_3) + dst->silabsCtx.hash_ctx.cmd_ctx = &dst->silabsCtx.cmd_ctx; + dst->silabsCtx.hash_ctx.hash_type_ctx = &dst->silabsCtx.hash_type_ctx; #endif #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_SHA224) @@ -2068,9 +2068,9 @@ int wc_Sha256Copy(wc_Sha256* src, wc_Sha256* dst) dst->W = NULL; #endif -#ifdef WOLFSSL_SILABS_SE_ACCEL - dst->silabsCtx.hash_ctx.cmd_ctx = &(dst->silabsCtx.cmd_ctx); - dst->silabsCtx.hash_ctx.hash_type_ctx = &(dst->silabsCtx.hash_type_ctx); +#if defined(WOLFSSL_SILABS_SE_ACCEL) && defined(WOLFSSL_SILABS_SE_ACCEL_3) + dst->silabsCtx.hash_ctx.cmd_ctx = &dst->silabsCtx.cmd_ctx; + dst->silabsCtx.hash_ctx.hash_type_ctx = &dst->silabsCtx.hash_type_ctx; #endif #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_SHA256) diff --git a/wolfcrypt/src/sha512.c b/wolfcrypt/src/sha512.c index 3d17a09b4..f4a9efa7f 100644 --- a/wolfcrypt/src/sha512.c +++ b/wolfcrypt/src/sha512.c @@ -1616,9 +1616,10 @@ int wc_Sha512Copy(wc_Sha512* src, wc_Sha512* dst) dst->W = NULL; #endif -#ifdef WOLFSSL_SILABS_SHA512 - dst->silabsCtx.hash_ctx.cmd_ctx = &(dst->silabsCtx.cmd_ctx); - dst->silabsCtx.hash_ctx.hash_type_ctx = &(dst->silabsCtx.hash_type_ctx); +#if defined(WOLFSSL_SILABS_SE_ACCEL) && defined(WOLFSSL_SILABS_SE_ACCEL_3) && \ + defined(WOLFSSL_SILABS_SHA512) + dst->silabsCtx.hash_ctx.cmd_ctx = &dst->silabsCtx.cmd_ctx; + dst->silabsCtx.hash_ctx.hash_type_ctx = &dst->silabsCtx.hash_type_ctx; #endif #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_SHA512) @@ -1867,9 +1868,10 @@ int wc_Sha384Copy(wc_Sha384* src, wc_Sha384* dst) dst->W = NULL; #endif -#ifdef WOLFSSL_SILABS_SHA384 - dst->silabsCtx.hash_ctx.cmd_ctx = &(dst->silabsCtx.cmd_ctx); - dst->silabsCtx.hash_ctx.hash_type_ctx = &(dst->silabsCtx.hash_type_ctx); +#if defined(WOLFSSL_SILABS_SE_ACCEL) && defined(WOLFSSL_SILABS_SE_ACCEL_3) && \ + defined(WOLFSSL_SILABS_SHA384) + dst->silabsCtx.hash_ctx.cmd_ctx = &dst->silabsCtx.cmd_ctx; + dst->silabsCtx.hash_ctx.hash_type_ctx = &dst->silabsCtx.hash_type_ctx; #endif #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_SHA384) diff --git a/wolfssl/wolfcrypt/port/silabs/silabs_hash.h b/wolfssl/wolfcrypt/port/silabs/silabs_hash.h index 6da76ac7a..de502a9ba 100644 --- a/wolfssl/wolfcrypt/port/silabs/silabs_hash.h +++ b/wolfssl/wolfcrypt/port/silabs/silabs_hash.h @@ -22,45 +22,75 @@ #ifndef _SILABS_HASH_H_ #define _SILABS_HASH_H_ -#include +#include #if defined(WOLFSSL_SILABS_SE_ACCEL) +#include + #include #include #include -#if defined(SL_SE_HASH_SHA384) && !defined(NO_SHA384) -#define WOLFSSL_SILABS_SHA384 +/* workaround to detect older Gecko SDK version 3 */ +#if !defined(WOLFSSL_SILABS_SE_ACCEL_3) && !defined(SL_SE_PRF_HMAC_SHA1) + /* Use streaming instead of new multipart */ + #define WOLFSSL_SILABS_SE_ACCEL_3 #endif -#if defined(SL_SE_HASH_SHA512) && !defined(NO_SHA384) -#define WOLFSSL_SILABS_SHA512 +/* Enable SHA2-2384 and SHA2-512 if HW supports and enabled */ +#if (_SILICON_LABS_SECURITY_FEATURE == _SILICON_LABS_SECURITY_FEATURE_VAULT) + #ifdef WOLFSSL_SHA384 + #define WOLFSSL_SILABS_SHA384 + #endif + #ifdef WOLFSSL_SHA512 + #define WOLFSSL_SILABS_SHA512 + #endif #endif +#ifdef WOLFSSL_SILABS_SE_ACCEL_3 +/* Gecko SDK v3 uses "streaming" interface */ typedef struct { - sl_se_hash_streaming_context_t hash_ctx; - sl_se_command_context_t cmd_ctx; - union hash_type_ctx_u { - sl_se_sha1_streaming_context_t sha1_ctx; - sl_se_sha224_streaming_context_t sha224_ctx; - sl_se_sha256_streaming_context_t sha256_ctx; -#ifdef WOLFSSL_SILABS_SHA384 - sl_se_sha384_streaming_context_t sha384_ctx; -#endif -#ifdef WOLFSSL_SILABS_SHA512 - sl_se_sha512_streaming_context_t sha512_ctx; -#endif - } hash_type_ctx; + sl_se_hash_streaming_context_t hash_ctx; + sl_se_command_context_t cmd_ctx; + union hash_type_ctx_u { + sl_se_sha1_streaming_context_t sha1_ctx; + sl_se_sha224_streaming_context_t sha224_ctx; + sl_se_sha256_streaming_context_t sha256_ctx; + #ifdef WOLFSSL_SILABS_SHA384 + sl_se_sha384_streaming_context_t sha384_ctx; + #endif + #ifdef WOLFSSL_SILABS_SHA512 + sl_se_sha512_streaming_context_t sha512_ctx; + #endif + } hash_type_ctx; } wc_silabs_sha_t; +#else +/* Gecko SDK v4 or later uses "multipart" interface */ +typedef struct { + sl_se_command_context_t cmd_ctx; + union hash_type_ctx_u { + sl_se_sha1_multipart_context_t sha1_ctx; + sl_se_sha224_multipart_context_t sha224_ctx; + sl_se_sha256_multipart_context_t sha256_ctx; + #ifdef WOLFSSL_SILABS_SHA384 + sl_se_sha384_multipart_context_t sha384_ctx; + #endif + #ifdef WOLFSSL_SILABS_SHA512 + sl_se_sha512_multipart_context_t sha512_ctx; + #endif + } hash_type_ctx; +} wc_silabs_sha_t; +#endif -int wc_silabs_se_hash_init (wc_silabs_sha_t* sha, enum wc_HashType type); -int wc_silabs_se_hash_update (wc_silabs_sha_t* sha, const byte* data, word32 len); -int wc_silabs_se_hash_final (wc_silabs_sha_t* sha, byte* hash); +int wc_silabs_se_hash_init(wc_silabs_sha_t* sha, enum wc_HashType type); +int wc_silabs_se_hash_update(wc_silabs_sha_t* sha, const byte* data, + word32 len); +int wc_silabs_se_hash_final(wc_silabs_sha_t* sha, byte* hash, word32 len); -#endif /* defined(WOLFSSL_SILABS_SE_ACCEL) */ +#endif /* WOLFSSL_SILABS_SE_ACCEL */ #endif /* _SILABS_HASH_H_ */