context.h 3.1 KB

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