BSL v1.1.1 - 50.g42e5d9b
AMMOS Bundle Protocol Security Library (BSL)
Loading...
Searching...
No Matches
KeyStore.c File Reference

Provider of a key store via the crypto API BSL_KeyStore_Descriptors_t. More...

#include "KeyStore.h"
#include <bsl/dynamic/Variant.h>
#include <m-bstring.h>
#include <m-dict.h>
#include <m-shared-ptr.h>
+ Include dependency graph for KeyStore.c:

Data Structures

struct  BSL_CryptoKey_t
 Struct to hold private key information. More...
 

Macros

#define M_OPL_BSL_CryptoKey_t()    M_OPEXTEND(M_POD_OPLIST, INIT(API_2(BSL_CryptoKey_Init)), INIT_SET(0), SET(0), CLEAR(API_2(BSL_CryptoKey_Deinit)))
 M*LIB OPLIST for BSL_CryptoKey_t.
 

Functions

static void BSL_CryptoKey_Init (BSL_CryptoKey_t *key)
 
static void BSL_CryptoKey_Deinit (BSL_CryptoKey_t *key)
 
void MockBPA_KeyStore_Init (void)
 Initialize the key storage and register it with BSL_KeyStore_Init().
 
void MockBPA_KeyStore_Deinit (void)
 De-register with BSL_KeyStore_Deinit() and clear all key storage.
 
int MockBPA_KeyStore_AddKey (const BSL_Data_t *keyid, BSL_Crypto_KeyHandle_t handle)
 Add a new key to the crypto key registry.
 
int MockBPA_KeyStore_RemoveKey (const BSL_Data_t *keyid)
 Erase key entry from crypto library registry, if present.
 
BSL_Variant_t * MockBPA_KeyStore_SetKeyParameter (BSL_Crypto_KeyHandle_t handle, int64_t param_id)
 Add a context-specific parameter to a known key.
 
static int MockBPA_KeyStore_FindKey (const BSL_Data_t *keyid, BSL_Crypto_KeyHandle_t *handle)
 
static const BSL_Variant_t * MockBPA_KeyStore_GetKeyParameter (BSL_Crypto_KeyHandle_t handle, int64_t param_id)
 
static int MockBPA_KeyStore_New (BSL_Crypto_KeyHandle_t *handle)
 
static int MockBPA_KeyStore_SetKeymat (BSL_Crypto_KeyHandle_t handle, const BSL_Data_t *data)
 
static int MockBPA_KeyStore_GetKeymat (BSL_Crypto_KeyHandle_t handle, BSL_Data_t *data)
 
static BSL_Crypto_KeyHandle_t MockBPA_KeyStore_Acquire (BSL_Crypto_KeyHandle_t handle)
 
static void MockBPA_KeyStore_Release (BSL_Crypto_KeyHandle_t handle)
 
static void MockBPA_KeyStore_UpdateStats (BSL_Crypto_KeyHandle_t handle, uint64_t use, uint64_t bytes)
 
static int MockBPA_KeyStore_GetStats (BSL_Crypto_KeyHandle_t handle, BSL_Crypto_KeyStats_t *stats)
 
BSL_KeyStore_Descriptors_t MockBPA_KeyStore_Descriptors (void)
 Get key store descriptors for the process.
 

Variables

static BSL_CryptoKeyDict_t StaticKeyRegistry
 Crypto key registry.
 
static pthread_mutex_t StaticCryptoMutex = PTHREAD_MUTEX_INITIALIZER
 

Detailed Description

Provider of a key store via the crypto API BSL_KeyStore_Descriptors_t.

Macro Definition Documentation

◆ M_OPL_BSL_CryptoKey_t

#define M_OPL_BSL_CryptoKey_t ( )     M_OPEXTEND(M_POD_OPLIST, INIT(API_2(BSL_CryptoKey_Init)), INIT_SET(0), SET(0), CLEAR(API_2(BSL_CryptoKey_Deinit)))

M*LIB OPLIST for BSL_CryptoKey_t.

Function Documentation

◆ BSL_CryptoKey_Deinit()

◆ BSL_CryptoKey_Init()

◆ MockBPA_KeyStore_Acquire()

static BSL_Crypto_KeyHandle_t MockBPA_KeyStore_Acquire ( BSL_Crypto_KeyHandle_t  handle)
static

◆ MockBPA_KeyStore_AddKey()

int MockBPA_KeyStore_AddKey ( const BSL_Data_t keyid,
BSL_Crypto_KeyHandle_t  handle 
)

Add a new key to the crypto key registry.

Parameters
[in]keyidkey ID that crypto functions will use to access key
[out]handleKey handle to add to the registry. Once the key is added it should be treated as read-only for thread-safety purposes. When handle is output, the handle must be released with BSL_Crypto_ReleaseKeyHandle() when it is done being used.
Returns
Zero upon success.

References ASSERT_ARG_NONNULL, CHK_ARG_NONNULL, keyid, StaticCryptoMutex, and StaticKeyRegistry.

Referenced by BSL_Crypto_AddRegistryKeyName(), MockBPA_KeyStore_Descriptors(), 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(), and test_key_stats().

◆ MockBPA_KeyStore_Deinit()

void MockBPA_KeyStore_Deinit ( void  )

De-register with BSL_KeyStore_Deinit() and clear all key storage.

References BSL_KeyStore_Deinit(), StaticCryptoMutex, and StaticKeyRegistry.

Referenced by _tearDown(), LLVMFuzzerTestOneInput(), main(), and tearDown().

◆ MockBPA_KeyStore_Descriptors()

◆ MockBPA_KeyStore_FindKey()

static int MockBPA_KeyStore_FindKey ( const BSL_Data_t keyid,
BSL_Crypto_KeyHandle_t handle 
)
static

◆ MockBPA_KeyStore_GetKeymat()

static int MockBPA_KeyStore_GetKeymat ( BSL_Crypto_KeyHandle_t  handle,
BSL_Data_t data 
)
static

◆ MockBPA_KeyStore_GetKeyParameter()

static const BSL_Variant_t * MockBPA_KeyStore_GetKeyParameter ( BSL_Crypto_KeyHandle_t  handle,
int64_t  param_id 
)
static

◆ MockBPA_KeyStore_GetStats()

static int MockBPA_KeyStore_GetStats ( BSL_Crypto_KeyHandle_t  handle,
BSL_Crypto_KeyStats_t stats 
)
static

◆ MockBPA_KeyStore_Init()

void MockBPA_KeyStore_Init ( void  )

Initialize the key storage and register it with BSL_KeyStore_Init().

References BSL_KeyStore_Init(), MockBPA_KeyStore_Descriptors(), StaticCryptoMutex, and StaticKeyRegistry.

Referenced by _setUp(), LLVMFuzzerTestOneInput(), main(), and setUp().

◆ MockBPA_KeyStore_New()

static int MockBPA_KeyStore_New ( BSL_Crypto_KeyHandle_t handle)
static

◆ MockBPA_KeyStore_Release()

static void MockBPA_KeyStore_Release ( BSL_Crypto_KeyHandle_t  handle)
static

◆ MockBPA_KeyStore_RemoveKey()

int MockBPA_KeyStore_RemoveKey ( const BSL_Data_t keyid)

Erase key entry from crypto library registry, if present.

Parameters
[in]keyidkey ID of key to remove.
Returns
Zero if the key was present.

References ASSERT_ARG_NONNULL, BSL_SUCCESS, keyid, StaticCryptoMutex, and StaticKeyRegistry.

Referenced by MockBPA_KeyStore_RemoveKeyName().

◆ MockBPA_KeyStore_SetKeymat()

static int MockBPA_KeyStore_SetKeymat ( BSL_Crypto_KeyHandle_t  handle,
const BSL_Data_t data 
)
static

◆ MockBPA_KeyStore_SetKeyParameter()

BSL_Variant_t * MockBPA_KeyStore_SetKeyParameter ( BSL_Crypto_KeyHandle_t  handle,
int64_t  param_id 
)

Add a context-specific parameter to a known key.

Parameters
[in]handleThe key ID to update.
[in]param_idThe parameter to access. If the parameter does not already exist it will be created.
Returns
Non-NULL pointer if successful.

References ASSERT_ARG_NONNULL, and BSL_CryptoKey_t::params.

Referenced by MockBPA_KeyStore_Descriptors(), 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().

◆ MockBPA_KeyStore_UpdateStats()

static void MockBPA_KeyStore_UpdateStats ( BSL_Crypto_KeyHandle_t  handle,
uint64_t  use,
uint64_t  bytes 
)
static

Variable Documentation

◆ StaticCryptoMutex

pthread_mutex_t StaticCryptoMutex = PTHREAD_MUTEX_INITIALIZER
static

◆ StaticKeyRegistry