fix bad free
[oweals/gnunet.git] / src / include / gnunet_abe_lib.h
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2001-2018 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 /**
20  * @file include/gnunet_abe_lib.h
21  * @brief Attribute-Based Encryption primitives for GNUnet
22  *
23  * @author Martin Schanzenbach
24  *
25  * @defgroup abe  ABE Crypto library: Attribute-Based Encryption operations
26  *
27  */
28 #ifndef GNUNET_ABE_LIB_H
29 #define GNUNET_ABE_LIB_H
30
31 #ifdef __cplusplus
32 extern "C"
33 {
34 #if 0                           /* keep Emacsens' auto-indent happy */
35 }
36 #endif
37 #endif
38
39 #include "gnunet_common.h"
40 #include <gcrypt.h>
41
42 /**
43  * @brief type for ABE master keys
44  */
45 struct GNUNET_CRYPTO_AbeMasterKey;
46
47 /**
48  * @brief type for ABE keys
49  */
50 struct GNUNET_CRYPTO_AbeKey;
51
52
53
54 /**
55  * @ingroup abe
56  * Create a new CP-ABE master key. Caller must free return value.
57  *
58  * @return fresh private key; free using #GNUNET_ABE_cpabe_delete_master_key
59  */
60 struct GNUNET_ABE_AbeMasterKey *
61 GNUNET_ABE_cpabe_create_master_key (void);
62
63 /**
64  * @ingroup abe
65  * Delete a CP-ABE master key.
66  *
67  * @param key the master key
68  * @return fresh private key; free using #GNUNET_free
69  */
70 void
71 GNUNET_ABE_cpabe_delete_master_key (struct GNUNET_ABE_AbeMasterKey *key);
72
73 /**
74  * @ingroup abe
75  * Create a new CP-ABE key. Caller must free return value.
76  *
77  * @param key the master key
78  * @param attrs the attributes to append to the key
79  * @return fresh private key; free using #GNUNET_ABE_cpabe_delete_key
80  */
81 struct GNUNET_ABE_AbeKey *
82 GNUNET_ABE_cpabe_create_key (struct GNUNET_ABE_AbeMasterKey *key,
83                                 char **attrs);
84
85 /**
86  * @ingroup abe
87  * Delete a CP-ABE key.
88  *
89  * @param key the key to delete
90  * @param delete_pub GNUNE_YES if the public key should also be freed (bug in gabe)
91  * @return fresh private key; free using #GNUNET_free
92  */
93 void
94 GNUNET_ABE_cpabe_delete_key (struct GNUNET_ABE_AbeKey *key,
95                                 int delete_pub);
96
97
98 /**
99  * @ingroup abe
100  * Encrypt a block using  sessionkey.
101  *
102  * @param block the block to encrypt
103  * @param size the size of the @a block
104  * @param policy the ABE policy
105  * @param key the key used to encrypt
106  * @param result the result buffer. Will be allocated. Free using #GNUNET_free
107  * @return the size of the encrypted block, -1 for errors
108  */
109 ssize_t
110 GNUNET_ABE_cpabe_encrypt (const void *block,
111                              size_t size,
112                              const char *policy,
113                              const struct GNUNET_ABE_AbeMasterKey *key,
114                              void **result);
115
116 /**
117  * @ingroup abe
118  * Decrypt a block using the ABE key.
119  *
120  * @param block the block to encrypt
121  * @param size the size of the @a block
122  * @param key the key used to decrypt
123  * @param result the result buffer. Will be allocated. Free using #GNUNET_free
124  * @return the size of the encrypted block, -1 for errors
125  */
126 ssize_t
127 GNUNET_ABE_cpabe_decrypt (const void *block,
128                              size_t size,
129                              const struct GNUNET_ABE_AbeKey *key,
130                              void **result);
131
132 /**
133  * @ingroup abe
134  * Serialize an ABE key.
135  *
136  * @param key the key to serialize
137  * @param result the result buffer. Will be allocated. Free using #GNUNET_free
138  * @return the size of the encrypted block, -1 for errors
139  */
140 ssize_t
141 GNUNET_ABE_cpabe_serialize_key (const struct GNUNET_ABE_AbeKey *key,
142                                    void **result);
143
144 /**
145  * @ingroup abe
146  * Deserialize a serialized ABE key.
147  *
148  * @param data the data to deserialize
149  * @param len the length of the data.
150  * @return the ABE key. NULL of unsuccessful
151  */
152 struct GNUNET_ABE_AbeKey*
153 GNUNET_ABE_cpabe_deserialize_key (const void *data,
154                                      size_t len);
155
156 /**
157  * @ingroup abe
158  * Serialize an ABE master key.
159  *
160  * @param key the key to serialize
161  * @param result the result buffer. Will be allocated. Free using #GNUNET_free
162  * @return the size of the encrypted block, -1 for errors
163  */
164 ssize_t
165 GNUNET_ABE_cpabe_serialize_master_key (const struct GNUNET_ABE_AbeMasterKey *key,
166                                           void **result);
167
168 /**
169  * @ingroup abe
170  * Deserialize an ABE master key.
171  *
172  * @param data the data to deserialize
173  * @param len the length of the data.
174  * @return the ABE key. NULL of unsuccessful
175  */
176 struct GNUNET_ABE_AbeMasterKey*
177 GNUNET_ABE_cpabe_deserialize_master_key (const void *data,
178                                             size_t len);
179
180
181 #if 0                           /* keep Emacsens' auto-indent happy */
182 {
183 #endif
184 #ifdef __cplusplus
185 }
186 #endif
187
188
189 /* ifndef GNUNET_ABE_LIB_H */
190 #endif
191 /* end of gnunet_abe_lib.h */