summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNIIBE Yutaka <gniibe@fsij.org>2018-12-19 10:28:32 +0900
committerNIIBE Yutaka <gniibe@fsij.org>2018-12-19 10:28:32 +0900
commit3028a221d39c1b593ea0c1bcbfccd33959769692 (patch)
tree16281859eadcc8a53a993077bec8e9d4be316cb4
parent876f7280e8604bc99ddda0526339ec5ec6b23c4b (diff)
downloadlibgcrypt-3028a221d39c1b593ea0c1bcbfccd33959769692.tar.gz
random: Add finalizer for rndjent.
* 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>
-rw-r--r--random/rand-internal.h1
-rw-r--r--random/rndjent.c17
-rw-r--r--random/rndlinux.c2
3 files changed, 20 insertions, 0 deletions
diff --git a/random/rand-internal.h b/random/rand-internal.h
index 2bc05f45..d99c6671 100644
--- a/random/rand-internal.h
+++ b/random/rand-internal.h
@@ -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);
diff --git a/random/rndjent.c b/random/rndjent.c
index 3740ddd4..3d01290f 100644
--- a/random/rndjent.c
+++ b/random/rndjent.c
@@ -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
+}
diff --git a/random/rndlinux.c b/random/rndlinux.c
index fefc3c37..3d41cd33 100644
--- a/random/rndlinux.c
+++ b/random/rndlinux.c
@@ -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;
}