|
BSL v1.1.1 - 50.g42e5d9b
AMMOS Bundle Protocol Security Library (BSL)
|
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. | |
Backend implementation of the crypto API using BSL_KeyStore_Descriptors_t callbacks.
| #define BSL_KeyStore_Descriptors_EMPTY |
| 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.
| [in] | hdl1 | The first key handle. |
| [in] | hdl2 | The second key handle. |
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().
| int BSL_Crypto_GenKey | ( | size_t | key_length, |
| BSL_Crypto_KeyHandle_t * | key_out | ||
| ) |
Generate a new cryptographic key.
| [in] | key_length | length of new key in bytes. |
| [out] | key_out | pointer 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().
| const BSL_Variant_t * BSL_Crypto_GetKeyParameter | ( | BSL_Crypto_KeyHandle_t | handle, |
| int64_t | param_id | ||
| ) |
Get key parameter for read-only access.
| [in] | handle | The handle to the key. |
| param_id | The unique identifier for the parameter. The available parameters will be determined by the key source (e.g. COSE_Key parameters). |
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().
| int BSL_Crypto_GetKeyStatistics | ( | BSL_Crypto_KeyHandle_t | handle, |
| BSL_Crypto_KeyStats_t * | stats | ||
| ) |
Retrieve statistics related to a crypto key.
| [in] | handle | The handle of a key in the crypto registry to retrieve the stats of. |
| [out] | stats | struct containing statistics related to the key id |
References ASSERT_PRECONDITION, BSL_KeyStore_State, CHK_ARG_NONNULL, BSL_KeyStore_Descriptors_t::find_key, and BSL_KeyStore_Descriptors_t::get_stats.
Referenced by BSLX_CoseSc_GenerateNonce(), 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_CASE(), TEST_CASE(), test_CCSDS_Example_Mac_Source(), test_CCSDS_Example_Mac_VerifyAccept(), and test_key_stats().
| int BSL_Crypto_GetRegistryKey | ( | const BSL_Data_t * | keyid, |
| BSL_Crypto_KeyHandle_t * | handle | ||
| ) |
Get pointers to an existing key, if present.
| keyid | The key to search for. | |
| [in,out] | handle | pointer to pointer for new key handle. The handle must be released with BSL_Crypto_ReleaseKeyHandle() when it is done being used. |
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().
| int BSL_Crypto_LoadKey | ( | const uint8_t * | secret, |
| size_t | secret_len, | ||
| BSL_Crypto_KeyHandle_t * | key_out | ||
| ) |
Load a new cryptographic key.
| [in] | secret | raw symmetric key. |
| secret_len | length of secret data. | |
| [out] | key_out | pointer to pointer for new key handle. The handle must be released with BSL_Crypto_ReleaseKeyHandle() when it is done being used. This applies even to cases where this function fails but still sets key_out non-NULL. |
References ASSERT_PRECONDITION, BSL_DATA_INIT_VIEW, BSL_ERR_SECURITY_CONTEXT_CRYPTO_FAILED, BSL_KeyStore_State, BSL_LOG_ERR, BSL_SUCCESS, CHK_ARG_EXPR, CHK_ARG_NONNULL, BSL_KeyStore_Descriptors_t::new_key, and BSL_KeyStore_Descriptors_t::set_keymat.
Referenced by BSL_Crypto_AddRegistryKeyName(), BSL_Crypto_GenKey(), BSL_Crypto_KDF(), BSL_Crypto_KeyLoader_LoadCoseKeySet_decode(), BSL_Crypto_KeyLoader_LoadJwkSet(), BSL_Crypto_UnwrapKey(), 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().
| void BSL_Crypto_ReleaseKeyHandle | ( | BSL_Crypto_KeyHandle_t | keyhandle | ) |
Release a key handle after it is done being used.
| [in] | keyhandle | key handle to release. If the handle is null this does nothing. |
References ASSERT_PRECONDITION, BSL_KeyStore_State, keyhandle, and BSL_KeyStore_Descriptors_t::release_key.
Referenced by BSL_Crypto_AddRegistryKeyName(), BSL_Crypto_KeyLoader_LoadCoseKeySet_decode(), BSL_Crypto_KeyLoader_LoadJwkSet(), BSLX_BCB_Decrypt(), BSLX_BCB_Encrypt(), BSLX_BIB_GenHMAC(), BSLX_CoseSc_Deinit(), 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().
| void BSL_KeyStore_Deinit | ( | void | ) |
Deinitialize the key store subsystem.
This should be called at the end of the process.
References BSL_KeyStore_Descriptors_EMPTY, and BSL_KeyStore_State.
Referenced by MockBPA_KeyStore_Deinit().
| int BSL_KeyStore_Init | ( | BSL_KeyStore_Descriptors_t | desc | ) |
Initialize the key store subsystem.
This must be called once per process.
| desc | The descriptor to use for future key store access. |
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().
| BSL_KeyStore_Descriptors_t BSL_KeyStore_State = BSL_KeyStore_Descriptors_EMPTY |
Initialized to library default.
Referenced by BSL_AuthCtx_Deinit(), BSL_AuthCtx_DigestBuffer(), BSL_AuthCtx_DigestSeq(), BSL_AuthCtx_Init(), BSL_Cipher_AddAadBuffer(), BSL_Cipher_AddAadSeq(), BSL_Cipher_AddSeq(), BSL_Cipher_Deinit(), BSL_Cipher_Init(), BSL_Crypto_CompareKeys(), BSL_Crypto_GetKeyParameter(), BSL_Crypto_GetKeyStatistics(), BSL_Crypto_GetRegistryKey(), BSL_Crypto_KDF(), BSL_Crypto_KeyLoader_LoadCoseKeySet_decode(), BSL_Crypto_KeyLoader_LoadJwkSet(), BSL_Crypto_LoadKey(), BSL_Crypto_ReleaseKeyHandle(), BSL_Crypto_UnwrapKey(), BSL_Crypto_WrapKey(), BSL_KeyStore_Deinit(), and BSL_KeyStore_Init().