OLD | NEW |
(Empty) | |
| 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 PURPOS
E |
| 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 235828 2012-05-23 11:26:28Z tue
xen $"); |
| 36 #endif |
| 37 |
| 38 #ifndef _NETINET_SCTP_AUTH_H_ |
| 39 #define _NETINET_SCTP_AUTH_H_ |
| 40 |
| 41 #ifdef SCTP_USE_NSS_SHA1 |
| 42 #include <netinet/sctp_nss_sha1.h> |
| 43 #endif |
| 44 |
| 45 /* digest lengths */ |
| 46 #define SCTP_AUTH_DIGEST_LEN_SHA1 20 |
| 47 #define SCTP_AUTH_DIGEST_LEN_SHA224 28 |
| 48 #define SCTP_AUTH_DIGEST_LEN_SHA256 32 |
| 49 #define SCTP_AUTH_DIGEST_LEN_SHA384 48 |
| 50 #define SCTP_AUTH_DIGEST_LEN_SHA512 64 |
| 51 #define SCTP_AUTH_DIGEST_LEN_MAX 64 |
| 52 |
| 53 /* random sizes */ |
| 54 #define SCTP_AUTH_RANDOM_SIZE_DEFAULT 32 |
| 55 #define SCTP_AUTH_RANDOM_SIZE_REQUIRED 32 |
| 56 #define SCTP_AUTH_RANDOM_SIZE_MAX 256 |
| 57 |
| 58 /* union of all supported HMAC algorithm contexts */ |
| 59 typedef union sctp_hash_context { |
| 60 SHA1_CTX sha1; |
| 61 #ifdef HAVE_SHA2 |
| 62 SHA256_CTX sha256; |
| 63 SHA384_CTX sha384; |
| 64 SHA512_CTX sha512; |
| 65 #endif |
| 66 } sctp_hash_context_t; |
| 67 |
| 68 typedef struct sctp_key { |
| 69 uint32_t keylen; |
| 70 uint8_t key[]; |
| 71 } sctp_key_t; |
| 72 |
| 73 typedef struct sctp_shared_key { |
| 74 LIST_ENTRY(sctp_shared_key) next; |
| 75 sctp_key_t *key; /* key text */ |
| 76 uint32_t refcount; /* reference count */ |
| 77 uint16_t keyid; /* shared key ID */ |
| 78 uint8_t deactivated; /* key is deactivated */ |
| 79 } sctp_sharedkey_t; |
| 80 |
| 81 LIST_HEAD(sctp_keyhead, sctp_shared_key); |
| 82 |
| 83 /* authentication chunks list */ |
| 84 typedef struct sctp_auth_chklist { |
| 85 uint8_t chunks[256]; |
| 86 uint8_t num_chunks; |
| 87 } sctp_auth_chklist_t; |
| 88 |
| 89 /* hmac algos supported list */ |
| 90 typedef struct sctp_hmaclist { |
| 91 uint16_t max_algo; /* max algorithms allocated */ |
| 92 uint16_t num_algo; /* num algorithms used */ |
| 93 uint16_t hmac[]; |
| 94 } sctp_hmaclist_t; |
| 95 |
| 96 /* authentication info */ |
| 97 typedef struct sctp_authinformation { |
| 98 sctp_key_t *random; /* local random key (concatenated) */ |
| 99 uint32_t random_len; /* local random number length for param */ |
| 100 sctp_key_t *peer_random;/* peer's random key (concatenated) */ |
| 101 sctp_key_t *assoc_key; /* cached concatenated send key */ |
| 102 sctp_key_t *recv_key; /* cached concatenated recv key */ |
| 103 uint16_t active_keyid; /* active send keyid */ |
| 104 uint16_t assoc_keyid; /* current send keyid (cached) */ |
| 105 uint16_t recv_keyid; /* last recv keyid (cached) */ |
| 106 } sctp_authinfo_t; |
| 107 |
| 108 |
| 109 |
| 110 /* |
| 111 * Macros |
| 112 */ |
| 113 #define sctp_auth_is_required_chunk(chunk, list) ((list == NULL) ? (0) : (list->
chunks[chunk] != 0)) |
| 114 |
| 115 /* |
| 116 * function prototypes |
| 117 */ |
| 118 |
| 119 /* socket option api functions */ |
| 120 extern sctp_auth_chklist_t *sctp_alloc_chunklist(void); |
| 121 extern void sctp_free_chunklist(sctp_auth_chklist_t *chklist); |
| 122 extern void sctp_clear_chunklist(sctp_auth_chklist_t *chklist); |
| 123 extern sctp_auth_chklist_t *sctp_copy_chunklist(sctp_auth_chklist_t *chklist); |
| 124 extern int sctp_auth_add_chunk(uint8_t chunk, sctp_auth_chklist_t *list); |
| 125 extern int sctp_auth_delete_chunk(uint8_t chunk, sctp_auth_chklist_t *list); |
| 126 extern size_t sctp_auth_get_chklist_size(const sctp_auth_chklist_t *list); |
| 127 extern void sctp_auth_set_default_chunks(sctp_auth_chklist_t *list); |
| 128 extern int sctp_serialize_auth_chunks(const sctp_auth_chklist_t *list, |
| 129 uint8_t *ptr); |
| 130 extern int sctp_pack_auth_chunks(const sctp_auth_chklist_t *list, |
| 131 uint8_t *ptr); |
| 132 extern int sctp_unpack_auth_chunks(const uint8_t *ptr, uint8_t num_chunks, |
| 133 sctp_auth_chklist_t *list); |
| 134 |
| 135 /* key handling */ |
| 136 extern sctp_key_t *sctp_alloc_key(uint32_t keylen); |
| 137 extern void sctp_free_key(sctp_key_t *key); |
| 138 extern void sctp_print_key(sctp_key_t *key, const char *str); |
| 139 extern void sctp_show_key(sctp_key_t *key, const char *str); |
| 140 extern sctp_key_t *sctp_generate_random_key(uint32_t keylen); |
| 141 extern sctp_key_t *sctp_set_key(uint8_t *key, uint32_t keylen); |
| 142 extern sctp_key_t *sctp_compute_hashkey(sctp_key_t *key1, sctp_key_t *key2, |
| 143 sctp_key_t *shared); |
| 144 |
| 145 /* shared key handling */ |
| 146 extern sctp_sharedkey_t *sctp_alloc_sharedkey(void); |
| 147 extern void sctp_free_sharedkey(sctp_sharedkey_t *skey); |
| 148 extern sctp_sharedkey_t *sctp_find_sharedkey(struct sctp_keyhead *shared_keys, |
| 149 uint16_t key_id); |
| 150 extern int sctp_insert_sharedkey(struct sctp_keyhead *shared_keys, |
| 151 sctp_sharedkey_t *new_skey); |
| 152 extern int sctp_copy_skeylist(const struct sctp_keyhead *src, |
| 153 struct sctp_keyhead *dest); |
| 154 /* ref counts on shared keys, by key id */ |
| 155 extern void sctp_auth_key_acquire(struct sctp_tcb *stcb, uint16_t keyid); |
| 156 extern void sctp_auth_key_release(struct sctp_tcb *stcb, uint16_t keyid, |
| 157 int so_locked); |
| 158 |
| 159 |
| 160 /* hmac list handling */ |
| 161 extern sctp_hmaclist_t *sctp_alloc_hmaclist(uint8_t num_hmacs); |
| 162 extern void sctp_free_hmaclist(sctp_hmaclist_t *list); |
| 163 extern int sctp_auth_add_hmacid(sctp_hmaclist_t *list, uint16_t hmac_id); |
| 164 extern sctp_hmaclist_t *sctp_copy_hmaclist(sctp_hmaclist_t *list); |
| 165 extern sctp_hmaclist_t *sctp_default_supported_hmaclist(void); |
| 166 extern uint16_t sctp_negotiate_hmacid(sctp_hmaclist_t *peer, |
| 167 sctp_hmaclist_t *local); |
| 168 extern int sctp_serialize_hmaclist(sctp_hmaclist_t *list, uint8_t *ptr); |
| 169 extern int sctp_verify_hmac_param(struct sctp_auth_hmac_algo *hmacs, |
| 170 uint32_t num_hmacs); |
| 171 |
| 172 extern sctp_authinfo_t *sctp_alloc_authinfo(void); |
| 173 extern void sctp_free_authinfo(sctp_authinfo_t *authinfo); |
| 174 |
| 175 /* keyed-HMAC functions */ |
| 176 extern uint32_t sctp_get_auth_chunk_len(uint16_t hmac_algo); |
| 177 extern uint32_t sctp_get_hmac_digest_len(uint16_t hmac_algo); |
| 178 extern uint32_t sctp_hmac(uint16_t hmac_algo, uint8_t *key, uint32_t keylen, |
| 179 uint8_t *text, uint32_t textlen, uint8_t *digest); |
| 180 extern int sctp_verify_hmac(uint16_t hmac_algo, uint8_t *key, uint32_t keylen, |
| 181 uint8_t *text, uint32_t textlen, uint8_t *digest, uint32_t digestlen); |
| 182 extern uint32_t sctp_compute_hmac(uint16_t hmac_algo, sctp_key_t *key, |
| 183 uint8_t *text, uint32_t textlen, uint8_t *digest); |
| 184 extern int sctp_auth_is_supported_hmac(sctp_hmaclist_t *list, uint16_t id); |
| 185 |
| 186 /* mbuf versions */ |
| 187 extern uint32_t sctp_hmac_m(uint16_t hmac_algo, uint8_t *key, uint32_t keylen, |
| 188 struct mbuf *m, uint32_t m_offset, uint8_t *digest, uint32_t trailer); |
| 189 extern uint32_t sctp_compute_hmac_m(uint16_t hmac_algo, sctp_key_t *key, |
| 190 struct mbuf *m, uint32_t m_offset, uint8_t *digest); |
| 191 |
| 192 /* |
| 193 * authentication routines |
| 194 */ |
| 195 extern void sctp_clear_cachedkeys(struct sctp_tcb *stcb, uint16_t keyid); |
| 196 extern void sctp_clear_cachedkeys_ep(struct sctp_inpcb *inp, uint16_t keyid); |
| 197 extern int sctp_delete_sharedkey(struct sctp_tcb *stcb, uint16_t keyid); |
| 198 extern int sctp_delete_sharedkey_ep(struct sctp_inpcb *inp, uint16_t keyid); |
| 199 extern int sctp_auth_setactivekey(struct sctp_tcb *stcb, uint16_t keyid); |
| 200 extern int sctp_auth_setactivekey_ep(struct sctp_inpcb *inp, uint16_t keyid); |
| 201 extern int sctp_deact_sharedkey(struct sctp_tcb *stcb, uint16_t keyid); |
| 202 extern int sctp_deact_sharedkey_ep(struct sctp_inpcb *inp, uint16_t keyid); |
| 203 |
| 204 extern void sctp_auth_get_cookie_params(struct sctp_tcb *stcb, struct mbuf *m, |
| 205 uint32_t offset, uint32_t length); |
| 206 extern void sctp_fill_hmac_digest_m(struct mbuf *m, uint32_t auth_offset, |
| 207 struct sctp_auth_chunk *auth, struct sctp_tcb *stcb, uint16_t key_id); |
| 208 extern struct mbuf *sctp_add_auth_chunk(struct mbuf *m, struct mbuf **m_end, |
| 209 struct sctp_auth_chunk **auth_ret, uint32_t *offset, |
| 210 struct sctp_tcb *stcb, uint8_t chunk); |
| 211 extern int sctp_handle_auth(struct sctp_tcb *stcb, struct sctp_auth_chunk *ch, |
| 212 struct mbuf *m, uint32_t offset); |
| 213 extern void sctp_notify_authentication(struct sctp_tcb *stcb, |
| 214 uint32_t indication, uint16_t keyid, uint16_t alt_keyid, int so_locked); |
| 215 extern int sctp_validate_init_auth_params(struct mbuf *m, int offset, |
| 216 int limit); |
| 217 extern void sctp_initialize_auth_params(struct sctp_inpcb *inp, |
| 218 struct sctp_tcb *stcb); |
| 219 |
| 220 /* test functions */ |
| 221 #ifdef SCTP_HMAC_TEST |
| 222 extern void sctp_test_hmac_sha1(void); |
| 223 extern void sctp_test_authkey(void); |
| 224 #endif |
| 225 #endif /* __SCTP_AUTH_H__ */ |
OLD | NEW |