Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport 2.16: Fix build failure on gcc-11 #3925

Merged
merged 8 commits into from
Dec 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ChangeLog.d/bugfix_3782.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Bugfix
* Fix build failures on GCC 11. Fixes #3782.
2 changes: 1 addition & 1 deletion library/cmac.c
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ int mbedtls_cipher_cmac( const mbedtls_cipher_info_t *cipher_info,
*/
int mbedtls_aes_cmac_prf_128( const unsigned char *key, size_t key_length,
const unsigned char *input, size_t in_len,
unsigned char *output )
unsigned char output[16] )
{
int ret;
const mbedtls_cipher_info_t *cipher_info;
Expand Down
21 changes: 15 additions & 6 deletions library/ssl_tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ static void ssl_calc_finished_tls( mbedtls_ssl_context *, unsigned char *, int )
#if defined(MBEDTLS_SSL_PROTO_TLS1_2)
#if defined(MBEDTLS_SHA256_C)
static void ssl_update_checksum_sha256( mbedtls_ssl_context *, const unsigned char *, size_t );
static void ssl_calc_verify_tls_sha256( mbedtls_ssl_context *,unsigned char * );
static void ssl_calc_verify_tls_sha256( mbedtls_ssl_context *, unsigned char * );
static void ssl_calc_finished_tls_sha256( mbedtls_ssl_context *,unsigned char *, int );
#endif

Expand Down Expand Up @@ -1142,7 +1142,7 @@ int mbedtls_ssl_derive_keys( mbedtls_ssl_context *ssl )
}

#if defined(MBEDTLS_SSL_PROTO_SSL3)
void ssl_calc_verify_ssl( mbedtls_ssl_context *ssl, unsigned char hash[36] )
void ssl_calc_verify_ssl( mbedtls_ssl_context *ssl, unsigned char *hash )
{
mbedtls_md5_context md5;
mbedtls_sha1_context sha1;
Expand Down Expand Up @@ -1191,7 +1191,7 @@ void ssl_calc_verify_ssl( mbedtls_ssl_context *ssl, unsigned char hash[36] )
#endif /* MBEDTLS_SSL_PROTO_SSL3 */

#if defined(MBEDTLS_SSL_PROTO_TLS1) || defined(MBEDTLS_SSL_PROTO_TLS1_1)
void ssl_calc_verify_tls( mbedtls_ssl_context *ssl, unsigned char hash[36] )
void ssl_calc_verify_tls( mbedtls_ssl_context *ssl, unsigned char *hash )
{
mbedtls_md5_context md5;
mbedtls_sha1_context sha1;
Expand Down Expand Up @@ -1219,7 +1219,7 @@ void ssl_calc_verify_tls( mbedtls_ssl_context *ssl, unsigned char hash[36] )

#if defined(MBEDTLS_SSL_PROTO_TLS1_2)
#if defined(MBEDTLS_SHA256_C)
void ssl_calc_verify_tls_sha256( mbedtls_ssl_context *ssl, unsigned char hash[32] )
void ssl_calc_verify_tls_sha256( mbedtls_ssl_context *ssl, unsigned char *hash )
{
mbedtls_sha256_context sha256;

Expand All @@ -1240,7 +1240,7 @@ void ssl_calc_verify_tls_sha256( mbedtls_ssl_context *ssl, unsigned char hash[32
#endif /* MBEDTLS_SHA256_C */

#if defined(MBEDTLS_SHA512_C)
void ssl_calc_verify_tls_sha384( mbedtls_ssl_context *ssl, unsigned char hash[48] )
void ssl_calc_verify_tls_sha384( mbedtls_ssl_context *ssl, unsigned char *hash )
{
mbedtls_sha512_context sha512;

Expand Down Expand Up @@ -6363,13 +6363,22 @@ static void ssl_calc_finished_tls_sha256(
#endif /* MBEDTLS_SHA256_C */

#if defined(MBEDTLS_SHA512_C)

typedef int (*finish_sha384_t)(mbedtls_sha512_context*, unsigned char*);

static void ssl_calc_finished_tls_sha384(
mbedtls_ssl_context *ssl, unsigned char *buf, int from )
{
int len = 12;
const char *sender;
mbedtls_sha512_context sha512;
unsigned char padbuf[48];
/*
* For SHA-384, we can save 16 bytes by keeping padbuf 48 bytes long.
* However, to avoid stringop-overflow warning in gcc, we have to cast
* mbedtls_sha512_finish_ret().
*/
finish_sha384_t finish_sha384 = (finish_sha384_t)mbedtls_sha512_finish_ret;

mbedtls_ssl_session *session = ssl->session_negotiate;
if( !session )
Expand All @@ -6396,7 +6405,7 @@ static void ssl_calc_finished_tls_sha384(
? "client finished"
: "server finished";

mbedtls_sha512_finish_ret( &sha512, padbuf );
finish_sha384( &sha512, padbuf );

ssl->handshake->tls_prf( session->master, 48, sender,
padbuf, 48, buf, len );
Expand Down
2 changes: 1 addition & 1 deletion programs/test/selftest.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ static int calloc_self_test( int verbose )
}
#endif /* MBEDTLS_SELF_TEST */

static int test_snprintf( size_t n, const char ref_buf[10], int ref_ret )
static int test_snprintf( size_t n, const char *ref_buf, int ref_ret )
{
int ret;
char buf[10] = "xxxxxxxxx";
Expand Down
2 changes: 1 addition & 1 deletion tests/suites/host_test.function
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ static int convert_params( size_t cnt , char ** params , int * int_params_store
#if defined(__GNUC__)
__attribute__((__noinline__))
#endif
static int test_snprintf( size_t n, const char ref_buf[10], int ref_ret )
static int test_snprintf( size_t n, const char *ref_buf, int ref_ret )
{
int ret;
char buf[10] = "xxxxxxxxx";
Expand Down