49#if COAP_OSCORE_SUPPORT 
   57  size_t rem_size = 
sizeof(buf);
 
   68  memcpy(result, buf, *len);
 
   78  size_t rem_size = 
sizeof(buf);
 
   86  memcpy(result, buf, *len);
 
  123                     const uint8_t *oscore_option,
 
  124                     size_t oscore_option_len,
 
  126                     uint8_t *external_aad_ptr,
 
  127                     size_t external_aad_size) {
 
  128  size_t external_aad_len = 0;
 
  129  size_t rem_size = external_aad_size;
 
  132  (void)oscore_option_len;
 
  133  (void)sender_public_key;
 
  165  return external_aad_len;
 
  173                           size_t option_buf_len,
 
  176                           uint8_t appendix_b_2) {
 
  178  size_t rem_space = option_buf_len;
 
  184  option_buffer[0] = 0;
 
  189    memcpy(&(option_buffer[offset]),
 
  200      uint8_t *ptr = &option_buffer[offset+1];
 
  202      option_buffer[0] |= 0x10;
 
  206      offset += option_buffer[offset] + 1;
 
  208      option_buffer[0] |= 0x10;
 
  211      memcpy(&(option_buffer[offset]),
 
  221    option_buffer[0] |= 0x08;
 
  230  if (offset == 1 && option_buffer[0] == 0) {
 
  234  assert(offset <= option_buf_len);
 
  251  uint8_t partial_iv_len = (opt_value[0] & 0x07);
 
  260  if (option_len > 255 || partial_iv_len == 6 || partial_iv_len == 7 ||
 
  261      (opt_value[0] & 0xC0) != 0) {
 
  265  if ((opt_value[0] & 0x20) != 0) {
 
  269  if (partial_iv_len != 0) {
 
  271    if (offset + partial_iv_len > option_len) {
 
  274    partial_iv.
s = &(opt_value[offset]);
 
  275    partial_iv.
length = partial_iv_len;
 
  277    offset += partial_iv_len;
 
  280  if ((opt_value[0] & 0x10) != 0) {
 
  283    if (offset >= option_len)
 
  285    kid_context.
length = opt_value[offset];
 
  287    if (offset + kid_context.
length > option_len) {
 
  290    kid_context.
s = &(opt_value[offset]);
 
  292    offset = offset + kid_context.
length;
 
  295  if ((opt_value[0] & 0x08) != 0) {
 
  298    key_id.
length = option_len - offset;
 
  299    if ((
int)key_id.
length < 0) {
 
  302    key_id.
s = &(opt_value[offset]);
 
  315                   size_t external_aad_len,
 
  319  size_t rem_size = aad_size;
 
  320  char encrypt0[] = 
"Encrypt0";
 
  349  memset(buffer, 0, size);
 
  357  for (
int i = 0; i < size; i++) {
 
  358    buffer[i] = buffer[i] ^ (uint8_t)ctx->
common_iv->
s[i];
 
  369  uint64_t incoming_seq =
 
  373    coap_log_warn(
"OSCORE Replay protection, SEQ larger than SEQ_MAX.\n");
 
  386  } 
else if (incoming_seq > ctx->
last_seq) {
 
  388    uint64_t shift = incoming_seq - ctx->
last_seq;
 
  393  } 
else if (incoming_seq == ctx->
last_seq) {
 
  398    uint64_t shift = ctx->
last_seq - incoming_seq - 1;
 
  402      coap_log_warn(
"OSCORE: Replay protection, SEQ outside of replay window (%" 
  409    pattern = 1ULL << shift;
 
  467#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.
 
uint64_t coap_decode_var_bytes8(const uint8_t *buf, size_t len)
Decodes multiple-length byte sequences.
 
#define coap_log_oscore(...)
 
#define coap_log_warn(...)
 
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_number(uint8_t **buffer, size_t *buf_size, int64_t value)
 
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)
 
void cose_encrypt0_set_kid_context(cose_encrypt0_t *ptr, coap_bin_const_t *kid_context)
 
void cose_encrypt0_set_partial_iv(cose_encrypt0_t *ptr, coap_bin_const_t *partial_iv)
 
void cose_encrypt0_set_key_id(cose_encrypt0_t *ptr, coap_bin_const_t *key_id)
 
size_t oscore_prepare_aad(const uint8_t *external_aad_buffer, size_t external_aad_len, uint8_t *aad_buffer, size_t aad_size)
 
size_t oscore_encode_option_value(uint8_t *option_buffer, size_t option_buf_len, cose_encrypt0_t *cose, uint8_t group, uint8_t appendix_b_2)
 
uint8_t oscore_validate_sender_seq(oscore_recipient_ctx_t *ctx, cose_encrypt0_t *cose)
 
int oscore_decode_option_value(const uint8_t *option_value, size_t option_len, cose_encrypt0_t *cose)
 
uint8_t oscore_increment_sender_seq(oscore_ctx_t *ctx)
 
void oscore_roll_back_seq(oscore_recipient_ctx_t *ctx)
 
size_t oscore_prepare_e_aad(oscore_ctx_t *ctx, cose_encrypt0_t *cose, const uint8_t *oscore_option, size_t oscore_option_len, coap_bin_const_t *sender_public_key, uint8_t *external_aad_ptr, size_t external_aad_size)
 
uint8_t * oscore_cs_key_params(cose_curve_t param, int8_t param_type, size_t *len)
 
void oscore_generate_nonce(cose_encrypt0_t *ptr, oscore_ctx_t *ctx, uint8_t *buffer, uint8_t size)
 
uint8_t * oscore_cs_params(int8_t param, int8_t param_type, size_t *len)
 
@ OSCORE_MODE_SINGLE
Vanilla RFC8613 support.
 
CoAP binary data definition with const data.
 
size_t length
length of binary data
 
const uint8_t * s
read-only binary data
 
coap_bin_const_t partial_iv
 
coap_bin_const_t kid_context
 
coap_bin_const_t oscore_option
 
uint32_t replay_window_size
 
coap_bin_const_t * common_iv
Derived from Master Secret, Master Salt, and ID Context.
 
oscore_sender_ctx_t * sender_context
 
uint64_t rollback_sliding_window
 
uint64_t rollback_last_seq