4a551a8f5a17dbe458c19c75a1bb4ee67fc57835
[strongswan.git] / src / libcharon / sa / keymat.h
1 /*
2 * Copyright (C) 2008 Martin Willi
3 * Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 /**
17 * @defgroup keymat keymat
18 * @{ @ingroup sa
19 */
20
21 #ifndef KEYMAT_H_
22 #define KEYMAT_H_
23
24 typedef struct keymat_t keymat_t;
25
26 #include <library.h>
27 #include <utils/identification.h>
28 #include <crypto/prfs/prf.h>
29 #include <crypto/aead.h>
30 #include <config/proposal.h>
31 #include <config/peer_cfg.h>
32 #include <sa/ike_sa_id.h>
33
34 /**
35 * Derivation an management of sensitive keying material.
36 */
37 struct keymat_t {
38
39 /**
40 * Create a diffie hellman object for key agreement.
41 *
42 * The diffie hellman is either for IKE negotiation/rekeying or
43 * CHILD_SA rekeying (using PFS). The resulting DH object must be passed
44 * to derive_keys or to derive_child_keys and destroyed after use
45 *
46 * @param group diffie hellman group
47 * @return DH object, NULL if group not supported
48 */
49 diffie_hellman_t* (*create_dh)(keymat_t *this,
50 diffie_hellman_group_t group);
51
52 /*
53 * Get a AEAD transform to en-/decrypt and sign/verify IKE messages.
54 *
55 * @param in TRUE for inbound (decrypt), FALSE for outbound (encrypt)
56 * @return crypter
57 */
58 aead_t* (*get_aead)(keymat_t *this, bool in);
59
60 /**
61 * Destroy a keymat_t.
62 */
63 void (*destroy)(keymat_t *this);
64 };
65
66 /**
67 * Create the appropriate keymat_t implementation based on the IKE version.
68 *
69 * @param version requested IKE version
70 * @param initiator TRUE if we are initiator
71 * @return keymat_t implmenetation
72 */
73 keymat_t *keymat_create(ike_version_t version, bool initiator);
74
75 /**
76 * Look up the key length of an encryption algorithm.
77 *
78 * @param alg algorithm to get key length for
79 * @return key length in bits
80 */
81 int keymat_get_keylen_encr(encryption_algorithm_t alg);
82
83 /**
84 * Look up the key length of an integrity algorithm.
85 *
86 * @param alg algorithm to get key length for
87 * @return key length in bits
88 */
89 int keymat_get_keylen_integ(integrity_algorithm_t alg);
90
91 #endif /** KEYMAT_H_ @}*/