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

Doxygen updates #32

Merged
merged 3 commits into from
Dec 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2,579 changes: 2,579 additions & 0 deletions CryptoLib-Doxyfile

Large diffs are not rendered by default.

119 changes: 96 additions & 23 deletions fsw/crypto_util/app/et_dt_validation.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
[email protected]
*/

/*
/**
* Unit Tests that macke use of TC_ApplySecurity function on the data.
* These tests will require Python3, as well as the pycryptodome module to be installed.
*/

#include "et_dt_validation.h"
Expand All @@ -29,6 +30,12 @@

// Setup for some Unit Tests using a Python Script to Verify validiy of frames
PyObject *pName, *pModule, *pDict, *pFunc, *pValue, *pArgs, *pClass, *pInstance;

/**
* @brief Python Teardown
* Used to dereference variables and free memory used during the python truth baseline process.
* Must be called or tests could cause memory leaks, and erroneous data.
**/
int EndPython()
{
Py_XDECREF(pInstance);
Expand All @@ -38,6 +45,19 @@ int EndPython()
Py_Finalize();
}

/**
* @brief Python Cryptodome Truth Baseline
* Used to generate truth data for Authorized Encryption. Results are compared against TC_ApplySecurity Functionality,
* as well as in reverse using the TC_ProcessSecurity function.
* @param data Hexstring of the plain text to be encrypted
* @param key Hexstring of the key to be used during encryption
* @param iv Hextring of the IV to be used during encryption
* @param header Hextring of the header (AAD) that will be used during encryption
* @param bitmask Hexstring of the bitmask that will be used on the header
* @param expected Ouput character array that will be allocated within this function. Memory must be freed upon completion of test.
* @param expected_length The length of the expected character array that is set within this function
* @note The uint8** expected that is passsed to this function must be freed by the user upon completion of unit test or other call.
**/
void python_auth_encryption(char* data, char* key, char* iv, char* header, char* bitmask, uint8** expected, long* expected_length)
{
Py_Initialize();
Expand Down Expand Up @@ -78,7 +98,11 @@ void python_auth_encryption(char* data, char* key, char* iv, char* header, char*
return;
}

// Test by utilizing python cryptography library
/**
* @brief Validation Test: Authorized Encryption using Python Truth Data
* Utilizes the python_auth_encryption(char* data, char* key, char* iv, char* header, char* bitmask, uint8** expected, long* expected_length) function to create baseline truth data. This data is then compared against the
* generated tag and cipher text that is generated by the Crypto_TC_ApplySecurity(const uint8* p_in_frame, const uint16 in_frame_length, uint8 **pp_in_frame, uint16 *p_enc_frame_len) function, as well as the FECF.
**/
UTEST(ET_VALIDATION, AUTH_ENCRYPTION_TEST)
{
//Setup & Initialize CryptoLib
Expand Down Expand Up @@ -136,6 +160,11 @@ UTEST(ET_VALIDATION, AUTH_ENCRYPTION_TEST)
EndPython();
}

/**
* @brief Validation Test: Authorized Decryption
* Makes use of truth data created from the previous AUTH_ENCRYPTION_TEST, to validate that Crypto_TC_ProcessSecurity( char* ingest, int* len_ingest,TC_t* tc_sdls_processed_frame)
* properly decrypts data and returns it to the intial truth data created by the python_auth_encryption(char* data, char* key, char* iv, char* header, char* bitmask, uint8** expected, long* expected_length) function.
**/
UTEST(DT_VALIDATION, AUTH_DECRYPTION_TEST)
{
//Setup & Initialize CryptoLib
Expand Down Expand Up @@ -192,8 +221,10 @@ UTEST(DT_VALIDATION, AUTH_DECRYPTION_TEST)
EndPython();
}

// AES-GCM 256 Test Vectors
// Reference: https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Algorithm-Validation-Program/documents/mac/gcmtestvectors.zip
/**
* @brief Validation Test: AES-GCM 256 Test Vectors
* Reference: https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Algorithm-Validation-Program/documents/mac/gcmtestvectors.zip
**/
UTEST(NIST_ENC_VALIDATION, AES_GCM_256_IV_96_PT_128_TEST_0)
{
uint8 *ptr_enc_frame = NULL;
Expand Down Expand Up @@ -255,8 +286,10 @@ UTEST(NIST_ENC_VALIDATION, AES_GCM_256_IV_96_PT_128_TEST_0)
free(buffer_nist_key_b);
}

// AES-GCM 256 Test Vectors
// Reference: https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Algorithm-Validation-Program/documents/mac/gcmtestvectors.zip
/**
* @brief Validation Test: AES-GCM 256 Test Vectors
* Reference: https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Algorithm-Validation-Program/documents/mac/gcmtestvectors.zip
**/
UTEST(NIST_DEC_VALIDATION, AES_GCM_256_IV_96_PT_128_TEST_0)
{
uint8 *ptr_enc_frame = NULL;
Expand Down Expand Up @@ -320,6 +353,10 @@ UTEST(NIST_DEC_VALIDATION, AES_GCM_256_IV_96_PT_128_TEST_0)
free(buffer_nist_key_b);
}

/**
* @brief Validation Test: AES-GCM 256 Test Vectors
* Reference: https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Algorithm-Validation-Program/documents/mac/gcmtestvectors.zip
**/
UTEST(NIST_ENC_VALIDATION, AES_GCM_256_IV_96_PT_128_TEST_1)
{
uint8 *ptr_enc_frame = NULL;
Expand Down Expand Up @@ -379,6 +416,10 @@ UTEST(NIST_ENC_VALIDATION, AES_GCM_256_IV_96_PT_128_TEST_1)
free(buffer_nist_key_b);
}

/**
* @brief Validation Test: AES-GCM 256 Test Vectors
* Reference: https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Algorithm-Validation-Program/documents/mac/gcmtestvectors.zip
**/
UTEST(NIST_DEC_VALIDATION, AES_GCM_256_IV_96_PT_128_TEST_1)
{
uint8 *ptr_enc_frame = NULL;
Expand Down Expand Up @@ -440,6 +481,10 @@ UTEST(NIST_DEC_VALIDATION, AES_GCM_256_IV_96_PT_128_TEST_1)
free(buffer_nist_key_b);
}

/**
* @brief Validation Test: AES-GCM 256 Test Vectors
* Reference: https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Algorithm-Validation-Program/documents/mac/gcmtestvectors.zip
**/
UTEST(NIST_ENC_VALIDATION, AES_GCM_256_IV_96_PT_128_TEST_2)
{
uint8 *ptr_enc_frame = NULL;
Expand Down Expand Up @@ -499,6 +544,10 @@ UTEST(NIST_ENC_VALIDATION, AES_GCM_256_IV_96_PT_128_TEST_2)
free(buffer_nist_key_b);
}

/**
* @brief Validation Test: AES-GCM 256 Test Vectors
* Reference: https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Algorithm-Validation-Program/documents/mac/gcmtestvectors.zip
**/
UTEST(NIST_DEC_VALIDATION, AES_GCM_256_IV_96_PT_128_TEST_2)
{
uint8 *ptr_enc_frame = NULL;
Expand Down Expand Up @@ -560,6 +609,10 @@ UTEST(NIST_DEC_VALIDATION, AES_GCM_256_IV_96_PT_128_TEST_2)
free(buffer_nist_key_b);
}

/**
* @brief Validation Test: AES-GCM 256 Test Vectors
* Reference: https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Algorithm-Validation-Program/documents/mac/gcmtestvectors.zip
**/
UTEST(NIST_ENC_VALIDATION, AES_GCM_256_IV_96_PT_128_TEST_3)
{
uint8 *ptr_enc_frame = NULL;
Expand Down Expand Up @@ -619,6 +672,10 @@ UTEST(NIST_ENC_VALIDATION, AES_GCM_256_IV_96_PT_128_TEST_3)
free(buffer_nist_key_b);
}

/**
* @brief Validation Test: AES-GCM 256 Test Vectors
* Reference: https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Algorithm-Validation-Program/documents/mac/gcmtestvectors.zip
**/
UTEST(NIST_DEC_VALIDATION, AES_GCM_256_IV_96_PT_128_TEST_3)
{
uint8 *ptr_enc_frame = NULL;
Expand Down Expand Up @@ -680,6 +737,10 @@ UTEST(NIST_DEC_VALIDATION, AES_GCM_256_IV_96_PT_128_TEST_3)
free(buffer_nist_key_b);
}

/**
* @brief Validation Test: AES-GCM 256 Test Vectors
* Reference: https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Algorithm-Validation-Program/documents/mac/gcmtestvectors.zip
**/
UTEST(NIST_ENC_VALIDATION, AES_GCM_256_IV_96_PT_128_TEST_4)
{
uint8 *ptr_enc_frame = NULL;
Expand Down Expand Up @@ -739,6 +800,10 @@ UTEST(NIST_ENC_VALIDATION, AES_GCM_256_IV_96_PT_128_TEST_4)
free(buffer_nist_key_b);
}

/**
* @brief Validation Test: AES-GCM 256 Test Vectors
* Reference: https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Algorithm-Validation-Program/documents/mac/gcmtestvectors.zip
**/
UTEST(NIST_DEC_VALIDATION, AES_GCM_256_IV_96_PT_128_TEST_4)
{
uint8 *ptr_enc_frame = NULL;
Expand Down Expand Up @@ -800,18 +865,20 @@ UTEST(NIST_DEC_VALIDATION, AES_GCM_256_IV_96_PT_128_TEST_4)
free(buffer_nist_key_b);
}

// Spot check of MAC tags assuming no plaintext payload
// Accomplished by a multi-step process:
// 1) Ensure a valid implementation - Utilize Cyberchef's AES Encrypt to re-create a NIST test vector with AAD
// 2) Generate Truth data - Use same CyberChef settings on a created TF
// 3) Validate Cryptolib output with CyberChef output
// Reference 1: https://gchq.github.io/CyberChef/#recipe=AES_Encrypt(%7B'option':'Hex','string':''%7D,%7B'option':'Hex','string':''%7D,'GCM','Hex','Hex',%7B'option':'Hex','string':''%7D)
// Reference 2: https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Algorithm-Validation-Program/documents/mac/gcmtestvectors.zip

// Bit Mask of zeros
// Bit-mask of zeros in this test for a total length of:
// Header (5) + Segment Hdr (1) + SPI (2) + IV (12)
// This means zero input to the MAC, which precedes the TF FECF
/**
* @brief Validation Test: MAC
* Reference 1: https://gchq.github.io/CyberChef/#recipe=AES_Encrypt(%7B'option':'Hex','string':''%7D,%7B'option':'Hex','string':''%7D,'GCM','Hex','Hex',%7B'option':'Hex','string':''%7D)
* Reference 2: https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Algorithm-Validation-Program/documents/mac/gcmtestvectors.zip
* Spot check of MAC tags assuming no plaintext payload
* Accomplished by a multi-step process:
* 1) Ensure a valid implementation - Utilize Cyberchef's AES Encrypt to re-create a NIST test vector with AAD
* 2) Generate Truth data - Use same CyberChef settings on a created TF
* 3) Validate Cryptolib output with CyberChef output
* Bit Mask of zeros
* Bit-mask of zeros in this test for a total length of:
* Header (5) + Segment Hdr (1) + SPI (2) + IV (12)
* This means zero input to the MAC, which precedes the TF FECF
**/
UTEST(NIST_ENC_MAC_VALIDATION, AES_GCM_256_IV_96_PT_128_TEST_0)
{
uint8 *ptr_enc_frame = NULL;
Expand Down Expand Up @@ -881,10 +948,13 @@ UTEST(NIST_ENC_MAC_VALIDATION, AES_GCM_256_IV_96_PT_128_TEST_0)
free(buffer_nist_aad_b);
}

// Bit Mask of ones
// Bit-mask of ones in this test on an empty frame for a total length of:
// Header (5) + Segment Hdr (1) + SPI (2) + IV (12)
// All bits are unmasked input to the MAC algorithm
/**
* @brief Validation Test: MAC
* Bit Mask of ones
* Bit-mask of ones in this test on an empty frame for a total length of:
* Header (5) + Segment Hdr (1) + SPI (2) + IV (12)
* All bits are unmasked input to the MAC algorithm
**/
UTEST(NIST_ENC_MAC_VALIDATION, AES_GCM_256_IV_96_PT_128_TEST_1)
{
uint8 *ptr_enc_frame = NULL;
Expand Down Expand Up @@ -954,7 +1024,10 @@ UTEST(NIST_ENC_MAC_VALIDATION, AES_GCM_256_IV_96_PT_128_TEST_1)
free(buffer_cyber_chef_mac_b);
}

// Bit-mask of ones
/**
* @brief Validation Test: MAC
* Bit-mask of ones
**/
UTEST(NIST_DEC_MAC_VALIDATION, AES_GCM_256_IV_96_PT_128_TEST_0)
{
// Setup & Initialize CryptoLib
Expand Down
37 changes: 23 additions & 14 deletions fsw/crypto_util/app/ut_tc_apply.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,20 @@
[email protected]
*/

/*
/**
* Unit Tests that macke use of TC_ApplySecurity function on the data.
*/
**/
#include "ut_tc_apply.h"
#include "utest.h"
#include "crypto.h"
#include "crypto_error.h"

// TODO: Should this be set up with a set of tests, or continue to Crypto_Init() each time. For now I think the current setup is the best path.

// Inactive SA Database
// TODO: Should this return or continue to function as currently written when SA is not initalized?
// TODO: I don't believe Crypto Init is cleaned up between each test. I am fairly certain that the init persists between tests.

// TODO: Need to cherry-pick Crypto_reInit functionality to use between each of these tests
/**
* @brief Unit Test: No Crypto_Init()
*
* TC_ApplySecurity should reject functionality if the Crypto_Init() function has not been called.
**/
UTEST(TC_APPLY_SECURITY, NO_CRYPTO_INIT)
{
// No Crypto_Init(), but we still Configure It;
Expand All @@ -52,7 +51,10 @@ UTEST(TC_APPLY_SECURITY, NO_CRYPTO_INIT)
Crypto_Shutdown();
}

// Nominal Test. This should read a raw_tc_sdls_ping.dat file, continue down the "happy path", and return CRYPTO_LIB_SUCCESS
/**
* @brief Unit Test: Nominal Case
* This should read a raw_tc_sdls_ping and continue down the "happy Path", finally returning CRYPTO_LIB_SUCCESS
**/
UTEST(TC_APPLY_SECURITY, HAPPY_PATH)
{
//Setup & Initialize CryptoLib
Expand All @@ -75,7 +77,10 @@ UTEST(TC_APPLY_SECURITY, HAPPY_PATH)
ASSERT_EQ(CRYPTO_LIB_SUCCESS, return_val);
}

// Bad Space Craft ID. This should pass the flawed .dat file, and return MANAGED_PARAMETERS_FOR_GVCID_NOT_FOUND
/**
* @brief Unit Test: Bad Spacecraft ID
* This should pass the flawed hex string, and return CRYPTO_LIB_ERR_INVALID_SCID
**/
UTEST(TC_APPLY_SECURITY, BAD_SPACE_CRAFT_ID)
{
//Setup & Initialize CryptoLib
Expand All @@ -96,6 +101,10 @@ UTEST(TC_APPLY_SECURITY, BAD_SPACE_CRAFT_ID)
ASSERT_EQ(MANAGED_PARAMETERS_FOR_GVCID_NOT_FOUND, return_val);
}

/**
* @brief Unit Test: Bad Virtual Channel ID
* This will be passed a flawed hex string with an invalid virtual channel ID. CRYPTO_LIB_ERR_INVALID_VCID should be returned.
**/
UTEST(TC_APPLY_SECURITY, BAD_VIRTUAL_CHANNEL_ID)
{
//Setup & Initialize CryptoLib
Expand All @@ -117,10 +126,10 @@ UTEST(TC_APPLY_SECURITY, BAD_VIRTUAL_CHANNEL_ID)
ASSERT_EQ(MANAGED_PARAMETERS_FOR_GVCID_NOT_FOUND, return_val);
}

// This test should test how to handle a null buffer being passed into the ApplySecurity Function.
// Currently this functionality isn't handled properly, and casues a seg-fault.
// TODO: We need to determine how this would return, as it will help in other test cases.
// Should this return the original buffer, a null pointer, OS_ERROR, etc?
/**
* @brief Unit Test: Null Buffer -> TC_ApplySecurity
* Tests how ApplySecurity function handles a null buffer. Should reject functionality, and return CRYPTO_LIB_ERR_NULL_BUFFER
**/
UTEST(TC_APPLY_SECURITY, NULL_BUFFER)
{
//Setup & Initialize CryptoLib
Expand Down
Loading