1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- <!-- HTML header for doxygen 1.8.10-->
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
- <meta http-equiv="X-UA-Compatible" content="IE=9"/>
- <meta name="generator" content="Doxygen 1.8.11"/>
- <title>Intel® Enhanced Privacy ID SDK: signmsg.c</title>
- <link href="tabs.css" rel="stylesheet" type="text/css"/>
- <script type="text/javascript" src="jquery.js"></script>
- <script type="text/javascript" src="dynsections.js"></script>
- <link href="navtree.css" rel="stylesheet" type="text/css"/>
- <script type="text/javascript" src="resize.js"></script>
- <script type="text/javascript" src="navtreedata.js"></script>
- <script type="text/javascript" src="navtree.js"></script>
- <script type="text/javascript">
- $(document).ready(initResizable);
- $(window).load(resizeHeight);
- </script>
- <link href="doxygen.css" rel="stylesheet" type="text/css" />
- <link href="epidstyle.css" rel="stylesheet" type="text/css"/>
- </head>
- <body>
- <div id="top"><!-- do not remove this div, it is closed by doxygen! -->
- <div id="titlearea">
- <table cellspacing="0" cellpadding="0">
- <tbody>
- <tr style="height: 56px;">
- <td id="projectalign" style="padding-left: 0.5em;">
- <div id="projectname"><a
- onclick="storeLink('index.html')"
- id="projectlink"
- class="index.html"
- href="index.html">Intel® Enhanced Privacy ID SDK</a>
-  <span id="projectnumber">2.0.0</span>
- </div>
- </td>
- </tr>
- </tbody>
- </table>
- </div>
- <!-- end header part -->
- <!-- Generated by Doxygen 1.8.11 -->
- </div><!-- top -->
- <div id="side-nav" class="ui-resizable side-nav-resizable">
- <div id="nav-tree">
- <div id="nav-tree-contents">
- <div id="nav-sync" class="sync"></div>
- </div>
- </div>
- <div id="splitbar" style="-moz-user-select:none;"
- class="ui-resizable-handle">
- </div>
- </div>
- <script type="text/javascript">
- $(document).ready(function(){initNavTree('signmsg_8c-example.html','');});
- </script>
- <div id="doc-content">
- <div class="header">
- <div class="headertitle">
- <div class="title">signmsg.c</div> </div>
- </div><!--header-->
- <div class="contents">
- <p>This is an example of how to call the SDK member APIs.</p>
- <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 "License");</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 "AS IS" 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 <stdlib.h></span></div><div class="line"><span class="preprocessor">#include <string.h></span></div><div class="line"><span class="preprocessor">#include "src/signmsg.h"</span></div><div class="line"><span class="preprocessor">#include "src/prng.h"</span></div><div class="line"><span class="preprocessor">#include "util/envutil.h"</span></div><div class="line"><span class="preprocessor">#include "util/stdtypes.h"</span></div><div class="line"><span class="preprocessor">#include "util/buffutil.h"</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"> &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, &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, &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(&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>(&pub_key, (<a class="code" href="struct_compressed_priv_key.html">CompressedPrivKey</a>*)priv_key_ptr,</div><div class="line"> &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>(&pub_key, &priv_key,</div><div class="line"> member_precomp_is_input ? member_precomp : NULL,</div><div class="line"> PrngGen, prng, &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(&prng);</div><div class="line"> <a name="a22"></a><a class="code" href="group___epid_member_module.html#ga3824589c683c5e0e59d483462fce65d6">EpidMemberDelete</a>(&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 -->
- </div><!-- doc-content -->
- <!-- HTML footer for doxygen 1.8.10-->
- <!-- start footer part -->
- <div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
- <ul>
- <li class="footer">
- © 2016 Intel Corporation
- </li>
- </ul>
- </div>
- </body>
- </html>
|