Skip to content

Commit 843d5c1

Browse files
stevew817adbridge
authored andcommitted
Apply feedback from @RonEld
* Use _C flags at compile time in SHA to avoid compiling in unconfigured features * Don't define ECP_SHORTWEIERSTRASS since it is part of the application's configuration
1 parent 704a0dc commit 843d5c1

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

features/mbedtls/targets/TARGET_Silicon_Labs/crypto_sha.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
#include "mbedtls/sha1.h"
4141
#include "mbedtls/sha256.h"
4242

43-
#if defined(MBEDTLS_SHA256_ALT) || defined(MBEDTLS_SHA1_ALT)
43+
#if ( defined(MBEDTLS_SHA256_ALT) && defined(MBEDTLS_SHA256_C) ) || ( defined(MBEDTLS_SHA1_ALT) && defined (MBEDTLS_SHA1_C) )
4444

4545
#include "em_device.h"
4646

@@ -51,6 +51,7 @@
5151
#include "em_assert.h"
5252
#include <string.h>
5353

54+
#if defined(MBEDTLS_SHA1_C)
5455
static const uint32_t init_state_sha1[8] =
5556
{
5657
0x67452301UL,
@@ -62,7 +63,9 @@ static const uint32_t init_state_sha1[8] =
6263
0x0UL,
6364
0x0UL
6465
};
66+
#endif /* defined(MBEDTLS_SHA1_C) */
6567

68+
#if defined(MBEDTLS_SHA256_C)
6669
static const uint32_t init_state_sha256[8] =
6770
{
6871
0x6A09E667UL,
@@ -86,6 +89,7 @@ static const uint32_t init_state_sha224[8] =
8689
0x64F98FA7UL,
8790
0xBEFA4FA4UL
8891
};
92+
#endif /* defined(MBEDTLS_SHA256_C) */
8993

9094
static const unsigned char sha_padding[64] =
9195
{
@@ -96,8 +100,12 @@ static const unsigned char sha_padding[64] =
96100
};
97101

98102
typedef enum {
103+
#if defined(MBEDTLS_SHA1_C)
99104
CRYPTO_SHA1,
105+
#endif /* defined(MBEDTLS_SHA1_C) */
106+
#if defined(MBEDTLS_SHA256_C)
100107
CRYPTO_SHA2
108+
#endif /* defined(MBEDTLS_SHA256_C) */
101109
} crypto_sha_mode_t;
102110

103111
/*
@@ -131,12 +139,16 @@ static void crypto_sha_update_state( uint32_t state[8],
131139
CRYPTO_TypeDef *crypto = crypto_management_acquire();
132140

133141
switch ( mode ) {
142+
#if defined(MBEDTLS_SHA1_C)
134143
case CRYPTO_SHA1:
135144
crypto->CTRL = CRYPTO_CTRL_SHA_SHA1;
136145
break;
146+
#endif /* defined(MBEDTLS_SHA1_C) */
147+
#if defined(MBEDTLS_SHA256_C)
137148
case CRYPTO_SHA2:
138149
crypto->CTRL = CRYPTO_CTRL_SHA_SHA2;
139150
break;
151+
#endif /* defined(MBEDTLS_SHA256_C) */
140152
}
141153

142154
crypto->WAC = 0;
@@ -446,4 +458,4 @@ void mbedtls_sha1_process( mbedtls_sha1_context *ctx,
446458

447459
#endif /* #if defined(CRYPTO_PRESENT) */
448460

449-
#endif /* #if defined(MBEDTLS_SHA256_ALT) || defined(MBEDTLS_SHA1_ALT) */
461+
#endif /* #if ( defined(MBEDTLS_SHA256_ALT) && defined(MBEDTLS_SHA256_C) ) || ( defined(MBEDTLS_SHA1_ALT) && defined (MBEDTLS_SHA1_C) ) */

features/mbedtls/targets/TARGET_Silicon_Labs/mbedtls_device.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
#define MBEDTLS_AES_ALT
3030

3131
#define MBEDTLS_ECP_INTERNAL_ALT
32-
#define ECP_SHORTWEIERSTRASS
3332
#define MBEDTLS_ECP_ADD_MIXED_ALT
3433
#define MBEDTLS_ECP_DOUBLE_JAC_ALT
3534
#define MBEDTLS_ECP_NORMALIZE_JAC_MANY_ALT

0 commit comments

Comments
 (0)