Skip to content

Commit 92348d1

Browse files
committed
Merge remote-tracking branch 'crypto/development' into development-restricted
* crypto/development: (77 commits) all.sh: disable MEMORY_BUFFER_ALLOC in cmake asan build Unify gcc and clang cmake flags to test with UBsan Add an input check in psa_its_set Remove storage errors from psa_generate_random Update getting_started.md Update based on Jaeden's comments. Update getting_started.md Fix return code warnings Update getting_started.md Fix warnings Add PSA_ERROR_STORAGE_FAILURE to psa_cipher_generate_iv Remove errorneous insert Add STORAGE_FAILURE everywhere + add missing codes Add storage failure to psa_mac_verify_finish Add storage failure to psa_mac_sign_finish Add PSA_ERROR_STORAGE_FAILURE to psa_aead_*_setup functions Added PSA_ERROR_BAD_STATE to functions with operations Added extra bad state case to psa_hash_setup Add missing return codes to psa_generate_key Add PSA_ERROR_BUFFER_TOO_SMALL to psa_mac_compute ...
2 parents c7cde03 + 7c2cc47 commit 92348d1

File tree

7 files changed

+380
-120
lines changed

7 files changed

+380
-120
lines changed

CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ if(CMAKE_COMPILER_IS_GNU)
137137
set(CMAKE_C_FLAGS_RELEASE "-O2")
138138
set(CMAKE_C_FLAGS_DEBUG "-O0 -g3")
139139
set(CMAKE_C_FLAGS_COVERAGE "-O0 -g3 --coverage")
140-
set(CMAKE_C_FLAGS_ASAN "-Werror -fsanitize=address -fno-common -O3")
141-
set(CMAKE_C_FLAGS_ASANDBG "-Werror -fsanitize=address -fno-common -O1 -g3 -fno-omit-frame-pointer -fno-optimize-sibling-calls ")
140+
set(CMAKE_C_FLAGS_ASAN "-Werror -fsanitize=address -fno-common -fsanitize=undefined -fno-sanitize-recover=all -O3")
141+
set(CMAKE_C_FLAGS_ASANDBG "-Werror -fsanitize=address -fno-common -fsanitize=undefined -fno-sanitize-recover=all -O1 -g3 -fno-omit-frame-pointer -fno-optimize-sibling-calls")
142142
set(CMAKE_C_FLAGS_CHECK "-Werror -Os")
143143
set(CMAKE_C_FLAGS_CHECKFULL "${CMAKE_C_FLAGS_CHECK} -Wcast-qual")
144144
endif(CMAKE_COMPILER_IS_GNU)
@@ -149,7 +149,7 @@ if(CMAKE_COMPILER_IS_CLANG)
149149
set(CMAKE_C_FLAGS_DEBUG "-O0 -g3")
150150
set(CMAKE_C_FLAGS_COVERAGE "-O0 -g3 --coverage")
151151
set(CMAKE_C_FLAGS_ASAN "-Werror -fsanitize=address -fno-common -fsanitize=undefined -fno-sanitize-recover=all -O3")
152-
set(CMAKE_C_FLAGS_ASANDBG "-Werror -fsanitize=address -fno-common -fsanitize=undefined -fno-sanitize-recover=all -O1 -g3 -fno-omit-frame-pointer -fno-optimize-sibling-calls ")
152+
set(CMAKE_C_FLAGS_ASANDBG "-Werror -fsanitize=address -fno-common -fsanitize=undefined -fno-sanitize-recover=all -O1 -g3 -fno-omit-frame-pointer -fno-optimize-sibling-calls")
153153
set(CMAKE_C_FLAGS_MEMSAN "-Werror -fsanitize=memory -O3")
154154
set(CMAKE_C_FLAGS_MEMSANDBG "-Werror -fsanitize=memory -O1 -g3 -fno-omit-frame-pointer -fno-optimize-sibling-calls -fsanitize-memory-track-origins=2")
155155
set(CMAKE_C_FLAGS_CHECK "-Werror -Os")

docs/getting_started.md

Lines changed: 99 additions & 97 deletions
Large diffs are not rendered by default.

include/psa/crypto.h

Lines changed: 259 additions & 12 deletions
Large diffs are not rendered by default.

library/bignum.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -742,10 +742,15 @@ int mbedtls_mpi_write_file( const char *p, const mbedtls_mpi *X, int radix, FILE
742742
static mbedtls_mpi_uint mpi_uint_bigendian_to_host_c( mbedtls_mpi_uint x )
743743
{
744744
uint8_t i;
745+
unsigned char *x_ptr;
745746
mbedtls_mpi_uint tmp = 0;
746-
/* This works regardless of the endianness. */
747-
for( i = 0; i < ciL; i++, x >>= 8 )
748-
tmp |= ( x & 0xFF ) << ( ( ciL - 1 - i ) << 3 );
747+
748+
for( i = 0, x_ptr = (unsigned char*) &x; i < ciL; i++, x_ptr++ )
749+
{
750+
tmp <<= CHAR_BIT;
751+
tmp |= (mbedtls_mpi_uint) *x_ptr;
752+
}
753+
749754
return( tmp );
750755
}
751756

library/platform_util.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,10 @@ static void * (* const volatile memset_func)( void *, int, size_t ) = memset;
7272

7373
void mbedtls_platform_zeroize( void *buf, size_t len )
7474
{
75-
memset_func( buf, 0, len );
75+
MBEDTLS_INTERNAL_VALIDATE( len == 0 || buf != NULL );
76+
77+
if( len > 0 )
78+
memset_func( buf, 0, len );
7679
}
7780
#endif /* MBEDTLS_PLATFORM_ZEROIZE_ALT */
7881

library/psa_its_file.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,12 @@ psa_status_t psa_its_set( psa_storage_uid_t uid,
214214
n = fwrite( &header, 1, sizeof( header ), stream );
215215
if( n != sizeof( header ) )
216216
goto exit;
217-
n = fwrite( p_data, 1, data_length, stream );
218-
if( n != data_length )
219-
goto exit;
217+
if( data_length != 0 )
218+
{
219+
n = fwrite( p_data, 1, data_length, stream );
220+
if( n != data_length )
221+
goto exit;
222+
}
220223
status = PSA_SUCCESS;
221224

222225
exit:

tests/scripts/all.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ component_test_no_use_psa_crypto_full_cmake_asan() {
701701
# full minus MBEDTLS_USE_PSA_CRYPTO: run the same set of tests as basic-build-test.sh
702702
msg "build: cmake, full config + MBEDTLS_USE_PSA_CRYPTO, ASan"
703703
scripts/config.pl full
704-
scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
704+
scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
705705
scripts/config.pl set MBEDTLS_ECP_RESTARTABLE # not using PSA, so enable restartable ECC
706706
scripts/config.pl set MBEDTLS_PSA_CRYPTO_C
707707
scripts/config.pl unset MBEDTLS_USE_PSA_CRYPTO

0 commit comments

Comments
 (0)