1
0
mirror of https://github.com/taigrr/arduinolibs synced 2025-01-18 04:33:12 -08:00
arduinolibs/crypto.html
Rhys Weatherley 95a162cdfd Update docs
2015-04-01 16:36:21 +10:00

176 lines
16 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.6"/>
<title>ArduinoLibs: Cryptographic Library</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
$(document).ready(function() { searchBox.OnSelectItem(0); });
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td style="padding-left: 0.5em;">
<div id="projectname">ArduinoLibs
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.6 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<div id="navrow1" class="tabs">
<ul class="tablist">
<li><a href="index.html"><span>Main&#160;Page</span></a></li>
<li class="current"><a href="pages.html"><span>Related&#160;Pages</span></a></li>
<li><a href="modules.html"><span>Modules</span></a></li>
<li><a href="annotated.html"><span>Classes</span></a></li>
<li><a href="files.html"><span>Files</span></a></li>
<li>
<div id="MSearchBox" class="MSearchBoxInactive">
<span class="left">
<img id="MSearchSelect" src="search/mag_sel.png"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
alt=""/>
<input type="text" id="MSearchField" value="Search" accesskey="S"
onfocus="searchBox.OnSearchFieldFocus(true)"
onblur="searchBox.OnSearchFieldFocus(false)"
onkeyup="searchBox.OnSearchFieldChange(event)"/>
</span><span class="right">
<a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
</span>
</div>
</li>
</ul>
</div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark">&#160;</span>Groups</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(9)"><span class="SelectionMark">&#160;</span>Pages</a></div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</div>
</div><!-- top -->
<div class="header">
<div class="headertitle">
<div class="title">Cryptographic Library </div> </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><h1><a class="anchor" id="crypto_algorithms"></a>
Supported Algorithms</h1>
<ul>
<li>Block ciphers: <a class="el" href="classAES128.html" title="AES block cipher with 128-bit keys. ">AES128</a>, <a class="el" href="classAES192.html" title="AES block cipher with 192-bit keys. ">AES192</a>, <a class="el" href="classAES256.html" title="AES block cipher with 256-bit keys. ">AES256</a> </li>
<li>Block cipher modes: <a class="el" href="classCTR.html" title="Implementation of the Counter (CTR) mode for 128-bit block ciphers. ">CTR</a>, <a class="el" href="classCFB.html" title="Implementation of the Cipher Feedback (CFB) mode for 128-bit block ciphers. ">CFB</a>, <a class="el" href="classCBC.html" title="Implementation of the Cipher Block Chaining (CBC) mode for 128-bit block ciphers. ...">CBC</a>, <a class="el" href="classOFB.html" title="Implementation of the Output Feedback (OFB) mode for 128-bit block ciphers. ">OFB</a>, <a class="el" href="classGCM.html" title="Implementation of the Galois Counter Mode (GCM). ">GCM</a> </li>
<li>Stream ciphers: <a class="el" href="classChaCha.html" title="ChaCha stream cipher. ">ChaCha</a> </li>
<li>Authenticated encryption with associated data (AEAD): <a class="el" href="classChaChaPoly.html" title="Authenticated cipher based on ChaCha and Poly1305. ">ChaChaPoly</a>, <a class="el" href="classGCM.html" title="Implementation of the Galois Counter Mode (GCM). ">GCM</a> </li>
<li><a class="el" href="classHash.html" title="Abstract base class for cryptographic hash algorithms. ">Hash</a> algorithms: <a class="el" href="classSHA1.html" title="SHA-1 hash algorithm. ">SHA1</a>, <a class="el" href="classSHA256.html" title="SHA-256 hash algorithm. ">SHA256</a>, <a class="el" href="classSHA512.html" title="SHA-512 hash algorithm. ">SHA512</a>, <a class="el" href="classSHA3__256.html" title="SHA3-256 hash algorithm. ">SHA3_256</a>, <a class="el" href="classSHA3__512.html" title="SHA3-512 hash algorithm. ">SHA3_512</a>, <a class="el" href="classBLAKE2s.html" title="BLAKE2s hash algorithm. ">BLAKE2s</a>, <a class="el" href="classBLAKE2b.html" title="BLAKE2b hash algorithm. ">BLAKE2b</a> (regular and HMAC modes) </li>
<li>Message authenticators: <a class="el" href="classPoly1305.html" title="Poly1305 message authenticator. ">Poly1305</a>, <a class="el" href="classGHASH.html" title="Implementation of the GHASH message authenticator. ">GHASH</a> </li>
<li>Public key algorithms: <a class="el" href="classCurve25519.html" title="Diffie-Hellman key agreement based on the elliptic curve modulo 2^255 - 19. ">Curve25519</a> </li>
<li>Random number generation: <a class="el" href="classRNGClass.html">RNG</a>, <a class="el" href="classTransistorNoiseSource.html" title="Processes the signal from a transistor-based noise source. ">TransistorNoiseSource</a>, <a class="el" href="classRingOscillatorNoiseSource.html" title="Processes the signal from a ring oscillator based noise source. ">RingOscillatorNoiseSource</a></li>
</ul>
<p>All cryptographic algorithms have been optimized for 8-bit Arduino platforms like the Uno. Memory usage is also reduced, particularly for <a class="el" href="classSHA1.html" title="SHA-1 hash algorithm. ">SHA1</a>, <a class="el" href="classSHA256.html" title="SHA-256 hash algorithm. ">SHA256</a>, and <a class="el" href="classSHA512.html" title="SHA-512 hash algorithm. ">SHA512</a> which save 256, 192, and 512 bytes respectively over traditional implementations. For all algorithms, static sbox tables and the like are placed into program memory to further reduce data memory usage.</p>
<p><a class="el" href="classChaCha.html" title="ChaCha stream cipher. ">ChaCha</a> with 20 rounds and 256-bit keys is the recommended symmetric encryption algorithm because it is twice as fast as <a class="el" href="classAES128.html" title="AES block cipher with 128-bit keys. ">AES128</a>, constant-time, and much more secure. <a class="el" href="classAES128.html" title="AES block cipher with 128-bit keys. ">AES128</a>, <a class="el" href="classAES192.html" title="AES block cipher with 192-bit keys. ">AES192</a>, and <a class="el" href="classAES256.html" title="AES block cipher with 256-bit keys. ">AES256</a> are provided for use in applications where compatibility with other systems is desirable.</p>
<p><a class="el" href="classBLAKE2s.html" title="BLAKE2s hash algorithm. ">BLAKE2s</a> and <a class="el" href="classBLAKE2b.html" title="BLAKE2b hash algorithm. ">BLAKE2b</a> are variations on the <a class="el" href="classChaCha.html" title="ChaCha stream cipher. ">ChaCha</a> stream cipher, designed for hashing, with 256-bit and 512-bit hash outputs respectively. They are intended as high performance replacements for <a class="el" href="classSHA256.html" title="SHA-256 hash algorithm. ">SHA256</a> and <a class="el" href="classSHA512.html" title="SHA-512 hash algorithm. ">SHA512</a> for when speed is critical but exact bit-compatibility of hash values is not.</p>
<h1><a class="anchor" id="crypto_other"></a>
Examples and other topics</h1>
<ul>
<li><a class="el" href="crypto_rng.html">Generating random numbers</a></li>
</ul>
<h1><a class="anchor" id="crypto_performance"></a>
Performance</h1>
<p>All figures are for the Arduino Uno running at 16 MHz. Figures for the Ardunino Mega 2560 running at 16 MHz are similar:</p>
<table class="doxtable">
<tr>
<td>Encryption Algorithm</td><td align="right">Encryption (per byte)</td><td align="right">Decryption (per byte)</td><td>Key Setup</td><td>State Size (bytes) </td></tr>
<tr>
<td><a class="el" href="classAES128.html" title="AES block cipher with 128-bit keys. ">AES128</a> (ECB mode)</td><td align="right">36.90us</td><td align="right">66.48us</td><td align="right">160.00us</td><td align="right">213 </td></tr>
<tr>
<td><a class="el" href="classAES192.html" title="AES block cipher with 192-bit keys. ">AES192</a> (ECB mode)</td><td align="right">44.20us</td><td align="right">80.35us</td><td align="right">166.54us</td><td align="right">245 </td></tr>
<tr>
<td><a class="el" href="classAES256.html" title="AES block cipher with 256-bit keys. ">AES256</a> (ECB mode)</td><td align="right">51.50us</td><td align="right">94.22us</td><td align="right">227.97us</td><td align="right">277 </td></tr>
<tr>
<td><a class="el" href="classChaCha.html" title="ChaCha stream cipher. ">ChaCha</a> (20 rounds)</td><td align="right">14.87us</td><td align="right">14.88us</td><td align="right">43.74us</td><td align="right">132 </td></tr>
<tr>
<td><a class="el" href="classChaCha.html" title="ChaCha stream cipher. ">ChaCha</a> (12 rounds)</td><td align="right">10.38us</td><td align="right">10.38us</td><td align="right">43.74us</td><td align="right">132 </td></tr>
<tr>
<td><a class="el" href="classChaCha.html" title="ChaCha stream cipher. ">ChaCha</a> (8 rounds)</td><td align="right">8.13us</td><td align="right">8.14us</td><td align="right">43.74us</td><td align="right">132 </td></tr>
<tr>
<td colspan="5"></td></tr>
<tr>
<td>AEAD Algorithm</td><td align="right">Encryption (per byte)</td><td align="right">Decryption (per byte)</td><td>Key Setup</td><td>State Size (bytes) </td></tr>
<tr>
<td><a class="el" href="classChaChaPoly.html" title="Authenticated cipher based on ChaCha and Poly1305. ">ChaChaPoly</a></td><td align="right">41.23us</td><td align="right">41.23us</td><td align="right">902.55us</td><td align="right">255 </td></tr>
<tr>
<td><a class="el" href="classGCM.html" title="Implementation of the Galois Counter Mode (GCM). ">GCM</a>&lt;<a class="el" href="classAES128.html" title="AES block cipher with 128-bit keys. ">AES128</a>&gt;</td><td align="right">186.47us</td><td align="right">186.42us</td><td align="right">1388.43us</td><td align="right">316 </td></tr>
<tr>
<td><a class="el" href="classGCM.html" title="Implementation of the Galois Counter Mode (GCM). ">GCM</a>&lt;<a class="el" href="classAES192.html" title="AES block cipher with 192-bit keys. ">AES192</a>&gt;</td><td align="right">194.17us</td><td align="right">193.72us</td><td align="right">1628.67us</td><td align="right">348 </td></tr>
<tr>
<td><a class="el" href="classGCM.html" title="Implementation of the Galois Counter Mode (GCM). ">GCM</a>&lt;<a class="el" href="classAES256.html" title="AES block cipher with 256-bit keys. ">AES256</a>&gt;</td><td align="right">201.47us</td><td align="right">201.02us</td><td align="right">1923.78us</td><td align="right">380 </td></tr>
<tr>
<td colspan="5"></td></tr>
<tr>
<td><a class="el" href="classHash.html" title="Abstract base class for cryptographic hash algorithms. ">Hash</a> Algorithm</td><td align="right">Hashing (per byte)</td><td align="right">Finalization</td><td>Key Setup</td><td>State Size (bytes) </td></tr>
<tr>
<td><a class="el" href="classSHA1.html" title="SHA-1 hash algorithm. ">SHA1</a></td><td align="right">21.90us</td><td></td><td align="right"></td><td align="right">95 </td></tr>
<tr>
<td><a class="el" href="classSHA256.html" title="SHA-256 hash algorithm. ">SHA256</a></td><td align="right">43.85us</td><td></td><td align="right"></td><td align="right">107 </td></tr>
<tr>
<td><a class="el" href="classSHA512.html" title="SHA-512 hash algorithm. ">SHA512</a></td><td align="right">123.24us</td><td></td><td align="right"></td><td align="right">211 </td></tr>
<tr>
<td><a class="el" href="classSHA3__256.html" title="SHA3-256 hash algorithm. ">SHA3_256</a></td><td align="right">121.69us</td><td></td><td align="right"></td><td align="right">405 </td></tr>
<tr>
<td><a class="el" href="classSHA3__512.html" title="SHA3-512 hash algorithm. ">SHA3_512</a></td><td align="right">229.12us</td><td></td><td align="right"></td><td align="right">405 </td></tr>
<tr>
<td><a class="el" href="classBLAKE2s.html" title="BLAKE2s hash algorithm. ">BLAKE2s</a></td><td align="right">18.54us</td><td></td><td align="right"></td><td align="right">171 </td></tr>
<tr>
<td><a class="el" href="classBLAKE2b.html" title="BLAKE2b hash algorithm. ">BLAKE2b</a></td><td align="right">50.58us</td><td></td><td align="right"></td><td align="right">339 </td></tr>
<tr>
<td><a class="el" href="classPoly1305.html" title="Poly1305 message authenticator. ">Poly1305</a></td><td align="right">26.29us</td><td></td><td align="right"></td><td align="right">87 </td></tr>
<tr>
<td><a class="el" href="classGHASH.html" title="Implementation of the GHASH message authenticator. ">GHASH</a></td><td align="right">148.14us</td><td></td><td align="right"></td><td align="right">33 </td></tr>
</table>
<p>Where a cipher supports more than one key size (such as <a class="el" href="classChaCha.html" title="ChaCha stream cipher. ">ChaCha</a>), the values are typically almost identical for 128-bit and 256-bit keys so only the maximum is shown above.</p>
<p>Public key algorithms have the following results on an Arduino Uno:</p>
<table class="doxtable">
<tr>
<td>Algorithm</td><td>Operation</td><td>Time</td><td>Comment </td></tr>
<tr>
<td><a class="el" href="classCurve25519.html" title="Diffie-Hellman key agreement based on the elliptic curve modulo 2^255 - 19. ">Curve25519</a></td><td><a class="el" href="classCurve25519.html#a2e4b7dd83a019b32c76584c99bfda21a">eval()</a></td><td>3738 ms</td><td>Raw curve evaluation </td></tr>
<tr>
<td><a class="el" href="classCurve25519.html" title="Diffie-Hellman key agreement based on the elliptic curve modulo 2^255 - 19. ">Curve25519</a></td><td><a class="el" href="classCurve25519.html#a2b6911583d17ea9a36bbbb40d58b3d89">dh1()</a></td><td>3740 ms</td><td>First half of Diffie-Hellman key agreement </td></tr>
<tr>
<td><a class="el" href="classCurve25519.html" title="Diffie-Hellman key agreement based on the elliptic curve modulo 2^255 - 19. ">Curve25519</a></td><td><a class="el" href="classCurve25519.html#a14022d6ac68ec691ffb0247275078ab9">dh2()</a></td><td>3738 ms</td><td>Second half of Diffie-Hellman key agreement </td></tr>
</table>
</div></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Wed Apr 1 2015 16:36:10 for ArduinoLibs by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.6
</small></address>
</body>
</html>