SHA512-HMAC bug fix and hash function self-test support
[strongswan.git] / src / pluto / ike_alg.h
1 /* IKE modular algorithm handling interface
2 * Author: JuanJo Ciarlante <jjo-ipsec@mendoza.gov.ar>
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * for more details.
13 *
14 * RCSID $Id: ike_alg.h,v 1.3 2004/09/16 23:22:22 as Exp $
15 */
16
17 #ifndef _IKE_ALG_H
18 #define _IKE_ALG_H
19
20 #include "connections.h"
21
22 struct ike_alg {
23 u_int16_t algo_type;
24 u_int16_t algo_id;
25 struct ike_alg *algo_next;
26 };
27
28 struct encrypt_desc {
29 u_int16_t algo_type;
30 u_int16_t algo_id;
31 struct ike_alg *algo_next;
32
33 size_t enc_ctxsize;
34 size_t enc_blocksize;
35 u_int keydeflen;
36 u_int keymaxlen;
37 u_int keyminlen;
38 void (*do_crypt)(u_int8_t *dat, size_t datasize, u_int8_t *key, size_t key_size, u_int8_t *iv, bool enc);
39 };
40
41 typedef struct hash_testvector hash_testvector_t;
42
43 struct hash_testvector {
44 const size_t msg_size;
45 const u_char *msg;
46 const u_char *msg_digest;
47 };
48
49 typedef struct hmac_testvector hmac_testvector_t;
50
51 struct hmac_testvector {
52 const size_t key_size;
53 const u_char *key;
54 const size_t msg_size;
55 const u_char *msg;
56 const u_char *hmac;
57 };
58 struct hash_desc {
59 u_int16_t algo_type;
60 u_int16_t algo_id;
61 struct ike_alg *algo_next;
62
63 size_t hash_ctx_size;
64 size_t hash_block_size;
65 size_t hash_digest_size;
66 const hash_testvector_t *hash_testvectors;
67 const hmac_testvector_t *hmac_testvectors;
68 void (*hash_init)(void *ctx);
69 void (*hash_update)(void *ctx, const u_int8_t *in, size_t datasize);
70 void (*hash_final)(u_int8_t *out, void *ctx);
71 };
72
73 #define IKE_ALG_ENCRYPT 0
74 #define IKE_ALG_HASH 1
75 #define IKE_ALG_MAX IKE_ALG_HASH
76
77 extern int ike_alg_add(struct ike_alg *a);
78 extern struct hash_desc *ike_alg_get_hasher(u_int alg);
79 extern struct encrypt_desc *ike_alg_get_encrypter(u_int alg);
80 extern bool ike_alg_enc_present(u_int ealg);
81 extern bool ike_alg_hash_present(u_int halg);
82 extern int ike_alg_register_hash(struct hash_desc *a);
83 extern int ike_alg_register_enc(struct encrypt_desc *e);
84 extern const struct oakley_group_desc* ike_alg_pfsgroup(struct connection *c
85 , lset_t policy);
86 extern struct db_context * ike_alg_db_new(struct alg_info_ike *ai, lset_t policy);
87 extern void ike_alg_list(void);
88 extern void ike_alg_show_connection(struct connection *c, const char *instance);
89 extern bool ik_alg_test(void);
90 extern bool ike_alg_ok_final(u_int ealg, u_int key_len, u_int aalg, u_int group
91 , struct alg_info_ike *alg_info_ike);
92 extern int ike_alg_init(void);
93
94 #endif /* _IKE_ALG_H */