mirror of
https://git.suyu.dev/suyu/mbedtls.git
synced 2026-01-04 13:45:05 +01:00
Merge remote-tracking branch 'upstream-restricted/mbedtls-2.16-proposed' into mbedtls-2.16-restricted
This commit is contained in:
commit
6d079baba8
7 changed files with 95 additions and 40 deletions
|
|
@ -216,14 +216,13 @@ filter_ciphersuites()
|
|||
G_CIPHERS=$( filter "$G_CIPHERS" )
|
||||
fi
|
||||
|
||||
# OpenSSL 1.0.1h doesn't support DTLS 1.2
|
||||
if [ `minor_ver "$MODE"` -ge 3 ] && is_dtls "$MODE"; then
|
||||
# OpenSSL <1.0.2 doesn't support DTLS 1.2. Check what OpenSSL
|
||||
# supports from the s_server help. (The s_client help isn't
|
||||
# accurate as of 1.0.2g: it supports DTLS 1.2 but doesn't list it.
|
||||
# But the s_server help seems to be accurate.)
|
||||
if ! $OPENSSL_CMD s_server -help 2>&1 | grep -q "^ *-$MODE "; then
|
||||
M_CIPHERS=""
|
||||
O_CIPHERS=""
|
||||
case "$PEER" in
|
||||
[Oo]pen*)
|
||||
M_CIPHERS=""
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
# For GnuTLS client -> mbed TLS server,
|
||||
|
|
|
|||
|
|
@ -985,6 +985,26 @@ component_test_aes_fewer_tables_and_rom_tables () {
|
|||
component_test_make_shared () {
|
||||
msg "build/test: make shared" # ~ 40s
|
||||
make SHARED=1 all check
|
||||
ldd programs/util/strerror | grep libmbedcrypto
|
||||
}
|
||||
|
||||
component_test_cmake_shared () {
|
||||
msg "build/test: cmake shared" # ~ 2min
|
||||
cmake -DUSE_SHARED_MBEDTLS_LIBRARY=On .
|
||||
make
|
||||
ldd programs/util/strerror | grep libmbedcrypto
|
||||
make test
|
||||
}
|
||||
|
||||
component_build_mbedtls_config_file () {
|
||||
msg "build: make with MBEDTLS_CONFIG_FILE" # ~40s
|
||||
# Use the full config so as to catch a maximum of places where
|
||||
# the check of MBEDTLS_CONFIG_FILE might be missing.
|
||||
scripts/config.pl full
|
||||
sed 's!"check_config.h"!"mbedtls/check_config.h"!' <"$CONFIG_H" >full_config.h
|
||||
echo '#error "MBEDTLS_CONFIG_FILE is not working"' >"$CONFIG_H"
|
||||
make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"'"
|
||||
rm -f full_config.h
|
||||
}
|
||||
|
||||
component_test_m32_o0 () {
|
||||
|
|
@ -1097,6 +1117,17 @@ component_build_arm_none_eabi_gcc () {
|
|||
make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
|
||||
}
|
||||
|
||||
component_build_arm_none_eabi_gcc_arm5vte () {
|
||||
msg "build: arm-none-eabi-gcc -march=arm5vte, make" # ~ 10s
|
||||
scripts/config.pl baremetal
|
||||
# Build for a target platform that's close to what Debian uses
|
||||
# for its "armel" distribution (https://wiki.debian.org/ArmEabiPort).
|
||||
# See https://github.com/ARMmbed/mbedtls/pull/2169 and comments.
|
||||
# It would be better to build with arm-linux-gnueabi-gcc but
|
||||
# we don't have that on our CI at this time.
|
||||
make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar CFLAGS='-Werror -Wall -Wextra -march=armv5te -O1' LDFLAGS='-march=armv5te' SHELL='sh -x' lib
|
||||
}
|
||||
|
||||
component_build_arm_none_eabi_gcc_no_udbl_division () {
|
||||
msg "build: arm-none-eabi-gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
|
||||
scripts/config.pl baremetal
|
||||
|
|
|
|||
|
|
@ -301,11 +301,24 @@ void entropy_nv_seed_std_io( )
|
|||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_ENTROPY_NV_SEED:MBEDTLS_PLATFORM_NV_SEED_ALT:MBEDTLS_ENTROPY_SHA512_ACCUMULATOR */
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_MD_C:MBEDTLS_ENTROPY_NV_SEED:MBEDTLS_PLATFORM_NV_SEED_ALT */
|
||||
void entropy_nv_seed( data_t * read_seed )
|
||||
{
|
||||
mbedtls_sha512_context accumulator;
|
||||
#if defined(MBEDTLS_ENTROPY_SHA512_ACCUMULATOR)
|
||||
const mbedtls_md_info_t *md_info =
|
||||
mbedtls_md_info_from_type( MBEDTLS_MD_SHA512 );
|
||||
#elif defined(MBEDTLS_ENTROPY_SHA256_ACCUMULATOR)
|
||||
const mbedtls_md_info_t *md_info =
|
||||
mbedtls_md_info_from_type( MBEDTLS_MD_SHA256 );
|
||||
#else
|
||||
#error "Unsupported entropy accumulator"
|
||||
#endif
|
||||
mbedtls_md_context_t accumulator;
|
||||
mbedtls_entropy_context ctx;
|
||||
int (*original_mbedtls_nv_seed_read)( unsigned char *buf, size_t buf_len ) =
|
||||
mbedtls_nv_seed_read;
|
||||
int (*original_mbedtls_nv_seed_write)( unsigned char *buf, size_t buf_len ) =
|
||||
mbedtls_nv_seed_write;
|
||||
|
||||
unsigned char header[2];
|
||||
unsigned char entropy[MBEDTLS_ENTROPY_BLOCK_SIZE];
|
||||
|
|
@ -316,17 +329,14 @@ void entropy_nv_seed( data_t * read_seed )
|
|||
|
||||
memset( entropy, 0, MBEDTLS_ENTROPY_BLOCK_SIZE );
|
||||
memset( buf, 0, MBEDTLS_ENTROPY_BLOCK_SIZE );
|
||||
memset( buffer_seed, 0, MBEDTLS_ENTROPY_BLOCK_SIZE );
|
||||
memset( empty, 0, MBEDTLS_ENTROPY_BLOCK_SIZE );
|
||||
memset( check_seed, 2, MBEDTLS_ENTROPY_BLOCK_SIZE );
|
||||
memset( check_entropy, 3, MBEDTLS_ENTROPY_BLOCK_SIZE );
|
||||
|
||||
// Set the initial NV seed to read
|
||||
memcpy( buffer_seed, read_seed->x, read_seed->len );
|
||||
|
||||
// Make sure we read/write NV seed from our buffers
|
||||
mbedtls_platform_set_nv_seed( buffer_nv_seed_read, buffer_nv_seed_write );
|
||||
|
||||
mbedtls_md_init( &accumulator );
|
||||
mbedtls_entropy_init( &ctx );
|
||||
entropy_clear_sources( &ctx );
|
||||
|
||||
|
|
@ -334,45 +344,57 @@ void entropy_nv_seed( data_t * read_seed )
|
|||
MBEDTLS_ENTROPY_BLOCK_SIZE,
|
||||
MBEDTLS_ENTROPY_SOURCE_STRONG ) == 0 );
|
||||
|
||||
// Set the initial NV seed to read
|
||||
TEST_ASSERT( read_seed->len >= MBEDTLS_ENTROPY_BLOCK_SIZE );
|
||||
memcpy( buffer_seed, read_seed->x, MBEDTLS_ENTROPY_BLOCK_SIZE );
|
||||
|
||||
// Do an entropy run
|
||||
TEST_ASSERT( mbedtls_entropy_func( &ctx, entropy, sizeof( entropy ) ) == 0 );
|
||||
|
||||
// Determine what should have happened with manual entropy internal logic
|
||||
// Only use the SHA-512 version to check
|
||||
|
||||
// Init accumulator
|
||||
header[1] = MBEDTLS_ENTROPY_BLOCK_SIZE;
|
||||
mbedtls_sha512_starts( &accumulator, 0 );
|
||||
TEST_ASSERT( mbedtls_md_setup( &accumulator, md_info, 0 ) == 0 );
|
||||
|
||||
// First run for updating write_seed
|
||||
header[0] = 0;
|
||||
mbedtls_sha512_update( &accumulator, header, 2 );
|
||||
mbedtls_sha512_update( &accumulator, read_seed->x, read_seed->len );
|
||||
mbedtls_sha512_finish( &accumulator, buf );
|
||||
TEST_ASSERT( mbedtls_md_starts( &accumulator ) == 0 );
|
||||
TEST_ASSERT( mbedtls_md_update( &accumulator, header, 2 ) == 0 );
|
||||
TEST_ASSERT( mbedtls_md_update( &accumulator,
|
||||
read_seed->x, MBEDTLS_ENTROPY_BLOCK_SIZE ) == 0 );
|
||||
TEST_ASSERT( mbedtls_md_finish( &accumulator, buf ) == 0 );
|
||||
|
||||
memset( &accumulator, 0, sizeof( mbedtls_sha512_context ) );
|
||||
mbedtls_sha512_starts( &accumulator, 0 );
|
||||
mbedtls_sha512_update( &accumulator, buf, MBEDTLS_ENTROPY_BLOCK_SIZE );
|
||||
TEST_ASSERT( mbedtls_md_starts( &accumulator ) == 0 );
|
||||
TEST_ASSERT( mbedtls_md_update( &accumulator,
|
||||
buf, MBEDTLS_ENTROPY_BLOCK_SIZE ) == 0 );
|
||||
|
||||
mbedtls_sha512( buf, MBEDTLS_ENTROPY_BLOCK_SIZE, check_seed, 0 );
|
||||
TEST_ASSERT( mbedtls_md( md_info, buf, MBEDTLS_ENTROPY_BLOCK_SIZE,
|
||||
check_seed ) == 0 );
|
||||
|
||||
// Second run for actual entropy (triggers mbedtls_entropy_update_nv_seed)
|
||||
header[0] = MBEDTLS_ENTROPY_SOURCE_MANUAL;
|
||||
mbedtls_sha512_update( &accumulator, header, 2 );
|
||||
mbedtls_sha512_update( &accumulator, empty, MBEDTLS_ENTROPY_BLOCK_SIZE );
|
||||
TEST_ASSERT( mbedtls_md_update( &accumulator, header, 2 ) == 0 );
|
||||
TEST_ASSERT( mbedtls_md_update( &accumulator,
|
||||
empty, MBEDTLS_ENTROPY_BLOCK_SIZE ) == 0 );
|
||||
|
||||
header[0] = 0;
|
||||
mbedtls_sha512_update( &accumulator, header, 2 );
|
||||
mbedtls_sha512_update( &accumulator, check_seed, MBEDTLS_ENTROPY_BLOCK_SIZE );
|
||||
mbedtls_sha512_finish( &accumulator, buf );
|
||||
TEST_ASSERT( mbedtls_md_update( &accumulator, header, 2 ) == 0 );
|
||||
TEST_ASSERT( mbedtls_md_update( &accumulator,
|
||||
check_seed, MBEDTLS_ENTROPY_BLOCK_SIZE ) == 0 );
|
||||
TEST_ASSERT( mbedtls_md_finish( &accumulator, buf ) == 0 );
|
||||
|
||||
mbedtls_sha512( buf, MBEDTLS_ENTROPY_BLOCK_SIZE, check_entropy, 0 );
|
||||
TEST_ASSERT( mbedtls_md( md_info, buf, MBEDTLS_ENTROPY_BLOCK_SIZE,
|
||||
check_entropy ) == 0 );
|
||||
|
||||
// Check result of both NV file and entropy received with the manual calculations
|
||||
TEST_ASSERT( memcmp( check_seed, buffer_seed, MBEDTLS_ENTROPY_BLOCK_SIZE ) == 0 );
|
||||
TEST_ASSERT( memcmp( check_entropy, entropy, MBEDTLS_ENTROPY_BLOCK_SIZE ) == 0 );
|
||||
|
||||
exit:
|
||||
mbedtls_md_free( &accumulator );
|
||||
mbedtls_entropy_free( &ctx );
|
||||
mbedtls_nv_seed_read = original_mbedtls_nv_seed_read;
|
||||
mbedtls_nv_seed_write = original_mbedtls_nv_seed_write;
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
|
|
|
|||
|
|
@ -170,10 +170,6 @@ void nist_kw_plaintext_lengths( int in_len, int out_len, int mode, int res )
|
|||
TEST_ASSERT( ciphertext != NULL );
|
||||
}
|
||||
|
||||
memset( plaintext, 0, in_len );
|
||||
memset( ciphertext, 0, output_len );
|
||||
|
||||
|
||||
TEST_ASSERT( mbedtls_nist_kw_setkey( &ctx, MBEDTLS_CIPHER_ID_AES,
|
||||
key, 8 * sizeof( key ), 1 ) == 0 );
|
||||
|
||||
|
|
@ -225,10 +221,6 @@ void nist_kw_ciphertext_lengths( int in_len, int out_len, int mode, int res )
|
|||
TEST_ASSERT( ciphertext != NULL );
|
||||
}
|
||||
|
||||
memset( plaintext, 0, output_len );
|
||||
memset( ciphertext, 0, in_len );
|
||||
|
||||
|
||||
TEST_ASSERT( mbedtls_nist_kw_setkey( &ctx, MBEDTLS_CIPHER_ID_AES,
|
||||
key, 8 * sizeof( key ), 0 ) == 0 );
|
||||
unwrap_ret = mbedtls_nist_kw_unwrap( &ctx, mode, ciphertext, in_len,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue