• 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_SRC_COMMITMENT_H_
17 #define EPID_COMMON_SRC_COMMITMENT_H_
18 /*!
19  * \file
20  * \brief Commitment hash interface.
21  * \addtogroup EpidCommon
22  * @{
23  */
24 #include <stddef.h>
25 
26 #include "epid/common/errors.h"
27 #include "epid/common/types.h"
28 
29 typedef struct FiniteField FiniteField;
30 typedef struct EcPoint EcPoint;
31 typedef struct EcGroup EcGroup;
32 typedef struct FfElement FfElement;
33 
34 #pragma pack(1)
35 /// Storage for values to create commitment in Sign and Verify algorithms
36 typedef struct CommitValues {
37   BigNumStr p;   ///< Intel(R) EPID2.0 parameter p
38   G1ElemStr g1;  ///< Intel(R) EPID2.0 parameter g1
39   G2ElemStr g2;  ///< Intel(R) EPID2.0 parameter g2
40   G1ElemStr h1;  ///< Group public key value h1
41   G1ElemStr h2;  ///< Group public key value h2
42   G2ElemStr w;   ///< Group public key value w
43   G1ElemStr B;   ///< Variable B computed in algorithm
44   G1ElemStr K;   ///< Variable K computed in algorithm
45   G1ElemStr T;   ///< Variable T computed in algorithm
46   G1ElemStr R1;  ///< Variable R1 computed in algorithm
47   GtElemStr R2;  ///< Variable R2 computed in algorithm
48 } CommitValues;
49 #pragma pack()
50 
51 /// Set group public key related fields from CommitValues structure
52 /*!
53   Set p, g1, g2, h1, h2 and w fields of values argument.
54 
55   \param[in] pub_key
56   Group public key
57   \param[out] values
58   Pointer to CommitValues structure to fill.
59 
60   \returns ::EpidStatus
61 
62   \see CalculateCommitmentHash
63 */
64 EpidStatus SetKeySpecificCommitValues(GroupPubKey const* pub_key,
65                                       CommitValues* values);
66 
67 /// Set CommitValues structure fields calculated in algorithm
68 /*!
69   Set B, K, T, R1 and R2 fields of values argument.
70 
71   \param[in] B
72   Value of B to set
73   \param[in] K
74   Value of K to set
75   \param[in] T
76   Value of T to set
77   \param[in] R1
78   Value of R1 to set
79   \param[in] G1
80   EcGroup containing element R1
81   \param[in] R2
82   Value of R2 to set
83   \param[in] GT
84   FiniteField containing element R2
85   \param[out] values
86   Pointer to CommitValues structure to fill.
87 
88   \returns ::EpidStatus
89 
90   \see CalculateCommitmentHash
91 */
92 EpidStatus SetCalculatedCommitValues(G1ElemStr const* B, G1ElemStr const* K,
93                                      G1ElemStr const* T, EcPoint const* R1,
94                                      EcGroup* G1, FfElement const* R2,
95                                      FiniteField* GT, CommitValues* values);
96 
97 /// Calculate Fp.hash(t3 || m) for Sign and Verfiy algorithms
98 /*!
99   Calculate c = Fp.hash(t3 || m) where t3 is
100   Fp.hash(p || g1 || g2 || h1 || h2 || w || B || K || T || R1 || R2).
101 
102   \param[in] values
103   Commit values to hash
104   \param[in] Fp
105   Finite field to perfom hash operation in
106   \param[in] hash_alg
107   Hash algorithm to use
108   \param[in] msg
109   Message to hash
110   \param[in] msg_len
111   Size of msg buffer in bytes
112   \param[out] c
113   Result of calculation
114 
115   \returns ::EpidStatus
116 
117   \see SetKeySpecificCommitValues
118   \see SetCalculatedCommitValues
119 */
120 EpidStatus CalculateCommitmentHash(CommitValues const* values, FiniteField* Fp,
121                                    HashAlg hash_alg, void const* msg,
122                                    size_t msg_len, FfElement* c);
123 
124 /*! @} */
125 #endif  // EPID_COMMON_SRC_COMMITMENT_H_
126