BSL v1.1.1 - 39.g9f43410
AMMOS Bundle Protocol Security Library (BSL)
Loading...
Searching...
No Matches
CoseMsg.c File Reference

Implementation of COSE structures [15]. More...

#include "CoseMsg.h"
#include "bsl/BPSecLib_Private.h"
#include "bsl/dynamic/CBOR.h"
+ Include dependency graph for CoseMsg.c:

Functions

void BSLX_CoseMsg_HdrMapTree_update (BSLX_CoseMsg_HdrMapTree_t base, const BSLX_CoseMsg_HdrMapTree_t addl)
 Update a base map with an additional map, adding items when the key is not already present.
 
int BSLX_CoseMsg_Headers_Encode_Map (QCBOREncodeContext *enc, const BSLX_CoseMsg_HdrMapTree_t *map)
 Encode a header parameter map.
 
int BSLX_CoseMsg_Headers_Decode_Map (QCBORDecodeContext *dec, BSLX_CoseMsg_HdrMapTree_t *map)
 Decode a header parameter map.
 
void BSLX_CoseMsg_Headers_Init (BSLX_CoseMsg_Headers_t *obj)
 Initialize the struct.
 
void BSLX_CoseMsg_Headers_Deinit (BSLX_CoseMsg_Headers_t *obj)
 Deinitialize the struct.
 
int BSLX_CoseMsg_Headers_Encode (QCBOREncodeContext *enc, const BSLX_CoseMsg_Headers_t *obj)
 Match BSL_CBOR_Encode_f signature.
 
int BSLX_CoseMsg_Headers_Decode (QCBORDecodeContext *dec, BSLX_CoseMsg_Headers_t *obj)
 Match BSL_CBOR_Decode_f signature.
 
int BSLX_CoseMsg_Headers_DerivePhdr (BSLX_CoseMsg_Headers_t *obj)
 Derive BSLX_CoseMsg_Headers_t::phdr_bstr from protected headers in BSLX_CoseMsg_Headers_t::phdr.
 
static int BSLX_CoseMsg_Headers_CheckCrit_Decode (QCBORDecodeContext *dec, const void *obj)
 Decode a crit array and fail directly.
 
int BSLX_CoseMsg_Headers_CheckCrit (const BSLX_CoseMsg_Headers_t *obj)
 Check for the presence of crit header referencing unsupported parameters.
 
const BSL_IdValPair_t * BSLX_CoseMsg_Headers_Get (const BSLX_CoseMsg_Headers_t *obj, int64_t label, bool need_phdr)
 Get a desired header parameter.
 
void BSLX_CoseMsg_Mac0_Init (BSLX_CoseMsg_Mac0_t *obj)
 Initialize the struct.
 
void BSLX_CoseMsg_Mac0_Deinit (BSLX_CoseMsg_Mac0_t *obj)
 Deinitialize the struct.
 
int BSLX_CoseMsg_Mac0_Encode (QCBOREncodeContext *enc, const BSLX_CoseMsg_Mac0_t *obj)
 Match BSL_CBOR_Encode_f signature.
 
int BSLX_CoseMsg_Mac0_Decode (QCBORDecodeContext *dec, BSLX_CoseMsg_Mac0_t *obj)
 Match BSL_CBOR_Decode_f signature.
 
void BSLX_CoseMsg_Encrypt0_Init (BSLX_CoseMsg_Encrypt0_t *obj)
 Initialize the struct.
 
void BSLX_CoseMsg_Encrypt0_Deinit (BSLX_CoseMsg_Encrypt0_t *obj)
 Deinitialize the struct.
 
int BSLX_CoseMsg_Encrypt0_Encode (QCBOREncodeContext *enc, const BSLX_CoseMsg_Encrypt0_t *obj)
 Match BSL_CBOR_Encode_f signature.
 
int BSLX_CoseMsg_Encrypt0_Decode (QCBORDecodeContext *dec, BSLX_CoseMsg_Encrypt0_t *obj)
 Match BSL_CBOR_Decode_f signature.
 
void BSLX_CoseMsg_Recipient_Init (BSLX_CoseMsg_Recipient_t *obj)
 Initialize the struct.
 
void BSLX_CoseMsg_Recipient_Deinit (BSLX_CoseMsg_Recipient_t *obj)
 Deinitialize the struct.
 
int BSLX_CoseMsg_Recipient_Encode (QCBOREncodeContext *enc, const BSLX_CoseMsg_Recipient_t *obj)
 Match BSL_CBOR_Encode_f signature.
 
int BSLX_CoseMsg_Recipient_Decode (QCBORDecodeContext *dec, BSLX_CoseMsg_Recipient_t *obj)
 Match BSL_CBOR_Decode_f signature.
 
void BSLX_CoseMsg_RecipientList_ResizeNew (BSLX_CoseMsg_RecipientList_t obj, size_t size)
 Resize recipients array, preserving existing if possible.
 
static void BSLX_CoseMsg_RecipientList_Encode (QCBOREncodeContext *enc, const BSLX_CoseMsg_RecipientList_t obj)
 
static int BSLX_CoseMsg_RecipientList_Decode (QCBORDecodeContext *dec, BSLX_CoseMsg_RecipientList_t obj)
 
void BSLX_CoseMsg_Mac_Init (BSLX_CoseMsg_Mac_t *obj)
 Initialize the struct.
 
void BSLX_CoseMsg_Mac_Deinit (BSLX_CoseMsg_Mac_t *obj)
 Deinitialize the struct.
 
int BSLX_CoseMsg_Mac_Encode (QCBOREncodeContext *enc, const BSLX_CoseMsg_Mac_t *obj)
 Match BSL_CBOR_Encode_f signature.
 
int BSLX_CoseMsg_Mac_Decode (QCBORDecodeContext *dec, BSLX_CoseMsg_Mac_t *obj)
 Match BSL_CBOR_Decode_f signature.
 
void BSLX_CoseMsg_Encrypt_Init (BSLX_CoseMsg_Encrypt_t *obj)
 Initialize the struct.
 
void BSLX_CoseMsg_Encrypt_Deinit (BSLX_CoseMsg_Encrypt_t *obj)
 Deinitialize the struct.
 
int BSLX_CoseMsg_Encrypt_Encode (QCBOREncodeContext *enc, const BSLX_CoseMsg_Encrypt_t *obj)
 Match BSL_CBOR_Encode_f signature.
 
int BSLX_CoseMsg_Encrypt_Decode (QCBORDecodeContext *dec, BSLX_CoseMsg_Encrypt_t *obj)
 Match BSL_CBOR_Decode_f signature.
 

Detailed Description

Implementation of COSE structures [15].

Function Documentation

◆ BSLX_CoseMsg_Encrypt0_Decode()

◆ BSLX_CoseMsg_Encrypt0_Deinit()

◆ BSLX_CoseMsg_Encrypt0_Encode()

int BSLX_CoseMsg_Encrypt0_Encode ( QCBOREncodeContext *  enc,
const BSLX_CoseMsg_Encrypt0_t obj 
)

◆ BSLX_CoseMsg_Encrypt0_Init()

◆ BSLX_CoseMsg_Encrypt_Decode()

◆ BSLX_CoseMsg_Encrypt_Deinit()

◆ BSLX_CoseMsg_Encrypt_Encode()

◆ BSLX_CoseMsg_Encrypt_Init()

◆ BSLX_CoseMsg_HdrMapTree_update()

void BSLX_CoseMsg_HdrMapTree_update ( BSLX_CoseMsg_HdrMapTree_t  base,
const BSLX_CoseMsg_HdrMapTree_t  addl 
)

Update a base map with an additional map, adding items when the key is not already present.

Referenced by BSLX_CoseSc_VerifyHeaders().

◆ BSLX_CoseMsg_Headers_CheckCrit()

int BSLX_CoseMsg_Headers_CheckCrit ( const BSLX_CoseMsg_Headers_t obj)

Check for the presence of crit header referencing unsupported parameters.

Parameters
[in]objThe headers to search.
Returns
BSL_SUCCESS if successful.

References BSL_CBOR_Decode(), BSL_ERR_DECODING, BSL_IdValPair_GetAsRaw(), BSL_LOG_ERR, BSL_SUCCESS, BSLX_COSEMSG_HDR_CRIT, BSLX_CoseMsg_Headers_CheckCrit_Decode(), and BSLX_CoseMsg_Headers_Get().

Referenced by BSLX_CoseSc_VerifyHeaders().

◆ BSLX_CoseMsg_Headers_CheckCrit_Decode()

static int BSLX_CoseMsg_Headers_CheckCrit_Decode ( QCBORDecodeContext *  dec,
const void *  obj 
)
static

◆ BSLX_CoseMsg_Headers_Decode()

◆ BSLX_CoseMsg_Headers_Decode_Map()

int BSLX_CoseMsg_Headers_Decode_Map ( QCBORDecodeContext *  dec,
BSLX_CoseMsg_HdrMapTree_t map 
)

Decode a header parameter map.

Matches BSL_CBOR_Encode_f signature.

References BSL_ERR_DECODING, BSL_IdValPair_Decode(), and BSL_SUCCESS.

Referenced by BSLX_CoseMsg_Headers_Decode(), and BSLX_CoseSc_GetAndValidateAddlHeaders().

◆ BSLX_CoseMsg_Headers_Deinit()

◆ BSLX_CoseMsg_Headers_DerivePhdr()

int BSLX_CoseMsg_Headers_DerivePhdr ( BSLX_CoseMsg_Headers_t obj)

Derive BSLX_CoseMsg_Headers_t::phdr_bstr from protected headers in BSLX_CoseMsg_Headers_t::phdr.

This is needed before cryptographic calculation and encoding.

Parameters
[in,out]objThe headers to encode and store into.
Returns
BSL_SUCCESS if successful.

References BSL_CBOR_Encode_Twopass(), BSL_Data_Resize(), BSL_SUCCESS, BSLX_CoseMsg_Headers_Encode_Map(), BSLX_CoseMsg_Headers_t::phdr, and BSLX_CoseMsg_Headers_t::phdr_bstr.

Referenced by BSLX_CoseSc_SourceHeaders().

◆ BSLX_CoseMsg_Headers_Encode()

◆ BSLX_CoseMsg_Headers_Encode_Map()

int BSLX_CoseMsg_Headers_Encode_Map ( QCBOREncodeContext *  enc,
const BSLX_CoseMsg_HdrMapTree_t map 
)

Encode a header parameter map.

Matches BSL_CBOR_Encode_f signature.

References BSL_IdValPair_Encode(), and BSL_SUCCESS.

Referenced by BSLX_CoseMsg_Headers_DerivePhdr(), and BSLX_CoseMsg_Headers_Encode().

◆ BSLX_CoseMsg_Headers_Get()

const BSL_IdValPair_t * BSLX_CoseMsg_Headers_Get ( const BSLX_CoseMsg_Headers_t obj,
int64_t  label,
bool  need_phdr 
)

Get a desired header parameter.

Parameters
[in]objThe headers to search.
labelThe label to search for.
need_phdrIf true the parameter needs to be in the protected map when it is present. This does not imply that it needs to be present.
Returns
Non-null pointer when found, or NULL if not found.

References BSL_LOG_ERR, BSLX_CoseMsg_Headers_t::phdr, and BSLX_CoseMsg_Headers_t::uhdr.

Referenced by BSLX_CoseMsg_Headers_CheckCrit(), BSLX_CoseSc_ExtractIV(), BSLX_CoseSc_GetAndValidateKey(), BSLX_CoseSc_GetAndValidateTarget(), and BSLX_CoseSc_HkdfContentKey().

◆ BSLX_CoseMsg_Headers_Init()

◆ BSLX_CoseMsg_Mac0_Decode()

◆ BSLX_CoseMsg_Mac0_Deinit()

◆ BSLX_CoseMsg_Mac0_Encode()

int BSLX_CoseMsg_Mac0_Encode ( QCBOREncodeContext *  enc,
const BSLX_CoseMsg_Mac0_t obj 
)

◆ BSLX_CoseMsg_Mac0_Init()

◆ BSLX_CoseMsg_Mac_Decode()

◆ BSLX_CoseMsg_Mac_Deinit()

◆ BSLX_CoseMsg_Mac_Encode()

◆ BSLX_CoseMsg_Mac_Init()

◆ BSLX_CoseMsg_Recipient_Decode()

◆ BSLX_CoseMsg_Recipient_Deinit()

◆ BSLX_CoseMsg_Recipient_Encode()

◆ BSLX_CoseMsg_Recipient_Init()

◆ BSLX_CoseMsg_RecipientList_Decode()

◆ BSLX_CoseMsg_RecipientList_Encode()

static void BSLX_CoseMsg_RecipientList_Encode ( QCBOREncodeContext *  enc,
const BSLX_CoseMsg_RecipientList_t  obj 
)
static

◆ BSLX_CoseMsg_RecipientList_ResizeNew()

void BSLX_CoseMsg_RecipientList_ResizeNew ( BSLX_CoseMsg_RecipientList_t  obj,
size_t  size 
)

Resize recipients array, preserving existing if possible.

References ASSERT_ARG_NONNULL.

Referenced by BSLX_CoseMsg_RecipientList_Decode(), BSLX_CoseSc_Encrypt_Source(), and BSLX_CoseSc_Mac_Source().