8aecd4148a9b00444dbbf1834aba9ed53e0de749
[strongswan.git] / src / pluto / crypto.h
1 /* crypto interfaces
2 * Copyright (C) 1998, 1999 D. Hugh Redelmeier.
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
15 #include <crypto/hashers/hasher.h>
16 #include <crypto/hashers/hasher.h>
17 #include <crypto/prfs/prf.h>
18
19 #include "ike_alg.h"
20
21 extern void init_crypto(void);
22 extern void free_crypto(void);
23
24 /* Oakley group descriptions */
25
26 extern MP_INT groupgenerator; /* MODP group generator (2) */
27
28 struct oakley_group_desc {
29 u_int16_t group;
30 MP_INT *modulus;
31 size_t bytes;
32 };
33
34 extern const struct oakley_group_desc unset_group; /* magic signifier */
35 extern const struct oakley_group_desc *lookup_group(u_int16_t group);
36 #define OAKLEY_GROUP_SIZE 7
37 extern const struct oakley_group_desc oakley_group[OAKLEY_GROUP_SIZE];
38
39 /* unification of cryptographic encoding/decoding algorithms
40 * The IV is taken from and returned to st->st_new_iv.
41 * This allows the old IV to be retained.
42 * Use update_iv to commit to the new IV (for example, once a packet has
43 * been validated).
44 */
45
46 #define MAX_OAKLEY_KEY_LEN0 (3 * DES_CBC_BLOCK_SIZE)
47 #define MAX_OAKLEY_KEY_LEN (256/BITS_PER_BYTE)
48
49 struct state; /* forward declaration, dammit */
50
51 #define update_iv(st) memcpy((st)->st_iv, (st)->st_new_iv \
52 , (st)->st_iv_len = (st)->st_new_iv_len)
53
54 #define set_ph1_iv(st, iv) \
55 passert((st)->st_ph1_iv_len <= sizeof((st)->st_ph1_iv)); \
56 memcpy((st)->st_ph1_iv, (iv), (st)->st_ph1_iv_len);
57
58 /* unification of cryptographic hashing mechanisms */
59
60 extern encryption_algorithm_t oakley_to_encryption_algorithm(int alg);
61 extern hash_algorithm_t oakley_to_hash_algorithm(int alg);
62 extern pseudo_random_function_t oakley_to_prf(int alg);
63