random: Add finalizer for rndjent.
authorNIIBE Yutaka <gniibe@fsij.org>
Wed, 19 Dec 2018 01:28:32 +0000 (10:28 +0900)
committerNIIBE Yutaka <gniibe@fsij.org>
Wed, 19 Dec 2018 01:28:32 +0000 (10:28 +0900)
* random/rand-internal.h (_gcry_rndjent_fini): New.
* random/rndjent.c (_gcry_rndjent_fini): New.
* random/rndlinux.c (_gcry_rndlinux_gather_random): Call the finalizer
when GCRYCTL_CLOSE_RANDOM_DEVICE.

--

GnuPG-bug-id: 3731
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
random/rand-internal.h
random/rndjent.c
random/rndlinux.c

index 2bc05f4..d99c667 100644 (file)
@@ -132,6 +132,7 @@ size_t _gcry_rndjent_poll (void (*add)(const void*,
                            enum random_origins origin,
                            size_t length);
 void _gcry_rndjent_dump_stats (void);
+void _gcry_rndjent_fini (void);
 
 /*-- rndhw.c --*/
 int _gcry_rndhw_failed_p (void);
index 3740ddd..3d01290 100644 (file)
@@ -370,3 +370,20 @@ _gcry_rndjent_dump_stats (void)
     }
 #endif /*USE_JENT*/
 }
+
+
+void
+_gcry_rndjent_fini (void)
+{
+#ifdef USE_JENT
+  lock_rng ();
+
+  if (jent_rng_is_initialized)
+    {
+      jent_entropy_collector_free (jent_rng_collector);
+      jent_rng_collector = NULL;
+    }
+
+  unlock_rng ();
+#endif
+}
index fefc3c3..3d41cd3 100644 (file)
@@ -156,6 +156,8 @@ _gcry_rndlinux_gather_random (void (*add)(const void*, size_t,
           close (fd_urandom);
           fd_urandom = -1;
         }
+
+      _gcry_rndjent_fini ();
       return 0;
     }