fix bad free
[oweals/gnunet.git] / src / include / gnunet_revocation_service.h
1 /*
2       This file is part of GNUnet
3       Copyright (C) 2013 GNUnet e.V.
4
5       GNUnet is free software: you can redistribute it and/or modify it
6       under the terms of the GNU Affero General Public License as published
7       by the Free Software Foundation, either version 3 of the License,
8       or (at your option) any later version.
9
10       GNUnet is distributed in the hope that it will be useful, but
11       WITHOUT ANY WARRANTY; without even the implied warranty of
12       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13       Affero General Public License for more details.
14      
15       You should have received a copy of the GNU Affero General Public License
16       along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18
19 #ifndef GNUNET_REVOCATION_SERVICE_H_
20 #define GNUNET_REVOCATION_SERVICE_H_
21
22 /**
23  * @author Christian Grothoff
24  *
25  * @file
26  * API to perform and access key revocations
27  *
28  * @defgroup revocation  Revocation service
29  * Perform and access key revocations.
30  *
31  * @see [Documentation](https://gnunet.org/revocation-subsystem)
32  *
33  * @{
34  */
35
36 #ifdef __cplusplus
37 extern "C"
38 {
39 #if 0                           /* keep Emacsens' auto-indent happy */
40 }
41 #endif
42 #endif
43
44 #include "gnunet_util_lib.h"
45
46 /**
47  * Version of the key revocation API.
48  */
49 #define GNUNET_REVOCATION_VERSION 0x00000000
50
51 /**
52  * Handle for the key revocation query.
53  */
54 struct GNUNET_REVOCATION_Query;
55
56 /**
57  * Callback to call with the result of a key revocation query.
58  *
59  * @param cls closure
60  * @param is_valid #GNUNET_NO of the key is/was revoked,
61  *                 #GNUNET_YES if the key is still valid,
62  *                 #GNUNET_SYSERR if we had trouble querying the service
63  *
64  */
65 typedef void (*GNUNET_REVOCATION_Callback) (void *cls,
66                                             int is_valid);
67
68
69 /**
70  * Check if a key was revoked.
71  *
72  * @param cfg the configuration to use
73  * @param key key to check for revocation
74  * @param func funtion to call with the result of the check
75  * @param func_cls closure to pass to @a func
76  * @return handle to use in #GNUNET_REVOCATION_query_cancel to stop REVOCATION from invoking the callback
77  */
78 struct GNUNET_REVOCATION_Query *
79 GNUNET_REVOCATION_query (const struct GNUNET_CONFIGURATION_Handle *cfg,
80                          const struct GNUNET_CRYPTO_EcdsaPublicKey *key,
81                          GNUNET_REVOCATION_Callback func, void *func_cls);
82
83
84 /**
85  * Cancel key revocation check.
86  *
87  * @param q query to cancel
88  */
89 void
90 GNUNET_REVOCATION_query_cancel (struct GNUNET_REVOCATION_Query *q);
91
92
93 /**
94  * Handle for the key revocation operation.
95  */
96 struct GNUNET_REVOCATION_Handle;
97
98
99 /**
100  * Perform key revocation.
101  *
102  * @param cfg the configuration to use
103  * @param key public key of the key to revoke
104  * @param sig signature to use on the revocation (should have been
105  *            created using #GNUNET_REVOCATION_sign_revocation).
106  * @param pow proof of work to use (should have been created by
107  *            iteratively calling #GNUNET_REVOCATION_check_pow)
108  * @param func funtion to call with the result of the check
109  *             (called with `is_valid` being #GNUNET_NO if
110  *              the revocation worked).
111  * @param func_cls closure to pass to @a func
112  * @return handle to use in #GNUNET_REVOCATION_revoke_cancel to stop REVOCATION from invoking the callback
113  */
114 struct GNUNET_REVOCATION_Handle *
115 GNUNET_REVOCATION_revoke (const struct GNUNET_CONFIGURATION_Handle *cfg,
116                           const struct GNUNET_CRYPTO_EcdsaPublicKey *key,
117                           const struct GNUNET_CRYPTO_EcdsaSignature *sig,
118                           uint64_t pow,
119                           GNUNET_REVOCATION_Callback func, void *func_cls);
120
121
122 /**
123  * Cancel key revocation.
124  *
125  * @param h operation to cancel
126  */
127 void
128 GNUNET_REVOCATION_revoke_cancel (struct GNUNET_REVOCATION_Handle *h);
129
130
131 /**
132  * Check if the given proof-of-work value
133  * would be acceptable for revoking the given key.
134  *
135  * @param key key to check for
136  * @param pow proof of work value
137  * @param matching_bits how many bits must match (configuration)
138  * @return #GNUNET_YES if the @a pow is acceptable, #GNUNET_NO if not
139  */
140 int
141 GNUNET_REVOCATION_check_pow (const struct GNUNET_CRYPTO_EcdsaPublicKey *key,
142                              uint64_t pow,
143                              unsigned int matching_bits);
144
145
146 /**
147  * Create a revocation signature.
148  *
149  * @param key private key of the key to revoke
150  * @param sig where to write the revocation signature
151  */
152 void
153 GNUNET_REVOCATION_sign_revocation (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
154                                    struct GNUNET_CRYPTO_EcdsaSignature *sig);
155
156
157 #if 0                           /* keep Emacsens' auto-indent happy */
158 {
159 #endif
160 #ifdef __cplusplus
161 }
162 #endif
163
164 #endif /* GNUNET_REVOCATION_SERVICE_H_ */
165
166 /** @} */ /* end of group revocation */