gcrypt: Allocate a secmem pool at startup.
authorAndre Noll <maan@tuebingen.mpg.de>
Wed, 3 Jan 2018 03:33:02 +0000 (04:33 +0100)
committerAndre Noll <maan@tuebingen.mpg.de>
Sun, 25 Feb 2018 23:10:28 +0000 (00:10 +0100)
The client side loads private keys. This patch makes sure the memory
which contains such key material is never swapped out.

gcrypt.c

index 705d0d8..ff4dab3 100644 (file)
--- a/gcrypt.c
+++ b/gcrypt.c
@@ -66,6 +66,16 @@ void crypt_init(void)
                        req_ver, gcry_check_version(NULL));
                exit(EXIT_FAILURE);
        }
+
+       /*
+        * Allocate a pool of secure memory. This also drops privileges where
+        * needed.
+        */
+       gcry_control(GCRYCTL_INIT_SECMEM, 65536, 0);
+
+       /* Tell Libgcrypt that initialization has completed. */
+       gcry_control(GCRYCTL_INITIALIZATION_FINISHED, 0);
+
        get_random_bytes_or_die((unsigned char *)&seed, sizeof(seed));
        srandom(seed);
 }