sign_commitment.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 signing helper implementation
  17. /*! \file */
  18. #include "epid/member/src/sign_commitment.h"
  19. #include "epid/common/math/ecgroup.h"
  20. #include "epid/common/src/commitment.h"
  21. /// Handle SDK Error with Break
  22. #define BREAK_ON_EPID_ERROR(ret) \
  23. if (kEpidNoErr != (ret)) { \
  24. break; \
  25. }
  26. EpidStatus HashSignCommitment(FiniteField* Fp, HashAlg hash_alg,
  27. GroupPubKey const* pub_key,
  28. SignCommitOutput const* commit_out,
  29. void const* msg, size_t msg_len,
  30. FpElemStr* c_str) {
  31. EpidStatus sts = kEpidErr;
  32. FfElement* c = NULL;
  33. if (!Fp || !commit_out || (0 != msg_len && !msg) || !c_str) {
  34. return kEpidBadArgErr;
  35. }
  36. do {
  37. CommitValues values = {0};
  38. sts = SetKeySpecificCommitValues(pub_key, &values);
  39. BREAK_ON_EPID_ERROR(sts);
  40. values.B = commit_out->B;
  41. values.K = commit_out->K;
  42. values.T = commit_out->T;
  43. values.R1 = commit_out->R1;
  44. values.R2 = commit_out->R2;
  45. sts = NewFfElement(Fp, &c);
  46. BREAK_ON_EPID_ERROR(sts);
  47. // 5. The member computes t3 = Fp.hash(p || g1 || g2 || h1 || h2
  48. // || w || B || K || T || R1 || R2).
  49. // 6. The member computes c = Fp.hash(t3 || m).
  50. sts = CalculateCommitmentHash(&values, Fp, hash_alg, msg, msg_len, c);
  51. BREAK_ON_EPID_ERROR(sts);
  52. sts = WriteFfElement(Fp, c, c_str, sizeof(*c_str));
  53. BREAK_ON_EPID_ERROR(sts);
  54. sts = kEpidNoErr;
  55. } while (0);
  56. DeleteFfElement(&c);
  57. return sts;
  58. }