diff options
Diffstat (limited to 'src/abe/abe.c')
-rw-r--r-- | src/abe/abe.c | 44 |
1 files changed, 21 insertions, 23 deletions
diff --git a/src/abe/abe.c b/src/abe/abe.c index 3f1f6dc5b..be9e95bee 100644 --- a/src/abe/abe.c +++ b/src/abe/abe.c | |||
@@ -2,20 +2,18 @@ | |||
2 | This file is part of GNUnet. Copyright (C) 2001-2018 Christian Grothoff | 2 | This file is part of GNUnet. Copyright (C) 2001-2018 Christian Grothoff |
3 | (and other contributing authors) | 3 | (and other contributing authors) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | it under the terms of the GNU General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation; either version 3, or (at your | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
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 | 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 General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with GNUnet; see the file COPYING. If not, write to the | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | ||
19 | 17 | ||
20 | */ | 18 | */ |
21 | 19 | ||
@@ -54,12 +52,12 @@ init_aes( element_t k, int enc, | |||
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 | 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)); |
@@ -124,16 +122,16 @@ aes_128_cbc_decrypt( char* ct, | |||
124 | unsigned char iv[16]; | 122 | unsigned char iv[16]; |
125 | char* tmp; | 123 | char* tmp; |
126 | uint32_t len; | 124 | uint32_t len; |
127 | 125 | ||
128 | init_aes(k, 1, &handle, &skey, iv); | 126 | init_aes(k, 1, &handle, &skey, iv); |
129 | 127 | ||
130 | tmp = GNUNET_malloc (size); | 128 | tmp = GNUNET_malloc (size); |
131 | 129 | ||
132 | //AES_cbc_encrypt(ct->data, pt->data, ct->len, &key, iv, AES_DECRYPT); | 130 | //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)); | 131 | GNUNET_assert (0 == gcry_cipher_decrypt (handle, tmp, size, ct, size)); |
134 | gcry_cipher_close (handle); | 132 | gcry_cipher_close (handle); |
135 | /* TODO make less crufty */ | 133 | /* TODO make less crufty */ |
136 | 134 | ||
137 | /* get real length */ | 135 | /* get real length */ |
138 | len = 0; | 136 | len = 0; |
139 | len = len | 137 | len = len |
@@ -195,7 +193,7 @@ GNUNET_ABE_cpabe_create_key (struct GNUNET_ABE_AbeMasterKey *key, | |||
195 | struct GNUNET_ABE_AbeKey *prv_key; | 193 | struct GNUNET_ABE_AbeKey *prv_key; |
196 | int size; | 194 | int size; |
197 | char *tmp; | 195 | char *tmp; |
198 | 196 | ||
199 | prv_key = GNUNET_new (struct GNUNET_ABE_AbeKey); | 197 | prv_key = GNUNET_new (struct GNUNET_ABE_AbeKey); |
200 | prv_key->prv = gabe_keygen(key->pub, key->msk, attrs); | 198 | prv_key->prv = gabe_keygen(key->pub, key->msk, attrs); |
201 | size = gabe_pub_serialize(key->pub, &tmp); | 199 | size = gabe_pub_serialize(key->pub, &tmp); |
@@ -234,7 +232,7 @@ write_cpabe (void **result, | |||
234 | { | 232 | { |
235 | char *ptr; | 233 | char *ptr; |
236 | uint32_t *len; | 234 | uint32_t *len; |
237 | 235 | ||
238 | *result = GNUNET_malloc (12 + cph_buf_len + aes_buf_len); | 236 | *result = GNUNET_malloc (12 + cph_buf_len + aes_buf_len); |
239 | ptr = *result; | 237 | ptr = *result; |
240 | len = (uint32_t*) ptr; | 238 | len = (uint32_t*) ptr; |
@@ -243,12 +241,12 @@ write_cpabe (void **result, | |||
243 | len = (uint32_t*) ptr; | 241 | len = (uint32_t*) ptr; |
244 | *len = htonl (aes_buf_len); | 242 | *len = htonl (aes_buf_len); |
245 | ptr += 4; | 243 | ptr += 4; |
246 | memcpy (ptr, aes_buf, aes_buf_len); | 244 | GNUNET_memcpy (ptr, aes_buf, aes_buf_len); |
247 | ptr += aes_buf_len; | 245 | ptr += aes_buf_len; |
248 | len = (uint32_t*) ptr; | 246 | len = (uint32_t*) ptr; |
249 | *len = htonl (cph_buf_len); | 247 | *len = htonl (cph_buf_len); |
250 | ptr += 4; | 248 | ptr += 4; |
251 | memcpy (ptr, cph_buf, cph_buf_len); | 249 | GNUNET_memcpy (ptr, cph_buf, cph_buf_len); |
252 | return 12 + cph_buf_len + aes_buf_len; | 250 | return 12 + cph_buf_len + aes_buf_len; |
253 | } | 251 | } |
254 | 252 | ||
@@ -271,13 +269,13 @@ read_cpabe (const void *data, | |||
271 | *aes_buf_len = ntohl (*len); | 269 | *aes_buf_len = ntohl (*len); |
272 | ptr += 4; | 270 | ptr += 4; |
273 | *aes_buf = GNUNET_malloc (*aes_buf_len); | 271 | *aes_buf = GNUNET_malloc (*aes_buf_len); |
274 | memcpy(*aes_buf, ptr, *aes_buf_len); | 272 | GNUNET_memcpy(*aes_buf, ptr, *aes_buf_len); |
275 | ptr += *aes_buf_len; | 273 | ptr += *aes_buf_len; |
276 | len = (uint32_t*)ptr; | 274 | len = (uint32_t*)ptr; |
277 | *cph_buf_len = ntohl (*len); | 275 | *cph_buf_len = ntohl (*len); |
278 | ptr += 4; | 276 | ptr += 4; |
279 | *cph_buf = GNUNET_malloc (*cph_buf_len); | 277 | *cph_buf = GNUNET_malloc (*cph_buf_len); |
280 | memcpy(*cph_buf, ptr, *cph_buf_len); | 278 | GNUNET_memcpy(*cph_buf, ptr, *cph_buf_len); |
281 | 279 | ||
282 | return buf_len; | 280 | return buf_len; |
283 | } | 281 | } |
@@ -429,7 +427,7 @@ GNUNET_ABE_cpabe_deserialize_key (const void *data, | |||
429 | &prv_len); | 427 | &prv_len); |
430 | key->pub = gabe_pub_unserialize (pub, pub_len); | 428 | key->pub = gabe_pub_unserialize (pub, pub_len); |
431 | key->prv = gabe_prv_unserialize (key->pub, prv, prv_len); | 429 | key->prv = gabe_prv_unserialize (key->pub, prv, prv_len); |
432 | 430 | ||
433 | GNUNET_free (pub); | 431 | GNUNET_free (pub); |
434 | GNUNET_free (prv); | 432 | GNUNET_free (prv); |
435 | return key; | 433 | return key; |
@@ -491,7 +489,7 @@ GNUNET_ABE_cpabe_deserialize_master_key (const void *data, | |||
491 | &msk_len); | 489 | &msk_len); |
492 | key->pub = gabe_pub_unserialize (pub, pub_len); | 490 | key->pub = gabe_pub_unserialize (pub, pub_len); |
493 | key->msk = gabe_msk_unserialize (key->pub, msk, msk_len); | 491 | key->msk = gabe_msk_unserialize (key->pub, msk, msk_len); |
494 | 492 | ||
495 | GNUNET_free (pub); | 493 | GNUNET_free (pub); |
496 | GNUNET_free (msk); | 494 | GNUNET_free (msk); |
497 | 495 | ||