Merge remote-tracking branch 'public/pr/2870' into baremetal

This commit is contained in:
Simon Butcher 2019-10-23 14:51:37 +01:00
commit a26fb4c64f
46 changed files with 699 additions and 0 deletions

View File

@ -164,6 +164,80 @@ MBEDTLS_DEPRECATED typedef int mbedtls_deprecated_numeric_constant_t;
*/ */
void mbedtls_platform_zeroize( void *buf, size_t len ); void mbedtls_platform_zeroize( void *buf, size_t len );
/**
* \brief Secure memset
*
* This is a constant-time version of memset(). If
* MBEDTLS_ENTROPY_HARDWARE_ALT is defined, the buffer is
* initialised with random data and the order is also
* randomised using the hardware RNG in order to further harden
* against side-channel attacks.
*
* \param ptr Buffer to be set.
* \param value Value to be used when setting the buffer.
* \param num The length of the buffer in bytes.
*
* \return The value of \p ptr.
*/
void *mbedtls_platform_memset( void *ptr, int value, size_t num );
/**
* \brief Secure memcpy
*
* This is a constant-time version of memcpy(). If
* MBEDTLS_ENTROPY_HARDWARE_ALT is defined, the buffer is
* initialised with random data and the order is also
* randomised using the hardware RNG in order to further harden
* against side-channel attacks.
*
* \param dst Destination buffer where the data is being copied to.
* \param src Source buffer where the data is being copied from.
* \param num The length of the buffers in bytes.
*
* \return The value of \p dst.
*/
void *mbedtls_platform_memcpy( void *dst, const void *src, size_t num );
/**
* \brief Secure memcmp
*
* This is a constant-time version of memcmp(). If
* MBEDTLS_ENTROPY_HARDWARE_ALT is defined, the order is also
* randomised using the hardware RNG in order to further harden
* against side-channel attacks.
*
* \param buf1 First buffer to compare.
* \param buf2 Second buffer to compare against.
* \param num The length of the buffers in bytes.
*
* \return 0 if the buffers were equal or an unspecified non-zero value
* otherwise.
*/
int mbedtls_platform_memcmp( const void *buf1, const void *buf2, size_t num );
/**
* \brief RNG-function for getting a random in given range.
*
* This function is meant to provide a global RNG to be used
* throughout Mbed TLS for hardening the library. It is used
* for generating a random delay, random data or random offset
* for utility functions. It is not meant to be a
* cryptographically secure RNG, but provide an RNG for utility
* functions.
*
* \note Currently the function is dependent of hardware providing an
* rng with MBEDTLS_ENTROPY_HARDWARE_ALT. By default, 0 is
* returned.
*
* \note If the given range is [0, 0), 0 is returned.
*
* \param num Max-value for the generated random number, exclusive.
* The generated number will be on range [0, num).
*
* \return The generated random number.
*/
uint32_t mbedtls_platform_random_in_range( size_t num );
#if defined(MBEDTLS_HAVE_TIME_DATE) #if defined(MBEDTLS_HAVE_TIME_DATE)
/** /**
* \brief Platform-specific implementation of gmtime_r() * \brief Platform-specific implementation of gmtime_r()

View File

@ -38,6 +38,10 @@
#include "mbedtls/platform.h" #include "mbedtls/platform.h"
#include "mbedtls/threading.h" #include "mbedtls/threading.h"
#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
#include "mbedtls/entropy_poll.h"
#endif
#include <stddef.h> #include <stddef.h>
#include <string.h> #include <string.h>
@ -79,6 +83,87 @@ void mbedtls_platform_zeroize( void *buf, size_t len )
} }
#endif /* MBEDTLS_PLATFORM_ZEROIZE_ALT */ #endif /* MBEDTLS_PLATFORM_ZEROIZE_ALT */
void *mbedtls_platform_memset( void *ptr, int value, size_t num )
{
/* Randomize start offset. */
size_t start_offset = (size_t) mbedtls_platform_random_in_range( num );
/* Randomize data */
uint32_t data = mbedtls_platform_random_in_range( 256 );
/* Perform a pair of memset operations from random locations with
* random data */
memset( (void *) ( (unsigned char *) ptr + start_offset ), data,
( num - start_offset ) );
memset( (void *) ptr, data, start_offset );
/* Perform the original memset */
return( memset( ptr, value, num ) );
}
void *mbedtls_platform_memcpy( void *dst, const void *src, size_t num )
{
/* Randomize start offset. */
size_t start_offset = (size_t) mbedtls_platform_random_in_range( num );
/* Randomize initial data to prevent leakage while copying */
uint32_t data = mbedtls_platform_random_in_range( 256 );
memset( (void *) dst, data, num );
memcpy( (void *) ( (unsigned char *) dst + start_offset ),
(void *) ( (unsigned char *) src + start_offset ),
( num - start_offset ) );
return( memcpy( (void *) dst, (void *) src, start_offset ) );
}
int mbedtls_platform_memcmp( const void *buf1, const void *buf2, size_t num )
{
volatile const unsigned char *A = (volatile const unsigned char *) buf1;
volatile const unsigned char *B = (volatile const unsigned char *) buf2;
volatile unsigned char diff = 0;
size_t i = num;
size_t start_offset = (size_t) mbedtls_platform_random_in_range( num );
for( i = start_offset; i < num; i++ )
{
unsigned char x = A[i], y = B[i];
diff |= x ^ y;
}
for( i = 0; i < start_offset; i++ )
{
unsigned char x = A[i], y = B[i];
diff |= x ^ y;
}
return( diff );
}
uint32_t mbedtls_platform_random_in_range( size_t num )
{
#if !defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
(void) num;
return 0;
#else
uint32_t result = 0;
size_t olen = 0;
mbedtls_hardware_poll( NULL, (unsigned char *) &result, sizeof( result ),
&olen );
if( num == 0 )
{
result = 0;
}
else
{
result %= num;
}
return( result );
#endif
}
#if defined(MBEDTLS_HAVE_TIME_DATE) && !defined(MBEDTLS_PLATFORM_GMTIME_R_ALT) #if defined(MBEDTLS_HAVE_TIME_DATE) && !defined(MBEDTLS_PLATFORM_GMTIME_R_ALT)
#include <time.h> #include <time.h>
#if !defined(_WIN32) && (defined(unix) || \ #if !defined(_WIN32) && (defined(unix) || \

View File

@ -80,6 +80,18 @@ int main( void )
} }
#else #else
#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
int mbedtls_hardware_poll( void *data, unsigned char *output,
size_t len, size_t *olen )
{
size_t i;
(void) data;
for( i = 0; i < len; ++i )
output[i] = rand();
*olen = len;
return( 0 );
}
#endif
int main( int argc, char *argv[] ) int main( int argc, char *argv[] )
{ {

View File

@ -82,6 +82,18 @@ int main( void )
} }
#else #else
#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
int mbedtls_hardware_poll( void *data, unsigned char *output,
size_t len, size_t *olen )
{
size_t i;
(void) data;
for( i = 0; i < len; ++i )
output[i] = rand();
*olen = len;
return( 0 );
}
#endif
int main( int argc, char *argv[] ) int main( int argc, char *argv[] )
{ {

View File

@ -52,6 +52,18 @@ int main( void )
} }
#else #else
#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
int mbedtls_hardware_poll( void *data, unsigned char *output,
size_t len, size_t *olen )
{
size_t i;
(void) data;
for( i = 0; i < len; ++i )
output[i] = rand();
*olen = len;
return( 0 );
}
#endif
static int generic_wrapper( mbedtls_md_handle_t md_info, char *filename, unsigned char *sum ) static int generic_wrapper( mbedtls_md_handle_t md_info, char *filename, unsigned char *sum )
{ {

View File

@ -48,6 +48,18 @@ int main( void )
} }
#else #else
#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
int mbedtls_hardware_poll( void *data, unsigned char *output,
size_t len, size_t *olen )
{
size_t i;
(void) data;
for( i = 0; i < len; ++i )
output[i] = rand();
*olen = len;
return( 0 );
}
#endif
int main( void ) int main( void )
{ {

View File

@ -72,6 +72,18 @@ int main( void )
} }
#else #else
#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
int mbedtls_hardware_poll( void *data, unsigned char *output,
size_t len, size_t *olen )
{
size_t i;
(void) data;
for( i = 0; i < len; ++i )
output[i] = rand();
*olen = len;
return( 0 );
}
#endif
int main( void ) int main( void )
{ {

View File

@ -69,6 +69,18 @@ int main( void )
*/ */
#define GENERATOR "4" #define GENERATOR "4"
#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
int mbedtls_hardware_poll( void *data, unsigned char *output,
size_t len, size_t *olen )
{
size_t i;
(void) data;
for( i = 0; i < len; ++i )
output[i] = rand();
*olen = len;
return( 0 );
}
#endif
int main( int argc, char **argv ) int main( int argc, char **argv )
{ {

View File

@ -72,6 +72,18 @@ int main( void )
} }
#else #else
#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
int mbedtls_hardware_poll( void *data, unsigned char *output,
size_t len, size_t *olen )
{
size_t i;
(void) data;
for( i = 0; i < len; ++i )
output[i] = rand();
*olen = len;
return( 0 );
}
#endif
int main( void ) int main( void )
{ {

View File

@ -100,6 +100,18 @@ static void dump_pubkey( const char *title, mbedtls_ecdsa_context *key )
#define dump_pubkey( a, b ) #define dump_pubkey( a, b )
#endif #endif
#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
int mbedtls_hardware_poll( void *data, unsigned char *output,
size_t len, size_t *olen )
{
size_t i;
(void) data;
for( i = 0; i < len; ++i )
output[i] = rand();
*olen = len;
return( 0 );
}
#endif
int main( int argc, char *argv[] ) int main( int argc, char *argv[] )
{ {

View File

@ -137,6 +137,18 @@ int main( void )
} }
#else #else
#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
int mbedtls_hardware_poll( void *data, unsigned char *output,
size_t len, size_t *olen )
{
size_t i;
(void) data;
for( i = 0; i < len; ++i )
output[i] = rand();
*olen = len;
return( 0 );
}
#endif
/* /*
* global options * global options

View File

@ -74,6 +74,18 @@ int main( void )
} }
#else #else
#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
int mbedtls_hardware_poll( void *data, unsigned char *output,
size_t len, size_t *olen )
{
size_t i;
(void) data;
for( i = 0; i < len; ++i )
output[i] = rand();
*olen = len;
return( 0 );
}
#endif
/* /*
* global options * global options

View File

@ -99,6 +99,18 @@ int main( void )
} }
#else #else
#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
int mbedtls_hardware_poll( void *data, unsigned char *output,
size_t len, size_t *olen )
{
size_t i;
(void) data;
for( i = 0; i < len; ++i )
output[i] = rand();
*olen = len;
return( 0 );
}
#endif
/* /*
* global options * global options

View File

@ -50,6 +50,18 @@ int main( void )
} }
#else #else
#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
int mbedtls_hardware_poll( void *data, unsigned char *output,
size_t len, size_t *olen )
{
size_t i;
(void) data;
for( i = 0; i < len; ++i )
output[i] = rand();
*olen = len;
return( 0 );
}
#endif
int main( void ) int main( void )
{ {

View File

@ -60,6 +60,18 @@ int main( void )
} }
#else #else
#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
int mbedtls_hardware_poll( void *data, unsigned char *output,
size_t len, size_t *olen )
{
size_t i;
(void) data;
for( i = 0; i < len; ++i )
output[i] = rand();
*olen = len;
return( 0 );
}
#endif
int main( int argc, char *argv[] ) int main( int argc, char *argv[] )
{ {

View File

@ -61,6 +61,18 @@ int main( void )
} }
#else #else
#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
int mbedtls_hardware_poll( void *data, unsigned char *output,
size_t len, size_t *olen )
{
size_t i;
(void) data;
for( i = 0; i < len; ++i )
output[i] = rand();
*olen = len;
return( 0 );
}
#endif
int main( int argc, char *argv[] ) int main( int argc, char *argv[] )
{ {

View File

@ -61,6 +61,18 @@ int main( void )
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
int mbedtls_hardware_poll( void *data, unsigned char *output,
size_t len, size_t *olen )
{
size_t i;
(void) data;
for( i = 0; i < len; ++i )
output[i] = rand();
*olen = len;
return( 0 );
}
#endif
/* /*
* For the currently used signature algorithms the buffer to store any signature * For the currently used signature algorithms the buffer to store any signature

View File

@ -57,6 +57,18 @@ int main( void )
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
int mbedtls_hardware_poll( void *data, unsigned char *output,
size_t len, size_t *olen )
{
size_t i;
(void) data;
for( i = 0; i < len; ++i )
output[i] = rand();
*olen = len;
return( 0 );
}
#endif
int main( int argc, char *argv[] ) int main( int argc, char *argv[] )
{ {

View File

@ -59,6 +59,18 @@ int main( void )
} }
#else #else
#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
int mbedtls_hardware_poll( void *data, unsigned char *output,
size_t len, size_t *olen )
{
size_t i;
(void) data;
for( i = 0; i < len; ++i )
output[i] = rand();
*olen = len;
return( 0 );
}
#endif
int main( int argc, char *argv[] ) int main( int argc, char *argv[] )
{ {

View File

@ -59,6 +59,18 @@ int main( void )
} }
#else #else
#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
int mbedtls_hardware_poll( void *data, unsigned char *output,
size_t len, size_t *olen )
{
size_t i;
(void) data;
for( i = 0; i < len; ++i )
output[i] = rand();
*olen = len;
return( 0 );
}
#endif
int main( int argc, char *argv[] ) int main( int argc, char *argv[] )
{ {

View File

@ -64,6 +64,18 @@ int main( void )
} }
#else #else
#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
int mbedtls_hardware_poll( void *data, unsigned char *output,
size_t len, size_t *olen )
{
size_t i;
(void) data;
for( i = 0; i < len; ++i )
output[i] = rand();
*olen = len;
return( 0 );
}
#endif
int main( void ) int main( void )
{ {

View File

@ -56,6 +56,18 @@ int main( void )
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
int mbedtls_hardware_poll( void *data, unsigned char *output,
size_t len, size_t *olen )
{
size_t i;
(void) data;
for( i = 0; i < len; ++i )
output[i] = rand();
*olen = len;
return( 0 );
}
#endif
int main( int argc, char *argv[] ) int main( int argc, char *argv[] )
{ {

View File

@ -60,6 +60,18 @@ int main( void )
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
int mbedtls_hardware_poll( void *data, unsigned char *output,
size_t len, size_t *olen )
{
size_t i;
(void) data;
for( i = 0; i < len; ++i )
output[i] = rand();
*olen = len;
return( 0 );
}
#endif
int main( int argc, char *argv[] ) int main( int argc, char *argv[] )
{ {

View File

@ -55,6 +55,18 @@ int main( void )
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
int mbedtls_hardware_poll( void *data, unsigned char *output,
size_t len, size_t *olen )
{
size_t i;
(void) data;
for( i = 0; i < len; ++i )
output[i] = rand();
*olen = len;
return( 0 );
}
#endif
int main( int argc, char *argv[] ) int main( int argc, char *argv[] )
{ {

View File

@ -60,6 +60,18 @@ int main( void )
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
int mbedtls_hardware_poll( void *data, unsigned char *output,
size_t len, size_t *olen )
{
size_t i;
(void) data;
for( i = 0; i < len; ++i )
output[i] = rand();
*olen = len;
return( 0 );
}
#endif
int main( int argc, char *argv[] ) int main( int argc, char *argv[] )
{ {

View File

@ -51,6 +51,18 @@ int main( void )
} }
#else #else
#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
int mbedtls_hardware_poll( void *data, unsigned char *output,
size_t len, size_t *olen )
{
size_t i;
(void) data;
for( i = 0; i < len; ++i )
output[i] = rand();
*olen = len;
return( 0 );
}
#endif
int main( int argc, char *argv[] ) int main( int argc, char *argv[] )
{ {

View File

@ -54,6 +54,18 @@ int main( void )
} }
#else #else
#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
int mbedtls_hardware_poll( void *data, unsigned char *output,
size_t len, size_t *olen )
{
size_t i;
(void) data;
for( i = 0; i < len; ++i )
output[i] = rand();
*olen = len;
return( 0 );
}
#endif
int main( int argc, char *argv[] ) int main( int argc, char *argv[] )
{ {

View File

@ -109,6 +109,19 @@ int rng_wrap( void *ctx, unsigned char *dst, size_t len )
} }
#endif /* MBEDTLS_SSL_CONF_RNG */ #endif /* MBEDTLS_SSL_CONF_RNG */
#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
int mbedtls_hardware_poll( void *data, unsigned char *output,
size_t len, size_t *olen )
{
size_t i;
(void) data;
for( i = 0; i < len; ++i )
output[i] = rand();
*olen = len;
return( 0 );
}
#endif
int main( int argc, char *argv[] ) int main( int argc, char *argv[] )
{ {
int ret, len; int ret, len;

View File

@ -118,6 +118,19 @@ int rng_wrap( void *ctx, unsigned char *dst, size_t len )
} }
#endif /* MBEDTLS_SSL_CONF_RNG */ #endif /* MBEDTLS_SSL_CONF_RNG */
#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
int mbedtls_hardware_poll( void *data, unsigned char *output,
size_t len, size_t *olen )
{
size_t i;
(void) data;
for( i = 0; i < len; ++i )
output[i] = rand();
*olen = len;
return( 0 );
}
#endif
int main( void ) int main( void )
{ {
int ret, len; int ret, len;

View File

@ -180,6 +180,19 @@ int rng_wrap( void *ctx, unsigned char *dst, size_t len )
} }
#endif /* MBEDTLS_SSL_CONF_RNG */ #endif /* MBEDTLS_SSL_CONF_RNG */
#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
int mbedtls_hardware_poll( void *data, unsigned char *output,
size_t len, size_t *olen )
{
size_t i;
(void) data;
for( i = 0; i < len; ++i )
output[i] = rand();
*olen = len;
return( 0 );
}
#endif
int main( void ) int main( void )
{ {
int ret = exit_ok; int ret = exit_ok;

View File

@ -99,6 +99,19 @@ int rng_wrap( void *ctx, unsigned char *dst, size_t len )
} }
#endif /* MBEDTLS_SSL_CONF_RNG */ #endif /* MBEDTLS_SSL_CONF_RNG */
#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
int mbedtls_hardware_poll( void *data, unsigned char *output,
size_t len, size_t *olen )
{
size_t i;
(void) data;
for( i = 0; i < len; ++i )
output[i] = rand();
*olen = len;
return( 0 );
}
#endif
int main( void ) int main( void )
{ {
int ret = 1, len; int ret = 1, len;

View File

@ -925,6 +925,19 @@ int rng_wrap( void *ctx, unsigned char *dst, size_t len )
} }
#endif /* MBEDTLS_SSL_CONF_RNG */ #endif /* MBEDTLS_SSL_CONF_RNG */
#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
int mbedtls_hardware_poll( void *data, unsigned char *output,
size_t len, size_t *olen )
{
size_t i;
(void) data;
for( i = 0; i < len; ++i )
output[i] = rand();
*olen = len;
return( 0 );
}
#endif
int main( int argc, char *argv[] ) int main( int argc, char *argv[] )
{ {
int ret = 0, len, tail_len, i, written, frags, retry_left; int ret = 0, len, tail_len, i, written, frags, retry_left;

View File

@ -116,6 +116,19 @@ int rng_wrap( void *ctx, unsigned char *dst, size_t len )
} }
#endif /* MBEDTLS_SSL_CONF_RNG */ #endif /* MBEDTLS_SSL_CONF_RNG */
#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
int mbedtls_hardware_poll( void *data, unsigned char *output,
size_t len, size_t *olen )
{
size_t i;
(void) data;
for( i = 0; i < len; ++i )
output[i] = rand();
*olen = len;
return( 0 );
}
#endif
int main( void ) int main( void )
{ {
int ret = 1, len, cnt = 0, pid; int ret = 1, len, cnt = 0, pid;

View File

@ -375,6 +375,19 @@ int rng_wrap( void *ctx, unsigned char *dst, size_t len )
} }
#endif /* MBEDTLS_SSL_CONF_RNG */ #endif /* MBEDTLS_SSL_CONF_RNG */
#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
int mbedtls_hardware_poll( void *data, unsigned char *output,
size_t len, size_t *olen )
{
size_t i;
(void) data;
for( i = 0; i < len; ++i )
output[i] = rand();
*olen = len;
return( 0 );
}
#endif
int main( int argc, char *argv[] ) int main( int argc, char *argv[] )
{ {
int ret = 1, len; int ret = 1, len;

View File

@ -111,6 +111,19 @@ int rng_wrap( void *ctx, unsigned char *dst, size_t len )
} }
#endif /* MBEDTLS_SSL_CONF_RNG */ #endif /* MBEDTLS_SSL_CONF_RNG */
#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
int mbedtls_hardware_poll( void *data, unsigned char *output,
size_t len, size_t *olen )
{
size_t i;
(void) data;
for( i = 0; i < len; ++i )
output[i] = rand();
*olen = len;
return( 0 );
}
#endif
int main( void ) int main( void )
{ {
int ret, len; int ret, len;

View File

@ -1536,6 +1536,19 @@ int rng_wrap( void *ctx, unsigned char *dst, size_t len )
} }
#endif /* MBEDTLS_SSL_CONF_RNG */ #endif /* MBEDTLS_SSL_CONF_RNG */
#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
int mbedtls_hardware_poll( void *data, unsigned char *output,
size_t len, size_t *olen )
{
size_t i;
(void) data;
for( i = 0; i < len; ++i )
output[i] = rand();
*olen = len;
return( 0 );
}
#endif
int main( int argc, char *argv[] ) int main( int argc, char *argv[] )
{ {
int ret = 0, len, written, frags, exchanges_left; int ret = 0, len, written, frags, exchanges_left;

View File

@ -258,6 +258,18 @@ typedef struct {
rsa, dhm, ecdsa, ecdh; rsa, dhm, ecdsa, ecdh;
} todo_list; } todo_list;
#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
int mbedtls_hardware_poll( void *data, unsigned char *output,
size_t len, size_t *olen )
{
size_t i;
(void) data;
for( i = 0; i < len; ++i )
output[i] = rand();
*olen = len;
return( 0 );
}
#endif
int main( int argc, char *argv[] ) int main( int argc, char *argv[] )
{ {

View File

@ -279,6 +279,19 @@ const selftest_t selftests[] =
}; };
#endif /* MBEDTLS_SELF_TEST */ #endif /* MBEDTLS_SELF_TEST */
#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
int mbedtls_hardware_poll( void *data, unsigned char *output,
size_t len, size_t *olen )
{
size_t i;
(void) data;
for( i = 0; i < len; ++i )
output[i] = rand();
*olen = len;
return( 0 );
}
#endif
int main( int argc, char *argv[] ) int main( int argc, char *argv[] )
{ {
#if defined(MBEDTLS_SELF_TEST) #if defined(MBEDTLS_SELF_TEST)

View File

@ -99,3 +99,16 @@ int main( int argc, char** argv )
return( exit_code ); return( exit_code );
} }
#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
int mbedtls_hardware_poll( void *data, unsigned char *output,
size_t len, size_t *olen )
{
size_t i;
(void) data;
for( i = 0; i < len; ++i )
output[i] = rand();
*olen = len;
return( 0 );
}
#endif

View File

@ -165,6 +165,19 @@ int rng_wrap( void *ctx, unsigned char *dst, size_t len )
} }
#endif /* MBEDTLS_SSL_CONF_RNG */ #endif /* MBEDTLS_SSL_CONF_RNG */
#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
int mbedtls_hardware_poll( void *data, unsigned char *output,
size_t len, size_t *olen )
{
size_t i;
(void) data;
for( i = 0; i < len; ++i )
output[i] = rand();
*olen = len;
return( 0 );
}
#endif
int main( int argc, char *argv[] ) int main( int argc, char *argv[] )
{ {
int ret = 1; int ret = 1;

View File

@ -154,6 +154,19 @@ int write_certificate_request( mbedtls_x509write_csr *req, const char *output_fi
return( 0 ); return( 0 );
} }
#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
int mbedtls_hardware_poll( void *data, unsigned char *output,
size_t len, size_t *olen )
{
size_t i;
(void) data;
for( i = 0; i < len; ++i )
output[i] = rand();
*olen = len;
return( 0 );
}
#endif
int main( int argc, char *argv[] ) int main( int argc, char *argv[] )
{ {
int ret = 1; int ret = 1;

View File

@ -214,6 +214,19 @@ int write_certificate( mbedtls_x509write_cert *crt, const char *output_file,
return( 0 ); return( 0 );
} }
#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
int mbedtls_hardware_poll( void *data, unsigned char *output,
size_t len, size_t *olen )
{
size_t i;
(void) data;
for( i = 0; i < len; ++i )
output[i] = rand();
*olen = len;
return( 0 );
}
#endif
int main( int argc, char *argv[] ) int main( int argc, char *argv[] )
{ {
int ret = 1; int ret = 1;

View File

@ -72,6 +72,19 @@ struct options
const char *filename; /* filename of the certificate file */ const char *filename; /* filename of the certificate file */
} opt; } opt;
#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
int mbedtls_hardware_poll( void *data, unsigned char *output,
size_t len, size_t *olen )
{
size_t i;
(void) data;
for( i = 0; i < len; ++i )
output[i] = rand();
*olen = len;
return( 0 );
}
#endif
int main( int argc, char *argv[] ) int main( int argc, char *argv[] )
{ {
int ret = 1; int ret = 1;

View File

@ -72,6 +72,19 @@ struct options
const char *filename; /* filename of the certificate request */ const char *filename; /* filename of the certificate request */
} opt; } opt;
#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
int mbedtls_hardware_poll( void *data, unsigned char *output,
size_t len, size_t *olen )
{
size_t i;
(void) data;
for( i = 0; i < len; ++i )
output[i] = rand();
*olen = len;
return( 0 );
}
#endif
int main( int argc, char *argv[] ) int main( int argc, char *argv[] )
{ {
int ret = 1; int ret = 1;

View File

@ -1591,6 +1591,16 @@ component_test_baremetal () {
if_build_succeeded tests/ssl-opt.sh --filter "^Default, DTLS$" if_build_succeeded tests/ssl-opt.sh --filter "^Default, DTLS$"
} }
component_test_hardware_entropy () {
msg "build: default config + MBEDTLS_ENTROPY_HARDWARE_ALT"
scripts/config.pl set MBEDTLS_ENTROPY_HARDWARE_ALT
make CFLAGS='-Werror -O1'
msg "test: default config + MBEDTLS_ENTROPY_HARDWARE_ALT"
if_build_succeeded make test
if_build_succeeded tests/ssl-opt.sh --filter "^Default, DTLS$"
}
component_test_allow_sha1 () { component_test_allow_sha1 () {
msg "build: allow SHA1 in certificates by default" msg "build: allow SHA1 in certificates by default"
scripts/config.pl set MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES scripts/config.pl set MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES

View File

@ -561,6 +561,16 @@ static int uecc_rng_wrapper( uint8_t *dest, unsigned int size )
} }
#endif /* MBEDTLS_USE_TINYCRYPT */ #endif /* MBEDTLS_USE_TINYCRYPT */
#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
int mbedtls_hardware_poll( void *data, unsigned char *output,
size_t len, size_t *olen )
{
(void) data;
*olen = len;
return( rnd_std_rand( NULL, output, len ) );
}
#endif
/** /**
* This function only returns zeros * This function only returns zeros
* *