summaryrefslogtreecommitdiff
path: root/src/util/crypto_random.c
diff options
context:
space:
mode:
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 @@
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Affero General Public License for more details.
-
+
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
@@ -269,6 +269,28 @@ GNUNET_CRYPTO_random_u64 (enum GNUNET_CRYPTO_Quality mode, uint64_t max)
/**
+ * Allocation wrapper for libgcrypt, used to avoid bad locking
+ * strategy of libgcrypt implementation.
+ */
+static void *
+w_malloc (size_t n)
+{
+ return calloc (n, 1);
+}
+
+
+/**
+ * Allocation wrapper for libgcrypt, used to avoid bad locking
+ * strategy of libgcrypt implementation.
+ */
+static int
+w_check (const void *p)
+{
+ return 0; /* not secure memory */
+}
+
+
+/**
* Initialize libgcrypt.
*/
void __attribute__ ((constructor))
@@ -283,6 +305,13 @@ GNUNET_CRYPTO_random_init ()
NEED_LIBGCRYPT_VERSION);
GNUNET_assert (0);
}
+ /* set custom allocators */
+ gcry_set_allocation_handler (&w_malloc,
+ &w_malloc,
+ &w_check,
+ &realloc,
+ &free);
+ /* Disable use of secure memory */
if ((rc = gcry_control (GCRYCTL_DISABLE_SECMEM, 0)))
FPRINTF (stderr,
"Failed to set libgcrypt option %s: %s\n",