aboutsummaryrefslogtreecommitdiffstats
path: root/src/libstrongswan/utils/chunk.c
diff options
context:
space:
mode:
authorMartin Willi <martin@revosec.ch>2014-04-03 11:46:09 +0200
committerMartin Willi <martin@revosec.ch>2014-06-04 15:53:11 +0200
commit460adb5d0925f4af807b09434b771545d1f62b47 (patch)
tree12c6bec9eb811c715d079e82e50840b865ecdb96 /src/libstrongswan/utils/chunk.c
parent5cd28cd25a009fd4d0d5b91b60e82cf7a661a169 (diff)
downloadstrongswan-460adb5d0925f4af807b09434b771545d1f62b47.tar.bz2
strongswan-460adb5d0925f4af807b09434b771545d1f62b47.tar.xz
unit-tests: Seed chunk_hash() only once, but before creating any hashtables
Due to the removal of pthread_once, we manually create the seed for chunk_hash(). With the new testable functions interface, this won't work for the hashtable initiated using __attribute__((constructor)). Enforce seeding before creating that hashtable.
Diffstat (limited to 'src/libstrongswan/utils/chunk.c')
-rw-r--r--src/libstrongswan/utils/chunk.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/libstrongswan/utils/chunk.c b/src/libstrongswan/utils/chunk.c
index ef79a7453..1a9674f4d 100644
--- a/src/libstrongswan/utils/chunk.c
+++ b/src/libstrongswan/utils/chunk.c
@@ -917,10 +917,17 @@ static u_char static_key[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
*/
void chunk_hash_seed()
{
+ static bool seeded = FALSE;
ssize_t len;
size_t done = 0;
int fd;
+ if (seeded)
+ {
+ /* just once to have the same seed during the whole process lifetimes */
+ return;
+ }
+
fd = open("/dev/urandom", O_RDONLY);
if (fd >= 0)
{
@@ -944,6 +951,7 @@ void chunk_hash_seed()
key[done] = (u_char)random();
}
}
+ seeded = TRUE;
}
/**