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

Commit e0ad5da

Browse files
committed
Provide magic function when compiling against openssl
1 parent dc23e6e commit e0ad5da

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

libtac/lib/magic.c

+31
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,35 @@ magic()
9090
return (u_int32_t)random();
9191
}
9292

93+
#else
94+
95+
#include <openssl/rand.h>
96+
97+
INITIALIZER(magic_init)
98+
{
99+
long seed = 0;
100+
struct timeval t;
101+
102+
RAND_load_file("/dev/urandom", sizeof(seed));
103+
104+
gettimeofday(&t, NULL);
105+
seed = gethostid() ^ t.tv_sec ^ t.tv_usec ^ getpid();
106+
107+
RAND_seed(&seed, sizeof(seed));
108+
}
109+
110+
/*
111+
* magic - Returns the next magic number.
112+
*/
113+
u_int32_t
114+
magic()
115+
{
116+
u_int32_t num;
117+
118+
RAND_bytes((unsigned char *)&num, sizeof(num));
119+
120+
return num;
121+
}
122+
93123
#endif
124+

0 commit comments

Comments
 (0)