48#if COAP_OSCORE_SUPPORT 
   56compose_info(uint8_t *buffer,
 
   64  size_t rem_size = buf_size;
 
   71  if (id_context != NULL && id_context->
length > 0) {
 
   82                              (
const char *)type->
s,
 
   97  if (memcmp(a_ptr, b_ptr, a_len) == 0) {
 
  106  if (c_context->p_osc_ctx) {
 
  114    prev->
next = osc_ctx;
 
  116    c_context->p_osc_ctx = osc_ctx;
 
  152  while (c_context->p_osc_ctx) {
 
  155    c_context->p_osc_ctx = osc_ctx->
next;
 
  166    if (next == osc_ctx) {
 
  170        c_context->p_osc_ctx = next->
next;
 
  194  *recipient_ctx = NULL;
 
  195  assert(rcpkey_id.
length == 0 || rcpkey_id.
s != NULL);
 
  203        if (rcpkey_id.
length != 0)
 
  207            ok = ok + (memcmp(pt->
id_context->
s, oscore_r2, 8) != 0);
 
  211        } 
else if (ctxkey_id) {
 
  219          } 
else if (ctxkey_id->
length > 0)
 
  224          *recipient_ctx = rpt;
 
  235#define OSCORE_LOG_SIZE 16 
  247    coap_log(level, 
"    %-16s <>\n", name);
 
  251    for (i = 0; i < value->
length; i += OSCORE_LOG_SIZE) {
 
  252      char number[3 * OSCORE_LOG_SIZE + 4];
 
  255                            value->
length - i > OSCORE_LOG_SIZE ?
 
  256                            OSCORE_LOG_SIZE : value->length - i,
 
  259      coap_log(level, 
"    %-16s %s\n", i == 0 ? name : 
"", number);
 
  266  coap_log(level, 
"    %-16s %2d\n", name, value);
 
  271  coap_log(level, 
"    %-16s %s\n", name, value);
 
  283  size_t space = (dst_len - 4) / 3;
 
  286  for (qq = 0; qq < src_len && qq < space; qq++) {
 
  287    char tmp = src[qq] >> 4;
 
  289      tmp = tmp + 0x61 - 10;
 
  295      tmp = tmp + 0x61 - 10;
 
  298    dest[qq * 3 + 1] = tmp;
 
  299    dest[qq * 3 + 2] = 0x20;
 
  303    dest[qq * 3 + 1] = 
'.';
 
  304    dest[qq * 3 + 2] = 
'.';
 
  315  uint8_t info_buffer[80];
 
  321  info_len = compose_info(info_buffer,
 
  328  if (info_len == 0 || info_len > 
sizeof(info_buffer))
 
  343oscore_log_context(
oscore_ctx_t *osc_ctx, 
const char *heading) {
 
  344#if COAP_MAX_LOGGING_LEVEL < _COAP_LOG_OSCORE 
  373      snprintf(buffer, 
sizeof(buffer), 
"Recipient ID[%zu]", count);
 
  377      snprintf(buffer, 
sizeof(buffer), 
"Recipient Key[%zu]", count);
 
  399      oscore_build_key(osc_ctx,
 
  409      oscore_build_key(osc_ctx,
 
  418  osc_ctx->
common_iv = oscore_build_key(osc_ctx,
 
  427  oscore_log_context(osc_ctx, 
"Updated Common context");
 
  446  if (sender_ctx == NULL)
 
  471    sender_ctx->
sender_key = oscore_build_key(osc_ctx,
 
  479    osc_ctx->
common_iv = oscore_build_key(osc_ctx,
 
  499  if (copy_rid == NULL)
 
  504  oscore_log_context(osc_ctx, 
"New Common context");
 
  505  oscore_enter_context(c_context, osc_ctx);
 
  526  if (sender_ctx == NULL)
 
  549      sender_ctx->
sender_key = oscore_build_key(osc_ctx,
 
  554      sender_ctx->
sender_key = oscore_build_key(osc_ctx,
 
  562    osc_ctx->
common_iv = oscore_build_key(osc_ctx,
 
  589  oscore_log_context(osc_ctx, 
"Common context");
 
  591  oscore_enter_context(c_context, osc_ctx);
 
  603                     uint32_t break_key) {
 
  608    coap_log_warn(
"oscore_add_recipient: Maximum size of recipient_id is 7 bytes\n");
 
  623  if (recipient_ctx == NULL)
 
  647  recipient_ctx->
osc_ctx = osc_ctx;
 
  652  return recipient_ctx;
 
  666      oscore_free_recipient(next);
 
  700  if (association == NULL)
 
  713                                                   token->
length, token->
s, NULL);
 
  721  if (association->
token == NULL)
 
  726    if (association->
aad == NULL)
 
  732    if (association->
nonce == NULL)
 
  780    session->associations = NULL;
 
  790#pragma GCC diagnostic ignored "-Wunused-function" 
Library specific build wrapper for coap_internal.h.
 
void * coap_malloc_type(coap_memory_tag_t type, size_t size)
Allocates a chunk of size bytes and returns a pointer to the newly allocated memory.
 
void coap_free_type(coap_memory_tag_t type, void *p)
Releases the memory that was allocated by coap_malloc_type().
 
#define COAP_OSCORE_DEFAULT_REPLAY_WINDOW
 
coap_log_t coap_get_log_level(void)
Get the current logging level.
 
#define coap_log_oscore(...)
 
#define coap_log_warn(...)
 
#define coap_log(level,...)
Logging function.
 
size_t oscore_cbor_put_text(uint8_t **buffer, size_t *buf_size, const char *text, size_t text_len)
 
size_t oscore_cbor_put_nil(uint8_t **buffer, size_t *buf_size)
 
size_t oscore_cbor_put_unsigned(uint8_t **buffer, size_t *buf_size, uint64_t value)
 
size_t oscore_cbor_put_bytes(uint8_t **buffer, size_t *buf_size, const uint8_t *bytes, size_t bytes_len)
 
size_t oscore_cbor_put_array(uint8_t **buffer, size_t *buf_size, size_t elements)
 
const char * cose_get_hkdf_alg_name(cose_hkdf_alg_t id, char *buffer, size_t buflen)
 
const char * cose_get_alg_name(cose_alg_t id, char *buffer, size_t buflen)
 
#define OSCORE_ASSOCIATIONS_ITER_SAFE(e, el, rtmp)
 
void oscore_convert_to_hex(const uint8_t *src, size_t src_len, char *dest, size_t dst_len)
 
int oscore_delete_association(coap_session_t *session, oscore_association_t *association)
 
oscore_recipient_ctx_t * oscore_add_recipient(oscore_ctx_t *ctx, coap_bin_const_t *rid, uint32_t break_key)
oscore_add_recipient - add in recipient information
 
int oscore_delete_recipient(oscore_ctx_t *osc_ctx, coap_bin_const_t *rid)
 
#define OSCORE_ASSOCIATIONS_DELETE(r, obj)
 
void oscore_update_ctx(oscore_ctx_t *osc_ctx, coap_bin_const_t *id_context)
oscore_update_ctx - update a osc_ctx with a new id_context
 
void oscore_free_context(oscore_ctx_t *osc_ctx)
 
#define OSCORE_ASSOCIATIONS_ADD(r, obj)
 
oscore_ctx_t * oscore_derive_ctx(coap_context_t *c_context, coap_oscore_conf_t *oscore_conf)
oscore_derive_ctx - derive a osc_ctx from oscore_conf information
 
void oscore_free_association(oscore_association_t *association)
 
int oscore_hkdf(cose_hkdf_alg_t hkdf_alg, coap_bin_const_t *salt, coap_bin_const_t *ikm, uint8_t *info, size_t info_len, uint8_t *okm, size_t okm_len)
Derive the key using HKDF() function.
 
int oscore_new_association(coap_session_t *session, coap_pdu_t *sent_pdu, coap_bin_const_t *token, oscore_recipient_ctx_t *recipient_ctx, coap_bin_const_t *aad, coap_bin_const_t *nonce, coap_bin_const_t *partial_iv, int is_observe)
 
void oscore_delete_server_associations(coap_session_t *session)
 
void oscore_log_char_value(coap_log_t level, const char *name, const char *value)
 
void oscore_free_contexts(coap_context_t *c_context)
 
void oscore_log_hex_value(coap_log_t level, const char *name, coap_bin_const_t *value)
 
void oscore_log_int_value(coap_log_t level, const char *name, int value)
 
oscore_ctx_t * oscore_duplicate_ctx(coap_context_t *c_context, oscore_ctx_t *o_osc_ctx, coap_bin_const_t *sender_id, coap_bin_const_t *recipient_id, coap_bin_const_t *id_context)
oscore_duplicate_ctx - duplicate a osc_ctx
 
int oscore_remove_context(coap_context_t *c_context, oscore_ctx_t *osc_ctx)
 
oscore_association_t * oscore_find_association(coap_session_t *session, coap_bin_const_t *token)
 
oscore_ctx_t * oscore_find_context(const coap_context_t *c_context, const coap_bin_const_t rcpkey_id, const coap_bin_const_t *ctxkey_id, uint8_t *oscore_r2, oscore_recipient_ctx_t **recipient_ctx)
oscore_find_context - Locate recipient context (and hence OSCORE context)
 
#define OSCORE_ASSOCIATIONS_FIND(r, k, res)
 
#define CONTEXT_INIT_VECT_LEN
 
uint8_t oscore_bytes_equal(uint8_t *a_ptr, uint8_t a_len, uint8_t *b_ptr, uint8_t b_len)
 
void coap_delete_pdu_lkd(coap_pdu_t *pdu)
Dispose of an CoAP PDU and free off associated storage.
 
coap_pdu_t * coap_pdu_duplicate_lkd(const coap_pdu_t *old_pdu, coap_session_t *session, size_t token_length, const uint8_t *token, coap_opt_filter_t *drop_options)
Duplicate an existing PDU.
 
int coap_get_data(const coap_pdu_t *pdu, size_t *len, const uint8_t **data)
Retrieves the length and data pointer of specified PDU.
 
int coap_add_data(coap_pdu_t *pdu, size_t len, const uint8_t *data)
Adds given data to the pdu that is passed as first parameter.
 
void coap_delete_bin_const(coap_bin_const_t *s)
Deletes the given const binary data and releases any memory allocated.
 
coap_str_const_t * coap_make_str_const(const char *string)
Take the specified byte array (text) and create a coap_str_const_t *.
 
coap_bin_const_t * coap_new_bin_const(const uint8_t *data, size_t size)
Take the specified byte array (text) and create a coap_bin_const_t * Returns a new const binary objec...
 
CoAP binary data definition with const data.
 
size_t length
length of binary data
 
const uint8_t * s
read-only binary data
 
The CoAP stack's global state is stored in a coap_context_t object.
 
The structure used to hold the OSCORE configuration information.
 
void * save_seq_num_func_param
Passed to save_seq_num_func()
 
uint32_t rfc8613_b_2
1 if rfc8613 B.2 protocol else 0
 
cose_hkdf_alg_t hkdf_alg
Set to one of COSE_HKDF_ALG_*.
 
uint32_t break_sender_key
1 if sender key to be broken, else 0
 
uint32_t ssn_freq
Sender Seq Num update frequency.
 
coap_oscore_save_seq_num_t save_seq_num_func
Called every seq num change.
 
uint32_t rfc8613_b_1_2
1 if rfc8613 B.1.2 enabled else 0
 
uint64_t start_seq_num
Used for ssn_freq updating.
 
coap_bin_const_t * sender_id
Sender ID (i.e.
 
coap_bin_const_t ** recipient_id
Recipient ID (i.e.
 
uint32_t break_recipient_key
1 if recipient key to be broken, else 0
 
coap_bin_const_t * master_secret
Common Master Secret.
 
cose_alg_t aead_alg
Set to one of COSE_ALGORITHM_AES*.
 
coap_bin_const_t * master_salt
Common Master Salt.
 
uint32_t replay_window
Replay window size Use COAP_OSCORE_DEFAULT_REPLAY_WINDOW.
 
coap_bin_const_t * id_context
Common ID context.
 
uint32_t recipient_id_count
Number of recipient_id entries.
 
Abstraction of virtual session that can be attached to coap_context_t (client) or coap_endpoint_t (se...
 
CoAP string data definition with const data.
 
const uint8_t * s
read-only string data
 
size_t length
length of string
 
coap_bin_const_t * obs_partial_iv
 
coap_bin_const_t * partial_iv
 
oscore_recipient_ctx_t * recipient_ctx
 
coap_bin_const_t * master_secret
 
uint32_t replay_window_size
 
coap_bin_const_t * common_iv
Derived from Master Secret, Master Salt, and ID Context.
 
struct oscore_ctx_t * next
 
uint8_t rfc8613_b_1_2
1 if rfc8613 B.1.2 enabled else 0
 
void * save_seq_num_func_param
Passed to save_seq_num_func()
 
oscore_sender_ctx_t * sender_context
 
uint8_t rfc8613_b_2
1 if rfc8613 B.2 protocol else 0
 
coap_bin_const_t * master_salt
 
coap_oscore_save_seq_num_t save_seq_num_func
Called every seq num change.
 
oscore_recipient_ctx_t * recipient_chain
 
coap_bin_const_t * id_context
contains GID in case of group
 
uint32_t ssn_freq
Sender Seq Num update frequency.
 
oscore_recipient_ctx_t * next_recipient
 
coap_bin_const_t * recipient_key
 
coap_bin_const_t * recipient_id
 
coap_bin_const_t * sender_id
 
coap_bin_const_t * sender_key
 
uint64_t next_seq
Used for ssn_freq updating.