f38af8ff49dddee76b3d94437fe1e22d89a3ba3f
[strongswan.git] / src / libstrongswan / credentials / keys / private_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 private_key private_key
18 * @{ @ingroup keys
19 */
20
21 #ifndef PRIVATE_KEY_H_
22 #define PRIVATE_KEY_H_
23
24 typedef struct private_key_t private_key_t;
25
26 #include <utils/identification.h>
27 #include <credentials/keys/public_key.h>
28
29 /**
30 * Abstract private key interface.
31 */
32 struct private_key_t {
33
34 /**
35 * Get the key type.
36 *
37 * @return type of the key
38 */
39 key_type_t (*get_type)(private_key_t *this);
40
41 /**
42 * Create a signature over a chunk of data.
43 *
44 * @param scheme signature scheme to use
45 * @param data chunk of data to sign
46 * @param signature where to allocate created signature
47 * @return TRUE if signature created
48 */
49 bool (*sign)(private_key_t *this, signature_scheme_t scheme,
50 chunk_t data, chunk_t *signature);
51 /**
52 * Decrypt a chunk of data.
53 *
54 * @param crypto chunk containing encrypted data
55 * @param plain where to allocate decrypted data
56 * @return TRUE if data decrypted and plaintext allocated
57 */
58 bool (*decrypt)(private_key_t *this, chunk_t crypto, chunk_t *plain);
59
60 /**
61 * Get the strength of the key in bytes.
62 *
63 * @return strength of the key in bytes
64 */
65 size_t (*get_keysize) (private_key_t *this);
66
67 /**
68 * Get a unique key identifier, such as a hash over the public key.
69 *
70 * @param type type of the key ID to get
71 * @return unique ID of the key as identification_t, or NULL
72 */
73 identification_t* (*get_id) (private_key_t *this, id_type_t type);
74
75 /**
76 * Get the public part from the private key.
77 *
78 * @return public key
79 */
80 public_key_t* (*get_public_key)(private_key_t *this);
81
82 /**
83 * Check if two private keys are equal.
84 *
85 * @param other other private key
86 * @return TRUE, if equality
87 */
88 bool (*equals) (private_key_t *this, private_key_t *other);
89
90 /**
91 * Check if a private key belongs to a public key.
92 *
93 * @param public public key
94 * @return TRUE, if keys belong together
95 */
96 bool (*belongs_to) (private_key_t *this, public_key_t *public);
97
98 /**
99 * Get an encoded form of the private key.
100 *
101 * @todo Do we need a encoding type specification?
102 *
103 * @return allocated chunk containing encoded private key
104 */
105 chunk_t (*get_encoding)(private_key_t *this);
106
107 /**
108 * Increase the refcount to this private key.
109 *
110 * @return this, with an increased refcount
111 */
112 private_key_t* (*get_ref)(private_key_t *this);
113
114 /**
115 * Decrease refcount, destroy private_key if no more references.
116 */
117 void (*destroy)(private_key_t *this);
118 };
119
120 #endif /** PRIVATE_KEY_H_ @}*/