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