aboutsummaryrefslogtreecommitdiff
path: root/src/util/crypto_random.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2018-08-11 06:20:40 +0200
committerChristian Grothoff <christian@grothoff.org>2018-08-11 06:20:40 +0200
commitba30221f3588d75b3073cd737fbbf6d0c80e5906 (patch)
treeaf268deae97db1d58c5f84381d15e49740484753 /src/util/crypto_random.c
parent0f54ff0768d776d07231418e6370602c3789ee56 (diff)
downloadgnunet-ba30221f3588d75b3073cd737fbbf6d0c80e5906.tar.gz
gnunet-ba30221f3588d75b3073cd737fbbf6d0c80e5906.zip
introduce allocation wrappers to improve libgcrypt performance
Diffstat (limited to 'src/util/crypto_random.c')
-rw-r--r--src/util/crypto_random.c31
1 files changed, 30 insertions, 1 deletions
diff --git a/src/util/crypto_random.c b/src/util/crypto_random.c
index 2163a9731..df6d3fb9b 100644
--- a/src/util/crypto_random.c
+++ b/src/util/crypto_random.c
@@ -11,7 +11,7 @@
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
@@ -269,6 +269,28 @@ GNUNET_CRYPTO_random_u64 (enum GNUNET_CRYPTO_Quality mode, uint64_t max)
269 269
270 270
271/** 271/**
272 * Allocation wrapper for libgcrypt, used to avoid bad locking
273 * strategy of libgcrypt implementation.
274 */
275static void *
276w_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 */
286static int
287w_check (const void *p)
288{
289 return 0; /* not secure memory */
290}
291
292
293/**
272 * Initialize libgcrypt. 294 * Initialize libgcrypt.
273 */ 295 */
274void __attribute__ ((constructor)) 296void __attribute__ ((constructor))
@@ -283,6 +305,13 @@ GNUNET_CRYPTO_random_init ()
283 NEED_LIBGCRYPT_VERSION); 305 NEED_LIBGCRYPT_VERSION);
284 GNUNET_assert (0); 306 GNUNET_assert (0);
285 } 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 */
286 if ((rc = gcry_control (GCRYCTL_DISABLE_SECMEM, 0))) 315 if ((rc = gcry_control (GCRYCTL_DISABLE_SECMEM, 0)))
287 FPRINTF (stderr, 316 FPRINTF (stderr,
288 "Failed to set libgcrypt option %s: %s\n", 317 "Failed to set libgcrypt option %s: %s\n",