|
BSL v1.1.1 - 39.g9f43410
AMMOS Bundle Protocol Security Library (BSL)
|
#include "DefaultScUtils.h"#include <bsl/BPSecLib_Private.h>#include <bsl/crypto/CryptoInterface.h>#include <bsl/dynamic/PublicInterfaceImpl.h>#include <bsl/mock_bpa/agent.h>#include <bsl/mock_bpa/log.h>#include <openssl/err.h>#include <openssl/rand.h>#include <inttypes.h>#include <unity.h>
Include dependency graph for test_CryptoInterface.c:Macros | |
| #define | TEST_THREADS 10 |
Functions | |
| static int | gcm_encrypt (const EVP_CIPHER *cipher, unsigned char *plaintext, int plaintext_len, unsigned char *aad, int aad_len, unsigned char *key, unsigned char *iv, int iv_len, unsigned char *ciphertext, int *ciphertext_len, unsigned char *tag) |
| copied from openssl examples, used for testing for now https://wiki.openssl.org/index.php/EVP_Authenticated_Encryption_and_Decryption | |
| static int | gcm_decrypt (const EVP_CIPHER *cipher, unsigned char *ciphertext, int ciphertext_len, unsigned char *aad, int aad_len, unsigned char *tag, unsigned char *key, unsigned char *iv, int iv_len, unsigned char *plaintext, int *plaintext_len) |
| copied from openssl examples, used for testing for now https://wiki.openssl.org/index.php/EVP_Authenticated_Encryption_and_Decryption | |
| void | suiteSetUp (void) |
| int | suiteTearDown (int failures) |
| void | setUp (void) |
| void | tearDown (void) |
| void | test_SeqReader_flat (void) |
| void | test_SeqWriter_flat (void) |
| TEST_MATRIX ([0, 1], ["Key1"], [BSL_CRYPTO_SHA_256], ["4869205468657265"], ["b0344c61d8db38535ca8afceaf0bf12b881dc200c9833da726e9376c2e32cff7"]) TEST_MATRIX([0 | |
| TEST_ASSERT_EQUAL_INT_MESSAGE (0, BSL_TestUtils_DecodeBase16_cstr(&pt_in_data, plaintext_in), "BSL_TestUtils_DecodeBase16_cstr() failed") | |
| TEST_ASSERT_EQUAL (0, BSL_Crypto_GetRegistryKeyName(keyid, &keyhandle)) | |
| TEST_ASSERT_EQUAL (0, BSL_AuthCtx_Init(&hmac, keyhandle, sha_var)) | |
| BSL_Crypto_ReleaseKeyHandle (keyhandle) | |
| switch (input_case) | |
| switch (sha_var) | |
| TEST_ASSERT_EQUAL (0, BSL_AuthCtx_Finalize(&hmac, &tag)) | |
| TEST_ASSERT_EQUAL (expect_hmac_sz, tag.len) | |
| TEST_ASSERT_TRUE (BSL_TestUtils_IsB16StrEqualTo(expected, tag)) | |
| void | test_encrypt (const char *plaintext_in, const char *keyid) |
| Test library encrypt using OpenSSL example decrypt. | |
| void | test_decrypt (const char *plaintext_in, const char *keyid) |
| Test library decrypt using OpenSSL example encrypt. | |
| void | test_crypto_generate_iv (int iv_len) |
| TEST_CASE ("000102030405060708090A0B0C0D0E0F", "00112233445566778899AABBCCDDEEFF", "1FA68B0A8112B447AEF34BD8FB5A7B829D3E862371D2CFE5") | |
| TEST_CASE ("0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b", BSL_CRYPTO_KDF_HKDF_SHA_256, "000102030405060708090a0b0c", "f0f1f2f3f4f5f6f7f8f9", 42, "3cb25f25faacd57a90434f64d0362f2a2d2d0a90cf1a5a4c5db02d56ecc4c5bf34007208d5b887185865") | |
| static void * | add_key_to_reg_fn (void *arg) |
| static void * | get_key_from_reg_fn (void *arg) |
| void | test_add_key_concurrency (void) |
| void | test_get_key_concurrency (void) |
| void | test_key_stats (void) |
Variables | |
| static BSL_LibCtx_t | bsl |
| static uint8_t | test_128 [16] |
| static uint8_t | test_256 [32] |
| const char * | keyid |
| const char BSL_Crypto_SHAVariant_e | sha_var |
| const char BSL_Crypto_SHAVariant_e const char * | plaintext_in |
| const char BSL_Crypto_SHAVariant_e const char const char * | expected |
| BSL_Data_Init & | pt_in_data |
| BSL_Crypto_KeyHandle_t | keyhandle |
| BSL_AuthCtx_t | hmac |
| int | expect_hmac_sz = 0 |
| BSL_Data_t | tag |
| static pthread_t | threads [TEST_THREADS] |
| #define TEST_THREADS 10 |
|
static |
References BSL_Crypto_AddRegistryKeyName(), BSL_LOG_INFO, and BSL_SUCCESS.
Referenced by test_add_key_concurrency().
| BSL_Crypto_ReleaseKeyHandle | ( | keyhandle | ) |
Referenced by get_key_from_reg_fn(), test_add_key_concurrency(), TEST_CASE(), TEST_CASE(), test_decrypt(), test_encrypt(), and test_key_stats().
|
static |
copied from openssl examples, used for testing for now https://wiki.openssl.org/index.php/EVP_Authenticated_Encryption_and_Decryption
Referenced by test_encrypt().
|
static |
copied from openssl examples, used for testing for now https://wiki.openssl.org/index.php/EVP_Authenticated_Encryption_and_Decryption
Referenced by test_decrypt().
|
static |
References BSL_Crypto_GetRegistryKeyName(), BSL_Crypto_ReleaseKeyHandle(), BSL_LOG_INFO, and BSL_SUCCESS.
Referenced by test_get_key_concurrency().
| void setUp | ( | void | ) |
References bsl, BSL_API_InitLib(), BSL_Crypto_AddRegistryKeyName(), BSL_CryptoInit(), test_128, test_256, and TEST_ASSERT_EQUAL().
| void suiteSetUp | ( | void | ) |
| int suiteTearDown | ( | int | failures | ) |
References mock_bpa_LogClose().
| switch | ( | input_case | ) |
| switch | ( | sha_var | ) |
References BSL_CRYPTO_SHA_256, BSL_CRYPTO_SHA_384, BSL_CRYPTO_SHA_512, and expect_hmac_sz.
| void tearDown | ( | void | ) |
References bsl, BSL_API_DeinitLib(), BSL_CryptoDeinit(), and TEST_ASSERT_EQUAL().
| void test_add_key_concurrency | ( | void | ) |
| TEST_ASSERT_EQUAL | ( | 0 | , |
| BSL_AuthCtx_Finalize &, & | tag | ||
| ) |
| TEST_ASSERT_EQUAL | ( | 0 | , |
| BSL_AuthCtx_Init &,, | sha_var | ||
| ) |
| TEST_ASSERT_EQUAL | ( | 0 | , |
| BSL_Crypto_GetRegistryKeyName(keyid, &keyhandle) | |||
| ) |
Referenced by _setUp(), _tearDown(), ccsds_mac_rng(), cose_exA_5_rng(), cose_exA_6_rng(), n_test_BSL_6(), setUp(), switch(), tearDown(), test_add_key_concurrency(), test_AppendixA_Example1_BIB_Source(), test_AppendixA_Example1_BIB_VerifyAccept(), test_AppendixA_Example4_BCB_Source(), test_AppendixA_Example4_BCB_VerifyAccept(), test_AppendixA_Example5_BCB_Source(), test_AppendixA_Example5_BCB_VerifyAccept(), test_AppendixA_Example6_BCB_Source(), test_BSL_32(), TEST_CASE(), TEST_CASE(), TEST_CASE(), test_CCSDS_Example_Mac_Source(), test_CCSDS_Example_Mac_VerifyAccept(), test_CoseSc_InvalidOptions_Source(), test_CoseSc_InvalidOptions_Verifier(), test_crypto_generate_iv(), test_decrypt(), test_dyn_mem_cbs_BSL_32(), test_encrypt(), test_get_key_concurrency(), test_key_stats(), test_MultiplePolicyProviders(), test_PolicyProvider_Inspect_RFC9173_BIB(), test_PolicyProvider_InspectEmptyRuleset(), test_PolicyProvider_InspectSingleBIBRuleset(), test_RFC9173_AppendixA_Example1_BIB_Source(), test_RFC9173_AppendixA_Example2_BCB_Acceptor(), test_RFC9173_AppendixA_Example2_BCB_Source(), test_RFC9173_AppendixA_Example3_Acceptor(), test_RFC9173_AppendixA_Example3_Source(), test_RFC9173_AppendixA_Example4_Acceptor(), test_RFC9173_AppendixA_Example4_Source(), test_SamplePolicyProvider_WildcardPolicyRuleVerifiesBIB(), test_sec_accept_keyunwrap(), test_sec_source_keywrap(), test_SecurityContext_BIB_Acceptor(), test_SecurityContext_BIB_Source(), test_SecurityContext_BIB_Verifier(), test_SecurityContext_BIB_Verifier_Failure(), test_SecurityContext_ValidatePolicyActionSet_UsesRegisteredValidator(), and TestASBDecodeEncodeClosure().
| TEST_ASSERT_EQUAL | ( | expect_hmac_sz | , |
| tag. | len | ||
| ) |
| TEST_ASSERT_EQUAL_INT_MESSAGE | ( | 0 | , |
| BSL_TestUtils_DecodeBase16_cstr &, | plaintext_in, | ||
| "BSL_TestUtils_DecodeBase16_cstr() failed" | |||
| ) |
Referenced by test_AppendixA_Example1_BIB_Source(), test_AppendixA_Example1_BIB_VerifyAccept(), test_AppendixA_Example4_BCB_Source(), test_AppendixA_Example4_BCB_VerifyAccept(), test_AppendixA_Example5_BCB_Source(), test_AppendixA_Example5_BCB_VerifyAccept(), test_AppendixA_Example6_BCB_Source(), test_BSL_HostEID_DecodeFromText_ipn(), test_BSL_HostEID_DecodeFromText_valid(), test_BSL_HostEIDPattern_DecodeFromText_valid(), test_bsl_loopback_eid(), test_BSL_TextUtil_Base16_Decode_valid(), TEST_CASE(), TEST_CASE(), TEST_CASE(), TEST_CASE(), test_CCSDS_Example_Mac_Source(), test_CCSDS_Example_Mac_VerifyAccept(), test_mock_bpa_crc_crc16(), test_mock_bpa_crc_crc32c(), test_mock_bpa_ctr_decode_invalid(), test_qcbor_decode_array_nested(), test_qcbor_decode_map_sequential(), test_qcbor_decode_only_head(), test_qcbor_decode_with_head(), and test_qcbor_decode_without_head().
| TEST_ASSERT_TRUE | ( | BSL_TestUtils_IsB16StrEqualTo(expected, tag) | ) |
Referenced by test_AppendixA_Example1_BIB_Source(), test_AppendixA_Example1_BIB_VerifyAccept(), test_AppendixA_Example4_BCB_Source(), test_AppendixA_Example4_BCB_VerifyAccept(), test_AppendixA_Example5_BCB_Source(), test_AppendixA_Example5_BCB_VerifyAccept(), test_AppendixA_Example6_BCB_Source(), test_bsl_mock_encode_bundle(), test_bsl_mock_encode_canonical(), test_bsl_mock_encode_primary(), TEST_CASE(), TEST_CASE(), TEST_CASE(), test_CCSDS_Example_Mac_Source(), test_CCSDS_Example_Mac_VerifyAccept(), test_CoseSc_InvalidOptions_Source(), test_CoseSc_InvalidOptions_Verifier(), test_RFC9173_AppendixA_Example1_BIB_Source(), test_RFC9173_AppendixA_Example2_BCB_Acceptor(), test_RFC9173_AppendixA_Example2_BCB_Source(), test_RFC9173_AppendixA_Example3_Source(), test_RFC9173_AppendixA_Example4_Acceptor(), test_RFC9173_AppendixA_Example4_Source(), test_sec_accept_keyunwrap(), test_sec_source_keywrap(), test_SecurityContext_BIB_Acceptor(), test_SecurityContext_BIB_Source(), test_SecurityContext_BIB_Verifier(), and TestASBDecodeEncodeClosure().
| TEST_CASE | ( | "000102030405060708090A0B0C0D0E0F" | , |
| "00112233445566778899AABBCCDDEEFF", | |||
| "1FA68B0A8112B447AEF34BD8FB5A7B829D3E862371D2CFE5" | |||
| ) |
References BSL_Crypto_AddRegistryKeyName(), BSL_Crypto_GetKeyStatistics(), BSL_Crypto_GetRegistryKeyName(), BSL_CRYPTO_KEYSTATS_BYTES_PROCESSED, BSL_CRYPTO_KEYSTATS_TIMES_USED, BSL_Crypto_ReleaseKeyHandle(), BSL_Crypto_RemoveRegistryKeyName(), BSL_Crypto_WrapKey(), BSL_Data_Deinit(), BSL_Data_Init(), BSL_Data_InitBuffer(), BSL_TestUtils_DecodeBase16_cstr(), BSL_TestUtils_IsB16StrEqualTo(), expected, BSL_Data_t::len, BSL_Data_t::ptr, BSL_Crypto_KeyStats_t::stats, TEST_ASSERT_EQUAL(), and TEST_ASSERT_TRUE().
| TEST_CASE | ( | "0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b" | , |
| BSL_CRYPTO_KDF_HKDF_SHA_256, | |||
| "000102030405060708090a0b0c" | , | ||
| "f0f1f2f3f4f5f6f7f8f9" | , | ||
| 42, | |||
| "3cb25f25faacd57a90434f64d0362f2a2d2d0a90cf1a5a4c5db02d56ecc4c5bf34007208d5b887185865" | |||
| ) |
References BSL_Crypto_AddRegistryKeyName(), BSL_Crypto_CompareKeys(), BSL_Crypto_GetKeyStatistics(), BSL_Crypto_GetRegistryKeyName(), BSL_Crypto_KDF(), BSL_CRYPTO_KEYSTATS_BYTES_PROCESSED, BSL_CRYPTO_KEYSTATS_TIMES_USED, BSL_Crypto_ReleaseKeyHandle(), BSL_Data_Deinit(), BSL_Data_Init(), BSL_TestUtils_DecodeBase16_cstr(), BSL_Data_t::len, BSL_Data_t::ptr, BSL_Crypto_KeyStats_t::stats, TEST_ASSERT_EQUAL(), and TEST_ASSERT_TRUE().
| void test_crypto_generate_iv | ( | int | iv_len | ) |
References BSL_Crypto_GenIV(), BSL_Data_Deinit(), BSL_Data_InitBuffer(), and TEST_ASSERT_EQUAL().
| void test_decrypt | ( | const char * | plaintext_in, |
| const char * | keyid | ||
| ) |
Test library decrypt using OpenSSL example encrypt.
References BSL_Cipher_AddAadBuffer(), BSL_Cipher_AddSeq(), BSL_Cipher_Deinit(), BSL_Cipher_FinalizeSeq(), BSL_Cipher_Init(), BSL_Cipher_SetTag(), BSL_CRYPTO_AES_128, BSL_CRYPTO_AES_256, BSL_CRYPTO_DECRYPT, BSL_Crypto_GenIV(), BSL_Crypto_GetRegistryKeyName(), BSL_Crypto_ReleaseKeyHandle(), BSL_Data_Deinit(), BSL_Data_InitBuffer(), BSL_free(), BSL_SeqReader_Destroy(), BSL_SeqWriter_Destroy(), BSL_TestUtils_FlatReader(), BSL_TestUtils_FlatWriter(), ctx, gcm_encrypt(), keyid, BSL_Data_t::len, plaintext_in, BSL_Data_t::ptr, tag, test_128, test_256, and TEST_ASSERT_EQUAL().
| void test_encrypt | ( | const char * | plaintext_in, |
| const char * | keyid | ||
| ) |
Test library encrypt using OpenSSL example decrypt.
References BSL_Cipher_AddAadBuffer(), BSL_Cipher_AddSeq(), BSL_Cipher_Deinit(), BSL_Cipher_FinalizeSeq(), BSL_Cipher_GetTag(), BSL_Cipher_Init(), BSL_CRYPTO_AES_128, BSL_CRYPTO_AES_256, BSL_CRYPTO_ENCRYPT, BSL_Crypto_GenIV(), BSL_Crypto_GetRegistryKeyName(), BSL_Crypto_ReleaseKeyHandle(), BSL_Data_Deinit(), BSL_Data_Init(), BSL_Data_InitBuffer(), BSL_free(), BSL_SeqReader_Destroy(), BSL_SeqWriter_Destroy(), BSL_TestUtils_FlatReader(), BSL_TestUtils_FlatWriter(), ctx, gcm_decrypt(), keyid, BSL_Data_t::len, plaintext_in, BSL_Data_t::ptr, tag, test_128, test_256, and TEST_ASSERT_EQUAL().
Referenced by test_key_stats().
| void test_get_key_concurrency | ( | void | ) |
References BSL_Crypto_AddRegistryKeyName(), get_key_from_reg_fn(), TEST_ASSERT_EQUAL(), TEST_THREADS, and threads.
| void test_key_stats | ( | void | ) |
| TEST_MATRIX | ( | ) |
| void test_SeqReader_flat | ( | void | ) |
References BSL_SeqReader_Destroy(), BSL_SeqReader_Get(), and BSL_TestUtils_FlatReader().
| void test_SeqWriter_flat | ( | void | ) |
References BSL_free(), BSL_SeqWriter_Destroy(), BSL_SeqWriter_Put(), and BSL_TestUtils_FlatWriter().
|
static |
| int expect_hmac_sz = 0 |
Referenced by switch().
| const char BSL_Crypto_SHAVariant_e const char const char* expected |
Referenced by TEST_CASE().
| BSL_AuthCtx_Deinit & hmac |
Referenced by switch().
| BSL_Crypto_KeyHandle_t keyhandle |
Referenced by BSL_AuthCtx_Init(), BSL_Cipher_Init(), BSL_Crypto_AddRegistryKeyName(), BSL_Crypto_ReleaseKeyHandle(), BSLX_CoseSc_GenerateNonce(), mock_bpa_key_registry_cosekey_decode(), mock_bpa_key_registry_init_jwk(), test_AppendixA_Example1_BIB_Source(), test_AppendixA_Example1_BIB_VerifyAccept(), test_AppendixA_Example4_BCB_Source(), test_AppendixA_Example4_BCB_VerifyAccept(), test_AppendixA_Example5_BCB_Source(), test_AppendixA_Example5_BCB_VerifyAccept(), test_AppendixA_Example6_BCB_Source(), test_CCSDS_Example_Mac_Source(), and test_CCSDS_Example_Mac_VerifyAccept().
| const char* keyid |
Referenced by BSL_Crypto_AddRegistryKey(), BSL_Crypto_GetRegistryKey(), BSL_Crypto_RemoveRegistryKey(), set_CoseSc_InvalidOptions_Source_baseline(), test_AppendixA_Example1_BIB_Source(), test_AppendixA_Example1_BIB_VerifyAccept(), test_AppendixA_Example4_BCB_Source(), test_AppendixA_Example4_BCB_VerifyAccept(), test_AppendixA_Example5_BCB_Source(), test_AppendixA_Example5_BCB_VerifyAccept(), test_AppendixA_Example6_BCB_Source(), test_CCSDS_Example_Mac_Source(), test_CCSDS_Example_Mac_VerifyAccept(), test_decrypt(), and test_encrypt().
| const char BSL_Crypto_SHAVariant_e const char* plaintext_in |
Referenced by test_decrypt(), and test_encrypt().
| BSL_Data_Deinit & pt_in_data |
Referenced by switch().
| const char BSL_Crypto_SHAVariant_e sha_var |
Referenced by BSL_AuthCtx_Init().
| BSL_Data_Deinit & tag |
|
static |
Referenced by setUp(), test_decrypt(), test_encrypt(), and test_key_stats().
|
static |
Referenced by setUp(), test_decrypt(), and test_encrypt().
|
static |
Referenced by test_add_key_concurrency(), and test_get_key_concurrency().