wolfcrypt-py/random.html

276 lines
8.4 KiB
HTML

<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Random Number Generation &mdash; wolfcrypt Python 3.14.0-1 documentation</title>
<link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
<link rel="index" title="Index"
href="genindex.html"/>
<link rel="search" title="Search" href="search.html"/>
<link rel="top" title="wolfcrypt Python 3.14.0-1 documentation" href="index.html"/>
<link rel="prev" title="Message Authentication Codes" href="mac.html"/>
<script src="_static/js/modernizr.min.js"></script>
</head>
<body class="wy-body-for-nav" role="document">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search">
<a href="index.html" class="icon icon-home"> wolfcrypt Python
</a>
<div class="version">
3.14.0-1
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="symmetric.html">Symmetric Key Algorithms</a></li>
<li class="toctree-l1"><a class="reference internal" href="asymmetric.html">Asymmetric Key Algorithms</a></li>
<li class="toctree-l1"><a class="reference internal" href="digest.html">Message Digests</a></li>
<li class="toctree-l1"><a class="reference internal" href="mac.html">Message Authentication Codes</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">Random Number Generation</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#example">Example</a></li>
</ul>
</li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" role="navigation" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="index.html">wolfcrypt Python</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="index.html">Docs</a> &raquo;</li>
<li>Random Number Generation</li>
<li class="wy-breadcrumbs-aside">
<a href="_sources/random.rst.txt" rel="nofollow"> View page source</a>
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<div class="section" id="random-number-generation">
<h1>Random Number Generation<a class="headerlink" href="#random-number-generation" title="Permalink to this headline"></a></h1>
<p>A <strong>cryptographically secure pseudo-random number generator</strong> (CSPRNG) is a
<strong>pseudo-random number generator</strong> (PRNG) with properties that make it suitable
for use in cryptography.</p>
<p>Using the standard random module APIs for cryptographic keys or initialization
vectors can result in major security issues depending on the algorithms in use.</p>
<p><code class="docutils literal notranslate"><span class="pre">wolfcrypt</span></code> provides the following CSPRNG implementation:</p>
<span class="target" id="module-wolfcrypt.random"></span><dl class="class">
<dt id="wolfcrypt.random.Random">
<em class="property">class </em><code class="descclassname">wolfcrypt.random.</code><code class="descname">Random</code><a class="reference internal" href="_modules/wolfcrypt/random.html#Random"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#wolfcrypt.random.Random" title="Permalink to this definition"></a></dt>
<dd><p>A Cryptographically Secure Pseudo Random Number Generator - CSPRNG</p>
<dl class="method">
<dt id="wolfcrypt.random.Random.byte">
<code class="descname">byte</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/wolfcrypt/random.html#Random.byte"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#wolfcrypt.random.Random.byte" title="Permalink to this definition"></a></dt>
<dd><p>Generate and return a random byte.</p>
</dd></dl>
<dl class="method">
<dt id="wolfcrypt.random.Random.bytes">
<code class="descname">bytes</code><span class="sig-paren">(</span><em>length</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/wolfcrypt/random.html#Random.bytes"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#wolfcrypt.random.Random.bytes" title="Permalink to this definition"></a></dt>
<dd><p>Generate and return a random sequence of length bytes.</p>
</dd></dl>
</dd></dl>
<div class="section" id="example">
<h2>Example<a class="headerlink" href="#example" title="Permalink to this headline"></a></h2>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">wolfcrypt.random</span> <span class="k">import</span> <span class="n">Random</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">r</span> <span class="o">=</span> <span class="n">Random</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">b</span> <span class="o">=</span> <span class="n">r</span><span class="o">.</span><span class="n">byte</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">b</span>
<span class="go">b&#39;\x8c&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">b16</span> <span class="o">=</span> <span class="n">r</span><span class="o">.</span><span class="n">bytes</span><span class="p">(</span><span class="mi">16</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">b16</span>
<span class="go">b&#39;]\x93nk\x95\xbc@\xffX\xab\xdcB\xda\x11\xf7\x03&#39;</span>
</pre></div>
</div>
</div>
</div>
</div>
<div class="articleComments">
</div>
</div>
<footer>
<div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
<a href="mac.html" class="btn btn-neutral" title="Message Authentication Codes" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a>
</div>
<hr/>
<div role="contentinfo">
<p>
&copy; Copyright 2018, wolfSSL Inc. All rights reserved.
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT:'./',
VERSION:'3.14.0-1',
COLLAPSE_INDEX:false,
FILE_SUFFIX:'.html',
HAS_SOURCE: true,
SOURCELINK_SUFFIX: '.txt'
};
</script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<script type="text/javascript" src="_static/js/theme.js"></script>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.StickyNav.enable();
});
</script>
</body>
</html>