commitment.h 3.9 KB

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