1*f2c2b5e4Spatrick /* $OpenBSD: ipsec.h,v 1.27 2017/11/08 13:33:49 patrick Exp $ */ 214e300e3Sniklas /* $EOM: ipsec.h,v 1.42 2000/12/03 07:58:20 angelos Exp $ */ 32040585eSniklas 42040585eSniklas /* 53635a927Sniklas * Copyright (c) 1998, 1999, 2001 Niklas Hallqvist. All rights reserved. 6bdbf6df3Sniklas * Copyright (c) 1999 Angelos D. Keromytis. All rights reserved. 7b7465804Sho * Copyright (c) 2001 H�kan Olsson. All rights reserved. 82040585eSniklas * 92040585eSniklas * Redistribution and use in source and binary forms, with or without 102040585eSniklas * modification, are permitted provided that the following conditions 112040585eSniklas * are met: 122040585eSniklas * 1. Redistributions of source code must retain the above copyright 132040585eSniklas * notice, this list of conditions and the following disclaimer. 142040585eSniklas * 2. Redistributions in binary form must reproduce the above copyright 152040585eSniklas * notice, this list of conditions and the following disclaimer in the 162040585eSniklas * documentation and/or other materials provided with the distribution. 172040585eSniklas * 182040585eSniklas * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 192040585eSniklas * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 202040585eSniklas * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 212040585eSniklas * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 222040585eSniklas * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 232040585eSniklas * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 242040585eSniklas * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 252040585eSniklas * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 262040585eSniklas * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 272040585eSniklas * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 282040585eSniklas */ 292040585eSniklas 302040585eSniklas /* 312040585eSniklas * This code was written under funding by Ericsson Radio Systems. 322040585eSniklas */ 332040585eSniklas 342040585eSniklas #ifndef _IPSEC_H_ 352040585eSniklas #define _IPSEC_H_ 362040585eSniklas 373635a927Sniklas #include <sys/queue.h> 383635a927Sniklas #include <sys/types.h> 399f110788Sniklas #include <netinet/in.h> 409f110788Sniklas 412040585eSniklas #include "ipsec_doi.h" 423635a927Sniklas #include "isakmp_cfg.h" 432040585eSniklas 442040585eSniklas struct group; 452040585eSniklas struct hash; 462040585eSniklas struct ike_auth; 472040585eSniklas struct message; 482040585eSniklas struct proto; 492040585eSniklas struct sa; 502040585eSniklas 512040585eSniklas /* 5261d575f0Sangelos * IPsec-specific data to be linked into the exchange struct. 533635a927Sniklas * XXX Should probably be several different structs, one for each kind 543635a927Sniklas * of exchange, i.e. phase 1, phase 2 and ISAKMP configuration parameters 553635a927Sniklas * separated. 562040585eSniklas */ 572040585eSniklas struct ipsec_exch { 58c006df14Sniklas u_int flags; 592040585eSniklas struct hash *hash; 602040585eSniklas struct ike_auth *ike_auth; 612040585eSniklas struct group *group; 622040585eSniklas u_int16_t prf_type; 633635a927Sniklas 643635a927Sniklas /* 0 if no KEY_EXCH was proposed, 1 otherwise */ 653635a927Sniklas u_int8_t pfs; 662040585eSniklas 672040585eSniklas /* 6812f43dabShshoexer * A copy of the initiator SA payload body for later computation of 6912f43dabShshoexer * hashes. Phase 1 only. 702040585eSniklas */ 712040585eSniklas size_t sa_i_b_len; 722040585eSniklas u_int8_t *sa_i_b; 732040585eSniklas 742040585eSniklas /* Diffie-Hellman values. */ 752040585eSniklas size_t g_x_len; 76*f2c2b5e4Spatrick size_t g_xy_len; 772040585eSniklas u_int8_t *g_xi; 782040585eSniklas u_int8_t *g_xr; 792040585eSniklas u_int8_t *g_xy; 802040585eSniklas 812040585eSniklas /* SKEYIDs. XXX Phase 1 only? */ 822040585eSniklas size_t skeyid_len; 832040585eSniklas u_int8_t *skeyid; 842040585eSniklas u_int8_t *skeyid_d; 852040585eSniklas u_int8_t *skeyid_a; 862040585eSniklas u_int8_t *skeyid_e; 872040585eSniklas 882040585eSniklas /* HASH_I & HASH_R. XXX Do these need to be saved here? */ 892040585eSniklas u_int8_t *hash_i; 902040585eSniklas u_int8_t *hash_r; 912040585eSniklas 922040585eSniklas /* KEYMAT */ 932040585eSniklas size_t keymat_len; 942b81057dSniklas 952b81057dSniklas /* Phase 2. */ 962b81057dSniklas u_int8_t *id_ci; 972b81057dSniklas size_t id_ci_sz; 982b81057dSniklas u_int8_t *id_cr; 992b81057dSniklas size_t id_cr_sz; 1003635a927Sniklas 1013635a927Sniklas /* ISAKMP configuration mode parameters */ 1023635a927Sniklas u_int16_t cfg_id; 1030fbaac37Sho u_int16_t cfg_type; 1040fbaac37Sho LIST_HEAD(isakmp_cfg_attr_head, isakmp_cfg_attr) attrs; 1052040585eSniklas }; 1062040585eSniklas 107c006df14Sniklas #define IPSEC_EXCH_FLAG_NO_ID 1 108c006df14Sniklas 1092040585eSniklas struct ipsec_sa { 1102040585eSniklas /* Phase 1. */ 1112040585eSniklas u_int8_t hash; 1122040585eSniklas size_t skeyid_len; 1132040585eSniklas u_int8_t *skeyid_d; 1142040585eSniklas u_int8_t *skeyid_a; 1152040585eSniklas u_int16_t prf_type; 1162040585eSniklas 1172040585eSniklas /* Phase 2. */ 1182040585eSniklas u_int16_t group_desc; 1192b81057dSniklas 12033b17ca3Sniklas /* Tunnel parameters. These are in network byte order. */ 121b7465804Sho struct sockaddr *src_net; 122b7465804Sho struct sockaddr *src_mask; 123b7465804Sho struct sockaddr *dst_net; 124b7465804Sho struct sockaddr *dst_mask; 12514e300e3Sniklas u_int8_t tproto; 12614e300e3Sniklas u_int16_t sport; 12714e300e3Sniklas u_int16_t dport; 1282040585eSniklas }; 1292040585eSniklas 1302040585eSniklas struct ipsec_proto { 1312040585eSniklas /* Phase 2. */ 1322040585eSniklas u_int16_t encap_mode; 1332040585eSniklas u_int16_t auth; 1342040585eSniklas u_int16_t keylen; 1352040585eSniklas u_int16_t keyrounds; 1362040585eSniklas 1379f110788Sniklas /* This is not negotiated, but rather configured. */ 1389f110788Sniklas int32_t replay_window; 1399f110788Sniklas 1402040585eSniklas /* KEYMAT */ 1412040585eSniklas u_int8_t *keymat[2]; 1422040585eSniklas }; 1432040585eSniklas 14412f43dabShshoexer extern u_int8_t *ipsec_add_hash_payload(struct message *, size_t); 1452040585eSniklas extern int ipsec_ah_keylength(struct proto *); 1462b81057dSniklas extern u_int8_t *ipsec_build_id(char *, size_t *); 147ad092485Shshoexer extern int ipsec_decode_attribute(u_int16_t, u_int8_t *, u_int16_t, 148ad092485Shshoexer void *); 14912f43dabShshoexer extern void ipsec_decode_transform(struct message *, struct sa *, 1502040585eSniklas struct proto *, u_int8_t *); 1512040585eSniklas extern int ipsec_esp_authkeylength(struct proto *); 1522040585eSniklas extern int ipsec_esp_enckeylength(struct proto *); 15312f43dabShshoexer extern int ipsec_fill_in_hash(struct message *); 1542040585eSniklas extern int ipsec_gen_g_x(struct message *); 15512f43dabShshoexer extern int ipsec_get_id(char *, int *, struct sockaddr **, 156b7465804Sho struct sockaddr **, u_int8_t *, u_int16_t *); 1573f961774Sniklas extern ssize_t ipsec_id_size(char *, u_int8_t *); 15817c23020Sniklas extern char *ipsec_id_string(u_int8_t *, size_t); 1592040585eSniklas extern void ipsec_init(void); 16012f43dabShshoexer extern int ipsec_initial_contact(struct message *); 16112f43dabShshoexer extern int ipsec_is_attribute_incompatible(u_int16_t, u_int8_t *, 16212f43dabShshoexer u_int16_t, void *); 1632040585eSniklas extern int ipsec_keymat_length(struct proto *); 1642040585eSniklas extern int ipsec_save_g_x(struct message *); 165b7465804Sho extern struct sa *ipsec_sa_lookup(struct sockaddr *, u_int32_t, u_int8_t); 1662040585eSniklas 16712f43dabShshoexer extern char *ipsec_decode_ids(char *, u_int8_t *, size_t, u_int8_t *, 16812f43dabShshoexer size_t, int); 169d54b6e99Sniklas extern int ipsec_clone_id(u_int8_t **, size_t *, u_int8_t *, size_t); 170d54b6e99Sniklas 1712040585eSniklas #endif /* _IPSEC_H_ */ 172