GNUnet 0.28.0-dev.5-30-g71440b34f
 
Loading...
Searching...
No Matches
crypto_gcrypt.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2001-2026 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
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/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19
20 */
21
40#include "platform.h"
41#include "gnunet_util_lib.h"
42#include <gcrypt.h>
43
44
49static void *
50w_malloc (size_t n)
51{
52 return calloc (n, 1);
53}
54
55
60static int
61w_check (const void *p)
62{
63 (void) p;
64 return 0; /* not secure memory */
65}
66
67
68void
70
74void __attribute__ ((constructor))
76{
77 gcry_error_t rc;
78
79 if (! gcry_check_version (NEED_LIBGCRYPT_VERSION))
80 {
81 fprintf (
82 stderr,
83 _ ("libgcrypt has not the expected version (version %s is required).\n"),
84 NEED_LIBGCRYPT_VERSION);
85 GNUNET_assert (0);
86 }
87 /* set custom allocators */
88 gcry_set_allocation_handler (&w_malloc, &w_malloc, &w_check, &realloc, &free);
89 /* Disable use of secure memory */
90 if ((rc = gcry_control (GCRYCTL_DISABLE_SECMEM, 0)))
91 fprintf (stderr,
92 "Failed to set libgcrypt option %s: %s\n",
93 "DISABLE_SECMEM",
94 gcry_strerror (rc));
95 /* Otherwise gnunet-ecc takes forever to complete, besides
96 we are fine with "just" using GCRY_STRONG_RANDOM */
97 if ((rc = gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0)))
98 fprintf (stderr,
99 "Failed to set libgcrypt option %s: %s\n",
100 "ENABLE_QUICK_RANDOM",
101 gcry_strerror (rc));
102 gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);
103}
104
105
106void
108
112void __attribute__ ((destructor))
114{
115 gcry_set_progress_handler (NULL, NULL);
116#ifdef GCRYCTL_CLOSE_RANDOM_DEVICE
117 (void) gcry_control (GCRYCTL_CLOSE_RANDOM_DEVICE, 0);
118#endif
119}
120
121
122/* end of crypto_gcrypt.c */
void GNUNET_CRYPTO_gcrypt_fini(void)
void GNUNET_CRYPTO_gcrypt_init(void)
static void * w_malloc(size_t n)
Allocation wrapper for libgcrypt, used to avoid bad locking strategy of libgcrypt implementation.
static int w_check(const void *p)
Allocation wrapper for libgcrypt, used to avoid bad locking strategy of libgcrypt implementation.
static struct GNUNET_Process * p
Helper process we started.
Definition gnunet-uri.c:38
struct GNUNET_PQ_ResultSpec __attribute__
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define _(String)
GNU gettext support macro.
Definition platform.h:179