| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Licensed Materials - Property of IBM | 3 * Licensed Materials - Property of IBM |
| 4 * | 4 * |
| 5 * trousers - An open source TCG Software Stack | 5 * trousers - An open source TCG Software Stack |
| 6 * | 6 * |
| 7 * (C) Copyright International Business Machines Corp. 2004-2007 | 7 * (C) Copyright International Business Machines Corp. 2004-2007 |
| 8 * | 8 * |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 TSS_HPOLICY hPolicy, hEncPolicy; | 35 TSS_HPOLICY hPolicy, hEncPolicy; |
| 36 BYTE *encData = NULL; | 36 BYTE *encData = NULL; |
| 37 BYTE *pcrData = NULL; | 37 BYTE *pcrData = NULL; |
| 38 UINT32 encDataSize; | 38 UINT32 encDataSize; |
| 39 UINT32 pcrDataSize; | 39 UINT32 pcrDataSize; |
| 40 UINT32 pcrInfoType = TSS_PCRS_STRUCT_DEFAULT; | 40 UINT32 pcrInfoType = TSS_PCRS_STRUCT_DEFAULT; |
| 41 UINT32 sealOrdinal = TPM_ORD_Seal; | 41 UINT32 sealOrdinal = TPM_ORD_Seal; |
| 42 TCS_KEY_HANDLE tcsKeyHandle; | 42 TCS_KEY_HANDLE tcsKeyHandle; |
| 43 TSS_HCONTEXT tspContext; | 43 TSS_HCONTEXT tspContext; |
| 44 Trspi_HashCtx hashCtx; | 44 Trspi_HashCtx hashCtx; |
| 45 » BYTE *sealData; | 45 » BYTE *sealData = NULL; |
| 46 struct authsess *xsap = NULL; | 46 struct authsess *xsap = NULL; |
| 47 #ifdef TSS_BUILD_SEALX | 47 #ifdef TSS_BUILD_SEALX |
| 48 UINT32 protectMode; | 48 UINT32 protectMode; |
| 49 #endif | 49 #endif |
| 50 | 50 |
| 51 if (rgbDataToSeal == NULL) | 51 if (rgbDataToSeal == NULL) |
| 52 return TSPERR(TSS_E_BAD_PARAMETER); | 52 return TSPERR(TSS_E_BAD_PARAMETER); |
| 53 | 53 |
| 54 if ((result = obj_encdata_get_tsp_context(hEncData, &tspContext))) | 54 if ((result = obj_encdata_get_tsp_context(hEncData, &tspContext))) |
| 55 return result; | 55 return result; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 84 /* If PCR's are of interest */ | 84 /* If PCR's are of interest */ |
| 85 pcrDataSize = 0; | 85 pcrDataSize = 0; |
| 86 if (hPcrComposite) { | 86 if (hPcrComposite) { |
| 87 if ((result = obj_pcrs_create_info_type(hPcrComposite, &pcrInfoT
ype, &pcrDataSize, | 87 if ((result = obj_pcrs_create_info_type(hPcrComposite, &pcrInfoT
ype, &pcrDataSize, |
| 88 &pcrData))) | 88 &pcrData))) |
| 89 return result; | 89 return result; |
| 90 } | 90 } |
| 91 | 91 |
| 92 if ((result = authsess_xsap_init(tspContext, hEncKey, hEncData, TSS_AUTH
_POLICY_REQUIRED, | 92 if ((result = authsess_xsap_init(tspContext, hEncKey, hEncData, TSS_AUTH
_POLICY_REQUIRED, |
| 93 sealOrdinal, TPM_ET_KEYHANDLE, &xsap))) | 93 sealOrdinal, TPM_ET_KEYHANDLE, &xsap))) |
| 94 » » return result; | 94 » » goto error; |
| 95 | 95 |
| 96 #ifdef TSS_BUILD_SEALX | 96 #ifdef TSS_BUILD_SEALX |
| 97 if (sealOrdinal == TPM_ORD_Seal) | 97 if (sealOrdinal == TPM_ORD_Seal) |
| 98 sealData = rgbDataToSeal; | 98 sealData = rgbDataToSeal; |
| 99 else { | 99 else { |
| 100 sealData = NULL; | |
| 101 if ((sealData = (BYTE *)calloc(1, ulDataLength)) == NULL) { | 100 if ((sealData = (BYTE *)calloc(1, ulDataLength)) == NULL) { |
| 102 LogError("malloc of %u bytes failed", ulDataLength); | 101 LogError("malloc of %u bytes failed", ulDataLength); |
| 103 result = TSPERR(TSS_E_OUTOFMEMORY); | 102 result = TSPERR(TSS_E_OUTOFMEMORY); |
| 104 goto error; | 103 goto error; |
| 105 } | 104 } |
| 106 | 105 |
| 107 if ((result = | 106 if ((result = |
| 108 ((TSS_RESULT (*)(PVOID, TSS_HKEY, TSS_HENCDATA, TSS_ALGORIT
HM_ID, | 107 ((TSS_RESULT (*)(PVOID, TSS_HKEY, TSS_HENCDATA, TSS_ALGORIT
HM_ID, |
| 109 UINT32, BYTE *, BYTE *, BYTE *, BYTE *, UINT32, BYTE *, | 108 UINT32, BYTE *, BYTE *, BYTE *, BYTE *, UINT32, BYTE *, |
| 110 BYTE *))xsap->cb_sealx.callback)(xsap->cb_sealx.appData, hE
ncKey, hEncData, | 109 BYTE *))xsap->cb_sealx.callback)(xsap->cb_sealx.appData, hE
ncKey, hEncData, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 121 #endif | 120 #endif |
| 122 | 121 |
| 123 result = Trspi_HashInit(&hashCtx, TSS_HASH_SHA1); | 122 result = Trspi_HashInit(&hashCtx, TSS_HASH_SHA1); |
| 124 result |= Trspi_Hash_UINT32(&hashCtx, sealOrdinal); | 123 result |= Trspi_Hash_UINT32(&hashCtx, sealOrdinal); |
| 125 result |= Trspi_Hash_ENCAUTH(&hashCtx, xsap->encAuthUse.authdata); | 124 result |= Trspi_Hash_ENCAUTH(&hashCtx, xsap->encAuthUse.authdata); |
| 126 result |= Trspi_Hash_UINT32(&hashCtx, pcrDataSize); | 125 result |= Trspi_Hash_UINT32(&hashCtx, pcrDataSize); |
| 127 result |= Trspi_HashUpdate(&hashCtx, pcrDataSize, pcrData); | 126 result |= Trspi_HashUpdate(&hashCtx, pcrDataSize, pcrData); |
| 128 result |= Trspi_Hash_UINT32(&hashCtx, ulDataLength); | 127 result |= Trspi_Hash_UINT32(&hashCtx, ulDataLength); |
| 129 result |= Trspi_HashUpdate(&hashCtx, ulDataLength, sealData); | 128 result |= Trspi_HashUpdate(&hashCtx, ulDataLength, sealData); |
| 130 if ((result |= Trspi_HashFinal(&hashCtx, digest.digest))) { | 129 if ((result |= Trspi_HashFinal(&hashCtx, digest.digest))) { |
| 131 if (sealData != rgbDataToSeal) | |
| 132 free(sealData); | |
| 133 goto error; | 130 goto error; |
| 134 } | 131 } |
| 135 | 132 |
| 136 if ((result = authsess_xsap_hmac(xsap, &digest))) | 133 if ((result = authsess_xsap_hmac(xsap, &digest))) |
| 137 goto error; | 134 goto error; |
| 138 | 135 |
| 139 #ifdef TSS_BUILD_SEALX | 136 #ifdef TSS_BUILD_SEALX |
| 140 if (sealOrdinal == TPM_ORD_Seal) { | 137 if (sealOrdinal == TPM_ORD_Seal) { |
| 141 if ((result = TCS_API(tspContext)->Seal(tspContext, tcsKeyHandle
, &xsap->encAuthUse, | 138 if ((result = TCS_API(tspContext)->Seal(tspContext, tcsKeyHandle
, &xsap->encAuthUse, |
| 142 pcrDataSize, pcrData, ul
DataLength, | 139 pcrDataSize, pcrData, ul
DataLength, |
| 143 sealData, xsap->pAuth, &
encDataSize, | 140 sealData, xsap->pAuth, &
encDataSize, |
| 144 » » » » » » » &encData))) | 141 » » » » » » » &encData))) { |
| 145 » » » return result; | 142 » » » goto error; |
| 143 » » } |
| 146 } else if (sealOrdinal == TPM_ORD_Sealx) { | 144 } else if (sealOrdinal == TPM_ORD_Sealx) { |
| 147 » » result = TCS_API(tspContext)->Sealx(tspContext, tcsKeyHandle, &x
sap->encAuthUse, | 145 » » if ((result = TCS_API(tspContext)->Sealx(tspContext, tcsKeyHandl
e, &xsap->encAuthUse, |
| 148 pcrDataSize, pcrData, ulData
Length, sealData, | 146 pcrDataSize, pcrData, ulData
Length, sealData, |
| 149 » » » » » » xsap->pAuth, &encDataSize, &
encData); | 147 » » » » » » xsap->pAuth, &encDataSize, &
encData))) { |
| 150 » » free(sealData); | |
| 151 | |
| 152 » » if (result != TSS_SUCCESS) | |
| 153 goto error; | 148 goto error; |
| 149 } |
| 154 } else { | 150 } else { |
| 155 result = TSPERR(TSS_E_INTERNAL_ERROR); | 151 result = TSPERR(TSS_E_INTERNAL_ERROR); |
| 156 goto error; | 152 goto error; |
| 157 } | 153 } |
| 158 #else | 154 #else |
| 159 if ((result = TCS_API(tspContext)->Seal(tspContext, tcsKeyHandle, &xsap-
>encAuthUse, | 155 if ((result = TCS_API(tspContext)->Seal(tspContext, tcsKeyHandle, &xsap-
>encAuthUse, |
| 160 pcrDataSize, pcrData, ulDataLeng
th, sealData, | 156 pcrDataSize, pcrData, ulDataLeng
th, sealData, |
| 161 xsap->pAuth, &encDataSize, &encD
ata))) | 157 xsap->pAuth, &encDataSize, &encD
ata))) |
| 162 goto error; | 158 goto error; |
| 163 #endif | 159 #endif |
| (...skipping 12 matching lines...) Expand all Loading... |
| 176 if ((result = obj_encdata_set_data(hEncData, encDataSize, encData))) | 172 if ((result = obj_encdata_set_data(hEncData, encDataSize, encData))) |
| 177 goto error; | 173 goto error; |
| 178 | 174 |
| 179 if (pcrDataSize) | 175 if (pcrDataSize) |
| 180 result = obj_encdata_set_pcr_info(hEncData, pcrInfoType, pcrData
); | 176 result = obj_encdata_set_pcr_info(hEncData, pcrInfoType, pcrData
); |
| 181 | 177 |
| 182 error: | 178 error: |
| 183 authsess_free(xsap); | 179 authsess_free(xsap); |
| 184 free(encData); | 180 free(encData); |
| 185 free(pcrData); | 181 free(pcrData); |
| 186 | 182 » if (sealData != rgbDataToSeal) |
| 183 » » free(sealData); |
| 187 return result; | 184 return result; |
| 188 } | 185 } |
| 189 | 186 |
| 190 TSS_RESULT | 187 TSS_RESULT |
| 191 Tspi_Data_Unseal(TSS_HENCDATA hEncData, /* in */ | 188 Tspi_Data_Unseal(TSS_HENCDATA hEncData, /* in */ |
| 192 TSS_HKEY hKey, /* in */ | 189 TSS_HKEY hKey, /* in */ |
| 193 UINT32 * pulUnsealedDataLength,/* out */ | 190 UINT32 * pulUnsealedDataLength,/* out */ |
| 194 BYTE ** prgbUnsealedData) /* out */ | 191 BYTE ** prgbUnsealedData) /* out */ |
| 195 { | 192 { |
| 196 UINT64 offset; | 193 UINT64 offset; |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 *pulUnsealedDataLength = unSealedDataLen; | 318 *pulUnsealedDataLength = unSealedDataLen; |
| 322 *prgbUnsealedData = unSealedData; | 319 *prgbUnsealedData = unSealedData; |
| 323 | 320 |
| 324 error: | 321 error: |
| 325 authsess_free(xsap); | 322 authsess_free(xsap); |
| 326 if (data) | 323 if (data) |
| 327 free_tspi(tspContext, data); | 324 free_tspi(tspContext, data); |
| 328 | 325 |
| 329 return result; | 326 return result; |
| 330 } | 327 } |
| OLD | NEW |