int check_passthru(tpmcmd_t* tpmcmd) { TPM_TAG tag; UINT32 len = 10; BYTE* ptr; size_t size; if(tpmcmd->req_len < 10) { return false; } ptr = tpmcmd->req; tpm_unmarshal_UINT16(&ptr, &len, &tag); if (tag == VTPM_TAG_REQ2) { info("VTPM passthru: %d bytes", (int)tpmcmd->req_len); tpmfront_cmd(tpmfront_dev, tpmcmd->req, tpmcmd->req_len, &tpmcmd->resp, &size); tpmcmd->resp_len = size; info("VTPM passthru return: %d bytes", (int)size); return true; } if (tag == VTPM_TAG_REQ) { info("VTPM pTPM-cmd: %d bytes", (int)tpmcmd->req_len); ptr = tpmcmd->req; tpm_marshal_UINT16(&ptr, &len, TPM_TAG_RQU_COMMAND); tpmfront_cmd(tpmfront_dev, tpmcmd->req, tpmcmd->req_len, &tpmcmd->resp, &size); tpmcmd->resp_len = size; info("VTPM pTPM-cmd return: %d bytes", (int)size); return true; } return false; }
static int tpm_compute_migration_digest(TPM_PUBKEY *migrationKey, TPM_MIGRATE_SCHEME migrationScheme, TPM_NONCE *tpmProof, TPM_DIGEST *digest) { tpm_sha1_ctx_t sha1; UINT32 len = sizeof_TPM_PUBKEY((*migrationKey)); BYTE *buf, *ptr, buf2[2]; buf = ptr = tpm_malloc(len); if (buf == NULL || tpm_marshal_TPM_PUBKEY(&ptr, &len, migrationKey)) { tpm_free(buf); return -1; } /* compute SHA1 hash */ tpm_sha1_init(&sha1); tpm_sha1_update(&sha1, buf, sizeof_TPM_PUBKEY((*migrationKey))); ptr = buf2; len = 2; tpm_marshal_UINT16(&ptr, &len, migrationScheme); tpm_sha1_update(&sha1, buf2, 2); tpm_sha1_update(&sha1, tpmProof->nonce, sizeof(TPM_NONCE)); tpm_sha1_final(&sha1, digest->digest); tpm_free(buf); return 0; }