sha256.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. /*!
  17. * \file
  18. * \brief SHA256 implementation.
  19. */
  20. #include "epid/common/math/hash.h"
  21. #include "epid/common/math/src/bignum-internal.h"
  22. #include "ext/ipp/include/ippcp.h"
  23. EpidStatus Sha256MessageDigest(void const* msg, size_t len,
  24. Sha256Digest* digest) {
  25. IppStatus sts;
  26. int ipp_len = (int)len;
  27. if ((len && !msg) || !digest) return kEpidBadArgErr;
  28. if (INT_MAX < len) return kEpidBadArgErr;
  29. sts = ippsSHA256MessageDigest(msg, ipp_len, (IppOctStr)digest);
  30. if (ippStsNoErr != sts) {
  31. if (ippStsLengthErr == sts) {
  32. return kEpidBadArgErr;
  33. } else {
  34. return kEpidMathErr;
  35. }
  36. }
  37. return kEpidNoErr;
  38. }