wolfcrypt-py/symmetric.html

340 lines
14 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<!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>Symmetric Key Algorithms &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="next" title="Asymmetric Key Algorithms" href="asymmetric.html"/>
<link rel="prev" title="wolfcrypt: the wolfSSL Crypto Engine" href="index.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 current"><a class="current reference internal" href="#">Symmetric Key Algorithms</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#symmetric-key-encryption-classes">Symmetric Key Encryption Classes</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#interface">Interface</a></li>
<li class="toctree-l3"><a class="reference internal" href="#aes">AES</a></li>
<li class="toctree-l3"><a class="reference internal" href="#triple-des">Triple DES</a></li>
</ul>
</li>
</ul>
</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"><a class="reference internal" href="random.html">Random Number Generation</a></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>Symmetric Key Algorithms</li>
<li class="wy-breadcrumbs-aside">
<a href="_sources/symmetric.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="module-wolfcrypt.ciphers">
<span id="symmetric-key-algorithms"></span><h1>Symmetric Key Algorithms<a class="headerlink" href="#module-wolfcrypt.ciphers" title="Permalink to this headline"></a></h1>
<p><strong>Symmetric key algorithms</strong> are encryption algorithms that use the <strong>same
cryptographic key</strong> for both encryption and decryption of data.
This operation is also known as <strong>Symmetric Key Encryption</strong>.</p>
<div class="section" id="symmetric-key-encryption-classes">
<h2>Symmetric Key Encryption Classes<a class="headerlink" href="#symmetric-key-encryption-classes" title="Permalink to this headline"></a></h2>
<div class="section" id="interface">
<h3>Interface<a class="headerlink" href="#interface" title="Permalink to this headline"></a></h3>
<p>All <strong>Symmetric Key Ciphers</strong> available in this module implements the following
interface:</p>
<dl class="class">
<dt id="wolfcrypt.ciphers._Cipher">
<em class="property">class </em><code class="descclassname">wolfcrypt.ciphers.</code><code class="descname">_Cipher</code><span class="sig-paren">(</span><em>key</em>, <em>mode</em>, <em>IV=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/wolfcrypt/ciphers.html#_Cipher"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#wolfcrypt.ciphers._Cipher" title="Permalink to this definition"></a></dt>
<dd><p>A <strong>PEP 272: Block Encryption Algorithms</strong> compliant
<strong>Symmetric Key Cipher</strong>.</p>
<dl class="classmethod">
<dt id="wolfcrypt.ciphers._Cipher.new">
<em class="property">classmethod </em><code class="descname">new</code><span class="sig-paren">(</span><em>key</em>, <em>mode</em>, <em>IV=None</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/wolfcrypt/ciphers.html#_Cipher.new"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#wolfcrypt.ciphers._Cipher.new" title="Permalink to this definition"></a></dt>
<dd><p>Returns a ciphering object, using the secret key contained in
the string <strong>key</strong>, and using the feedback mode <strong>mode</strong>, which
must be one of MODE_* defined in this module.</p>
<p>If <strong>mode</strong> is MODE_CBC or MODE_CFB, <strong>IV</strong> must be provided and
must be a string of the same length as the block size. Not
providing a value of <strong>IV</strong> will result in a ValueError exception
being raised.</p>
</dd></dl>
<dl class="method">
<dt id="wolfcrypt.ciphers._Cipher.encrypt">
<code class="descname">encrypt</code><span class="sig-paren">(</span><em>string</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/wolfcrypt/ciphers.html#_Cipher.encrypt"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#wolfcrypt.ciphers._Cipher.encrypt" title="Permalink to this definition"></a></dt>
<dd><p>Encrypts a non-empty string, using the key-dependent data in
the object, and with the appropriate feedback mode.</p>
<p>The strings length must be an exact multiple of the algorithms
block size or, in CFB mode, of the segment size.</p>
<p>Returns a string containing the ciphertext.</p>
</dd></dl>
<dl class="method">
<dt id="wolfcrypt.ciphers._Cipher.decrypt">
<code class="descname">decrypt</code><span class="sig-paren">(</span><em>string</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/wolfcrypt/ciphers.html#_Cipher.decrypt"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#wolfcrypt.ciphers._Cipher.decrypt" title="Permalink to this definition"></a></dt>
<dd><p>Decrypts <strong>string</strong>, using the key-dependent data in the
object and with the appropriate feedback mode.</p>
<p>The strings length must be an exact multiple of the algorithms
block size or, in CFB mode, of the segment size.</p>
<p>Returns a string containing the plaintext.</p>
</dd></dl>
</dd></dl>
</div>
<div class="section" id="aes">
<h3>AES<a class="headerlink" href="#aes" title="Permalink to this headline"></a></h3>
<dl class="class">
<dt id="wolfcrypt.ciphers.Aes">
<em class="property">class </em><code class="descclassname">wolfcrypt.ciphers.</code><code class="descname">Aes</code><span class="sig-paren">(</span><em>key</em>, <em>mode</em>, <em>IV=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/wolfcrypt/ciphers.html#Aes"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#wolfcrypt.ciphers.Aes" title="Permalink to this definition"></a></dt>
<dd><p>The <strong>Advanced Encryption Standard</strong> (AES), a.k.a. Rijndael, is
a symmetric-key cipher standardized by <strong>NIST</strong>.</p>
</dd></dl>
<p><strong>Example:</strong></p>
<div class="highlight-pycon notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">wolfcrypt.ciphers</span> <span class="kn">import</span> <span class="n">Aes</span><span class="p">,</span> <span class="n">MODE_CBC</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">cipher</span> <span class="o">=</span> <span class="n">Aes</span><span class="p">(</span><span class="sa">b</span><span class="s1">&#39;0123456789abcdef&#39;</span><span class="p">,</span> <span class="n">MODE_CBC</span><span class="p">,</span> <span class="sa">b</span><span class="s1">&#39;1234567890abcdef&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ciphertext</span> <span class="o">=</span> <span class="n">cipher</span><span class="o">.</span><span class="n">encrypt</span><span class="p">(</span><span class="s1">&#39;now is the time &#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ciphertext</span>
<span class="go">b&#39;\x95\x94\x92W_B\x81S,\xcc\x9dFw\xa23\xcb&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">cipher</span><span class="o">.</span><span class="n">decrypt</span><span class="p">(</span><span class="n">ciphertext</span><span class="p">)</span>
<span class="go">b&#39;now is the time &#39;</span>
</pre></div>
</div>
</div>
<div class="section" id="triple-des">
<h3>Triple DES<a class="headerlink" href="#triple-des" title="Permalink to this headline"></a></h3>
<dl class="class">
<dt id="wolfcrypt.ciphers.Des3">
<em class="property">class </em><code class="descclassname">wolfcrypt.ciphers.</code><code class="descname">Des3</code><span class="sig-paren">(</span><em>key</em>, <em>mode</em>, <em>IV=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/wolfcrypt/ciphers.html#Des3"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#wolfcrypt.ciphers.Des3" title="Permalink to this definition"></a></dt>
<dd><p><strong>Triple DES</strong> (3DES) is the common name for the <strong>Triple Data
Encryption Algorithm</strong> (TDEA or Triple DEA) symmetric-key block
cipher, which applies the <strong>Data Encryption Standard</strong> (DES)
cipher algorithm three times to each data block.</p>
</dd></dl>
<p><strong>Example:</strong></p>
<div class="highlight-pycon notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">wolfcrypt.ciphers</span> <span class="kn">import</span> <span class="n">Des3</span><span class="p">,</span> <span class="n">MODE_CBC</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">cipher</span> <span class="o">=</span> <span class="n">Des3</span><span class="p">(</span><span class="sa">b</span><span class="s1">&#39;0123456789abcdeffedeba98&#39;</span><span class="p">,</span> <span class="n">MODE_CBC</span><span class="p">,</span> <span class="sa">b</span><span class="s1">&#39;12345678&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ciphertext</span> <span class="o">=</span> <span class="n">cipher</span><span class="o">.</span><span class="n">encrypt</span><span class="p">(</span><span class="s1">&#39;now is the time &#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ciphertext</span>
<span class="go">b&#39;l\x04\xd0$\xe8\x0c1\xd6\x1b\x07}V\xa6ty\xe8&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">cipher</span><span class="o">.</span><span class="n">decrypt</span><span class="p">(</span><span class="n">ciphertext</span><span class="p">)</span>
<span class="go">b&#39;now is the time &#39;</span>
</pre></div>
</div>
</div>
</div>
</div>
</div>
<div class="articleComments">
</div>
</div>
<footer>
<div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
<a href="asymmetric.html" class="btn btn-neutral float-right" title="Asymmetric Key Algorithms" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a>
<a href="index.html" class="btn btn-neutral" title="wolfcrypt: the wolfSSL Crypto Engine" 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>