Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#[[
Copyright (c) 2024 The Johns Hopkins University Applied Physics
Copyright (c) 2025 The Johns Hopkins University Applied Physics
Laboratory LLC.

This file is part of the Bundle Protocol Security Library (BSL).
Expand Down
2 changes: 1 addition & 1 deletion docs/api/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#[[
Copyright (c) 2024 The Johns Hopkins University Applied Physics
Copyright (c) 2025 The Johns Hopkins University Applied Physics
Laboratory LLC.

This file is part of the Bundle Protocol Security Library (BSL).
Expand Down
2 changes: 1 addition & 1 deletion docs/api/Developer_Guide.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!--
Copyright (c) 2024 The Johns Hopkins University Applied Physics
Copyright (c) 2025 The Johns Hopkins University Applied Physics
Laboratory LLC.

This file is part of the Bundle Protocol Security Library (BSL).
Expand Down
2 changes: 1 addition & 1 deletion docs/api/InterfaceSpec.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!--
Copyright (c) 2024 The Johns Hopkins University Applied Physics
Copyright (c) 2025 The Johns Hopkins University Applied Physics
Laboratory LLC.

This file is part of the Bundle Protocol Security Library (BSL).
Expand Down
2 changes: 1 addition & 1 deletion docs/api/UserGuide.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!--
Copyright (c) 2024 The Johns Hopkins University Applied Physics
Copyright (c) 2025 The Johns Hopkins University Applied Physics
Laboratory LLC.

This file is part of the Bundle Protocol Security Library (BSL).
Expand Down
2 changes: 1 addition & 1 deletion docs/api/footer.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!--
-- Copyright (c) 2024 The Johns Hopkins University Applied Physics
-- Copyright (c) 2025 The Johns Hopkins University Applied Physics
-- Laboratory LLC.
--
-- This file is part of the Bundle Protocol Security Library (BSL).
Expand Down
2 changes: 1 addition & 1 deletion docs/api/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!DOCTYPE html>
<!--
-- Copyright (c) 2024 The Johns Hopkins University Applied Physics
-- Copyright (c) 2025 The Johns Hopkins University Applied Physics
-- Laboratory LLC.
--
-- This file is part of the Bundle Protocol Security Library (BSL).
Expand Down
2 changes: 1 addition & 1 deletion docs/api/mainpage.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!--
Copyright (c) 2024 The Johns Hopkins University Applied Physics
Copyright (c) 2025 The Johns Hopkins University Applied Physics
Laboratory LLC.

This file is part of the Bundle Protocol Security Library (BSL).
Expand Down
2 changes: 1 addition & 1 deletion docs/man/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#[[
Copyright (c) 2024 The Johns Hopkins University Applied Physics
Copyright (c) 2025 The Johns Hopkins University Applied Physics
Laboratory LLC.

This file is part of the Bundle Protocol Security Library (BSL).
Expand Down
37 changes: 23 additions & 14 deletions src/BPSecLib_Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,10 @@ typedef struct BSL_Data_s
/** Static initializer for a data store.
* @sa BSL_Data_Init()
*/
#define BSL_DATA_INIT_NULL { .owned = false, .ptr = NULL, .len = 0 }
#define BSL_DATA_INIT_NULL \
{ \
.owned = false, .ptr = NULL, .len = 0 \
}

/** Initialize an empty data struct.
*
Expand Down Expand Up @@ -387,7 +390,10 @@ int BSL_SeqWriter_Put(BSL_SeqWriter_t *obj, const uint8_t *buf, size_t *bufsize)
/** Static initializer for an invalid ::BSL_HostEID_t.
* Even after this, BSL_HostEID_Init() must be used to get into a valid state.
*/
#define BSL_HOSTEID_INIT_INVALID { .handle = NULL }
#define BSL_HOSTEID_INIT_INVALID \
{ \
.handle = NULL \
}

/** Initialize an abstract EID.
*
Expand Down Expand Up @@ -434,7 +440,10 @@ int BSL_HostEID_DecodeFromCBOR(BSL_HostEID_t *eid, void *decoder);
/** Static initializer for an invalid ::BSL_HostEIDPattern_t.
* Even after this, BSL_HostEIDPattern_Init() must be used to get into a valid state.
*/
#define BSL_HOSTEID_INIT_INVALID { .handle = NULL }
#define BSL_HOSTEID_INIT_INVALID \
{ \
.handle = NULL \
}

/** Initialize an abstract EID Pattern.
*
Expand Down Expand Up @@ -515,25 +524,25 @@ typedef enum
} BSL_BundleCtrlFlag_e;

/** @brief Calls the host interface to get a bundle primary block information.abort
*
*
* @param[in] bundle Bundle context
* @param[out] result_primary_block Non-null pointer to result which gets populated on a zero return code.
* @returns 0 on success, negative on error
*/
int BSL_BundleCtx_GetBundleMetadata(const BSL_BundleRef_t *bundle, BSL_PrimaryBlock_t *result_primary_block);

/** @brief Returns an array in which each element contains the id of the corresponding block.abort
*
*
* @param[in] bundle Bundle context
* @param[in] array_count Number of elements in `block_id_index_array`
* @param[out] block_id_index_array Array of `array_count` elements for results
* @param[out] result_count Contains the number of elements put into the array
*/
int BSL_BundleCtx_GetBlockIds(const BSL_BundleRef_t *bundle, size_t array_count,
uint64_t block_ids_array[array_count], size_t *result_count);
int BSL_BundleCtx_GetBlockIds(const BSL_BundleRef_t *bundle, size_t array_count, uint64_t block_ids_array[array_count],
size_t *result_count);

/** @brief Returns information about the bundle Canonical block
*
*
* @param[in] bundle Context bundle
* @param[in] block_num The number of the bundle canonical block we seek information on
* @param[out] result_block Pointer to allocated memory which contains the results of the query.
Expand All @@ -551,17 +560,17 @@ int BSL_BundleCtx_GetBlockMetadata(const BSL_BundleRef_t *bundle, uint64_t block
int BSL_BundleCtx_CreateBlock(BSL_BundleRef_t *bundle, uint64_t block_type_code, uint64_t *block_num);

/** @brief Requests the removal of a block from a bundle
*
*
* @param[in] bundle Context bundle
* @param[in] block_num Block number to be removed
* @returns 0 on success, negative on failure.
*/
int BSL_BundleCtx_RemoveBlock(BSL_BundleRef_t *bundle, uint64_t block_num);

/** @brief Requests the re-allocation of a block's BTSD, useful for BCB.
*
*
* @note Uses semantics similar to memcpy.
*
*
* @param[in] bundle Context bundle
* @param[in] block_num Number of block requesting re-allocated of BTSD
* @param[in] bytesize Size of new BTSD
Expand Down Expand Up @@ -1005,13 +1014,13 @@ size_t BSL_SecurityActionSet_Sizeof(void);
void BSL_SecurityActionSet_Init(BSL_SecurityActionSet_t *self);

/** @brief Increment a security failure for this action set
*
*
* @param[in, out] self Pointer to this security action set.
*/
void BSL_SecurityActionSet_IncrError(BSL_SecurityActionSet_t *self);

/** @brief Returns count of failures after processing this action set
*
*
* @param[in] self Pointer ot this security action set.
* @returns Count of errors.
*/
Expand All @@ -1024,7 +1033,7 @@ size_t BSL_SecurityActionSet_CountErrors(const BSL_SecurityActionSet_t *self);
void BSL_SecurityActionSet_Deinit(BSL_SecurityActionSet_t *self);

/** @brief Append a security operation to the security action set
*
*
* @param[in, out] self This security action set.
* @param[in] sec_oper Security operation to include.
* @returns 0 on success, negative on error
Expand Down
7 changes: 4 additions & 3 deletions src/backend/AbsSecBlock.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ void BSL_AbsSecBlock_Print(const BSL_AbsSecBlock_t *self)
for (size_t index = 0; index < BSLB_SecResultList_size(self->results); index++)
{
BSL_SecResult_t *sec_result = BSLB_SecResultList_get(self->results, index);
BSL_Log_DumpAsHexString((uint8_t*)str, sizeof(str), sec_result->_bytes, sec_result->_bytelen);
BSL_LOG_INFO("ASB Result[%lu]: tgt=%lu, id=%lu %s", index, sec_result->target_block_num, sec_result->result_id, str);
BSL_Log_DumpAsHexString((uint8_t *)str, sizeof(str), sec_result->_bytes, sec_result->_bytelen);
BSL_LOG_INFO("ASB Result[%lu]: tgt=%lu, id=%lu %s", index, sec_result->target_block_num, sec_result->result_id,
str);
}
}

Expand Down Expand Up @@ -409,7 +410,7 @@ int BSL_AbsSecBlock_DecodeFromCBOR(BSL_AbsSecBlock_t *self, BSL_Data_t encoded_c
// This is a failure case - should more clearly return?
BSL_LOG_ERR("Unhandled case");
// NOLINTNEXTLINE
exit(1);
exit(1);
}

const size_t item_end = QCBORDecode_Tell(&asbdec);
Expand Down
9 changes: 5 additions & 4 deletions src/backend/CryptoInterface.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ int BSL_Crypto_UnwrapKey(BSL_Data_t *unwrapped_key_output, BSL_Data_t wrapped_ke
unwrapped_key_output->len = (size_t)unwrapped_key_len;

int final_len = 0;
int res = EVP_DecryptFinal_ex(ctx, &unwrapped_key_output->ptr[unwrapped_key_output->len], &final_len);
int res = EVP_DecryptFinal_ex(ctx, &unwrapped_key_output->ptr[unwrapped_key_output->len], &final_len);
if (res != 1)
{
BSL_LOG_ERR("Failed DecryptFinal: %s", ERR_error_string(ERR_get_error(), NULL));
Expand Down Expand Up @@ -155,7 +155,7 @@ int BSL_Crypto_WrapKey(BSL_Data_t *wrapped_key, BSL_Data_t cek, size_t content_k
}

wrapped_key->len = (size_t)len;
int final_len = 0;
int final_len = 0;
if (!EVP_EncryptFinal_ex(ctx, &wrapped_key->ptr[wrapped_key->len], &final_len))
{
EVP_CIPHER_CTX_free(ctx);
Expand Down Expand Up @@ -237,7 +237,7 @@ int BSL_AuthCtx_DigestSeq(BSL_AuthCtx_t *hmac_ctx, BSL_SeqReader_t *reader)
int BSL_AuthCtx_Finalize(BSL_AuthCtx_t *hmac_ctx, void **hmac, size_t *hmac_len)
{
size_t req = 0;
int res = EVP_DigestSignFinal(hmac_ctx->libhandle, NULL, &req);
int res = EVP_DigestSignFinal(hmac_ctx->libhandle, NULL, &req);
CHK_PROPERTY(res == 1);

*hmac_len = req;
Expand Down Expand Up @@ -279,7 +279,8 @@ int BSL_Cipher_Init(BSL_Cipher_t *cipher_ctx, BSL_CipherMode_e enc, BSL_CryptoCi
return BSL_ERR_FAILURE;
}

int res = EVP_CipherInit_ex(cipher_ctx->libhandle, cipher, NULL, NULL, NULL, (cipher_ctx->enc == BSL_CRYPTO_ENCRYPT));
int res =
EVP_CipherInit_ex(cipher_ctx->libhandle, cipher, NULL, NULL, NULL, (cipher_ctx->enc == BSL_CRYPTO_ENCRYPT));
CHK_PROPERTY(res == 1);

cipher_ctx->block_size = (size_t)EVP_CIPHER_CTX_block_size(cipher_ctx->libhandle);
Expand Down
8 changes: 4 additions & 4 deletions src/backend/LoggingStderr.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ M_BUFFER_DEF(BSL_LogEvent_queue, BSL_LogEvent_event_t, BSL_LOG_QUEUE_SIZE, M_BUF
/// @endcond

/// Shared safe queue
static BSL_LogEvent_queue_t event_queue;
static BSL_LogEvent_queue_t event_queue;
/// Sink thread ID
static pthread_t thr_sink;
static pthread_t thr_sink;
/// True if ::thr_sink is valid
static atomic_bool thr_valid = ATOMIC_VAR_INIT(false);
static atomic_bool thr_valid = ATOMIC_VAR_INIT(false);
/// NOLINTEND

uint8_t *BSL_Log_DumpAsHexString(uint8_t *dstbuf, size_t dstlen, const uint8_t *srcbuf, size_t srclen)
Expand All @@ -107,7 +107,7 @@ uint8_t *BSL_Log_DumpAsHexString(uint8_t *dstbuf, size_t dstlen, const uint8_t *

memset(dstbuf, 0, dstlen);
const char hex_digits[] = "0123456789ABCDEF";
for (size_t i = 0; i < srclen && (((i * 2) + 1) < dstlen-1); i++)
for (size_t i = 0; i < srclen && (((i * 2) + 1) < dstlen - 1); i++)
{
dstbuf[(i * 2)] = (uint8_t)hex_digits[(srcbuf[i] >> 4) & 0x0F];
dstbuf[(i * 2) + 1] = (uint8_t)hex_digits[srcbuf[i] & 0x0F];
Expand Down
14 changes: 7 additions & 7 deletions src/backend/SecurityActionSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@
/// @note This is intended to be a write-once, read-only struct
struct BSL_SecurityActionSet_s
{
BSL_SecOper_t sec_operations[BSL_SECURITYACTIONSET_MAX_OPS]; ///< Fixed array of security operations (for simpler mem management)
size_t sec_operations_count; ///< Count of sec_operations
uint64_t new_block_ids[BSL_SECURITYACTIONSET_MAX_OPS]; ///< Array for IDs of blocks to be created
uint64_t new_block_types[BSL_SECURITYACTIONSET_MAX_OPS]; ///< Array for block type codes of blocks to be created.
size_t arrays_capacity; ///< Capacity of sec_operations
int err_code; ///< General error code
BSL_SecOper_t sec_operations[BSL_SECURITYACTIONSET_MAX_OPS]; ///< Fixed array of security operations (for simpler
///< mem management)
size_t sec_operations_count; ///< Count of sec_operations
uint64_t new_block_ids[BSL_SECURITYACTIONSET_MAX_OPS]; ///< Array for IDs of blocks to be created
uint64_t new_block_types[BSL_SECURITYACTIONSET_MAX_OPS]; ///< Array for block type codes of blocks to be created.
size_t arrays_capacity; ///< Capacity of sec_operations
int err_code; ///< General error code
};


#endif /* BSLB_SECACTIONSET_H_ */
2 changes: 1 addition & 1 deletion src/backend/SecurityResultSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include <BPSecLib_Private.h>

#define BSL_SECURITYRESPONSESET_ARRAYLEN (10)
#define BSL_SECURITYRESPONSESET_STRLEN (256)
#define BSL_SECURITYRESPONSESET_STRLEN (256)

/// @brief Contains the results and outcomes after performing the security operations.
/// @note This struct is still in-concept
Expand Down
2 changes: 1 addition & 1 deletion src/backend/UtilDefs_Data.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ int BSL_Data_Resize(BSL_Data_t *data, size_t len)
{
return BSL_SUCCESS;
}

if (len == 0)
{
bsl_data_int_free(data);
Expand Down
6 changes: 3 additions & 3 deletions src/security_context/BCB_AES_GCM.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,9 @@ static int BSLX_BCB_Decrypt(BSLX_BCB_t *bcb_context)
// This should have resized the buffer downward
CHK_PROPERTY(content_enc_key.len < 2048);

BSL_Cipher_t cipher = { 0 };
int cipher_init = BSL_Cipher_Init(&cipher, BSL_CRYPTO_DECRYPT, aes_mode, bcb_context->iv.ptr, (int)bcb_context->iv.len,
content_enc_key);
BSL_Cipher_t cipher = { 0 };
int cipher_init = BSL_Cipher_Init(&cipher, BSL_CRYPTO_DECRYPT, aes_mode, bcb_context->iv.ptr,
(int)bcb_context->iv.len, content_enc_key);
if (BSL_SUCCESS != cipher_init)
{
BSL_LOG_ERR("Failed to init BCB AES cipher");
Expand Down
9 changes: 4 additions & 5 deletions src/security_context/BIB_HMAC_SHA2.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ int BSLX_BIB_InitFromSecOper(BSLX_BIB_t *self, const BSL_SecOper_t *sec_oper)
{
const BSL_SecParam_t *param = BSL_SecOper_GetParamAt(sec_oper, param_index);
uint64_t param_id = BSL_SecParam_GetId(param);
bool is_int = BSL_SecParam_IsInt64(param);
uint64_t int_val = -1;
bool is_int = BSL_SecParam_IsInt64(param);
uint64_t int_val = -1;
if (is_int)
{
int_val = BSL_SecParam_GetAsUInt64(param);
Expand Down Expand Up @@ -203,8 +203,7 @@ int BSLX_BIB_GenIPPT(BSLX_BIB_t *self, BSL_Data_t ippt_space)
// Now begin process of computing IPPT
if (self->integrity_scope_flags & RFC9173_BIB_INTEGSCOPEFLAG_INC_PRIM)
{
UsefulBufC prim_encoded = { .ptr = self->primary_block.cbor,
.len = self->primary_block.cbor_len };
UsefulBufC prim_encoded = { .ptr = self->primary_block.cbor, .len = self->primary_block.cbor_len };
QCBOREncode_AddEncoded(&encoder, prim_encoded);
}
if (self->integrity_scope_flags & RFC9173_BIB_INTEGSCOPEFLAG_INC_TARGET_HDR)
Expand Down Expand Up @@ -267,7 +266,7 @@ int BSLX_BIB_GenHMAC(BSLX_BIB_t *self, BSL_Data_t ippt_data)
}

void *hmac_result_ptr = (void *)&self->hmac_result_val._bytes[0];
size_t hmaclen = 0;
size_t hmaclen = 0;
if ((res = BSL_AuthCtx_Finalize(&hmac_ctx, &hmac_result_ptr, &hmaclen)) != 0)
{
BSL_LOG_ERR("bsl_hmac_ctx_finalize failed with code %d", res);
Expand Down
2 changes: 1 addition & 1 deletion src/security_context/DefaultSecContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include <BPSecLib_Private.h>
#include <BPSecLib_Public.h>

#define BSLX_MAX_KEYLEN (2048)
#define BSLX_MAX_KEYLEN (2048)
#define BSLX_MAX_AES_PAD (64)

int BSLX_BCB_Execute(BSL_LibCtx_t *lib, const BSL_BundleRef_t *bundle, const BSL_SecOper_t *sec_oper,
Expand Down
21 changes: 21 additions & 0 deletions test/test_SecurityTypes.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
/*
* Copyright (c) 2025 The Johns Hopkins University Applied Physics
* Laboratory LLC.
*
* This file is part of the Bundle Protocol Security Library (BSL).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* This work was performed for the Jet Propulsion Laboratory, California
* Institute of Technology, sponsored by the United States Government under
* the prime contract 80NM0018D0004 between the Caltech and NASA under
* subcontract 1700763.
*/
#include <stdlib.h>
#include <stdio.h>
#include <unity.h>
Expand Down