diff options
Diffstat (limited to 'src/util/crypto_random.c')
-rw-r--r-- | src/util/crypto_random.c | 45 |
1 files changed, 36 insertions, 9 deletions
diff --git a/src/util/crypto_random.c b/src/util/crypto_random.c index d5b5eb9ec..df6d3fb9b 100644 --- a/src/util/crypto_random.c +++ b/src/util/crypto_random.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 | ||
@@ -271,6 +269,28 @@ GNUNET_CRYPTO_random_u64 (enum GNUNET_CRYPTO_Quality mode, uint64_t max) | |||
271 | 269 | ||
272 | 270 | ||
273 | /** | 271 | /** |
272 | * Allocation wrapper for libgcrypt, used to avoid bad locking | ||
273 | * strategy of libgcrypt implementation. | ||
274 | */ | ||
275 | static void * | ||
276 | w_malloc (size_t n) | ||
277 | { | ||
278 | return calloc (n, 1); | ||
279 | } | ||
280 | |||
281 | |||
282 | /** | ||
283 | * Allocation wrapper for libgcrypt, used to avoid bad locking | ||
284 | * strategy of libgcrypt implementation. | ||
285 | */ | ||
286 | static int | ||
287 | w_check (const void *p) | ||
288 | { | ||
289 | return 0; /* not secure memory */ | ||
290 | } | ||
291 | |||
292 | |||
293 | /** | ||
274 | * Initialize libgcrypt. | 294 | * Initialize libgcrypt. |
275 | */ | 295 | */ |
276 | void __attribute__ ((constructor)) | 296 | void __attribute__ ((constructor)) |
@@ -285,6 +305,13 @@ GNUNET_CRYPTO_random_init () | |||
285 | NEED_LIBGCRYPT_VERSION); | 305 | NEED_LIBGCRYPT_VERSION); |
286 | GNUNET_assert (0); | 306 | GNUNET_assert (0); |
287 | } | 307 | } |
308 | /* set custom allocators */ | ||
309 | gcry_set_allocation_handler (&w_malloc, | ||
310 | &w_malloc, | ||
311 | &w_check, | ||
312 | &realloc, | ||
313 | &free); | ||
314 | /* Disable use of secure memory */ | ||
288 | if ((rc = gcry_control (GCRYCTL_DISABLE_SECMEM, 0))) | 315 | if ((rc = gcry_control (GCRYCTL_DISABLE_SECMEM, 0))) |
289 | FPRINTF (stderr, | 316 | FPRINTF (stderr, |
290 | "Failed to set libgcrypt option %s: %s\n", | 317 | "Failed to set libgcrypt option %s: %s\n", |