diff options
Diffstat (limited to 'src/abe/abe.c')
-rw-r--r-- | src/abe/abe.c | 327 |
1 files changed, 164 insertions, 163 deletions
diff --git a/src/abe/abe.c b/src/abe/abe.c index 091ba0ced..31c6e04e0 100644 --- a/src/abe/abe.c +++ b/src/abe/abe.c | |||
@@ -11,13 +11,13 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 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/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | 19 | ||
20 | */ | 20 | */ |
21 | 21 | ||
22 | /** | 22 | /** |
23 | * @file abe/abe.c | 23 | * @file abe/abe.c |
@@ -33,55 +33,53 @@ | |||
33 | #include "gnunet_crypto_lib.h" | 33 | #include "gnunet_crypto_lib.h" |
34 | #include "gnunet_abe_lib.h" | 34 | #include "gnunet_abe_lib.h" |
35 | 35 | ||
36 | struct GNUNET_ABE_AbeMasterKey | 36 | struct GNUNET_ABE_AbeMasterKey { |
37 | { | ||
38 | gabe_pub_t* pub; | 37 | gabe_pub_t* pub; |
39 | gabe_msk_t* msk; | 38 | gabe_msk_t* msk; |
40 | }; | 39 | }; |
41 | 40 | ||
42 | struct GNUNET_ABE_AbeKey | 41 | struct GNUNET_ABE_AbeKey { |
43 | { | ||
44 | gabe_pub_t* pub; | 42 | gabe_pub_t* pub; |
45 | gabe_prv_t* prv; | 43 | gabe_prv_t* prv; |
46 | }; | 44 | }; |
47 | 45 | ||
48 | static int | 46 | static int |
49 | init_aes( element_t k, int enc, | 47 | init_aes(element_t k, int enc, |
50 | gcry_cipher_hd_t* handle, | 48 | gcry_cipher_hd_t* handle, |
51 | struct GNUNET_CRYPTO_SymmetricSessionKey *key, | 49 | struct GNUNET_CRYPTO_SymmetricSessionKey *key, |
52 | unsigned char* iv) | 50 | unsigned char* iv) |
53 | { | 51 | { |
54 | int rc; | 52 | int rc; |
55 | int key_len; | 53 | int key_len; |
56 | unsigned char* key_buf; | 54 | unsigned char* key_buf; |
57 | 55 | ||
58 | key_len = element_length_in_bytes(k) < 33 ? 3 : element_length_in_bytes(k); | 56 | key_len = element_length_in_bytes(k) < 33 ? 3 : element_length_in_bytes(k); |
59 | key_buf = (unsigned char*) malloc(key_len); | 57 | key_buf = (unsigned char*)malloc(key_len); |
60 | element_to_bytes(key_buf, k); | 58 | element_to_bytes(key_buf, k); |
61 | 59 | ||
62 | GNUNET_memcpy (key->aes_key, key_buf, GNUNET_CRYPTO_AES_KEY_LENGTH); | 60 | GNUNET_memcpy(key->aes_key, key_buf, GNUNET_CRYPTO_AES_KEY_LENGTH); |
63 | GNUNET_assert (0 == | 61 | GNUNET_assert(0 == |
64 | gcry_cipher_open (handle, GCRY_CIPHER_AES256, | 62 | gcry_cipher_open(handle, GCRY_CIPHER_AES256, |
65 | GCRY_CIPHER_MODE_CFB, 0)); | 63 | GCRY_CIPHER_MODE_CFB, 0)); |
66 | rc = gcry_cipher_setkey (*handle, | 64 | rc = gcry_cipher_setkey(*handle, |
67 | key->aes_key, | 65 | key->aes_key, |
68 | sizeof (key->aes_key)); | 66 | sizeof(key->aes_key)); |
69 | GNUNET_assert ((0 == rc) || ((char) rc == GPG_ERR_WEAK_KEY)); | 67 | GNUNET_assert((0 == rc) || ((char)rc == GPG_ERR_WEAK_KEY)); |
70 | memset (iv, 0, 16); //TODO make reasonable | 68 | memset(iv, 0, 16); //TODO make reasonable |
71 | rc = gcry_cipher_setiv (*handle, | 69 | rc = gcry_cipher_setiv(*handle, |
72 | iv, | 70 | iv, |
73 | 16); | 71 | 16); |
74 | GNUNET_assert ((0 == rc) || ((char) rc == GPG_ERR_WEAK_KEY)); | 72 | GNUNET_assert((0 == rc) || ((char)rc == GPG_ERR_WEAK_KEY)); |
75 | 73 | ||
76 | free(key_buf); | 74 | free(key_buf); |
77 | return rc; | 75 | return rc; |
78 | } | 76 | } |
79 | 77 | ||
80 | static int | 78 | static int |
81 | aes_128_cbc_encrypt( char* pt, | 79 | aes_128_cbc_encrypt(char* pt, |
82 | int size, | 80 | int size, |
83 | element_t k, | 81 | element_t k, |
84 | char **ct ) | 82 | char **ct) |
85 | { | 83 | { |
86 | gcry_cipher_hd_t handle; | 84 | gcry_cipher_hd_t handle; |
87 | struct GNUNET_CRYPTO_SymmetricSessionKey skey; | 85 | struct GNUNET_CRYPTO_SymmetricSessionKey skey; |
@@ -90,34 +88,35 @@ aes_128_cbc_encrypt( char* pt, | |||
90 | int padding; | 88 | int padding; |
91 | int buf_size; | 89 | int buf_size; |
92 | uint8_t len[4]; | 90 | uint8_t len[4]; |
91 | |||
93 | init_aes(k, 1, &handle, &skey, iv); | 92 | init_aes(k, 1, &handle, &skey, iv); |
94 | 93 | ||
95 | /* TODO make less crufty */ | 94 | /* TODO make less crufty */ |
96 | 95 | ||
97 | /* stuff in real length (big endian) before padding */ | 96 | /* stuff in real length (big endian) before padding */ |
98 | len[0] = (size & 0xff000000)>>24; | 97 | len[0] = (size & 0xff000000) >> 24; |
99 | len[1] = (size & 0xff0000)>>16; | 98 | len[1] = (size & 0xff0000) >> 16; |
100 | len[2] = (size & 0xff00)>>8; | 99 | len[2] = (size & 0xff00) >> 8; |
101 | len[3] = (size & 0xff)>>0; | 100 | len[3] = (size & 0xff) >> 0; |
102 | padding = 16 - ((4+size) % 16); | 101 | padding = 16 - ((4 + size) % 16); |
103 | buf_size = 4 + size + padding; | 102 | buf_size = 4 + size + padding; |
104 | buf = GNUNET_malloc (buf_size); | 103 | buf = GNUNET_malloc(buf_size); |
105 | GNUNET_memcpy (buf, len, 4); | 104 | GNUNET_memcpy(buf, len, 4); |
106 | GNUNET_memcpy (buf+4, pt, size); | 105 | GNUNET_memcpy(buf + 4, pt, size); |
107 | *ct = GNUNET_malloc (buf_size); | 106 | *ct = GNUNET_malloc(buf_size); |
108 | 107 | ||
109 | GNUNET_assert (0 == gcry_cipher_encrypt (handle, *ct, buf_size, buf, buf_size)); | 108 | GNUNET_assert(0 == gcry_cipher_encrypt(handle, *ct, buf_size, buf, buf_size)); |
110 | gcry_cipher_close (handle); | 109 | gcry_cipher_close(handle); |
111 | //AES_cbc_encrypt(pt->data, ct->data, pt->len, &key, iv, AES_ENCRYPT); | 110 | //AES_cbc_encrypt(pt->data, ct->data, pt->len, &key, iv, AES_ENCRYPT); |
112 | GNUNET_free (buf); | 111 | GNUNET_free(buf); |
113 | return buf_size; | 112 | return buf_size; |
114 | } | 113 | } |
115 | 114 | ||
116 | static int | 115 | static int |
117 | aes_128_cbc_decrypt( char* ct, | 116 | aes_128_cbc_decrypt(char* ct, |
118 | int size, | 117 | int size, |
119 | element_t k, | 118 | element_t k, |
120 | char **pt ) | 119 | char **pt) |
121 | { | 120 | { |
122 | struct GNUNET_CRYPTO_SymmetricSessionKey skey; | 121 | struct GNUNET_CRYPTO_SymmetricSessionKey skey; |
123 | gcry_cipher_hd_t handle; | 122 | gcry_cipher_hd_t handle; |
@@ -127,22 +126,22 @@ aes_128_cbc_decrypt( char* ct, | |||
127 | 126 | ||
128 | init_aes(k, 1, &handle, &skey, iv); | 127 | init_aes(k, 1, &handle, &skey, iv); |
129 | 128 | ||
130 | tmp = GNUNET_malloc (size); | 129 | tmp = GNUNET_malloc(size); |
131 | 130 | ||
132 | //AES_cbc_encrypt(ct->data, pt->data, ct->len, &key, iv, AES_DECRYPT); | 131 | //AES_cbc_encrypt(ct->data, pt->data, ct->len, &key, iv, AES_DECRYPT); |
133 | GNUNET_assert (0 == gcry_cipher_decrypt (handle, tmp, size, ct, size)); | 132 | GNUNET_assert(0 == gcry_cipher_decrypt(handle, tmp, size, ct, size)); |
134 | gcry_cipher_close (handle); | 133 | gcry_cipher_close(handle); |
135 | /* TODO make less crufty */ | 134 | /* TODO make less crufty */ |
136 | 135 | ||
137 | /* get real length */ | 136 | /* get real length */ |
138 | len = 0; | 137 | len = 0; |
139 | len = len | 138 | len = len |
140 | | ((tmp[0])<<24) | ((tmp[1])<<16) | 139 | | ((tmp[0]) << 24) | ((tmp[1]) << 16) |
141 | | ((tmp[2])<<8) | ((tmp[3])<<0); | 140 | | ((tmp[2]) << 8) | ((tmp[3]) << 0); |
142 | /* truncate any garbage from the padding */ | 141 | /* truncate any garbage from the padding */ |
143 | *pt = GNUNET_malloc (len); | 142 | *pt = GNUNET_malloc(len); |
144 | GNUNET_memcpy (*pt, tmp+4, len); | 143 | GNUNET_memcpy(*pt, tmp + 4, len); |
145 | GNUNET_free (tmp); | 144 | GNUNET_free(tmp); |
146 | return len; | 145 | return len; |
147 | } | 146 | } |
148 | 147 | ||
@@ -153,13 +152,14 @@ aes_128_cbc_decrypt( char* ct, | |||
153 | * @return fresh private key; free using #GNUNET_ABE_cpabe_delete_master_key | 152 | * @return fresh private key; free using #GNUNET_ABE_cpabe_delete_master_key |
154 | */ | 153 | */ |
155 | struct GNUNET_ABE_AbeMasterKey* | 154 | struct GNUNET_ABE_AbeMasterKey* |
156 | GNUNET_ABE_cpabe_create_master_key (void) | 155 | GNUNET_ABE_cpabe_create_master_key(void) |
157 | { | 156 | { |
158 | struct GNUNET_ABE_AbeMasterKey* key; | 157 | struct GNUNET_ABE_AbeMasterKey* key; |
159 | key = GNUNET_new (struct GNUNET_ABE_AbeMasterKey); | 158 | |
159 | key = GNUNET_new(struct GNUNET_ABE_AbeMasterKey); | ||
160 | gabe_setup(&key->pub, &key->msk); | 160 | gabe_setup(&key->pub, &key->msk); |
161 | GNUNET_assert (NULL != key->pub); | 161 | GNUNET_assert(NULL != key->pub); |
162 | GNUNET_assert (NULL != key->msk); | 162 | GNUNET_assert(NULL != key->msk); |
163 | return key; | 163 | return key; |
164 | } | 164 | } |
165 | 165 | ||
@@ -171,13 +171,13 @@ GNUNET_ABE_cpabe_create_master_key (void) | |||
171 | * @return fresh private key; free using #GNUNET_free | 171 | * @return fresh private key; free using #GNUNET_free |
172 | */ | 172 | */ |
173 | void | 173 | void |
174 | GNUNET_ABE_cpabe_delete_master_key (struct GNUNET_ABE_AbeMasterKey *key) | 174 | GNUNET_ABE_cpabe_delete_master_key(struct GNUNET_ABE_AbeMasterKey *key) |
175 | { | 175 | { |
176 | gabe_msk_free (key->msk); | 176 | gabe_msk_free(key->msk); |
177 | gabe_pub_free (key->pub); | 177 | gabe_pub_free(key->pub); |
178 | //GNUNET_free (key->msk); | 178 | //GNUNET_free (key->msk); |
179 | //gabe_msk_free (key->msk); //For some reason free of pub implicit? | 179 | //gabe_msk_free (key->msk); //For some reason free of pub implicit? |
180 | GNUNET_free (key); | 180 | GNUNET_free(key); |
181 | } | 181 | } |
182 | 182 | ||
183 | /** | 183 | /** |
@@ -189,19 +189,19 @@ GNUNET_ABE_cpabe_delete_master_key (struct GNUNET_ABE_AbeMasterKey *key) | |||
189 | * @return fresh private key; free using #GNUNET_ABE_cpabe_delete_key | 189 | * @return fresh private key; free using #GNUNET_ABE_cpabe_delete_key |
190 | */ | 190 | */ |
191 | struct GNUNET_ABE_AbeKey* | 191 | struct GNUNET_ABE_AbeKey* |
192 | GNUNET_ABE_cpabe_create_key (struct GNUNET_ABE_AbeMasterKey *key, | 192 | GNUNET_ABE_cpabe_create_key(struct GNUNET_ABE_AbeMasterKey *key, |
193 | char **attrs) | 193 | char **attrs) |
194 | { | 194 | { |
195 | struct GNUNET_ABE_AbeKey *prv_key; | 195 | struct GNUNET_ABE_AbeKey *prv_key; |
196 | int size; | 196 | int size; |
197 | char *tmp; | 197 | char *tmp; |
198 | 198 | ||
199 | prv_key = GNUNET_new (struct GNUNET_ABE_AbeKey); | 199 | prv_key = GNUNET_new(struct GNUNET_ABE_AbeKey); |
200 | prv_key->prv = gabe_keygen(key->pub, key->msk, attrs); | 200 | prv_key->prv = gabe_keygen(key->pub, key->msk, attrs); |
201 | size = gabe_pub_serialize(key->pub, &tmp); | 201 | size = gabe_pub_serialize(key->pub, &tmp); |
202 | prv_key->pub = gabe_pub_unserialize(tmp, size); | 202 | prv_key->pub = gabe_pub_unserialize(tmp, size); |
203 | GNUNET_free (tmp); | 203 | GNUNET_free(tmp); |
204 | GNUNET_assert (NULL != prv_key->prv); | 204 | GNUNET_assert(NULL != prv_key->prv); |
205 | return prv_key; | 205 | return prv_key; |
206 | } | 206 | } |
207 | 207 | ||
@@ -214,50 +214,50 @@ GNUNET_ABE_cpabe_create_key (struct GNUNET_ABE_AbeMasterKey *key, | |||
214 | * @return fresh private key; free using #GNUNET_free | 214 | * @return fresh private key; free using #GNUNET_free |
215 | */ | 215 | */ |
216 | void | 216 | void |
217 | GNUNET_ABE_cpabe_delete_key (struct GNUNET_ABE_AbeKey *key, | 217 | GNUNET_ABE_cpabe_delete_key(struct GNUNET_ABE_AbeKey *key, |
218 | int delete_pub) | 218 | int delete_pub) |
219 | { | 219 | { |
220 | //Memory management in gabe is buggy | 220 | //Memory management in gabe is buggy |
221 | gabe_prv_free (key->prv); | 221 | gabe_prv_free(key->prv); |
222 | if (GNUNET_YES == delete_pub) | 222 | if (GNUNET_YES == delete_pub) |
223 | gabe_pub_free (key->pub); | 223 | gabe_pub_free(key->pub); |
224 | GNUNET_free (key); | 224 | GNUNET_free(key); |
225 | } | 225 | } |
226 | 226 | ||
227 | static ssize_t | 227 | static ssize_t |
228 | write_cpabe (void **result, | 228 | write_cpabe(void **result, |
229 | uint32_t file_len, | 229 | uint32_t file_len, |
230 | char* cph_buf, | 230 | char* cph_buf, |
231 | int cph_buf_len, | 231 | int cph_buf_len, |
232 | char* aes_buf, | 232 | char* aes_buf, |
233 | int aes_buf_len) | 233 | int aes_buf_len) |
234 | { | 234 | { |
235 | char *ptr; | 235 | char *ptr; |
236 | uint32_t *len; | 236 | uint32_t *len; |
237 | 237 | ||
238 | *result = GNUNET_malloc (12 + cph_buf_len + aes_buf_len); | 238 | *result = GNUNET_malloc(12 + cph_buf_len + aes_buf_len); |
239 | ptr = *result; | 239 | ptr = *result; |
240 | len = (uint32_t*) ptr; | 240 | len = (uint32_t*)ptr; |
241 | *len = htonl (file_len); | 241 | *len = htonl(file_len); |
242 | ptr += 4; | 242 | ptr += 4; |
243 | len = (uint32_t*) ptr; | 243 | len = (uint32_t*)ptr; |
244 | *len = htonl (aes_buf_len); | 244 | *len = htonl(aes_buf_len); |
245 | ptr += 4; | 245 | ptr += 4; |
246 | GNUNET_memcpy (ptr, aes_buf, aes_buf_len); | 246 | GNUNET_memcpy(ptr, aes_buf, aes_buf_len); |
247 | ptr += aes_buf_len; | 247 | ptr += aes_buf_len; |
248 | len = (uint32_t*) ptr; | 248 | len = (uint32_t*)ptr; |
249 | *len = htonl (cph_buf_len); | 249 | *len = htonl(cph_buf_len); |
250 | ptr += 4; | 250 | ptr += 4; |
251 | GNUNET_memcpy (ptr, cph_buf, cph_buf_len); | 251 | GNUNET_memcpy(ptr, cph_buf, cph_buf_len); |
252 | return 12 + cph_buf_len + aes_buf_len; | 252 | return 12 + cph_buf_len + aes_buf_len; |
253 | } | 253 | } |
254 | 254 | ||
255 | static ssize_t | 255 | static ssize_t |
256 | read_cpabe (const void *data, | 256 | read_cpabe(const void *data, |
257 | char** cph_buf, | 257 | char** cph_buf, |
258 | int *cph_buf_len, | 258 | int *cph_buf_len, |
259 | char** aes_buf, | 259 | char** aes_buf, |
260 | int *aes_buf_len) | 260 | int *aes_buf_len) |
261 | { | 261 | { |
262 | int buf_len; | 262 | int buf_len; |
263 | char *ptr; | 263 | char *ptr; |
@@ -265,18 +265,18 @@ read_cpabe (const void *data, | |||
265 | 265 | ||
266 | ptr = (char*)data; | 266 | ptr = (char*)data; |
267 | len = (uint32_t*)ptr; | 267 | len = (uint32_t*)ptr; |
268 | buf_len = ntohl (*len); | 268 | buf_len = ntohl(*len); |
269 | ptr += 4; | 269 | ptr += 4; |
270 | len = (uint32_t*)ptr; | 270 | len = (uint32_t*)ptr; |
271 | *aes_buf_len = ntohl (*len); | 271 | *aes_buf_len = ntohl(*len); |
272 | ptr += 4; | 272 | ptr += 4; |
273 | *aes_buf = GNUNET_malloc (*aes_buf_len); | 273 | *aes_buf = GNUNET_malloc(*aes_buf_len); |
274 | GNUNET_memcpy(*aes_buf, ptr, *aes_buf_len); | 274 | GNUNET_memcpy(*aes_buf, ptr, *aes_buf_len); |
275 | ptr += *aes_buf_len; | 275 | ptr += *aes_buf_len; |
276 | len = (uint32_t*)ptr; | 276 | len = (uint32_t*)ptr; |
277 | *cph_buf_len = ntohl (*len); | 277 | *cph_buf_len = ntohl(*len); |
278 | ptr += 4; | 278 | ptr += 4; |
279 | *cph_buf = GNUNET_malloc (*cph_buf_len); | 279 | *cph_buf = GNUNET_malloc(*cph_buf_len); |
280 | GNUNET_memcpy(*cph_buf, ptr, *cph_buf_len); | 280 | GNUNET_memcpy(*cph_buf, ptr, *cph_buf_len); |
281 | 281 | ||
282 | return buf_len; | 282 | return buf_len; |
@@ -294,11 +294,11 @@ read_cpabe (const void *data, | |||
294 | * @return the size of the encrypted block, -1 for errors | 294 | * @return the size of the encrypted block, -1 for errors |
295 | */ | 295 | */ |
296 | ssize_t | 296 | ssize_t |
297 | GNUNET_ABE_cpabe_encrypt (const void *block, | 297 | GNUNET_ABE_cpabe_encrypt(const void *block, |
298 | size_t size, | 298 | size_t size, |
299 | const char *policy, | 299 | const char *policy, |
300 | const struct GNUNET_ABE_AbeMasterKey *key, | 300 | const struct GNUNET_ABE_AbeMasterKey *key, |
301 | void **result) | 301 | void **result) |
302 | { | 302 | { |
303 | gabe_cph_t* cph; | 303 | gabe_cph_t* cph; |
304 | char* plt; | 304 | char* plt; |
@@ -309,15 +309,15 @@ GNUNET_ABE_cpabe_encrypt (const void *block, | |||
309 | int aes_buf_len; | 309 | int aes_buf_len; |
310 | ssize_t result_len; | 310 | ssize_t result_len; |
311 | 311 | ||
312 | if( !(cph = gabe_enc(key->pub, m, (char*)policy)) ) | 312 | if (!(cph = gabe_enc(key->pub, m, (char*)policy))) |
313 | return GNUNET_SYSERR; | 313 | return GNUNET_SYSERR; |
314 | cph_buf_len = gabe_cph_serialize(cph, | 314 | cph_buf_len = gabe_cph_serialize(cph, |
315 | &cph_buf); | 315 | &cph_buf); |
316 | gabe_cph_free(cph); | 316 | gabe_cph_free(cph); |
317 | GNUNET_free (cph); | 317 | GNUNET_free(cph); |
318 | plt = GNUNET_memdup (block, size); | 318 | plt = GNUNET_memdup(block, size); |
319 | aes_buf_len = aes_128_cbc_encrypt(plt, size, m, &aes_buf); | 319 | aes_buf_len = aes_128_cbc_encrypt(plt, size, m, &aes_buf); |
320 | GNUNET_free (plt); | 320 | GNUNET_free(plt); |
321 | element_clear(m); | 321 | element_clear(m); |
322 | result_len = write_cpabe(result, size, cph_buf, cph_buf_len, aes_buf, aes_buf_len); | 322 | result_len = write_cpabe(result, size, cph_buf, cph_buf_len, aes_buf, aes_buf_len); |
323 | GNUNET_free(cph_buf); | 323 | GNUNET_free(cph_buf); |
@@ -336,10 +336,10 @@ GNUNET_ABE_cpabe_encrypt (const void *block, | |||
336 | * @return the size of the encrypted block, -1 for errors | 336 | * @return the size of the encrypted block, -1 for errors |
337 | */ | 337 | */ |
338 | ssize_t | 338 | ssize_t |
339 | GNUNET_ABE_cpabe_decrypt (const void *block, | 339 | GNUNET_ABE_cpabe_decrypt(const void *block, |
340 | size_t size, | 340 | size_t size, |
341 | const struct GNUNET_ABE_AbeKey *key, | 341 | const struct GNUNET_ABE_AbeKey *key, |
342 | void **result) | 342 | void **result) |
343 | { | 343 | { |
344 | char* aes_buf; | 344 | char* aes_buf; |
345 | char* cph_buf; | 345 | char* cph_buf; |
@@ -351,22 +351,23 @@ GNUNET_ABE_cpabe_decrypt (const void *block, | |||
351 | 351 | ||
352 | read_cpabe(block, &cph_buf, &cph_buf_size, &aes_buf, &aes_buf_size); | 352 | read_cpabe(block, &cph_buf, &cph_buf_size, &aes_buf, &aes_buf_size); |
353 | cph = gabe_cph_unserialize(key->pub, cph_buf, cph_buf_size); | 353 | cph = gabe_cph_unserialize(key->pub, cph_buf, cph_buf_size); |
354 | if( !gabe_dec(key->pub, key->prv, cph, m) ) { | 354 | if (!gabe_dec(key->pub, key->prv, cph, m)) |
355 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 355 | { |
356 | "%s\n", gabe_error()); | 356 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
357 | GNUNET_free (aes_buf); | 357 | "%s\n", gabe_error()); |
358 | GNUNET_free (cph_buf); | 358 | GNUNET_free(aes_buf); |
359 | gabe_cph_free(cph); | 359 | GNUNET_free(cph_buf); |
360 | GNUNET_free (cph); | 360 | gabe_cph_free(cph); |
361 | element_clear (m); | 361 | GNUNET_free(cph); |
362 | return GNUNET_SYSERR; | 362 | element_clear(m); |
363 | } | 363 | return GNUNET_SYSERR; |
364 | } | ||
364 | gabe_cph_free(cph); | 365 | gabe_cph_free(cph); |
365 | GNUNET_free (cph); | 366 | GNUNET_free(cph); |
366 | plt_len = aes_128_cbc_decrypt(aes_buf, aes_buf_size, m, (char**)result); | 367 | plt_len = aes_128_cbc_decrypt(aes_buf, aes_buf_size, m, (char**)result); |
367 | GNUNET_free (cph_buf); | 368 | GNUNET_free(cph_buf); |
368 | GNUNET_free (aes_buf); | 369 | GNUNET_free(aes_buf); |
369 | element_clear (m); | 370 | element_clear(m); |
370 | //freeing is buggy in gabe | 371 | //freeing is buggy in gabe |
371 | //gabe_prv_free (prv); | 372 | //gabe_prv_free (prv); |
372 | //gabe_pub_free (pub); | 373 | //gabe_pub_free (pub); |
@@ -382,8 +383,8 @@ GNUNET_ABE_cpabe_decrypt (const void *block, | |||
382 | * @return the size of the encrypted block, -1 for errors | 383 | * @return the size of the encrypted block, -1 for errors |
383 | */ | 384 | */ |
384 | ssize_t | 385 | ssize_t |
385 | GNUNET_ABE_cpabe_serialize_key (const struct GNUNET_ABE_AbeKey *key, | 386 | GNUNET_ABE_cpabe_serialize_key(const struct GNUNET_ABE_AbeKey *key, |
386 | void **result) | 387 | void **result) |
387 | { | 388 | { |
388 | ssize_t len; | 389 | ssize_t len; |
389 | char *pub; | 390 | char *pub; |
@@ -391,14 +392,14 @@ GNUNET_ABE_cpabe_serialize_key (const struct GNUNET_ABE_AbeKey *key, | |||
391 | int pub_len; | 392 | int pub_len; |
392 | int prv_len; | 393 | int prv_len; |
393 | 394 | ||
394 | pub_len = gabe_pub_serialize (key->pub, &pub); | 395 | pub_len = gabe_pub_serialize(key->pub, &pub); |
395 | prv_len = gabe_prv_serialize (key->prv, &prv); | 396 | prv_len = gabe_prv_serialize(key->prv, &prv); |
396 | 397 | ||
397 | len = pub_len + prv_len + 12; | 398 | len = pub_len + prv_len + 12; |
398 | write_cpabe (result, len, pub, pub_len, prv, prv_len); | 399 | write_cpabe(result, len, pub, pub_len, prv, prv_len); |
399 | 400 | ||
400 | GNUNET_free (pub); | 401 | GNUNET_free(pub); |
401 | GNUNET_free (prv); | 402 | GNUNET_free(prv); |
402 | 403 | ||
403 | return len; | 404 | return len; |
404 | } | 405 | } |
@@ -412,8 +413,8 @@ GNUNET_ABE_cpabe_serialize_key (const struct GNUNET_ABE_AbeKey *key, | |||
412 | * @return the ABE key. NULL of unsuccessful | 413 | * @return the ABE key. NULL of unsuccessful |
413 | */ | 414 | */ |
414 | struct GNUNET_ABE_AbeKey* | 415 | struct GNUNET_ABE_AbeKey* |
415 | GNUNET_ABE_cpabe_deserialize_key (const void *data, | 416 | GNUNET_ABE_cpabe_deserialize_key(const void *data, |
416 | size_t len) | 417 | size_t len) |
417 | { | 418 | { |
418 | struct GNUNET_ABE_AbeKey *key; | 419 | struct GNUNET_ABE_AbeKey *key; |
419 | char *pub; | 420 | char *pub; |
@@ -421,17 +422,17 @@ GNUNET_ABE_cpabe_deserialize_key (const void *data, | |||
421 | int prv_len; | 422 | int prv_len; |
422 | int pub_len; | 423 | int pub_len; |
423 | 424 | ||
424 | key = GNUNET_new (struct GNUNET_ABE_AbeKey); | 425 | key = GNUNET_new(struct GNUNET_ABE_AbeKey); |
425 | read_cpabe (data, | 426 | read_cpabe(data, |
426 | &pub, | 427 | &pub, |
427 | &pub_len, | 428 | &pub_len, |
428 | &prv, | 429 | &prv, |
429 | &prv_len); | 430 | &prv_len); |
430 | key->pub = gabe_pub_unserialize (pub, pub_len); | 431 | key->pub = gabe_pub_unserialize(pub, pub_len); |
431 | key->prv = gabe_prv_unserialize (key->pub, prv, prv_len); | 432 | key->prv = gabe_prv_unserialize(key->pub, prv, prv_len); |
432 | 433 | ||
433 | GNUNET_free (pub); | 434 | GNUNET_free(pub); |
434 | GNUNET_free (prv); | 435 | GNUNET_free(prv); |
435 | return key; | 436 | return key; |
436 | } | 437 | } |
437 | 438 | ||
@@ -444,8 +445,8 @@ GNUNET_ABE_cpabe_deserialize_key (const void *data, | |||
444 | * @return the size of the encrypted block, -1 for errors | 445 | * @return the size of the encrypted block, -1 for errors |
445 | */ | 446 | */ |
446 | ssize_t | 447 | ssize_t |
447 | GNUNET_ABE_cpabe_serialize_master_key (const struct GNUNET_ABE_AbeMasterKey *key, | 448 | GNUNET_ABE_cpabe_serialize_master_key(const struct GNUNET_ABE_AbeMasterKey *key, |
448 | void **result) | 449 | void **result) |
449 | { | 450 | { |
450 | ssize_t len; | 451 | ssize_t len; |
451 | char *pub; | 452 | char *pub; |
@@ -453,14 +454,14 @@ GNUNET_ABE_cpabe_serialize_master_key (const struct GNUNET_ABE_AbeMasterKey *key | |||
453 | int pub_len; | 454 | int pub_len; |
454 | int msk_len; | 455 | int msk_len; |
455 | 456 | ||
456 | pub_len = gabe_pub_serialize (key->pub, &pub); | 457 | pub_len = gabe_pub_serialize(key->pub, &pub); |
457 | msk_len = gabe_msk_serialize (key->msk, &msk); | 458 | msk_len = gabe_msk_serialize(key->msk, &msk); |
458 | 459 | ||
459 | len = pub_len + msk_len + 12; | 460 | len = pub_len + msk_len + 12; |
460 | write_cpabe (result, len, pub, pub_len, msk, msk_len); | 461 | write_cpabe(result, len, pub, pub_len, msk, msk_len); |
461 | 462 | ||
462 | GNUNET_free (pub); | 463 | GNUNET_free(pub); |
463 | GNUNET_free (msk); | 464 | GNUNET_free(msk); |
464 | 465 | ||
465 | return len; | 466 | return len; |
466 | } | 467 | } |
@@ -474,8 +475,8 @@ GNUNET_ABE_cpabe_serialize_master_key (const struct GNUNET_ABE_AbeMasterKey *key | |||
474 | * @return the ABE key. NULL of unsuccessful | 475 | * @return the ABE key. NULL of unsuccessful |
475 | */ | 476 | */ |
476 | struct GNUNET_ABE_AbeMasterKey* | 477 | struct GNUNET_ABE_AbeMasterKey* |
477 | GNUNET_ABE_cpabe_deserialize_master_key (const void *data, | 478 | GNUNET_ABE_cpabe_deserialize_master_key(const void *data, |
478 | size_t len) | 479 | size_t len) |
479 | { | 480 | { |
480 | struct GNUNET_ABE_AbeMasterKey *key; | 481 | struct GNUNET_ABE_AbeMasterKey *key; |
481 | char *msk; | 482 | char *msk; |
@@ -483,17 +484,17 @@ GNUNET_ABE_cpabe_deserialize_master_key (const void *data, | |||
483 | int msk_len; | 484 | int msk_len; |
484 | int pub_len; | 485 | int pub_len; |
485 | 486 | ||
486 | key = GNUNET_new (struct GNUNET_ABE_AbeMasterKey); | 487 | key = GNUNET_new(struct GNUNET_ABE_AbeMasterKey); |
487 | read_cpabe (data, | 488 | read_cpabe(data, |
488 | &pub, | 489 | &pub, |
489 | &pub_len, | 490 | &pub_len, |
490 | &msk, | 491 | &msk, |
491 | &msk_len); | 492 | &msk_len); |
492 | key->pub = gabe_pub_unserialize (pub, pub_len); | 493 | key->pub = gabe_pub_unserialize(pub, pub_len); |
493 | key->msk = gabe_msk_unserialize (key->pub, msk, msk_len); | 494 | key->msk = gabe_msk_unserialize(key->pub, msk, msk_len); |
494 | 495 | ||
495 | GNUNET_free (pub); | 496 | GNUNET_free(pub); |
496 | GNUNET_free (msk); | 497 | GNUNET_free(msk); |
497 | 498 | ||
498 | return key; | 499 | return key; |
499 | } | 500 | } |