1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Python: module gdata.Crypto.Util.randpool</title>
</head><body bgcolor="#f0f0f8">
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
<tr bgcolor="#7799ee">
<td valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"> <br><big><big><strong><a href="gdata.html"><font color="#ffffff">gdata</font></a>.<a href="gdata.Crypto.html"><font color="#ffffff">Crypto</font></a>.<a href="gdata.Crypto.Util.html"><font color="#ffffff">Util</font></a>.randpool</strong></big></big></font></td
><td align=right valign=bottom
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/home/afshar/wrk/gdata-python-client/src/gdata/Crypto/Util/randpool.py">/home/afshar/wrk/gdata-python-client/src/gdata/Crypto/Util/randpool.py</a></font></td></tr></table>
<p><tt># randpool.py : Cryptographically strong random number generation<br>
#<br>
# Part of the Python Cryptography Toolkit<br>
#<br>
# Distribute and use freely; there are no restrictions on further<br>
# dissemination and usage except those imposed by the laws of your<br>
# country of residence. This software is provided "as is" without<br>
# warranty of fitness for use or suitability for any purpose, express<br>
# or implied. Use at your own risk or not at all.<br>
#</tt></p>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#aa55cc">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr>
<tr><td bgcolor="#aa55cc"><tt> </tt></td><td> </td>
<td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="array.html">array</a><br>
<a href="os.html">os</a><br>
</td><td width="25%" valign=top><a href="termios.html">termios</a><br>
<a href="time.html">time</a><br>
</td><td width="25%" valign=top><a href="types.html">types</a><br>
<a href="warnings.html">warnings</a><br>
</td><td width="25%" valign=top></td></tr></table></td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ee77aa">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Classes</strong></big></font></td></tr>
<tr><td bgcolor="#ee77aa"><tt> </tt></td><td> </td>
<td width="100%"><dl>
<dt><font face="helvetica, arial"><a href="gdata.Crypto.Util.randpool.html#KeyboardEntry">KeyboardEntry</a>
</font></dt><dt><font face="helvetica, arial"><a href="gdata.Crypto.Util.randpool.html#RandomPool">RandomPool</a>
</font></dt><dd>
<dl>
<dt><font face="helvetica, arial"><a href="gdata.Crypto.Util.randpool.html#PersistentRandomPool">PersistentRandomPool</a>
</font></dt><dd>
<dl>
<dt><font face="helvetica, arial"><a href="gdata.Crypto.Util.randpool.html#KeyboardRandomPool">KeyboardRandomPool</a>
</font></dt></dl>
</dd>
</dl>
</dd>
</dl>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom> <br>
<font color="#000000" face="helvetica, arial"><a name="KeyboardEntry">class <strong>KeyboardEntry</strong></a></font></td></tr>
<tr><td bgcolor="#ffc8d8"><tt> </tt></td><td> </td>
<td width="100%">Methods defined here:<br>
<dl><dt><a name="KeyboardEntry-__init__"><strong>__init__</strong></a>(self, fd<font color="#909090">=0</font>)</dt></dl>
<dl><dt><a name="KeyboardEntry-close"><strong>close</strong></a>(self, delay<font color="#909090">=0</font>)</dt></dl>
<dl><dt><a name="KeyboardEntry-getch"><strong>getch</strong></a>(self)</dt></dl>
</td></tr></table> <p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom> <br>
<font color="#000000" face="helvetica, arial"><a name="KeyboardRandomPool">class <strong>KeyboardRandomPool</strong></a>(<a href="gdata.Crypto.Util.randpool.html#PersistentRandomPool">PersistentRandomPool</a>)</font></td></tr>
<tr><td bgcolor="#ffc8d8"><tt> </tt></td><td> </td>
<td width="100%"><dl><dt>Method resolution order:</dt>
<dd><a href="gdata.Crypto.Util.randpool.html#KeyboardRandomPool">KeyboardRandomPool</a></dd>
<dd><a href="gdata.Crypto.Util.randpool.html#PersistentRandomPool">PersistentRandomPool</a></dd>
<dd><a href="gdata.Crypto.Util.randpool.html#RandomPool">RandomPool</a></dd>
</dl>
<hr>
Methods defined here:<br>
<dl><dt><a name="KeyboardRandomPool-__init__"><strong>__init__</strong></a>(self, *args, **kwargs)</dt></dl>
<dl><dt><a name="KeyboardRandomPool-randomize"><strong>randomize</strong></a>(self, N<font color="#909090">=0</font>)</dt><dd><tt>Adds N bits of entropy to random pool. If N is 0, fill up pool.</tt></dd></dl>
<hr>
Methods inherited from <a href="gdata.Crypto.Util.randpool.html#PersistentRandomPool">PersistentRandomPool</a>:<br>
<dl><dt><a name="KeyboardRandomPool-save"><strong>save</strong></a>(self)</dt></dl>
<hr>
Methods inherited from <a href="gdata.Crypto.Util.randpool.html#RandomPool">RandomPool</a>:<br>
<dl><dt><a name="KeyboardRandomPool-addEvent"><strong>addEvent</strong></a>(self, event, s<font color="#909090">=''</font>)</dt></dl>
<dl><dt><a name="KeyboardRandomPool-add_event"><strong>add_event</strong></a>(self, s<font color="#909090">=''</font>)</dt><dd><tt><a href="#KeyboardRandomPool-add_event">add_event</a>(s:string)<br>
Add an event to the random pool. The current time is stored<br>
between calls and used to estimate the entropy. The optional<br>
's' parameter is a string that will also be XORed into the pool.<br>
Returns the estimated number of additional bits of entropy gain.</tt></dd></dl>
<dl><dt><a name="KeyboardRandomPool-getBytes"><strong>getBytes</strong></a>(self, N)</dt><dd><tt># Deprecated method names: remove in PCT 2.1 or later.</tt></dd></dl>
<dl><dt><a name="KeyboardRandomPool-get_bytes"><strong>get_bytes</strong></a>(self, N)</dt><dd><tt><a href="#KeyboardRandomPool-get_bytes">get_bytes</a>(N:int) : string<br>
Return N bytes of random data.</tt></dd></dl>
<dl><dt><a name="KeyboardRandomPool-stir"><strong>stir</strong></a>(self, s<font color="#909090">=''</font>)</dt><dd><tt><a href="#KeyboardRandomPool-stir">stir</a>(s:string)<br>
Mix up the randomness pool. This will call <a href="#KeyboardRandomPool-add_event">add_event</a>() twice,<br>
but out of paranoia the entropy attribute will not be<br>
increased. The optional 's' parameter is a string that will<br>
be hashed with the randomness pool.</tt></dd></dl>
<dl><dt><a name="KeyboardRandomPool-stir_n"><strong>stir_n</strong></a>(self, N<font color="#909090">=3</font>)</dt><dd><tt><a href="#KeyboardRandomPool-stir_n">stir_n</a>(N)<br>
stirs the random pool N times</tt></dd></dl>
</td></tr></table> <p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom> <br>
<font color="#000000" face="helvetica, arial"><a name="PersistentRandomPool">class <strong>PersistentRandomPool</strong></a>(<a href="gdata.Crypto.Util.randpool.html#RandomPool">RandomPool</a>)</font></td></tr>
<tr><td bgcolor="#ffc8d8"><tt> </tt></td><td> </td>
<td width="100%">Methods defined here:<br>
<dl><dt><a name="PersistentRandomPool-__init__"><strong>__init__</strong></a>(self, filename<font color="#909090">=None</font>, *args, **kwargs)</dt></dl>
<dl><dt><a name="PersistentRandomPool-save"><strong>save</strong></a>(self)</dt></dl>
<hr>
Methods inherited from <a href="gdata.Crypto.Util.randpool.html#RandomPool">RandomPool</a>:<br>
<dl><dt><a name="PersistentRandomPool-addEvent"><strong>addEvent</strong></a>(self, event, s<font color="#909090">=''</font>)</dt></dl>
<dl><dt><a name="PersistentRandomPool-add_event"><strong>add_event</strong></a>(self, s<font color="#909090">=''</font>)</dt><dd><tt><a href="#PersistentRandomPool-add_event">add_event</a>(s:string)<br>
Add an event to the random pool. The current time is stored<br>
between calls and used to estimate the entropy. The optional<br>
's' parameter is a string that will also be XORed into the pool.<br>
Returns the estimated number of additional bits of entropy gain.</tt></dd></dl>
<dl><dt><a name="PersistentRandomPool-getBytes"><strong>getBytes</strong></a>(self, N)</dt><dd><tt># Deprecated method names: remove in PCT 2.1 or later.</tt></dd></dl>
<dl><dt><a name="PersistentRandomPool-get_bytes"><strong>get_bytes</strong></a>(self, N)</dt><dd><tt><a href="#PersistentRandomPool-get_bytes">get_bytes</a>(N:int) : string<br>
Return N bytes of random data.</tt></dd></dl>
<dl><dt><a name="PersistentRandomPool-randomize"><strong>randomize</strong></a>(self, N<font color="#909090">=0</font>)</dt><dd><tt><a href="#PersistentRandomPool-randomize">randomize</a>(N:int)<br>
use the class entropy source to get some entropy data.<br>
This is overridden by KeyboardRandomize().</tt></dd></dl>
<dl><dt><a name="PersistentRandomPool-stir"><strong>stir</strong></a>(self, s<font color="#909090">=''</font>)</dt><dd><tt><a href="#PersistentRandomPool-stir">stir</a>(s:string)<br>
Mix up the randomness pool. This will call <a href="#PersistentRandomPool-add_event">add_event</a>() twice,<br>
but out of paranoia the entropy attribute will not be<br>
increased. The optional 's' parameter is a string that will<br>
be hashed with the randomness pool.</tt></dd></dl>
<dl><dt><a name="PersistentRandomPool-stir_n"><strong>stir_n</strong></a>(self, N<font color="#909090">=3</font>)</dt><dd><tt><a href="#PersistentRandomPool-stir_n">stir_n</a>(N)<br>
stirs the random pool N times</tt></dd></dl>
</td></tr></table> <p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom> <br>
<font color="#000000" face="helvetica, arial"><a name="RandomPool">class <strong>RandomPool</strong></a></font></td></tr>
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td>
<td colspan=2><tt>randpool.py : Cryptographically strong random number generation.<br>
<br>
The implementation here is similar to the one in PGP. To be<br>
cryptographically strong, it must be difficult to determine the RNG's<br>
output, whether in the future or the past. This is done by using<br>
a cryptographic hash function to "stir" the random data.<br>
<br>
Entropy is gathered in the same fashion as PGP; the highest-resolution<br>
clock around is read and the data is added to the random number pool.<br>
A conservative estimate of the entropy is then kept.<br>
<br>
If a cryptographically secure random source is available (/dev/urandom<br>
on many Unixes, Windows CryptGenRandom on most Windows), then use<br>
it.<br>
<br>
Instance Attributes:<br>
bits : int<br>
Maximum size of pool in bits<br>
bytes : int<br>
Maximum size of pool in bytes<br>
entropy : int<br>
Number of bits of entropy in this pool.<br>
<br>
Methods:<br>
<a href="#RandomPool-add_event">add_event</a>([s]) : add some entropy to the pool<br>
<a href="#RandomPool-get_bytes">get_bytes</a>(int) : get N bytes of random data<br>
<a href="#RandomPool-randomize">randomize</a>([N]) : get N bytes of randomness from external source<br> </tt></td></tr>
<tr><td> </td>
<td width="100%">Methods defined here:<br>
<dl><dt><a name="RandomPool-__init__"><strong>__init__</strong></a>(self, numbytes<font color="#909090">=160</font>, cipher<font color="#909090">=None</font>, hash<font color="#909090">=None</font>)</dt></dl>
<dl><dt><a name="RandomPool-addEvent"><strong>addEvent</strong></a>(self, event, s<font color="#909090">=''</font>)</dt></dl>
<dl><dt><a name="RandomPool-add_event"><strong>add_event</strong></a>(self, s<font color="#909090">=''</font>)</dt><dd><tt><a href="#RandomPool-add_event">add_event</a>(s:string)<br>
Add an event to the random pool. The current time is stored<br>
between calls and used to estimate the entropy. The optional<br>
's' parameter is a string that will also be XORed into the pool.<br>
Returns the estimated number of additional bits of entropy gain.</tt></dd></dl>
<dl><dt><a name="RandomPool-getBytes"><strong>getBytes</strong></a>(self, N)</dt><dd><tt># Deprecated method names: remove in PCT 2.1 or later.</tt></dd></dl>
<dl><dt><a name="RandomPool-get_bytes"><strong>get_bytes</strong></a>(self, N)</dt><dd><tt><a href="#RandomPool-get_bytes">get_bytes</a>(N:int) : string<br>
Return N bytes of random data.</tt></dd></dl>
<dl><dt><a name="RandomPool-randomize"><strong>randomize</strong></a>(self, N<font color="#909090">=0</font>)</dt><dd><tt><a href="#RandomPool-randomize">randomize</a>(N:int)<br>
use the class entropy source to get some entropy data.<br>
This is overridden by KeyboardRandomize().</tt></dd></dl>
<dl><dt><a name="RandomPool-stir"><strong>stir</strong></a>(self, s<font color="#909090">=''</font>)</dt><dd><tt><a href="#RandomPool-stir">stir</a>(s:string)<br>
Mix up the randomness pool. This will call <a href="#RandomPool-add_event">add_event</a>() twice,<br>
but out of paranoia the entropy attribute will not be<br>
increased. The optional 's' parameter is a string that will<br>
be hashed with the randomness pool.</tt></dd></dl>
<dl><dt><a name="RandomPool-stir_n"><strong>stir_n</strong></a>(self, N<font color="#909090">=3</font>)</dt><dd><tt><a href="#RandomPool-stir_n">stir_n</a>(N)<br>
stirs the random pool N times</tt></dd></dl>
</td></tr></table></td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#55aa55">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Data</strong></big></font></td></tr>
<tr><td bgcolor="#55aa55"><tt> </tt></td><td> </td>
<td width="100%"><strong>STIRNUM</strong> = 3<br>
<strong>__revision__</strong> = '$Id: randpool.py,v 1.14 2004/05/06 12:56:54 akuchling Exp $'<br>
<strong>winrandom</strong> = None</td></tr></table>
</body></html>
|