webkit  2cdf99a9e3038c7e01b3c37e8ad903ecbe5eecf1
https://github.com/WebKit/webkit
sctp_auth.h
Go to the documentation of this file.
1 /*-
2  * Copyright (c) 2001-2008, by Cisco Systems, Inc. All rights reserved.
3  * Copyright (c) 2008-2012, by Randall Stewart. All rights reserved.
4  * Copyright (c) 2008-2012, by Michael Tuexen. 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 are met:
8  *
9  * a) Redistributions of source code must retain the above copyright notice,
10  * this list of conditions and the following disclaimer.
11  *
12  * b) Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in
14  * the documentation and/or other materials provided with the distribution.
15  *
16  * c) Neither the name of Cisco Systems, Inc. nor the names of its
17  * contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
30  * THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #ifdef __FreeBSD__
34 #include <sys/cdefs.h>
35 __FBSDID("$FreeBSD: head/sys/netinet/sctp_auth.h 271673 2014-09-16 14:20:33Z tuexen $");
36 #endif
37 
38 #ifndef _NETINET_SCTP_AUTH_H_
39 #define _NETINET_SCTP_AUTH_H_
40 
41 #include <netinet/sctp_os.h>
42 
43 /* digest lengths */
44 #define SCTP_AUTH_DIGEST_LEN_SHA1 20
45 #define SCTP_AUTH_DIGEST_LEN_SHA256 32
46 #define SCTP_AUTH_DIGEST_LEN_MAX SCTP_AUTH_DIGEST_LEN_SHA256
47 
48 /* random sizes */
49 #define SCTP_AUTH_RANDOM_SIZE_DEFAULT 32
50 #define SCTP_AUTH_RANDOM_SIZE_REQUIRED 32
51 
52 /* union of all supported HMAC algorithm contexts */
53 typedef union sctp_hash_context {
55 #if defined(SCTP_SUPPORT_HMAC_SHA256)
56  SCTP_SHA256_CTX sha256;
57 #endif
59 
60 typedef struct sctp_key {
63 } sctp_key_t;
64 
65 typedef struct sctp_shared_key {
67  sctp_key_t *key; /* key text */
68  uint32_t refcount; /* reference count */
69  uint16_t keyid; /* shared key ID */
70  uint8_t deactivated; /* key is deactivated */
72 
73 LIST_HEAD(sctp_keyhead, sctp_shared_key);
74 
75 /* authentication chunks list */
76 typedef struct sctp_auth_chklist {
77  uint8_t chunks[256];
80 
81 /* hmac algos supported list */
82 typedef struct sctp_hmaclist {
83  uint16_t max_algo; /* max algorithms allocated */
84  uint16_t num_algo; /* num algorithms used */
85  uint16_t hmac[];
87 
88 /* authentication info */
89 typedef struct sctp_authinformation {
90  sctp_key_t *random; /* local random key (concatenated) */
91  uint32_t random_len; /* local random number length for param */
92  sctp_key_t *peer_random;/* peer's random key (concatenated) */
93  sctp_key_t *assoc_key; /* cached concatenated send key */
94  sctp_key_t *recv_key; /* cached concatenated recv key */
95  uint16_t active_keyid; /* active send keyid */
96  uint16_t assoc_keyid; /* current send keyid (cached) */
97  uint16_t recv_keyid; /* last recv keyid (cached) */
99 
100 
101 
102 /*
103  * Macros
104  */
105 #define sctp_auth_is_required_chunk(chunk, list) ((list == NULL) ? (0) : (list->chunks[chunk] != 0))
106 
107 /*
108  * function prototypes
109  */
110 
111 /* socket option api functions */
113 extern void sctp_free_chunklist(sctp_auth_chklist_t *chklist);
114 extern void sctp_clear_chunklist(sctp_auth_chklist_t *chklist);
118 extern size_t sctp_auth_get_chklist_size(const sctp_auth_chklist_t *list);
119 extern int sctp_serialize_auth_chunks(const sctp_auth_chklist_t *list,
120  uint8_t *ptr);
121 extern int sctp_pack_auth_chunks(const sctp_auth_chklist_t *list,
122  uint8_t *ptr);
123 extern int sctp_unpack_auth_chunks(const uint8_t *ptr, uint8_t num_chunks,
124  sctp_auth_chklist_t *list);
125 
126 /* key handling */
127 extern sctp_key_t *sctp_alloc_key(uint32_t keylen);
128 extern void sctp_free_key(sctp_key_t *key);
129 extern void sctp_print_key(sctp_key_t *key, const char *str);
130 extern void sctp_show_key(sctp_key_t *key, const char *str);
132 extern sctp_key_t *sctp_set_key(uint8_t *key, uint32_t keylen);
134  sctp_key_t *shared);
135 
136 /* shared key handling */
138 extern void sctp_free_sharedkey(sctp_sharedkey_t *skey);
139 extern sctp_sharedkey_t *sctp_find_sharedkey(struct sctp_keyhead *shared_keys,
140  uint16_t key_id);
141 extern int sctp_insert_sharedkey(struct sctp_keyhead *shared_keys,
142  sctp_sharedkey_t *new_skey);
143 extern int sctp_copy_skeylist(const struct sctp_keyhead *src,
144  struct sctp_keyhead *dest);
145 /* ref counts on shared keys, by key id */
146 extern void sctp_auth_key_acquire(struct sctp_tcb *stcb, uint16_t keyid);
147 extern void sctp_auth_key_release(struct sctp_tcb *stcb, uint16_t keyid,
148  int so_locked);
149 
150 
151 /* hmac list handling */
152 extern sctp_hmaclist_t *sctp_alloc_hmaclist(uint16_t num_hmacs);
153 extern void sctp_free_hmaclist(sctp_hmaclist_t *list);
154 extern int sctp_auth_add_hmacid(sctp_hmaclist_t *list, uint16_t hmac_id);
158  sctp_hmaclist_t *local);
159 extern int sctp_serialize_hmaclist(sctp_hmaclist_t *list, uint8_t *ptr);
160 extern int sctp_verify_hmac_param(struct sctp_auth_hmac_algo *hmacs,
161  uint32_t num_hmacs);
162 
164 extern void sctp_free_authinfo(sctp_authinfo_t *authinfo);
165 
166 /* keyed-HMAC functions */
167 extern uint32_t sctp_get_auth_chunk_len(uint16_t hmac_algo);
168 extern uint32_t sctp_get_hmac_digest_len(uint16_t hmac_algo);
169 extern uint32_t sctp_hmac(uint16_t hmac_algo, uint8_t *key, uint32_t keylen,
170  uint8_t *text, uint32_t textlen, uint8_t *digest);
171 extern int sctp_verify_hmac(uint16_t hmac_algo, uint8_t *key, uint32_t keylen,
172  uint8_t *text, uint32_t textlen, uint8_t *digest, uint32_t digestlen);
174  uint8_t *text, uint32_t textlen, uint8_t *digest);
176 
177 /* mbuf versions */
178 extern uint32_t sctp_hmac_m(uint16_t hmac_algo, uint8_t *key, uint32_t keylen,
179  struct mbuf *m, uint32_t m_offset, uint8_t *digest, uint32_t trailer);
181  struct mbuf *m, uint32_t m_offset, uint8_t *digest);
182 
183 /*
184  * authentication routines
185  */
186 extern void sctp_clear_cachedkeys(struct sctp_tcb *stcb, uint16_t keyid);
187 extern void sctp_clear_cachedkeys_ep(struct sctp_inpcb *inp, uint16_t keyid);
188 extern int sctp_delete_sharedkey(struct sctp_tcb *stcb, uint16_t keyid);
189 extern int sctp_delete_sharedkey_ep(struct sctp_inpcb *inp, uint16_t keyid);
190 extern int sctp_auth_setactivekey(struct sctp_tcb *stcb, uint16_t keyid);
191 extern int sctp_auth_setactivekey_ep(struct sctp_inpcb *inp, uint16_t keyid);
192 extern int sctp_deact_sharedkey(struct sctp_tcb *stcb, uint16_t keyid);
193 extern int sctp_deact_sharedkey_ep(struct sctp_inpcb *inp, uint16_t keyid);
194 
195 extern void sctp_auth_get_cookie_params(struct sctp_tcb *stcb, struct mbuf *m,
197 extern void sctp_fill_hmac_digest_m(struct mbuf *m, uint32_t auth_offset,
198  struct sctp_auth_chunk *auth, struct sctp_tcb *stcb, uint16_t key_id);
199 extern struct mbuf *sctp_add_auth_chunk(struct mbuf *m, struct mbuf **m_end,
200  struct sctp_auth_chunk **auth_ret, uint32_t *offset,
201  struct sctp_tcb *stcb, uint8_t chunk);
202 extern int sctp_handle_auth(struct sctp_tcb *stcb, struct sctp_auth_chunk *ch,
203  struct mbuf *m, uint32_t offset);
204 extern void sctp_notify_authentication(struct sctp_tcb *stcb,
205  uint32_t indication, uint16_t keyid, uint16_t alt_keyid, int so_locked);
206 extern int sctp_validate_init_auth_params(struct mbuf *m, int offset,
207  int limit);
208 extern void sctp_initialize_auth_params(struct sctp_inpcb *inp,
209  struct sctp_tcb *stcb);
210 
211 /* test functions */
212 #ifdef SCTP_HMAC_TEST
213 extern void sctp_test_hmac_sha1(void);
214 extern void sctp_test_authkey(void);
215 #endif
216 #endif /* __SCTP_AUTH_H__ */
Definition: sctp_header.h:541
int sctp_deact_sharedkey_ep(struct sctp_inpcb *inp, uint16_t keyid)
Definition: sctp_auth.c:1401
sctp_key_t * peer_random
Definition: sctp_auth.h:92
Definition: sctp_auth.h:82
struct sctp_auth_chklist sctp_auth_chklist_t
uint32_t keylen
Definition: sctp_auth.h:61
uint16_t max_algo
Definition: sctp_auth.h:83
uint32_t sctp_hmac(uint16_t hmac_algo, uint8_t *key, uint32_t keylen, uint8_t *text, uint32_t textlen, uint8_t *digest)
Definition: sctp_auth.c:948
Definition: sctp_header.h:546
void sctp_auth_key_release(struct sctp_tcb *stcb, uint16_t keyid, int so_locked)
Definition: sctp_auth.c:568
def chunk(list, chunkSize)
Definition: make-js-file-arrays.py:38
Definition: XMLHttpRequest.idl:39
sctp_auth_chklist_t * sctp_alloc_chunklist(void)
Definition: sctp_auth.c:63
int sctp_serialize_hmaclist(sctp_hmaclist_t *list, uint8_t *ptr)
Definition: sctp_auth.c:768
Definition: sctp_pcb.h:444
unsigned int uint32_t
Definition: ptypes.h:105
#define SCTP_SHA1_CTX
Definition: sctp_os_userspace.h:999
void sctp_auth_key_acquire(struct sctp_tcb *stcb, uint16_t keyid)
Definition: sctp_auth.c:551
SCTP_SHA1_CTX sha1
Definition: sctp_auth.h:54
int sctp_verify_hmac_param(struct sctp_auth_hmac_algo *hmacs, uint32_t num_hmacs)
Definition: sctp_auth.c:785
uint32_t sctp_get_auth_chunk_len(uint16_t hmac_algo)
Definition: sctp_auth.c:834
Definition: sctp_auth.h:53
uint16_t assoc_keyid
Definition: sctp_auth.h:96
sctp_sharedkey_t * sctp_find_sharedkey(struct sctp_keyhead *shared_keys, uint16_t key_id)
Definition: sctp_auth.c:492
void sctp_initialize_auth_params(struct sctp_inpcb *inp, struct sctp_tcb *stcb)
Definition: sctp_auth.c:1978
sctp_key_t * sctp_compute_hashkey(sctp_key_t *key1, sctp_key_t *key2, sctp_key_t *shared)
Definition: sctp_auth.c:405
void sctp_clear_chunklist(sctp_auth_chklist_t *chklist)
Definition: sctp_auth.c:56
dest
Definition: upload.py:394
Definition: auth.py:1
Definition: sctp_auth.h:89
int sctp_validate_init_auth_params(struct mbuf *m, int offset, int limit)
Definition: sctp_auth.c:1843
const GLfloat * m
Definition: gl2ext.h:850
Definition: sctp_auth.h:65
void sctp_clear_cachedkeys_ep(struct sctp_inpcb *inp, uint16_t keyid)
Definition: sctp_auth.c:1234
void sctp_notify_authentication(struct sctp_tcb *stcb, uint32_t indication, uint16_t keyid, uint16_t alt_keyid, int so_locked)
Definition: sctp_auth.c:1776
void sctp_free_key(sctp_key_t *key)
Definition: sctp_auth.c:262
int sctp_deact_sharedkey(struct sctp_tcb *stcb, uint16_t keyid)
Definition: sctp_auth.c:1367
uint16_t keyid
Definition: sctp_auth.h:69
uint16_t num_algo
Definition: sctp_auth.h:84
int sctp_handle_auth(struct sctp_tcb *stcb, struct sctp_auth_chunk *ch, struct mbuf *m, uint32_t offset)
Definition: sctp_auth.c:1656
sctp_key_t * sctp_set_key(uint8_t *key, uint32_t keylen)
Definition: sctp_auth.c:334
struct sctp_authinformation sctp_authinfo_t
void sctp_print_key(sctp_key_t *key, const char *str)
Definition: sctp_auth.c:269
uint32_t refcount
Definition: sctp_auth.h:68
uint16_t recv_keyid
Definition: sctp_auth.h:97
uint32_t sctp_hmac_m(uint16_t hmac_algo, uint8_t *key, uint32_t keylen, struct mbuf *m, uint32_t m_offset, uint8_t *digest, uint32_t trailer)
Definition: sctp_auth.c:1008
struct sctp_key sctp_key_t
EGLStreamKHR EGLint EGLint offset
Definition: eglext.h:984
sctp_hmaclist_t * sctp_alloc_hmaclist(uint16_t num_hmacs)
Definition: sctp_auth.c:639
int sctp_auth_delete_chunk(uint8_t chunk, sctp_auth_chklist_t *list)
Definition: sctp_auth.c:133
void sctp_free_sharedkey(sctp_sharedkey_t *skey)
Definition: sctp_auth.c:479
Definition: interfaces.idl:172
sctp_key_t * random
Definition: sctp_auth.h:90
void sctp_clear_cachedkeys(struct sctp_tcb *stcb, uint16_t keyid)
Definition: sctp_auth.c:1213
void sctp_free_hmaclist(sctp_hmaclist_t *list)
Definition: sctp_auth.c:657
unsigned char uint8_t
Definition: ptypes.h:89
int sctp_delete_sharedkey_ep(struct sctp_inpcb *inp, uint16_t keyid)
Definition: sctp_auth.c:1288
unsigned short uint16_t
Definition: ptypes.h:97
size_t sctp_auth_get_chklist_size(const sctp_auth_chklist_t *list)
Definition: sctp_auth.c:149
int sctp_auth_is_supported_hmac(sctp_hmaclist_t *list, uint16_t id)
Definition: sctp_auth.c:1191
Definition: sctp_auth.h:76
uint16_t sctp_negotiate_hmacid(sctp_hmaclist_t *peer, sctp_hmaclist_t *local)
Definition: sctp_auth.c:741
void sctp_auth_get_cookie_params(struct sctp_tcb *stcb, struct mbuf *m, uint32_t offset, uint32_t length)
Definition: sctp_auth.c:1430
uint32_t sctp_compute_hmac_m(uint16_t hmac_algo, sctp_key_t *key, struct mbuf *m, uint32_t m_offset, uint8_t *digest)
Definition: sctp_auth.c:1159
uint8_t num_chunks
Definition: sctp_auth.h:78
LIST_HEAD(sctp_keyhead, sctp_shared_key)
Definition: sctp_pcb.h:614
Definition: user_mbuf.h:231
sctp_key_t * assoc_key
Definition: sctp_auth.h:93
sctp_hmaclist_t * sctp_default_supported_hmaclist(void)
Definition: sctp_auth.c:717
sctp_key_t * sctp_generate_random_key(uint32_t keylen)
Definition: sctp_auth.c:319
int sctp_verify_hmac(uint16_t hmac_algo, uint8_t *key, uint32_t keylen, uint8_t *text, uint32_t textlen, uint8_t *digest, uint32_t digestlen)
Definition: sctp_auth.c:1091
int sctp_serialize_auth_chunks(const sctp_auth_chklist_t *list, uint8_t *ptr)
Definition: sctp_auth.c:162
str
Definition: make-dist.py:305
uint8_t deactivated
Definition: sctp_auth.h:70
sctp_authinfo_t * sctp_alloc_authinfo(void)
Definition: sctp_auth.c:798
GLenum src
Definition: gl2ext.h:304
uint32_t sctp_compute_hmac(uint16_t hmac_algo, sctp_key_t *key, uint8_t *text, uint32_t textlen, uint8_t *digest)
Definition: sctp_auth.c:1124
void sctp_free_authinfo(sctp_authinfo_t *authinfo)
Definition: sctp_auth.c:814
int sctp_delete_sharedkey(struct sctp_tcb *stcb, uint16_t keyid)
Definition: sctp_auth.c:1254
int sctp_pack_auth_chunks(const sctp_auth_chklist_t *list, uint8_t *ptr)
Definition: sctp_auth.c:179
int sctp_auth_add_chunk(uint8_t chunk, sctp_auth_chklist_t *list)
Definition: sctp_auth.c:107
sctp_hmaclist_t * sctp_copy_hmaclist(sctp_hmaclist_t *list)
Definition: sctp_auth.c:697
int sctp_unpack_auth_chunks(const uint8_t *ptr, uint8_t num_chunks, sctp_auth_chklist_t *list)
Definition: sctp_auth.c:211
union sctp_hash_context sctp_hash_context_t
int sctp_auth_setactivekey_ep(struct sctp_inpcb *inp, uint16_t keyid)
Definition: sctp_auth.c:1348
struct mbuf * sctp_add_auth_chunk(struct mbuf *m, struct mbuf **m_end, struct sctp_auth_chunk **auth_ret, uint32_t *offset, struct sctp_tcb *stcb, uint8_t chunk)
Definition: sctp_output.c:14773
uint32_t random_len
Definition: sctp_auth.h:91
uint32_t sctp_get_hmac_digest_len(uint16_t hmac_algo)
Definition: sctp_auth.c:843
int sctp_copy_skeylist(const struct sctp_keyhead *src, struct sctp_keyhead *dest)
Definition: sctp_auth.c:617
void sctp_show_key(sctp_key_t *key, const char *str)
Definition: sctp_auth.c:288
Definition: sctp_auth.h:60
sctp_sharedkey_t * sctp_alloc_sharedkey(void)
Definition: sctp_auth.c:461
struct sctp_shared_key sctp_sharedkey_t
void sctp_fill_hmac_digest_m(struct mbuf *m, uint32_t auth_offset, struct sctp_auth_chunk *auth, struct sctp_tcb *stcb, uint16_t key_id)
Definition: sctp_auth.c:1567
struct sctp_hmaclist sctp_hmaclist_t
CFArrayRef CFTypeRef key
Definition: AVFoundationCFSoftLinking.h:129
sctp_key_t * recv_key
Definition: sctp_auth.h:94
sctp_key_t * sctp_alloc_key(uint32_t keylen)
Definition: sctp_auth.c:247
#define LIST_ENTRY(type)
Definition: user_queue.h:350
sctp_key_t * key
Definition: sctp_auth.h:67
void sctp_free_chunklist(sctp_auth_chklist_t *chklist)
Definition: sctp_auth.c:78
int sctp_insert_sharedkey(struct sctp_keyhead *shared_keys, sctp_sharedkey_t *new_skey)
Definition: sctp_auth.c:504
GLuint GLsizei GLsizei * length
Definition: gl2.h:435
sctp_auth_chklist_t * sctp_copy_chunklist(sctp_auth_chklist_t *chklist)
Definition: sctp_auth.c:85
int sctp_auth_setactivekey(struct sctp_tcb *stcb, uint16_t keyid)
Definition: sctp_auth.c:1320
int sctp_auth_add_hmacid(sctp_hmaclist_t *list, uint16_t hmac_id)
Definition: sctp_auth.c:666
const uint16_t key1[47]
Definition: auth_driver.c:64
uint16_t active_keyid
Definition: sctp_auth.h:95