OSDN Git Service

2013.10.24
[uclinux-h8/uClinux-dist.git] / freeswan / pluto / ike_alg.h
1 #ifndef _IKE_ALG_H
2 #define _IKE_ALG_H
3
4 #define IKE_ALG_COMMON \
5         u_int16_t algo_type;            \
6         u_int16_t algo_id;              \
7         struct ike_alg *algo_next
8 struct ike_alg {
9     IKE_ALG_COMMON;
10 };
11 struct encrypt_desc {
12     IKE_ALG_COMMON;
13     size_t enc_ctxsize;
14     size_t enc_blocksize;
15     unsigned keydeflen;
16     unsigned keymaxlen;
17     unsigned keyminlen;
18     void (*do_crypt)(u_int8_t *dat, size_t datasize, u_int8_t *key, size_t key_size, u_int8_t *iv, bool enc);
19 };
20 struct hash_desc {
21     IKE_ALG_COMMON;
22     size_t hash_ctx_size;
23     size_t hash_digest_size;
24     void (*hash_init)(void *ctx);
25     void (*hash_update)(void *ctx, const u_int8_t *in, size_t datasize);
26     void (*hash_final)(u_int8_t *out, void *ctx);
27 };
28 struct db_context * ike_alg_db_new(struct alg_info_ike *ai, lset_t policy);
29 void ike_alg_show_status(void);
30 void ike_alg_show_connection(struct connection *c, const char *instance);
31
32 #define IKE_EALG_FOR_EACH(a) \
33         for(a=ike_alg_base[IKE_ALG_ENCRYPT];a;a=a->algo_next)
34 #define IKE_HALG_FOR_EACH(a) \
35         for(a=ike_alg_base[IKE_ALG_HASH];a;a=a->algo_next)
36 bool ike_alg_enc_present(int ealg);
37 bool ike_alg_hash_present(int halg);
38 bool ike_alg_enc_ok(int ealg, unsigned key_len, struct alg_info_ike *alg_info_ike, const char **);
39
40 int ike_alg_init(void);
41
42 /*      
43  *      This could be just OAKLEY_XXXXXX_ALGORITHM, but it's
44  *      here with other name as a way to assure that the
45  *      algorithm hook type is supported (detected at compile time)
46  */
47 #define IKE_ALG_ENCRYPT 0
48 #define IKE_ALG_HASH    1
49 #define IKE_ALG_MAX     1
50 extern struct ike_alg *ike_alg_base[IKE_ALG_MAX+1];
51 int ike_alg_add(struct ike_alg *);
52 int ike_alg_register_enc(struct encrypt_desc *e);
53 int ike_alg_register_hash(struct hash_desc *a);
54 struct ike_alg *ike_alg_find(unsigned algo_type, unsigned algo_id, unsigned keysize);
55 static __inline__ struct hash_desc *ike_alg_get_hasher(int alg)
56 {
57         return (struct hash_desc *) ike_alg_find(IKE_ALG_HASH, alg, 0);
58 }
59 static __inline__ struct encrypt_desc *ike_alg_get_encrypter(int alg)
60 {
61         return (struct encrypt_desc *) ike_alg_find(IKE_ALG_ENCRYPT, alg, 0);
62 }
63 #endif /* _IKE_ALG_H */