summaryrefslogtreecommitdiffstats
path: root/netwerk/srtp/src/include/ekt.h
blob: b0d888bac98489c5d59cee90cc767cdb62f35079 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/*
 * ekt.h
 *
 * interface to Encrypted Key Transport for SRTP
 *
 * David McGrew
 * Cisco Systems, Inc.
 */
/*
 *	
 * Copyright (c) 2001-2005 Cisco Systems, Inc.
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 
 *   Redistributions of source code must retain the above copyright
 *   notice, this list of conditions and the following disclaimer.
 * 
 *   Redistributions in binary form must reproduce the above
 *   copyright notice, this list of conditions and the following
 *   disclaimer in the documentation and/or other materials provided
 *   with the distribution.
 * 
 *   Neither the name of the Cisco Systems, Inc. nor the names of its
 *   contributors may be used to endorse or promote products derived
 *   from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 * OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */



/*
 * EKT implementation strategy 
 * 
 * use stream_template approach
 *
 * in srtp_unprotect, when a new stream appears, check if template has
 * EKT defined, and if it does, then apply EKT processing 
 *
 * question: will we want to allow key-sharing templates in addition
 * to EKT templates?  could define a new ssrc_type_t that's associated
 * with an EKT, e.g.  ssrc_any_ekt.
 *
 *
 */

#ifndef EKT_H
#define EKT_H

#ifdef __cplusplus
extern "C" {
#endif

#include "srtp_priv.h"

#define EKT_CIPHER_DEFAULT           1
#define EKT_CIPHER_AES_128_ECB       1
#define EKT_CIPHER_AES_192_KEY_WRAP  2
#define EKT_CIPHER_AES_256_KEY_WRAP  3

typedef uint16_t ekt_spi_t;


unsigned
ekt_octets_after_base_tag(ekt_stream_t ekt);

/*
 * an srtp_policy_t structure can contain a pointer to an
 * ekt_policy_t structure
 *
 * this structure holds all of the high level EKT information, and it
 * is passed into libsrtp to indicate what policy should be in effect
 */

typedef struct ekt_policy_ctx_t {
  ekt_spi_t  spi;     /* security parameter index */
  uint8_t    ekt_cipher_type;
  uint8_t   *ekt_key;
  struct ekt_policy_ctx_t *next_ekt_policy;
} ekt_policy_ctx_t;


/*
 * an ekt_data_t structure holds the data corresponding to an ekt key,
 * spi, and so on
 */

typedef struct ekt_data_t {
  ekt_spi_t spi;
  uint8_t ekt_cipher_type;
  aes_expanded_key_t ekt_enc_key;
  aes_expanded_key_t ekt_dec_key;
  struct ekt_data_t *next_ekt_data;
} ekt_data_t;

/*
 * an srtp_stream_ctx_t can contain an ekt_stream_ctx_t
 *
 * an ekt_stream_ctx_t structure holds all of the EKT information for
 * a specific SRTP stream
 */

typedef struct ekt_stream_ctx_t {
  ekt_data_t *data;    
  uint16_t    isn;     /* initial sequence number  */
  uint8_t     encrypted_master_key[SRTP_MAX_KEY_LEN];
} ekt_stream_ctx_t;



err_status_t 
ekt_alloc(ekt_stream_t *stream_data, ekt_policy_t policy);

err_status_t
ekt_stream_init(ekt_stream_t e, 
		ekt_spi_t spi,
		void *ekt_key,
		unsigned ekt_cipher_type);

err_status_t
ekt_stream_init_from_policy(ekt_stream_t e, ekt_policy_t p);
  


err_status_t
srtp_stream_init_from_ekt(srtp_stream_t stream,			  
			  const void *srtcp_hdr,
			  unsigned pkt_octet_len);
		

void
ekt_write_data(ekt_stream_t ekt,
	       uint8_t *base_tag, 
	       unsigned base_tag_len, 
	       int *packet_len,
	       xtd_seq_num_t pkt_index);		

/*
 * We handle EKT by performing some additional steps before
 * authentication (copying the auth tag into a temporary location,
 * zeroizing the "base tag" field in the packet)
 *
 * With EKT, the tag_len parameter is actually the base tag
 * length
 */

err_status_t
ekt_tag_verification_preproces(uint8_t *pkt_tag, 
			       uint8_t *pkt_tag_copy, 
			       unsigned tag_len);

err_status_t
ekt_tag_verification_postproces(uint8_t *pkt_tag,
				uint8_t *pkt_tag_copy,
				unsigned tag_len);


/*
 * @brief EKT pre-processing for srtcp tag generation
 *
 * This function does the pre-processing of the SRTCP authentication
 * tag format.  When EKT is used, it consists of writing the Encrypted
 * Master Key, the SRTP ROC, the Initial Sequence Number, and SPI
 * fields.  The Base Authentication Tag field is set to the all-zero
 * value
 * 
 * When EKT is not used, this function is a no-op.
 * 
 */

err_status_t
srtp_stream_srtcp_auth_tag_generation_preprocess(const srtp_stream_t *s,
						 uint8_t *pkt_tag,
						 unsigned pkt_octet_len);

/* it's not clear that a tag_generation_postprocess function is needed */

err_status_t
srtcp_auth_tag_generation_postprocess(void);


#ifdef __cplusplus
}
#endif

#endif /* EKT_H */