From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1164f8,19ab04458779b99e X-Google-Attributes: gid1164f8,public X-Google-Thread: 102b75,d5991e208f8d5b5b X-Google-Attributes: gid102b75,public From: billm@cygnus.com (Bill Moyer) Subject: Re: Steal their thunder (was Re: Alpha window of opportunity?) Date: 1998/06/11 Message-ID: <6lp8a8$crd$1@andros.cygnus.com>#1/1 X-Deja-AN: 361805248 References: <6l5gh1$vjc$1@piglet.cc.uic.edu> <357E265D.D42F5D98@shore.net> <6lmgtd$aer$1@andros.cygnus.com> <357F78F4.15322973@shore.net> Organization: Subtle, but there. Newsgroups: comp.arch,comp.sys.dec In article <357F78F4.15322973@shore.net> Russell Sasamori writes: >> Regarding LFSR's, wide integers still help you here when you are >>implementing your LFSR ADT as multiple LFSR's operating in parallel, >>with each register representing a bitslice of all of the LFSR's. > >I'm trying to visualize this. Would it help if I turned my head >sideways? If possible I would like to see an example in C code. Sure .. here's an NLFSR ADT I wrote a while ago which implements eight parallel LFSR's in a byte stream and uses multiple eight-stream LFSR's to generate random numbers via a nonlinear function. It's not very optimized code, but then when I wrote it performance wasn't an issue. /* LFSR.H -- defining the Linear Feedback Shift Register ADT */ #include typedef struct lfsrtag { int32 mag; /* number of bytes pointed to by d */ int32 finger; /* roving pointer into d[] to front/list */ int32 mix; /* bitmask of xor elements */ byte *d; /* data */ } lfsrt; /* LFSR.C -- defining the Linear Feedback Shift Register ADT */ #include "lfsr.h" /* crank() extracts a byte from the lfsr, performs the */ /* "mix" to generate the replacement byte, and returns */ /* the extracted byte. */ byte crank ( lfsr ) lfsrt *lfsr; { byte retval; byte vat; int32 targ; int32 index; int32 mix = lfsr->mix; retval = lfsr->d[lfsr->finger]; targ = lfsr->finger; lfsr->finger++; if ( lfsr->finger == lfsr->mag ) lfsr->finger = 0; vat = 0; index = 0; while(mix) { if ( mix & 1 ) { index = index + targ; if ( index >= lfsr->mag ) index -= lfsr->mag; if ( index >= lfsr->mag ) index -= lfsr->mag; vat ^= lfsr->d[index]; } index++; mix >>= 1; } lfsr->d[targ] = vat; return retval; } /* nonlinear() returns a byte calculated by performing a nonlinear */ /* operation on bytes extracted from three lfsr's. The byte stream */ /* obtained from nonlinear() is not suceptible to the correlation */ /* attack, and is a cryptographically strong source of randomness */ /* given that the lfsr's were initialized with random data from a */ /* cryptographically strong source. */ byte nonlinear ( a, b, c ) byte a, b, c; { byte retval; byte upper; word32 pot; int i = 0; pot = a * b; while ( pot && !(pot&1) ) { i++; pot >>= 1; } i++; pot >>= 1; retval = pot << i; if (i>=8) return c; if (!pot) return c; upper = c << (8-i); retval ^= upper >> (8-i); return retval; } ****DISCLAIMER****DISCLAIMER****DISCLAIMER****DISCLAIMER****DISCLAIMER**** Whether or not this NLFSR actually can be a cryptographically strong source of randomness is anyone's guess. I make no claims about its appropriateness for any task whatsoever, despite the comments in the code. It has been somewhat tested and appears to operate well. ****DISCLAIMER****DISCLAIMER****DISCLAIMER****DISCLAIMER****DISCLAIMER**** Note - stdtypes.h is an automatically generated file. The "stdtypes" utility tests the host computer for various characteristics and creates the .h file with a bunch of standard values and types. I use it as a matter of course with most of my personal projects and distribute it with them, to make writing portable and clearly-defined C code easier. Feel free to use/promulgate it. The source is a little large to politely dis- tribute in a newsgroup, so I stuck it at my workplace web site: A sample stdtypes.h file is at: -- Bill Moyer