commitment.h 4.5 KB

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