hash_basename.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. /// Basename hashing helper implementation
  17. /*! \file */
  18. #include "epid/member/src/hash_basename.h"
  19. #include "epid/common/math/ecgroup.h"
  20. /// Handle SDK Error with Break
  21. #define BREAK_ON_EPID_ERROR(ret) \
  22. if (kEpidNoErr != (ret)) { \
  23. break; \
  24. }
  25. EpidStatus HashBaseName(EcGroup* G1, HashAlg hash_alg, void const* basename,
  26. size_t basename_len, G1ElemStr* B_str,
  27. uint32_t* iterations) {
  28. EpidStatus sts = kEpidErr;
  29. EcPoint* B = NULL;
  30. if (!G1 || (0 != basename_len && !basename) || !B_str) {
  31. return kEpidBadArgErr;
  32. }
  33. do {
  34. sts = NewEcPoint(G1, &B);
  35. BREAK_ON_EPID_ERROR(sts);
  36. sts = EcHash(G1, basename, basename_len, hash_alg, B, iterations);
  37. BREAK_ON_EPID_ERROR(sts);
  38. sts = WriteEcPoint(G1, B, B_str, sizeof(*B_str));
  39. BREAK_ON_EPID_ERROR(sts);
  40. sts = kEpidNoErr;
  41. } while (0);
  42. DeleteEcPoint(&B);
  43. return sts;
  44. }