SHA256Write.c.html 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. SHA256Write.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='SHA256Reset.c.html' title=' SHA256Reset.c '>PREV</a>]
  17. [<a href='toolkit.html' title=' Index '>HOME</a>]
  18. [<a href='SignalToNoise1.c.html' title=' SignalToNoise1.c '>NEXT</a>]
  19. </div>
  20. <pre>
  21. /*====================================================================*
  22. *
  23. * void SHA256Write (struct sha256 * sha256, void const * memory, size_t extent);
  24. *
  25. * SHA256.h
  26. *
  27. * write a block of data to an SHA256 digest; this function behaves
  28. * like function write() but returns no value and does not fail; an
  29. * unlimited amount of data may be written using successive writes;
  30. *
  31. * to start a new digest, use function SHA266Reset(); to read the
  32. * digest, use function SHA256Fetch();
  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 SHA256WRITE_SOURCE
  42. #define SHA256WRITE_SOURCE
  43. #include &quot;../key/SHA256.h&quot;
  44. void SHA256Write (struct sha256 * sha256, void const * memory, size_t extent)
  45. {
  46. if (extent)
  47. {
  48. uint8_t * buffer = (uint8_t *)(memory);
  49. unsigned left = sha256-&gt;count [0] &amp; 0x3F;
  50. unsigned fill = sizeof (sha256-&gt;block) - left;
  51. sha256-&gt;count [0] += (uint32_t)(extent);
  52. sha256-&gt;count [0] &amp;= 0xFFFFFFFF;
  53. if (sha256-&gt;count [0] &lt; extent)
  54. {
  55. sha256-&gt;count [1]++;
  56. }
  57. if ((left) &amp;&amp; (extent &gt;= fill))
  58. {
  59. memcpy (sha256-&gt;block + left, buffer, fill);
  60. SHA256Block (sha256, sha256-&gt;block);
  61. extent -= fill;
  62. buffer += fill;
  63. left = 0;
  64. }
  65. while (extent &gt;= sizeof (sha256-&gt;block))
  66. {
  67. SHA256Block (sha256, buffer);
  68. extent -= sizeof (sha256-&gt;block);
  69. buffer += sizeof (sha256-&gt;block);
  70. }
  71. if (extent)
  72. {
  73. memcpy (sha256-&gt;block + left, buffer, extent);
  74. }
  75. }
  76. return;
  77. }
  78. #endif
  79. </pre>
  80. <div class='footerlink'>
  81. [<a href='SHA256Reset.c.html' title=' SHA256Reset.c '>PREV</a>]
  82. [<a href='toolkit.html' title=' Index '>HOME</a>]
  83. [<a href='SignalToNoise1.c.html' title=' SignalToNoise1.c '>NEXT</a>]
  84. </div>
  85. </body>
  86. </html>