netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] (4/4) use system get_random_bytes in hdlcdrv
@ 2003-09-19 20:38 Stephen Hemminger
  2003-09-19 21:46 ` Andi Kleen
  0 siblings, 1 reply; 3+ messages in thread
From: Stephen Hemminger @ 2003-09-19 20:38 UTC (permalink / raw)
  To: Thomas Sailer, Jeff Garzik; +Cc: linux-hams, netdev

Real random numbers aren't important here, but having custom
random number generate seems silly when linux kernel has good
way to get random data.

diff -Nru a/drivers/net/hamradio/hdlcdrv.c b/drivers/net/hamradio/hdlcdrv.c
--- a/drivers/net/hamradio/hdlcdrv.c	Fri Sep 19 13:18:58 2003
+++ b/drivers/net/hamradio/hdlcdrv.c	Fri Sep 19 13:18:58 2003
@@ -52,6 +52,7 @@
 #include <linux/slab.h>
 #include <linux/errno.h>
 #include <linux/init.h>
+#include <linux/random.h>
 #include <asm/bitops.h>
 #include <asm/uaccess.h>
 
@@ -434,18 +435,10 @@
 
 /* ---------------------------------------------------------------------- */
 
-static unsigned short random_seed;
-
-static inline unsigned short random_num(void)
-{
-	random_seed = 28629 * random_seed + 157;
-	return random_seed;
-}
-
-/* ---------------------------------------------------------------------- */
-
 void hdlcdrv_arbitrate(struct net_device *dev, struct hdlcdrv_state *s)
 {
+	u8 prand;
+
 	if (!s || s->magic != HDLCDRV_MAGIC || s->hdlctx.ptt || !s->skb) 
 		return;
 	if (s->ch_params.fulldup) {
@@ -459,7 +452,9 @@
 	if ((--s->hdlctx.slotcnt) > 0)
 		return;
 	s->hdlctx.slotcnt = s->ch_params.slottime;
-	if ((random_num() % 256) > s->ch_params.ppersist)
+
+	get_random_bytes(&prand, sizeof(prand));
+	if (prand > s->ch_params.ppersist)
 		return;
 	start_tx(dev, s);
 }

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] (4/4) use system get_random_bytes in hdlcdrv
  2003-09-19 20:38 [PATCH] (4/4) use system get_random_bytes in hdlcdrv Stephen Hemminger
@ 2003-09-19 21:46 ` Andi Kleen
  2003-09-22 16:50   ` Stephen Hemminger
  0 siblings, 1 reply; 3+ messages in thread
From: Andi Kleen @ 2003-09-19 21:46 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: Thomas Sailer, Jeff Garzik, linux-hams, netdev

>  void hdlcdrv_arbitrate(struct net_device *dev, struct hdlcdrv_state *s)
>  {
> +	u8 prand;
> +
>  	if (!s || s->magic != HDLCDRV_MAGIC || s->hdlctx.ptt || !s->skb) 
>  		return;
>  	if (s->ch_params.fulldup) {
> @@ -459,7 +452,9 @@
>  	if ((--s->hdlctx.slotcnt) > 0)
>  		return;
>  	s->hdlctx.slotcnt = s->ch_params.slottime;
> -	if ((random_num() % 256) > s->ch_params.ppersist)
> +
> +	get_random_bytes(&prand, sizeof(prand));
> +	if (prand > s->ch_params.ppersist)

The "hard" random numbers generated by get_random_bytes
are a precious scarce resource (many systems don't generate them very often).
They should only be used as seed or when it is needed for security, otherwise
users who really need them risk blocking on /dev/random.
Especially if that function is called often it would be a bad idea.

-Andi

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] (4/4) use system get_random_bytes in hdlcdrv
  2003-09-19 21:46 ` Andi Kleen
@ 2003-09-22 16:50   ` Stephen Hemminger
  0 siblings, 0 replies; 3+ messages in thread
From: Stephen Hemminger @ 2003-09-22 16:50 UTC (permalink / raw)
  To: Andi Kleen; +Cc: Thomas Sailer, Jeff Garzik, linux-hams, netdev

On Fri, 19 Sep 2003 23:46:42 +0200
Andi Kleen <ak@suse.de> wrote:

> >  void hdlcdrv_arbitrate(struct net_device *dev, struct hdlcdrv_state *s)
> >  {
> > +	u8 prand;
> > +
> >  	if (!s || s->magic != HDLCDRV_MAGIC || s->hdlctx.ptt || !s->skb) 
> >  		return;
> >  	if (s->ch_params.fulldup) {
> > @@ -459,7 +452,9 @@
> >  	if ((--s->hdlctx.slotcnt) > 0)
> >  		return;
> >  	s->hdlctx.slotcnt = s->ch_params.slottime;
> > -	if ((random_num() % 256) > s->ch_params.ppersist)
> > +
> > +	get_random_bytes(&prand, sizeof(prand));
> > +	if (prand > s->ch_params.ppersist)
> 
> The "hard" random numbers generated by get_random_bytes
> are a precious scarce resource (many systems don't generate them very often).
> They should only be used as seed or when it is needed for security, otherwise
> users who really need them risk blocking on /dev/random.
> Especially if that function is called often it would be a bad idea.

Well go ahead an leave it out.  It gets called once, and isn't important.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2003-09-22 16:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-09-19 20:38 [PATCH] (4/4) use system get_random_bytes in hdlcdrv Stephen Hemminger
2003-09-19 21:46 ` Andi Kleen
2003-09-22 16:50   ` Stephen Hemminger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).