📄 16-02.html
字号:
<!-- END SUB HEADER -->
<!--Begin Content Column -->
<FONT FACE="Arial,Helvetica" SIZE="-1">
To access the contents, click the chapter and section titles.
</FONT>
<P>
<B>Applied Cryptography, Second Edition: Protocols, Algorthms, and Source Code in C (cloth)</B>
<FONT SIZE="-1">
<BR>
<I>(Publisher: John Wiley & Sons, Inc.)</I>
<BR>
Author(s): Bruce Schneier
<BR>
ISBN: 0471128457
<BR>
Publication Date: 01/01/96
</FONT>
<P>
<form name="Search" method="GET" action="http://search.earthweb.com/search97/search_redir.cgi">
<INPUT TYPE="hidden" NAME="Action" VALUE="Search">
<INPUT TYPE="hidden" NAME="SearchPage" VALUE="http://search.earthweb.com/search97/samples/forms/srchdemo.htm">
<INPUT TYPE="hidden" NAME="Collection" VALUE="ITK">
<INPUT TYPE="hidden" NAME="ResultTemplate" VALUE="itk-full.hts">
<INPUT TYPE="hidden" NAME="ViewTemplate" VALUE="view.hts">
<font face="arial, helvetica" size=2><b>Search this book:</b></font><br>
<INPUT NAME="queryText" size=50 VALUE=""> <input type="submit" name="submitbutton" value="Go!">
<INPUT type=hidden NAME="section_on" VALUE="on">
<INPUT type=hidden NAME="section" VALUE="http://www.itknowledge.com/reference/standard/0471128457/">
</form>
<!-- Empty Reference Subhead -->
<!--ISBN=0471128457//-->
<!--TITLE=APPLIED CRYPTOGRAPHY, SECOND EDITION: Protocols, Algorithms, and Source Code in C//-->
<!--AUTHOR=Bruce Schneier//-->
<!--PUBLISHER=Wiley Computer Publishing//-->
<!--CHAPTER=16//-->
<!--PAGES=371-374//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="16-01.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="16-03.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<P>Linear congruential generators remain useful for noncryptographic applications, however, such as simulations. They are efficient and show good statistical behavior with respect to most reasonable empirical tests. Considerable information on linear congruential generators and their implementations can be found in [942].
</P>
<P><FONT SIZE="+1"><B><I>Combining Linear Congruential Generators</I></B></FONT></P>
<P>Various people examined the combination of linear congruential generators [1595,941]. The results are no more cryptographically secure, but the combinations have longer periods and perform better in some randomness tests.
</P>
<P>Use this generator for 32-bit computers [941]:</P>
<!-- CODE //-->
<PRE>
static long s1 = 1 ; /* A “long” must be 32 bits long. */ static long s2 = 1 ;
#define MODMULT(a,b,c,m,s) q = s/a; s = b*(s-a*q) - c*q; if (s<0) s+=m ;
/* MODMULT(a,b,c,m,s) computes s*b mod m, provided that m=a*b+c and 0 <= c < m. */
/* combinedLCG returns a pseudorandom real value in the range
* (0,1). It combines linear congruential generators with
* periods of 2<SUP>31</SUP>-85 and 2<SUP>31</SUP>-249, and has a period that is the
* product of these two prime numbers. */
double combinedLCG ( void )
{
long q ;
long z ;
MODMULT ( 53668, 40014, 12211, 2147483563L, s1 )
MODMULT ( 52774, 40692, 3791, 2147483399L, s2 )
z = s1 - s2 ;
if ( z < 1 )
z += 2147483562 ;
return z * 4.656613e-10 ;
}
/* In general, call initLCG before using combinedLCG. */
void initLCG ( long InitS1, long InitS2 )
{
s1 = InitS1 ;
s2 = InitS2 ;
}
</PRE>
<!-- END CODE //-->
<P>This generator works as long as the machine can represent all integers between-2<SUP>31</SUP> + 85 and 2<SUP>31</SUP> - 85. The variables, <I>s</I><SUB>1</SUB> and <I>s</I><SUB>2</SUB>, are global; they hold the current state of the generator. Before the first call, they must be initialized. The variable <I>s</I><SUB>1</SUB> needs an initial value between 1 and 2147483562; the variable <I>s</I><SUB>2</SUB> needs an initial value between 1 and 2147483398. The generator has a period somewhere in the neighborhood of 10<SUP>18</SUP>.</P>
<P>If you only have a 16-bit computer, use this generator instead:</P>
<!-- CODE //-->
<PRE>
static int s1 = 1 ; /* An “int” must be 16 bits long. */
static int s2 = 1 ;
static int s3 = 1 ;
#define MODMULT(a,b,c,m,s) q = s/a; s = b*(s-a*q) - c*q; if
(s<0) s+=m ;
/* combined LCG returns a pseudorandom real value in the
range
* (0,1). It combines linear congruential generators with
* periods of 2<SUP>15</SUP>-405, 2<SUP>15</SUP>-1041, and 2<SUP>15</SUP>-1111, and has a period
* that is the product of these three prime numbers. */
double combinedLCG ( void )
{
int q ;
int z ;
MODMULT ( 206, 157, 21, 32363, s1 )
MODMULT ( 217, 146, 45, 31727, s2 )
MODMULT ( 222, 142, 133, 31657, s3 )
z = s1 - s2 ;
if ( z > 706 )
z -= 32362 ;
z += s3 ;
if ( z < 1 )
z += 32362 ;
return z * 3.0899e-5 ;
}
/* In general, call initLCG before using combinedLCG. */
void initLCG ( int InitS1, int InitS2, InitS3 )
{
s1 = InitS1 ;
s2 = InitS2 ;
s3 = InitS3 ;
}
</PRE>
<!-- END CODE //-->
<P>This generator works as long as the machine can represent all integers between-32363 and 32363. The variables, <I>s</I><SUB>1</SUB>, <I>s</I><SUB>2</SUB>, and <I>s</I><SUB>3</SUB>, are global; they hold the current state of the generator. Before the first call, they must be initialized. The variable <I>s</I><SUB>1</SUB> needs an initial value between 1 and 32362. The variable <I>s</I><SUB>2</SUB> needs an initial value between 1 and 31726. The variable <I>s</I><SUB>3</SUB> needs an initial value between 1 and 31656. This generator has a period of 1.6*10<SUP>13</SUP>.</P>
<P>For both of these generators, the constant term <I>b</I> in the linear congruence is 0.</P>
<H3><A NAME="Heading3"></A><FONT COLOR="#000077">16.2 Linear Feedback Shift Registers</FONT></H3>
<P>Shift register sequences are used in both cryptography and coding theory. There is a wealth of theory about them; stream ciphers based on shift registers have been the workhorse of military cryptography since the beginnings of electronics.
</P>
<P>A <B>feedback shift register</B> is made up of two parts: a shift register and a <B>feedback function</B> (see Figure 16.1). The shift register is a sequence of bits. (The <B>length</B> of a shift register is figured in bits; if it is <I>n</I> bits long, it is called an <I>n-</I>bit shift register.) Each time a bit is needed, all of the bits in the shift register are shifted 1 bit to the right. The new left-most bit is computed as a function of the other bits in the register. The output of the shift register is 1 bit, often the least significant bit. The <B>period</B> of a shift register is the length of the output sequence before it starts repeating.</P>
<P>Cryptographers have liked stream ciphers made up of shift registers: They are easily implemented in digital hardware. I will only touch on the mathematical theory. Ernst Selmer, the Norwegian government’s chief cryptographer, worked out the theory of shift register sequences in 1965 [1411]. Solomon Golomb, an NSA mathematician, wrote a book with Selmer’s results and some of his own [643]. See also [970,971,1647].</P>
<P>The simplest kind of feedback shift register is a <B>linear feedback shift register</B>, or LFSR (see Figure 16.2). The feedback function is simply the XOR of certain bits in the register; the list of these bits is called a <B>tap sequence</B>. Sometimes this is called a <B>Fibonacci configuration</B>. Because of the simple feedback sequence, a large body of mathematical theory can be applied to analyzing LFSRs. Cryptographers like to analyze sequences to convince themselves that they are random enough to be secure. LFSRs are the most common type of shift registers used in cryptography.</P>
<P>Figure 16.3 is a 4-bit LFSR tapped at the first and fourth bit. If it is initialized with the value 1111, it produces the following sequence of internal states before repeating:</P>
<DL>
<DD>1 1 1 1
<DD>0 1 1 1
<DD>1 0 1 1
<DD>0 1 0 1
<DD>1 0 1 0
<DD>1 1 0 1
<DD>0 1 1 0
<DD>0 0 1 1
<DD>1 0 0 1
<DD>0 1 0 0
<DD>0 0 1 0
<DD>0 0 0 1
<DD>1 0 0 0
<DD>1 1 0 0
<DD>1 1 1 0
</DL>
<I><P><A NAME="Fig1"></A><A HREF="javascript:displayWindow('images/16-01.jpg',282,87 )"><IMG SRC="images/16-01t.jpg"></A>
<BR><A HREF="javascript:displayWindow('images/16-01.jpg',282,87)"><FONT COLOR="#000077"><B>Figure 16.1</B></FONT></A> Feedback shift register.</I>
<I></P>
<P><A NAME="Fig2"></A><A HREF="javascript:displayWindow('images/16-02.jpg',309,92 )"><IMG SRC="images/16-02t.jpg"></A>
<BR><A HREF="javascript:displayWindow('images/16-02.jpg',309,92)"><FONT COLOR="#000077"><B>Figure 16.2</B></FONT></A> Linear feedback shift register.</I>
</P>
<P>The output sequence is the string of least significant bits:
</P>
<DL>
<DD>1 1 1 1 0 1 0 1 1 0 0 1 0 0 0....
</DL>
<P>An <I>n-</I>bit LFSR can be in one of 2<SUP>n</SUP> - 1 internal states. This means that it can, in theory, generate a 2<SUP>n</SUP> - 1-bit-long pseudo-random sequence before repeating. (It’s 2<SUP>n</SUP> - 1 and not 2<SUP>n</SUP> because a shift register filled with zeros will cause the LFSR to output a neverending stream of zeros—this is not particularly useful.) Only LFSRs with certain tap sequences will cycle through all 2<SUP>n</SUP> - 1 internal states; these are the maximal-period LFSRs. The resulting output sequence is called an <B>m-sequence</B>.</P><P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="16-01.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="16-03.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
[an error occurred while processing this directive]
<!-- all of the reference materials (books) have the footer and subfoot reveresed --><!-- reference_subfoot = footer --><!-- reference_footer = subfoot --><!-- BEGIN SUB FOOTER --> <br><br> </TD> </TR> </TABLE> <table width="640" border=0 cellpadding=0 cellspacing=0> <tr> <td align="left" width=135><img src="/images/white.gif" width=100 height="1" alt="" border="0"></td> <!-- END SUB FOOTER -->
<!-- all of the books have the footer and subfoot reveresed --><!-- reference_subfoot = footer --><!-- reference_footer = subfoot --><!-- FOOTER --> <td width="515" align="left" bgcolor="#FFFFFF"><font face="arial, helvetica" size="1"><b><a href="/products.html"><font color="#006666">Products</font></a> | <a href="/contactus.html"><font color="#006666">Contact Us</font></a> | <a href="/aboutus.html"><font color="#006666">About Us</font></a> | <a href="http://www.earthweb.com/corporate/privacy.html" target="_blank"><font color="#006666">Privacy</font></a> | <a href="http://www.itmarketer.com/" target="_blank"><font color="#006666">Ad Info</font></a> | <a href="/"><font color="#006666">Home</font></a></b> <br><br> Use of this site is subject to certain <a href="/agreement.html">Terms & Conditions</a>, <a href="/copyright.html">Copyright © 1996-1999 EarthWeb Inc.</a><br> All rights reserved. Reproduction whole or in part in any form or medium without express written permision of EarthWeb is prohibited.</font><p></td> </tr></table></BODY></HTML><!-- END FOOTER -->
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -