Skip to content

Commit

Permalink
Merge pull request #90 from nasa/AMMOSGH29-install_target_dev
Browse files Browse the repository at this point in the history
AMMOSGH29 : Add install target, update RPATH
  • Loading branch information
jlucas9 authored Mar 18, 2022
2 parents 0097af2 + d3af74b commit 488df01
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 10 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ cmake-build-debug
_deps

DartConfiguration.tcl

install
14 changes: 13 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,26 @@
cmake_minimum_required(VERSION 3.14.0)
project(CRYPTO C)

set(CMAKE_INSTALL_RPATH "$ORIGIN/../lib")

OPTION(DEBUG "Debug" OFF) # Disabled by default, enable with: -DDEBUG=ON
OPTION(MYSQL "Mysql" OFF) # Disabled by default, enable with: -DMYSQL=ON
OPTION(LIBGCRYPT "Libgcrypt" ON) # Enabled by default, disable with: -DLIBGCRYPT=OFF
OPTION(KMCCRYPTO "KmcCrypto" OFF) # Disabled by default, enable with: -DKMCCRYPTO=ON
OPTION(ENCTEST "Encryption-Tests" OFF) # Disabled by default, enable with: -DENCTEST=ON
OPTION(CODECOV "Code-Coverage" OFF) # Disabled by default, enable with: -DCODECOV=ON
OPTION(SYSTEM_INSTALL "SystemInstall" OFF) #Disabled by default, enable with: -DSYSTEM_INSTALL=ON

set(CMAKE_INSTALL_RPATH "$ORIGIN/../lib")
set(CMAKE_INSTALL_PREFIX ${PROJECT_SOURCE_DIR}/install)

IF(CRYPTO_SUBMODULE_INSTALL) #If building CryptoLib as a submodule of another build system (EG, JPL KMC, Nasa NOS3, etc...)
set(CMAKE_INSTALL_PREFIX ${CRYPTO_SUBMODULE_INSTALL})
ENDIF()

IF(SYSTEM_INSTALL)
set(CMAKE_INSTALL_PREFIX /usr/local)
ENDIF()


IF(DEBUG)
ADD_DEFINITIONS(-DDEBUG -DOCF_DEBUG -DFECF_DEBUG -DSA_DEBUG -DPDU_DEBUG -DCCSDS_DEBUG -DTC_DEBUG -DMAC_DEBUG -DTM_DEBUG)
Expand Down
14 changes: 11 additions & 3 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,19 @@ if(MYSQL)
target_link_libraries(Crypto ${MYSQL_LIBS})
endif()


#Include cmake install module - todo
#include(GNUInstallDirs)
set_target_properties(Crypto PROPERTIES PUBLIC_HEADER "../include/crypto.h;../include/crypto_config_structs.h;../include/crypto_error.h;../include/crypto_print.h;../include/crypto_structs.h;")

add_custom_command(TARGET Crypto POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:Crypto> ${PROJECT_BINARY_DIR}/lib/libCrypto.so
COMMENT "Created ${PROJECT_BINARY_DIR}/lib/libCrypto.so"
)

install(TARGETS Crypto
DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_PREFIX}/include)

IF(MYSQL)
file(GLOB MYSQL_SCRIPTS crypto_sadb/sadb_mariadb_admin_scripts/*.sql)
install(FILES ${MYSQL_SCRIPTS}
DESTINATION ${CMAKE_INSTALL_PREFIX}/etc/sadb_mariadb_admin_scripts)
endif()
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,6 @@ static int32_t cryptography_authenticate(uint8_t* data_out, size_t len_data_out,
iv = iv;
iv_len = iv_len;
ecs = ecs;
acs = acs;

curl_easy_reset(curl);
configure_curl_connect_opts(curl);
Expand All @@ -275,6 +274,13 @@ static int32_t cryptography_authenticate(uint8_t* data_out, size_t len_data_out,
uint8_t* auth_payload = aad;
size_t auth_payload_len = aad_len;

// Verify valid acs enum
int32_t algo = cryptography_get_acs_algo(acs);
if (algo == CRYPTO_LIB_ERR_UNSUPPORTED_ACS)
{
return CRYPTO_LIB_ERR_UNSUPPORTED_ACS;
}

// Need to copy the data over, since authentication won't change/move the data directly
if(data_out != NULL){
memcpy(data_out, data_in, len_data_in);
Expand Down Expand Up @@ -488,7 +494,13 @@ static int32_t cryptography_validate_authentication(uint8_t* data_out, size_t le
iv = iv;
iv_len = iv_len;
ecs = ecs;
acs = acs;

// Verify valid acs enum
int32_t algo = cryptography_get_acs_algo(acs);
if (algo == CRYPTO_LIB_ERR_UNSUPPORTED_ACS)
{
return CRYPTO_LIB_ERR_UNSUPPORTED_ACS;
}

// Need to copy the data over, since authentication won't change/move the data directly
if(data_out != NULL){
Expand Down Expand Up @@ -1253,9 +1265,9 @@ int32_t cryptography_get_acs_algo(int8_t algo_enum)
int32_t algo = CRYPTO_LIB_ERR_UNSUPPORTED_ACS; // All valid algo enums will be positive
switch (algo_enum)
{
// case CRYPTO_AES256_CMAC:
// algo = GCRY_MAC_CMAC_AES;
// break;
case CRYPTO_AES256_CMAC:
algo = CRYPTO_AES256_CMAC;
break;

default:
#ifdef DEBUG
Expand All @@ -1264,5 +1276,5 @@ int32_t cryptography_get_acs_algo(int8_t algo_enum)
break;
}

return (int)algo;
return (int32_t)algo;
}

0 comments on commit 488df01

Please sign in to comment.