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

Backend implementation of the crypto API using BSL_KeyStore_Descriptors_t callbacks. More...

#include "KeyStore.h"
#include "CryptoInterface.h"
#include <bsl/front/TextUtil.h>
#include <bsl/dynamic/Variant.h>
+ Include dependency graph for KeyStore.c:

Macros

#define BSL_KeyStore_Descriptors_EMPTY
 

Functions

int BSL_KeyStore_Init (BSL_KeyStore_Descriptors_t desc)
 Initialize the key store subsystem.
 
void BSL_KeyStore_Deinit (void)
 Deinitialize the key store subsystem.
 
void BSL_Crypto_ReleaseKeyHandle (BSL_Crypto_KeyHandle_t keyhandle)
 Release a key handle after it is done being used.
 
bool BSL_Crypto_CompareKeys (BSL_Crypto_KeyHandle_t hdl1, BSL_Crypto_KeyHandle_t hdl2)
 Compare two keys in a time-invariant way.
 
int BSL_Crypto_GenKey (size_t key_length, BSL_Crypto_KeyHandle_t *key_out)
 Generate a new cryptographic key.
 
int BSL_Crypto_LoadKey (const uint8_t *secret, size_t secret_len, BSL_Crypto_KeyHandle_t *key_out)
 Load a new cryptographic key.
 
const BSL_Variant_t * BSL_Crypto_GetKeyParameter (BSL_Crypto_KeyHandle_t handle, int64_t param_id)
 Get key parameter for read-only access.
 
int BSL_Crypto_GetRegistryKey (const BSL_Data_t *keyid, BSL_Crypto_KeyHandle_t *handle)
 Get pointers to an existing key, if present.
 
int BSL_Crypto_GetKeyStatistics (BSL_Crypto_KeyHandle_t handle, BSL_Crypto_KeyStats_t *stats)
 Retrieve statistics related to a crypto key.
 

Variables

BSL_KeyStore_Descriptors_t BSL_KeyStore_State = BSL_KeyStore_Descriptors_EMPTY
 Initialized to library default.
 

Detailed Description

Backend implementation of the crypto API using BSL_KeyStore_Descriptors_t callbacks.

Macro Definition Documentation

◆ BSL_KeyStore_Descriptors_EMPTY

#define BSL_KeyStore_Descriptors_EMPTY
Value:
{ \
.new_key = NULL \
}

Function Documentation

◆ BSL_Crypto_CompareKeys()

bool BSL_Crypto_CompareKeys ( BSL_Crypto_KeyHandle_t  hdl1,
BSL_Crypto_KeyHandle_t  hdl2 
)

Compare two keys in a time-invariant way.

This avoids side channel attacks which depend on comparison time.

Parameters
[in]hdl1The first key handle.
[in]hdl2The second key handle.
Returns
True if they compare equal.

References ASSERT_PRECONDITION, BSL_Crypto_Compare(), BSL_KeyStore_State, BSL_SUCCESS, CHK_AS_BOOL, BSL_KeyStore_Descriptors_t::get_keymat, BSL_Data_t::len, and BSL_Data_t::ptr.

Referenced by TEST_CASE().

◆ BSL_Crypto_GenKey()

int BSL_Crypto_GenKey ( size_t  key_length,
BSL_Crypto_KeyHandle_t key_out 
)

Generate a new cryptographic key.

Parameters
[in]key_lengthlength of new key in bytes.
[out]key_outpointer to pointer for new key handle. The handle must be released with BSL_Crypto_ReleaseKeyHandle() when it is done being used.

References BSL_Crypto_GenIV(), BSL_Crypto_LoadKey(), BSL_Data_Deinit(), BSL_Data_InitBuffer(), BSL_ERR_FAILURE, BSL_SUCCESS, CHK_ARG_EXPR, CHK_ARG_NONNULL, BSL_Data_t::len, and BSL_Data_t::ptr.

Referenced by BSLX_BCB_Encrypt(), BSLX_BIB_GenHMAC(), and BSLX_CoseSc_GenerateContentKey().

◆ BSL_Crypto_GetKeyParameter()

const BSL_Variant_t * BSL_Crypto_GetKeyParameter ( BSL_Crypto_KeyHandle_t  handle,
int64_t  param_id 
)

Get key parameter for read-only access.

Parameters
[in]handleThe handle to the key.
param_idThe unique identifier for the parameter. The available parameters will be determined by the key source (e.g. COSE_Key parameters).
Returns
A non-null pointer if the parameter exists.

References ASSERT_PRECONDITION, BSL_KeyStore_State, and BSL_KeyStore_Descriptors_t::get_parameter.

Referenced by BSLX_CoseSc_ExtractIV(), BSLX_CoseSc_GenerateIV(), and BSLX_CoseSc_GetAndValidateKey().

◆ BSL_Crypto_GetKeyStatistics()

◆ BSL_Crypto_GetRegistryKey()

int BSL_Crypto_GetRegistryKey ( const BSL_Data_t keyid,
BSL_Crypto_KeyHandle_t handle 
)

Get pointers to an existing key, if present.

Parameters
keyidThe key to search for.
[in,out]handlepointer to pointer for new key handle. The handle must be released with BSL_Crypto_ReleaseKeyHandle() when it is done being used.
Returns
Zero if the key was present.

References ASSERT_PRECONDITION, BSL_KeyStore_State, CHK_ARG_NONNULL, BSL_KeyStore_Descriptors_t::find_key, and keyid.

Referenced by BSL_Crypto_GetRegistryKeyName(), BSLX_BCB_Decrypt(), BSLX_BCB_Encrypt(), BSLX_BIB_GenHMAC(), and BSLX_CoseSc_GetAndValidateKey().

◆ BSL_Crypto_LoadKey()

◆ BSL_Crypto_ReleaseKeyHandle()

◆ BSL_KeyStore_Deinit()

void BSL_KeyStore_Deinit ( void  )

Deinitialize the key store subsystem.

This should be called at the end of the process.

Warning
This function is not thread safe and should be used after any BSL_LibCtx_s is deinitialized.

References BSL_KeyStore_Descriptors_EMPTY, and BSL_KeyStore_State.

Referenced by MockBPA_KeyStore_Deinit().

◆ BSL_KeyStore_Init()

int BSL_KeyStore_Init ( BSL_KeyStore_Descriptors_t  desc)

Initialize the key store subsystem.

This must be called once per process.

Warning
This function is not thread safe and should be used before any BSL_LibCtx_s is initialized or other BSL interfaces used.
Parameters
descThe descriptor to use for future key store access.
Returns
Zero if successful, negative on error.

References BSL_KeyStore_Descriptors_t::acquire_key, BSL_KeyStore_Descriptors_t::add_key, BSL_KeyStore_State, BSL_SUCCESS, CHK_PRECONDITION, BSL_KeyStore_Descriptors_t::find_key, BSL_KeyStore_Descriptors_t::get_keymat, BSL_KeyStore_Descriptors_t::get_parameter, BSL_KeyStore_Descriptors_t::get_stats, BSL_KeyStore_Descriptors_t::new_key, BSL_KeyStore_Descriptors_t::release_key, BSL_KeyStore_Descriptors_t::set_keymat, BSL_KeyStore_Descriptors_t::set_parameter, and BSL_KeyStore_Descriptors_t::update_stats.

Referenced by MockBPA_KeyStore_Init().

Variable Documentation

◆ BSL_KeyStore_State