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