Add libtomcrypt and libtommath submodules

These provide e.g. rsa_oaep, which can be used for sw crypto

Signed-off-by: Jukka Laitinen <jukkax@ssrc.tii.ae>
This commit is contained in:
Jukka Laitinen 2021-06-02 13:44:52 +03:00 committed by Beat Küng
parent be4f7cabf9
commit 40063bd54b
7 changed files with 117 additions and 1 deletions

8
.gitmodules vendored
View File

@ -66,3 +66,11 @@
[submodule "Tools/simulation-ignition"]
path = Tools/simulation-ignition
url = https://github.com/Auterion/px4-simulation-ignition.git
[submodule "src/lib/crypto/libtomcrypt"]
path = src/lib/crypto/libtomcrypt
url = https://github.com/PX4/libtomcrypt.git
branch = px4
[submodule "src/lib/crypto/libtommath"]
path = src/lib/crypto/libtommath
url = https://github.com/PX4/libtommath.git
branch = px4

View File

@ -24,4 +24,7 @@ exec find boards msg src platforms test \
-path src/modules/micrortps_bridge/micro-CDR -prune -o \
-path src/modules/micrortps_bridge/microRTPS_client -prune -o \
-path test/mavsdk_tests/catch2 -prune -o \
-path src/lib/crypto/monocypher -prune -o \
-path src/lib/crypto/libtomcrypt -prune -o \
-path src/lib/crypto/libtommath -prune -o \
-type f \( -name "*.c" -o -name "*.h" -o -name "*.cpp" -o -name "*.hpp" \) | grep $PATTERN

View File

@ -32,7 +32,6 @@
############################################################################
px4_add_git_submodule(TARGET git_matrix PATH "matrix")
px4_add_git_submodule(TARGET git_monocypher PATH "crypto/monocypher")
add_subdirectory(airspeed)
add_subdirectory(avoidance)

View File

@ -31,6 +31,12 @@
#
############################################################################
if (DEFINED PX4_CRYPTO)
px4_add_git_submodule(TARGET git_monocypher PATH "monocypher")
px4_add_git_submodule(TARGET git_libtomcrypt PATH "libtomcrypt")
px4_add_git_submodule(TARGET git_libtommath PATH "libtommath")
px4_add_library(monocypher
monocypher/src/monocypher.c
monocypher/src/optional/monocypher-ed25519.c
@ -43,3 +49,54 @@ target_include_directories(monocypher
# There is a one shadow warning in monocypher 3.1.2, ignore it
target_compile_options(monocypher PRIVATE -Wno-shadow)
file(GLOB TOMMATH_SRC RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "libtommath/*.c")
px4_add_library(libtommath
${TOMMATH_SRC}
)
file(GLOB_RECURSE PK_SRC RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "libtomcrypt/src/pk/*.c")
file(GLOB_RECURSE MATH_SRC RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "libtomcrypt/src/math/*.c")
px4_add_library(libtomcrypt
libtomcrypt_wrappers.c
${PK_SRC}
${MATH_SRC}
libtomcrypt/src/hashes/sha2/sha256.c
libtomcrypt/src/hashes/helper/hash_memory.c
libtomcrypt/src/prngs/sprng.c
libtomcrypt/src/misc/crypt/crypt_ltc_mp_descriptor.c
libtomcrypt/src/misc/crypt/crypt_hash_is_valid.c
libtomcrypt/src/misc/crypt/crypt_prng_is_valid.c
libtomcrypt/src/misc/zeromem.c
)
target_include_directories(libtomcrypt
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/libtommath
)
target_include_directories(libtomcrypt
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/libtomcrypt/src/headers
)
# libtomcrypt defines:
# ARGTYPE=3: No argument checking
add_definitions(-DARGTYPE=3 -DLTC_EASY -DLTC_NO_TEST -DLTM_DESC -DMP_LOW_MEM)
# link to libtommath and os provided random library
target_link_libraries(libtomcrypt
PRIVATE
libtommath
px4_random
)
# Fix for erroneous warning on some compilers:
# "der_encode_asn1_identifier.c:39:18: error: comparison is always false due to limited range of data type"
target_compile_options(libtomcrypt PRIVATE -Wno-type-limits)
endif()

@ -0,0 +1 @@
Subproject commit 673f5ce29015a9bba3c96792920a10601b5b0718

View File

@ -0,0 +1,47 @@
#include <px4_random.h>
#include <tomcrypt.h>
struct ltc_hash_descriptor hash_descriptor[] = {
{
"sha256",
0,
32,
64,
/* OID */
{ 2, 16, 840, 1, 101, 3, 4, 2, 1, },
9,
&sha256_init,
&sha256_process,
&sha256_done,
&sha256_test,
NULL
}
};
struct ltc_prng_descriptor prng_descriptor[] = {
{
"sprng", 0,
&sprng_start,
&sprng_add_entropy,
&sprng_ready,
&sprng_read,
&sprng_done,
&sprng_export,
&sprng_import,
&sprng_test
}
};
unsigned long rng_get_bytes(unsigned char *out,
unsigned long outlen,
void (*callback)(void))
{
return px4_get_secure_random((uint8_t *)out, (size_t)outlen);
}
void libtomcrypt_init(void)
{
ltc_mp = ltm_desc;
}

@ -0,0 +1 @@
Subproject commit fd73d7630b9d3ed5a79d613ff680a549e9780de7