SHA256Fetch.c.html 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?xml version='1.0' encoding='iso-8859-1'?>
  2. <!doctype html public '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
  3. <html xmlns='http://www.w3c.org/1999/xhtml' lang='en-us'>
  4. <head>
  5. <title>
  6. SHA256Fetch.c
  7. </title>
  8. <meta http-equiv='content-type' content='text/html;iso-8859-1'/>
  9. <meta name='generator' content='motley-tools 1.9.4 13:40:33 Feb 18 2015'/>
  10. <meta name='author' content='cmaier@cmassoc.net'/>
  11. <meta name='robots' content='noindex,nofollow'/>
  12. <link href='toolkit.css' rel='stylesheet' type='text/css'/>
  13. </head>
  14. <body>
  15. <div class='headerlink'>
  16. [<a href='SHA256.c.html' title=' SHA256.c '>PREV</a>]
  17. [<a href='toolkit.html' title=' Index '>HOME</a>]
  18. [<a href='SHA256Ident.c.html' title=' SHA256Ident.c '>NEXT</a>]
  19. </div>
  20. <pre>
  21. /*====================================================================*
  22. *
  23. * void SHA256Fetch (struct sha256 * sha256, uint8_t digest []);
  24. *
  25. * SHA256.h
  26. *
  27. * read the SHA256 digest; this function works like function read()
  28. * but the function returns no value and the digest buffer is fixed
  29. * length;
  30. *
  31. * to start a digest, use function SHA256Reset(); to write data to
  32. * the digest use function SHA256Write();
  33. *
  34. * Read standard FIPS180-2 sec 5.3.2 for an explanation;
  35. *
  36. * Motley Tools by Charles Maier &lt;cmaier@cmassoc.net&gt;;
  37. * Copyright (c) 2001-2006 by Charles Maier Associates;
  38. * Licensed under the Internet Software Consortium License;
  39. *
  40. *--------------------------------------------------------------------*/
  41. #ifndef SHA256FETCH_SOURCE
  42. #define SHA256FETCH_SOURCE
  43. #include &quot;../key/SHA256.h&quot;
  44. static void encode (uint8_t memory [], uint32_t number)
  45. {
  46. *memory++ = (uint8_t)(number &gt;&gt; 24);
  47. *memory++ = (uint8_t)(number &gt;&gt; 16);
  48. *memory++ = (uint8_t)(number &gt;&gt; 8);
  49. *memory++ = (uint8_t)(number &gt;&gt; 0);
  50. return;
  51. }
  52. void SHA256Fetch (struct sha256 * sha256, uint8_t digest [])
  53. {
  54. unsigned word;
  55. uint8_t bits [8];
  56. uint32_t upper = (sha256-&gt;count [0] &gt;&gt; 29) | (sha256-&gt;count [1] &lt;&lt; 3);
  57. uint32_t lower = (sha256-&gt;count [0] &lt;&lt; 3);
  58. uint32_t final = (sha256-&gt;count [0] &amp; 0x3F);
  59. uint32_t extra = (final &lt; 56)? (56 - final): (120 - final);
  60. encode (&amp;bits [0], upper);
  61. encode (&amp;bits [4], lower);
  62. SHA256Write (sha256, sha256-&gt;extra, extra);
  63. SHA256Write (sha256, bits, sizeof (bits));
  64. for (word = 0; word &lt; sizeof (sha256-&gt;state) / sizeof (uint32_t); word++)
  65. {
  66. encode (digest, sha256-&gt;state [word]);
  67. digest += sizeof (uint32_t);
  68. }
  69. memset (sha256, 0, sizeof (struct sha256));
  70. return;
  71. }
  72. #endif
  73. </pre>
  74. <div class='footerlink'>
  75. [<a href='SHA256.c.html' title=' SHA256.c '>PREV</a>]
  76. [<a href='toolkit.html' title=' Index '>HOME</a>]
  77. [<a href='SHA256Ident.c.html' title=' SHA256Ident.c '>NEXT</a>]
  78. </div>
  79. </body>
  80. </html>