static TPM_RESULT execute_TPM_GetPubKey(TPM_REQUEST *req, TPM_RESPONSE *rsp) { BYTE *ptr; UINT32 len; TPM_KEY_HANDLE keyHandle; TPM_PUBKEY pubKey; TPM_RESULT res; /* compute parameter digest */ tpm_compute_in_param_digest(req); /* unmarshal input */ ptr = req->param; len = req->paramSize; if (tpm_unmarshal_TPM_KEY_HANDLE(&ptr, &len, &keyHandle) || len != 0) return TPM_BAD_PARAMETER; /* execute command */ res = TPM_GetPubKey(keyHandle, &req->auth1, &pubKey); if (res != TPM_SUCCESS) return res; /* marshal output */ rsp->paramSize = len = sizeof_TPM_PUBKEY(pubKey); rsp->param = ptr = malloc(len); if (ptr == NULL || tpm_marshal_TPM_PUBKEY(&ptr, &len, &pubKey)) { free(rsp->param); res = TPM_FAIL; } free_TPM_PUBKEY(pubKey); return res; }
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; }