diff options
Diffstat (limited to 'src/util/crypto_abe.c')
-rw-r--r-- | src/util/crypto_abe.c | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/src/util/crypto_abe.c b/src/util/crypto_abe.c index fcaa826ed..581e63764 100644 --- a/src/util/crypto_abe.c +++ b/src/util/crypto_abe.c | |||
@@ -2,20 +2,18 @@ | |||
2 | This file is part of GNUnet. Copyright (C) 2001-2014 Christian Grothoff | 2 | This file is part of GNUnet. Copyright (C) 2001-2014 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 | ||
@@ -53,12 +51,14 @@ init_aes( element_t k, int enc, | |||
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 | memcpy (key->aes_key, key_buf, GNUNET_CRYPTO_AES_KEY_LENGTH); | 59 | GNUNET_memcpy (key->aes_key, |
60 | key_buf, | ||
61 | GNUNET_CRYPTO_AES_KEY_LENGTH); | ||
62 | GNUNET_assert (0 == | 62 | GNUNET_assert (0 == |
63 | gcry_cipher_open (handle, GCRY_CIPHER_AES256, | 63 | gcry_cipher_open (handle, GCRY_CIPHER_AES256, |
64 | GCRY_CIPHER_MODE_CFB, 0)); | 64 | GCRY_CIPHER_MODE_CFB, 0)); |
@@ -123,16 +123,16 @@ aes_128_cbc_decrypt( char* ct, | |||
123 | unsigned char iv[16]; | 123 | unsigned char iv[16]; |
124 | char* tmp; | 124 | char* tmp; |
125 | uint32_t len; | 125 | uint32_t len; |
126 | 126 | ||
127 | init_aes(k, 1, &handle, &skey, iv); | 127 | init_aes(k, 1, &handle, &skey, iv); |
128 | 128 | ||
129 | tmp = GNUNET_malloc (size); | 129 | tmp = GNUNET_malloc (size); |
130 | 130 | ||
131 | //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); |
132 | GNUNET_assert (0 == gcry_cipher_decrypt (handle, tmp, size, ct, size)); | 132 | GNUNET_assert (0 == gcry_cipher_decrypt (handle, tmp, size, ct, size)); |
133 | gcry_cipher_close (handle); | 133 | gcry_cipher_close (handle); |
134 | /* TODO make less crufty */ | 134 | /* TODO make less crufty */ |
135 | 135 | ||
136 | /* get real length */ | 136 | /* get real length */ |
137 | len = 0; | 137 | len = 0; |
138 | len = len | 138 | len = len |
@@ -173,7 +173,7 @@ GNUNET_CRYPTO_cpabe_create_key (struct GNUNET_CRYPTO_AbeMasterKey *key, | |||
173 | struct GNUNET_CRYPTO_AbeKey *prv_key; | 173 | struct GNUNET_CRYPTO_AbeKey *prv_key; |
174 | int size; | 174 | int size; |
175 | char *tmp; | 175 | char *tmp; |
176 | 176 | ||
177 | prv_key = GNUNET_new (struct GNUNET_CRYPTO_AbeKey); | 177 | prv_key = GNUNET_new (struct GNUNET_CRYPTO_AbeKey); |
178 | prv_key->prv = gabe_keygen(key->pub, key->msk, attrs); | 178 | prv_key->prv = gabe_keygen(key->pub, key->msk, attrs); |
179 | size = gabe_pub_serialize(key->pub, &tmp); | 179 | size = gabe_pub_serialize(key->pub, &tmp); |
@@ -204,7 +204,7 @@ write_cpabe (void **result, | |||
204 | { | 204 | { |
205 | char *ptr; | 205 | char *ptr; |
206 | uint32_t *len; | 206 | uint32_t *len; |
207 | 207 | ||
208 | *result = GNUNET_malloc (12 + cph_buf_len + aes_buf_len); | 208 | *result = GNUNET_malloc (12 + cph_buf_len + aes_buf_len); |
209 | ptr = *result; | 209 | ptr = *result; |
210 | len = (uint32_t*) ptr; | 210 | len = (uint32_t*) ptr; |
@@ -213,12 +213,12 @@ write_cpabe (void **result, | |||
213 | len = (uint32_t*) ptr; | 213 | len = (uint32_t*) ptr; |
214 | *len = htonl (aes_buf_len); | 214 | *len = htonl (aes_buf_len); |
215 | ptr += 4; | 215 | ptr += 4; |
216 | memcpy (ptr, aes_buf, aes_buf_len); | 216 | GNUNET_memcpy (ptr, aes_buf, aes_buf_len); |
217 | ptr += aes_buf_len; | 217 | ptr += aes_buf_len; |
218 | len = (uint32_t*) ptr; | 218 | len = (uint32_t*) ptr; |
219 | *len = htonl (cph_buf_len); | 219 | *len = htonl (cph_buf_len); |
220 | ptr += 4; | 220 | ptr += 4; |
221 | memcpy (ptr, cph_buf, cph_buf_len); | 221 | GNUNET_memcpy (ptr, cph_buf, cph_buf_len); |
222 | return 12 + cph_buf_len + aes_buf_len; | 222 | return 12 + cph_buf_len + aes_buf_len; |
223 | } | 223 | } |
224 | 224 | ||
@@ -241,13 +241,13 @@ read_cpabe (const void *data, | |||
241 | *aes_buf_len = ntohl (*len); | 241 | *aes_buf_len = ntohl (*len); |
242 | ptr += 4; | 242 | ptr += 4; |
243 | *aes_buf = GNUNET_malloc (*aes_buf_len); | 243 | *aes_buf = GNUNET_malloc (*aes_buf_len); |
244 | memcpy(*aes_buf, ptr, *aes_buf_len); | 244 | GNUNET_memcpy (*aes_buf, ptr, *aes_buf_len); |
245 | ptr += *aes_buf_len; | 245 | ptr += *aes_buf_len; |
246 | len = (uint32_t*)ptr; | 246 | len = (uint32_t*)ptr; |
247 | *cph_buf_len = ntohl (*len); | 247 | *cph_buf_len = ntohl (*len); |
248 | ptr += 4; | 248 | ptr += 4; |
249 | *cph_buf = GNUNET_malloc (*cph_buf_len); | 249 | *cph_buf = GNUNET_malloc (*cph_buf_len); |
250 | memcpy(*cph_buf, ptr, *cph_buf_len); | 250 | GNUNET_memcpy (*cph_buf, ptr, *cph_buf_len); |
251 | 251 | ||
252 | return buf_len; | 252 | return buf_len; |
253 | } | 253 | } |
@@ -362,7 +362,7 @@ GNUNET_CRYPTO_cpabe_deserialize_key (const void *data, | |||
362 | &prv_len); | 362 | &prv_len); |
363 | key->pub = gabe_pub_unserialize (pub, pub_len); | 363 | key->pub = gabe_pub_unserialize (pub, pub_len); |
364 | key->prv = gabe_prv_unserialize (key->pub, prv, prv_len); | 364 | key->prv = gabe_prv_unserialize (key->pub, prv, prv_len); |
365 | 365 | ||
366 | GNUNET_free (pub); | 366 | GNUNET_free (pub); |
367 | GNUNET_free (prv); | 367 | GNUNET_free (prv); |
368 | return key; | 368 | return key; |
@@ -408,7 +408,7 @@ GNUNET_CRYPTO_cpabe_deserialize_master_key (const void *data, | |||
408 | &msk_len); | 408 | &msk_len); |
409 | key->pub = gabe_pub_unserialize (pub, pub_len); | 409 | key->pub = gabe_pub_unserialize (pub, pub_len); |
410 | key->msk = gabe_msk_unserialize (key->pub, msk, msk_len); | 410 | key->msk = gabe_msk_unserialize (key->pub, msk, msk_len); |
411 | 411 | ||
412 | GNUNET_free (pub); | 412 | GNUNET_free (pub); |
413 | GNUNET_free (msk); | 413 | GNUNET_free (msk); |
414 | 414 | ||