Add a return value to simaka_message_t.generate()
[strongswan.git] / src / libsimaka / simaka_crypto.h
1 /*
2 * Copyright (C) 2009 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 simaka_crypto simaka_crypto
18 * @{ @ingroup libsimaka
19 */
20
21 #ifndef SIMAKA_CRYPTO_H_
22 #define SIMAKA_CRYPTO_H_
23
24 #include <library.h>
25
26 typedef struct simaka_crypto_t simaka_crypto_t;
27
28 /**
29 * EAP-SIM/AKA crypto helper and key derivation class.
30 */
31 struct simaka_crypto_t {
32
33 /**
34 * Get the signer to use for AT_MAC calculation/verification.
35 *
36 * @return signer reference, NULL if no keys have been derived
37 */
38 signer_t* (*get_signer)(simaka_crypto_t *this);
39
40 /**
41 * Get the signer to use for AT_ENCR_DATA encryption/decryption.
42 *
43 * @return crypter reference, NULL if no keys have been derived
44 */
45 crypter_t* (*get_crypter)(simaka_crypto_t *this);
46
47 /**
48 * Get the random number generator.
49 *
50 * @return rng reference
51 */
52 rng_t* (*get_rng)(simaka_crypto_t *this);
53
54 /**
55 * Derive keys after full authentication.
56 *
57 * This methods derives the k_encr/k_auth keys and loads them into the
58 * internal crypter/signer instances. The passed data is method specific:
59 * For EAP-SIM, it is "n*Kc|NONCE_MT|Version List|Selected Version", for
60 * EAP-AKA it is "IK|CK".
61 *
62 * @param id peer identity
63 * @param data method specific data
64 * @param mk chunk receiving allocated master key MK
65 * @return allocated MSK value
66 */
67 chunk_t (*derive_keys_full)(simaka_crypto_t *this, identification_t *id,
68 chunk_t data, chunk_t *mk);
69
70 /**
71 * Derive k_encr/k_auth keys from MK using fast reauthentication.
72 *
73 * This methods derives the k_encr/k_auth keys and loads them into the
74 * internal crypter/signer instances.
75 *
76 * @param mk master key
77 */
78 void (*derive_keys_reauth)(simaka_crypto_t *this, chunk_t mk);
79
80 /**
81 * Derive MSK using fast reauthentication.
82 *
83 * @param id fast reauthentication identity
84 * @param counter fast reauthentication counter value, network order
85 * @param nonce_s server generated NONCE_S value
86 * @param mk master key of last full authentication
87 */
88 chunk_t (*derive_keys_reauth_msk)(simaka_crypto_t *this,
89 identification_t *id, chunk_t counter,
90 chunk_t nonce_s, chunk_t mk);
91
92 /**
93 * Clear keys (partially) derived.
94 */
95 void (*clear_keys)(simaka_crypto_t *this);
96
97 /**
98 * Destroy a simaka_crypto_t.
99 */
100 void (*destroy)(simaka_crypto_t *this);
101 };
102
103 /**
104 * Create a simaka_crypto instance.
105 *
106 * @return EAP-SIM/AKA crypto instance, NULL if algorithms missing
107 */
108 simaka_crypto_t *simaka_crypto_create();
109
110 #endif /** SIMAKA_CRYPTO_H_ @}*/