diff options
author | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
---|---|---|
committer | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
commit | d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb (patch) | |
tree | 9efd18ea7d425652085ed0bd5e8e45604bc5f6b9 /src/util/crypto_abe.c | |
parent | a0fce305c565c0937d917a92712f15e9c5736260 (diff) | |
download | gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.tar.gz gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.zip |
uncrustify as demanded.
Diffstat (limited to 'src/util/crypto_abe.c')
-rw-r--r-- | src/util/crypto_abe.c | 335 |
1 files changed, 168 insertions, 167 deletions
diff --git a/src/util/crypto_abe.c b/src/util/crypto_abe.c index 1d69a01ae..d702738de 100644 --- a/src/util/crypto_abe.c +++ b/src/util/crypto_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 util/crypto_random.c | 23 | * @file util/crypto_random.c |
@@ -32,57 +32,55 @@ | |||
32 | 32 | ||
33 | #include "gnunet_crypto_lib.h" | 33 | #include "gnunet_crypto_lib.h" |
34 | 34 | ||
35 | struct GNUNET_CRYPTO_AbeMasterKey | 35 | struct GNUNET_CRYPTO_AbeMasterKey { |
36 | { | ||
37 | gabe_pub_t* pub; | 36 | gabe_pub_t* pub; |
38 | gabe_msk_t* msk; | 37 | gabe_msk_t* msk; |
39 | }; | 38 | }; |
40 | 39 | ||
41 | struct GNUNET_CRYPTO_AbeKey | 40 | struct GNUNET_CRYPTO_AbeKey { |
42 | { | ||
43 | gabe_pub_t* pub; | 41 | gabe_pub_t* pub; |
44 | gabe_prv_t* prv; | 42 | gabe_prv_t* prv; |
45 | }; | 43 | }; |
46 | 44 | ||
47 | static int | 45 | static int |
48 | init_aes( element_t k, int enc, | 46 | init_aes(element_t k, int enc, |
49 | gcry_cipher_hd_t* handle, | 47 | gcry_cipher_hd_t* handle, |
50 | struct GNUNET_CRYPTO_SymmetricSessionKey *key, | 48 | struct GNUNET_CRYPTO_SymmetricSessionKey *key, |
51 | unsigned char* iv) | 49 | unsigned char* iv) |
52 | { | 50 | { |
53 | int rc; | 51 | int rc; |
54 | int key_len; | 52 | int key_len; |
55 | unsigned char* key_buf; | 53 | unsigned char* key_buf; |
56 | 54 | ||
57 | key_len = element_length_in_bytes(k) < 33 ? 3 : element_length_in_bytes(k); | 55 | key_len = element_length_in_bytes(k) < 33 ? 3 : element_length_in_bytes(k); |
58 | key_buf = (unsigned char*) malloc(key_len); | 56 | key_buf = (unsigned char*)malloc(key_len); |
59 | element_to_bytes(key_buf, k); | 57 | element_to_bytes(key_buf, k); |
60 | 58 | ||
61 | GNUNET_memcpy (key->aes_key, | 59 | GNUNET_memcpy(key->aes_key, |
62 | key_buf, | 60 | key_buf, |
63 | GNUNET_CRYPTO_AES_KEY_LENGTH); | 61 | GNUNET_CRYPTO_AES_KEY_LENGTH); |
64 | GNUNET_assert (0 == | 62 | GNUNET_assert(0 == |
65 | gcry_cipher_open (handle, GCRY_CIPHER_AES256, | 63 | gcry_cipher_open(handle, GCRY_CIPHER_AES256, |
66 | GCRY_CIPHER_MODE_CFB, 0)); | 64 | GCRY_CIPHER_MODE_CFB, 0)); |
67 | rc = gcry_cipher_setkey (*handle, | 65 | rc = gcry_cipher_setkey(*handle, |
68 | key->aes_key, | 66 | key->aes_key, |
69 | sizeof (key->aes_key)); | 67 | sizeof(key->aes_key)); |
70 | GNUNET_assert ((0 == rc) || ((char) rc == GPG_ERR_WEAK_KEY)); | 68 | GNUNET_assert((0 == rc) || ((char)rc == GPG_ERR_WEAK_KEY)); |
71 | memset (iv, 0, 16); //TODO make reasonable | 69 | memset(iv, 0, 16); //TODO make reasonable |
72 | rc = gcry_cipher_setiv (*handle, | 70 | rc = gcry_cipher_setiv(*handle, |
73 | iv, | 71 | iv, |
74 | 16); | 72 | 16); |
75 | GNUNET_assert ((0 == rc) || ((char) rc == GPG_ERR_WEAK_KEY)); | 73 | GNUNET_assert((0 == rc) || ((char)rc == GPG_ERR_WEAK_KEY)); |
76 | 74 | ||
77 | free(key_buf); | 75 | free(key_buf); |
78 | return rc; | 76 | return rc; |
79 | } | 77 | } |
80 | 78 | ||
81 | static int | 79 | static int |
82 | aes_128_cbc_encrypt( char* pt, | 80 | aes_128_cbc_encrypt(char* pt, |
83 | int size, | 81 | int size, |
84 | element_t k, | 82 | element_t k, |
85 | char **ct ) | 83 | char **ct) |
86 | { | 84 | { |
87 | gcry_cipher_hd_t handle; | 85 | gcry_cipher_hd_t handle; |
88 | struct GNUNET_CRYPTO_SymmetricSessionKey skey; | 86 | struct GNUNET_CRYPTO_SymmetricSessionKey skey; |
@@ -91,34 +89,35 @@ aes_128_cbc_encrypt( char* pt, | |||
91 | int padding; | 89 | int padding; |
92 | int buf_size; | 90 | int buf_size; |
93 | uint8_t len[4]; | 91 | uint8_t len[4]; |
92 | |||
94 | init_aes(k, 1, &handle, &skey, iv); | 93 | init_aes(k, 1, &handle, &skey, iv); |
95 | 94 | ||
96 | /* TODO make less crufty */ | 95 | /* TODO make less crufty */ |
97 | 96 | ||
98 | /* stuff in real length (big endian) before padding */ | 97 | /* stuff in real length (big endian) before padding */ |
99 | len[0] = (size & 0xff000000)>>24; | 98 | len[0] = (size & 0xff000000) >> 24; |
100 | len[1] = (size & 0xff0000)>>16; | 99 | len[1] = (size & 0xff0000) >> 16; |
101 | len[2] = (size & 0xff00)>>8; | 100 | len[2] = (size & 0xff00) >> 8; |
102 | len[3] = (size & 0xff)>>0; | 101 | len[3] = (size & 0xff) >> 0; |
103 | padding = 16 - ((4+size) % 16); | 102 | padding = 16 - ((4 + size) % 16); |
104 | buf_size = 4 + size + padding; | 103 | buf_size = 4 + size + padding; |
105 | buf = GNUNET_malloc (buf_size); | 104 | buf = GNUNET_malloc(buf_size); |
106 | GNUNET_memcpy (buf, len, 4); | 105 | GNUNET_memcpy(buf, len, 4); |
107 | GNUNET_memcpy (buf+4, pt, size); | 106 | GNUNET_memcpy(buf + 4, pt, size); |
108 | *ct = GNUNET_malloc (buf_size); | 107 | *ct = GNUNET_malloc(buf_size); |
109 | 108 | ||
110 | GNUNET_assert (0 == gcry_cipher_encrypt (handle, *ct, buf_size, buf, buf_size)); | 109 | GNUNET_assert(0 == gcry_cipher_encrypt(handle, *ct, buf_size, buf, buf_size)); |
111 | gcry_cipher_close (handle); | 110 | gcry_cipher_close(handle); |
112 | //AES_cbc_encrypt(pt->data, ct->data, pt->len, &key, iv, AES_ENCRYPT); | 111 | //AES_cbc_encrypt(pt->data, ct->data, pt->len, &key, iv, AES_ENCRYPT); |
113 | GNUNET_free (buf); | 112 | GNUNET_free(buf); |
114 | return buf_size; | 113 | return buf_size; |
115 | } | 114 | } |
116 | 115 | ||
117 | static int | 116 | static int |
118 | aes_128_cbc_decrypt( char* ct, | 117 | aes_128_cbc_decrypt(char* ct, |
119 | int size, | 118 | int size, |
120 | element_t k, | 119 | element_t k, |
121 | char **pt ) | 120 | char **pt) |
122 | { | 121 | { |
123 | struct GNUNET_CRYPTO_SymmetricSessionKey skey; | 122 | struct GNUNET_CRYPTO_SymmetricSessionKey skey; |
124 | gcry_cipher_hd_t handle; | 123 | gcry_cipher_hd_t handle; |
@@ -128,108 +127,109 @@ aes_128_cbc_decrypt( char* ct, | |||
128 | 127 | ||
129 | init_aes(k, 1, &handle, &skey, iv); | 128 | init_aes(k, 1, &handle, &skey, iv); |
130 | 129 | ||
131 | tmp = GNUNET_malloc (size); | 130 | tmp = GNUNET_malloc(size); |
132 | 131 | ||
133 | //AES_cbc_encrypt(ct->data, pt->data, ct->len, &key, iv, AES_DECRYPT); | 132 | //AES_cbc_encrypt(ct->data, pt->data, ct->len, &key, iv, AES_DECRYPT); |
134 | GNUNET_assert (0 == gcry_cipher_decrypt (handle, tmp, size, ct, size)); | 133 | GNUNET_assert(0 == gcry_cipher_decrypt(handle, tmp, size, ct, size)); |
135 | gcry_cipher_close (handle); | 134 | gcry_cipher_close(handle); |
136 | /* TODO make less crufty */ | 135 | /* TODO make less crufty */ |
137 | 136 | ||
138 | /* get real length */ | 137 | /* get real length */ |
139 | len = 0; | 138 | len = 0; |
140 | len = len | 139 | len = len |
141 | | ((tmp[0])<<24) | ((tmp[1])<<16) | 140 | | ((tmp[0]) << 24) | ((tmp[1]) << 16) |
142 | | ((tmp[2])<<8) | ((tmp[3])<<0); | 141 | | ((tmp[2]) << 8) | ((tmp[3]) << 0); |
143 | /* truncate any garbage from the padding */ | 142 | /* truncate any garbage from the padding */ |
144 | *pt = GNUNET_malloc (len); | 143 | *pt = GNUNET_malloc(len); |
145 | GNUNET_memcpy (*pt, tmp+4, len); | 144 | GNUNET_memcpy(*pt, tmp + 4, len); |
146 | GNUNET_free (tmp); | 145 | GNUNET_free(tmp); |
147 | return len; | 146 | return len; |
148 | } | 147 | } |
149 | 148 | ||
150 | struct GNUNET_CRYPTO_AbeMasterKey* | 149 | struct GNUNET_CRYPTO_AbeMasterKey* |
151 | GNUNET_CRYPTO_cpabe_create_master_key (void) | 150 | GNUNET_CRYPTO_cpabe_create_master_key(void) |
152 | { | 151 | { |
153 | struct GNUNET_CRYPTO_AbeMasterKey* key; | 152 | struct GNUNET_CRYPTO_AbeMasterKey* key; |
154 | key = GNUNET_new (struct GNUNET_CRYPTO_AbeMasterKey); | 153 | |
154 | key = GNUNET_new(struct GNUNET_CRYPTO_AbeMasterKey); | ||
155 | gabe_setup(&key->pub, &key->msk); | 155 | gabe_setup(&key->pub, &key->msk); |
156 | GNUNET_assert (NULL != key->pub); | 156 | GNUNET_assert(NULL != key->pub); |
157 | GNUNET_assert (NULL != key->msk); | 157 | GNUNET_assert(NULL != key->msk); |
158 | return key; | 158 | return key; |
159 | } | 159 | } |
160 | 160 | ||
161 | void | 161 | void |
162 | GNUNET_CRYPTO_cpabe_delete_master_key (struct GNUNET_CRYPTO_AbeMasterKey *key) | 162 | GNUNET_CRYPTO_cpabe_delete_master_key(struct GNUNET_CRYPTO_AbeMasterKey *key) |
163 | { | 163 | { |
164 | gabe_msk_free (key->msk); | 164 | gabe_msk_free(key->msk); |
165 | gabe_pub_free (key->pub); | 165 | gabe_pub_free(key->pub); |
166 | //GNUNET_free (key->msk); | 166 | //GNUNET_free (key->msk); |
167 | //gabe_msk_free (key->msk); //For some reason free of pub implicit? | 167 | //gabe_msk_free (key->msk); //For some reason free of pub implicit? |
168 | GNUNET_free (key); | 168 | GNUNET_free(key); |
169 | } | 169 | } |
170 | 170 | ||
171 | struct GNUNET_CRYPTO_AbeKey* | 171 | struct GNUNET_CRYPTO_AbeKey* |
172 | GNUNET_CRYPTO_cpabe_create_key (struct GNUNET_CRYPTO_AbeMasterKey *key, | 172 | GNUNET_CRYPTO_cpabe_create_key(struct GNUNET_CRYPTO_AbeMasterKey *key, |
173 | char **attrs) | 173 | char **attrs) |
174 | { | 174 | { |
175 | struct GNUNET_CRYPTO_AbeKey *prv_key; | 175 | struct GNUNET_CRYPTO_AbeKey *prv_key; |
176 | int size; | 176 | int size; |
177 | char *tmp; | 177 | char *tmp; |
178 | 178 | ||
179 | prv_key = GNUNET_new (struct GNUNET_CRYPTO_AbeKey); | 179 | prv_key = GNUNET_new(struct GNUNET_CRYPTO_AbeKey); |
180 | prv_key->prv = gabe_keygen(key->pub, key->msk, attrs); | 180 | prv_key->prv = gabe_keygen(key->pub, key->msk, attrs); |
181 | size = gabe_pub_serialize(key->pub, &tmp); | 181 | size = gabe_pub_serialize(key->pub, &tmp); |
182 | prv_key->pub = gabe_pub_unserialize(tmp, size); | 182 | prv_key->pub = gabe_pub_unserialize(tmp, size); |
183 | GNUNET_free (tmp); | 183 | GNUNET_free(tmp); |
184 | GNUNET_assert (NULL != prv_key->prv); | 184 | GNUNET_assert(NULL != prv_key->prv); |
185 | return prv_key; | 185 | return prv_key; |
186 | } | 186 | } |
187 | 187 | ||
188 | void | 188 | void |
189 | GNUNET_CRYPTO_cpabe_delete_key (struct GNUNET_CRYPTO_AbeKey *key, | 189 | GNUNET_CRYPTO_cpabe_delete_key(struct GNUNET_CRYPTO_AbeKey *key, |
190 | int delete_pub) | 190 | int delete_pub) |
191 | { | 191 | { |
192 | //Memory management in gabe is buggy | 192 | //Memory management in gabe is buggy |
193 | gabe_prv_free (key->prv); | 193 | gabe_prv_free(key->prv); |
194 | if (GNUNET_YES == delete_pub) | 194 | if (GNUNET_YES == delete_pub) |
195 | gabe_pub_free (key->pub); | 195 | gabe_pub_free(key->pub); |
196 | GNUNET_free (key); | 196 | GNUNET_free(key); |
197 | } | 197 | } |
198 | 198 | ||
199 | ssize_t | 199 | ssize_t |
200 | write_cpabe (void **result, | 200 | write_cpabe(void **result, |
201 | uint32_t file_len, | 201 | uint32_t file_len, |
202 | char* cph_buf, | 202 | char* cph_buf, |
203 | int cph_buf_len, | 203 | int cph_buf_len, |
204 | char* aes_buf, | 204 | char* aes_buf, |
205 | int aes_buf_len) | 205 | int aes_buf_len) |
206 | { | 206 | { |
207 | char *ptr; | 207 | char *ptr; |
208 | uint32_t *len; | 208 | uint32_t *len; |
209 | 209 | ||
210 | *result = GNUNET_malloc (12 + cph_buf_len + aes_buf_len); | 210 | *result = GNUNET_malloc(12 + cph_buf_len + aes_buf_len); |
211 | ptr = *result; | 211 | ptr = *result; |
212 | len = (uint32_t*) ptr; | 212 | len = (uint32_t*)ptr; |
213 | *len = htonl (file_len); | 213 | *len = htonl(file_len); |
214 | ptr += 4; | 214 | ptr += 4; |
215 | len = (uint32_t*) ptr; | 215 | len = (uint32_t*)ptr; |
216 | *len = htonl (aes_buf_len); | 216 | *len = htonl(aes_buf_len); |
217 | ptr += 4; | 217 | ptr += 4; |
218 | GNUNET_memcpy (ptr, aes_buf, aes_buf_len); | 218 | GNUNET_memcpy(ptr, aes_buf, aes_buf_len); |
219 | ptr += aes_buf_len; | 219 | ptr += aes_buf_len; |
220 | len = (uint32_t*) ptr; | 220 | len = (uint32_t*)ptr; |
221 | *len = htonl (cph_buf_len); | 221 | *len = htonl(cph_buf_len); |
222 | ptr += 4; | 222 | ptr += 4; |
223 | GNUNET_memcpy (ptr, cph_buf, cph_buf_len); | 223 | GNUNET_memcpy(ptr, cph_buf, cph_buf_len); |
224 | return 12 + cph_buf_len + aes_buf_len; | 224 | return 12 + cph_buf_len + aes_buf_len; |
225 | } | 225 | } |
226 | 226 | ||
227 | ssize_t | 227 | ssize_t |
228 | read_cpabe (const void *data, | 228 | read_cpabe(const void *data, |
229 | char** cph_buf, | 229 | char** cph_buf, |
230 | int *cph_buf_len, | 230 | int *cph_buf_len, |
231 | char** aes_buf, | 231 | char** aes_buf, |
232 | int *aes_buf_len) | 232 | int *aes_buf_len) |
233 | { | 233 | { |
234 | int buf_len; | 234 | int buf_len; |
235 | char *ptr; | 235 | char *ptr; |
@@ -237,29 +237,29 @@ read_cpabe (const void *data, | |||
237 | 237 | ||
238 | ptr = (char*)data; | 238 | ptr = (char*)data; |
239 | len = (uint32_t*)ptr; | 239 | len = (uint32_t*)ptr; |
240 | buf_len = ntohl (*len); | 240 | buf_len = ntohl(*len); |
241 | ptr += 4; | 241 | ptr += 4; |
242 | len = (uint32_t*)ptr; | 242 | len = (uint32_t*)ptr; |
243 | *aes_buf_len = ntohl (*len); | 243 | *aes_buf_len = ntohl(*len); |
244 | ptr += 4; | 244 | ptr += 4; |
245 | *aes_buf = GNUNET_malloc (*aes_buf_len); | 245 | *aes_buf = GNUNET_malloc(*aes_buf_len); |
246 | GNUNET_memcpy (*aes_buf, ptr, *aes_buf_len); | 246 | GNUNET_memcpy(*aes_buf, ptr, *aes_buf_len); |
247 | ptr += *aes_buf_len; | 247 | ptr += *aes_buf_len; |
248 | len = (uint32_t*)ptr; | 248 | len = (uint32_t*)ptr; |
249 | *cph_buf_len = ntohl (*len); | 249 | *cph_buf_len = ntohl(*len); |
250 | ptr += 4; | 250 | ptr += 4; |
251 | *cph_buf = GNUNET_malloc (*cph_buf_len); | 251 | *cph_buf = GNUNET_malloc(*cph_buf_len); |
252 | GNUNET_memcpy (*cph_buf, ptr, *cph_buf_len); | 252 | GNUNET_memcpy(*cph_buf, ptr, *cph_buf_len); |
253 | 253 | ||
254 | return buf_len; | 254 | return buf_len; |
255 | } | 255 | } |
256 | 256 | ||
257 | ssize_t | 257 | ssize_t |
258 | GNUNET_CRYPTO_cpabe_encrypt (const void *block, | 258 | GNUNET_CRYPTO_cpabe_encrypt(const void *block, |
259 | size_t size, | 259 | size_t size, |
260 | const char *policy, | 260 | const char *policy, |
261 | const struct GNUNET_CRYPTO_AbeMasterKey *key, | 261 | const struct GNUNET_CRYPTO_AbeMasterKey *key, |
262 | void **result) | 262 | void **result) |
263 | { | 263 | { |
264 | gabe_cph_t* cph; | 264 | gabe_cph_t* cph; |
265 | char* plt; | 265 | char* plt; |
@@ -270,15 +270,15 @@ GNUNET_CRYPTO_cpabe_encrypt (const void *block, | |||
270 | int aes_buf_len; | 270 | int aes_buf_len; |
271 | ssize_t result_len; | 271 | ssize_t result_len; |
272 | 272 | ||
273 | if( !(cph = gabe_enc(key->pub, m, (char*)policy)) ) | 273 | if (!(cph = gabe_enc(key->pub, m, (char*)policy))) |
274 | return GNUNET_SYSERR; | 274 | return GNUNET_SYSERR; |
275 | cph_buf_len = gabe_cph_serialize(cph, | 275 | cph_buf_len = gabe_cph_serialize(cph, |
276 | &cph_buf); | 276 | &cph_buf); |
277 | gabe_cph_free(cph); | 277 | gabe_cph_free(cph); |
278 | GNUNET_free (cph); | 278 | GNUNET_free(cph); |
279 | plt = GNUNET_memdup (block, size); | 279 | plt = GNUNET_memdup(block, size); |
280 | aes_buf_len = aes_128_cbc_encrypt(plt, size, m, &aes_buf); | 280 | aes_buf_len = aes_128_cbc_encrypt(plt, size, m, &aes_buf); |
281 | GNUNET_free (plt); | 281 | GNUNET_free(plt); |
282 | element_clear(m); | 282 | element_clear(m); |
283 | result_len = write_cpabe(result, size, cph_buf, cph_buf_len, aes_buf, aes_buf_len); | 283 | result_len = write_cpabe(result, size, cph_buf, cph_buf_len, aes_buf, aes_buf_len); |
284 | GNUNET_free(cph_buf); | 284 | GNUNET_free(cph_buf); |
@@ -287,10 +287,10 @@ GNUNET_CRYPTO_cpabe_encrypt (const void *block, | |||
287 | } | 287 | } |
288 | 288 | ||
289 | ssize_t | 289 | ssize_t |
290 | GNUNET_CRYPTO_cpabe_decrypt (const void *block, | 290 | GNUNET_CRYPTO_cpabe_decrypt(const void *block, |
291 | size_t size, | 291 | size_t size, |
292 | const struct GNUNET_CRYPTO_AbeKey *key, | 292 | const struct GNUNET_CRYPTO_AbeKey *key, |
293 | void **result) | 293 | void **result) |
294 | { | 294 | { |
295 | char* aes_buf; | 295 | char* aes_buf; |
296 | char* cph_buf; | 296 | char* cph_buf; |
@@ -302,22 +302,23 @@ GNUNET_CRYPTO_cpabe_decrypt (const void *block, | |||
302 | 302 | ||
303 | read_cpabe(block, &cph_buf, &cph_buf_size, &aes_buf, &aes_buf_size); | 303 | read_cpabe(block, &cph_buf, &cph_buf_size, &aes_buf, &aes_buf_size); |
304 | cph = gabe_cph_unserialize(key->pub, cph_buf, cph_buf_size); | 304 | cph = gabe_cph_unserialize(key->pub, cph_buf, cph_buf_size); |
305 | if( !gabe_dec(key->pub, key->prv, cph, m) ) { | 305 | if (!gabe_dec(key->pub, key->prv, cph, m)) |
306 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 306 | { |
307 | "%s\n", gabe_error()); | 307 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
308 | GNUNET_free (aes_buf); | 308 | "%s\n", gabe_error()); |
309 | GNUNET_free (cph_buf); | 309 | GNUNET_free(aes_buf); |
310 | gabe_cph_free(cph); | 310 | GNUNET_free(cph_buf); |
311 | GNUNET_free (cph); | 311 | gabe_cph_free(cph); |
312 | element_clear (m); | 312 | GNUNET_free(cph); |
313 | return GNUNET_SYSERR; | 313 | element_clear(m); |
314 | } | 314 | return GNUNET_SYSERR; |
315 | } | ||
315 | gabe_cph_free(cph); | 316 | gabe_cph_free(cph); |
316 | GNUNET_free (cph); | 317 | GNUNET_free(cph); |
317 | plt_len = aes_128_cbc_decrypt(aes_buf, aes_buf_size, m, (char**)result); | 318 | plt_len = aes_128_cbc_decrypt(aes_buf, aes_buf_size, m, (char**)result); |
318 | GNUNET_free (cph_buf); | 319 | GNUNET_free(cph_buf); |
319 | GNUNET_free (aes_buf); | 320 | GNUNET_free(aes_buf); |
320 | element_clear (m); | 321 | element_clear(m); |
321 | //freeing is buggy in gabe | 322 | //freeing is buggy in gabe |
322 | //gabe_prv_free (prv); | 323 | //gabe_prv_free (prv); |
323 | //gabe_pub_free (pub); | 324 | //gabe_pub_free (pub); |
@@ -325,8 +326,8 @@ GNUNET_CRYPTO_cpabe_decrypt (const void *block, | |||
325 | } | 326 | } |
326 | 327 | ||
327 | ssize_t | 328 | ssize_t |
328 | GNUNET_CRYPTO_cpabe_serialize_key (const struct GNUNET_CRYPTO_AbeKey *key, | 329 | GNUNET_CRYPTO_cpabe_serialize_key(const struct GNUNET_CRYPTO_AbeKey *key, |
329 | void **result) | 330 | void **result) |
330 | { | 331 | { |
331 | ssize_t len; | 332 | ssize_t len; |
332 | char *pub; | 333 | char *pub; |
@@ -334,21 +335,21 @@ GNUNET_CRYPTO_cpabe_serialize_key (const struct GNUNET_CRYPTO_AbeKey *key, | |||
334 | int pub_len; | 335 | int pub_len; |
335 | int prv_len; | 336 | int prv_len; |
336 | 337 | ||
337 | pub_len = gabe_pub_serialize (key->pub, &pub); | 338 | pub_len = gabe_pub_serialize(key->pub, &pub); |
338 | prv_len = gabe_prv_serialize (key->prv, &prv); | 339 | prv_len = gabe_prv_serialize(key->prv, &prv); |
339 | 340 | ||
340 | len = pub_len + prv_len + 12; | 341 | len = pub_len + prv_len + 12; |
341 | write_cpabe (result, len, pub, pub_len, prv, prv_len); | 342 | write_cpabe(result, len, pub, pub_len, prv, prv_len); |
342 | 343 | ||
343 | GNUNET_free (pub); | 344 | GNUNET_free(pub); |
344 | GNUNET_free (prv); | 345 | GNUNET_free(prv); |
345 | 346 | ||
346 | return len; | 347 | return len; |
347 | } | 348 | } |
348 | 349 | ||
349 | struct GNUNET_CRYPTO_AbeKey* | 350 | struct GNUNET_CRYPTO_AbeKey* |
350 | GNUNET_CRYPTO_cpabe_deserialize_key (const void *data, | 351 | GNUNET_CRYPTO_cpabe_deserialize_key(const void *data, |
351 | size_t len) | 352 | size_t len) |
352 | { | 353 | { |
353 | struct GNUNET_CRYPTO_AbeKey *key; | 354 | struct GNUNET_CRYPTO_AbeKey *key; |
354 | char *pub; | 355 | char *pub; |
@@ -356,23 +357,23 @@ GNUNET_CRYPTO_cpabe_deserialize_key (const void *data, | |||
356 | int prv_len; | 357 | int prv_len; |
357 | int pub_len; | 358 | int pub_len; |
358 | 359 | ||
359 | key = GNUNET_new (struct GNUNET_CRYPTO_AbeKey); | 360 | key = GNUNET_new(struct GNUNET_CRYPTO_AbeKey); |
360 | read_cpabe (data, | 361 | read_cpabe(data, |
361 | &pub, | 362 | &pub, |
362 | &pub_len, | 363 | &pub_len, |
363 | &prv, | 364 | &prv, |
364 | &prv_len); | 365 | &prv_len); |
365 | key->pub = gabe_pub_unserialize (pub, pub_len); | 366 | key->pub = gabe_pub_unserialize(pub, pub_len); |
366 | key->prv = gabe_prv_unserialize (key->pub, prv, prv_len); | 367 | key->prv = gabe_prv_unserialize(key->pub, prv, prv_len); |
367 | 368 | ||
368 | GNUNET_free (pub); | 369 | GNUNET_free(pub); |
369 | GNUNET_free (prv); | 370 | GNUNET_free(prv); |
370 | return key; | 371 | return key; |
371 | } | 372 | } |
372 | 373 | ||
373 | ssize_t | 374 | ssize_t |
374 | GNUNET_CRYPTO_cpabe_serialize_master_key (const struct GNUNET_CRYPTO_AbeMasterKey *key, | 375 | GNUNET_CRYPTO_cpabe_serialize_master_key(const struct GNUNET_CRYPTO_AbeMasterKey *key, |
375 | void **result) | 376 | void **result) |
376 | { | 377 | { |
377 | ssize_t len; | 378 | ssize_t len; |
378 | char *pub; | 379 | char *pub; |
@@ -380,21 +381,21 @@ GNUNET_CRYPTO_cpabe_serialize_master_key (const struct GNUNET_CRYPTO_AbeMasterKe | |||
380 | int pub_len; | 381 | int pub_len; |
381 | int msk_len; | 382 | int msk_len; |
382 | 383 | ||
383 | pub_len = gabe_pub_serialize (key->pub, &pub); | 384 | pub_len = gabe_pub_serialize(key->pub, &pub); |
384 | msk_len = gabe_msk_serialize (key->msk, &msk); | 385 | msk_len = gabe_msk_serialize(key->msk, &msk); |
385 | 386 | ||
386 | len = pub_len + msk_len + 12; | 387 | len = pub_len + msk_len + 12; |
387 | write_cpabe (result, len, pub, pub_len, msk, msk_len); | 388 | write_cpabe(result, len, pub, pub_len, msk, msk_len); |
388 | 389 | ||
389 | GNUNET_free (pub); | 390 | GNUNET_free(pub); |
390 | GNUNET_free (msk); | 391 | GNUNET_free(msk); |
391 | 392 | ||
392 | return len; | 393 | return len; |
393 | } | 394 | } |
394 | 395 | ||
395 | struct GNUNET_CRYPTO_AbeMasterKey* | 396 | struct GNUNET_CRYPTO_AbeMasterKey* |
396 | GNUNET_CRYPTO_cpabe_deserialize_master_key (const void *data, | 397 | GNUNET_CRYPTO_cpabe_deserialize_master_key(const void *data, |
397 | size_t len) | 398 | size_t len) |
398 | { | 399 | { |
399 | struct GNUNET_CRYPTO_AbeMasterKey *key; | 400 | struct GNUNET_CRYPTO_AbeMasterKey *key; |
400 | char *msk; | 401 | char *msk; |
@@ -402,17 +403,17 @@ GNUNET_CRYPTO_cpabe_deserialize_master_key (const void *data, | |||
402 | int msk_len; | 403 | int msk_len; |
403 | int pub_len; | 404 | int pub_len; |
404 | 405 | ||
405 | key = GNUNET_new (struct GNUNET_CRYPTO_AbeMasterKey); | 406 | key = GNUNET_new(struct GNUNET_CRYPTO_AbeMasterKey); |
406 | read_cpabe (data, | 407 | read_cpabe(data, |
407 | &pub, | 408 | &pub, |
408 | &pub_len, | 409 | &pub_len, |
409 | &msk, | 410 | &msk, |
410 | &msk_len); | 411 | &msk_len); |
411 | key->pub = gabe_pub_unserialize (pub, pub_len); | 412 | key->pub = gabe_pub_unserialize(pub, pub_len); |
412 | key->msk = gabe_msk_unserialize (key->pub, msk, msk_len); | 413 | key->msk = gabe_msk_unserialize(key->pub, msk, msk_len); |
413 | 414 | ||
414 | GNUNET_free (pub); | 415 | GNUNET_free(pub); |
415 | GNUNET_free (msk); | 416 | GNUNET_free(msk); |
416 | 417 | ||
417 | return key; | 418 | return key; |
418 | } | 419 | } |