From 59392b0075c7ad79572c04a51cca621fae8cab16 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Mon, 24 May 2021 22:58:37 +0200 Subject: [PATCH 1/4] Fix misplaced extern "C" affecting MBEDTLS_ARIA_ALT Reported via Mbed OS: https://github.com/ARMmbed/mbed-os/issues/14694 Signed-off-by: Gilles Peskine --- include/mbedtls/aria.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/mbedtls/aria.h b/include/mbedtls/aria.h index 7dd960f29a26..e98414760d94 100644 --- a/include/mbedtls/aria.h +++ b/include/mbedtls/aria.h @@ -51,14 +51,14 @@ #define MBEDTLS_ERR_ARIA_INVALID_INPUT_LENGTH -0x005E /**< Invalid data input length. */ -#if !defined(MBEDTLS_ARIA_ALT) -// Regular implementation -// - #ifdef __cplusplus extern "C" { #endif +#if !defined(MBEDTLS_ARIA_ALT) +// Regular implementation +// + /** * \brief The ARIA context-type definition. */ From be89fea1a7b2046c97a85a8328bc840616026a52 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Tue, 25 May 2021 09:17:22 +0200 Subject: [PATCH 2/4] ARIA: add missing context init/free This fixes the self-test with alternative implementations. Signed-off-by: Gilles Peskine --- library/aria.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/library/aria.c b/library/aria.c index 18756355223b..a5786b37ab38 100644 --- a/library/aria.c +++ b/library/aria.c @@ -921,7 +921,7 @@ static const uint8_t aria_test2_ctr_ct[3][48] = // CTR ciphertext { \ if( verbose ) \ mbedtls_printf( "failed\n" ); \ - return( 1 ); \ + goto exit; \ } else { \ if( verbose ) \ mbedtls_printf( "passed\n" ); \ @@ -935,6 +935,7 @@ int mbedtls_aria_self_test( int verbose ) int i; uint8_t blk[MBEDTLS_ARIA_BLOCKSIZE]; mbedtls_aria_context ctx; + int ret = 1; #if (defined(MBEDTLS_CIPHER_MODE_CFB) || defined(MBEDTLS_CIPHER_MODE_CTR)) size_t j; @@ -946,6 +947,8 @@ int mbedtls_aria_self_test( int verbose ) uint8_t buf[48], iv[MBEDTLS_ARIA_BLOCKSIZE]; #endif + mbedtls_aria_init( &ctx ); + /* * Test set 1 */ @@ -1065,7 +1068,11 @@ int mbedtls_aria_self_test( int verbose ) mbedtls_printf( "\n" ); #endif /* MBEDTLS_CIPHER_MODE_CTR */ - return( 0 ); + ret = 0; + +exit: + mbedtls_aria_free( &ctx ); + return( ret ); } #endif /* MBEDTLS_SELF_TEST */ From c537aa83f42f537eeb7dc2818a28849298de2e9e Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Tue, 25 May 2021 09:17:46 +0200 Subject: [PATCH 3/4] CAMELLIA: add missing context init/free This fixes the self-test with alternative implementations. Signed-off-by: Gilles Peskine --- library/camellia.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/library/camellia.c b/library/camellia.c index d60f93188074..f7e013611ba4 100644 --- a/library/camellia.c +++ b/library/camellia.c @@ -942,9 +942,11 @@ int mbedtls_camellia_self_test( int verbose ) unsigned char nonce_counter[16]; unsigned char stream_block[16]; #endif + int ret = 1; mbedtls_camellia_context ctx; + mbedtls_camellia_init( &ctx ); memset( key, 0, 32 ); for( j = 0; j < 6; j++ ) { @@ -974,8 +976,7 @@ int mbedtls_camellia_self_test( int verbose ) { if( verbose != 0 ) mbedtls_printf( "failed\n" ); - - return( 1 ); + goto exit; } } @@ -1027,8 +1028,7 @@ int mbedtls_camellia_self_test( int verbose ) { if( verbose != 0 ) mbedtls_printf( "failed\n" ); - - return( 1 ); + goto exit; } } @@ -1071,8 +1071,7 @@ int mbedtls_camellia_self_test( int verbose ) { if( verbose != 0 ) mbedtls_printf( "failed\n" ); - - return( 1 ); + goto exit; } } else @@ -1087,8 +1086,7 @@ int mbedtls_camellia_self_test( int verbose ) { if( verbose != 0 ) mbedtls_printf( "failed\n" ); - - return( 1 ); + goto exit; } } @@ -1100,7 +1098,11 @@ int mbedtls_camellia_self_test( int verbose ) mbedtls_printf( "\n" ); #endif /* MBEDTLS_CIPHER_MODE_CTR */ - return( 0 ); + ret = 0; + +exit: + mbedtls_camellia_free( &ctx ); + return( ret ); } #endif /* MBEDTLS_SELF_TEST */ From 0e1f05d34bf8c0bf2729188a32efa8743d0a9a03 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Tue, 25 May 2021 09:28:54 +0200 Subject: [PATCH 4/4] Changelog entry for the ARIA_ALT and CAMELLIA_ALT fixes Fix ARMmbed/mbed-os#14694 Signed-off-by: Gilles Peskine --- ChangeLog.d/aria-alt.txt | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 ChangeLog.d/aria-alt.txt diff --git a/ChangeLog.d/aria-alt.txt b/ChangeLog.d/aria-alt.txt new file mode 100644 index 000000000000..20aaa2b71d1e --- /dev/null +++ b/ChangeLog.d/aria-alt.txt @@ -0,0 +1,5 @@ +Bugfix + * Fix some issues affecting MBEDTLS_ARIA_ALT implementations: a misplaced + directive in a header and a missing initialization in the self-test. + * Fix a missing initialization in the Camellia self-test, affecting + MBEDTLS_CAMELLIA_ALT implementations.