• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*############################################################################
2   # Copyright 2016-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 #ifndef EPID_COMMON_1_1_SRC_COMMITMENT_H_
17 #define EPID_COMMON_1_1_SRC_COMMITMENT_H_
18 /*!
19  * \file
20  * \brief Commitment hash interface.
21  * \addtogroup EpidCommon
22  * @{
23  */
24 #include "epid/common/1.1/types.h"
25 #include "epid/common/errors.h"
26 #include "epid/common/math/ecgroup.h"
27 #include "epid/common/math/finitefield.h"
28 #include "epid/common/math/hash.h"
29 
30 #pragma pack(1)
31 /// Storage for values to create Intel(R) EPID 1.1 commitment in Sign and Verify
32 /// algorithms
33 typedef struct Epid11CommitValues {
34   BigNumStr p;         ///< Intel(R) EPID 1.1 parameter p
35   Epid11G1ElemStr g1;  ///< Intel(R) EPID 1.1 parameter g1
36   Epid11G2ElemStr g2;  ///< Intel(R) EPID 1.1 parameter g2
37   Epid11G1ElemStr g3;  ///< Intel(R) EPID 1.1 parameter g3
38   Epid11G1ElemStr h1;  ///< Group public key value h1
39   Epid11G1ElemStr h2;  ///< Group public key value h2
40   Epid11G2ElemStr w;   ///< Group public key value w
41   Epid11G3ElemStr B;   ///< Variable B computed in algorithm
42   Epid11G3ElemStr K;   ///< Variable K computed in algorithm
43   Epid11G1ElemStr T1;  ///< Variable T1 computed in algorithm
44   Epid11G1ElemStr T2;  ///< Variable T2 computed in algorithm
45   Epid11G1ElemStr R1;  ///< Variable R1 computed in algorithm
46   Epid11G1ElemStr R2;  ///< Variable R2 computed in algorithm
47   Epid11G3ElemStr R3;  ///< Variable R3 computed in algorithm
48   Epid11GtElemStr R4;  ///< Variable R4 computed in algorithm
49 } Epid11CommitValues;
50 #pragma pack()
51 
52 /// Set Intel(R) EPID 1.1 group public key related fields to Epid11CommitValues
53 /// structure
54 /*!
55   Set p, g1, g2, g3, h1, h2 and w fields of values argument.
56 
57   \param[in] pub_key
58   Intel(R) EPID 1.1 Group public key
59   \param[out] values
60   Pointer to Epid11CommitValues structure to fill.
61 
62   \returns ::EpidStatus
63 
64   \see CalculateCommitmentHash
65 */
66 EpidStatus SetKeySpecificEpid11CommitValues(Epid11GroupPubKey const* pub_key,
67                                             Epid11CommitValues* values);
68 
69 /// Set Epid11CommitValues structure fields calculated in Intel(R) EPID 1.1 Sign
70 /// or Verify algorithm
71 /*!
72   Set B, K, T1, T2, R1, R2, R3 and R4 fields of values argument.
73 
74   \param[in] B
75   Value of B to set
76   \param[in] K
77   Value of K to set
78   \param[in] T1
79   Value of T1 to set
80   \param[in] T2
81   Value of T2 to set
82   \param[in] R1
83   Value of R1 to set
84   \param[in] R2
85   Value of R2 to set
86   \param[in] R3
87   Value of R3 to set
88   \param[in] R4
89   Value of R4 to set
90   \param[in] G1
91   EcGroup containing element R1, R2
92   \param[in] G3
93   EcGroup containing element R3
94   \param[in] GT
95   FiniteField containing element R4
96   \param[out] values
97   Pointer to CommitValues structure to fill.
98 
99   \returns ::EpidStatus
100 
101   \see CalculateCommitmentHash
102 */
103 EpidStatus SetCalculatedEpid11CommitValues(
104     Epid11G3ElemStr const* B, Epid11G3ElemStr const* K,
105     Epid11G1ElemStr const* T1, Epid11G1ElemStr const* T2, EcPoint const* R1,
106     EcPoint const* R2, EcPoint const* R3, FfElement const* R4, EcGroup* G1,
107     EcGroup* G3, FiniteField* GT, Epid11CommitValues* values);
108 
109 /// Calculate Hash(t4 || nd || mSize || m) for Intel(R) EPID 1.1 Sign and Verfiy
110 /// algorithms
111 /*!
112   Calculate c = Hash(t4 || nd || mSize || m) where t4 is
113   Hash(p || g1 || g2 || g3 || h1 || h2 || w || B || K || T1 || T2 || R1 || R2 ||
114   R3 || R4).
115 
116   \param[in] values
117   Commit values to hash
118   \param[in] msg
119   Message to hash
120   \param[in] msg_len
121   Size of msg buffer in bytes
122   \param[in] nd
123   80-bit big integer
124   \param[out] c
125   Result of calculation
126 
127   \returns ::EpidStatus
128 
129   \see SetKeySpecificCommitValues
130   \see SetCalculatedCommitValues
131 */
132 EpidStatus CalculateEpid11CommitmentHash(Epid11CommitValues const* values,
133                                          void const* msg, uint32_t msg_len,
134                                          OctStr80 const* nd, Sha256Digest* c);
135 
136 /*! @} */
137 #endif  // EPID_COMMON_1_1_SRC_COMMITMENT_H_
138