~exarkun/pyopenssl/trunk

« back to all changes in this revision

Viewing changes to doc/api/rand.rst

  • Committer: Jean-Paul Calderone
  • Date: 2011-09-11 19:49:43 UTC
  • mfrom: (156.3.22 sphinx-doc)
  • Revision ID: exarkun@divmod.com-20110911194943-ucaan2tzidk7ek5l
Convert the documentation from LaTeX/epytext to Sphinx/ReST

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
.. _openssl-rand:
 
2
 
 
3
:py:mod:`rand` --- An interface to the OpenSSL pseudo random number generator
 
4
=============================================================================
 
5
 
 
6
.. py:module:: OpenSSL.rand
 
7
   :synopsis: An interface to the OpenSSL pseudo random number generator
 
8
 
 
9
 
 
10
This module handles the OpenSSL pseudo random number generator (PRNG) and
 
11
declares the following:
 
12
 
 
13
.. py:function:: add(string, entropy)
 
14
 
 
15
    Mix bytes from *string* into the PRNG state. The *entropy* argument is
 
16
    (the lower bound of) an estimate of how much randomness is contained in
 
17
    *string*, measured in bytes. For more information, see e.g. :rfc:`1750`.
 
18
 
 
19
 
 
20
.. py:function:: bytes(num_bytes)
 
21
 
 
22
    Get some random bytes from the PRNG as a string.
 
23
 
 
24
    This is a wrapper for the C function :py:func:`RAND_bytes`.
 
25
 
 
26
 
 
27
.. py:function:: cleanup()
 
28
 
 
29
    Erase the memory used by the PRNG.
 
30
 
 
31
    This is a wrapper for the C function :py:func:`RAND_cleanup`.
 
32
 
 
33
 
 
34
.. py:function:: egd(path[, bytes])
 
35
 
 
36
    Query the `Entropy Gathering Daemon <http://www.lothar.com/tech/crypto/>`_ on
 
37
    socket *path* for *bytes* bytes of random data and uses :py:func:`add` to
 
38
    seed the PRNG. The default value of *bytes* is 255.
 
39
 
 
40
 
 
41
.. py:function:: load_file(path[, bytes])
 
42
 
 
43
    Read *bytes* bytes (or all of it, if *bytes* is negative) of data from the
 
44
    file *path* to seed the PRNG. The default value of *bytes* is -1.
 
45
 
 
46
 
 
47
.. py:function:: screen()
 
48
 
 
49
    Add the current contents of the screen to the PRNG state.
 
50
 
 
51
    Availability: Windows.
 
52
 
 
53
 
 
54
.. py:function:: seed(string)
 
55
 
 
56
    This is equivalent to calling :py:func:`add` with *entropy* as the length
 
57
    of the string.
 
58
 
 
59
 
 
60
.. py:function:: status()
 
61
 
 
62
    Returns true if the PRNG has been seeded with enough data, and false otherwise.
 
63
 
 
64
 
 
65
.. py:function:: write_file(path)
 
66
 
 
67
    Write a number of random bytes (currently 1024) to the file *path*. This
 
68
    file can then be used with :py:func:`load_file` to seed the PRNG again.
 
69
 
 
70
 
 
71
.. py:exception:: Error
 
72
 
 
73
    If the current RAND method supports any errors, this is raised when needed.
 
74
    The default method does not raise this when the entropy pool is depleted.
 
75
 
 
76
    Whenever this exception is raised directly, it has a list of error messages
 
77
    from the OpenSSL error queue, where each item is a tuple *(lib, function,
 
78
    reason)*. Here *lib*, *function* and *reason* are all strings, describing
 
79
    where and what the problem is. See :manpage:`err(3)` for more information.