conversion.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. /// TPM-SDK data conversion interface.
  17. /*! \file */
  18. #ifndef EPID_MEMBER_TPM2_IBM_TSS_CONVERSION_H_
  19. #define EPID_MEMBER_TPM2_IBM_TSS_CONVERSION_H_
  20. #include <tss2/TPM_Types.h>
  21. #include "epid/common/errors.h"
  22. #include "epid/common/types.h"
  23. #ifndef TPM_ALG_SHA256
  24. /// TPM code of SHA 256 algorithm
  25. #define TPM_ALG_SHA256 (TPM_ALG_ID)(0x000B)
  26. #endif
  27. #ifndef TPM_ALG_SHA384
  28. /// TPM code of SHA 384 algorithm
  29. #define TPM_ALG_SHA384 (TPM_ALG_ID)(0x000C)
  30. #endif
  31. #ifndef TPM_ALG_SHA512
  32. /// TPM code of SHA 512 algorithm
  33. #define TPM_ALG_SHA512 (TPM_ALG_ID)(0x000D)
  34. #endif
  35. #ifndef TPM_ALG_NULL
  36. /// TPM code of Null algorithm
  37. #define TPM_ALG_NULL (TPM_ALG_ID)(0x0010)
  38. #endif
  39. /// \cond
  40. typedef struct G1ElemStr G1ElemStr;
  41. /// \endcond
  42. /// Maps HashAlg to TPM type
  43. /*!
  44. Maps Intel(R) EPID SDK HashAlg into TPMI_ALG_HASH.
  45. \param[in] hash_alg
  46. Code of the hash algorithm
  47. \returns TPMI_ALG_HASH
  48. */
  49. TPMI_ALG_HASH EpidtoTpm2HashAlg(HashAlg hash_alg);
  50. /// Maps TPMI_ALG_HASH to HashAlg
  51. /*!
  52. Maps TPM hash code TPMI_ALG_HASH into HashAlg.
  53. \param[in] tpm_hash_alg
  54. Code of the hash algorithm in TPM
  55. \returns HashAlg
  56. */
  57. HashAlg Tpm2toEpidHashAlg(TPMI_ALG_HASH tpm_hash_alg);
  58. /// Converts serialized FfElement into TPM type
  59. /*!
  60. \param[in] str
  61. Serialized Intel(R) EPID SDK FfElement
  62. \param[out] tpm_data
  63. tpm type data.
  64. \returns ::EpidStatus
  65. */
  66. EpidStatus ReadTpm2FfElement(OctStr256 const* str,
  67. TPM2B_ECC_PARAMETER* tpm_data);
  68. /// Converts TPM finite field element types into serialized FfElement
  69. /*!
  70. \param[in] tpm_data
  71. The TPM finite field data, typically TPM2B_DIGEST or
  72. TPM2B_ECC_PARAMETER.
  73. \param[out] str
  74. The target buffer.
  75. \returns ::EpidStatus
  76. */
  77. EpidStatus WriteTpm2FfElement(TPM2B_ECC_PARAMETER const* tpm_data,
  78. OctStr256* str);
  79. /// Converts ECPoint string to TMP ECPoint structure.
  80. /*!
  81. \param[in] p_str
  82. The serialized EcPoint to convert.
  83. \param[out] tpm_point
  84. The TPM EC point representation.
  85. \returns ::EpidStatus
  86. */
  87. EpidStatus ReadTpm2EcPoint(G1ElemStr const* p_str, TPM2B_ECC_POINT* tpm_point);
  88. /// Serializes TMP ECPoint to ECPoint string.
  89. /*!
  90. \param[in] tpm_point
  91. The TPM EC point to convert.
  92. \param[in] p_str
  93. The target string.
  94. \returns ::EpidStatus
  95. */
  96. EpidStatus WriteTpm2EcPoint(TPM2B_ECC_POINT const* tpm_point, G1ElemStr* p_str);
  97. #endif // EPID_MEMBER_TPM2_IBM_TSS_CONVERSION_H_