Contiki-NG
Loading...
Searching...
No Matches
edhoc-trace.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2025, RISE Research Institutes of Sweden AB.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the copyright holder nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 */
30
31/**
32 * \file
33 * EDHOC tracing and logging header.
34 * \author
35 * Nicolas Tsiftes <nicolas.tsiftes@ri.se>
36 */
37
38#ifndef EDHOC_TRACE_H_
39#define EDHOC_TRACE_H_
40
41#include "edhoc.h"
42#include "sys/log.h"
43
44/* Enhanced tracing macros aligned with RFC 9529 format */
45
46/**
47 * \brief Print protocol step header in RFC 9529 style
48 * \param step_name The name of the protocol step (e.g., "message_1", "message_2")
49 */
50#define EDHOC_TRACE_STEP(step_name) \
51 LOG_DBG("=== EDHOC %s ===\n", step_name)
52
53/**
54 * \brief Print cryptographic value in RFC 9529 trace format
55 * \param label Descriptive label for the value
56 * \param data Pointer to the data
57 * \param len Length of the data in bytes
58 */
59#define EDHOC_TRACE_VALUE(label, data, len) do { \
60 if(LOG_LEVEL >= LOG_LEVEL_DBG) { \
61 LOG_DBG("%s (%zu bytes): ", label, (size_t)(len)); \
62 if((len) > 0) { \
63 LOG_DBG_BYTES(data, len); \
64 } \
65 LOG_DBG_("\n"); \
66 } \
67} while(0)
68
69/**
70 * \brief Print protocol state transition
71 * \param from_state Previous state
72 * \param to_state New state
73 */
74#define EDHOC_TRACE_STATE(from_state, to_state) \
75 LOG_DBG("State transition: %s -> %s\n", from_state, to_state)
76
77/**
78 * \brief Print computation step description
79 * \param description Brief description of the computation
80 */
81#define EDHOC_TRACE_COMPUTE(description) \
82 LOG_DBG("Computing: %s\n", description)
83
84/**
85 * \brief Print detailed debug value (only at DBG level)
86 * \param label Descriptive label
87 * \param data Pointer to the data
88 * \param len Length of the data
89 */
90#define EDHOC_DBG_VALUE(label, data, len) do { \
91 if(LOG_LEVEL >= LOG_LEVEL_DBG) { \
92 LOG_DBG("%s (%d bytes): ", label, (int)(len)); \
93 if((len) > 0) { \
94 LOG_DBG_BYTES(data, len); \
95 LOG_DBG_("\n"); \
96 } else { \
97 LOG_DBG_("(empty)\n"); \
98 } \
99 } \
100} while(0)
101
102/* Function prototypes for enhanced tracing */
103
104/**
105 * \brief Print EDHOC message in RFC 9529 trace format
106 * \param msg_num Message number (1, 2, 3, or 4)
107 * \param msg_data Message data
108 * \param msg_len Message length
109 * \param is_tx True if transmitting, false if receiving
110 */
111void edhoc_trace_message(uint8_t msg_num, const uint8_t *msg_data, size_t msg_len, bool is_tx);
112
113/**
114 * \brief Print ephemeral key generation step
115 * \param role_label Role label ("Initiator" or "Responder")
116 * \param pub_x Public key X coordinate
117 * \param pub_y Public key Y coordinate (optional, can be NULL)
118 * \param priv Private key (optional for security, can be NULL)
119 */
120void edhoc_trace_ephemeral_key(const char *role_label,
121 const uint8_t *pub_x,
122 const uint8_t *pub_y,
123 const uint8_t *priv);
124
125/**
126 * \brief Print transcript hash computation
127 * \param th_label TH label ("TH_2", "TH_3", "TH_4")
128 * \param th_data Transcript hash data
129 * \param input_data Input data for hash computation (optional)
130 * \param input_len Input data length
131 */
132void edhoc_trace_transcript_hash(const char *th_label,
133 const uint8_t *th_data,
134 const uint8_t *input_data,
135 size_t input_len);
136
137/**
138 * \brief Print PRK derivation step
139 * \param prk_label PRK label ("PRK_2e", "PRK_3e2m", "PRK_4e3m")
140 * \param prk_data PRK data
141 * \param salt_data Salt used (optional)
142 * \param ikm_data Input keying material (optional)
143 */
144void edhoc_trace_prk_derivation(const char *prk_label,
145 const uint8_t *prk_data,
146 const uint8_t *salt_data,
147 const uint8_t *ikm_data);
148
149/**
150 * \brief Print MAC computation step
151 * \param mac_label MAC label ("MAC_2", "MAC_3")
152 * \param mac_data MAC data
153 * \param context_data Context data used for MAC computation (optional)
154 * \param context_len Context data length
155 */
156void edhoc_trace_mac_computation(const char *mac_label,
157 const uint8_t *mac_data,
158 const uint8_t *context_data,
159 size_t context_len);
160
161/**
162 * \brief Print credential information
163 * \param cred_label Credential label ("CRED_I", "CRED_R")
164 * \param cred_data Credential data
165 * \param cred_len Credential length
166 * \param id_cred_data ID_CRED data (optional)
167 * \param id_cred_len ID_CRED length
168 */
169void edhoc_trace_credential(const char *cred_label,
170 const uint8_t *cred_data, size_t cred_len,
171 const uint8_t *id_cred_data, size_t id_cred_len);
172
173/**
174 * \brief Print session summary at protocol completion
175 * \param ctx EDHOC context
176 */
177void edhoc_trace_session_summary(const edhoc_context_t *ctx);
178
179#endif /* EDHOC_TRACE_H_ */
void edhoc_trace_transcript_hash(const char *th_label, const uint8_t *th_data, const uint8_t *input_data, size_t input_len)
Print transcript hash computation.
Definition edhoc-trace.c:97
void edhoc_trace_credential(const char *cred_label, const uint8_t *cred_data, size_t cred_len, const uint8_t *id_cred_data, size_t id_cred_len)
Print credential information.
void edhoc_trace_mac_computation(const char *mac_label, const uint8_t *mac_data, const uint8_t *context_data, size_t context_len)
Print MAC computation step.
void edhoc_trace_ephemeral_key(const char *role_label, const uint8_t *pub_x, const uint8_t *pub_y, const uint8_t *priv)
Print ephemeral key generation step.
Definition edhoc-trace.c:64
void edhoc_trace_message(uint8_t msg_num, const uint8_t *msg_data, size_t msg_len, bool is_tx)
Print EDHOC message in RFC 9529 trace format.
Definition edhoc-trace.c:48
void edhoc_trace_session_summary(const edhoc_context_t *ctx)
Print session summary at protocol completion.
void edhoc_trace_prk_derivation(const char *prk_label, const uint8_t *prk_data, const uint8_t *salt_data, const uint8_t *ikm_data)
Print PRK derivation step.
An implementation of Ephemeral Diffie-Hellman Over COSE (EDHOC) (RFC9528).
Header file for the logging system.