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