lkml.org 
[lkml]   [2001]   [Feb]   [23]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: random PID generation
On Fri, 23 Feb 2001, Sean Hunter wrote:

> I have already written a 2.2 implementation which does not suffer from these
> problems. It was rejected because Alan Cox (and others) felt it only provided
> security through obscurity.
>
> Sean

The following is a simple random generator that will never give two
consecutive like numbers (therefore it's not really random). It's
pretty good for things like non-guessible PIDs, TCP/IP ports, etc.
Just mask off the length that you don't need. It this was called
occasionally from some timer or other interrupt, you don't even know its
starting value. With the current magic number, it's period is 0xfffnnnnn.
Several years ago, I ran an exhaustive search program (133MHz CPU) looking
for a magic number to produce a longer period. I'm told that there
is a magic number that will give a period of 0xffffffff.


static int rnn = 0;

static int rnd()
{
int ret;
__asm__ __volatile__(
"\tmovl (rnn), %%eax\n"
"\trorl $3, %%eax\n"
"\taddl $0x586c3ec3, %%eax\n"
"\tmovl %%eax, (rnn)\n"
: "=eax" (ret) );
return ret;
}


Cheers,
Dick Johnson

Penguin : Linux version 2.4.1 on an i686 machine (799.53 BogoMips).

"Memory is like gasoline. You use it up when you are running. Of
course you get it all back when you reboot..."; Actual explanation
obtained from the Micro$oft help desk.


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 13:17    [W:0.049 / U:0.548 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site