• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 /// Tpm2Ctx wrapper class implementation.
17 /*! \file */
18 #include "epid/member/tpm2/unittests/tpm2_wrapper-testhelper.h"
19 
20 #include <cstring>
21 #include <string>
22 
23 #include "epid/common-testhelper/epid2params_wrapper-testhelper.h"
24 #include "epid/common-testhelper/epid_params-testhelper.h"
25 #include "epid/common-testhelper/mem_params-testhelper.h"
26 
27 extern "C" {
28 #include "epid/common/src/epid2params.h"
29 #include "epid/common/src/hashsize.h"
30 #include "epid/common/stdtypes.h"
31 #include "epid/common/types.h"
32 #include "epid/member/tpm2/context.h"
33 #include "epid/member/tpm2/sign.h"
34 }
35 
Tpm2CtxObj(BitSupplier rnd_func,void * rnd_param,const FpElemStr * f,Epid2ParamsObj const & params)36 Tpm2CtxObj::Tpm2CtxObj(BitSupplier rnd_func, void* rnd_param,
37                        const FpElemStr* f, Epid2ParamsObj const& params)
38     : ctx_(nullptr) {
39   EpidStatus sts = kEpidNoErr;
40   BitSupplier rnd_func_ = NULL;
41   void* rnd_param_ = NULL;
42   const FpElemStr* f_ = NULL;
43   MemberParams mem_params = {0};
44   SetMemberParams(rnd_func, rnd_param, f, &mem_params);
45 
46   sts = Tpm2CreateContext(&mem_params, params, &rnd_func_, &rnd_param_, &f_,
47                           &ctx_);
48   if (kEpidNoErr != sts) {
49     printf("%s(%d): %s\n", __FILE__, __LINE__, "test defect:");
50     throw std::logic_error(std::string("Failed to call: ") +
51                            "Tpm2CreateContext()");
52   }
53 }
54 
~Tpm2CtxObj()55 Tpm2CtxObj::~Tpm2CtxObj() { Tpm2DeleteContext(&ctx_); }
56 
ctx() const57 Tpm2Ctx* Tpm2CtxObj::ctx() const { return ctx_; }
58 
operator Tpm2Ctx*() const59 Tpm2CtxObj::operator Tpm2Ctx*() const { return ctx_; }
60 
operator const Tpm2Ctx*() const61 Tpm2CtxObj::operator const Tpm2Ctx*() const { return ctx_; }
62