join_commitment.c 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. #include "epid/member/src/join_commitment.h"
  19. #include "epid/common/math/finitefield.h"
  20. #include "epid/common/types.h"
  21. /// Handle SDK Error with Break
  22. #define BREAK_ON_EPID_ERROR(ret) \
  23. if (kEpidNoErr != (ret)) { \
  24. break; \
  25. }
  26. #pragma pack(1)
  27. /// Storage for values to create commitment in Sign and Verify algorithms
  28. typedef struct JoinPCommitValues {
  29. BigNumStr p; ///< Intel(R) EPID 2.0 parameter p
  30. G1ElemStr g1; ///< Intel(R) EPID 2.0 parameter g1
  31. G2ElemStr g2; ///< Intel(R) EPID 2.0 parameter g2
  32. G1ElemStr h1; ///< Group public key value h1
  33. G1ElemStr h2; ///< Group public key value h2
  34. G2ElemStr w; ///< Group public key value w
  35. G1ElemStr F; ///< Variable F computed in algorithm
  36. G1ElemStr R; ///< Variable R computed in algorithm
  37. IssuerNonce NI; ///< Nonce
  38. } JoinPCommitValues;
  39. #pragma pack()
  40. EpidStatus HashJoinCommitment(FiniteField* Fp, HashAlg hash_alg,
  41. GroupPubKey const* pub_key,
  42. G1ElemStr const* F_str, G1ElemStr const* R_str,
  43. IssuerNonce const* NI, FpElemStr* c_str) {
  44. EpidStatus sts = kEpidErr;
  45. FfElement* c = NULL;
  46. if (!Fp || !pub_key || !F_str || !R_str || !NI || !c_str) {
  47. return kEpidBadArgErr;
  48. }
  49. do {
  50. JoinPCommitValues commit_values = {0};
  51. Epid2Params params = {
  52. #include "epid/common/src/epid2params_ate.inc"
  53. };
  54. commit_values.p = params.p;
  55. commit_values.g1 = params.g1;
  56. commit_values.g2 = params.g2;
  57. commit_values.h1 = pub_key->h1;
  58. commit_values.h2 = pub_key->h2;
  59. commit_values.w = pub_key->w;
  60. commit_values.F = *F_str;
  61. commit_values.R = *R_str;
  62. commit_values.NI = *NI;
  63. sts = NewFfElement(Fp, &c);
  64. BREAK_ON_EPID_ERROR(sts);
  65. // Step 4. The member computes c = Fp.hash(p || g1 || g2 || h1 ||
  66. // h2 || w || F || R || NI).
  67. sts = FfHash(Fp, &commit_values, sizeof(commit_values), hash_alg, c);
  68. BREAK_ON_EPID_ERROR(sts);
  69. sts = WriteFfElement(Fp, c, c_str, sizeof(*c_str));
  70. BREAK_ON_EPID_ERROR(sts);
  71. sts = kEpidNoErr;
  72. } while (0);
  73. DeleteFfElement(&c);
  74. return sts;
  75. }