mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2026-05-11 14:38:17 +02:00
Enforce NULL context for hardcoded RNG
This commit is contained in:
@@ -95,6 +95,20 @@ static void my_debug( void *ctx, int level,
|
||||
}
|
||||
#endif /* MBEDTLS_DEBUG_C */
|
||||
|
||||
#if defined(MBEDTLS_SSL_CONF_RNG)
|
||||
int rng_wrap( void *ctx, unsigned char *dst, size_t len );
|
||||
|
||||
mbedtls_ctr_drbg_context *rng_ctx_global = NULL;
|
||||
int rng_wrap( void *ctx, unsigned char *dst, size_t len )
|
||||
{
|
||||
/* We expect the NULL parameter here. */
|
||||
if( ctx != NULL )
|
||||
return( -1 );
|
||||
|
||||
return( mbedtls_ctr_drbg_random( rng_ctx_global, dst, len ) );
|
||||
}
|
||||
#endif /* MBEDTLS_SSL_CONF_RNG */
|
||||
|
||||
int main( int argc, char *argv[] )
|
||||
{
|
||||
int ret, len;
|
||||
@@ -192,7 +206,13 @@ int main( int argc, char *argv[] )
|
||||
* Production code should set a proper ca chain and use REQUIRED. */
|
||||
mbedtls_ssl_conf_authmode( &conf, MBEDTLS_SSL_VERIFY_OPTIONAL );
|
||||
mbedtls_ssl_conf_ca_chain( &conf, &cacert, NULL );
|
||||
|
||||
#if !defined(MBEDTLS_SSL_CONF_RNG)
|
||||
mbedtls_ssl_conf_rng( &conf, mbedtls_ctr_drbg_random, &ctr_drbg );
|
||||
#else
|
||||
rng_ctx_global = &ctr_drbg;
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_DEBUG_C)
|
||||
mbedtls_ssl_conf_dbg( &conf, my_debug, stdout );
|
||||
#endif
|
||||
|
||||
@@ -104,6 +104,20 @@ static void my_debug( void *ctx, int level,
|
||||
}
|
||||
#endif /* MBEDTLS_DEBUG_C */
|
||||
|
||||
#if defined(MBEDTLS_SSL_CONF_RNG)
|
||||
int rng_wrap( void *ctx, unsigned char *dst, size_t len );
|
||||
|
||||
mbedtls_ctr_drbg_context *rng_ctx_global = NULL;
|
||||
int rng_wrap( void *ctx, unsigned char *dst, size_t len )
|
||||
{
|
||||
/* We expect the NULL parameter here. */
|
||||
if( ctx != NULL )
|
||||
return( -1 );
|
||||
|
||||
return( mbedtls_ctr_drbg_random( rng_ctx_global, dst, len ) );
|
||||
}
|
||||
#endif /* MBEDTLS_SSL_CONF_RNG */
|
||||
|
||||
int main( void )
|
||||
{
|
||||
int ret, len;
|
||||
@@ -224,7 +238,12 @@ int main( void )
|
||||
goto exit;
|
||||
}
|
||||
|
||||
#if !defined(MBEDTLS_SSL_CONF_RNG)
|
||||
mbedtls_ssl_conf_rng( &conf, mbedtls_ctr_drbg_random, &ctr_drbg );
|
||||
#else
|
||||
rng_ctx_global = &ctr_drbg;
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_DEBUG_C)
|
||||
mbedtls_ssl_conf_dbg( &conf, my_debug, stdout );
|
||||
#endif
|
||||
|
||||
@@ -166,6 +166,19 @@ enum exit_codes
|
||||
ssl_write_failed,
|
||||
};
|
||||
|
||||
#if defined(MBEDTLS_SSL_CONF_RNG)
|
||||
int rng_wrap( void *ctx, unsigned char *dst, size_t len );
|
||||
|
||||
mbedtls_ctr_drbg_context *rng_ctx_global = NULL;
|
||||
int rng_wrap( void *ctx, unsigned char *dst, size_t len )
|
||||
{
|
||||
/* We expect the NULL parameter here. */
|
||||
if( ctx != NULL )
|
||||
return( -1 );
|
||||
|
||||
return( mbedtls_ctr_drbg_random( rng_ctx_global, dst, len ) );
|
||||
}
|
||||
#endif /* MBEDTLS_SSL_CONF_RNG */
|
||||
|
||||
int main( void )
|
||||
{
|
||||
@@ -212,7 +225,7 @@ int main( void )
|
||||
#if !defined(MBEDTLS_SSL_CONF_RNG)
|
||||
mbedtls_ssl_conf_rng( &conf, mbedtls_ctr_drbg_random, &ctr_drbg );
|
||||
#else
|
||||
mbedtls_ssl_conf_rng_ctx( &conf, &ctr_drbg );
|
||||
rng_ctx_global = &ctr_drbg;
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED)
|
||||
|
||||
@@ -85,6 +85,20 @@ static void my_debug( void *ctx, int level,
|
||||
}
|
||||
#endif /* MBEDTLS_DEBUG_C */
|
||||
|
||||
#if defined(MBEDTLS_SSL_CONF_RNG)
|
||||
int rng_wrap( void *ctx, unsigned char *dst, size_t len );
|
||||
|
||||
mbedtls_ctr_drbg_context *rng_ctx_global = NULL;
|
||||
int rng_wrap( void *ctx, unsigned char *dst, size_t len )
|
||||
{
|
||||
/* We expect the NULL parameter here. */
|
||||
if( ctx != NULL )
|
||||
return( -1 );
|
||||
|
||||
return( mbedtls_ctr_drbg_random( rng_ctx_global, dst, len ) );
|
||||
}
|
||||
#endif /* MBEDTLS_SSL_CONF_RNG */
|
||||
|
||||
int main( void )
|
||||
{
|
||||
int ret = 1, len;
|
||||
@@ -179,7 +193,13 @@ int main( void )
|
||||
* but makes interop easier in this simplified example */
|
||||
mbedtls_ssl_conf_authmode( &conf, MBEDTLS_SSL_VERIFY_OPTIONAL );
|
||||
mbedtls_ssl_conf_ca_chain( &conf, &cacert, NULL );
|
||||
|
||||
#if !defined(MBEDTLS_SSL_CONF_RNG)
|
||||
mbedtls_ssl_conf_rng( &conf, mbedtls_ctr_drbg_random, &ctr_drbg );
|
||||
#else
|
||||
rng_ctx_global = &ctr_drbg;
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_DEBUG_C)
|
||||
mbedtls_ssl_conf_dbg( &conf, my_debug, stdout );
|
||||
#endif
|
||||
|
||||
@@ -889,6 +889,20 @@ int report_cid_usage( mbedtls_ssl_context *ssl,
|
||||
}
|
||||
#endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */
|
||||
|
||||
#if defined(MBEDTLS_SSL_CONF_RNG)
|
||||
int rng_wrap( void *ctx, unsigned char *dst, size_t len );
|
||||
|
||||
mbedtls_ctr_drbg_context *rng_ctx_global = NULL;
|
||||
int rng_wrap( void *ctx, unsigned char *dst, size_t len )
|
||||
{
|
||||
/* We expect the NULL parameter here. */
|
||||
if( ctx != NULL )
|
||||
return( -1 );
|
||||
|
||||
return( mbedtls_ctr_drbg_random( rng_ctx_global, dst, len ) );
|
||||
}
|
||||
#endif /* MBEDTLS_SSL_CONF_RNG */
|
||||
|
||||
int main( int argc, char *argv[] )
|
||||
{
|
||||
int ret = 0, len, tail_len, i, written, frags, retry_left;
|
||||
@@ -1942,7 +1956,7 @@ int main( int argc, char *argv[] )
|
||||
#if !defined(MBEDTLS_SSL_CONF_RNG)
|
||||
mbedtls_ssl_conf_rng( &conf, mbedtls_ctr_drbg_random, &ctr_drbg );
|
||||
#else
|
||||
mbedtls_ssl_conf_rng_ctx( &conf, &ctr_drbg );
|
||||
rng_ctx_global = &ctr_drbg;
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_DEBUG_C)
|
||||
|
||||
@@ -102,6 +102,20 @@ static void my_debug( void *ctx, int level,
|
||||
}
|
||||
#endif /* MBEDTLS_DEBUG_C */
|
||||
|
||||
#if defined(MBEDTLS_SSL_CONF_RNG)
|
||||
int rng_wrap( void *ctx, unsigned char *dst, size_t len );
|
||||
|
||||
mbedtls_ctr_drbg_context *rng_ctx_global = NULL;
|
||||
int rng_wrap( void *ctx, unsigned char *dst, size_t len )
|
||||
{
|
||||
/* We expect the NULL parameter here. */
|
||||
if( ctx != NULL )
|
||||
return( -1 );
|
||||
|
||||
return( mbedtls_ctr_drbg_random( rng_ctx_global, dst, len ) );
|
||||
}
|
||||
#endif /* MBEDTLS_SSL_CONF_RNG */
|
||||
|
||||
int main( void )
|
||||
{
|
||||
int ret = 1, len, cnt = 0, pid;
|
||||
@@ -196,7 +210,12 @@ int main( void )
|
||||
goto exit;
|
||||
}
|
||||
|
||||
#if !defined(MBEDTLS_SSL_CONF_RNG)
|
||||
mbedtls_ssl_conf_rng( &conf, mbedtls_ctr_drbg_random, &ctr_drbg );
|
||||
#else
|
||||
rng_ctx_global = &ctr_drbg;
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_DEBUG_C)
|
||||
mbedtls_ssl_conf_dbg( &conf, my_debug, stdout );
|
||||
#endif
|
||||
|
||||
@@ -361,6 +361,20 @@ static int write_and_get_response( mbedtls_net_context *sock_fd, unsigned char *
|
||||
while( 1 );
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_SSL_CONF_RNG)
|
||||
int rng_wrap( void *ctx, unsigned char *dst, size_t len );
|
||||
|
||||
mbedtls_ctr_drbg_context *rng_ctx_global = NULL;
|
||||
int rng_wrap( void *ctx, unsigned char *dst, size_t len )
|
||||
{
|
||||
/* We expect the NULL parameter here. */
|
||||
if( ctx != NULL )
|
||||
return( -1 );
|
||||
|
||||
return( mbedtls_ctr_drbg_random( rng_ctx_global, dst, len ) );
|
||||
}
|
||||
#endif /* MBEDTLS_SSL_CONF_RNG */
|
||||
|
||||
int main( int argc, char *argv[] )
|
||||
{
|
||||
int ret = 1, len;
|
||||
@@ -620,7 +634,12 @@ int main( int argc, char *argv[] )
|
||||
* but makes interop easier in this simplified example */
|
||||
mbedtls_ssl_conf_authmode( &conf, MBEDTLS_SSL_VERIFY_OPTIONAL );
|
||||
|
||||
#if !defined(MBEDTLS_SSL_CONF_RNG)
|
||||
mbedtls_ssl_conf_rng( &conf, mbedtls_ctr_drbg_random, &ctr_drbg );
|
||||
#else
|
||||
rng_ctx_global = &ctr_drbg;
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_DEBUG_C)
|
||||
mbedtls_ssl_conf_dbg( &conf, my_debug, stdout );
|
||||
#endif
|
||||
|
||||
@@ -325,6 +325,20 @@ static int thread_create( mbedtls_net_context *client_fd )
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_SSL_CONF_RNG)
|
||||
int rng_wrap( void *ctx, unsigned char *dst, size_t len );
|
||||
|
||||
mbedtls_ctr_drbg_context *rng_ctx_global = NULL;
|
||||
int rng_wrap( void *ctx, unsigned char *dst, size_t len )
|
||||
{
|
||||
/* We expect the NULL parameter here. */
|
||||
if( ctx != NULL )
|
||||
return( -1 );
|
||||
|
||||
return( mbedtls_ctr_drbg_random( rng_ctx_global, dst, len ) );
|
||||
}
|
||||
#endif /* MBEDTLS_SSL_CONF_RNG */
|
||||
|
||||
int main( void )
|
||||
{
|
||||
int ret;
|
||||
@@ -439,7 +453,12 @@ int main( void )
|
||||
goto exit;
|
||||
}
|
||||
|
||||
#if !defined(MBEDTLS_SSL_CONF_RNG)
|
||||
mbedtls_ssl_conf_rng( &conf, mbedtls_ctr_drbg_random, &ctr_drbg );
|
||||
#else
|
||||
rng_ctx_global = &ctr_drbg;
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_DEBUG_C)
|
||||
mbedtls_ssl_conf_dbg( &conf, my_mutexed_debug, stdout );
|
||||
#endif
|
||||
|
||||
@@ -97,6 +97,20 @@ static void my_debug( void *ctx, int level,
|
||||
}
|
||||
#endif /* MBEDTLS_DEBUG_C */
|
||||
|
||||
#if defined(MBEDTLS_SSL_CONF_RNG)
|
||||
int rng_wrap( void *ctx, unsigned char *dst, size_t len );
|
||||
|
||||
mbedtls_ctr_drbg_context *rng_ctx_global = NULL;
|
||||
int rng_wrap( void *ctx, unsigned char *dst, size_t len )
|
||||
{
|
||||
/* We expect the NULL parameter here. */
|
||||
if( ctx != NULL )
|
||||
return( -1 );
|
||||
|
||||
return( mbedtls_ctr_drbg_random( rng_ctx_global, dst, len ) );
|
||||
}
|
||||
#endif /* MBEDTLS_SSL_CONF_RNG */
|
||||
|
||||
int main( void )
|
||||
{
|
||||
int ret, len;
|
||||
@@ -212,7 +226,12 @@ int main( void )
|
||||
goto exit;
|
||||
}
|
||||
|
||||
#if !defined(MBEDTLS_SSL_CONF_RNG)
|
||||
mbedtls_ssl_conf_rng( &conf, mbedtls_ctr_drbg_random, &ctr_drbg );
|
||||
#else
|
||||
rng_ctx_global = &ctr_drbg;
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_DEBUG_C)
|
||||
mbedtls_ssl_conf_dbg( &conf, my_debug, stdout );
|
||||
#endif
|
||||
|
||||
@@ -1505,6 +1505,20 @@ int report_cid_usage( mbedtls_ssl_context *ssl,
|
||||
}
|
||||
#endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */
|
||||
|
||||
#if defined(MBEDTLS_SSL_CONF_RNG)
|
||||
int rng_wrap( void *ctx, unsigned char *dst, size_t len );
|
||||
|
||||
mbedtls_ctr_drbg_context *rng_ctx_global = NULL;
|
||||
int rng_wrap( void *ctx, unsigned char *dst, size_t len )
|
||||
{
|
||||
/* We expect the NULL parameter here. */
|
||||
if( ctx != NULL )
|
||||
return( -1 );
|
||||
|
||||
return( mbedtls_ctr_drbg_random( rng_ctx_global, dst, len ) );
|
||||
}
|
||||
#endif /* MBEDTLS_SSL_CONF_RNG */
|
||||
|
||||
int main( int argc, char *argv[] )
|
||||
{
|
||||
int ret = 0, len, written, frags, exchanges_left;
|
||||
@@ -2754,7 +2768,7 @@ int main( int argc, char *argv[] )
|
||||
#if !defined(MBEDTLS_SSL_CONF_RNG)
|
||||
mbedtls_ssl_conf_rng( &conf, mbedtls_ctr_drbg_random, &ctr_drbg );
|
||||
#else
|
||||
mbedtls_ssl_conf_rng_ctx( &conf, &ctr_drbg );
|
||||
rng_ctx_global = &ctr_drbg;
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_DEBUG_C)
|
||||
|
||||
@@ -149,6 +149,20 @@ static int my_verify( void *data, mbedtls_x509_crt *crt, int depth, uint32_t *fl
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_SSL_CONF_RNG)
|
||||
int rng_wrap( void *ctx, unsigned char *dst, size_t len );
|
||||
|
||||
mbedtls_ctr_drbg_context *rng_ctx_global = NULL;
|
||||
int rng_wrap( void *ctx, unsigned char *dst, size_t len )
|
||||
{
|
||||
/* We expect the NULL parameter here. */
|
||||
if( ctx != NULL )
|
||||
return( -1 );
|
||||
|
||||
return( mbedtls_ctr_drbg_random( rng_ctx_global, dst, len ) );
|
||||
}
|
||||
#endif /* MBEDTLS_SSL_CONF_RNG */
|
||||
|
||||
int main( int argc, char *argv[] )
|
||||
{
|
||||
int ret = 1;
|
||||
@@ -424,7 +438,12 @@ int main( int argc, char *argv[] )
|
||||
else
|
||||
mbedtls_ssl_conf_authmode( &conf, MBEDTLS_SSL_VERIFY_NONE );
|
||||
|
||||
mbedtls_ssl_conf_rng( &conf, mbedtls_ctr_drbg_random, &ctr_drbg );
|
||||
#if !defined(MBEDTLS_SSL_CONF_RNG)
|
||||
mbedtls_ssl_conf_rng( &conf, mbedtls_ctr_drbg_random, &ctr_drbg );
|
||||
#else
|
||||
rng_ctx_global = &ctr_drbg;
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_DEBUG_C)
|
||||
mbedtls_ssl_conf_dbg( &conf, my_debug, stdout );
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user