Skip to content

Commit 4fde885

Browse files
authored
Merge pull request #357 from gilles-peskine-arm/merge-crypto-development-20200203
Update Mbed Crypto with latest Mbed TLS changes as of 2020-02-03
2 parents b7000d4 + 2579675 commit 4fde885

File tree

7 files changed

+52
-20
lines changed

7 files changed

+52
-20
lines changed

include/mbedtls/error.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
* Low-level module errors (0x0002-0x007E, 0x0001-0x007F)
5656
*
5757
* Module Nr Codes assigned
58-
* ERROR 2 0x006E 0x0001
58+
* ERROR 2 0x006E 0x0001
5959
* MPI 7 0x0002-0x0010
6060
* GCM 3 0x0012-0x0014 0x0013-0x0013
6161
* BLOWFISH 3 0x0016-0x0018 0x0017-0x0017

library/error.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525
#include MBEDTLS_CONFIG_FILE
2626
#endif
2727

28-
#if defined(MBEDTLS_ERROR_C) || defined(MBEDTLS_ERROR_STRERROR_DUMMY)
29-
#include "mbedtls/error.h"
28+
#if defined(MBEDTLS_ERROR_STRERROR_DUMMY)
3029
#include <string.h>
3130
#endif
3231

programs/aes/aescrypt2.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ int main( int argc, char *argv[] )
9696
unsigned char IV[16];
9797
unsigned char tmp[16];
9898
unsigned char key[512];
99-
unsigned char digest[32];
99+
unsigned char digest[64];
100100
unsigned char buffer[1024];
101101
unsigned char diff;
102102

scripts/config.pl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
## This file is part of Mbed TLS (https://tls.mbed.org)
2020

2121
my $py = $0;
22-
$py =~ s/\.pl$/.py/;
22+
$py =~ s/\.pl$/.py/ or die "Unable to determine the name of the Python script";
2323
exec 'python3', $py, @ARGV;
24-
print STDERR "$0: python3: $!\n";
24+
print STDERR "$0: python3: $!. Trying python instead.\n";
2525
exec 'python', $py, @ARGV;
2626
print STDERR "$0: python: $!\n";
2727
exit 127;

scripts/data_files/error.fmt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525
#include MBEDTLS_CONFIG_FILE
2626
#endif
2727

28-
#if defined(MBEDTLS_ERROR_C) || defined(MBEDTLS_ERROR_STRERROR_DUMMY)
29-
#include "mbedtls/error.h"
28+
#if defined(MBEDTLS_ERROR_STRERROR_DUMMY)
3029
#include <string.h>
3130
#endif
3231

tests/suites/helpers.function

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,11 +311,11 @@ typedef enum
311311
#define TEST_VALID_PARAM( TEST ) \
312312
TEST_ASSERT( ( TEST, 1 ) );
313313

314-
#define TEST_HELPER_ASSERT(a) if( !( a ) ) \
314+
#define TEST_HELPER_ASSERT(a) if( !( a ) ) \
315315
{ \
316-
mbedtls_fprintf( stderr, "Assertion Failed at %s:%d - %s\n", \
316+
mbedtls_fprintf( stderr, "Assertion Failed at %s:%d - %s\n", \
317317
__FILE__, __LINE__, #a ); \
318-
mbedtls_exit( 1 ); \
318+
mbedtls_exit( 1 ); \
319319
}
320320

321321
#if defined(__GNUC__)
@@ -370,6 +370,38 @@ typedef enum
370370
*/
371371
#define MAX( x, y ) ( ( x ) > ( y ) ? ( x ) : ( y ) )
372372

373+
/** Allocate memory dynamically and fail the test case if this fails.
374+
*
375+
* You must set \p pointer to \c NULL before calling this macro and
376+
* put `mbedtls_free( pointer )` in the test's cleanup code.
377+
*
378+
* If \p length is zero, the resulting \p pointer will be \c NULL.
379+
* This is usually what we want in tests since API functions are
380+
* supposed to accept null pointers when a buffer size is zero.
381+
*
382+
* This macro expands to an instruction, not an expression.
383+
* It may jump to the \c exit label.
384+
*
385+
* \param pointer An lvalue where the address of the allocated buffer
386+
* will be stored.
387+
* This expression may be evaluated multiple times.
388+
* \param length Number of elements to allocate.
389+
* This expression may be evaluated multiple times.
390+
*
391+
*/
392+
#define ASSERT_ALLOC( pointer, length ) \
393+
do \
394+
{ \
395+
TEST_ASSERT( ( pointer ) == NULL ); \
396+
if( ( length ) != 0 ) \
397+
{ \
398+
( pointer ) = mbedtls_calloc( sizeof( *( pointer ) ), \
399+
( length ) ); \
400+
TEST_ASSERT( ( pointer ) != NULL ); \
401+
} \
402+
} \
403+
while( 0 )
404+
373405
/*
374406
* 32-bit integer manipulation macros (big endian)
375407
*/

tests/suites/host_test.function

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -525,15 +525,6 @@ int execute_tests( int argc , const char ** argv )
525525
mbedtls_memory_buffer_alloc_init( alloc_buf, sizeof( alloc_buf ) );
526526
#endif
527527

528-
if( outcome_file_name != NULL )
529-
{
530-
outcome_file = fopen( outcome_file_name, "a" );
531-
if( outcome_file == NULL )
532-
{
533-
mbedtls_fprintf( stderr, "Unable to open outcome file. Continuing anyway.\n" );
534-
}
535-
}
536-
537528
/*
538529
* The C standard doesn't guarantee that all-bits-0 is the representation
539530
* of a NULL pointer. We do however use that in our code for initializing
@@ -555,6 +546,15 @@ int execute_tests( int argc , const char ** argv )
555546
return( 1 );
556547
}
557548

549+
if( outcome_file_name != NULL )
550+
{
551+
outcome_file = fopen( outcome_file_name, "a" );
552+
if( outcome_file == NULL )
553+
{
554+
mbedtls_fprintf( stderr, "Unable to open outcome file. Continuing anyway.\n" );
555+
}
556+
}
557+
558558
while( arg_index < argc )
559559
{
560560
next_arg = argv[arg_index];
@@ -607,6 +607,8 @@ int execute_tests( int argc , const char ** argv )
607607
{
608608
mbedtls_fprintf( stderr, "Failed to open test file: %s\n",
609609
test_filename );
610+
if( outcome_file != NULL )
611+
fclose( outcome_file );
610612
return( 1 );
611613
}
612614

0 commit comments

Comments
 (0)