86586a7c77668fc66f462ea8423ca2751a1f303c
[strongswan.git] / src / libstrongswan / credentials / keys / shared_key.h
1 /*
2 * Copyright (C) 2007 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 shared_key shared_key
18 * @{ @ingroup keys
19 */
20
21 #ifndef SHARED_KEY_H_
22 #define SHARED_KEY_H_
23
24 #include <utils/enumerator.h>
25 #include <utils/identification.h>
26
27 typedef struct shared_key_t shared_key_t;
28 typedef enum shared_key_type_t shared_key_type_t;
29
30 /**
31 * Type of a shared key.
32 */
33 enum shared_key_type_t {
34 /** wildcard for all keys */
35 SHARED_ANY,
36 /** PSK for IKE authentication */
37 SHARED_IKE,
38 /** key for a EAP authentication method */
39 SHARED_EAP,
40 /** key to decrypt encrypted private keys */
41 SHARED_PRIVATE_KEY_PASS,
42 /** PIN to unlock a smartcard */
43 SHARED_PIN,
44 };
45
46 /**
47 * enum names for shared_key_type_t
48 */
49 extern enum_name_t *shared_key_type_names;
50
51 /**
52 * A symmetric key shared between multiple owners.
53 *
54 * This class is not thread save, do not add owners while others might be
55 * reading.
56 */
57 struct shared_key_t {
58
59 /**
60 * Get the kind of this key.
61 *
62 * @return type of the key
63 */
64 shared_key_type_t (*get_type)(shared_key_t *this);
65
66 /**
67 * Get the shared key data.
68 *
69 * @return chunk pointing to the internal key
70 */
71 chunk_t (*get_key)(shared_key_t *this);
72
73 /**
74 * Increase refcount of the key.
75 *
76 * @return this with an increased refcount
77 */
78 shared_key_t* (*get_ref)(shared_key_t *this);
79
80 /**
81 * Destroy a shared_key instance if all references are gone.
82 */
83 void (*destroy)(shared_key_t *this);
84 };
85
86 #endif /** SHARED_KEY_H_ @} */