Zephyr API Documentation 4.5.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
srtp.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2026 Basalte bv
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
11
12#ifndef ZEPHYR_INCLUDE_NET_SRTP_H_
13#define ZEPHYR_INCLUDE_NET_SRTP_H_
14
15#include <psa/crypto.h>
16#include <zephyr/kernel.h>
18
19#ifdef __cplusplus
20extern "C" {
21#endif
22
34
36#define SRTP_AES_128_KEY_LEN 16
38#define SRTP_AES_256_KEY_LEN 32
40#define SRTP_MASTER_SALT_LEN 14
42#define SRTP_AES_GCM_SALT_LEN 12
44#define SRTP_HMAC_SHA1_KEY_LEN 20
46#define SRTP_AES_GCM_TAG_LEN 16
48#define SRTP_AES_GCM_IV_LEN 12
50#define SRTP_MKI_MAX_LEN 16
51
55#define SRTP_TRAILER_MAX_LEN (SRTP_AES_GCM_TAG_LEN + SRTP_MKI_MAX_LEN)
56
74
87
129
132#define SRTP_REPLAY_WINDOW_WORD_BITS 64
133#define SRTP_REPLAY_WINDOW_WORDS \
134 DIV_ROUND_UP(CONFIG_SRTP_REPLAY_WINDOW_SIZE, SRTP_REPLAY_WINDOW_WORD_BITS)
136
147 uint32_t ssrc;
148 enum srtp_cipher cipher;
149 enum srtp_auth auth;
150 uint32_t kdr;
151
153 uint32_t roc;
155 uint16_t s_l;
157 bool seq_initialized;
159 uint64_t index_max;
161 uint64_t replay_window[SRTP_REPLAY_WINDOW_WORDS];
163 uint64_t tx_count;
164
166 psa_key_id_t master_key;
167 uint8_t master_salt[SRTP_MASTER_SALT_LEN];
168 size_t master_salt_len;
171 size_t mki_len;
173 uint64_t key_segment;
174
176 psa_key_id_t k_e;
178 psa_key_id_t k_a;
181
182 struct k_mutex lock;
184};
185
200int srtp_stream_init(struct srtp_stream *stream, const struct srtp_policy *policy, uint32_t ssrc);
201
212int srtp_stream_deinit(struct srtp_stream *stream);
213
234int srtp_stream_protect(struct srtp_stream *stream, uint8_t *buf, size_t pkt_len, size_t buf_size,
235 size_t *out_len);
236
245int srtp_policy_check(const struct srtp_policy *policy);
246
264int srtp_stream_unprotect(struct srtp_stream *stream, uint8_t *buf, size_t pkt_len,
265 size_t *out_len);
266
281 struct srtp_stream tx;
282 bool tx_enabled;
283
284 struct srtp_stream rx[CONFIG_SRTP_MAX_RX_STREAMS];
285 bool rx_bound[CONFIG_SRTP_MAX_RX_STREAMS];
287 uint8_t rx_users[CONFIG_SRTP_MAX_RX_STREAMS];
288 bool rx_enabled;
289
293 struct srtp_policy rx_policy;
294 uint8_t rx_master_key[SRTP_AES_256_KEY_LEN];
295 uint8_t rx_master_salt[SRTP_MASTER_SALT_LEN];
297
302 atomic_t users;
304 struct k_mutex lock;
306 struct k_condvar drained;
307
308#ifdef CONFIG_RTP_TRANSPORT_NET_PKT
312 uint8_t net_pkt_buf[CONFIG_SRTP_NET_PKT_BUF_SIZE];
314 struct k_mutex net_pkt_lock;
315#endif /* CONFIG_RTP_TRANSPORT_NET_PKT */
317};
318
319#ifdef __cplusplus
320}
321#endif
322
326
327#endif /* ZEPHYR_INCLUDE_NET_SRTP_H_ */
long atomic_t
Atomic integer variable.
Definition atomic_types.h:34
int srtp_stream_init(struct srtp_stream *stream, const struct srtp_policy *policy, uint32_t ssrc)
Initialize an SRTP stream from a policy.
srtp_cipher
SRTP encryption transform.
Definition srtp.h:58
int srtp_stream_unprotect(struct srtp_stream *stream, uint8_t *buf, size_t pkt_len, size_t *out_len)
Unprotect a serialized SRTP packet in place (RFC 3711, section-3.3).
#define SRTP_MKI_MAX_LEN
Maximum length of a master key identifier (MKI) in bytes.
Definition srtp.h:50
#define SRTP_MASTER_SALT_LEN
Length of the SRTP master and session salt in bytes (RFC 3711).
Definition srtp.h:40
int srtp_policy_check(const struct srtp_policy *policy)
Validate an SRTP policy.
#define SRTP_AES_256_KEY_LEN
Length of an AES-256 key in bytes.
Definition srtp.h:38
srtp_auth
SRTP authentication transform.
Definition srtp.h:76
int srtp_stream_protect(struct srtp_stream *stream, uint8_t *buf, size_t pkt_len, size_t buf_size, size_t *out_len)
Protect a serialized RTP packet in place (RFC 3711, section-3.3).
int srtp_stream_deinit(struct srtp_stream *stream)
Release an SRTP stream.
@ SRTP_CIPHER_AES_128_GCM
AES-128 in Galois/counter mode (RFC 7714).
Definition srtp.h:67
@ SRTP_CIPHER_AES_256_GCM
AES-256 in Galois/counter mode (RFC 7714); session keys are derived via the AES_256_CM_PRF (RFC 6188)...
Definition srtp.h:72
@ SRTP_CIPHER_AES_128_CM
AES-128 in counter mode (AES-CM, RFC 3711, section-4.1.1).
Definition srtp.h:62
@ SRTP_CIPHER_NULL
No encryption (RFC 3711, section-4.1.3); packets are authenticated only.
Definition srtp.h:60
@ SRTP_AUTH_NULL
No authentication tag.
Definition srtp.h:81
@ SRTP_AUTH_HMAC_SHA1_32
HMAC-SHA1 with a 32-bit (4-byte) tag (RFC 3711, section-4.2).
Definition srtp.h:85
@ SRTP_AUTH_HMAC_SHA1_80
HMAC-SHA1 with an 80-bit (10-byte) tag (RFC 3711, section-4.2).
Definition srtp.h:83
Public kernel APIs.
uint32_t psa_key_id_t
Definition key_ids.h:25
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT64_TYPE__ uint64_t
Definition stdint.h:91
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
Kernel condition variable structure.
Definition kernel.h:3895
Kernel mutex structure.
Definition kernel.h:3762
SRTP stream protection policy.
Definition srtp.h:89
uint32_t kdr
Key derivation rate (RFC 3711, section-4.3.1); 0 to derive session keys once, otherwise a power of tw...
Definition srtp.h:111
size_t master_salt_len
Length of master_salt in bytes.
Definition srtp.h:106
size_t master_key_len
Length of master_key in bytes.
Definition srtp.h:100
enum srtp_cipher cipher
Encryption transform.
Definition srtp.h:91
enum srtp_auth auth
Authentication transform.
Definition srtp.h:93
const uint8_t * mki
Master key identifier (MKI, RFC 3711, section-3.1) appended to every protected packet and matched on ...
Definition srtp.h:119
size_t mki_len
Length of mki in bytes; 0 for no MKI.
Definition srtp.h:121
bool allow_null_auth
Explicit opt-in for SRTP_AUTH_NULL with non-AEAD ciphers.
Definition srtp.h:127
const uint8_t * master_salt
Master salt; SRTP_MASTER_SALT_LEN bytes, or SRTP_AES_GCM_SALT_LEN bytes for the AES-GCM ciphers.
Definition srtp.h:104
const uint8_t * master_key
Master key; SRTP_AES_128_KEY_LEN bytes, or SRTP_AES_256_KEY_LEN bytes for SRTP_CIPHER_AES_256_GCM.
Definition srtp.h:98
SRTP state of an RTP session.
Definition srtp.h:279
SRTP per-SSRC cryptographic context.
Definition srtp.h:145
Macro utilities.