blob: 9d7d6b204aed2f9d7b82c67ef4510a0f177211db [file] [log] [blame]
David McGrew79870d62007-06-15 18:17:39 +00001/*
2 * ekt.h
3 *
4 * interface to Encrypted Key Transport for SRTP
5 *
6 * David McGrew
7 * Cisco Systems, Inc.
8 */
9/*
10 *
11 * Copyright (c) 2001-2005 Cisco Systems, Inc.
12 * All rights reserved.
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
16 * are met:
17 *
18 * Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 *
21 * Redistributions in binary form must reproduce the above
22 * copyright notice, this list of conditions and the following
23 * disclaimer in the documentation and/or other materials provided
24 * with the distribution.
25 *
26 * Neither the name of the Cisco Systems, Inc. nor the names of its
27 * contributors may be used to endorse or promote products derived
28 * from this software without specific prior written permission.
29 *
30 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
31 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
32 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
33 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
34 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
35 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
36 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
37 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
40 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
41 * OF THE POSSIBILITY OF SUCH DAMAGE.
42 *
43 */
44
45
46
47/*
48 * EKT implementation strategy
49 *
50 * use stream_template approach
51 *
52 * in srtp_unprotect, when a new stream appears, check if template has
53 * EKT defined, and if it does, then apply EKT processing
54 *
55 * question: will we want to allow key-sharing templates in addition
56 * to EKT templates? could define a new ssrc_type_t that's associated
57 * with an EKT, e.g. ssrc_any_ekt.
58 *
59 *
60 */
61
62#ifndef EKT_H
63#define EKT_H
64
65#ifdef __cplusplus
66extern "C" {
67#endif
68
69#include "srtp_priv.h"
70
jfigusc5887e72014-11-06 09:46:18 -050071#define SRTP_EKT_CIPHER_DEFAULT 1
72#define SRTP_EKT_CIPHER_AES_128_ECB 1
73#define SRTP_EKT_CIPHER_AES_192_KEY_WRAP 2
74#define SRTP_EKT_CIPHER_AES_256_KEY_WRAP 3
David McGrew79870d62007-06-15 18:17:39 +000075
jfigusc5887e72014-11-06 09:46:18 -050076typedef uint16_t srtp_ekt_spi_t;
David McGrew79870d62007-06-15 18:17:39 +000077
78
jfigusc5887e72014-11-06 09:46:18 -050079unsigned srtp_ekt_octets_after_base_tag(srtp_ekt_stream_t ekt);
David McGrew79870d62007-06-15 18:17:39 +000080
81/*
82 * an srtp_policy_t structure can contain a pointer to an
jfigusc5887e72014-11-06 09:46:18 -050083 * srtp_ekt_policy_t structure
David McGrew79870d62007-06-15 18:17:39 +000084 *
85 * this structure holds all of the high level EKT information, and it
86 * is passed into libsrtp to indicate what policy should be in effect
87 */
88
jfigusc5887e72014-11-06 09:46:18 -050089typedef struct srtp_ekt_policy_ctx_t {
90 srtp_ekt_spi_t spi; /* security parameter index */
David McGrew79870d62007-06-15 18:17:39 +000091 uint8_t ekt_cipher_type;
92 uint8_t *ekt_key;
jfigusc5887e72014-11-06 09:46:18 -050093 struct srtp_ekt_policy_ctx_t *next_ekt_policy;
94} srtp_ekt_policy_ctx_t;
David McGrew79870d62007-06-15 18:17:39 +000095
96
97/*
jfigusc5887e72014-11-06 09:46:18 -050098 * an srtp_ekt_data_t structure holds the data corresponding to an ekt key,
David McGrew79870d62007-06-15 18:17:39 +000099 * spi, and so on
100 */
101
jfigusc5887e72014-11-06 09:46:18 -0500102typedef struct srtp_ekt_data_t {
103 srtp_ekt_spi_t spi;
David McGrew79870d62007-06-15 18:17:39 +0000104 uint8_t ekt_cipher_type;
jfigus5a2b2d02014-11-19 14:34:20 -0500105 srtp_aes_expanded_key_t ekt_enc_key;
106 srtp_aes_expanded_key_t ekt_dec_key;
David McGrew79870d62007-06-15 18:17:39 +0000107 struct ekt_data_t *next_ekt_data;
jfigusc5887e72014-11-06 09:46:18 -0500108} srtp_ekt_data_t;
David McGrew79870d62007-06-15 18:17:39 +0000109
110/*
jfigusc5887e72014-11-06 09:46:18 -0500111 * an srtp_stream_ctx_t can contain an srtp_ekt_stream_ctx_t
David McGrew79870d62007-06-15 18:17:39 +0000112 *
jfigusc5887e72014-11-06 09:46:18 -0500113 * an srtp_ekt_stream_ctx_t structure holds all of the EKT information for
David McGrew79870d62007-06-15 18:17:39 +0000114 * a specific SRTP stream
115 */
116
jfigusc5887e72014-11-06 09:46:18 -0500117typedef struct srtp_ekt_stream_ctx_t {
118 srtp_ekt_data_t *data;
119 uint16_t isn; /* initial sequence number */
120 uint8_t encrypted_master_key[SRTP_MAX_KEY_LEN];
121} srtp_ekt_stream_ctx_t;
David McGrew79870d62007-06-15 18:17:39 +0000122
123
124
jfigusc5887e72014-11-06 09:46:18 -0500125srtp_err_status_t srtp_ekt_alloc(srtp_ekt_stream_t *stream_data, srtp_ekt_policy_t policy);
David McGrew79870d62007-06-15 18:17:39 +0000126
jfigusc5887e72014-11-06 09:46:18 -0500127srtp_err_status_t srtp_ekt_stream_init(srtp_ekt_stream_t e, srtp_ekt_spi_t spi, void *ekt_key, unsigned ekt_cipher_type);
David McGrew79870d62007-06-15 18:17:39 +0000128
jfigusc5887e72014-11-06 09:46:18 -0500129srtp_err_status_t srtp_ekt_stream_init_from_policy(srtp_ekt_stream_t e, srtp_ekt_policy_t p);
David McGrew79870d62007-06-15 18:17:39 +0000130
131
132
jfigus857009c2014-11-05 11:17:43 -0500133srtp_err_status_t srtp_stream_init_from_ekt(srtp_stream_t stream, const void *srtcp_hdr, unsigned pkt_octet_len);
David McGrew79870d62007-06-15 18:17:39 +0000134
135
jfigusde8deb32014-11-25 12:58:11 -0500136void srtp_ekt_write_data(srtp_ekt_stream_t ekt, uint8_t *base_tag, unsigned base_tag_len, int *packet_len, srtp_xtd_seq_num_t pkt_index);
David McGrew79870d62007-06-15 18:17:39 +0000137
138/*
139 * We handle EKT by performing some additional steps before
140 * authentication (copying the auth tag into a temporary location,
141 * zeroizing the "base tag" field in the packet)
142 *
143 * With EKT, the tag_len parameter is actually the base tag
144 * length
145 */
jfigusc5887e72014-11-06 09:46:18 -0500146srtp_err_status_t srtp_ekt_tag_verification_preproces(uint8_t *pkt_tag, uint8_t *pkt_tag_copy, unsigned tag_len);
David McGrew79870d62007-06-15 18:17:39 +0000147
jfigusc5887e72014-11-06 09:46:18 -0500148srtp_err_status_t srtp_ekt_tag_verification_postproces(uint8_t *pkt_tag, uint8_t *pkt_tag_copy, unsigned tag_len);
David McGrew79870d62007-06-15 18:17:39 +0000149
150
151/*
152 * @brief EKT pre-processing for srtcp tag generation
153 *
154 * This function does the pre-processing of the SRTCP authentication
155 * tag format. When EKT is used, it consists of writing the Encrypted
156 * Master Key, the SRTP ROC, the Initial Sequence Number, and SPI
157 * fields. The Base Authentication Tag field is set to the all-zero
158 * value
159 *
160 * When EKT is not used, this function is a no-op.
161 *
162 */
jfigus857009c2014-11-05 11:17:43 -0500163srtp_err_status_t srtp_stream_srtcp_auth_tag_generation_preprocess(const srtp_stream_t *s, uint8_t *pkt_tag, unsigned pkt_octet_len);
David McGrew79870d62007-06-15 18:17:39 +0000164
165/* it's not clear that a tag_generation_postprocess function is needed */
jfigus857009c2014-11-05 11:17:43 -0500166srtp_err_status_t srtcp_auth_tag_generation_postprocess(void);
David McGrew79870d62007-06-15 18:17:39 +0000167
168
169#ifdef __cplusplus
170}
171#endif
172
173#endif /* EKT_H */