Skip to content

Commit a42457d

Browse files
authored
Merge pull request #3015 from andresag01/update_mbedtls_rc
Update to mbed TLS release candidate
2 parents 08ff689 + 2ff5400 commit a42457d

22 files changed

+290
-127
lines changed

features/mbedtls/VERSION.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
a592dcc1c6277bb191269e709cdd3d5593e593ed
1+
8e004104020dd4328434e8a207245b0327bbb9b1

features/mbedtls/inc/mbedtls/cmac.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ extern "C" {
4444
*/
4545
struct mbedtls_cmac_context_t
4646
{
47-
4847
/** Internal state of the CMAC algorithm */
4948
unsigned char state[MBEDTLS_CIPHER_BLKSIZE_MAX];
5049

@@ -54,9 +53,6 @@ struct mbedtls_cmac_context_t
5453

5554
/** Length of data pending to be processed */
5655
size_t unprocessed_len;
57-
58-
/** Flag to indicate if the last block needs padding */
59-
int padding_flag;
6056
};
6157

6258
/**

features/mbedtls/inc/mbedtls/config.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -955,18 +955,6 @@
955955
*/
956956
//#define MBEDTLS_SHA256_SMALLER
957957

958-
/**
959-
* \def MBEDTLS_SSL_AEAD_RANDOM_IV
960-
*
961-
* Generate a random IV rather than using the record sequence number as a
962-
* nonce for ciphersuites using and AEAD algorithm (GCM or CCM).
963-
*
964-
* Using the sequence number is generally recommended.
965-
*
966-
* Uncomment this macro to always use random IVs with AEAD ciphersuites.
967-
*/
968-
//#define MBEDTLS_SSL_AEAD_RANDOM_IV
969-
970958
/**
971959
* \def MBEDTLS_SSL_ALL_ALERT_MESSAGES
972960
*

features/mbedtls/inc/mbedtls/gcm.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,8 @@ int mbedtls_gcm_update( mbedtls_gcm_context *ctx,
190190
* 16 bytes.
191191
*
192192
* \param ctx GCM context
193-
* \param tag buffer for holding the tag (may be NULL if tag_len is 0)
194-
* \param tag_len length of the tag to generate
193+
* \param tag buffer for holding the tag
194+
* \param tag_len length of the tag to generate (must be at least 4)
195195
*
196196
* \return 0 if successful or MBEDTLS_ERR_GCM_BAD_INPUT
197197
*/

features/mbedtls/inc/mbedtls/ssl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@
107107
#define MBEDTLS_ERR_SSL_TIMEOUT -0x6800 /**< The operation timed out. */
108108
#define MBEDTLS_ERR_SSL_CLIENT_RECONNECT -0x6780 /**< The client initiated a reconnect from the same port. */
109109
#define MBEDTLS_ERR_SSL_UNEXPECTED_RECORD -0x6700 /**< Record header looks valid but is not expected. */
110+
#define MBEDTLS_ERR_SSL_NON_FATAL -0x6680 /**< The alert message received indicates a non-fatal error. */
111+
#define MBEDTLS_ERR_SSL_INVALID_VERIFY_HASH -0x6600 /**< Couldn't set the hash for verifying CertificateVerify */
110112

111113
/*
112114
* Various constants

features/mbedtls/inc/mbedtls/ssl_internal.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,11 @@ int mbedtls_ssl_send_fatal_handshake_failure( mbedtls_ssl_context *ssl );
355355
void mbedtls_ssl_reset_checksum( mbedtls_ssl_context *ssl );
356356
int mbedtls_ssl_derive_keys( mbedtls_ssl_context *ssl );
357357

358+
int mbedtls_ssl_read_record_layer( mbedtls_ssl_context *ssl );
359+
int mbedtls_ssl_handle_message_type( mbedtls_ssl_context *ssl );
360+
int mbedtls_ssl_prepare_handshake_record( mbedtls_ssl_context *ssl );
361+
void mbedtls_ssl_update_handshake_status( mbedtls_ssl_context *ssl );
362+
358363
int mbedtls_ssl_read_record( mbedtls_ssl_context *ssl );
359364
int mbedtls_ssl_fetch_input( mbedtls_ssl_context *ssl, size_t nb_want );
360365

@@ -384,6 +389,7 @@ mbedtls_pk_type_t mbedtls_ssl_pk_alg_from_sig( unsigned char sig );
384389

385390
mbedtls_md_type_t mbedtls_ssl_md_alg_from_hash( unsigned char hash );
386391
unsigned char mbedtls_ssl_hash_from_md_alg( int md );
392+
int mbedtls_ssl_set_calc_verify_md( mbedtls_ssl_context *ssl, int md );
387393

388394
#if defined(MBEDTLS_ECP_C)
389395
int mbedtls_ssl_check_curve( const mbedtls_ssl_context *ssl, mbedtls_ecp_group_id grp_id );

features/mbedtls/inc/mbedtls/x509_csr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ int mbedtls_x509write_csr_der( mbedtls_x509write_csr *ctx, unsigned char *buf, s
282282
*
283283
* \note f_rng may be NULL if RSA is used for signature and the
284284
* signature is made offline (otherwise f_rng is desirable
285-
* for couermeasures against timing attacks).
285+
* for countermeasures against timing attacks).
286286
* ECDSA signatures always require a non-NULL f_rng.
287287
*/
288288
int mbedtls_x509write_csr_pem( mbedtls_x509write_csr *ctx, unsigned char *buf, size_t size,

features/mbedtls/src/asn1parse.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ int mbedtls_asn1_get_int( unsigned char **p,
153153
if( ( ret = mbedtls_asn1_get_tag( p, end, &len, MBEDTLS_ASN1_INTEGER ) ) != 0 )
154154
return( ret );
155155

156-
if( len > sizeof( int ) || ( **p & 0x80 ) != 0 )
156+
if( len == 0 || len > sizeof( int ) || ( **p & 0x80 ) != 0 )
157157
return( MBEDTLS_ERR_ASN1_INVALID_LENGTH );
158158

159159
*val = 0;

features/mbedtls/src/cmac.c

Lines changed: 36 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,6 @@ int mbedtls_cipher_cmac_starts( mbedtls_cipher_context_t *ctx,
235235
ctx->cmac_ctx = cmac_ctx;
236236

237237
mbedtls_zeroize( cmac_ctx->state, sizeof( cmac_ctx->state ) );
238-
cmac_ctx->padding_flag = 1;
239238

240239
return 0;
241240
}
@@ -256,8 +255,8 @@ int mbedtls_cipher_cmac_update( mbedtls_cipher_context_t *ctx,
256255
block_size = ctx->cipher_info->block_size;
257256
state = ctx->cmac_ctx->state;
258257

259-
/* Is their data still to process from the last call, that's equal to
260-
* or greater than a block? */
258+
/* Is there data still to process from the last call, that's greater in
259+
* size than a block? */
261260
if( cmac_ctx->unprocessed_len > 0 &&
262261
ilen > block_size - cmac_ctx->unprocessed_len )
263262
{
@@ -273,9 +272,8 @@ int mbedtls_cipher_cmac_update( mbedtls_cipher_context_t *ctx,
273272
goto exit;
274273
}
275274

276-
ilen -= block_size;
277-
input += cmac_ctx->unprocessed_len;
278-
275+
input += block_size - cmac_ctx->unprocessed_len;
276+
ilen -= block_size - cmac_ctx->unprocessed_len;
279277
cmac_ctx->unprocessed_len = 0;
280278
}
281279

@@ -293,20 +291,15 @@ int mbedtls_cipher_cmac_update( mbedtls_cipher_context_t *ctx,
293291

294292
ilen -= block_size;
295293
input += block_size;
296-
297-
cmac_ctx->padding_flag = 0;
298294
}
299295

300296
/* If there is data left over that wasn't aligned to a block */
301297
if( ilen > 0 )
302298
{
303-
memcpy( &cmac_ctx->unprocessed_block, input, ilen );
304-
cmac_ctx->unprocessed_len = ilen;
305-
306-
if( ilen % block_size > 0 )
307-
cmac_ctx->padding_flag = 1;
308-
else
309-
cmac_ctx->padding_flag = 0;
299+
memcpy( &cmac_ctx->unprocessed_block[cmac_ctx->unprocessed_len],
300+
input,
301+
ilen );
302+
cmac_ctx->unprocessed_len += ilen;
310303
}
311304

312305
exit:
@@ -339,7 +332,7 @@ int mbedtls_cipher_cmac_finish( mbedtls_cipher_context_t *ctx,
339332
last_block = cmac_ctx->unprocessed_block;
340333

341334
/* Calculate last block */
342-
if( cmac_ctx->padding_flag )
335+
if( cmac_ctx->unprocessed_len < block_size )
343336
{
344337
cmac_pad( M_last, block_size, last_block, cmac_ctx->unprocessed_len );
345338
cmac_xor_block( M_last, M_last, K2, block_size );
@@ -366,7 +359,6 @@ int mbedtls_cipher_cmac_finish( mbedtls_cipher_context_t *ctx,
366359
mbedtls_zeroize( K1, sizeof( K1 ) );
367360
mbedtls_zeroize( K2, sizeof( K2 ) );
368361

369-
cmac_ctx->padding_flag = 1;
370362
cmac_ctx->unprocessed_len = 0;
371363
mbedtls_zeroize( cmac_ctx->unprocessed_block,
372364
sizeof( cmac_ctx->unprocessed_block ) );
@@ -390,7 +382,6 @@ int mbedtls_cipher_cmac_reset( mbedtls_cipher_context_t *ctx )
390382
sizeof( cmac_ctx->unprocessed_block ) );
391383
mbedtls_zeroize( cmac_ctx->state,
392384
sizeof( cmac_ctx->state ) );
393-
cmac_ctx->padding_flag = 1;
394385

395386
return( 0 );
396387
}
@@ -746,19 +737,19 @@ static int cmac_test_subkeys( int verbose,
746737
return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE );
747738
}
748739

749-
mbedtls_cipher_init( &ctx );
750-
751740
for( i = 0; i < num_tests; i++ )
752741
{
753742
if( verbose != 0 )
754743
mbedtls_printf( " %s CMAC subkey #%u: ", testname, i + 1 );
755744

745+
mbedtls_cipher_init( &ctx );
746+
756747
if( ( ret = mbedtls_cipher_setup( &ctx, cipher_info ) ) != 0 )
757748
{
758749
if( verbose != 0 )
759750
mbedtls_printf( "test execution failed\n" );
760751

761-
goto exit;
752+
goto cleanup;
762753
}
763754

764755
if( ( ret = mbedtls_cipher_setkey( &ctx, key, keybits,
@@ -767,32 +758,39 @@ static int cmac_test_subkeys( int verbose,
767758
if( verbose != 0 )
768759
mbedtls_printf( "test execution failed\n" );
769760

770-
goto exit;
761+
goto cleanup;
771762
}
772763

773764
ret = cmac_generate_subkeys( &ctx, K1, K2 );
774765
if( ret != 0 )
775766
{
776767
if( verbose != 0 )
777768
mbedtls_printf( "failed\n" );
778-
goto exit;
769+
770+
goto cleanup;
779771
}
780772

781-
if( ( ret = memcmp( K1, subkeys, block_size ) != 0 ) ||
782-
( ret = memcmp( K2, &subkeys[block_size], block_size ) != 0 ) )
773+
if( ( ret = memcmp( K1, subkeys, block_size ) ) != 0 ||
774+
( ret = memcmp( K2, &subkeys[block_size], block_size ) ) != 0 )
783775
{
784776
if( verbose != 0 )
785777
mbedtls_printf( "failed\n" );
786-
goto exit;
778+
779+
goto cleanup;
787780
}
788781

789782
if( verbose != 0 )
790783
mbedtls_printf( "passed\n" );
784+
785+
mbedtls_cipher_free( &ctx );
791786
}
792787

793-
exit:
788+
goto exit;
789+
790+
cleanup:
794791
mbedtls_cipher_free( &ctx );
795792

793+
exit:
796794
return( ret );
797795
}
798796

@@ -889,7 +887,7 @@ int mbedtls_cmac_self_test( int verbose )
889887
(const unsigned char*)aes_128_subkeys,
890888
MBEDTLS_CIPHER_AES_128_ECB,
891889
MBEDTLS_AES_BLOCK_SIZE,
892-
NB_CMAC_TESTS_PER_KEY ) != 0 ) )
890+
NB_CMAC_TESTS_PER_KEY ) ) != 0 )
893891
{
894892
return( ret );
895893
}
@@ -903,7 +901,7 @@ int mbedtls_cmac_self_test( int verbose )
903901
(const unsigned char*)aes_128_expected_result,
904902
MBEDTLS_CIPHER_AES_128_ECB,
905903
MBEDTLS_AES_BLOCK_SIZE,
906-
NB_CMAC_TESTS_PER_KEY ) != 0 ) )
904+
NB_CMAC_TESTS_PER_KEY ) ) != 0 )
907905
{
908906
return( ret );
909907
}
@@ -916,7 +914,7 @@ int mbedtls_cmac_self_test( int verbose )
916914
(const unsigned char*)aes_192_subkeys,
917915
MBEDTLS_CIPHER_AES_192_ECB,
918916
MBEDTLS_AES_BLOCK_SIZE,
919-
NB_CMAC_TESTS_PER_KEY ) != 0 ) )
917+
NB_CMAC_TESTS_PER_KEY ) ) != 0 )
920918
{
921919
return( ret );
922920
}
@@ -930,7 +928,7 @@ int mbedtls_cmac_self_test( int verbose )
930928
(const unsigned char*)aes_192_expected_result,
931929
MBEDTLS_CIPHER_AES_192_ECB,
932930
MBEDTLS_AES_BLOCK_SIZE,
933-
NB_CMAC_TESTS_PER_KEY ) != 0 ) )
931+
NB_CMAC_TESTS_PER_KEY ) ) != 0 )
934932
{
935933
return( ret );
936934
}
@@ -943,7 +941,7 @@ int mbedtls_cmac_self_test( int verbose )
943941
(const unsigned char*)aes_256_subkeys,
944942
MBEDTLS_CIPHER_AES_256_ECB,
945943
MBEDTLS_AES_BLOCK_SIZE,
946-
NB_CMAC_TESTS_PER_KEY ) != 0 ) )
944+
NB_CMAC_TESTS_PER_KEY ) ) != 0 )
947945
{
948946
return( ret );
949947
}
@@ -957,7 +955,7 @@ int mbedtls_cmac_self_test( int verbose )
957955
(const unsigned char*)aes_256_expected_result,
958956
MBEDTLS_CIPHER_AES_256_ECB,
959957
MBEDTLS_AES_BLOCK_SIZE,
960-
NB_CMAC_TESTS_PER_KEY ) != 0 ) )
958+
NB_CMAC_TESTS_PER_KEY ) ) != 0 )
961959
{
962960
return( ret );
963961
}
@@ -972,7 +970,7 @@ int mbedtls_cmac_self_test( int verbose )
972970
(const unsigned char*)des3_2key_subkeys,
973971
MBEDTLS_CIPHER_DES_EDE3_ECB,
974972
MBEDTLS_DES3_BLOCK_SIZE,
975-
NB_CMAC_TESTS_PER_KEY ) != 0 ) )
973+
NB_CMAC_TESTS_PER_KEY ) ) != 0 )
976974
{
977975
return( ret );
978976
}
@@ -986,7 +984,7 @@ int mbedtls_cmac_self_test( int verbose )
986984
(const unsigned char*)des3_2key_expected_result,
987985
MBEDTLS_CIPHER_DES_EDE3_ECB,
988986
MBEDTLS_DES3_BLOCK_SIZE,
989-
NB_CMAC_TESTS_PER_KEY ) != 0 ) )
987+
NB_CMAC_TESTS_PER_KEY ) ) != 0 )
990988
{
991989
return( ret );
992990
}
@@ -999,7 +997,7 @@ int mbedtls_cmac_self_test( int verbose )
999997
(const unsigned char*)des3_3key_subkeys,
1000998
MBEDTLS_CIPHER_DES_EDE3_ECB,
1001999
MBEDTLS_DES3_BLOCK_SIZE,
1002-
NB_CMAC_TESTS_PER_KEY ) != 0 ) )
1000+
NB_CMAC_TESTS_PER_KEY ) ) != 0 )
10031001
{
10041002
return( ret );
10051003
}
@@ -1013,14 +1011,14 @@ int mbedtls_cmac_self_test( int verbose )
10131011
(const unsigned char*)des3_3key_expected_result,
10141012
MBEDTLS_CIPHER_DES_EDE3_ECB,
10151013
MBEDTLS_DES3_BLOCK_SIZE,
1016-
NB_CMAC_TESTS_PER_KEY ) != 0 ) )
1014+
NB_CMAC_TESTS_PER_KEY ) ) != 0 )
10171015
{
10181016
return( ret );
10191017
}
10201018
#endif /* MBEDTLS_DES_C */
10211019

10221020
#if defined(MBEDTLS_AES_C)
1023-
if( ( ret = test_aes128_cmac_prf( verbose ) != 0 ) )
1021+
if( ( ret = test_aes128_cmac_prf( verbose ) ) != 0 )
10241022
return( ret );
10251023
#endif /* MBEDTLS_AES_C */
10261024

features/mbedtls/src/error.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,10 @@ void mbedtls_strerror( int ret, char *buf, size_t buflen )
435435
mbedtls_snprintf( buf, buflen, "SSL - The client initiated a reconnect from the same port" );
436436
if( use_ret == -(MBEDTLS_ERR_SSL_UNEXPECTED_RECORD) )
437437
mbedtls_snprintf( buf, buflen, "SSL - Record header looks valid but is not expected" );
438+
if( use_ret == -(MBEDTLS_ERR_SSL_NON_FATAL) )
439+
mbedtls_snprintf( buf, buflen, "SSL - The alert message received indicates a non-fatal error" );
440+
if( use_ret == -(MBEDTLS_ERR_SSL_INVALID_VERIFY_HASH) )
441+
mbedtls_snprintf( buf, buflen, "SSL - Couldn't set the hash for verifying CertificateVerify" );
438442
#endif /* MBEDTLS_SSL_TLS_C */
439443

440444
#if defined(MBEDTLS_X509_USE_C) || defined(MBEDTLS_X509_CREATE_C)

features/mbedtls/src/gcm.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,8 +415,7 @@ int mbedtls_gcm_finish( mbedtls_gcm_context *ctx,
415415
if( tag_len > 16 || tag_len < 4 )
416416
return( MBEDTLS_ERR_GCM_BAD_INPUT );
417417

418-
if( tag_len != 0 )
419-
memcpy( tag, ctx->base_ectr, tag_len );
418+
memcpy( tag, ctx->base_ectr, tag_len );
420419

421420
if( orig_len || orig_add_len )
422421
{

0 commit comments

Comments
 (0)