@@ -44,8 +44,14 @@ struct coap_security_s {
44
44
45
45
#if defined(MBEDTLS_CTR_DRBG_C )
46
46
mbedtls_ctr_drbg_context _drbg ;
47
+ #define DRBG_INIT mbedtls_ctr_drbg_init
48
+ #define DRBG_RANDOM mbedtls_ctr_drbg_random
49
+ #define DRBG_FREE mbedtls_ctr_drbg_free
47
50
#elif defined(MBEDTLS_HMAC_DRBG_C )
48
51
mbedtls_hmac_drbg_context _drbg ;
52
+ #define DRBG_INIT mbedtls_hmac_drbg_init
53
+ #define DRBG_RANDOM mbedtls_hmac_drbg_random
54
+ #define DRBG_FREE mbedtls_hmac_drbg_free
49
55
#else
50
56
#error "CTR or HMAC must be defined for coap_security_handler!"
51
57
#endif
@@ -122,11 +128,7 @@ static int coap_security_handler_init(coap_security_t *sec)
122
128
123
129
mbedtls_ssl_init (& sec -> _ssl );
124
130
mbedtls_ssl_config_init (& sec -> _conf );
125
- #if defined(MBEDTLS_CTR_DRBG_C )
126
- mbedtls_ctr_drbg_init (& sec -> _drbg );
127
- #elif defined(MBEDTLS_HMAC_DRBG_C )
128
- mbedtls_hmac_drbg_init (& sec -> _drbg );
129
- #endif
131
+ DRBG_INIT (& sec -> _drbg );
130
132
mbedtls_entropy_init (& sec -> _entropy );
131
133
132
134
#if defined(MBEDTLS_X509_CRT_PARSE_C )
@@ -157,6 +159,8 @@ static int coap_security_handler_init(coap_security_t *sec)
157
159
strlen (pers ))) != 0 ) {
158
160
return -1 ;
159
161
}
162
+ #else
163
+ #error "CTR or HMAC must be defined for coap_security_handler!"
160
164
#endif
161
165
return 0 ;
162
166
}
@@ -180,11 +184,9 @@ static void coap_security_handler_reset(coap_security_t *sec)
180
184
#endif
181
185
182
186
mbedtls_entropy_free (& sec -> _entropy );
183
- #if defined(MBEDTLS_CTR_DRBG_C )
184
- mbedtls_ctr_drbg_free (& sec -> _drbg );
185
- #elif defined(MBEDTLS_HMAC_DRBG_C )
186
- mbedtls_hmac_drbg_free (& sec -> _drbg );
187
- #endif
187
+
188
+ DRBG_FREE (& sec -> _drbg );
189
+
188
190
mbedtls_ssl_config_free (& sec -> _conf );
189
191
mbedtls_ssl_free (& sec -> _ssl );
190
192
#if defined(MBEDTLS_PLATFORM_C )
@@ -421,11 +423,7 @@ int coap_security_handler_connect_non_blocking(coap_security_t *sec, bool is_ser
421
423
}
422
424
423
425
#if !defined(MBEDTLS_SSL_CONF_RNG )
424
- #if defined(MBEDTLS_CTR_DRBG_C )
425
- mbedtls_ssl_conf_rng (& sec -> _conf , mbedtls_ctr_drbg_random , & sec -> _drbg );
426
- #elif defined(MBEDTLS_HMAC_DRBG_C )
427
- mbedtls_ssl_conf_rng (& sec -> _conf , mbedtls_hmac_drbg_random , & sec -> _drbg );
428
- #endif
426
+ mbedtls_ssl_conf_rng (& sec -> _conf , DRBG_RANDOM , & sec -> _drbg );
429
427
#endif
430
428
431
429
if ((mbedtls_ssl_setup (& sec -> _ssl , & sec -> _conf )) != 0 ) {
0 commit comments