BSL v1.1.1 - 39.g9f43410
AMMOS Bundle Protocol Security Library (BSL)
Loading...
Searching...
No Matches
test_CryptoInterface.c File Reference
#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_Initpt_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]
 

Macro Definition Documentation

◆ TEST_THREADS

#define TEST_THREADS   10

Function Documentation

◆ add_key_to_reg_fn()

static void * add_key_to_reg_fn ( void *  arg)
static

◆ BSL_Crypto_ReleaseKeyHandle()

◆ gcm_decrypt()

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 
)
static

copied from openssl examples, used for testing for now https://wiki.openssl.org/index.php/EVP_Authenticated_Encryption_and_Decryption

References ctx, and tag.

Referenced by test_encrypt().

◆ gcm_encrypt()

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 
)
static

copied from openssl examples, used for testing for now https://wiki.openssl.org/index.php/EVP_Authenticated_Encryption_and_Decryption

References ctx, and tag.

Referenced by test_decrypt().

◆ get_key_from_reg_fn()

static void * get_key_from_reg_fn ( void *  arg)
static

◆ setUp()

◆ suiteSetUp()

◆ suiteTearDown()

int suiteTearDown ( int  failures)

References mock_bpa_LogClose().

◆ switch() [1/2]

◆ switch() [2/2]

◆ tearDown()

void tearDown ( void  )

◆ test_add_key_concurrency()

◆ TEST_ASSERT_EQUAL() [1/4]

TEST_ASSERT_EQUAL ( ,
BSL_AuthCtx_Finalize &, &  tag 
)

◆ TEST_ASSERT_EQUAL() [2/4]

TEST_ASSERT_EQUAL ( ,
BSL_AuthCtx_Init &,,  sha_var 
)

◆ TEST_ASSERT_EQUAL() [3/4]

TEST_ASSERT_EQUAL ( ,
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() [4/4]

TEST_ASSERT_EQUAL ( expect_hmac_sz  ,
tag.  len 
)

◆ TEST_ASSERT_EQUAL_INT_MESSAGE()

◆ TEST_ASSERT_TRUE()

◆ TEST_CASE() [1/2]

◆ TEST_CASE() [2/2]

TEST_CASE ( "0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b"  ,
  BSL_CRYPTO_KDF_HKDF_SHA_256,
"000102030405060708090a0b0c"  ,
"f0f1f2f3f4f5f6f7f8f9"  ,
  42,
"3cb25f25faacd57a90434f64d0362f2a2d2d0a90cf1a5a4c5db02d56ecc4c5bf34007208d5b887185865"   
)

◆ test_crypto_generate_iv()

void test_crypto_generate_iv ( int  iv_len)

◆ test_decrypt()

◆ test_encrypt()

◆ test_get_key_concurrency()

void test_get_key_concurrency ( void  )

◆ test_key_stats()

◆ TEST_MATRIX()

TEST_MATRIX ( )

◆ test_SeqReader_flat()

void test_SeqReader_flat ( void  )

◆ test_SeqWriter_flat()

void test_SeqWriter_flat ( void  )

Variable Documentation

◆ bsl

◆ expect_hmac_sz

int expect_hmac_sz = 0

Referenced by switch().

◆ expected

const char BSL_Crypto_SHAVariant_e const char const char* expected
Initial value:
{
Optional heap data storage and views.
Definition Data.h:45
BSL_Data_Init & pt_in_data
Definition test_CryptoInterface.c:334

Referenced by TEST_CASE().

◆ hmac

Referenced by switch().

◆ keyhandle

◆ keyid

◆ plaintext_in

const char BSL_Crypto_SHAVariant_e const char* plaintext_in

Referenced by test_decrypt(), and test_encrypt().

◆ pt_in_data

BSL_Data_Deinit & pt_in_data

Referenced by switch().

◆ sha_var

const char BSL_Crypto_SHAVariant_e sha_var

Referenced by BSL_AuthCtx_Init().

◆ tag

◆ test_128

uint8_t test_128[16]
static
Initial value:
= { 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b }

Referenced by setUp(), test_decrypt(), test_encrypt(), and test_key_stats().

◆ test_256

uint8_t test_256[32]
static
Initial value:
= { 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b }

Referenced by setUp(), test_decrypt(), and test_encrypt().

◆ threads

pthread_t threads[TEST_THREADS]
static