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

pkg/libcose: bump, set random function on init

This commit is contained in:
Francisco Molina 2022-04-25 16:07:08 +02:00
parent 5a6bb44660
commit 8b6ddca6e9
12 changed files with 136 additions and 2 deletions

View File

@ -14,6 +14,10 @@ ifneq (,$(filter auto_init_saul,$(USEMODULE)))
USEMODULE += saul_init_devs USEMODULE += saul_init_devs
endif endif
ifneq (,$(filter auto_init_libcose_crypt,$(USEMODULE)))
USEMODULE += libcose_crypt_init
endif
ifneq (,$(filter xtimer,$(USEMODULE))) ifneq (,$(filter xtimer,$(USEMODULE)))
ifeq (,$(filter ztimer_xtimer_compat,$(USEMODULE))) ifeq (,$(filter ztimer_xtimer_compat,$(USEMODULE)))
USEMODULE += div USEMODULE += div

View File

@ -31,6 +31,16 @@ config MODULE_LIBCOSE_CRYPT_MONOCYPHER
depends on TEST_KCONFIG depends on TEST_KCONFIG
depends on PACKAGE_MONOCYPHER depends on PACKAGE_MONOCYPHER
config MODULE_LIBCOSE_CRYPT_INIT
bool "LibCose Crypt Initialization functions"
default y
config MODULE_AUTO_INIT_LIBCOSE_CRYPT
bool "Auto initialize LibCose Crypt"
depends on MODULE_AUTO_INIT
select MODULE_LIBCOSE_CRYPT_INIT
default y
endif # PACKAGE_LIBCOSE endif # PACKAGE_LIBCOSE
config MODULE_LIBCOSE_CRYPT config MODULE_LIBCOSE_CRYPT

View File

@ -1,6 +1,6 @@
PKG_NAME=libcose PKG_NAME=libcose
PKG_URL=https://github.com/bergzand/libcose PKG_URL=https://github.com/bergzand/libcose
PKG_VERSION=2929fdce7affbd5bb9db201370d95d8f7cf680f9 PKG_VERSION=ea1fed87d6ca9b478f8bed323af97e6b192c0a6d
PKG_LICENSE=LGPL PKG_LICENSE=LGPL
include $(RIOTBASE)/pkg/pkg.mk include $(RIOTBASE)/pkg/pkg.mk

View File

@ -13,3 +13,9 @@ endif
ifneq (,$(filter libcose_crypt_tinycrypt,$(USEMODULE))) ifneq (,$(filter libcose_crypt_tinycrypt,$(USEMODULE)))
USEPKG += tinycrypt USEPKG += tinycrypt
endif endif
ifneq (,$(filter libcose_crypt_monocypher,$(USEMODULE)))
USEPKG += monocypher
endif
DEFAULT_MODULE += auto_init_libcose_crypt
DEFAULT_MODULE += libcose_crypt_init

View File

@ -10,6 +10,16 @@ endif
ifneq (,$(filter libcose_crypt_tinycrypt,$(USEMODULE))) ifneq (,$(filter libcose_crypt_tinycrypt,$(USEMODULE)))
CFLAGS += -DCRYPTO_TINYCRYPT CFLAGS += -DCRYPTO_TINYCRYPT
endif endif
ifneq (,$(filter libcose_crypt_monocypher,$(USEMODULE)))
CFLAGS += -DCRYPTO_MONOCYPHER
endif
ifneq (,$(filter libcose_crypt_init,$(USEMODULE)))
DIRS += $(RIOTBASE)/pkg/libcose/init
endif
# Declare pseudomodules here to be selfcontained # Declare pseudomodules here to be selfcontained
PSEUDOMODULES += libcose_crypt_% PSEUDOMODULES += libcose_crypt_c25519
PSEUDOMODULES += libcose_crypt_hacl
PSEUDOMODULES += libcose_crypt_tinycrypt
PSEUDOMODULES += libcose_crypt_monocypher
PSEUDOMODULES += auto_init_libcose_crypt

View File

@ -1,4 +1,6 @@
MODULE := libcose_crypt MODULE := libcose_crypt
SUBMODULES = 1 SUBMODULES = 1
SRC += keygen_symm.c
include $(RIOTBASE)/Makefile.base include $(RIOTBASE)/Makefile.base

View File

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

View File

@ -0,0 +1,48 @@
/*
* Copyright (C) 2022 Inria
*
* 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 pkg_libcose
*
* @{
*
* @file
* @brief Crypto function api for glueing RIOT crypto libraries
*
* @author Francisco Molina <francois-xavier.molina@inria.fr>
*/
#ifndef COSE_CRYPTO_RIOT_H
#define COSE_CRYPTO_RIOT_H
#ifdef __cplusplus
extern "C" {
#endif
#ifndef AUTO_INIT_PRIO_MOD_LIBCOSE
/**
* @brief libCOSE init priority
*/
#define AUTO_INIT_PRIO_MOD_LIBCOSE 1050
#endif
/**
* @brief Initialize libCOSE RIOT crypto backend
*
* @note Automatically called if 'auto_init_libcose_crypt_riot' is included
*
*/
void libcose_crypt_init(void);
#ifdef __cplusplus
}
#endif
#endif /* COSE_CRYPTO_RIOT_H */
/** @} */

View File

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

48
pkg/libcose/init/init.c Normal file
View File

@ -0,0 +1,48 @@
/*
* Copyright (C) 2022 Inria
*
* 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 pkg_libcose
* @{
*
* @file
* @brief RIOT as a crypto backend common functions
*
* @author Francisco Molina <francois-xavier.molina@inria.fr>
*
* @}
*/
#include <stdint.h>
#include "random.h"
#include "kernel_defines.h"
#include "xfa.h"
#include "cose/crypto.h"
#if IS_USED(MODULE_AUTO_INIT)
#include "auto_init_utils.h"
#endif
static int _riot_random_bytes(void* arg, unsigned char * buf, size_t len)
{
(void)arg;
random_bytes((uint8_t*) buf, len);
return 1;
}
void libcose_crypt_init(void)
{
cose_crypt_set_rng(_riot_random_bytes, NULL);
}
#if IS_USED(MODULE_AUTO_INIT_LIBCOSE_CRYPT)
/* initialize just after random module */
AUTO_INIT(libcose_crypt_init, AUTO_INIT_PRIO_MOD_LIBCOSE);
#endif