sha2.html 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <!-- This file is generated by Nim. -->
  4. <html xmlns="https://www.w3.org/1999/xhtml" xml:lang="en" lang="en" data-theme="auto">
  5. <head>
  6. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  7. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  8. <title>src/checksums/sha2</title>
  9. <!-- Google fonts -->
  10. <link href='https://fonts.googleapis.com/css?family=Lato:400,600,900' rel='stylesheet' type='text/css'/>
  11. <link href='https://fonts.googleapis.com/css?family=Source+Code+Pro:400,500,600' rel='stylesheet' type='text/css'/>
  12. <!-- Favicon -->
  13. <link rel="shortcut icon" href="data:image/x-icon;base64,AAABAAEAEBAAAAEAIABoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AAAAAAUAAAAF////AP///wD///8A////AP///wD///8A////AP///wD///8A////AAAAAAIAAABbAAAAlQAAAKIAAACbAAAAmwAAAKIAAACVAAAAWwAAAAL///8A////AP///wD///8A////AAAAABQAAADAAAAAYwAAAA3///8A////AP///wD///8AAAAADQAAAGMAAADAAAAAFP///wD///8A////AP///wAAAACdAAAAOv///wD///8A////AP///wD///8A////AP///wD///8AAAAAOgAAAJ3///8A////AP///wAAAAAnAAAAcP///wAAAAAoAAAASv///wD///8A////AP///wAAAABKAAAAKP///wAAAABwAAAAJ////wD///8AAAAAgQAAABwAAACIAAAAkAAAAJMAAACtAAAAFQAAABUAAACtAAAAkwAAAJAAAACIAAAAHAAAAIH///8A////AAAAAKQAAACrAAAAaP///wD///8AAAAARQAAANIAAADSAAAARf///wD///8AAAAAaAAAAKsAAACk////AAAAADMAAACcAAAAnQAAABj///8A////AP///wAAAAAYAAAAGP///wD///8A////AAAAABgAAACdAAAAnAAAADMAAAB1AAAAwwAAAP8AAADpAAAAsQAAAE4AAAAb////AP///wAAAAAbAAAATgAAALEAAADpAAAA/wAAAMMAAAB1AAAAtwAAAOkAAAD/AAAA/wAAAP8AAADvAAAA3gAAAN4AAADeAAAA3gAAAO8AAAD/AAAA/wAAAP8AAADpAAAAtwAAAGUAAAA/AAAA3wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAADfAAAAPwAAAGX///8A////AAAAAEgAAADtAAAAvwAAAL0AAADGAAAA7wAAAO8AAADGAAAAvQAAAL8AAADtAAAASP///wD///8A////AP///wD///8AAAAAO////wD///8A////AAAAAIcAAACH////AP///wD///8AAAAAO////wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A//8AAP//AAD4HwAA7/cAAN/7AAD//wAAoYUAAJ55AACf+QAAh+EAAAAAAADAAwAA4AcAAP5/AAD//wAA//8AAA=="/>
  14. <link rel="icon" type="image/png" sizes="32x32" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAA3XAAAN1wFCKJt4AAAAB3RJTUUH4QQQEwksSS9ZWwAAAk1JREFUWMPtll2ITVEUx39nn/O7Y5qR8f05wtCUUr6ZIS++8pEnkZInPImneaCQ5METNdOkeFBKUhMPRIkHKfEuUZSUlGlKPN2TrgfncpvmnntnmlEyq1Z7t89/rf9a6+y99oZxGZf/XeIq61EdtgKXgdXA0xrYAvBjOIF1AI9zvjcC74BSpndrJPkBWDScTF8Aa4E3wDlgHbASaANmVqlcCnwHvgDvgVfAJ+AikAAvgfVZwLnSVZHZaOuKoQi3ZOMi4NkYkpe1p4J7A8BpYAD49hfIy/oqG0+hLomiKP2L5L+1ubn5115S+3OAn4EnwBlgMzCjyt6ZAnQCJ4A7wOs88iRJHvw50HoujuPBoCKwHWiosy8MdfZnAdcHk8dxXFJ3VQbQlCTJvRBCGdRbD4M6uc5glpY3eAihpN5S5w12diSEcCCEcKUO4ljdr15T76ur1FDDLIQQ3qv71EdDOe3Kxj3leRXyk+pxdWnFWod6Wt2bY3de3aSuUHcPBVimHs7mK9WrmeOF6lR1o9qnzskh2ar2qm1qizpfXaPeVGdlmGN5pb09qMxz1Xb1kLqgzn1RyH7JUXW52lr5e/Kqi9qpto7V1atuUzfnARrV7jEib1T76gG2qxdGmXyiekkt1GswPTtek0aBfJp6YySGBfWg2tPQ0FAYgf1stUfdmdcjarbYJEniKIq6gY/Aw+zWHAC+p2labGpqiorFYgGYCEzN7oQdQClN07O1/EfDyGgC0ALMBdYAi4FyK+4H3gLPsxfR1zRNi+NP7nH5J+QntnXe5B5mpfQAAAAASUVORK5CYII=">
  15. <!-- CSS -->
  16. <link rel="stylesheet" type="text/css" href="nimdoc.out.css?v=2.3.1">
  17. <!-- JS -->
  18. <script type="text/javascript" src="dochack.js?v=2.3.1"></script>
  19. </head>
  20. <body>
  21. <div class="document" id="documentId">
  22. <div class="container">
  23. <h1 class="title">src/checksums/sha2</h1>
  24. <div class="row">
  25. <div class="three columns">
  26. <div class="theme-select-wrapper">
  27. <label for="theme-select">Theme:&nbsp;</label>
  28. <select id="theme-select" onchange="setTheme(this.value)">
  29. <option value="auto">🌗 Match OS</option>
  30. <option value="dark">🌑 Dark</option>
  31. <option value="light">🌕 Light</option>
  32. </select>
  33. </div>
  34. <div id="global-links">
  35. <ul class="simple-boot">
  36. <li><a href="manual.html">Manual</a></li>
  37. <li><a href="lib.html">Standard library</a></li>
  38. <li> <a id="indexLink" href="theindex.html">Index</a></li>
  39. <li><a href="compiler/theindex.html">Compiler docs</a></li>
  40. <li><a href="https://nim-lang.github.io/fusion/theindex.html">Fusion docs</a></li>
  41. <li><a href="https://nim-lang.github.io/Nim/">devel</a>, <a href="https://nim-lang.org/documentation.html">stable</a></li>
  42. </ul>
  43. </div>
  44. <div id="searchInputDiv">
  45. Search: <input type="search" id="searchInput"
  46. oninput="search()" />
  47. </div>
  48. <ul class="simple simple-toc" id="toc-list">
  49. <li><a class="reference" id="implemented-algorithms_toc" href="#implemented-algorithms">Implemented Algorithms</a></li>
  50. <li>
  51. <a class="reference reference-toplevel" href="#6" id="56">Imports</a>
  52. </li>
  53. <li>
  54. <details open>
  55. <summary><a class="reference reference-toplevel" href="#7" id="57">Types</a></summary>
  56. <ul class="simple simple-toc-section">
  57. <li><a class="reference" href="#ShaDigest_224" title="ShaDigest_224 = array[28, char]">ShaDigest_224</a></li>
  58. <li><a class="reference" href="#ShaDigest_256" title="ShaDigest_256 = array[32, char]">ShaDigest_256</a></li>
  59. <li><a class="reference" href="#ShaDigest_384" title="ShaDigest_384 = array[48, char]">ShaDigest_384</a></li>
  60. <li><a class="reference" href="#ShaDigest_512" title="ShaDigest_512 = array[64, char]">ShaDigest_512</a></li>
  61. <li><a class="reference" href="#ShaInstance" title="ShaInstance = enum
  62. Sha_224, ## SHA-224 with an output size of 28 bytes (truncated from SHA-256)
  63. Sha_256, ## SHA-256 with an output size of 32 bytes
  64. Sha_384, ## SHA-384 with an output size of 48 bytes (truncated from SHA-512)
  65. Sha_512 ## SHA-512 with an output size of 64 bytes">ShaInstance</a></li>
  66. <li><a class="reference" href="#ShaState" title="ShaState = distinct ShaContext">ShaState</a></li>
  67. <li><a class="reference" href="#ShaStateStatic" title="ShaStateStatic[instance] = distinct ShaState">ShaStateStatic</a></li>
  68. </ul>
  69. </details>
  70. </li>
  71. <li>
  72. <details open>
  73. <summary><a class="reference reference-toplevel" href="#12" id="62">Procs</a></summary>
  74. <ul class="simple simple-toc-section">
  75. <ul class="simple nested-toc-section">digest
  76. <li><a class="reference" href="#digest%2CShaState%2CopenArray%5Bchar%5D" title="digest(state: var ShaState; dest: var openArray[char]): int">digest(state: var ShaState; dest: var openArray[char]): int</a></li>
  77. <li><a class="reference" href="#digest%2CShaStateStatic%5BShaInstance%5D" title="digest(state: var ShaStateStatic[Sha_224]): ShaDigest_224">digest(state: var ShaStateStatic[Sha_224]): ShaDigest_224</a></li>
  78. <li><a class="reference" href="#digest%2CShaStateStatic%5BShaInstance%5D_2" title="digest(state: var ShaStateStatic[Sha_256]): ShaDigest_256">digest(state: var ShaStateStatic[Sha_256]): ShaDigest_256</a></li>
  79. <li><a class="reference" href="#digest%2CShaStateStatic%5BShaInstance%5D_3" title="digest(state: var ShaStateStatic[Sha_384]): ShaDigest_384">digest(state: var ShaStateStatic[Sha_384]): ShaDigest_384</a></li>
  80. <li><a class="reference" href="#digest%2CShaStateStatic%5BShaInstance%5D_4" title="digest(state: var ShaStateStatic[Sha_512]): ShaDigest_512">digest(state: var ShaStateStatic[Sha_512]): ShaDigest_512</a></li>
  81. </ul>
  82. <ul class="simple nested-toc-section">digestLength
  83. <li><a class="reference" href="#digestLength%2CShaInstance" title="digestLength(instance: ShaInstance): int">digestLength(instance: ShaInstance): int</a></li>
  84. </ul>
  85. <ul class="simple nested-toc-section">initSha
  86. <li><a class="reference" href="#initSha%2CShaInstance" title="initSha(instance: ShaInstance): ShaState">initSha(instance: ShaInstance): ShaState</a></li>
  87. </ul>
  88. <ul class="simple nested-toc-section">initSha_224
  89. <li><a class="reference" href="#initSha_224" title="initSha_224(): ShaStateStatic[Sha_224]">initSha_224(): ShaStateStatic[Sha_224]</a></li>
  90. </ul>
  91. <ul class="simple nested-toc-section">initSha_256
  92. <li><a class="reference" href="#initSha_256" title="initSha_256(): ShaStateStatic[Sha_256]">initSha_256(): ShaStateStatic[Sha_256]</a></li>
  93. </ul>
  94. <ul class="simple nested-toc-section">initSha_384
  95. <li><a class="reference" href="#initSha_384" title="initSha_384(): ShaStateStatic[Sha_384]">initSha_384(): ShaStateStatic[Sha_384]</a></li>
  96. </ul>
  97. <ul class="simple nested-toc-section">initSha_512
  98. <li><a class="reference" href="#initSha_512" title="initSha_512(): ShaStateStatic[Sha_512]">initSha_512(): ShaStateStatic[Sha_512]</a></li>
  99. </ul>
  100. <ul class="simple nested-toc-section">initShaStateStatic
  101. <li><a class="reference" href="#initShaStateStatic%2CstaticShaInstance" title="initShaStateStatic(instance: static ShaInstance): ShaStateStatic[instance]">initShaStateStatic(instance: static ShaInstance): ShaStateStatic[instance]</a></li>
  102. </ul>
  103. <ul class="simple nested-toc-section">secureHash
  104. <li><a class="reference" href="#secureHash%2CShaInstance%2CopenArray%5Bchar%5D" title="secureHash(instance: ShaInstance; data: openArray[char]): seq[char]">secureHash(instance: ShaInstance; data: openArray[char]): seq[char]</a></li>
  105. <li><a class="reference" href="#secureHash%2CstaticShaInstance%2CopenArray%5Bchar%5D" title="secureHash(instance: static ShaInstance; data: openArray[char]): auto">secureHash(instance: static ShaInstance; data: openArray[char]): auto</a></li>
  106. </ul>
  107. <ul class="simple nested-toc-section">update
  108. <li><a class="reference" href="#update%2CShaState%2CopenArray%5Bchar%5D" title="update(state: var ShaState; data: openArray[char])">update(state: var ShaState; data: openArray[char])</a></li>
  109. <li><a class="reference" href="#update%2CShaStateStatic%5Binstance%5D%2CopenArray%5Bchar%5D" title="update[instance: static ShaInstance](state: var ShaStateStatic[instance];
  110. data: openArray[char])">update[instance: static ShaInstance](state: var ShaStateStatic[instance];
  111. data: openArray[char])</a></li>
  112. </ul>
  113. </ul>
  114. </details>
  115. </li>
  116. </ul>
  117. </div>
  118. <div class="nine columns" id="content">
  119. <div id="tocRoot"></div>
  120. <p class="module-desc"><p><a class="reference external" href="https://en.wikipedia.org/wiki/SHA-2">SHA-2 (Secure Hash Algorithm 2)</a> is a cryptographic hash function which takes an input and produces a value known as a message digest.</p>
  121. <p>It provides fixed size algorithms that generate a one-shot message digest of a determinate size.</p>
  122. <h1><a class="toc-backref" id="implemented-algorithms" href="#implemented-algorithms">Implemented Algorithms</a></h1><p>Fixed size functions:</p>
  123. <ul class="simple"><li>SHA-224</li>
  124. <li>SHA-256</li>
  125. <li>SHA-384</li>
  126. <li>SHA-512</li>
  127. </ul>
  128. <p>For convenience, this module provides output-length type checked functions for the implemented fixed size functions via <tt class="docutils literal"><span class="pre"><span class="Identifier">initSha_224</span></span></tt>, <tt class="docutils literal"><span class="pre"><span class="Identifier">initSha_256</span></span></tt>, <tt class="docutils literal"><span class="pre"><span class="Identifier">initSha_384</span></span></tt> and <tt class="docutils literal"><span class="pre"><span class="Identifier">initSha_512</span></span></tt>. These functions provide a <tt class="docutils literal"><span class="pre"><span class="Identifier">digest</span></span></tt> overload returning a correctly sized message digest array.</p>
  129. <p>If more relaxed types are required, an &quot;unchecked&quot; <tt class="docutils literal"><span class="pre"><span class="Identifier">Sha2State</span></span></tt> can be used, but care must be taken to provide <tt class="docutils literal"><span class="pre"><span class="Identifier">digest</span></span></tt> with a correctly sized <tt class="docutils literal"><span class="pre"><span class="Identifier">dest</span></span></tt> array. </p>
  130. <p><strong class="examples_text">Example:</strong></p>
  131. <pre class="listing"><span class="Keyword">import</span> <span class="Identifier">src</span><span class="Operator">/</span><span class="Identifier">checksums</span><span class="Operator">/</span><span class="Identifier">sha2</span>
  132. <span class="Keyword">var</span> <span class="Identifier">hasher</span> <span class="Operator">=</span> <span class="Identifier">initSha_256</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  133. <span class="Identifier">hasher</span><span class="Operator">.</span><span class="Identifier">update</span><span class="Punctuation">(</span><span class="StringLit">&quot;The quick brown fox &quot;</span><span class="Punctuation">)</span>
  134. <span class="Identifier">hasher</span><span class="Operator">.</span><span class="Identifier">update</span><span class="Punctuation">(</span><span class="StringLit">&quot;jumps over the lazy dog&quot;</span><span class="Punctuation">)</span>
  135. <span class="Keyword">let</span> <span class="Identifier">digest</span> <span class="Operator">=</span> <span class="Identifier">hasher</span><span class="Operator">.</span><span class="Identifier">digest</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  136. <span class="Identifier">assert</span> <span class="Operator">$</span><span class="Identifier">digest</span> <span class="Operator">==</span> <span class="StringLit">&quot;d7a8fbb307d7809469ca9abcb0082e4f8d5651e46d3cdb762d02d0bf37c9e592&quot;</span></pre>
  137. <p><strong class="examples_text">Example:</strong></p>
  138. <pre class="listing"><span class="Keyword">import</span> <span class="Identifier">src</span><span class="Operator">/</span><span class="Identifier">checksums</span><span class="Operator">/</span><span class="Identifier">sha2</span>
  139. <span class="Keyword">var</span> <span class="Identifier">hasher</span> <span class="Operator">=</span> <span class="Identifier">initSha_384</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  140. <span class="Identifier">hasher</span><span class="Operator">.</span><span class="Identifier">update</span><span class="Punctuation">(</span><span class="StringLit">&quot;The quick brown fox &quot;</span><span class="Punctuation">)</span>
  141. <span class="Identifier">hasher</span><span class="Operator">.</span><span class="Identifier">update</span><span class="Punctuation">(</span><span class="StringLit">&quot;jumps over the lazy dog&quot;</span><span class="Punctuation">)</span>
  142. <span class="Keyword">let</span> <span class="Identifier">digest</span> <span class="Operator">=</span> <span class="Identifier">hasher</span><span class="Operator">.</span><span class="Identifier">digest</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  143. <span class="Identifier">assert</span> <span class="Operator">$</span><span class="Identifier">digest</span> <span class="Operator">==</span> <span class="StringLit">&quot;ca737f1014a48f4c0b6dd43cb177b0afd9e5169367544c494011e3317dbf9a509cb1e5dc1e85a941bbee3d7f2afbc9b1&quot;</span></pre></p>
  144. <div class="section" id="6">
  145. <h1><a class="toc-backref" href="#6">Imports</a></h1>
  146. <dl class="item">
  147. <a class="reference external" href="sha_utils.html">sha_utils</a>
  148. </dl>
  149. </div>
  150. <div class="section" id="7">
  151. <h1><a class="toc-backref" href="#7">Types</a></h1>
  152. <dl class="item">
  153. <div id="ShaDigest_224">
  154. <dt><pre><a href="sha2.html#ShaDigest_224"><span class="Identifier">ShaDigest_224</span></a> <span class="Other">=</span> <span class="Identifier">array</span><span class="Other">[</span><span class="DecNumber">28</span><span class="Other">,</span> <span class="Identifier">char</span><span class="Other">]</span></pre></dt>
  155. <dd>
  156. SHA-224 output digest.
  157. </dd>
  158. </div>
  159. <div id="ShaDigest_256">
  160. <dt><pre><a href="sha2.html#ShaDigest_256"><span class="Identifier">ShaDigest_256</span></a> <span class="Other">=</span> <span class="Identifier">array</span><span class="Other">[</span><span class="DecNumber">32</span><span class="Other">,</span> <span class="Identifier">char</span><span class="Other">]</span></pre></dt>
  161. <dd>
  162. SHA-256 output digest.
  163. </dd>
  164. </div>
  165. <div id="ShaDigest_384">
  166. <dt><pre><a href="sha2.html#ShaDigest_384"><span class="Identifier">ShaDigest_384</span></a> <span class="Other">=</span> <span class="Identifier">array</span><span class="Other">[</span><span class="DecNumber">48</span><span class="Other">,</span> <span class="Identifier">char</span><span class="Other">]</span></pre></dt>
  167. <dd>
  168. SHA-384 output digest.
  169. </dd>
  170. </div>
  171. <div id="ShaDigest_512">
  172. <dt><pre><a href="sha2.html#ShaDigest_512"><span class="Identifier">ShaDigest_512</span></a> <span class="Other">=</span> <span class="Identifier">array</span><span class="Other">[</span><span class="DecNumber">64</span><span class="Other">,</span> <span class="Identifier">char</span><span class="Other">]</span></pre></dt>
  173. <dd>
  174. SHA-512 output digest.
  175. </dd>
  176. </div>
  177. <div id="ShaInstance">
  178. <dt><pre><a href="sha2.html#ShaInstance"><span class="Identifier">ShaInstance</span></a> <span class="Other">=</span> <span class="Keyword">enum</span>
  179. <span class="Identifier">Sha_224</span><span class="Other">,</span> <span class="Comment">## SHA-224 with an output size of 28 bytes (truncated from SHA-256)</span>
  180. <span class="Identifier">Sha_256</span><span class="Other">,</span> <span class="Comment">## SHA-256 with an output size of 32 bytes</span>
  181. <span class="Identifier">Sha_384</span><span class="Other">,</span> <span class="Comment">## SHA-384 with an output size of 48 bytes (truncated from SHA-512)</span>
  182. <span class="Identifier">Sha_512</span> <span class="Comment">## SHA-512 with an output size of 64 bytes</span></pre></dt>
  183. <dd>
  184. Selects a specific SHA instance with well known message digest lengths and properties.
  185. </dd>
  186. </div>
  187. <div id="ShaState">
  188. <dt><pre><a href="sha2.html#ShaState"><span class="Identifier">ShaState</span></a> <span class="Other">=</span> <span class="Keyword">distinct</span> <span class="Identifier">ShaContext</span></pre></dt>
  189. <dd>
  190. <p>An unchecked SHA state created from a specific <tt class="docutils literal"><span class="pre"><span class="Identifier">ShaInstance</span></span></tt>.</p>
  191. <p>Unchecked meaning the user has to make sure that the target buffer has enough room to store the resulting digest, otherwise <tt class="docutils literal"><span class="pre"><span class="Identifier">digest</span></span></tt> will truncate the output.</p>
  192. </dd>
  193. </div>
  194. <div id="ShaStateStatic">
  195. <dt><pre><a href="sha2.html#ShaStateStatic"><span class="Identifier">ShaStateStatic</span></a><span class="Other">[</span><span class="Identifier">instance</span><span class="Other">]</span> <span class="Other">=</span> <span class="Keyword">distinct</span> <a href="sha2.html#ShaState"><span class="Identifier">ShaState</span></a></pre></dt>
  196. <dd>
  197. A statically checked SHA state created from a specific <tt class="docutils literal"><span class="pre"><span class="Identifier">ShaInstance</span></span></tt>.
  198. </dd>
  199. </div>
  200. </dl>
  201. </div>
  202. <div class="section" id="12">
  203. <h1><a class="toc-backref" href="#12">Procs</a></h1>
  204. <dl class="item">
  205. <div id="digest-procs-all">
  206. <div id="digest,ShaState,openArray[char]">
  207. <dt><pre><span class="Keyword">proc</span> <a href="#digest%2CShaState%2CopenArray%5Bchar%5D"><span class="Identifier">digest</span></a><span class="Other">(</span><span class="Identifier">state</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="sha2.html#ShaState"><span class="Identifier">ShaState</span></a><span class="Other">;</span> <span class="Identifier">dest</span><span class="Other">:</span> <span class="Keyword">var</span> <span class="Identifier">openArray</span><span class="Other">[</span><span class="Identifier">char</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">int</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
  208. <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  209. <dd>
  210. <p>Finishes, stores the completed message digest in <tt class="docutils literal"><span class="pre"><span class="Identifier">dest</span></span></tt> and returns the number of bytes written in <tt class="docutils literal"><span class="pre"><span class="Identifier">dest</span></span></tt>.</p>
  211. <p>If <tt class="docutils literal"><span class="pre"><span class="Identifier">dest</span></span></tt> is not big enough to contain the digest produced by the selected instance, everything that would overflow is truncated.</p>
  212. </dd>
  213. </div>
  214. <div id="digest,ShaStateStatic[ShaInstance]">
  215. <dt><pre><span class="Keyword">proc</span> <a href="#digest%2CShaStateStatic%5BShaInstance%5D"><span class="Identifier">digest</span></a><span class="Other">(</span><span class="Identifier">state</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="sha2.html#ShaStateStatic"><span class="Identifier">ShaStateStatic</span></a><span class="Other">[</span><span class="Identifier">Sha_224</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <a href="sha2.html#ShaDigest_224"><span class="Identifier">ShaDigest_224</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
  216. <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  217. <dd>
  218. Finishes and returns the completed SHA-224 message digest.
  219. </dd>
  220. </div>
  221. <div id="digest,ShaStateStatic[ShaInstance]_2">
  222. <dt><pre><span class="Keyword">proc</span> <a href="#digest%2CShaStateStatic%5BShaInstance%5D_2"><span class="Identifier">digest</span></a><span class="Other">(</span><span class="Identifier">state</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="sha2.html#ShaStateStatic"><span class="Identifier">ShaStateStatic</span></a><span class="Other">[</span><span class="Identifier">Sha_256</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <a href="sha2.html#ShaDigest_256"><span class="Identifier">ShaDigest_256</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
  223. <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  224. <dd>
  225. Finishes and returns the completed SHA-256 message digest.
  226. </dd>
  227. </div>
  228. <div id="digest,ShaStateStatic[ShaInstance]_3">
  229. <dt><pre><span class="Keyword">proc</span> <a href="#digest%2CShaStateStatic%5BShaInstance%5D_3"><span class="Identifier">digest</span></a><span class="Other">(</span><span class="Identifier">state</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="sha2.html#ShaStateStatic"><span class="Identifier">ShaStateStatic</span></a><span class="Other">[</span><span class="Identifier">Sha_384</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <a href="sha2.html#ShaDigest_384"><span class="Identifier">ShaDigest_384</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
  230. <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  231. <dd>
  232. Finishes and returns the completed SHA-284 message digest.
  233. </dd>
  234. </div>
  235. <div id="digest,ShaStateStatic[ShaInstance]_4">
  236. <dt><pre><span class="Keyword">proc</span> <a href="#digest%2CShaStateStatic%5BShaInstance%5D_4"><span class="Identifier">digest</span></a><span class="Other">(</span><span class="Identifier">state</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="sha2.html#ShaStateStatic"><span class="Identifier">ShaStateStatic</span></a><span class="Other">[</span><span class="Identifier">Sha_512</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <a href="sha2.html#ShaDigest_512"><span class="Identifier">ShaDigest_512</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
  237. <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  238. <dd>
  239. Finishes and returns the completed SHA-512 message digest.
  240. </dd>
  241. </div>
  242. </div>
  243. <div id="digestLength-procs-all">
  244. <div id="digestLength,ShaInstance">
  245. <dt><pre><span class="Keyword">func</span> <a href="#digestLength%2CShaInstance"><span class="Identifier">digestLength</span></a><span class="Other">(</span><span class="Identifier">instance</span><span class="Other">:</span> <a href="sha2.html#ShaInstance"><span class="Identifier">ShaInstance</span></a><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">int</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
  246. <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  247. <dd>
  248. Returns the message digest size for the selected SHA instance.
  249. </dd>
  250. </div>
  251. </div>
  252. <div id="initSha-procs-all">
  253. <div id="initSha,ShaInstance">
  254. <dt><pre><span class="Keyword">func</span> <a href="#initSha%2CShaInstance"><span class="Identifier">initSha</span></a><span class="Other">(</span><span class="Identifier">instance</span><span class="Other">:</span> <a href="sha2.html#ShaInstance"><span class="Identifier">ShaInstance</span></a><span class="Other">)</span><span class="Other">:</span> <a href="sha2.html#ShaState"><span class="Identifier">ShaState</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
  255. <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  256. <dd>
  257. Constructs a new unchecked SHA state for the selected instance <tt class="docutils literal"><span class="pre"><span class="Identifier">instance</span></span></tt>.
  258. </dd>
  259. </div>
  260. </div>
  261. <div id="initSha_224-procs-all">
  262. <div id="initSha_224">
  263. <dt><pre><span class="Keyword">func</span> <a href="#initSha_224"><span class="Identifier">initSha_224</span></a><span class="Other">(</span><span class="Other">)</span><span class="Other">:</span> <a href="sha2.html#ShaStateStatic"><span class="Identifier">ShaStateStatic</span></a><span class="Other">[</span><span class="Identifier">Sha_224</span><span class="Other">]</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  264. <dd>
  265. Constructs a new statically checked state for the SHA-224 instance.
  266. </dd>
  267. </div>
  268. </div>
  269. <div id="initSha_256-procs-all">
  270. <div id="initSha_256">
  271. <dt><pre><span class="Keyword">func</span> <a href="#initSha_256"><span class="Identifier">initSha_256</span></a><span class="Other">(</span><span class="Other">)</span><span class="Other">:</span> <a href="sha2.html#ShaStateStatic"><span class="Identifier">ShaStateStatic</span></a><span class="Other">[</span><span class="Identifier">Sha_256</span><span class="Other">]</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  272. <dd>
  273. Constructs a new statically checked state for the SHA-256 instance.
  274. </dd>
  275. </div>
  276. </div>
  277. <div id="initSha_384-procs-all">
  278. <div id="initSha_384">
  279. <dt><pre><span class="Keyword">func</span> <a href="#initSha_384"><span class="Identifier">initSha_384</span></a><span class="Other">(</span><span class="Other">)</span><span class="Other">:</span> <a href="sha2.html#ShaStateStatic"><span class="Identifier">ShaStateStatic</span></a><span class="Other">[</span><span class="Identifier">Sha_384</span><span class="Other">]</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  280. <dd>
  281. Constructs a new statically checked state for the SHA-384 instance.
  282. </dd>
  283. </div>
  284. </div>
  285. <div id="initSha_512-procs-all">
  286. <div id="initSha_512">
  287. <dt><pre><span class="Keyword">func</span> <a href="#initSha_512"><span class="Identifier">initSha_512</span></a><span class="Other">(</span><span class="Other">)</span><span class="Other">:</span> <a href="sha2.html#ShaStateStatic"><span class="Identifier">ShaStateStatic</span></a><span class="Other">[</span><span class="Identifier">Sha_512</span><span class="Other">]</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  288. <dd>
  289. Constructs a new statically checked state for the SHA-512 instance.
  290. </dd>
  291. </div>
  292. </div>
  293. <div id="initShaStateStatic-procs-all">
  294. <div id="initShaStateStatic,staticShaInstance">
  295. <dt><pre><span class="Keyword">func</span> <a href="#initShaStateStatic%2CstaticShaInstance"><span class="Identifier">initShaStateStatic</span></a><span class="Other">(</span><span class="Identifier">instance</span><span class="Other">:</span> <span class="Identifier">static</span> <span class="Identifier">ShaInstance</span><span class="Other">)</span><span class="Other">:</span> <a href="sha2.html#ShaStateStatic"><span class="Identifier">ShaStateStatic</span></a><span class="Other">[</span><span class="Identifier">instance</span><span class="Other">]</span></pre></dt>
  296. <dd>
  297. Constructs a new statically checked SHA state for the selected instance <tt class="docutils literal"><span class="pre"><span class="Identifier">instance</span></span></tt>.
  298. </dd>
  299. </div>
  300. </div>
  301. <div id="secureHash-procs-all">
  302. <div id="secureHash,ShaInstance,openArray[char]">
  303. <dt><pre><span class="Keyword">proc</span> <a href="#secureHash%2CShaInstance%2CopenArray%5Bchar%5D"><span class="Identifier">secureHash</span></a><span class="Other">(</span><span class="Identifier">instance</span><span class="Other">:</span> <a href="sha2.html#ShaInstance"><span class="Identifier">ShaInstance</span></a><span class="Other">;</span> <span class="Identifier">data</span><span class="Other">:</span> <span class="Identifier">openArray</span><span class="Other">[</span><span class="Identifier">char</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">seq</span><span class="Other">[</span><span class="Identifier">char</span><span class="Other">]</span> {.
  304. <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  305. <dd>
  306. Convenience wrapper around the standard &quot;init, update, digest&quot; sequence with a runtime selected SHA instance.
  307. </dd>
  308. </div>
  309. <div id="secureHash,staticShaInstance,openArray[char]">
  310. <dt><pre><span class="Keyword">proc</span> <a href="#secureHash%2CstaticShaInstance%2CopenArray%5Bchar%5D"><span class="Identifier">secureHash</span></a><span class="Other">(</span><span class="Identifier">instance</span><span class="Other">:</span> <span class="Identifier">static</span> <span class="Identifier">ShaInstance</span><span class="Other">;</span> <span class="Identifier">data</span><span class="Other">:</span> <span class="Identifier">openArray</span><span class="Other">[</span><span class="Identifier">char</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">auto</span></pre></dt>
  311. <dd>
  312. Convenience wrapper around the standard &quot;init, update, digest&quot; sequence with a statically selected SHA instance.
  313. </dd>
  314. </div>
  315. </div>
  316. <div id="update-procs-all">
  317. <div id="update,ShaState,openArray[char]">
  318. <dt><pre><span class="Keyword">proc</span> <a href="#update%2CShaState%2CopenArray%5Bchar%5D"><span class="Identifier">update</span></a><span class="Other">(</span><span class="Identifier">state</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="sha2.html#ShaState"><span class="Identifier">ShaState</span></a><span class="Other">;</span> <span class="Identifier">data</span><span class="Other">:</span> <span class="Identifier">openArray</span><span class="Other">[</span><span class="Identifier">char</span><span class="Other">]</span><span class="Other">)</span> {.<span class="Identifier">borrow</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
  319. <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  320. <dd>
  321. Updates the given <tt class="docutils literal"><span class="pre"><span class="Identifier">ShaState</span></span></tt> with the provided buffer <tt class="docutils literal"><span class="pre"><span class="Identifier">data</span></span></tt>.
  322. </dd>
  323. </div>
  324. <div id="update,ShaStateStatic[instance],openArray[char]">
  325. <dt><pre><span class="Keyword">proc</span> <a href="#update%2CShaStateStatic%5Binstance%5D%2CopenArray%5Bchar%5D"><span class="Identifier">update</span></a><span class="Other">[</span><span class="Identifier">instance</span><span class="Other">:</span> <span class="Identifier">static</span> <span class="Identifier">ShaInstance</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">state</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="sha2.html#ShaStateStatic"><span class="Identifier">ShaStateStatic</span></a><span class="Other">[</span><span class="Identifier">instance</span><span class="Other">]</span><span class="Other">;</span>
  326. <span class="Identifier">data</span><span class="Other">:</span> <span class="Identifier">openArray</span><span class="Other">[</span><span class="Identifier">char</span><span class="Other">]</span><span class="Other">)</span></pre></dt>
  327. <dd>
  328. Updates the given <tt class="docutils literal"><span class="pre"><span class="Identifier">ShaStateStatic</span></span></tt> with the provided buffer <tt class="docutils literal"><span class="pre"><span class="Identifier">data</span></span></tt>.
  329. </dd>
  330. </div>
  331. </div>
  332. </dl>
  333. </div>
  334. </div>
  335. </div>
  336. <div class="twelve-columns footer">
  337. <span class="nim-sprite"></span>
  338. <br>
  339. <small style="color: var(--hint);">Made with Nim. Generated: 2025-02-03 14:57:40 UTC</small>
  340. </div>
  341. </div>
  342. </div>
  343. <script defer data-domain="nim-lang.org" src="https://plausible.io/js/plausible.js"></script>
  344. </body>
  345. </html>