@@ -331,6 +331,19 @@ bool net_socket_is_tls(void *obj)
331331 return PART_OF_ARRAY (tls_contexts , (struct tls_context * )obj );
332332}
333333
334+ static int tls_ctr_drbg_random (void * ctx , unsigned char * buf , size_t len )
335+ {
336+ ARG_UNUSED (ctx );
337+
338+ #if defined(CONFIG_CSPRNG_ENABLED )
339+ return sys_csrand_get (buf , len );
340+ #else
341+ sys_rand_get (buf , len );
342+
343+ return 0 ;
344+ #endif
345+ }
346+
334347#if defined(CONFIG_NET_SOCKETS_ENABLE_DTLS )
335348/* mbedTLS-defined function for setting timer. */
336349static void dtls_timing_set_delay (void * data , uint32_t int_ms , uint32_t fin_ms )
@@ -1428,7 +1441,8 @@ static int tls_set_private_key(struct tls_context *tls,
14281441 int err ;
14291442
14301443 err = mbedtls_pk_parse_key (& tls -> priv_key , priv_key -> buf ,
1431- priv_key -> len , NULL , 0 );
1444+ priv_key -> len , NULL , 0 ,
1445+ tls_ctr_drbg_random , NULL );
14321446 if (err != 0 ) {
14331447 return - EINVAL ;
14341448 }
@@ -1814,7 +1828,9 @@ static int tls_mbedtls_init(struct tls_context *context, bool is_server)
18141828
18151829 /* Configure cookie for DTLS server */
18161830 if (role == MBEDTLS_SSL_IS_SERVER ) {
1817- ret = mbedtls_ssl_cookie_setup (& context -> cookie );
1831+ ret = mbedtls_ssl_cookie_setup (& context -> cookie ,
1832+ tls_ctr_drbg_random ,
1833+ NULL );
18181834 if (ret != 0 ) {
18191835 return - ENOMEM ;
18201836 }
@@ -1839,6 +1855,10 @@ static int tls_mbedtls_init(struct tls_context *context, bool is_server)
18391855 context -> options .verify_level );
18401856 }
18411857
1858+ mbedtls_ssl_conf_rng (& context -> config ,
1859+ tls_ctr_drbg_random ,
1860+ NULL );
1861+
18421862 ret = tls_mbedtls_set_credentials (context );
18431863 if (ret != 0 ) {
18441864 return ret ;
@@ -1935,7 +1955,8 @@ static int tls_check_priv_key(struct tls_credential *priv_key)
19351955 mbedtls_pk_init (& key_ctx );
19361956
19371957 err = mbedtls_pk_parse_key (& key_ctx , priv_key -> buf ,
1938- priv_key -> len , NULL , 0 );
1958+ priv_key -> len , NULL , 0 ,
1959+ tls_ctr_drbg_random , NULL );
19391960 if (err != 0 ) {
19401961 NET_ERR ("Failed to parse %s on tag %d, err: -0x%x" ,
19411962 "private key" , priv_key -> tag , - err );
0 commit comments