oSHA256.xml 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <chapter id='oSHA256'>
  2. <title>
  3. Class oSHA256
  4. </title>
  5. <section id="oSHA256-class" >
  6. <title>
  7. Introduction
  8. </title>
  9. <para>
  10. This class implements 256-bit encryption according to FIPS180-2 sec 5.3.2 by converting variable-length input to a fixed-length, 32-byte digest. The class is analagous to a file, allowing an unlimited amount of data may be written but only a fixed-length amount of data may be read and each read rewinds the file.
  11. </para>
  12. <para>
  13. This class is declared in <ulink url='oSHA256.hpp.html'>oSHA256.hpp</ulink> and defined in <ulink url='oSHA256.cpp.html'>oSHA256.cpp</ulink>.
  14. </para>
  15. <section id="oSHA256-inheritance">
  16. <title>
  17. Inheritance
  18. </title>
  19. <para>
  20. None.
  21. </para>
  22. </section>
  23. <section id="oSHA256-dependence">
  24. <title>
  25. Dependence
  26. </title>
  27. <para>
  28. None.
  29. </para>
  30. </section>
  31. </section>
  32. <section id="oSHA256-properties">
  33. <title>
  34. Properties
  35. </title>
  36. <para>
  37. </para>
  38. <section id="oSHA256-DigestLength">
  39. <title>
  40. oSHA256::DigestLength
  41. </title>
  42. <funcsynopsis>
  43. <funcprototype>
  44. <funcdef>unsigned <function>DigestLength</function></funcdef>
  45. <paramdef></paramdef>
  46. </funcprototype>
  47. </funcsynopsis>
  48. <para>
  49. Return the digest length in bytes. The digest length is <constant>32</constant>. This property is implemented as a constant and so parenthesis should be omitted when referencing it, despite what is shown.
  50. </para>
  51. </section>
  52. </section>
  53. <section id="oSHA256-methods">
  54. <title>
  55. Methods
  56. </title>
  57. <para>
  58. </para>
  59. <section id="oSHA256-Fetch">
  60. <title>
  61. oSHA256::Fetch
  62. </title>
  63. <funcsynopsis>
  64. <funcprototype>
  65. <funcdef>oSHA256 &amp; <function>Fetch</function></funcdef>
  66. <paramdef>void * <parameter>memory</parameter></paramdef>
  67. </funcprototype>
  68. </funcsynopsis>
  69. <para>
  70. End the current encryption cycle and copy the <varname>digest</varname> to external memory. The digest length is <link linkend='oSHA256-DigestLength'>DigestLength</link> bytes so no length argument is needed. Automatically, initialize the object instance for another encryption cycle once the digest has been copied.
  71. </para>
  72. </section>
  73. <section id="oSHA256-Write">
  74. <title>
  75. oSHA256::Write
  76. </title>
  77. <funcsynopsis>
  78. <funcprototype>
  79. <funcdef>oSHA256 &amp; <function>Write</function></funcdef>
  80. <paramdef>void const * <parameter>memory</parameter></paramdef>
  81. <paramdef>size_t <parameter>extent</parameter></paramdef>
  82. </funcprototype>
  83. </funcsynopsis>
  84. <para>
  85. Encrypt a block of <varname>memory</varname>. Return the object instance address. This method may be called any number of times with any data of any length. Data encryption is cumulative such that data may be encrypted in one large block or many small ones. All writes prior to a <link linkend='oSHA256-Fetch'>Fetch</link> comprise an <quote>encryption cycle</quote>
  86. </para>
  87. </section>
  88. <section id="oSHA256-Reset">
  89. <title>
  90. oSHA256::Reset
  91. </title>
  92. <funcsynopsis>
  93. <funcprototype>
  94. <funcdef>oSHA256 &amp; <function>Reset</function></funcdef>
  95. <paramdef>void</paramdef>
  96. </funcprototype>
  97. </funcsynopsis>
  98. <para>
  99. Initialize the class instance in preparation for another encryption cycle. Return the object instance reference. This discards the computed digest in the process. If the digest is needed then call method <link linkend='oSHA256-Fetch'>Fetch</link>, instead.
  100. </para>
  101. </section>
  102. </section>
  103. <section id="oSHA256-examples">
  104. <title>
  105. Examples
  106. </title>
  107. <example>
  108. <title>
  109. Computing an SHA256 Digest
  110. </title>
  111. <programlisting>
  112. oSHA256 <varname>encoder</varname>;
  113. uint8_t <varname>digest</varname> [<varname>encoder</varname>.<function>DigestLength</function>];
  114. char <varname>buffer</varname> [<constant>1024</constant>];
  115. signed <varname>length</varname>;
  116. signed <varname>fd</varname>;
  117. while ((<varname>length</varname> = read (<varname>fd</varname>, <varname>buffer</varname>, sizeof (<varname>buffer</varname>))) &gt; <constant>0</constant>)
  118. {
  119. <varname>encoder</varname>.<function>Write</function> (<varname>buffer</varname>, <varname>length</varname>);
  120. }
  121. <varname>encoder</varname>.<function>Fetch</function> (<varname>digest</varname>);
  122. </programlisting>
  123. <para>
  124. This example computes the SHA256 digest for an entire file. An <varname>encoder</varname> is instantiated and a <varname>digest</varname> buffer is reserved. As each <varname>buffer</varname> is read from file, it is encrypted using the <link linkend='oSHA256-Write'>Write</link> method and, at the end, the <varname>digest</varname> is obtained using the <link linkend='oSHA256-Fetch'>Fetch</link> method.
  125. </para>
  126. <para>
  127. The file content is not important. It may be either text or a binary. The computed <varname>digest</varname> will, for all practical purposes, be unique and may serve as the file <quote>finger-print</quote>. Therefore, two files having the same <varname>digest</varname> are, in all probability, identical.
  128. </para>
  129. </example>
  130. </section>
  131. </chapter>