Skip to content

Commit d596ca8

Browse files
committed
Fix GCC warning in ssl_calc_finished_tls_sha384
This commit fixes the same warning fixed by baeedbf, but without wasting RAM. By casting `mbedtls_sha512_finish_ret()`, `padbuf` could be kept 48 bytes long without triggering any warnings. Signed-off-by: Rodrigo Dias Correa <rodrigo@correas.us>
1 parent 683028a commit d596ca8

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

library/ssl_tls.c

+11-2
Original file line numberDiff line numberDiff line change
@@ -3197,12 +3197,15 @@ static void ssl_calc_finished_tls_sha256(
31973197
#endif /* MBEDTLS_SHA256_C */
31983198

31993199
#if defined(MBEDTLS_SHA512_C)
3200+
3201+
typedef int (*finish_sha384_t)(mbedtls_sha512_context*, unsigned char[48]);
3202+
32003203
static void ssl_calc_finished_tls_sha384(
32013204
mbedtls_ssl_context *ssl, unsigned char *buf, int from )
32023205
{
32033206
int len = 12;
32043207
const char *sender;
3205-
unsigned char padbuf[64];
3208+
unsigned char padbuf[48];
32063209
#if defined(MBEDTLS_USE_PSA_CRYPTO)
32073210
size_t hash_size;
32083211
psa_hash_operation_t sha384_psa = PSA_HASH_OPERATION_INIT;
@@ -3255,8 +3258,14 @@ static void ssl_calc_finished_tls_sha384(
32553258
MBEDTLS_SSL_DEBUG_BUF( 4, "finished sha512 state", (unsigned char *)
32563259
sha512.state, sizeof( sha512.state ) );
32573260
#endif
3261+
/*
3262+
* For SHA-384, we can save 16 bytes by keeping padbuf 48 bytes long.
3263+
* However, to avoid stringop-overflow warning in gcc, we have to cast
3264+
* mbedtls_sha512_finish_ret().
3265+
*/
3266+
finish_sha384_t finish = (finish_sha384_t)mbedtls_sha512_finish_ret;
3267+
finish( &sha512, padbuf );
32583268

3259-
mbedtls_sha512_finish_ret( &sha512, padbuf );
32603269
mbedtls_sha512_free( &sha512 );
32613270
#endif
32623271

0 commit comments

Comments
 (0)