oHPAVKey.xml 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. <chapter id='oHPAVKey'>
  2. <title>
  3. Class oHPAVKey
  4. </title>
  5. <section id="oHPAVKey-class" >
  6. <title>
  7. Introduction
  8. </title>
  9. <para>
  10. This class implements a HomePlug AV compliant encryption key generator. It can be used to generate a Device Access Key (<acronym>DAK</acronym>), Network Management Key (<acronym>NMK</acronym>) or Network Identifier (<acronym>NID</acronym>) from user supplied passwords or pass phrases. It can also be used to verify that passwords and pass phrases conform to recommendations outlined in the <citetitle>HomePlug AV Specification</citetitle>, although such conformace is optional.
  11. </para>
  12. <para>
  13. This class is declared in <ulink url='oHPAVKey.hpp.html'>oHPAVKey.hpp</ulink> and defined in <ulink url='oHPAVKey.cpp.html'>oHPAVKey.cpp</ulink>.
  14. </para>
  15. <section id="oHPAVKey-inheritance">
  16. <title>
  17. Inheritance
  18. </title>
  19. <para>
  20. This class inherits the <link linkend='oflagword'>oflagword</link> class to implement the validation flagword. All public flagword properties and methods are accessible.
  21. </para>
  22. </section>
  23. <section id="oHPAVKey-dependence">
  24. <title>
  25. Dependence
  26. </title>
  27. <para>
  28. None.
  29. </para>
  30. </section>
  31. </section>
  32. <section id="oHPAVKey-properties">
  33. <title>
  34. Properties
  35. </title>
  36. <para>
  37. None.
  38. </para>
  39. <section id="oHPAVKey-DAKLength">
  40. <title>
  41. oHPAVKey::DAKLength
  42. </title>
  43. <funcsynopsis>
  44. <funcprototype>
  45. <funcdef>unsigned <function>DAKLength</function></funcdef>
  46. <paramdef><parameter></parameter></paramdef>
  47. </funcprototype>
  48. </funcsynopsis>
  49. <para>
  50. The length of an Device Access Key (<acronym>DAK</acronym>) in bytes as defined in the <citetitle>HomePlug AV Specification</citetitle>. This property is implemented as a true constant. Parenthesis are not used when referencing it.
  51. </para>
  52. </section>
  53. <section id="oHPAVKey-DigestLength">
  54. <title>
  55. oHPAVKey::DigestLength
  56. </title>
  57. <funcsynopsis>
  58. <funcprototype>
  59. <funcdef>unsigned <function>DigestLength</function></funcdef>
  60. <paramdef><parameter></parameter></paramdef>
  61. </funcprototype>
  62. </funcsynopsis>
  63. <para>
  64. The SHA256 digest length in bytes. All HomePlug AV keys are first computed as an SHA256 digest but only a portion of the digest is used as the key. The portion used depends on the key type. HomePlug AV keys will never exceed this length. This property is implemented as a true constant. Parenthesis are not used when referencing it.
  65. </para>
  66. </section>
  67. <section id="oHPAVKey-MaxCharValue">
  68. <title>
  69. oHPAVKey::MaxCharValue
  70. </title>
  71. <funcsynopsis>
  72. <funcprototype>
  73. <funcdef>unsigned <function>MaxCharValue</function></funcdef>
  74. <paramdef><parameter></parameter></paramdef>
  75. </funcprototype>
  76. </funcsynopsis>
  77. <para>
  78. The maximum character value permitted in a HomePlug AV compliant pass phrase, as defined in the <citetitle>HomePlug AV Specification</citetitle>. Key encryption will work given any byte value but this constant is provided for cases where HomePlug AV compliance is important. Class method <link linkend='oHPAVKey-IllegalCharValue'>IllegalCharValue</link> uses this constant internally when validating pass phrases. This property is implemented as a true constant. Parenthesis are not used when referencing it.
  79. </para>
  80. </section>
  81. <section id="oHPAVKey-MaxPhraseLength">
  82. <title>
  83. oHPAVKey::MaxPhraseLength
  84. </title>
  85. <funcsynopsis>
  86. <funcprototype>
  87. <funcdef>unsigned <function>MaxPhraseLength</function></funcdef>
  88. <paramdef><parameter></parameter></paramdef>
  89. </funcprototype>
  90. </funcsynopsis>
  91. <para>
  92. The maximum length of a HomePlug AV compliant pass phrase, as defined in the <citetitle>HomePlug AV Specification</citetitle>. Key encryption will work given pass phrases of any length but this constant is provided for cases where HomePlug AV compliance is important. Class method <link linkend='oHPAVKey-IllegalPassPhrase'>IllegalPassPhrase</link> uses this constant internally when validating pass phrases. This property is implemented as a true constant. Parenthesis are not used when referencing it.
  93. </para>
  94. </section>
  95. <section id="oHPAVKey-MinCharValue">
  96. <title>
  97. oHPAVKey::MinCharValue
  98. </title>
  99. <funcsynopsis>
  100. <funcprototype>
  101. <funcdef>unsigned <function>MinCharValue</function></funcdef>
  102. <paramdef><parameter></parameter></paramdef>
  103. </funcprototype>
  104. </funcsynopsis>
  105. <para>
  106. The minimum character value permitted in a HomePlug AV compliant pass phrase, as defined in the <citetitle>HomePlug AV Specification</citetitle>. Key encryption will work given any byte value but this constant is provided for cases where HomePlug AV compliance is important. Class method <link linkend='oHPAVKey-IllegalCharValue'>IllegalCharValue</link> uses this constant internally when validating pass phrases. This property is implemented as a true constant. Parenthesis are not used when referencing it.
  107. </para>
  108. </section>
  109. <section id="oHPAVKey-MinPhraseLength">
  110. <title>
  111. oHPAVKey::MinPhraseLength
  112. </title>
  113. <funcsynopsis>
  114. <funcprototype>
  115. <funcdef>unsigned <function>MinPhraseLength</function></funcdef>
  116. <paramdef><parameter></parameter></paramdef>
  117. </funcprototype>
  118. </funcsynopsis>
  119. <para>
  120. The minimum length of a HomePlug AV compliant pass phrase, as defined in the <citetitle>HomePlug AV Specification</citetitle>. Key encryption will work given pass phrases of any length but this constant is provided for cases where HomePlug AV compliance is important. Class method <link linkend='oHPAVKey-IllegalPassPhrase'>IllegalPassPhrase</link> uses this constant internally when validating pass phrases.This property is implemented as a true constant. Parenthesis are not used when referencing it.
  121. </para>
  122. </section>
  123. <section id="oHPAVKey-NIDLength">
  124. <title>
  125. oHPAVKey::NIDLength
  126. </title>
  127. <funcsynopsis>
  128. <funcprototype>
  129. <funcdef>unsigned <function>NIDLength</function></funcdef>
  130. <paramdef><parameter></parameter></paramdef>
  131. </funcprototype>
  132. </funcsynopsis>
  133. <para>
  134. The length of a Network Identifier (<acronym>NID</acronym>) in bytes as defined in the <citetitle>HomePlug AV Specification</citetitle>. This property is implemented as a true constant. Parenthesis are not used when referencing it.
  135. </para>
  136. </section>
  137. <section id="oHPAVKey-NMKLength">
  138. <title>
  139. oHPAVKey::NMKLength
  140. </title>
  141. <funcsynopsis>
  142. <funcprototype>
  143. <funcdef>unsigned <function>NMKLength</function></funcdef>
  144. <paramdef><parameter></parameter></paramdef>
  145. </funcprototype>
  146. </funcsynopsis>
  147. <para>
  148. The length of a Network Membership Key (<acronym>NMK</acronym>) in bytes as defined in the <citetitle>HomePlug AV Specification</citetitle>. This property is implemented as a true constant. Parenthesis are not used when referencing it.
  149. </para>
  150. </section>
  151. </section>
  152. <section id="oHPAVKey-methods">
  153. <title>
  154. Methods
  155. </title>
  156. <para>
  157. </para>
  158. <section id="oHPAVKey-ComputeDAK">
  159. <title>
  160. oHPAVKey::ComputeDAK
  161. </title>
  162. <funcsynopsis>
  163. <funcprototype>
  164. <funcdef>oHPAVKey &amp; <function>ComputeDAK</function></funcdef>
  165. <paramdef>char const * <parameter>phrase</parameter></paramdef>
  166. </funcprototype>
  167. </funcsynopsis>
  168. <para>
  169. Compute the HomePlug AV compliant Device Access Key (<acronym>DAK</acronym>) from the <constant>NUL</constant> terminated pass phrase string. Return the object instance reference. Use method <link linkend='oHPAVKey-ExportKey'>ExportKey</link> to obtain the key portion of the computed digest. The string argument is called the <quote>Device Password</quote> but the encrypted version is called the <quote>Device Access Key</quote>.
  170. </para>
  171. <para>
  172. This method does not enforce HomePlug AV pass phrase rules. Consequently, the pass phrase may be any length and contain any non-<constant>NUL</constant> character value. Use method <link linkend='oHPAVKey-IllegalPassPhrase'>IllegalPassPhrase</link> to validate the string argument before calling this method, if HomePlug AV pass phrase compliance is important.
  173. </para>
  174. </section>
  175. <section id="oHPAVKey-ComputeNMK">
  176. <title>
  177. oHPAVKey::ComputeNMK
  178. </title>
  179. <funcsynopsis>
  180. <funcprototype>
  181. <funcdef>oHPAVKey &amp; <function>ComputeNMK</function></funcdef>
  182. <paramdef>char const * <parameter>phrase</parameter></paramdef>
  183. </funcprototype>
  184. </funcsynopsis>
  185. <para>
  186. Compute the HomePlug AV compliant Network Membership Key (<acronym>NMK</acronym>) from the <constant>NUL</constant> terminated pass phrase string. Return the object instance reference. Use method <link linkend='oHPAVKey-ExportKey'>ExportKey</link> to obtain the key portion of the computed digest. The string argument is called the <quote>Network Password</quote> but the encrypted version is called the <quote>Network Membership Key</quote>.
  187. </para>
  188. <para>
  189. This method does not enforce HomePlug AV pass phrase rules. Consequently, the pass phrase may be any length and contain any non-<constant>NUL</constant> character value. Use method <link linkend='oHPAVKey-IllegalPassPhrase'>IllegalPassPhrase</link> to validate the string argument before calling this method, if HomePlug AV pass phrase compliance is important.
  190. </para>
  191. </section>
  192. <section id="oHPAVKey-ComputeNID">
  193. <title>
  194. oHPAVKey::ComputeNID
  195. </title>
  196. <funcsynopsis>
  197. <funcprototype>
  198. <funcdef>oHPAVKey &amp; <function>ComputeNID</function></funcdef>
  199. <paramdef> byte <parameter>level</parameter></paramdef>
  200. </funcprototype>
  201. </funcsynopsis>
  202. <para>
  203. Compute the HomePlug AV compliant preferred Network Identifier (<acronym>NID</acronym>) from the encrypted Network Membership Key. Return the object instance reference. This method assumes that an <varname>NMK</varname> has just been computed using method <link linkend='oHPAVKey-ComputeNMK'>ComputeNMK</link>. Use method <link linkend='oHPAVKey-ExportKey'>ExportKey</link> to obtain the key portion of the digest.
  204. </para>
  205. <para>
  206. The preferred <acronym>NID</acronym> is derived by encrypting the <acronym>NMK</acronym>. This means that a new preferred <acronym>NID</acronym> should be computed whenever the <acronym>NMK</acronym> is computed.
  207. </para>
  208. </section>
  209. <section id="oHPAVKey-ExportKey">
  210. <title>
  211. oHPAVKey::ExportKey
  212. </title>
  213. <funcsynopsis>
  214. <funcprototype>
  215. <funcdef>oHPAVKey &amp; <function>ExportKey</function></funcdef>
  216. <paramdef>void const * <parameter>memory</parameter></paramdef>
  217. </funcprototype>
  218. </funcsynopsis>
  219. <para>
  220. Copy the computed digest to external memory. The computed digest is <link linkend='oHPAVKey-DigestLength'>DigestLength</link> bytes in length, but fewer bytes may be copied, depending on the key type that was last computed. Only <link linkend='oHPAVKey-DAKLength'>DAKLength</link> bytes are copied for a <acronym>DAK</acronym>. Only <link linkend='oHPAVKey-NMKLength'>NMKLength</link> bytes are copied for an <acronym>NMK</acronym>. Only <link linkend='oHPAVKey-NIDLength'>NIDLength</link> bytes are copied for a <acronym>NID</acronym>.
  221. </para>
  222. </section>
  223. <section id="oHPAVKey-IllegalCharValue">
  224. <title>
  225. oHPAVKey::IllegalCharValue
  226. </title>
  227. <funcsynopsis>
  228. <funcprototype>
  229. <funcdef>bool <function>IllegalCharValue</function></funcdef>
  230. <paramdef>unsigned <parameter>character</parameter></paramdef>
  231. </funcprototype>
  232. </funcsynopsis>
  233. <para>
  234. Return <constant>true</constant> if the character argument <varname>character</varname> exceeds the range <link linkend='oHPAVKey-MinCharValue'>MinCharValue</link> through <link linkend='oHPAVKey-MaxCharValue'>MaxCharValue</link>.
  235. </para>
  236. </section>
  237. <section id="oHPAVKey-IllegalPassPhrase">
  238. <title>
  239. oHPAVKey::IllegalPassPhrase
  240. </title>
  241. <funcsynopsis>
  242. <funcprototype>
  243. <funcdef>bool <function>IllegalPassPhrase</function></funcdef>
  244. <paramdef>char const * <parameter>phrase</parameter></paramdef>
  245. </funcprototype>
  246. </funcsynopsis>
  247. <para>
  248. Return <constant>true</constant> if character string argument <varname>phrase</varname> either contains illegal characters, as determined by method <link linkend='oHPAVKey-IllegalCharValue'>IllegalCharValue</link>, or exceeds the lengths <link linkend='oHPAVKey-MinPhraseLength'>MinPhraseLength</link> through <link linkend='oHPAVKey-MaxPhraseLength'>MaxPhraseLength</link>.
  249. </para>
  250. </section>
  251. <section id="oHPAVKey-Print">
  252. <title>
  253. oHPAVKey::Print
  254. </title>
  255. <funcsynopsis>
  256. <funcprototype>
  257. <funcdef>oHPAVKey &amp; <function>Print</function></funcdef>
  258. <paramdef>char const * <parameter>phrase</parameter></paramdef>
  259. </funcprototype>
  260. </funcsynopsis>
  261. <para>
  262. Print the last computed key on stdout. If argument <varname>phrase</varname> is not <constant>NULL</constant> and is not empty then append one space and print the phrase. Terminate output with a newline.
  263. </para>
  264. </section>
  265. </section>
  266. <section id="oHPAVKey-examples">
  267. <title>
  268. Examples
  269. </title>
  270. <example>
  271. <title>
  272. Encrypt a Device Password
  273. </title>
  274. <programlisting>
  275. oHPAVKey <varname>encoder</varname>;
  276. char * <varname>password</varname> = "HelloWorld!";
  277. byte <varname>buffer</varname> [<varname>encoder</varname>.<constant>DigestLength</constant>]
  278. <varname>encoder</varname>.<function>ComputeDAK</function> (<varname>password</varname>);
  279. <varname>encoder</varname>.<function>ExportKey</function> (<varname>buffer</varname>)
  280. </programlisting>
  281. <para>
  282. This example instantiates an <varname>encoder</varname>, defines the <varname>password</varname> to be encrypted and allocates a <varname>buffer</varname> having <link linkend='oHPAVKey-DigestLength'>DigestLength</link> bytes. Class method <link linkend='oHPAVKey-ComputeDAK'>ComputeDAK</link> encrypts the <varname>password</varname> using <acronym>DAK</acronym> encryption rules. Method <link linkend='oHPAVKey-ExportKey'>ExportKey</link> copies the encrypted password into <varname>buffer</varname>. Since <varname>buffer</varname> contains a <acronym>DAK</acronym>, only the first <link linkend='oHPAVKey-DAKLength'>DAKLength</link> bytes are relevant.
  283. </para>
  284. </example>
  285. <example>
  286. <title>
  287. Encrypt a Network Password
  288. </title>
  289. <programlisting>
  290. oHPAVKey <varname>encoder</varname>;
  291. char * <varname>password</varname> = "Super Computers Inc.";
  292. byte <varname>buffer</varname> [<varname>encoder</varname>.<constant>DigestLength</constant>]
  293. <varname>encoder</varname>.<function>ComputeNMK</function> (<varname>password</varname>);
  294. <varname>encoder</varname>.<function>ExportKey</function> (<varname>buffer</varname>)
  295. <varname>encoder</varname>.<function>ComputeNID</function> (<varname>1</varname>);
  296. <varname>encoder</varname>.<function>ExportKey</function> (<varname>buffer</varname>)
  297. </programlisting>
  298. <para>
  299. This example instantiates an <varname>encoder</varname>, defines the <varname>password</varname> to be encrypted and allocates a <varname>buffer</varname> having <link linkend='oHPAVKey-DigestLength'>DigestLength</link> bytes, as above. Class method <link linkend='oHPAVKey-ComputeNMK'>ComputeNMK</link> encrypts the <varname>password</varname> using <acronym>NMK</acronym> encryption rules. Method <link linkend='oHPAVKey-ExportKey'>ExportKey</link> copies the encrypted password into <varname>buffer</varname>. Since <varname>buffer</varname> now contains an <acronym>NMK</acronym>, only the first <link linkend='oHPAVKey-NMKLength'>NMKLength</link> bytes are relevant.
  300. </para>
  301. <para>
  302. The example then computes an <acronym>NID</acronym> from the <acronym>NMK</acronym> that was just computed. Class methods ComputeNID encrypts the <acronym>NMK</acronym> and encodes it with security level <constant>1</constant>. Method <link linkend='oHPAVKey-ExportKey'>ExportKey</link> copies the encrypted <acronym>NMK</acronym> into <varname>buffer</varname>. Since <varname>buffer</varname> now contains a <acronym>NID</acronym>, only the first <link linkend='oHPAVKey-NIDLength'>NIDLength</link> bytes are relevant.
  303. </para>
  304. </example>
  305. </section>
  306. </chapter>