Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[nasa/cryptolib#144] WolfSSL Crypto Module #200

Merged
merged 51 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
0801224
[nasa/cryptolib#144] Create initial clone of libgcrypt crypto module …
jlucas9 Aug 29, 2023
aad51c5
[nasa/cryptolib#144] Created new scripts for build_wolf, update how S…
jlucas9 Aug 29, 2023
335422d
[nasa/cryptolib#144] Rough draft of wolfssl crypto module - not yet b…
jlucas9 Sep 6, 2023
55c5087
[nasa/cryptolib#144] Wolf crypto module building, no unit tests yet;
jlucas9 Sep 7, 2023
df2159c
[nasa/cryptolib#144] Updates to script comments, added LD_LIBRARY_PAT…
jlucas9 Sep 15, 2023
bc252d1
Merge remote-tracking branch 'origin/dev' into cryptolib#144-WolfSSL
jlucas9 Sep 20, 2023
c7e203c
[nasa/cryptolib#144] Updates to crypto_config.c to autodetermine cryp…
jlucas9 Sep 21, 2023
0cb5137
[nasa/cryptolib#144] Update wolfssl module to not use global Aes, but…
jlucas9 Sep 22, 2023
c399980
[nasa/cryptolib#144] Unit tests all running;
jlucas9 Sep 26, 2023
52fec76
[nasa/cryptolib#144] First attempt at CI for wolf build;
jlucas9 Sep 26, 2023
a750d90
[nasa/cryptolib#144] CI for wolf build - round 2;
jlucas9 Sep 26, 2023
ecbc0fe
[nasa/cryptolib#144] CI for wolf build - round 3, omitting the make i…
jlucas9 Sep 26, 2023
5acf258
[nasa/cryptolib#144] CI for wolf build - set LD_LIBRARY_PATH to wolfs…
jlucas9 Sep 26, 2023
5b80a82
[nasa/cryptolib#144] CI for wolf build - added to $GITHUB_PATH enviro…
jlucas9 Sep 27, 2023
7321d3c
[nasa/cryptolib#144] Added executable bit to scripts and updated Wolf…
jlucas9 Sep 28, 2023
6a01c06
Update build.yml - Test WolfSSL Container
rjbrown2 Oct 3, 2023
36938fd
Update build.yml
rjbrown2 Oct 3, 2023
ffc580d
Update build.yml
rjbrown2 Oct 3, 2023
823ac6d
Update build.yml
rjbrown2 Oct 3, 2023
c8f0a32
Update build.yml
rjbrown2 Oct 3, 2023
f918df2
Update build.yml
rjbrown2 Oct 3, 2023
dbc06c6
Update build.yml
rjbrown2 Oct 3, 2023
838083a
Update build.yml
rjbrown2 Oct 3, 2023
1fdc5f4
Update build.yml
rjbrown2 Oct 3, 2023
c1e500e
Update build.yml
rjbrown2 Oct 3, 2023
aa24a0b
Update build.yml
rjbrown2 Oct 3, 2023
110781d
Update build.yml
rjbrown2 Oct 3, 2023
94347ae
Update build.yml
rjbrown2 Oct 3, 2023
177bfc5
Update build.yml
rjbrown2 Oct 3, 2023
a6211f2
Update build.yml
rjbrown2 Oct 3, 2023
e7cd6ee
Update build.yml
rjbrown2 Oct 3, 2023
67e1fd8
Update build.yml
rjbrown2 Oct 3, 2023
89c4b2a
Update build.yml
rjbrown2 Oct 3, 2023
377bbc4
Update build.yml
rjbrown2 Oct 3, 2023
d7b84af
Update build.yml
rjbrown2 Oct 3, 2023
7f27ab8
Update build.yml
rjbrown2 Oct 3, 2023
ebcb21f
Update build.yml
rjbrown2 Oct 3, 2023
b00c5b2
Update build.yml
rjbrown2 Oct 3, 2023
fab84da
Update build.yml
rjbrown2 Oct 3, 2023
e9b33b5
Update build.yml
rjbrown2 Oct 3, 2023
f6aea7d
Update build.yml
rjbrown2 Oct 3, 2023
8f61ca2
Update build.yml
rjbrown2 Oct 3, 2023
6853e4b
Update build.yml
rjbrown2 Oct 3, 2023
38d0c3b
Update build.yml
rjbrown2 Oct 3, 2023
52f6dd3
Update build.yml
rjbrown2 Oct 3, 2023
58d0445
Update build_wolf.sh
rjbrown2 Oct 3, 2023
e079d7c
Update build.yml
rjbrown2 Oct 3, 2023
85ad35f
Update build.yml
rjbrown2 Oct 3, 2023
7bdba9d
Update Dockerfile
rjbrown2 Oct 3, 2023
df6337d
Update build_wolf.sh
rjbrown2 Oct 3, 2023
361424a
Update build_wolf.sh
rjbrown2 Oct 3, 2023
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
43 changes: 41 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Update
run: sudo apt-get update
- name: Install Dependencies
run: sudo apt-get install -y lcov libcurl4-openssl-dev libmariadb-dev libmariadb-dev-compat libgcrypt20-dev python3
run: sudo apt-get install -y lcov libcurl4-openssl-dev libmariadb-dev libmariadb-dev-compat libgcrypt20-dev python3
- name: Install Python Libraries
run: sudo pip install pycryptodome
# End Container Setup
Expand Down Expand Up @@ -74,4 +74,43 @@ jobs:

- name: KMC Build Script
working-directory: ${{github.workspace}}
run: bash ${GITHUB_WORKSPACE}/support/scripts/build_kmc.sh
run: bash ${GITHUB_WORKSPACE}/support/scripts/build_kmc.sh

#
# Wolf Build
#
wolf_build:
# Container Setup
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Update
run: sudo apt-get update
- name: Install Dependencies
run: sudo apt-get install -y lcov libcurl4-openssl-dev libmariadb-dev libmariadb-dev-compat libgcrypt20-dev python3 autoconf libtool
- name: Install Python Libraries
run: sudo pip install pycryptodome
- name: Clone WolfSSL
run: git clone --depth 1 --branch v5.6.0-stable https://github.com/wolfSSL/wolfssl.git /tmp/wolfssl

# cmake -DCMAKE_INSTALL_PREFIX=/home/runner/.local -DWOLFSSL_AESCCM=yes -DWOLFSSL_AESSIV=yes -DWOLFSSL_CMAC=yes ..;
- name: Build WolfSSL
# -DCMAKE_INSTALL_PREFIX=/home/runner/.local
#run: cd /tmp/wolfssl/;
# sudo chown -R runner /usr/local;
# ./autogen.sh;
# ./configure --enable-aesccm --enable-aessiv --enable-cmac;
# make;
# make install;
#sudo chown -R runner /usr/local;
run: mkdir /tmp/wolfssl/build;
cd /tmp/wolfssl/build;
cmake -DWOLFSSL_AESCCM=yes -DWOLFSSL_AESSIV=yes -DWOLFSSL_CMAC=yes ..;
cmake --build .;
sudo make install;
sudo ldconfig;
# End Container Setup

- name: Wolf Build Script
working-directory: ${{github.workspace}}
run: bash ${GITHUB_WORKSPACE}/support/scripts/build_wolf.sh
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ project(crypto C)
option(CODECOV "Code Coverage" OFF)
option(CRYPTO_LIBGCRYPT "Cryptography Module - Libgcrypt" ON)
option(CRYPTO_KMC "Cryptography Module - KMC" OFF)
option(CRYPTO_WOLFSSL "Cryptography Module - WolfSSL" OFF)
option(DEBUG "Debug" OFF)
option(KEY_CUSTOM "Key Module - Custom" OFF)
option(KEY_INTERNAL "Key Module - Internal" ON)
Expand Down
7 changes: 6 additions & 1 deletion include/crypto_config_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,30 @@ typedef enum
} InitStatus;
typedef enum
{
KEY_TYPE_UNITIALIZED = 0,
KEY_TYPE_CUSTOM,
KEY_TYPE_INTERNAL,
KEY_TYPE_KMC
} KeyType;
typedef enum
{
MC_TYPE_UNITIALIZED = 0,
MC_TYPE_CUSTOM,
MC_TYPE_INTERNAL
} McType;
typedef enum
{
SA_TYPE_UNITIALIZED = 0,
SA_TYPE_CUSTOM,
SA_TYPE_INMEMORY,
SA_TYPE_MARIADB
} SadbType;
typedef enum
{
CRYPTOGRAPHY_TYPE_UNITIALIZED = 0,
CRYPTOGRAPHY_TYPE_LIBGCRYPT,
CRYPTOGRAPHY_TYPE_KMCCRYPTO
CRYPTOGRAPHY_TYPE_KMCCRYPTO,
CRYPTOGRAPHY_TYPE_WOLFSSL
} CryptographyType;
// gvcid managed parameter enums
typedef enum
Expand Down
1 change: 1 addition & 0 deletions include/cryptography_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,6 @@ typedef struct

CryptographyInterface get_cryptography_interface_libgcrypt(void);
CryptographyInterface get_cryptography_interface_kmc_crypto_service(void);
CryptographyInterface get_cryptography_interface_wolfssl(void);

#endif //CRYPTOLIB_CRYPTOGRAPHY_INTERFACE_H
12 changes: 12 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ else()
list(APPEND LIB_SRC_FILES ${KMC_FILES})
endif()

if(CRYPTO_WOLFSSL)
aux_source_directory(crypto/wolfssl WOLFSSL_FILES)
list(APPEND LIB_SRC_FILES ${WOLFSSL_FILES})
else()
aux_source_directory(crypto/wolfssl_stub WOLFSSL_FILES)
list(APPEND LIB_SRC_FILES ${WOLFSSL_FILES})
endif()

if(KEY_CUSTOM)
# Assumes CryptoLib is a Git submodule to project and custom directories and definitions exist at top level
aux_source_directory(../../key/custom KEY_CUSTOM_FILES)
Expand Down Expand Up @@ -119,6 +127,10 @@ if(CRYPTO_KMC)
target_link_libraries(crypto curl)
endif()

if(CRYPTO_WOLFSSL)
target_link_libraries(crypto wolfssl)
endif()

if(SA_MARIADB)
execute_process(COMMAND mysql_config --cflags
OUTPUT_VARIABLE MYSQL_CFLAGS OUTPUT_STRIP_TRAILING_WHITESPACE)
Expand Down
22 changes: 10 additions & 12 deletions src/core/crypto_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,23 +201,22 @@ int32_t Crypto_Init(void)
} // TODO: Error stack

/* Crypto Interface */
// Prepare Cryptographic Library from config
if(crypto_config.cryptography_type == CRYPTOGRAPHY_TYPE_LIBGCRYPT)
// Determine which cryptographic module is in use
cryptography_if = get_cryptography_interface_libgcrypt();
if (cryptography_if == NULL)
{
cryptography_if = get_cryptography_interface_libgcrypt();
cryptography_if = get_cryptography_interface_wolfssl();
}
else if (crypto_config.cryptography_type == CRYPTOGRAPHY_TYPE_KMCCRYPTO)
{
if (cryptography_kmc_crypto_config == NULL)
if (cryptography_if == NULL)
{ // Note this needs to be the last option in the chain due to addition configuration required
if (cryptography_kmc_crypto_config != NULL)
{
status = CRYPTOGRAPHY_KMC_CRYPTO_SERVICE_CONFIGURATION_NOT_COMPLETE;
printf(KRED "ERROR: CryptoLib KMC Crypto Service Interface must be configured before intializing!\n" RESET);
return status;
cryptography_if = get_cryptography_interface_kmc_crypto_service();
}
cryptography_if = get_cryptography_interface_kmc_crypto_service();
}
else
if (cryptography_if == NULL)
{
printf("Fatal Error: Unable to identify Cryptography Interface!\n");
status = CRYPTOGRAPHY_INVALID_CRYPTO_INTERFACE_TYPE;
return status;
}
Expand All @@ -237,7 +236,6 @@ int32_t Crypto_Init(void)
return status;
}


// Init Security Associations
status = sa_if->sa_init();
if (status==CRYPTO_LIB_SUCCESS)
Expand Down
100 changes: 51 additions & 49 deletions src/core/crypto_tc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1149,26 +1149,26 @@ int32_t Crypto_TC_ProcessSecurity_Cam(uint8_t* ingest, int* len_ingest, TC_t* tc
return status;
}

status = cryptography_if->cryptography_aead_decrypt(tc_sdls_processed_frame->tc_pdu, // plaintext output
(size_t)(tc_sdls_processed_frame->tc_pdu_len), // length of data
&(ingest[tc_enc_payload_start_index]), // ciphertext input
(size_t)(tc_sdls_processed_frame->tc_pdu_len), // in data length
&(ekp->value[0]), // Key
Crypto_Get_ECS_Algo_Keylen(sa_ptr->ecs),
sa_ptr, // SA for key reference
tc_sdls_processed_frame->tc_sec_header.iv, // IV
sa_ptr->iv_len, // IV Length
tc_sdls_processed_frame->tc_sec_trailer.mac, // Frame Expected Tag
sa_ptr->stmacf_len, // tag size
aad, // additional authenticated data
aad_len, // length of AAD
(sa_ptr->est), // Decryption Bool
(sa_ptr->ast), // Authentication Bool
(sa_ptr->ast), // AAD Bool
&sa_ptr->ecs, // encryption cipher
&sa_ptr->acs, // authentication cipher
cam_cookies

status = cryptography_if->cryptography_aead_decrypt(
tc_sdls_processed_frame->tc_pdu, // plaintext output
(size_t)(tc_sdls_processed_frame->tc_pdu_len), // length of data
&(ingest[tc_enc_payload_start_index]), // ciphertext input
(size_t)(tc_sdls_processed_frame->tc_pdu_len), // in data length
&(ekp->value[0]), // Key
Crypto_Get_ECS_Algo_Keylen(sa_ptr->ecs), //
sa_ptr, // SA for key reference
tc_sdls_processed_frame->tc_sec_header.iv, // IV
sa_ptr->iv_len, // IV Length
tc_sdls_processed_frame->tc_sec_trailer.mac, // Frame Expected Tag
sa_ptr->stmacf_len, // tag size
aad, // additional authenticated data
aad_len, // length of AAD
(sa_ptr->est), // Decryption Bool
(sa_ptr->ast), // Authentication Bool
(sa_ptr->ast), // AAD Bool
&sa_ptr->ecs, // encryption cipher
&sa_ptr->acs, // authentication cipher
cam_cookies //
);
}
else if (sa_service_type != SA_PLAINTEXT && ecs_is_aead_algorithm == CRYPTO_FALSE) // Non aead algorithm
Expand All @@ -1185,22 +1185,24 @@ int32_t Crypto_TC_ProcessSecurity_Cam(uint8_t* ingest, int* len_ingest, TC_t* tc
return status;
}

status = cryptography_if->cryptography_validate_authentication(tc_sdls_processed_frame->tc_pdu, // plaintext output
(size_t)(tc_sdls_processed_frame->tc_pdu_len), // length of data
&(ingest[tc_enc_payload_start_index]), // ciphertext input
(size_t)(tc_sdls_processed_frame->tc_pdu_len), // in data length
&(akp->value[0]), // Key
Crypto_Get_ACS_Algo_Keylen(sa_ptr->acs),
sa_ptr, // SA for key reference
tc_sdls_processed_frame->tc_sec_header.iv, // IV
sa_ptr->iv_len, // IV Length
tc_sdls_processed_frame->tc_sec_trailer.mac, // Frame Expected Tag
sa_ptr->stmacf_len, // tag size
aad, // additional authenticated data
aad_len, // length of AAD
CRYPTO_CIPHER_NONE, // encryption cipher
sa_ptr->acs, // authentication cipher
cam_cookies);
status = cryptography_if->cryptography_validate_authentication(
tc_sdls_processed_frame->tc_pdu, // plaintext output
(size_t)(tc_sdls_processed_frame->tc_pdu_len), // length of data
&(ingest[tc_enc_payload_start_index]), // ciphertext input
(size_t)(tc_sdls_processed_frame->tc_pdu_len), // in data length
&(akp->value[0]), // Key
Crypto_Get_ACS_Algo_Keylen(sa_ptr->acs), //
sa_ptr, // SA for key reference
tc_sdls_processed_frame->tc_sec_header.iv, // IV
sa_ptr->iv_len, // IV Length
tc_sdls_processed_frame->tc_sec_trailer.mac, // Frame Expected Tag
sa_ptr->stmacf_len, // tag size
aad, // additional authenticated data
aad_len, // length of AAD
CRYPTO_CIPHER_NONE, // encryption cipher
sa_ptr->acs, // authentication cipher
cam_cookies //
);
}
if (sa_service_type == SA_ENCRYPTION || sa_service_type == SA_AUTHENTICATED_ENCRYPTION)
{
Expand All @@ -1213,19 +1215,19 @@ int32_t Crypto_TC_ProcessSecurity_Cam(uint8_t* ingest, int* len_ingest, TC_t* tc
return status;
}

status = cryptography_if->cryptography_decrypt(tc_sdls_processed_frame->tc_pdu, // plaintext output
(size_t)(tc_sdls_processed_frame->tc_pdu_len), // length of data
&(ingest[tc_enc_payload_start_index]), // ciphertext input
(size_t)(tc_sdls_processed_frame->tc_pdu_len), // in data length
&(ekp->value[0]), // Key
Crypto_Get_ECS_Algo_Keylen(sa_ptr->ecs),
sa_ptr, // SA for key reference
tc_sdls_processed_frame->tc_sec_header.iv, // IV
sa_ptr->iv_len, // IV Length
&sa_ptr->ecs, // encryption cipher
&sa_ptr->acs, // authentication cipher
cam_cookies

status = cryptography_if->cryptography_decrypt(
tc_sdls_processed_frame->tc_pdu, // plaintext output
(size_t)(tc_sdls_processed_frame->tc_pdu_len), // length of data
&(ingest[tc_enc_payload_start_index]), // ciphertext input
(size_t)(tc_sdls_processed_frame->tc_pdu_len), // in data length
&(ekp->value[0]), // Key
Crypto_Get_ECS_Algo_Keylen(sa_ptr->ecs), //
sa_ptr, // SA for key reference
tc_sdls_processed_frame->tc_sec_header.iv, // IV
sa_ptr->iv_len, // IV Length
&sa_ptr->ecs, // encryption cipher
&sa_ptr->acs, // authentication cipher
cam_cookies //
);

// Handle Padding Removal
Expand Down
5 changes: 1 addition & 4 deletions src/crypto/kmc_stub/cryptography_interface_kmc.stub.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@

#include "cryptography_interface.h"

static CryptographyInterfaceStruct cryptography_if;

CryptographyInterface get_cryptography_interface_kmc_crypto_service(void)
{
fprintf(stderr,"ERROR: Loading KMC Crypto Service cryptography interface stub source code. Rebuild CryptoLib with -DKMCCRYPTO=ON to use proper KMC Crytpo Service implementation.\n");
return &cryptography_if;
return NULL;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@

#include "cryptography_interface.h"

static CryptographyInterfaceStruct cryptography_if;

CryptographyInterface get_cryptography_interface_libgcrypt(void)
{
fprintf(stderr,"ERROR: Loading libgcrypt cryptography interface stub source code. Rebuild CryptoLib with -DCRYPTO_LIBGCRYPT=ON to use proper libgcrypt implementation.\n");
return &cryptography_if;
return NULL;
}
Loading
Loading