signmsg_8c-example.html 19 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <!-- HTML header for doxygen 1.8.10-->
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
  6. <meta http-equiv="X-UA-Compatible" content="IE=9"/>
  7. <meta name="generator" content="Doxygen 1.8.11"/>
  8. <title>Intel&reg; Enhanced Privacy ID SDK: signmsg.c</title>
  9. <link href="tabs.css" rel="stylesheet" type="text/css"/>
  10. <script type="text/javascript" src="jquery.js"></script>
  11. <script type="text/javascript" src="dynsections.js"></script>
  12. <link href="navtree.css" rel="stylesheet" type="text/css"/>
  13. <script type="text/javascript" src="resize.js"></script>
  14. <script type="text/javascript" src="navtreedata.js"></script>
  15. <script type="text/javascript" src="navtree.js"></script>
  16. <script type="text/javascript">
  17. $(document).ready(initResizable);
  18. $(window).load(resizeHeight);
  19. </script>
  20. <link href="doxygen.css" rel="stylesheet" type="text/css" />
  21. <link href="epidstyle.css" rel="stylesheet" type="text/css"/>
  22. </head>
  23. <body>
  24. <div id="top"><!-- do not remove this div, it is closed by doxygen! -->
  25. <div id="titlearea">
  26. <table cellspacing="0" cellpadding="0">
  27. <tbody>
  28. <tr style="height: 56px;">
  29. <td id="projectalign" style="padding-left: 0.5em;">
  30. <div id="projectname"><a
  31. onclick="storeLink('index.html')"
  32. id="projectlink"
  33. class="index.html"
  34. href="index.html">Intel&reg; Enhanced Privacy ID SDK</a>
  35. &#160;<span id="projectnumber">2.0.0</span>
  36. </div>
  37. </td>
  38. </tr>
  39. </tbody>
  40. </table>
  41. </div>
  42. <!-- end header part -->
  43. <!-- Generated by Doxygen 1.8.11 -->
  44. </div><!-- top -->
  45. <div id="side-nav" class="ui-resizable side-nav-resizable">
  46. <div id="nav-tree">
  47. <div id="nav-tree-contents">
  48. <div id="nav-sync" class="sync"></div>
  49. </div>
  50. </div>
  51. <div id="splitbar" style="-moz-user-select:none;"
  52. class="ui-resizable-handle">
  53. </div>
  54. </div>
  55. <script type="text/javascript">
  56. $(document).ready(function(){initNavTree('signmsg_8c-example.html','');});
  57. </script>
  58. <div id="doc-content">
  59. <div class="header">
  60. <div class="headertitle">
  61. <div class="title">signmsg.c</div> </div>
  62. </div><!--header-->
  63. <div class="contents">
  64. <p>This is an example of how to call the SDK member APIs.</p>
  65. <div class="fragment"><div class="line"><span class="comment">/*############################################################################</span></div><div class="line"><span class="comment"> # Copyright 2016 Intel Corporation</span></div><div class="line"><span class="comment"> #</span></div><div class="line"><span class="comment"> # Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);</span></div><div class="line"><span class="comment"> # you may not use this file except in compliance with the License.</span></div><div class="line"><span class="comment"> # You may obtain a copy of the License at</span></div><div class="line"><span class="comment"> #</span></div><div class="line"><span class="comment"> # http://www.apache.org/licenses/LICENSE-2.0</span></div><div class="line"><span class="comment"> #</span></div><div class="line"><span class="comment"> # Unless required by applicable law or agreed to in writing, software</span></div><div class="line"><span class="comment"> # distributed under the License is distributed on an &quot;AS IS&quot; BASIS,</span></div><div class="line"><span class="comment"> # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span></div><div class="line"><span class="comment"> # See the License for the specific language governing permissions and</span></div><div class="line"><span class="comment"> # limitations under the License.</span></div><div class="line"><span class="comment"> ############################################################################*/</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include &lt;stdlib.h&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;string.h&gt;</span></div><div class="line"><span class="preprocessor">#include &quot;src/signmsg.h&quot;</span></div><div class="line"><span class="preprocessor">#include &quot;src/prng.h&quot;</span></div><div class="line"><span class="preprocessor">#include &quot;util/envutil.h&quot;</span></div><div class="line"><span class="preprocessor">#include &quot;util/stdtypes.h&quot;</span></div><div class="line"><span class="preprocessor">#include &quot;util/buffutil.h&quot;</span></div><div class="line"></div><div class="line"><span class="keywordtype">bool</span> IsCaCertAuthorizedByRootCa(<span class="keywordtype">void</span> <span class="keyword">const</span>* data, <span class="keywordtype">size_t</span> size) {</div><div class="line"> <span class="comment">// Implementation of this function is out of scope of the sample.</span></div><div class="line"> <span class="comment">// In an actual implementation Issuing CA certificate must be validated</span></div><div class="line"> <span class="comment">// with CA Root certificate before using it in parse functions.</span></div><div class="line"> (void)data;</div><div class="line"> (void)size;</div><div class="line"> <span class="keywordflow">return</span> <span class="keyword">true</span>;</div><div class="line">}</div><div class="line"></div><div class="line"><a class="code" href="group___error_codes.html#gafdb27c77c2c4b32c807e326a8a0da360">EpidStatus</a> SignMsg(<span class="keywordtype">void</span> <span class="keyword">const</span>* msg, <span class="keywordtype">size_t</span> msg_len, <span class="keywordtype">void</span> <span class="keyword">const</span>* basename,</div><div class="line"> <span class="keywordtype">size_t</span> basename_len, <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> <span class="keyword">const</span>* signed_sig_rl,</div><div class="line"> <span class="keywordtype">size_t</span> signed_sig_rl_size,</div><div class="line"> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> <span class="keyword">const</span>* signed_pubkey,</div><div class="line"> <span class="keywordtype">size_t</span> signed_pubkey_size, <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> <span class="keyword">const</span>* priv_key_ptr,</div><div class="line"> <span class="keywordtype">size_t</span> privkey_size, <a class="code" href="group___epid_types.html#ga5e450438f6f9a5eacd0cf5ce354ec890">HashAlg</a> hash_alg,</div><div class="line"> <a name="_a0"></a><a class="code" href="struct_member_precomp.html">MemberPrecomp</a>* member_precomp, <span class="keywordtype">bool</span> member_precomp_is_input,</div><div class="line"> <a name="_a1"></a><a class="code" href="struct_epid_signature.html">EpidSignature</a>** sig, <span class="keywordtype">size_t</span>* sig_len,</div><div class="line"> <a name="_a2"></a><a class="code" href="struct_epid_ca_certificate.html">EpidCaCertificate</a> <span class="keyword">const</span>* cacert) {</div><div class="line"> <a class="code" href="group___error_codes.html#gafdb27c77c2c4b32c807e326a8a0da360">EpidStatus</a> sts = <a name="a3"></a><a class="code" href="group___error_codes.html#ggafdb27c77c2c4b32c807e326a8a0da360aa08f0d2e394b37694117a6a32bc71e6e">kEpidErr</a>;</div><div class="line"> <span class="keywordtype">void</span>* prng = NULL;</div><div class="line"> <a name="_a4"></a><a class="code" href="struct_member_ctx.html">MemberCtx</a>* member = NULL;</div><div class="line"></div><div class="line"> <a name="_a5"></a><a class="code" href="struct_sig_rl.html">SigRl</a>* sig_rl = NULL;</div><div class="line"> <span class="keywordtype">size_t</span> sig_rl_size = 0;</div><div class="line"></div><div class="line"> <span class="keywordflow">do</span> {</div><div class="line"> <a name="_a6"></a><a class="code" href="struct_group_pub_key.html">GroupPubKey</a> pub_key = {0};</div><div class="line"> <a name="_a7"></a><a class="code" href="struct_priv_key.html">PrivKey</a> priv_key = {0};</div><div class="line"></div><div class="line"> <span class="keywordflow">if</span> (!sig) {</div><div class="line"> sts = <a name="a8"></a><a class="code" href="group___error_codes.html#ggafdb27c77c2c4b32c807e326a8a0da360ad134d6cc95a9dcb1b1a9f9c358047cbf">kEpidBadArgErr</a>;</div><div class="line"> <span class="keywordflow">break</span>;</div><div class="line"> }</div><div class="line"></div><div class="line"> <span class="comment">// authenticate and extract group public key</span></div><div class="line"> sts = <a name="a9"></a><a class="code" href="group___file_parser.html#ga43fdbc1bf2edd3695d21cb457365afbb">EpidParseGroupPubKeyFile</a>(signed_pubkey, signed_pubkey_size, cacert,</div><div class="line"> &amp;pub_key);</div><div class="line"> <span class="keywordflow">if</span> (<a name="a10"></a><a class="code" href="group___error_codes.html#ggafdb27c77c2c4b32c807e326a8a0da360a8a6861e14322ca9193498ffc955537f9">kEpidNoErr</a> != sts) {</div><div class="line"> <span class="keywordflow">break</span>;</div><div class="line"> }</div><div class="line"></div><div class="line"> <span class="keywordflow">if</span> (signed_sig_rl) {</div><div class="line"> <span class="comment">// authenticate and determine space needed for SigRl</span></div><div class="line"> sts = <a name="a11"></a><a class="code" href="group___file_parser.html#ga237ef5a43076aa6fc6eb18829a93da3f">EpidParseSigRlFile</a>(signed_sig_rl, signed_sig_rl_size, cacert,</div><div class="line"> sig_rl, &amp;sig_rl_size);</div><div class="line"> <span class="keywordflow">if</span> (<a name="a12"></a><a class="code" href="group___error_codes.html#ggafdb27c77c2c4b32c807e326a8a0da360aeedd19b8a1cbdecf963f90b4860e02b8">kEpidSigInvalid</a> == sts) {</div><div class="line"> <span class="comment">// authentication failure</span></div><div class="line"> <span class="keywordflow">break</span>;</div><div class="line"> }</div><div class="line"> <span class="keywordflow">if</span> (<a class="code" href="group___error_codes.html#ggafdb27c77c2c4b32c807e326a8a0da360a8a6861e14322ca9193498ffc955537f9">kEpidNoErr</a> != sts) {</div><div class="line"> <span class="keywordflow">break</span>;</div><div class="line"> }</div><div class="line"> sig_rl = AllocBuffer(sig_rl_size);</div><div class="line"> <span class="keywordflow">if</span> (!sig_rl) {</div><div class="line"> sts = <a name="a13"></a><a class="code" href="group___error_codes.html#ggafdb27c77c2c4b32c807e326a8a0da360a11a4d2f1c37064eb663de08dc57bcda8">kEpidMemAllocErr</a>;</div><div class="line"> <span class="keywordflow">break</span>;</div><div class="line"> }</div><div class="line"></div><div class="line"> <span class="comment">// fill the SigRl</span></div><div class="line"> sts = <a class="code" href="group___file_parser.html#ga237ef5a43076aa6fc6eb18829a93da3f">EpidParseSigRlFile</a>(signed_sig_rl, signed_sig_rl_size, cacert,</div><div class="line"> sig_rl, &amp;sig_rl_size);</div><div class="line"> <span class="keywordflow">if</span> (<a class="code" href="group___error_codes.html#ggafdb27c77c2c4b32c807e326a8a0da360aeedd19b8a1cbdecf963f90b4860e02b8">kEpidSigInvalid</a> == sts) {</div><div class="line"> <span class="comment">// authentication failure</span></div><div class="line"> <span class="keywordflow">break</span>;</div><div class="line"> }</div><div class="line"> <span class="keywordflow">if</span> (<a class="code" href="group___error_codes.html#ggafdb27c77c2c4b32c807e326a8a0da360a8a6861e14322ca9193498ffc955537f9">kEpidNoErr</a> != sts) {</div><div class="line"> <span class="keywordflow">break</span>;</div><div class="line"> }</div><div class="line"> }</div><div class="line"></div><div class="line"> <span class="comment">// acquire PRNG</span></div><div class="line"> sts = PrngCreate(&amp;prng);</div><div class="line"> <span class="keywordflow">if</span> (<a class="code" href="group___error_codes.html#ggafdb27c77c2c4b32c807e326a8a0da360a8a6861e14322ca9193498ffc955537f9">kEpidNoErr</a> != sts) {</div><div class="line"> <span class="keywordflow">break</span>;</div><div class="line"> }</div><div class="line"></div><div class="line"> <span class="comment">// decompress private key</span></div><div class="line"> <span class="keywordflow">if</span> (privkey_size == <span class="keyword">sizeof</span>(<a class="code" href="struct_priv_key.html">PrivKey</a>)) {</div><div class="line"> priv_key = *(<a class="code" href="struct_priv_key.html">PrivKey</a>*)priv_key_ptr;</div><div class="line"> } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (privkey_size == <span class="keyword">sizeof</span>(<a name="_a14"></a><a class="code" href="struct_compressed_priv_key.html">CompressedPrivKey</a>)) {</div><div class="line"> sts = <a name="a15"></a><a class="code" href="group___epid_member_module.html#gaf8cd05388f017486f14da2ee48d067ef">EpidDecompressPrivKey</a>(&amp;pub_key, (<a class="code" href="struct_compressed_priv_key.html">CompressedPrivKey</a>*)priv_key_ptr,</div><div class="line"> &amp;priv_key);</div><div class="line"> <span class="keywordflow">if</span> (<a class="code" href="group___error_codes.html#ggafdb27c77c2c4b32c807e326a8a0da360a8a6861e14322ca9193498ffc955537f9">kEpidNoErr</a> != sts) {</div><div class="line"> <span class="keywordflow">break</span>;</div><div class="line"> }</div><div class="line"> } <span class="keywordflow">else</span> {</div><div class="line"> sts = <a class="code" href="group___error_codes.html#ggafdb27c77c2c4b32c807e326a8a0da360aa08f0d2e394b37694117a6a32bc71e6e">kEpidErr</a>;</div><div class="line"> <span class="keywordflow">break</span>;</div><div class="line"> }</div><div class="line"></div><div class="line"> <span class="comment">// create member</span></div><div class="line"> sts = <a name="a16"></a><a class="code" href="group___epid_member_module.html#ga561c4d544a78ee1bf59c3f4f919aa7bb">EpidMemberCreate</a>(&amp;pub_key, &amp;priv_key,</div><div class="line"> member_precomp_is_input ? member_precomp : NULL,</div><div class="line"> PrngGen, prng, &amp;member);</div><div class="line"> <span class="keywordflow">if</span> (<a class="code" href="group___error_codes.html#ggafdb27c77c2c4b32c807e326a8a0da360a8a6861e14322ca9193498ffc955537f9">kEpidNoErr</a> != sts) {</div><div class="line"> <span class="keywordflow">break</span>;</div><div class="line"> }</div><div class="line"></div><div class="line"> <span class="comment">// return member pre-computation blob if requested</span></div><div class="line"> sts = <a name="a17"></a><a class="code" href="group___epid_member_module.html#ga5c35798d62cf81c4ca62b22c38809721">EpidMemberWritePrecomp</a>(member, member_precomp);</div><div class="line"> <span class="keywordflow">if</span> (<a class="code" href="group___error_codes.html#ggafdb27c77c2c4b32c807e326a8a0da360a8a6861e14322ca9193498ffc955537f9">kEpidNoErr</a> != sts) {</div><div class="line"> <span class="keywordflow">break</span>;</div><div class="line"> }</div><div class="line"></div><div class="line"> <span class="comment">// register any provided basename as allowed</span></div><div class="line"> <span class="keywordflow">if</span> (0 != basename_len) {</div><div class="line"> sts = <a name="a18"></a><a class="code" href="group___epid_member_module.html#gad92d3c3266ae1833ffb1dba9ad76035d">EpidRegisterBaseName</a>(member, basename, basename_len);</div><div class="line"> <span class="keywordflow">if</span> (<a class="code" href="group___error_codes.html#ggafdb27c77c2c4b32c807e326a8a0da360a8a6861e14322ca9193498ffc955537f9">kEpidNoErr</a> != sts) {</div><div class="line"> <span class="keywordflow">break</span>;</div><div class="line"> }</div><div class="line"> }</div><div class="line"></div><div class="line"> sts = <a name="a19"></a><a class="code" href="group___epid_member_module.html#ga9998eb454838ff5d232ff22ecbab31bf">EpidMemberSetHashAlg</a>(member, hash_alg);</div><div class="line"> <span class="keywordflow">if</span> (<a class="code" href="group___error_codes.html#ggafdb27c77c2c4b32c807e326a8a0da360a8a6861e14322ca9193498ffc955537f9">kEpidNoErr</a> != sts) {</div><div class="line"> <span class="keywordflow">break</span>;</div><div class="line"> }</div><div class="line"></div><div class="line"> <span class="comment">// Signature</span></div><div class="line"> <span class="comment">// Note: Signature size must be computed after sig_rl is loaded.</span></div><div class="line"> *sig_len = <a name="a20"></a><a class="code" href="group___epid_member_module.html#ga76e535722467af7c16809b5b521e0000">EpidGetSigSize</a>(sig_rl);</div><div class="line"></div><div class="line"> *sig = AllocBuffer(*sig_len);</div><div class="line"> <span class="keywordflow">if</span> (!*sig) {</div><div class="line"> sts = <a class="code" href="group___error_codes.html#ggafdb27c77c2c4b32c807e326a8a0da360a11a4d2f1c37064eb663de08dc57bcda8">kEpidMemAllocErr</a>;</div><div class="line"> <span class="keywordflow">break</span>;</div><div class="line"> }</div><div class="line"></div><div class="line"> <span class="comment">// sign message</span></div><div class="line"> sts = <a name="a21"></a><a class="code" href="group___epid_member_module.html#ga759155a719254f734157722716dac640">EpidSign</a>(member, msg, msg_len, basename, basename_len, sig_rl,</div><div class="line"> sig_rl_size, *sig, *sig_len);</div><div class="line"> <span class="keywordflow">if</span> (<a class="code" href="group___error_codes.html#ggafdb27c77c2c4b32c807e326a8a0da360a8a6861e14322ca9193498ffc955537f9">kEpidNoErr</a> != sts) {</div><div class="line"> <span class="keywordflow">break</span>;</div><div class="line"> }</div><div class="line"> sts = <a class="code" href="group___error_codes.html#ggafdb27c77c2c4b32c807e326a8a0da360a8a6861e14322ca9193498ffc955537f9">kEpidNoErr</a>;</div><div class="line"> } <span class="keywordflow">while</span> (0);</div><div class="line"></div><div class="line"> PrngDelete(&amp;prng);</div><div class="line"> <a name="a22"></a><a class="code" href="group___epid_member_module.html#ga3824589c683c5e0e59d483462fce65d6">EpidMemberDelete</a>(&amp;member);</div><div class="line"></div><div class="line"> <span class="keywordflow">if</span> (sig_rl) free(sig_rl);</div><div class="line"></div><div class="line"> <span class="keywordflow">return</span> sts;</div><div class="line">}</div></div><!-- fragment --> </div><!-- contents -->
  66. </div><!-- doc-content -->
  67. <!-- HTML footer for doxygen 1.8.10-->
  68. <!-- start footer part -->
  69. <div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  70. <ul>
  71. <li class="footer">
  72. &copy; 2016 Intel Corporation
  73. </li>
  74. </ul>
  75. </div>
  76. </body>
  77. </html>