• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*############################################################################
2   # Copyright 2017 Intel Corporation
3   #
4   # Licensed under the Apache License, Version 2.0 (the "License");
5   # you may not use this file except in compliance with the License.
6   # You may obtain a copy of the License at
7   #
8   #     http://www.apache.org/licenses/LICENSE-2.0
9   #
10   # Unless required by applicable law or agreed to in writing, software
11   # distributed under the License is distributed on an "AS IS" BASIS,
12   # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   # See the License for the specific language governing permissions and
14   # limitations under the License.
15   ############################################################################*/
16 /// Host join helper implementation
17 /*! \file */
18 
19 #include "epid/member/src/join_commitment.h"
20 
21 #include "epid/common/math/finitefield.h"
22 #include "epid/common/types.h"
23 
24 /// Handle SDK Error with Break
25 #define BREAK_ON_EPID_ERROR(ret) \
26   if (kEpidNoErr != (ret)) {     \
27     break;                       \
28   }
29 
30 #pragma pack(1)
31 /// Storage for values to create commitment in Sign and Verify algorithms
32 typedef struct JoinPCommitValues {
33   BigNumStr p;     ///< Intel(R) EPID 2.0 parameter p
34   G1ElemStr g1;    ///< Intel(R) EPID 2.0 parameter g1
35   G2ElemStr g2;    ///< Intel(R) EPID 2.0 parameter g2
36   G1ElemStr h1;    ///< Group public key value h1
37   G1ElemStr h2;    ///< Group public key value h2
38   G2ElemStr w;     ///< Group public key value w
39   G1ElemStr F;     ///< Variable F computed in algorithm
40   G1ElemStr R;     ///< Variable R computed in algorithm
41   IssuerNonce NI;  ///< Nonce
42 } JoinPCommitValues;
43 #pragma pack()
44 
HashJoinCommitment(FiniteField * Fp,HashAlg hash_alg,GroupPubKey const * pub_key,G1ElemStr const * F_str,G1ElemStr const * R_str,IssuerNonce const * NI,FpElemStr * c_str)45 EpidStatus HashJoinCommitment(FiniteField* Fp, HashAlg hash_alg,
46                               GroupPubKey const* pub_key,
47                               G1ElemStr const* F_str, G1ElemStr const* R_str,
48                               IssuerNonce const* NI, FpElemStr* c_str) {
49   EpidStatus sts = kEpidErr;
50   FfElement* c = NULL;
51 
52   if (!Fp || !pub_key || !F_str || !R_str || !NI || !c_str) {
53     return kEpidBadArgErr;
54   }
55 
56   do {
57     JoinPCommitValues commit_values = {0};
58     Epid2Params params = {
59 #include "epid/common/src/epid2params_ate.inc"
60     };
61 
62     commit_values.p = params.p;
63     commit_values.g1 = params.g1;
64     commit_values.g2 = params.g2;
65     commit_values.h1 = pub_key->h1;
66     commit_values.h2 = pub_key->h2;
67     commit_values.w = pub_key->w;
68     commit_values.F = *F_str;
69     commit_values.R = *R_str;
70     commit_values.NI = *NI;
71 
72     sts = NewFfElement(Fp, &c);
73     BREAK_ON_EPID_ERROR(sts);
74 
75     // Step 4. The member computes c = Fp.hash(p || g1 || g2 || h1 ||
76     // h2 || w || F || R || NI).
77     sts = FfHash(Fp, &commit_values, sizeof(commit_values), hash_alg, c);
78     BREAK_ON_EPID_ERROR(sts);
79 
80     sts = WriteFfElement(Fp, c, c_str, sizeof(*c_str));
81     BREAK_ON_EPID_ERROR(sts);
82 
83     sts = kEpidNoErr;
84   } while (0);
85 
86   DeleteFfElement(&c);
87 
88   return sts;
89 }
90