900c6613e9fb8a2ddb74d5d46ad7a635ad21624b
[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 <collections/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 /** Calculated NT Hash = MD4(UTF-16LE(password)) */
45 SHARED_NT_HASH,
46 };
47
48 /**
49 * enum names for shared_key_type_t
50 */
51 extern enum_name_t *shared_key_type_names;
52
53 /**
54 * A symmetric key shared between multiple owners.
55 *
56 * This class is not thread save, do not add owners while others might be
57 * reading.
58 */
59 struct shared_key_t {
60
61 /**
62 * Get the kind of this key.
63 *
64 * @return type of the key
65 */
66 shared_key_type_t (*get_type)(shared_key_t *this);
67
68 /**
69 * Get the shared key data.
70 *
71 * @return chunk pointing to the internal key
72 */
73 chunk_t (*get_key)(shared_key_t *this);
74
75 /**
76 * Increase refcount of the key.
77 *
78 * @return this with an increased refcount
79 */
80 shared_key_t* (*get_ref)(shared_key_t *this);
81
82 /**
83 * Destroy a shared_key instance if all references are gone.
84 */
85 void (*destroy)(shared_key_t *this);
86 };
87
88 /**
89 * A simple private key implementation
90 *
91 * @param type type of the shared key
92 * @param key key data, gets owned by instance
93 * @return simple shared key instance
94 */
95 shared_key_t *shared_key_create(shared_key_type_t type, chunk_t key);
96
97 #endif /** SHARED_KEY_H_ @} */