libcoap 4.3.5-develop-5347a62
Loading...
Searching...
No Matches
oscore.h
Go to the documentation of this file.
1/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
3/*
4 * Copyright (c) 2018, SICS, RISE AB
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the Institute nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 *
31 */
32
46
47#ifndef _OSCORE_H
48#define _OSCORE_H
49
50#include "oscore_cose.h"
51#include "oscore_context.h"
52
53#ifdef __cplusplus
54extern "C" {
55#endif
56
62
63/* Estimate your header size, especially when using Proxy-Uri. */
64#define COAP_MAX_HEADER_SIZE 70
65
66/* OSCORE error messages (to be moved elsewhere */
67#define OSCORE_DECRYPTION_ERROR 100
68#define PACKET_SERIALIZATION_ERROR 102
69
70/* oscore_cs_params
71 * returns cbor array [[param_type], [paramtype, param]]
72 */
73uint8_t *oscore_cs_params(int8_t param, int8_t param_type, size_t *len);
74
75/* oscore_cs_key_params
76 * returns cbor array [paramtype, param]
77 */
78uint8_t *oscore_cs_key_params(cose_curve_t param, int8_t param_type, size_t *len);
79
91ssize_t oscore_encode_option_value(uint8_t *option_buffer,
92 size_t option_buf_len,
93 cose_encrypt0_t *cose,
94 uint8_t group_flag,
95 uint8_t appendix_b_2);
96
97/*
98 * Decodes the OSCORE option value and places decoded values into the provided
99 * cose structure */
100int oscore_decode_option_value(const uint8_t *option_value,
101 size_t option_len,
102 cose_encrypt0_t *cose);
103
104#if COAP_OSCORE_GROUP_SUPPORT
105/* Sets alg and keys in COSE SIGN */
106void oscore_populate_sign(cose_sign1_t *sign,
107 oscore_ctx_t *ctx,
108 coap_crypto_cred_t *public_cred,
109 coap_crypto_pri_key_t *private_key);
110
111/*
112 * oscore_prepare_sig_structure
113 *
114 * creates and sets structure to be signed
115 */
116size_t oscore_prepare_sig_structure(uint8_t *sigptr,
117 size_t sig_size,
118 const uint8_t *e_aad_buffer,
119 uint16_t e_aad_len,
120 const uint8_t *text,
121 uint16_t text_len);
122#endif /* COAP_OSCORE_GROUP_SUPPORT */
123
124/* Creates AAD, creates External AAD and serializes it into the complete AAD
125 * structure. Returns serialized size. */
126size_t oscore_prepare_aad(const uint8_t *external_aad_buffer,
127 size_t external_aad_len,
128 uint8_t *aad_buffer,
129 size_t aad_size);
130
132 cose_encrypt0_t *cose,
133 const uint8_t *oscore_option,
134 size_t oscore_option_len,
135 coap_crypto_cred_t *sender_cred,
136#if COAP_OSCORE_GROUP_SUPPORT
137 oscore_mode_t mode,
138#endif /* COAP_OSCORE_GROUP_SUPPORT */
139 uint8_t *external_aad_ptr,
140 size_t external_aad_size);
141
142/* Creates Nonce */
144 oscore_ctx_t *ctx,
145 uint8_t *buffer,
146 uint8_t size);
147
148/*Return 1 if OK, Error code otherwise */
150 cose_encrypt0_t *cose);
151
152/* Return 0 if SEQ MAX, return 1 if OK */
154
155/* Restore the sequence number and replay-window to the previous state. This is
156 * to be used when decryption fail. */
158
160
161#ifdef __cplusplus
162}
163#endif
164
165#endif /* _OSCORE_H */
cose_curve_t
Definition oscore_cose.h:62
size_t oscore_prepare_aad(const uint8_t *external_aad_buffer, size_t external_aad_len, uint8_t *aad_buffer, size_t aad_size)
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)
oscore_mode_t
uint8_t oscore_increment_sender_seq(oscore_ctx_t *ctx)
void oscore_roll_back_seq(oscore_recipient_ctx_t *ctx)
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)
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_crypto_cred_t *sender_cred, uint8_t *external_aad_ptr, size_t external_aad_size)
ssize_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)
Encode the OSCORE option.
An implementation of the Object Security for Constrained RESTful Environments (RFC 8613).
An implementation of the CBOR Object Signing and Encryption (RFC).
Holds credential definitions.
Holds private key definitions.