diff options
author | Werner Koch <wk@gnupg.org> | 2013-12-11 16:59:41 +0100 |
---|---|---|
committer | Werner Koch <wk@gnupg.org> | 2013-12-11 17:01:15 +0100 |
commit | cd548ba2dc777b8b27d8d33182ba733c20222120 (patch) | |
tree | 58b2151b8e12bf23958e946554de4fd0ee86ee97 /random/random.c | |
parent | eae1e7712e1b687bd77eb37d0eb505fc9d46d93c (diff) | |
download | libgcrypt-cd548ba2dc777b8b27d8d33182ba733c20222120.tar.gz |
random: Add a feature to close device file descriptors.
* src/gcrypt.h.in (GCRYCTL_CLOSE_RANDOM_DEVICE): New.
* src/global.c (_gcry_vcontrol): Call _gcry_random_close_fds.
* random/random.c (_gcry_random_close_fds): New.
* random/random-csprng.c (_gcry_rngcsprng_close_fds): New.
* random/random-fips.c (_gcry_rngfips_close_fds): New.
* random/random-system.c (_gcry_rngsystem_close_fds): New.
* random/rndlinux.c (open_device): Add arg retry.
(_gcry_rndlinux_gather_random): Add mode to close open fds.
* tests/random.c (check_close_random_device): New.
(main): Call new test.
Signed-off-by: Werner Koch <wk@gnupg.org>
Diffstat (limited to 'random/random.c')
-rw-r--r-- | random/random.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/random/random.c b/random/random.c index 46793013..97018c42 100644 --- a/random/random.c +++ b/random/random.c @@ -165,6 +165,27 @@ _gcry_random_initialize (int full) } +/* If possible close file descriptors used by the RNG. */ +void +_gcry_random_close_fds (void) +{ + /* Note that we can't do that directly because each random system + has its own lock functions which need to be used for accessing + the entropy gatherer. */ + + if (fips_mode ()) + _gcry_rngfips_close_fds (); + else if (rng_types.standard) + _gcry_rngcsprng_close_fds (); + else if (rng_types.fips) + _gcry_rngfips_close_fds (); + else if (rng_types.system) + _gcry_rngsystem_close_fds (); + else + _gcry_rngcsprng_close_fds (); +} + + /* Return the current RNG type. IGNORE_FIPS_MODE is a flag used to skip the test for FIPS. This is useful, so that we are able to return the type of the RNG even before we have setup FIPS mode |