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

Implementation of the COSE context [17]. More...

#include "CoseContext.h"
#include "CoseContext_Private.h"
#include "CoseMsg.h"
#include "bsl/BPSecLib_Private.h"
#include "bsl/crypto/CryptoInterface.h"
#include "bsl/dynamic/CBOR.h"
#include <m-bptree.h>
#include <m-bstring.h>
#include <m-deque.h>
#include <m-variant.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
+ Include dependency graph for CoseContext.c:

Data Structures

struct  BSLX_CoseSc_t
 
struct  BSLX_CoseSc_KdfContext_t
 Limited fields actually used by this COSE implementation. More...
 

Functions

static int local_cmp_int64 (const void *lhs, const void *rhs)
 Matches signature for bsearch()
 
static void BSLX_CoseSc_Init (BSLX_CoseSc_t *self)
 
static void BSLX_CoseSc_Deinit (BSLX_CoseSc_t *self)
 
static void BSLX_CoseSc_Prepare (BSLX_CoseSc_t *self, BSL_BundleRef_t *bundle, BSL_SecOper_t *sec_oper)
 
static void BSLX_CoseSc_GetOptions (BSLX_CoseSc_t *self, const BSL_SecOper_t *sec_oper)
 
bool BSLX_CoseSc_Validate (BSL_LibCtx_t *lib, BSL_BundleRef_t *bundle, BSL_SecOper_t *sec_oper)
 Match signature BSL_SecCtx_Validate_f.
 
int BSLX_CoseSc_AadScope_Encode (QCBOREncodeContext *enc, const BSLX_CoseSc_AadScope_t *scope)
 
int BSLX_CoseSc_AadScope_Decode (QCBORDecodeContext *dec, BSLX_CoseSc_AadScope_t *scope)
 
static m_bstring_t * BSLX_CoseSc_ChunkList_GetBstring (BSLX_CoseSc_ChunkList_t chunklist)
 Get the last bytes chunk to append to, or add one if needed.
 
static size_t BSLX_CoseSc_bstring_AppendHead (m_bstring_t data, uint8_t major, uint64_t argument)
 Append a CBOR head only.
 
static size_t BSLX_CoseSc_bstring_AppendRaw (m_bstring_t data, const BSL_Data_t *chunk)
 Append raw CBOR encoded data.
 
static int BSLX_CoseSc_ExternalAad_Chunked (const BSLX_CoseSc_t *ctx, BSLX_CoseSc_ChunkList_t chunklist, size_t *total)
 Handle the external AAD content as appending to a list of chunks.
 
static void BSLX_CoseSc_BuildAad (BSLX_CoseSc_t *ctx, BSLX_CoseSc_ChunkList_t chunklist, const BSLX_CoseMsg_Headers_t *headers, const char *context)
 Common COSE AAD composition for MAC, Encrypt, and Sign.
 
static void BSLX_CoseSc_Mac_Compute (BSLX_CoseSc_t *ctx, const BSLX_CoseMsg_Headers_t *headers, const char *context, BSL_Data_t *tag)
 Internal processing according to Section 6.3 of RFC 9052.
 
static void BSLX_CoseSc_GetAndValidateTarget (BSLX_CoseSc_t *self, const BSLX_CoseMsg_Headers_t *headers)
 
static void BSLX_CoseSc_GetAndValidateKey (BSLX_CoseSc_t *self, const BSLX_CoseMsg_Headers_t *headers)
 Combine options and received headers to validate end key.
 
static void BSLX_CoseSc_GetAndValidateAddlHeaders (BSLX_CoseSc_t *self)
 
static void BSLX_CoseSc_GetAndValidateAadScope (BSLX_CoseSc_t *self)
 
static void BSLX_CoseSc_SourceHeaders (BSLX_CoseSc_t *ctx, BSLX_CoseMsg_Headers_t *headers0, BSLX_CoseMsg_Headers_t *headers1)
 Common logic for headers at the source.
 
static void BSLX_CoseSc_VerifyHeaders (BSLX_CoseSc_t *ctx, BSLX_CoseMsg_Headers_t *headers0, BSLX_CoseMsg_Headers_t *headers1)
 Common logic for headers at verifier or acceptor.
 
static void BSLX_CoseSc_AddAadScope (BSLX_CoseSc_t *ctx)
 
static void BSLX_CoseSc_Mac0_Source (BSLX_CoseSc_t *ctx)
 Internal processing to source a COSE_Mac0 message.
 
static void BSLX_CoseSc_Mac0_VerifyAccept (BSLX_CoseSc_t *ctx, const BSL_IdValPair_t *result)
 Internal processing to verify a COSE_Mac0 message.
 
static int BSLX_CoseSc_GenerateNonce (BSL_Crypto_KeyHandle_t keyhandle, BSL_Data_t *out, BSL_Data_t *partial, const BSL_Data_t *base, bool use_offset, int64_t offset, size_t default_len)
 Synthesize a nonce value based on option values.
 
static int BSLX_CoseSc_KdfContext_Encode (QCBOREncodeContext *enc, const BSLX_CoseSc_KdfContext_t *obj)
 Matches BSL_CBOR_Encode_f signature.
 
static void BSLX_CoseSc_HkdfContentKey (BSLX_CoseSc_t *ctx, BSLX_CoseMsg_Recipient_t *recip)
 HKDF processing for source and verifier.
 
static void BSLX_CoseSc_GenerateContentKey (BSLX_CoseSc_t *ctx, BSLX_CoseMsg_Recipient_t *recip)
 Common processing to source content key from recipient layer.
 
static void BSLX_CoseSc_ExtractContentKey (BSLX_CoseSc_t *ctx, BSLX_CoseMsg_Recipient_t *recip)
 Common processing to extract content key from recipient layer.
 
static void BSLX_CoseSc_Mac_Source (BSLX_CoseSc_t *ctx)
 Internal processing to source a COSE_Mac message.
 
static void BSLX_CoseSc_Mac_VerifyAccept (BSLX_CoseSc_t *ctx, const BSL_IdValPair_t *result)
 Internal processing to verify a COSE_Mac message.
 
static void BSLX_CoseSc_Encrypt_Compute (BSLX_CoseSc_t *ctx, const BSLX_CoseMsg_Headers_t *headers, const char *context, BSL_CipherMode_e mode)
 Internal processing according to Section 5.3 of RFC 9052.
 
static void BSLX_CoseSc_GenerateIV (BSLX_CoseSc_t *ctx, BSLX_CoseMsg_Headers_t *headers)
 Generate optional partial IV depending on key Base IV.
 
static void BSLX_CoseSc_ExtractIV (BSLX_CoseSc_t *ctx, const BSLX_CoseMsg_Headers_t *headers)
 Extract IV header parameters and augment with key data.
 
static void BSLX_CoseSc_Encrypt0_Source (BSLX_CoseSc_t *ctx)
 Internal processing to source a COSE_Encrypt0 message.
 
static void BSLX_CoseSc_Encrypt0_VerifyAccept (BSLX_CoseSc_t *ctx, const BSL_IdValPair_t *result)
 Internal processing to verify a COSE_Encrypt0 message.
 
static void BSLX_CoseSc_Encrypt_Source (BSLX_CoseSc_t *ctx)
 Internal processing to source a COSE_Encrypt message.
 
static void BSLX_CoseSc_Encrypt_VerifyAccept (BSLX_CoseSc_t *ctx, const BSL_IdValPair_t *result)
 Internal processing to verify a COSE_Encrypt message.
 
int BSLX_CoseSc_Execute (BSL_LibCtx_t *lib, BSL_BundleRef_t *bundle, BSL_SecOper_t *sec_oper)
 Match signature BSL_SecCtx_Execute_f.
 

Variables

static const int64_t cose_bib_cnt_algs []
 Acceptable target algorithms for MAC.
 
static const int64_t cose_bcb_cnt_algs []
 Acceptable target algorithms for Encrypt.
 
static const int64_t cose_recip_alg_unprot []
 Recipient algorithms which cannot protect the header.
 

Detailed Description

Implementation of the COSE context [17].

Function Documentation

◆ BSLX_CoseSc_AadScope_Decode()

int BSLX_CoseSc_AadScope_Decode ( QCBORDecodeContext *  dec,
BSLX_CoseSc_AadScope_t scope 
)

◆ BSLX_CoseSc_AadScope_Encode()

◆ BSLX_CoseSc_AddAadScope()

◆ BSLX_CoseSc_bstring_AppendHead()

static size_t BSLX_CoseSc_bstring_AppendHead ( m_bstring_t  data,
uint8_t  major,
uint64_t  argument 
)
static

◆ BSLX_CoseSc_bstring_AppendRaw()

static size_t BSLX_CoseSc_bstring_AppendRaw ( m_bstring_t  data,
const BSL_Data_t chunk 
)
static

Append raw CBOR encoded data.

References BSL_Data_t::len, and BSL_Data_t::ptr.

Referenced by BSLX_CoseSc_BuildAad(), and BSLX_CoseSc_ExternalAad_Chunked().

◆ BSLX_CoseSc_BuildAad()

static void BSLX_CoseSc_BuildAad ( BSLX_CoseSc_t ctx,
BSLX_CoseSc_ChunkList_t  chunklist,
const BSLX_CoseMsg_Headers_t headers,
const char *  context 
)
static

◆ BSLX_CoseSc_ChunkList_GetBstring()

static m_bstring_t * BSLX_CoseSc_ChunkList_GetBstring ( BSLX_CoseSc_ChunkList_t  chunklist)
static

Get the last bytes chunk to append to, or add one if needed.

Referenced by BSLX_CoseSc_BuildAad(), BSLX_CoseSc_Encrypt_Compute(), BSLX_CoseSc_ExternalAad_Chunked(), and BSLX_CoseSc_Mac_Compute().

◆ BSLX_CoseSc_Deinit()

◆ BSLX_CoseSc_Encrypt0_Source()

◆ BSLX_CoseSc_Encrypt0_VerifyAccept()

◆ BSLX_CoseSc_Encrypt_Compute()

◆ BSLX_CoseSc_Encrypt_Source()

◆ BSLX_CoseSc_Encrypt_VerifyAccept()

◆ BSLX_CoseSc_Execute()

◆ BSLX_CoseSc_ExternalAad_Chunked()

◆ BSLX_CoseSc_ExtractContentKey()

◆ BSLX_CoseSc_ExtractIV()

◆ BSLX_CoseSc_GenerateContentKey()

◆ BSLX_CoseSc_GenerateIV()

◆ BSLX_CoseSc_GenerateNonce()

static int BSLX_CoseSc_GenerateNonce ( BSL_Crypto_KeyHandle_t  keyhandle,
BSL_Data_t out,
BSL_Data_t partial,
const BSL_Data_t base,
bool  use_offset,
int64_t  offset,
size_t  default_len 
)
static

◆ BSLX_CoseSc_GetAndValidateAadScope()

◆ BSLX_CoseSc_GetAndValidateAddlHeaders()

◆ BSLX_CoseSc_GetAndValidateKey()

◆ BSLX_CoseSc_GetAndValidateTarget()

◆ BSLX_CoseSc_GetOptions()

◆ BSLX_CoseSc_HkdfContentKey()

◆ BSLX_CoseSc_Init()

◆ BSLX_CoseSc_KdfContext_Encode()

◆ BSLX_CoseSc_Mac0_Source()

◆ BSLX_CoseSc_Mac0_VerifyAccept()

◆ BSLX_CoseSc_Mac_Compute()

◆ BSLX_CoseSc_Mac_Source()

◆ BSLX_CoseSc_Mac_VerifyAccept()

◆ BSLX_CoseSc_Prepare()

◆ BSLX_CoseSc_SourceHeaders()

◆ BSLX_CoseSc_Validate()

◆ BSLX_CoseSc_VerifyHeaders()

◆ local_cmp_int64()

static int local_cmp_int64 ( const void *  lhs,
const void *  rhs 
)
static

Matches signature for bsearch()

Referenced by BSLX_CoseSc_GetOptions(), and BSLX_CoseSc_SourceHeaders().

Variable Documentation

◆ cose_bcb_cnt_algs

const int64_t cose_bcb_cnt_algs[]
static
Initial value:
= {
}
@ BSLX_COSEMSG_ALG_AES_GCM_128
A128GCM.
Definition CoseMsg.h:87
@ BSLX_COSEMSG_ALG_AES_GCM_192
A192GCM.
Definition CoseMsg.h:89
@ BSLX_COSEMSG_ALG_AES_GCM_256
A256GCM.
Definition CoseMsg.h:91

Acceptable target algorithms for Encrypt.

Note
These must be sorted for bsearch() to work.

Referenced by BSLX_CoseSc_GetOptions().

◆ cose_bib_cnt_algs

const int64_t cose_bib_cnt_algs[]
static
Initial value:
= {
}
@ BSLX_COSEMSG_ALG_HMAC_SHA_512_512
HMAC 512/512.
Definition CoseMsg.h:97
@ BSLX_COSEMSG_ALG_HMAC_SHA_384_384
HMAC 384/384.
Definition CoseMsg.h:95
@ BSLX_COSEMSG_ALG_HMAC_SHA_256_256
HMAC 256/256.
Definition CoseMsg.h:93

Acceptable target algorithms for MAC.

Note
These must be sorted for bsearch() to work.

Referenced by BSLX_CoseSc_GetOptions().

◆ cose_recip_alg_unprot

const int64_t cose_recip_alg_unprot[]
static
Initial value:
@ BSLX_COSEMSG_ALG_AES_KW_192
A256KW.
Definition CoseMsg.h:83
@ BSLX_COSEMSG_ALG_AES_KW_256
A256KW.
Definition CoseMsg.h:81
@ BSLX_COSEMSG_ALG_AES_KW_128
A256KW.
Definition CoseMsg.h:85

Recipient algorithms which cannot protect the header.

Note
These must be sorted for bsearch() to work.

Referenced by BSLX_CoseSc_SourceHeaders().