precomp.c 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. /// Member pre-computation implementation
  17. /*! \file */
  18. #include "epid/member/src/precomp.h"
  19. #include "epid/common/src/epid2params.h"
  20. #include "epid/common/src/grouppubkey.h"
  21. #include "epid/common/types.h"
  22. /// Handle SDK Error with Break
  23. #define BREAK_ON_EPID_ERROR(ret) \
  24. if (kEpidNoErr != (ret)) { \
  25. break; \
  26. }
  27. EpidStatus PrecomputeMemberPairing(Epid2Params_ const* epid2_params,
  28. GroupPubKey const* pub_key,
  29. G1ElemStr const* A_str,
  30. MemberPrecomp* precomp) {
  31. EpidStatus sts = kEpidErr;
  32. GroupPubKey_* pub_key_ = NULL;
  33. EcPoint* A = NULL;
  34. FfElement* e = NULL;
  35. if (!epid2_params || !pub_key || !A_str || !precomp) return kEpidBadArgErr;
  36. do {
  37. EcGroup* G1 = epid2_params->G1;
  38. EcGroup* G2 = epid2_params->G2;
  39. FiniteField* GT = epid2_params->GT;
  40. PairingState* ps_ctx = epid2_params->pairing_state;
  41. EcPoint* g2 = epid2_params->g2;
  42. sts = CreateGroupPubKey(pub_key, G1, G2, &pub_key_);
  43. BREAK_ON_EPID_ERROR(sts);
  44. sts = NewFfElement(GT, &e);
  45. BREAK_ON_EPID_ERROR(sts);
  46. // 1. The member computes e12 = pairing(h1, g2).
  47. sts = Pairing(ps_ctx, pub_key_->h1, g2, e);
  48. BREAK_ON_EPID_ERROR(sts);
  49. sts = WriteFfElement(GT, e, &precomp->e12, sizeof(precomp->e12));
  50. BREAK_ON_EPID_ERROR(sts);
  51. // 2. The member computes e22 = pairing(h2, g2).
  52. sts = Pairing(ps_ctx, pub_key_->h2, g2, e);
  53. BREAK_ON_EPID_ERROR(sts);
  54. sts = WriteFfElement(GT, e, &precomp->e22, sizeof(precomp->e22));
  55. BREAK_ON_EPID_ERROR(sts);
  56. // 3. The member computes e2w = pairing(h2, w).
  57. sts = Pairing(ps_ctx, pub_key_->h2, pub_key_->w, e);
  58. BREAK_ON_EPID_ERROR(sts);
  59. sts = WriteFfElement(GT, e, &precomp->e2w, sizeof(precomp->e2w));
  60. BREAK_ON_EPID_ERROR(sts);
  61. // 4. The member computes ea2 = pairing(A, g2).
  62. sts = NewEcPoint(G1, &A);
  63. BREAK_ON_EPID_ERROR(sts);
  64. sts = ReadEcPoint(G1, A_str, sizeof(*A_str), A);
  65. BREAK_ON_EPID_ERROR(sts);
  66. sts = Pairing(ps_ctx, A, g2, e);
  67. BREAK_ON_EPID_ERROR(sts);
  68. sts = WriteFfElement(GT, e, &precomp->ea2, sizeof(precomp->ea2));
  69. BREAK_ON_EPID_ERROR(sts);
  70. sts = kEpidNoErr;
  71. } while (0);
  72. DeleteGroupPubKey(&pub_key_);
  73. DeleteEcPoint(&A);
  74. DeleteFfElement(&e);
  75. return sts;
  76. }