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