|
BSL v1.0.0 - 16.g9d98179
AMMOS Bundle Protocol Security Library (BSL)
|
#include <inttypes.h>#include <openssl/err.h>#include <openssl/rand.h>#include <unity.h>#include <BPSecLib_Private.h>#include <CryptoInterface.h>#include <backend/UtilDefs_SeqReadWrite.h>#include <backend/PublicInterfaceImpl.h>#include <mock_bpa/agent.h>#include <mock_bpa/log.h>#include "bsl_test_utils.h"
Include dependency graph for test_CryptoInterface.c:Macros | |
| #define | TEST_THREADS 10 |
Functions | |
| 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 | |
| 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 | |
| string_init_set_str (exp_txt, expected) | |
| TEST_ASSERT_EQUAL_INT_MESSAGE (0, BSL_TestUtils_DecodeBase16(&expected_data, exp_txt), "BSL_TestUtils_DecodeBase16() failed") | |
| string_init_set_str (pt_txt, plaintext_in) | |
| TEST_ASSERT_EQUAL (0, BSL_Crypto_GetRegistryKey(keyid, &keyhandle)) | |
| TEST_ASSERT_EQUAL (0, BSL_AuthCtx_Init(&hmac, keyhandle, sha_var)) | |
| switch (input_case) | |
| switch (hmac.SHA_variant) | |
| TEST_ASSERT_EQUAL (0, BSL_AuthCtx_Finalize(&hmac, &hmac_buf_ptr, &hmac_len)) | |
| TEST_ASSERT_EQUAL (hmac_sz, hmac_len) | |
| TEST_ASSERT_EQUAL_INT (hmac_len, expected_data.len) | |
| TEST_ASSERT_EQUAL_MEMORY (hmac_buf_ptr, expected_data.ptr, expected_data.len) | |
| TEST_ASSERT_EQUAL (0, BSL_AuthCtx_Deinit(&hmac)) | |
| string_clear (exp_txt) | |
| string_clear (pt_txt) | |
| 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") | |
| 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_CryptoCipherSHAVariant_e | sha_var |
| const char BSL_CryptoCipherSHAVariant_e const char * | plaintext_in |
| const char BSL_CryptoCipherSHAVariant_e const char char * | expected |
| BSL_Data_t | expected_data |
| string_t | pt_txt |
| BSL_Data_t | pt_in_data |
| void * | keyhandle |
| BSL_AuthCtx_t | hmac |
| int | hmac_sz = 0 |
| uint8_t | hmac_buf [hmac_sz] |
| void * | hmac_buf_ptr = hmac_buf |
| size_t | hmac_len |
| static pthread_t | threads [TEST_THREADS] |
| #define TEST_THREADS 10 |
|
static |
References BSL_Crypto_AddRegistryKey(), BSL_LOG_INFO, and BSL_SUCCESS.
Referenced by test_add_key_concurrency().
| 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
References ctx.
Referenced by test_encrypt().
| 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
References ctx.
Referenced by test_decrypt().
|
static |
References BSL_Crypto_GetRegistryKey(), BSL_LOG_INFO, and BSL_SUCCESS.
Referenced by test_get_key_concurrency().
| void setUp | ( | void | ) |
References bsl, BSL_API_InitLib(), BSL_Crypto_AddRegistryKey(), BSL_CryptoInit(), test_128, test_256, and TEST_ASSERT_EQUAL().
| string_clear | ( | exp_txt | ) |
Referenced by BSL_Crypto_AddRegistryKey(), BSL_Crypto_GetKeyStatistics(), BSL_Crypto_GetRegistryKey(), BSL_Crypto_RemoveRegistryKey(), BSL_TestUtils_IsB16StrEqualTo(), BSL_TestUtils_LoadBundleFromCBOR(), mock_bpa_LogEvent_event_deinit(), printencoded(), test_bsl_loopback_bundle(), test_bsl_loopback_eid(), test_bsl_mock_encode_canonical(), test_BSL_TestUtils_DecodeBase16_valid(), TEST_CASE(), TEST_CASE(), TEST_CASE(), TEST_CASE(), TEST_CASE(), test_DecodeBase16(), test_qcbor_decode_only_head(), test_qcbor_decode_with_head(), test_qcbor_decode_without_head(), test_sec_accept_keyunwrap(), and test_sec_source_keywrap().
| string_clear | ( | pt_txt | ) |
| string_init_set_str | ( | exp_txt | , |
| expected | |||
| ) |
Referenced by BSL_Crypto_AddRegistryKey(), BSL_Crypto_GetKeyStatistics(), BSL_Crypto_GetRegistryKey(), BSL_Crypto_RemoveRegistryKey(), BSL_TestUtils_IsB16StrEqualTo(), BSL_TestUtils_LoadBundleFromCBOR(), test_bsl_loopback_bundle(), test_bsl_loopback_eid(), test_bsl_mock_encode_canonical(), test_BSL_TestUtils_DecodeBase16_valid(), TEST_CASE(), TEST_CASE(), TEST_CASE(), TEST_CASE(), TEST_CASE(), test_DecodeBase16(), test_qcbor_decode_only_head(), test_qcbor_decode_with_head(), test_qcbor_decode_without_head(), test_sec_accept_keyunwrap(), and test_sec_source_keywrap().
| string_init_set_str | ( | pt_txt | , |
| plaintext_in | |||
| ) |
| void suiteSetUp | ( | void | ) |
| int suiteTearDown | ( | int | failures | ) |
References mock_bpa_LogClose().
| switch | ( | hmac. | SHA_variant | ) |
References BSL_CRYPTO_SHA_256, BSL_CRYPTO_SHA_384, BSL_CRYPTO_SHA_512, and hmac_sz.
| switch | ( | input_case | ) |
| void tearDown | ( | void | ) |
References bsl, BSL_API_DeinitLib(), BSL_CryptoDeinit(), and TEST_ASSERT_EQUAL().
| void test_add_key_concurrency | ( | void | ) |
References add_key_to_reg_fn(), BSL_Crypto_GetRegistryKey(), BSL_SUCCESS, TEST_ASSERT_EQUAL(), TEST_THREADS, and threads.
| TEST_ASSERT_EQUAL | ( | 0 | , |
| BSL_AuthCtx_Deinit & | hmac | ||
| ) |
| TEST_ASSERT_EQUAL | ( | 0 | , |
| BSL_AuthCtx_Finalize &, &, & | hmac_len | ||
| ) |
| TEST_ASSERT_EQUAL | ( | 0 | , |
| BSL_AuthCtx_Init &,, | sha_var | ||
| ) |
| TEST_ASSERT_EQUAL | ( | 0 | , |
| BSL_Crypto_GetRegistryKey(keyid, &keyhandle) | |||
| ) |
Referenced by _setUp(), _tearDown(), n_test_BSL_6(), setUp(), switch(), tearDown(), test_add_key_concurrency(), test_BSL_32(), test_bsl_mock_encode_bundle(), TEST_CASE(), TEST_CASE(), TEST_CASE(), 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(), and TestASBDecodeEncodeClosure().
| TEST_ASSERT_EQUAL_INT | ( | hmac_len | , |
| expected_data. | len | ||
| ) |
Referenced by suiteSetUp(), switch(), test_BSL_HostEID_DecodeFromText_ipn(), test_BSL_HostEIDPattern_DecodeFromText_valid(), test_BSL_HostEIDPattern_IsMatch(), test_bsl_loopback_bundle(), test_bsl_loopback_eid(), test_bsl_mock_encode_bundle(), test_bsl_mock_encode_canonical(), test_BSL_TestUtils_DecodeBase16_valid(), TEST_CASE(), TEST_CASE(), TEST_CASE(), TEST_CASE(), TEST_CASE(), test_decrypt(), test_encrypt(), test_mock_bpa_base16_decode_valid(), test_mock_bpa_base16_encode(), test_mock_bpa_base64_decode_valid(), test_mock_bpa_slash_escape_valid(), test_mock_bpa_slash_unescape_valid(), test_mock_bpa_uri_percent_decode_valid(), test_mock_bpa_uri_percent_encode_valid(), test_qcbor_decode_only_head(), test_qcbor_decode_with_head(), test_qcbor_decode_without_head(), test_sec_source_keywrap(), test_SeqReader_flat(), test_SeqWriter_flat(), and TestASBDecodeEncodeClosure().
| TEST_ASSERT_EQUAL_INT_MESSAGE | ( | 0 | , |
| BSL_TestUtils_DecodeBase16 &, | exp_txt, | ||
| "BSL_TestUtils_DecodeBase16() failed" | |||
| ) |
Referenced by test_BSL_HostEID_DecodeFromText_ipn(), test_BSL_HostEID_DecodeFromText_valid(), test_BSL_HostEIDPattern_DecodeFromText_valid(), test_bsl_loopback_bundle(), test_bsl_loopback_eid(), test_bsl_mock_encode_canonical(), test_BSL_TestUtils_DecodeBase16_valid(), TEST_CASE(), TEST_CASE(), TEST_CASE(), TEST_CASE(), test_mock_bpa_base16_decode_valid(), test_qcbor_decode_only_head(), test_qcbor_decode_with_head(), and test_qcbor_decode_without_head().
| TEST_ASSERT_EQUAL_MEMORY | ( | hmac_buf_ptr | , |
| expected_data. | ptr, | ||
| expected_data. | len | ||
| ) |
Referenced by test_bsl_loopback_bundle(), test_bsl_loopback_eid(), test_bsl_mock_encode_bundle(), test_bsl_mock_encode_canonical(), test_BSL_TestUtils_DecodeBase16_valid(), TEST_CASE(), TEST_CASE(), TEST_CASE(), TEST_CASE(), test_decrypt(), test_encrypt(), test_mock_bpa_base16_decode_valid(), test_mock_bpa_base64_decode_valid(), test_RFC9173_AppendixA_Example1_BIB_Source(), test_RFC9173_AppendixA_Example2_BCB_Acceptor(), test_RFC9173_AppendixA_Example2_BCB_Source(), test_sec_accept_keyunwrap(), test_sec_source_keywrap(), test_SeqReader_flat(), test_SeqWriter_flat(), and TestASBDecodeEncodeClosure().
| TEST_CASE | ( | "000102030405060708090A0B0C0D0E0F" | , |
| "00112233445566778899AABBCCDDEEFF", | |||
| "1FA68B0A8112B447AEF34BD8FB5A7B829D3E862371D2CFE5" | |||
| ) |
References BSL_Crypto_AddRegistryKey(), BSL_Crypto_ClearGeneratedKeyHandle(), BSL_Crypto_GetRegistryKey(), BSL_Crypto_RemoveRegistryKey(), BSL_Crypto_WrapKey(), BSL_Data_Deinit(), BSL_Data_Init(), BSL_Data_InitBuffer(), BSL_TestUtils_DecodeBase16(), expected, expected_data, BSL_Data_t::len, BSL_Data_t::ptr, string_clear(), string_init_set_str(), TEST_ASSERT_EQUAL(), and TEST_ASSERT_EQUAL_MEMORY().
| void test_crypto_generate_iv | ( | int | iv_len | ) |
References BSL_Crypto_GenIV(), and TEST_ASSERT_EQUAL().
| void test_decrypt | ( | const char * | plaintext_in, |
| const char * | keyid | ||
| ) |
Test library decrypt using OpenSSL example encrypt.
References BSL_Cipher_AddAAD(), 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_GetRegistryKey(), BSL_free(), BSL_SeqReader_Destroy(), BSL_SeqWriter_Destroy(), BSL_TestUtils_FlatReader(), BSL_TestUtils_FlatWriter(), ctx, gcm_encrypt(), keyid, plaintext_in, test_128, test_256, TEST_ASSERT_EQUAL(), TEST_ASSERT_EQUAL_INT(), and TEST_ASSERT_EQUAL_MEMORY().
| void test_encrypt | ( | const char * | plaintext_in, |
| const char * | keyid | ||
| ) |
Test library encrypt using OpenSSL example decrypt.
References BSL_Cipher_AddAAD(), 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_GetRegistryKey(), BSL_free(), BSL_SeqReader_Destroy(), BSL_SeqWriter_Destroy(), BSL_TestUtils_FlatReader(), BSL_TestUtils_FlatWriter(), ctx, gcm_decrypt(), keyid, plaintext_in, test_128, test_256, TEST_ASSERT_EQUAL(), TEST_ASSERT_EQUAL_INT(), and TEST_ASSERT_EQUAL_MEMORY().
Referenced by test_key_stats().
| void test_get_key_concurrency | ( | void | ) |
References BSL_Crypto_AddRegistryKey(), get_key_from_reg_fn(), TEST_ASSERT_EQUAL(), TEST_THREADS, and threads.
| void test_key_stats | ( | void | ) |
| TEST_MATRIX | ( | ) |
| void test_SeqReader_flat | ( | void | ) |
| void test_SeqWriter_flat | ( | void | ) |
|
static |
| const char BSL_CryptoCipherSHAVariant_e const char char* expected |
Referenced by BSL_AbsSecBlock_ContainsResult(), test_bsl_mock_encode_bundle(), and TEST_CASE().
| BSL_Data_Deinit & expected_data |
Referenced by TEST_CASE().
| BSL_AuthCtx_t hmac |
Referenced by BSL_AuthCtx_Finalize(), and switch().
| uint8_t hmac_buf[hmac_sz] |
| void* hmac_buf_ptr = hmac_buf |
| size_t hmac_len |
Referenced by BSL_AuthCtx_Finalize().
| int hmac_sz = 0 |
Referenced by switch().
| void* keyhandle |
Referenced by BSL_AuthCtx_Init(), and BSL_Crypto_ClearGeneratedKeyHandle().
| const char* keyid |
| const char BSL_CryptoCipherSHAVariant_e const char* plaintext_in |
Referenced by test_decrypt(), and test_encrypt().
| BSL_Data_Deinit & pt_in_data |
Referenced by switch().
| string_t pt_txt |
| const char BSL_CryptoCipherSHAVariant_e sha_var |
Referenced by BSL_AuthCtx_Init(), and mock_bpa_register_policy_from_json().
|
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().