mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
pkg/libcose: add RIOT as crypto backend
This commit is contained in:
parent
8b6ddca6e9
commit
c7b9657ff5
@ -31,6 +31,11 @@ config MODULE_LIBCOSE_CRYPT_MONOCYPHER
|
||||
depends on TEST_KCONFIG
|
||||
depends on PACKAGE_MONOCYPHER
|
||||
|
||||
config MODULE_LIBCOSE_CRYPT_RIOT
|
||||
bool "COSE use RIOT backend"
|
||||
depends on TEST_KCONFIG
|
||||
select MODULE_CRYPTO
|
||||
|
||||
config MODULE_LIBCOSE_CRYPT_INIT
|
||||
bool "LibCose Crypt Initialization functions"
|
||||
default y
|
||||
|
@ -16,6 +16,9 @@ endif
|
||||
ifneq (,$(filter libcose_crypt_monocypher,$(USEMODULE)))
|
||||
USEPKG += monocypher
|
||||
endif
|
||||
ifneq (,$(filter libcose_crypt_riot,$(USEMODULE)))
|
||||
USEMODULE += crypto
|
||||
endif
|
||||
|
||||
DEFAULT_MODULE += auto_init_libcose_crypt
|
||||
DEFAULT_MODULE += libcose_crypt_init
|
||||
DEFAULT_MODULE += auto_init_libcose_crypt
|
||||
|
@ -1,4 +1,7 @@
|
||||
INCLUDES += -I$(PKGDIRBASE)/libcose/include
|
||||
INCLUDES += -I$(PKGDIRBASE)/libcose/include \
|
||||
-I$(RIOTBASE)/pkg/libcose/include \
|
||||
#
|
||||
|
||||
CFLAGS += -DUSE_CBOR_CONTEXT
|
||||
|
||||
ifneq (,$(filter libcose_crypt_hacl,$(USEMODULE)))
|
||||
@ -13,6 +16,10 @@ endif
|
||||
ifneq (,$(filter libcose_crypt_monocypher,$(USEMODULE)))
|
||||
CFLAGS += -DCRYPTO_MONOCYPHER
|
||||
endif
|
||||
ifneq (,$(filter libcose_crypt_riot,$(USEMODULE)))
|
||||
CFLAGS += -DCRYPTO_RIOT
|
||||
DIRS += $(RIOTBASE)/pkg/libcose/contrib
|
||||
endif
|
||||
ifneq (,$(filter libcose_crypt_init,$(USEMODULE)))
|
||||
DIRS += $(RIOTBASE)/pkg/libcose/init
|
||||
endif
|
||||
|
54
pkg/libcose/contrib/libcose_riot_crypto.c
Normal file
54
pkg/libcose/contrib/libcose_riot_crypto.c
Normal file
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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 for libcose implementation
|
||||
*
|
||||
* @author Francisco Molina <francois-xavier.molina@inria.fr>
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "crypto/chacha20poly1305.h"
|
||||
|
||||
#include "cose.h"
|
||||
#include "cose/crypto.h"
|
||||
#include "cose/crypto/selectors.h"
|
||||
|
||||
int cose_crypto_aead_encrypt_chachapoly(uint8_t *c, size_t *clen,
|
||||
const uint8_t *msg, size_t msglen,
|
||||
const uint8_t *aad, size_t aadlen,
|
||||
const uint8_t *npub, const uint8_t *k)
|
||||
{
|
||||
if (*clen < msglen + CHACHA20POLY1305_TAG_BYTES) {
|
||||
return COSE_ERR_INVALID_PARAM;
|
||||
}
|
||||
chacha20poly1305_encrypt(c, msg, msglen, aad, aadlen, k, npub);
|
||||
*clen = msglen + CHACHA20POLY1305_TAG_BYTES;
|
||||
return COSE_OK;
|
||||
}
|
||||
|
||||
int cose_crypto_aead_decrypt_chachapoly(uint8_t *msg, size_t *msglen,
|
||||
const uint8_t *c, size_t clen,
|
||||
const uint8_t *aad, size_t aadlen,
|
||||
const uint8_t *npub, const uint8_t *k)
|
||||
{
|
||||
if (chacha20poly1305_decrypt(c, clen, msg, msglen, aad, aadlen, k, npub) == 1) {
|
||||
return COSE_OK;
|
||||
}
|
||||
else {
|
||||
return COSE_ERR_CRYPTO;
|
||||
}
|
||||
}
|
@ -31,6 +31,14 @@ extern "C" {
|
||||
#define AUTO_INIT_PRIO_MOD_LIBCOSE 1050
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @name list of provided algorithms
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
#define HAVE_ALGO_CHACHA20POLY1305
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @brief Initialize libCOSE RIOT crypto backend
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user