• 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 /// SDK TPM API.
17 /*! \file */
18 
19 #ifndef EPID_MEMBER_TPM2_CONTEXT_H_
20 #define EPID_MEMBER_TPM2_CONTEXT_H_
21 
22 #include "epid/common/bitsupplier.h"
23 #include "epid/common/errors.h"
24 #include "epid/common/types.h"
25 
26 /// \cond
27 typedef struct Tpm2Ctx Tpm2Ctx;
28 typedef struct FpElemStr FpElemStr;
29 typedef struct Epid2Params_ Epid2Params_;
30 typedef struct MemberParams MemberParams;
31 /// \endcond
32 
33 /*!
34   \addtogroup Tpm2Module tpm2
35   \ingroup EpidMemberModule
36   @{
37 */
38 
39 /// Creates a new Tpm context
40 /*!
41 
42  Must be called to create the TPM context that is used by other TPM
43  APIs.
44 
45  You need to use a cryptographically secure random number generator
46  to create a TPM context. The ::BitSupplier is provided as a function
47  prototype for your own implementation of the random number generator.
48 
49  ::Tpm2DeleteContext must be called to safely release the TPM context.
50 
51  \param[in] params
52  member parameters to initialize rnd_func, rnd_param, ff_elem, ctx.
53 
54  \param[in] epid2_params
55  The field and group parameters.
56 
57  \param[out] rnd_func
58  random function if exists in MemberParms
59 
60  \param[out] rnd_param
61   random parameters if exists in MemberParms
62 
63  \param[out] f
64  seed f if exists in MemberParams
65 
66  \param[out] ctx
67  Newly constructed TPM context.
68 
69  \returns ::EpidStatus
70 
71  \see Tpm2DeleteContext
72 */
73 EpidStatus Tpm2CreateContext(MemberParams const* params,
74                              Epid2Params_ const* epid2_params,
75                              BitSupplier* rnd_func, void** rnd_param,
76                              const FpElemStr** f, Tpm2Ctx** ctx);
77 
78 /// Deletes an existing Tpm context.
79 /*!
80 
81  Must be called to safely release a TPM context created using
82  ::Tpm2CreateContext.
83 
84  De-initializes the context, frees memory used by the context, and
85  sets the context pointer to NULL.
86 
87  \param[in,out] ctx
88  The TPM context. Can be NULL.
89 
90  \see Tpm2CreateContext
91 */
92 void Tpm2DeleteContext(Tpm2Ctx** ctx);
93 
94 /// Sets the hash algorithm to be used by a TPM2.
95 /*!
96 
97  \param[in] ctx
98  The TPM2 context.
99  \param[in] hash_alg
100  The hash algorithm to use.
101 
102  \returns ::EpidStatus
103 */
104 EpidStatus Tpm2SetHashAlg(Tpm2Ctx* ctx, HashAlg hash_alg);
105 
106 /// Reset an existing Tpm context.
107 /*!
108 
109 Must be called to reset a TPM context created using
110 ::Tpm2CreateContext.
111 
112 Re-initializes the context, reset memory used for primary key.
113 
114 \param[in,out] ctx
115 The TPM context. Can be NULL.
116 
117 \see Tpm2CreateContext
118 */
119 void Tpm2ResetContext(Tpm2Ctx** ctx);
120 
121 /*! @} */
122 
123 #endif  // EPID_MEMBER_TPM2_CONTEXT_H_
124