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