dect
/
libdect
Archived
13
0
Fork 0

libdect: don't reseed PRNG on dect_open_handle()

Move seeding to an __init function to avoid reseeding the PRNG multiple
times with the same seed when opening multiple handles in a short amount
of time.

While at it, switch from rand() to random() since it uses a better
PRNG in old libcs and non-Linux systems.

Signed-off-by: Patrick McHardy <kaber@trash.net>
This commit is contained in:
Patrick McHardy 2010-11-14 22:08:45 +01:00
parent 305e9be660
commit 4e04c104d1
2 changed files with 6 additions and 3 deletions

View File

@ -1550,7 +1550,7 @@ static void dect_pp_set_default_pmid(struct dect_handle *dh)
{
dect_assert(!(dh->flags & DECT_PP_TPUI));
dh->pmid = DECT_PMID_DEFAULT_ID +
(rand() & DECT_PMID_DEFAULT_NUM_MASK);
(random() & DECT_PMID_DEFAULT_NUM_MASK);
lce_debug("set default pmid %05x\n", dh->pmid);
}

View File

@ -57,8 +57,6 @@ struct dect_handle *dect_open_handle(struct dect_ops *ops, const char *cluster)
if (cluster == NULL)
cluster = "cluster0";
srand(time(NULL));
dh = dect_alloc_handle(ops);
if (dh == NULL)
goto err1;
@ -98,4 +96,9 @@ void *dect_handle_priv(struct dect_handle *dh)
}
EXPORT_SYMBOL(dect_handle_priv);
static void __init libdect_init(void)
{
srandom(time(NULL));
}
/** @} */