summaryrefslogtreecommitdiff
path: root/src/pluto/alg_info.h
blob: cacc2a354b27da4e3b6b13e0391bc43d73acb966 (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
/* Algorithm info parsing and creation functions
 * Author: JuanJo Ciarlante <jjo-ipsec@mendoza.gov.ar>
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or (at your
 * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.
 *
 * RCSID $Id: alg_info.h 3252 2007-10-06 21:24:50Z andreas $
 */

#ifndef ALG_INFO_H
#define ALG_INFO_H

struct esp_info {
	u_int8_t transid;	/* ESP transform */
	u_int16_t auth;		/* AUTH */
	size_t enckeylen;	/* keylength for ESP transform */
	size_t authkeylen;	/* keylength for AUTH */
	u_int8_t encryptalg;	/* normally  encryptalg=transid */
	u_int8_t authalg;	/* normally  authalg=auth+1 */
};

struct ike_info {
	u_int16_t ike_ealg;	/* high 16 bit nums for reserved */
	u_int8_t ike_halg;
	size_t ike_eklen;
	size_t ike_hklen;
	u_int16_t ike_modp;
};

#define ALG_INFO_COMMON \
	int alg_info_cnt;		\
	int ref_cnt;			\
	unsigned alg_info_flags;	\
	unsigned alg_info_protoid

struct alg_info {
	ALG_INFO_COMMON;
};

struct alg_info_esp {
	ALG_INFO_COMMON;
	struct esp_info esp[64];
	int esp_pfsgroup;
};

struct alg_info_ike {
	ALG_INFO_COMMON;
	struct ike_info ike[64];
};
#define esp_ealg_id transid
#define esp_aalg_id auth
#define esp_ealg_keylen enckeylen	/* bits */
#define esp_aalg_keylen authkeylen	/* bits */

/*	alg_info_flags bits */
#define ALG_INFO_F_STRICT	0x01

extern int alg_info_esp_aa2sadb(int auth);
extern int alg_info_esp_sadb2aa(int sadb_aalg);
extern void alg_info_free(struct alg_info *alg_info);
extern void alg_info_addref(struct alg_info *alg_info);
extern void alg_info_delref(struct alg_info **alg_info);
extern struct alg_info_esp* alg_info_esp_create_from_str(const char *alg_str
    , const char **err_p);
extern struct alg_info_ike* alg_info_ike_create_from_str(const char *alg_str
    , const char **err_p);
extern int alg_info_parse(const char *str);
extern int alg_info_snprint(char *buf, int buflen
    , struct alg_info *alg_info);
extern int alg_info_snprint_esp(char *buf, int buflen
    , struct alg_info_esp *alg_info);
extern int alg_info_snprint_ike(char *buf, int buflen
    , struct alg_info_ike *alg_info);
#define ALG_INFO_ESP_FOREACH(ai, ai_esp, i) \
	for (i=(ai)->alg_info_cnt,ai_esp=(ai)->esp; i--; ai_esp++) 
#define ALG_INFO_IKE_FOREACH(ai, ai_ike, i) \
	for (i=(ai)->alg_info_cnt,ai_ike=(ai)->ike; i--; ai_ike++) 
#endif /* ALG_INFO_H */