Skip to content
This repository has been archived by the owner on Feb 28, 2024. It is now read-only.

Commit

Permalink
Provide magic function when compiling against openssl
Browse files Browse the repository at this point in the history
  • Loading branch information
pprindeville committed Oct 7, 2016
1 parent 531b9fb commit 75e914e
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions libtac/lib/magic.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,35 @@ magic()
return (u_int32_t)random();
}

#else

#include <openssl/rand.h>

INITIALIZER(magic_init)
{
long seed = 0;
struct timeval t;

RAND_load_file("/dev/urandom", sizeof(seed));

gettimeofday(&t, NULL);
seed = gethostid() ^ t.tv_sec ^ t.tv_usec ^ getpid();

RAND_seed(&seed, sizeof(seed));
}

/*
* magic - Returns the next magic number.
*/
u_int32_t
magic()
{
u_int32_t num;

RAND_bytes((unsigned char *)&num, sizeof(num));

return num;
}

#endif

0 comments on commit 75e914e

Please sign in to comment.