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

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

◆ gcm_decrypt()

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().

◆ gcm_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().

◆ get_key_from_reg_fn()

static void * get_key_from_reg_fn ( void *  arg)
static

◆ setUp()

◆ string_clear() [1/2]

◆ string_clear() [2/2]

string_clear ( pt_txt  )

◆ string_init_set_str() [1/2]

◆ string_init_set_str() [2/2]

string_init_set_str ( pt_txt  ,
plaintext_in   
)

◆ suiteSetUp()

◆ suiteTearDown()

int suiteTearDown ( int  failures)

References mock_bpa_LogClose().

◆ switch() [1/2]

switch ( hmac.  SHA_variant)

◆ switch() [2/2]

◆ tearDown()

void tearDown ( void  )

◆ test_add_key_concurrency()

void test_add_key_concurrency ( void  )

◆ TEST_ASSERT_EQUAL() [1/5]

TEST_ASSERT_EQUAL ( ,
BSL_AuthCtx_Deinit hmac 
)

◆ TEST_ASSERT_EQUAL() [2/5]

TEST_ASSERT_EQUAL ( ,
BSL_AuthCtx_Finalize &, &, &  hmac_len 
)

◆ TEST_ASSERT_EQUAL() [3/5]

TEST_ASSERT_EQUAL ( ,
BSL_AuthCtx_Init &,,  sha_var 
)

◆ TEST_ASSERT_EQUAL() [4/5]

◆ TEST_ASSERT_EQUAL() [5/5]

TEST_ASSERT_EQUAL ( hmac_sz  ,
hmac_len   
)

◆ TEST_ASSERT_EQUAL_INT()

◆ TEST_ASSERT_EQUAL_INT_MESSAGE()

◆ TEST_ASSERT_EQUAL_MEMORY()

◆ TEST_CASE()

◆ 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()

◆ test_SeqWriter_flat()

Variable Documentation

◆ bsl

◆ expected

const char BSL_CryptoCipherSHAVariant_e const char char* expected
Initial value:
{
string_t exp_txt

Referenced by BSL_AbsSecBlock_ContainsResult(), test_bsl_mock_encode_bundle(), and TEST_CASE().

◆ expected_data

BSL_Data_Deinit & expected_data

Referenced by TEST_CASE().

◆ hmac

Referenced by BSL_AuthCtx_Finalize(), and switch().

◆ hmac_buf

uint8_t hmac_buf[hmac_sz]

◆ hmac_buf_ptr

void* hmac_buf_ptr = hmac_buf

◆ hmac_len

size_t hmac_len

Referenced by BSL_AuthCtx_Finalize().

◆ hmac_sz

int hmac_sz = 0

Referenced by switch().

◆ keyhandle

void* keyhandle

◆ keyid

◆ plaintext_in

const char BSL_CryptoCipherSHAVariant_e const char* plaintext_in

Referenced by test_decrypt(), and test_encrypt().

◆ pt_in_data

BSL_Data_Deinit & pt_in_data

Referenced by switch().

◆ pt_txt

string_t pt_txt

◆ sha_var

◆ 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