55 size_t rem_size =
sizeof(buf);
66 memcpy(result, buf, *len);
76 size_t rem_size =
sizeof(buf);
84 memcpy(result, buf, *len);
121 const uint8_t *oscore_option,
122 size_t oscore_option_len,
124 uint8_t *external_aad_ptr,
125 size_t external_aad_size) {
126 size_t external_aad_len = 0;
127 size_t rem_size = external_aad_size;
130 (void)oscore_option_len;
131 (void)sender_public_key;
163 return external_aad_len;
171 size_t option_buf_len,
174 uint8_t appendix_b_2) {
176 size_t rem_space = option_buf_len;
182 option_buffer[0] = 0;
187 memcpy(&(option_buffer[offset]),
198 uint8_t *ptr = &option_buffer[offset+1];
200 option_buffer[0] |= 0x10;
204 offset += option_buffer[offset] + 1;
206 option_buffer[0] |= 0x10;
209 memcpy(&(option_buffer[offset]),
219 option_buffer[0] |= 0x08;
228 if (offset == 1 && option_buffer[0] == 0) {
232 assert(offset <= option_buf_len);
249 uint8_t partial_iv_len = (opt_value[0] & 0x07);
258 if (option_len > 255 || partial_iv_len == 6 || partial_iv_len == 7 ||
259 (opt_value[0] & 0xC0) != 0) {
263 if ((opt_value[0] & 0x20) != 0) {
267 if (partial_iv_len != 0) {
269 if (offset + partial_iv_len > option_len) {
272 partial_iv.
s = &(opt_value[offset]);
273 partial_iv.
length = partial_iv_len;
275 offset += partial_iv_len;
278 if ((opt_value[0] & 0x10) != 0) {
281 if (offset >= option_len)
283 kid_context.
length = opt_value[offset];
285 if (offset + kid_context.
length > option_len) {
288 kid_context.
s = &(opt_value[offset]);
290 offset = offset + kid_context.
length;
293 if ((opt_value[0] & 0x08) != 0) {
296 key_id.
length = option_len - offset;
297 if ((
int)key_id.
length < 0) {
300 key_id.
s = &(opt_value[offset]);
313 size_t external_aad_len,
317 size_t rem_size = aad_size;
318 char encrypt0[] =
"Encrypt0";
347 memset(buffer, 0, size);
355 for (
int i = 0; i < size; i++) {
356 buffer[i] = buffer[i] ^ (uint8_t)ctx->
common_iv->
s[i];
367 uint64_t incoming_seq =
371 coap_log_warn(
"OSCORE Replay protection, SEQ larger than SEQ_MAX.\n");
384 }
else if (incoming_seq > ctx->
last_seq) {
386 uint64_t shift = incoming_seq - ctx->
last_seq;
391 }
else if (incoming_seq == ctx->
last_seq) {
396 uint64_t shift = ctx->
last_seq - incoming_seq - 1;
400 coap_log_warn(
"OSCORE: Replay protection, SEQ outside of replay window (%"
407 pattern = 1ULL << shift;
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_flag, 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 *opt_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