Skip to content

Commit 89a497a

Browse files
author
Arto Kinnunen
committed
Merge branch 'release_internal' into release_external
* release_internal: MBEDTLS_SSL_EXPORT_KEYS added to Nanostack's tls_sec_prot_lib Added missing optimizations based on mbedtls/baremetal.h config Added new global rng, needed for MbedTLS optimisations Prepare for upcoming MbedTLS changes Fixed error of function 'mac_fcf_lenght' Fixed error of structure Fixed spelling mistake of structure
2 parents 00ea3fb + c8cc660 commit 89a497a

File tree

5 files changed

+45
-21
lines changed

5 files changed

+45
-21
lines changed

nanostack/ns_sha256.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,45 +61,45 @@ static inline void ns_sha256_clone(ns_sha256_context *dst,
6161

6262
static inline void ns_sha256_starts(ns_sha256_context *ctx)
6363
{
64-
mbedtls_sha256_starts(ctx, 0);
64+
(void)mbedtls_sha256_starts_ret(ctx, 0);
6565
}
6666

6767
static inline void ns_sha256_update(ns_sha256_context *ctx, const void *input,
6868
size_t ilen)
6969
{
70-
mbedtls_sha256_update(ctx, input, ilen);
70+
(void)mbedtls_sha256_update_ret(ctx, input, ilen);
7171
}
7272

7373
static inline void ns_sha256_finish(ns_sha256_context *ctx, void *output)
7474
{
75-
mbedtls_sha256_finish(ctx, output);
75+
(void)mbedtls_sha256_finish_ret(ctx, output);
7676
}
7777

7878
static inline void ns_sha256(const void *input, size_t ilen, void *output)
7979
{
80-
mbedtls_sha256(input, ilen, output, 0);
80+
(void)mbedtls_sha256_ret(input, ilen, output, 0);
8181
}
8282

8383
/* Extensions to standard mbed TLS - output the first bits of a hash only */
8484
/* Number of bits must be a multiple of 32, and <=256 */
8585
static inline void ns_sha256_finish_nbits(ns_sha256_context *ctx, void *output, unsigned obits)
8686
{
8787
if (obits == 256) {
88-
mbedtls_sha256_finish(ctx, output);
88+
(void)mbedtls_sha256_finish_ret(ctx, output);
8989
} else {
9090
uint8_t sha256[32];
91-
mbedtls_sha256_finish(ctx, sha256);
91+
(void)mbedtls_sha256_finish_ret(ctx, sha256);
9292
memcpy(output, sha256, obits / 8);
9393
}
9494
}
9595

9696
static inline void ns_sha256_nbits(const void *input, size_t ilen, void *output, unsigned obits)
9797
{
9898
if (obits == 256) {
99-
mbedtls_sha256(input, ilen, output, 0);
99+
(void)mbedtls_sha256_ret(input, ilen, output, 0);
100100
} else {
101101
uint8_t sha256[32];
102-
mbedtls_sha256(input, ilen, sha256, 0);
102+
(void)mbedtls_sha256_ret(input, ilen, sha256, 0);
103103
memcpy(output, sha256, obits / 8);
104104
}
105105
}

source/MAC/IEEE802_15_4/mac_header_helper_functions.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ static uint8_t *mcps_mac_security_aux_header_start_pointer_get(const mac_pre_par
3232
static uint8_t *mac_header_information_elements_write(const mac_pre_build_frame_t *buffer, uint8_t *ptr);
3333

3434

35-
static uint8_t mac_fcf_lenght(const mac_fcf_sequence_t *header)
35+
static uint8_t mac_fcf_length(const mac_fcf_sequence_t *header)
3636
{
3737
uint8_t length;
3838
if (header->frameVersion == MAC_FRAME_VERSION_2015) {
@@ -298,7 +298,7 @@ static uint8_t *mac_header_write_fcf_dsn(const mac_fcf_sequence_t *header, uint8
298298
uint16_t mac_header_off_set_to_aux_header(const mac_fcf_sequence_t *fcf)
299299
{
300300
//Skip first FCF & address field
301-
uint16_t offset = mac_fcf_lenght(fcf);//Skip FCF + DSN
301+
uint16_t offset = mac_fcf_length(fcf);//Skip FCF + DSN
302302
offset += mac_dst_address_length_with_panid(fcf);
303303
offset += mac_address_length(fcf->SrcAddrMode);
304304
if (fcf->SrcPanPresents) {
@@ -351,7 +351,7 @@ static bool mac_header_pan_full_compressed(const mac_fcf_sequence_t *header)
351351

352352
static uint16_t mac_header_read_src_pan(const mac_fcf_sequence_t *header, const uint8_t *ptr)
353353
{
354-
ptr += mac_fcf_lenght(header);//Skip FCF + DSN
354+
ptr += mac_fcf_length(header);//Skip FCF + DSN
355355

356356
ptr += mac_dst_address_length_with_panid(header); //Skip Dst panID & Address
357357

@@ -360,7 +360,7 @@ static uint16_t mac_header_read_src_pan(const mac_fcf_sequence_t *header, const
360360

361361
static uint16_t mac_header_read_dst_pan(const mac_fcf_sequence_t *header, const uint8_t *ptr)
362362
{
363-
ptr += mac_fcf_lenght(header);//Skip FCF + DSN
363+
ptr += mac_fcf_length(header);//Skip FCF + DSN
364364

365365
return common_read_16_bit_inverse(ptr);
366366
}
@@ -403,7 +403,7 @@ void mac_header_get_src_address(const mac_fcf_sequence_t *header, const uint8_t
403403
return;
404404
}
405405

406-
ptr += mac_fcf_lenght(header);//Skip FCF + DSN
406+
ptr += mac_fcf_length(header);//Skip FCF + DSN
407407

408408
ptr += mac_dst_address_length_with_panid(header);
409409

@@ -430,7 +430,7 @@ void mac_header_get_dst_address(const mac_fcf_sequence_t *header, const uint8_t
430430
}
431431
uint8_t address_len, address_index, i;
432432

433-
ptr += mac_fcf_lenght(header);//Skip FCF + DSN
433+
ptr += mac_fcf_length(header);//Skip FCF + DSN
434434

435435
address_len = mac_address_length(header->DstAddrMode);
436436

source/MAC/IEEE802_15_4/mac_security_mib.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ static int mac_sec_mib_frame_counter_key_buffer_allocate(protocol_interface_rf_m
9090
mlme_key_descriptor_t *key_descriptor_list = rf_mac_setup->key_description_table;
9191
uint32_t *frame_counter_pointer = rf_mac_setup->key_device_frame_counter_list_buffer;
9292
for (uint8_t i = 0; i < rf_mac_setup->key_description_table_size; i++) {
93-
key_descriptor_list->KeyDeviceFrameCouterList = frame_counter_pointer;
93+
key_descriptor_list->KeyDeviceFrameCounterList = frame_counter_pointer;
9494
key_descriptor_list->KeyFrameCounterPerKey = true;
9595
key_descriptor_list->KeyFrameCounter = 0;
9696
//Update Pointers
@@ -105,7 +105,7 @@ static void mac_sec_mib_frame_counter_key_buffer_free(protocol_interface_rf_mac_
105105
{
106106
mlme_key_descriptor_t *key_descriptor_list = rf_mac_setup->key_description_table;
107107
for (uint8_t i = 0; i < rf_mac_setup->key_description_table_size; i++) {
108-
key_descriptor_list->KeyDeviceFrameCouterList = NULL;
108+
key_descriptor_list->KeyDeviceFrameCounterList = NULL;
109109
key_descriptor_list->KeyFrameCounterPerKey = false;
110110
//Update Pointers
111111
key_descriptor_list++;
@@ -368,7 +368,7 @@ int8_t mac_sec_mib_key_description_set(uint8_t atribute_index, mlme_key_descript
368368
key_ptr->KeyFrameCounter = 0;
369369
if (key_ptr->KeyDeviceListEntries == 0) {
370370
//Clear all frame counters from old possible user's
371-
uint32_t *counter_ptr = key_ptr->KeyDeviceFrameCouterList;
371+
uint32_t *counter_ptr = key_ptr->KeyDeviceFrameCounterList;
372372
for (int i = 0; i < rf_mac_setup->device_description_table_size; i++) {
373373
*counter_ptr++ = 0;
374374
}
@@ -613,7 +613,7 @@ void mac_sec_mib_key_outgoing_frame_counter_decrement(struct protocol_interface_
613613
void mac_sec_mib_key_device_frame_counter_set(mlme_key_descriptor_t *key_descpription_table, mlme_device_descriptor_t *device_info, uint32_t frame_counter, uint8_t attribute_index)
614614
{
615615
if (key_descpription_table->KeyFrameCounterPerKey) {
616-
uint32_t *counter_ptr = key_descpription_table->KeyDeviceFrameCouterList + attribute_index;
616+
uint32_t *counter_ptr = key_descpription_table->KeyDeviceFrameCounterList + attribute_index;
617617
*counter_ptr = frame_counter;
618618
} else {
619619
device_info->FrameCounter = frame_counter;
@@ -623,7 +623,7 @@ void mac_sec_mib_key_device_frame_counter_set(mlme_key_descriptor_t *key_descpri
623623
uint32_t mac_mib_key_device_frame_counter_get(mlme_key_descriptor_t *key_descpription_table, mlme_device_descriptor_t *device_info, uint8_t attribute_index)
624624
{
625625
if (key_descpription_table->KeyFrameCounterPerKey) {
626-
uint32_t *counter_ptr = key_descpription_table->KeyDeviceFrameCouterList + attribute_index;
626+
uint32_t *counter_ptr = key_descpription_table->KeyDeviceFrameCounterList + attribute_index;
627627
return *counter_ptr;
628628
}
629629
return device_info->FrameCounter;

source/MAC/IEEE802_15_4/mac_security_mib.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ typedef struct mlme_key_descriptor_s {
2727
mlme_key_id_lookup_descriptor_t *KeyIdLookupList;
2828
mlme_key_device_descriptor_t *KeyDeviceList;
2929
mlme_key_usage_descriptor_t *KeyUsageList;
30-
uint32_t *KeyDeviceFrameCouterList;
30+
uint32_t *KeyDeviceFrameCounterList;
3131
uint32_t KeyFrameCounter;
3232
uint8_t Key[16];
3333
uint8_t KeyDeviceListSize;

source/Security/protocols/tls_sec_prot/tls_sec_prot_lib.c

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#include MBEDTLS_CONFIG_FILE
2525
#endif
2626

27-
#if defined(MBEDTLS_SSL_TLS_C) && defined(MBEDTLS_X509_CRT_PARSE_C)
27+
#if defined(MBEDTLS_SSL_TLS_C) && defined(MBEDTLS_X509_CRT_PARSE_C) && defined(MBEDTLS_SSL_EXPORT_KEYS) /* EXPORT_KEYS not supported by mbedtls baremetal yet */
2828
#define WS_MBEDTLS_SECURITY_ENABLED
2929
#endif
3030

@@ -40,7 +40,9 @@
4040
#include "Security/protocols/sec_prot_certs.h"
4141
#include "Security/protocols/tls_sec_prot/tls_sec_prot_lib.h"
4242

43+
#if defined(MBEDTLS_SSL_TLS_C) && defined(MBEDTLS_X509_CRT_PARSE_C) && defined(MBEDTLS_SSL_EXPORT_KEYS) /* EXPORT_KEYS not supported by mbedtls baremetal yet */
4344
#ifdef WS_MBEDTLS_SECURITY_ENABLED
45+
#endif
4446

4547
#include "mbedtls/sha256.h"
4648
#include "mbedtls/error.h"
@@ -327,8 +329,10 @@ int8_t tls_sec_prot_lib_connect(tls_security_t *sec, bool is_server, const sec_p
327329
return -1;
328330
}
329331

332+
#if !defined(MBEDTLS_SSL_CONF_RNG)
330333
// Configure random number generator
331334
mbedtls_ssl_conf_rng(&sec->conf, mbedtls_ctr_drbg_random, &sec->ctr_drbg);
335+
#endif
332336

333337
#ifdef MBEDTLS_ECP_RESTARTABLE
334338
// Set ECC calculation maximum operations (affects only client)
@@ -340,16 +344,30 @@ int8_t tls_sec_prot_lib_connect(tls_security_t *sec, bool is_server, const sec_p
340344
return -1;
341345
}
342346

347+
// Defines MBEDTLS_SSL_CONF_RECV/SEND/RECV_TIMEOUT define global functions which should be the same for all
348+
// callers of mbedtls_ssl_set_bio_ctx and there should be only one ssl context. If these rules don't apply,
349+
// these defines can't be used.
350+
#if !defined(MBEDTLS_SSL_CONF_RECV) && !defined(MBEDTLS_SSL_CONF_SEND) && !defined(MBEDTLS_SSL_CONF_RECV_TIMEOUT)
343351
// Set calbacks
344352
mbedtls_ssl_set_bio(&sec->ssl, sec, tls_sec_prot_lib_ssl_send, tls_sec_prot_lib_ssl_recv, NULL);
353+
#else
354+
mbedtls_ssl_set_bio_ctx(&sec->ssl, sec);
355+
#endif /* !defined(MBEDTLS_SSL_CONF_RECV) && !defined(MBEDTLS_SSL_CONF_SEND) && !defined(MBEDTLS_SSL_CONF_RECV_TIMEOUT) */
356+
357+
// Defines MBEDTLS_SSL_CONF_SET_TIMER/GET_TIMER define global functions which should be the same for all
358+
// callers of mbedtls_ssl_set_timer_cb and there should be only one ssl context. If these rules don't apply,
359+
// these defines can't be used.
360+
#if !defined(MBEDTLS_SSL_CONF_SET_TIMER) && !defined(MBEDTLS_SSL_CONF_GET_TIMER)
345361
mbedtls_ssl_set_timer_cb(&sec->ssl, sec, tls_sec_prot_lib_ssl_set_timer, tls_sec_prot_lib_ssl_get_timer);
362+
#endif /* !defined(MBEDTLS_SSL_CONF_SET_TIMER) && !defined(MBEDTLS_SSL_CONF_GET_TIMER) */
346363

347364
// Configure certificates, keys and certificate revocation list
348365
if (tls_sec_prot_lib_configure_certificates(sec, certs) != 0) {
349366
tr_error("cert conf fail");
350367
return -1;
351368
}
352369

370+
#if !defined(MBEDTLS_SSL_CONF_SINGLE_CIPHERSUITE)
353371
// Configure ciphersuites
354372
static const int sec_suites[] = {
355373
MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8,
@@ -358,6 +376,7 @@ int8_t tls_sec_prot_lib_connect(tls_security_t *sec, bool is_server, const sec_p
358376
0
359377
};
360378
mbedtls_ssl_conf_ciphersuites(&sec->conf, sec_suites);
379+
#endif /* !defined(MBEDTLS_SSL_CONF_SINGLE_CIPHERSUITE) */
361380

362381
#ifdef TLS_SEC_PROT_LIB_TLS_DEBUG
363382
mbedtls_ssl_conf_dbg(&sec->conf, tls_sec_prot_lib_debug, sec);
@@ -367,8 +386,13 @@ int8_t tls_sec_prot_lib_connect(tls_security_t *sec, bool is_server, const sec_p
367386
// Export keys callback
368387
mbedtls_ssl_conf_export_keys_ext_cb(&sec->conf, tls_sec_prot_lib_ssl_export_keys, sec);
369388

389+
#if !defined(MBEDTLS_SSL_CONF_MIN_MINOR_VER) || !defined(MBEDTLS_SSL_CONF_MIN_MAJOR_VER)
370390
mbedtls_ssl_conf_min_version(&sec->conf, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3);
391+
#endif /* !defined(MBEDTLS_SSL_CONF_MIN_MINOR_VER) || !defined(MBEDTLS_SSL_CONF_MIN_MAJOR_VER) */
392+
393+
#if !defined(MBEDTLS_SSL_CONF_MAX_MINOR_VER) || !defined(MBEDTLS_SSL_CONF_MAX_MAJOR_VER)
371394
mbedtls_ssl_conf_max_version(&sec->conf, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3);
395+
#endif /* !defined(MBEDTLS_SSL_CONF_MAX_MINOR_VER) || !defined(MBEDTLS_SSL_CONF_MAX_MAJOR_VER) */
372396

373397
// Set certificate verify callback
374398
mbedtls_ssl_set_verify(&sec->ssl, tls_sec_prot_lib_x509_crt_verify, sec);

0 commit comments

Comments
 (0)