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-09-27 17:45:07 +02:00
committed by Beat Küng
parent be4f7cabf9
commit 40063bd54b
7 changed files with 117 additions and 1 deletions
-1
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)
+57
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()
+47
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;
}