1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

pkg/mbedtls/init: add dedicated mbedtls auto-init module

This commit is contained in:
Fabian Hüßler 2023-03-28 10:43:48 +02:00
parent e2d6f97982
commit f9ecfab2c1
7 changed files with 66 additions and 2 deletions

View File

@ -1,3 +1,5 @@
DEFAULT_MODULE += auto_init_mbedtls
ifneq (,$(filter mbedtls_%,$(USEMODULE)))
USEMODULE += mbedtls_contrib
endif

View File

@ -35,6 +35,11 @@ ifneq (,$(filter mbedtls_self_test,$(USEMODULE)))
CFLAGS += -DCONFIG_MBEDTLS_SELF_TEST=1
endif
NO_PSEUDOMODULES += auto_init_mbedtls
ifneq (,$(filter auto_init_mbedtls,$(USEMODULE)))
DIRS += $(RIOTBASE)/pkg/mbedtls/init
endif
ifneq (,$(filter mbedtls_crypto,$(USEMODULE)))
include $(RIOTPKG)/mbedtls/contrib/crypto/Makefile.include
endif

View File

@ -47,7 +47,7 @@ int mbedtls_platform_mutex_unlock(mbedtls_threading_mutex_t *mutex)
return 0;
}
void auto_init_mbedtls(void)
void threading_mbedtls_riot_init(void)
{
/* Configure mbedTLS to use RIOT specific threading functions. */
mbedtls_threading_set_alt( mbedtls_platform_mutex_init,

View File

@ -35,6 +35,11 @@ typedef struct {
mutex_t riot_mutex; /**< RIOT mutex structure */
} mbedtls_threading_mutex_t;
/**
* @brief Initialize alternative threading API of RIOT
*/
void threading_mbedtls_riot_init(void);
#endif /* MBEDTLS_THREADING_ALT */
#ifdef __cplusplus

View File

@ -0,0 +1,3 @@
MODULE = auto_init_mbedtls
include $(RIOTBASE)/Makefile.base

View File

@ -0,0 +1,49 @@
/*
* Copyright (C) 2021 HAW Hamburg
* 2023 ML!PA Consulting Gmbh
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @ingroup sys_auto_init
* @{
* @file
* @brief Initializes RIOT mbedtls modue
*
* @author Peter Kietzmann <peter.kietzmann@haw-hamburg.de>
* @author Fabian Hüßler <fabian.huessler@ml-pa.com>
* @}
*/
#include "modules.h"
#include "log.h"
#if IS_USED(MODULE_MBEDTLS_THREADING)
#include "mbedtls/threading.h"
#include "threading_alt.h"
#endif
#if IS_USED(MODULE_MBEDTLS_ENTROPY)
#include "entropy_mbedtls_riot.h"
#endif
#if IS_USED(MODULE_MBEDTLS_RANDOM)
#include "random_mbedtls_riot.h"
#endif
#define ENABLE_DEBUG 0
#include "debug.h"
void auto_init_mbedtls(void)
{
#if IS_USED(MODULE_MBEDTLS_THREADING_ALT)
threading_mbedtls_riot_init();
#endif
#if IS_USED(MODULE_MBEDTLS_ENTROPY)
entropy_mbedtls_riot_init();
#endif
#if IS_USED(MODULE_MBEDTLS_RANDOM)
random_mbedtls_riot_init();
#endif
}

View File

@ -272,7 +272,7 @@ extern void suit_init_conditions(void);
AUTO_INIT(suit_init_conditions,
AUTO_INIT_PRIO_MOD_SUIT);
#endif
#if IS_USED(MODULE_MBEDTLS)
#if IS_USED(MODULE_AUTO_INIT_MBEDTLS)
extern void auto_init_mbedtls(void);
AUTO_INIT(auto_init_mbedtls,
AUTO_INIT_PRIO_MOD_MBEDTLS);