Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
ea2f531
Integrate Nano CBOR leaving the old cbor library as a backup
dmochkas Jun 26, 2026
be3986f
Changed CBorStream abstraction paradigm
dcostan Jul 2, 2026
45a998c
Fixed integer static casts and NanoCBOR infinite loops
dcostan Jul 3, 2026
fc93a4d
Changed CBorStream abstraction paradigm and general fixes
dcostan Jul 2, 2026
bbd7c8a
Merge branch 'libcose_integration' of github.com:dmochkas/rmw_desert_…
dmochkas Jul 8, 2026
78b5a40
Implement security layer with cose
dmochkas Jul 8, 2026
75bc70f
Downgrade NanoCBOR to compatible version
dmochkas Jul 8, 2026
efffb9f
Fixed a new nosense bug in CMakeLists
dcostan Jul 9, 2026
48e0a46
Fixed another compile error
dcostan Jul 9, 2026
37ea31d
Changed to coherent notations in CMakeList
dcostan Jul 9, 2026
ef45888
Cleanup
dcostan Jul 10, 2026
da8db26
Implemented runtime key checks
dcostan Jul 10, 2026
c73b685
Brace style fix
dcostan Jul 10, 2026
2ce10aa
Brace style fix bis
dcostan Jul 10, 2026
a8c0c14
Prevent cherry-pick and patch error for backport
dcostan Jul 13, 2026
0d7ffc7
Adding context initialization with key and iv derivations
dmochkas Jul 13, 2026
d7ee409
Register configurations from config.cmake
dmochkas Jul 13, 2026
630553b
Integrate Ascon HKDF and nonce management
dmochkas Jul 14, 2026
5c55829
Remove original libcose
dmochkas Jul 14, 2026
becc7d0
Integrate ascon in Security Layer and add submodules
dmochkas Jul 14, 2026
a54cd2c
Cleanup the build
dmochkas Jul 14, 2026
e68d5b5
Dynamic PIV len and config instructions
dmochkas Jul 14, 2026
ca3f4b9
Included ASCON in rmw_desert library
dcostan Jul 14, 2026
9ac8deb
Fix warnings and make Security Layer global
dmochkas Jul 14, 2026
1dbe0fa
Add COSE stateless comression that removes the serialization overhead
dmochkas Jul 16, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[submodule "thirdparty/NanoCBOR"]
path = thirdparty/NanoCBOR
url = https://github.com/bergzand/NanoCBOR
[submodule "thirdparty/mbedtls"]
path = thirdparty/mbedtls
url = https://github.com/Mbed-TLS/mbedtls.git
[submodule "thirdparty/libcose"]
path = thirdparty/libcose
url = https://github.com/dmochkas/libcose
[submodule "thirdparty/ascon-c"]
path = thirdparty/ascon-c
url = https://github.com/dmochkas/ascon-c
111 changes: 100 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ cmake_minimum_required(VERSION 3.5)

project(rmw_desert)

include(config.cmake)

# Default to C++20
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 20)
endif()

set(CMAKE_POLICY_VERSION_MINIMUM 3.5)

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic -pthread)
endif()
Expand All @@ -23,9 +27,6 @@ find_package(rosidl_typesupport_introspection_cpp REQUIRED)
find_package(rcutils REQUIRED)
find_package(rcpputils REQUIRED)

set(CBOR_ROOT cbor)
include_directories(${CBOR_ROOT}/include)

add_library(rmw_desert
src/get_node_info_and_types.cpp
src/init.cpp
Expand All @@ -46,21 +47,109 @@ add_library(rmw_desert
src/desert_classes/DesertClient.cpp
src/desert_classes/DesertService.cpp
src/desert_classes/DesertGuardCondition.cpp
src/desert_classes/CBorStream.cpp
src/desert_classes/CStringHelper.cpp
src/desert_classes/TcpDaemon.cpp
src/desert_classes/Discovery.cpp
src/desert_classes/TopicsConfig.cpp
src/desert_classes/demangle.cpp

${CBOR_ROOT}/src/common.c
${CBOR_ROOT}/src/parser.c
${CBOR_ROOT}/src/decoder.c
${CBOR_ROOT}/src/encoder.c
${CBOR_ROOT}/src/helper.c
${CBOR_ROOT}/src/ieee754.c
)

if (${CBOR_LIB} STREQUAL "libmcu_cbor")
set(CBOR_ROOT cbor)
include_directories(${CBOR_ROOT}/include)
target_sources(rmw_desert PRIVATE
${CBOR_ROOT}/src/common.c
${CBOR_ROOT}/src/parser.c
${CBOR_ROOT}/src/decoder.c
${CBOR_ROOT}/src/encoder.c
${CBOR_ROOT}/src/helper.c
${CBOR_ROOT}/src/ieee754.c
src/desert_classes/LibMcuCBorStream.cpp
)
target_compile_definitions(rmw_desert PRIVATE LIBMCU_CBOR_ENABLED)
elseif (${CBOR_LIB} STREQUAL "NanoCBOR")
set(CBOR_ROOT thirdparty/NanoCBOR)
include_directories(${CBOR_ROOT}/include)
target_sources(rmw_desert PRIVATE
${CBOR_ROOT}/src/decoder.c
${CBOR_ROOT}/src/encoder.c
src/desert_classes/NanoCBorStream.cpp
)
target_compile_definitions(rmw_desert PRIVATE NANOCBOR_ENABLED)
else ()
message(FATAL_ERROR "At least one CBOR libraty is required")
endif ()

target_include_directories(rmw_desert PRIVATE ${CBOR_INC_DIR})

if (SECURE_MODE_ENABLED)
if (NOT ${CBOR_LIB} STREQUAL "NanoCBOR")
message(FATAL_ERROR "Secure mode requires NanoCBOR lib.")
endif ()

add_compile_options(-fPIC)

set(COSE_ROOT "thirdparty/libcose")
set(COSE_LIB "libcose")
set(COSE_INC_DIR "${COSE_ROOT}/include")
add_library(${COSE_LIB} OBJECT
${COSE_ROOT}/src/cose_common.c
${COSE_ROOT}/src/cose_crypto.c
${COSE_ROOT}/src/cose_encrypt.c
${COSE_ROOT}/src/cose_hdr.c
${COSE_ROOT}/src/cose_hkdf.c
${COSE_ROOT}/src/cose_key.c
${COSE_ROOT}/src/cose_recipient.c
${COSE_ROOT}/src/cose_sign.c
${COSE_ROOT}/src/cose_signature.c
${COSE_ROOT}/src/crypt/keygen_symm.c
)
target_include_directories(${COSE_LIB} PRIVATE ${COSE_INC_DIR} ${CBOR_INC_DIR})

if (${CRYPTO_LIB} STREQUAL "mbedtls")
add_subdirectory(thirdparty/mbedtls)

target_sources(${COSE_LIB} PRIVATE ${COSE_ROOT}/src/crypt/mbedtls.c)
target_link_libraries(${COSE_LIB} PRIVATE mbedtls)
target_link_libraries(rmw_desert PRIVATE mbedtls)
add_compile_definitions(CRYPTO_MBEDTLS)
elseif (${CRYPTO_LIB} STREQUAL "ascon-c")
set(ASCON_LIB "ascon-c")
set(ASCON_AEAD_ROOT thirdparty/ascon-c/crypto_aead/asconaead128/opt64)
set(ASCON_HASH_ROOT thirdparty/ascon-c/crypto_hash/asconhash256/opt64)
add_library(${ASCON_LIB} OBJECT
${ASCON_AEAD_ROOT}/aead.c
${ASCON_AEAD_ROOT}/permutations.c
${ASCON_HASH_ROOT}/hash.c
)
target_compile_definitions(${ASCON_LIB} PRIVATE ASCON_INLINE_MODE=0)

target_sources(${COSE_LIB} PRIVATE ${COSE_ROOT}/src/crypt/ascon_c.c)
target_sources(rmw_desert PRIVATE $<TARGET_OBJECTS:${ASCON_LIB}>)
add_compile_definitions(CRYPTO_ASCON)
else ()
message(FATAL_ERROR "Cryptolib ${CRYPTO_LIB} is not supported")
endif ()

target_sources(rmw_desert PRIVATE
$<TARGET_OBJECTS:${COSE_LIB}>
src/desert_classes/security/sec_utils.cpp
src/desert_classes/security/AeadParams.cpp
src/desert_classes/security/SecurityLayer.cpp
)
target_include_directories(rmw_desert PRIVATE ${COSE_INC_DIR})
target_compile_definitions(rmw_desert PRIVATE SECURE_MODE_ENABLED)
target_compile_definitions(rmw_desert PRIVATE
AEAD_ALGO="${AEAD_ALGO}"
KDF_ALGO="${KDF_ALGO}"
PIV_LEN=${PIV_LEN}
SENDER_ID="${SENDER_ID}"
RECEIVER_ID="${RECEIVER_ID}")
if (COSE_STATELESS_COMP_ENABLED)
target_compile_definitions(rmw_desert PRIVATE COSE_STATELESS_COMP_ENABLED)
endif ()
endif ()

INCLUDE (FindPkgConfig)

# specific order: dependents before dependencies
Expand Down
9 changes: 9 additions & 0 deletions config.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
set(CBOR_LIB "NanoCBOR" CACHE STRING "Cbor library.") # libmcu_cbor, NanoCBOR
option(SECURE_MODE_ENABLED "Enable COSE Security Layer." ON)
option(COSE_STATELESS_COMP_ENABLED "Enable COSE stateless compression." ON)
set(CRYPTO_LIB "ascon-c" CACHE STRING "Crypto library.") # ascon-c, mbedtls
set(AEAD_ALGO "Ascon-AEAD128" CACHE STRING "Algorithm for authenticated encryption with additional data.") # Ascon-AEAD128, Ascon-AEAD128-64, Ascon-AEAD128-32
set(KDF_ALGO "HKDF-Ascon256" CACHE STRING "Algorithm for key derivation.")
set(PIV_LEN 2 CACHE STRING "Length of Partial IV.") # Max 16
set(SENDER_ID "0x01" CACHE STRING "Sender ID in hex.")
set(RECEIVER_ID "0x02" CACHE STRING "Receiver ID in hex.")
28 changes: 11 additions & 17 deletions src/desert_classes/CBorStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,6 @@

/** @endcond */

#include "cbor/encoder.h"
#include "cbor/ieee754.h"
#include "cbor/decoder.h"
#include "cbor/parser.h"
#include "cbor/helper.h"

#include "half.hpp"

#define PUBLISHER_TYPE 0
Expand Down Expand Up @@ -225,16 +219,20 @@ class TxStream
}

private:
// Forward declarations to abstract the implementation
struct WRITER;
struct ERROR;

uint8_t _stream_type;
std::string _stream_name;
uint8_t _stream_identifier;

bool _overflow;
uint8_t * _packet;
cbor_writer_t * _writer;
uint8_t * _packet;
WRITER * _writer;

void new_packet();
void handle_overrun(cbor_error_t result);
void handle_overrun(ERROR result);

std::string toUTF8(const std::u16string source);

Expand Down Expand Up @@ -317,13 +315,6 @@ class RxStream
*/
RxStream & operator>>(int8_t & n);

/**
* @brief Decode a generic integer
* @param n Field to decode
*/
template<typename T>
RxStream & deserialize_integer(T & n);

/**
* @brief Decode char
* @param n Field to decode
Expand Down Expand Up @@ -428,6 +419,9 @@ class RxStream
static void interpret_packets();

private:
// Forward declarations to abstract the implementation
struct ITEM;

uint8_t _stream_type;
std::string _stream_name;
uint8_t _stream_identifier;
Expand Down Expand Up @@ -455,7 +449,7 @@ class RxStream

static std::mutex _rx_mutex;

static std::pair<void *, int> interpret_field(cbor_item_t * items, size_t i, union _cbor_value & val);
static std::pair<void *, int> interpret_field(ITEM * items, size_t i, union _cbor_value & val);
std::u16string toUTF16(const std::string source);
};

Expand Down
Loading