Contiki-NG
Loading...
Searching...
No Matches
edhoc-exporter.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2024, RISE Research Institutes of Sweden AB
3 * Copyright (c) 2020, Industrial Systems Institute (ISI), Patras, Greece
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. Neither the name of the copyright holder nor the names of its contributors
15 * may be used to endorse or promote products derived from this software
16 * without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 *
30 */
31
32/**
33 * \file
34 * EDHOC Exporter API - Interface to derive application security contexts
35 * from the EDHOC shared secret
36 *
37 * \author
38 * Lidia Pocero <pocero@isi.gr>, Rikard Höglund, Marco Tiloca
39 * Christos Koulamas <cklm@isi.gr>
40 */
41
42/**
43 * \addtogroup edhoc
44 * @{
45 */
46#ifndef _EDHOC_EXPORTER_H_
47#define _EDHOC_EXPORTER_H_
48
49#include <stdint.h>
50#include <string.h>
51#include <stdio.h>
52#include "edhoc.h"
53
54/* OSCORE KEY and SALT size */
55#define OSCORE_SALT_SZ 8
56#define OSCORE_KEY_SZ 16 /* Key length of the APP AEAD algorithm in bytes */
57
58/* PSK KEY and SALT sizes */
59#define PSK_KEY_SZ 16
60#define PSK_KEY_ID_SZ 4
61
62/* EDHOC Exporter Labels */
63#define OSCORE_MASTER_SECRET_LABEL 0
64#define OSCORE_MASTER_SALT_LABEL 1
65
66/**
67 * \brief OSCORE context struct
68 */
69typedef struct oscore_ctx {
70 uint8_t master_secret[OSCORE_KEY_SZ];
71 uint8_t master_salt[OSCORE_SALT_SZ];
72 int client_ID; /* CoAP client is the Initiator */
73 int server_ID; /* CoAP server is the Responder */
75
76/**
77 * \brief Derive an OSCORE Context from EDHOC
78 * \param osc Output OSCORE Context struct
79 * \param ctx Input EDHOC Context struct
80 * \return A positive value on success, or a negative HKDF error code on failure
81 *
82 * This function derives an OSCORE Security Context [RFC8613] from the EDHOC shared secret.
83 * It can be called by both EDHOC Initiator and Responder once the EDHOC protocol has finished
84 * successfully.
85 */
86int8_t edhoc_exporter_oscore(oscore_ctx_t *osc, edhoc_context_t *ctx);
87
88/**
89 * \brief Print OSCORE Security Context contents for debugging
90 * \param osc Input OSCORE Context struct
91 */
93
94/**
95 * \brief Derive an application-specific key from EDHOC
96 * \param result Output buffer where the derived key will be stored
97 * \param in_key PRK_Exporter key to use
98 * \param exporter_label Label used to differentiate different key derivation outputs
99 * \param context Context data used to generate the info input for key derivation
100 * \param context_sz The size of the context data
101 * \param length Length of the key to be derived
102 * \return The number of derived key bytes (a positive value) on success, or a negative error code on failure
103 *
104 * This function derives a key for application-specific use from the EDHOC shared secret using the EDHOC KDF.
105 * The key derivation is based on the provided label and length. This can be used to export keys
106 * after the successful completion of the EDHOC protocol.
107 */
108int8_t edhoc_exporter(const uint8_t *in_key, uint8_t exporter_label,
109 const uint8_t *context, uint8_t context_sz,
110 uint16_t length, uint8_t *result);
111
112#endif /* _EDHOC_EXPORTER_H_ */
113/** @} */
An implementation of Ephemeral Diffie-Hellman Over COSE (EDHOC) (RFC9528).
struct oscore_ctx oscore_ctx_t
OSCORE context struct.
void print_oscore_ctx(oscore_ctx_t *osc)
Print OSCORE Security Context contents for debugging.
int8_t edhoc_exporter(const uint8_t *in_key, uint8_t exporter_label, const uint8_t *context, uint8_t context_sz, uint16_t length, uint8_t *result)
Derive an application-specific key from EDHOC.
int8_t edhoc_exporter_oscore(oscore_ctx_t *osc, edhoc_context_t *ctx)
Derive an OSCORE Context from EDHOC.
OSCORE context struct.