Esempio n. 1
0
/**
 * Test random
 *
 * TODO: check params/data read/written.
 * TODO: check overflow tests.
 */
static void RandomTest(void)
{
	uint8_t buf[32];
	uint32_t size;

	ResetMocks();
	size = sizeof(buf);
	TEST_EQ(TlclGetRandom(buf, sizeof(buf), &size), 0, "GetRandom");
	TEST_EQ(calls[0].req_cmd, TPM_ORD_GetRandom, "  cmd");
	TEST_EQ(size, 0, "  size 0");
}
Esempio n. 2
0
/****************************************************************************
 *
 * Open an OSAP session
 * Object Specific Authorization Protocol, returned handle must manipulate
 * a single object given as a parameter (can introduce AuthData).
 *                                                                          *
 ****************************************************************************/
uint32_t TSS_OSAPopen(struct tss_osapsess *sess, const uint8_t *key, uint16_t etype,
		      uint32_t evalue)
{
	struct s_tpm_osap_open_cmd cmd;
	uint8_t response[TPM_LARGE_ENOUGH_COMMAND_SIZE];
	uint32_t nonceSize;
	uint32_t result;

	debug("TPM: TSS_OSAPopen\n");
	/* check input arguments */
	if (key == NULL || sess == NULL) {
		return TPM_E_NULL_ARG;
	}

	TlclGetRandom(sess->ononceOSAP, TPM_NONCE_SIZE, &nonceSize);

	memcpy(&cmd, &tpm_osap_open_cmd, sizeof(cmd));
	ToTpmUint16(cmd.buffer + tpm_osap_open_cmd.type, etype);
	ToTpmUint32(cmd.buffer + tpm_osap_open_cmd.value, evalue);
	memcpy(cmd.buffer + tpm_osap_open_cmd.nonce, sess->ononceOSAP, TPM_NONCE_SIZE);

	result = TlclSendReceive(cmd.buffer, response, sizeof(response));

	if (result == TPM_SUCCESS) {
		FromTpmUint32(response + kTpmResponseHeaderLength, &(sess->handle));
		memcpy(sess->enonce, response + kTpmResponseHeaderLength + sizeof(uint32_t), TPM_NONCE_SIZE);
		memcpy(sess->enonceOSAP, response + kTpmResponseHeaderLength + sizeof(uint32_t) + TPM_NONCE_SIZE, TPM_NONCE_SIZE);

		debug("TPM: TSS_OSAPopen success, calculating HMAC\n");
		/*DATA_DEBUG("key", key, TPM_HASH_SIZE);
		DATA_DEBUG("enonceOSAP", sess->enonceOSAP, TPM_NONCE_SIZE);
		DATA_DEBUG("ononceOSAP", sess->ononceOSAP, TPM_NONCE_SIZE);*/

		/* not implemented */
		SHA1_CTX hmac;
		hmac_starts(&hmac, key, TPM_HASH_SIZE);
		hmac_update(&hmac, sess->enonceOSAP, TPM_NONCE_SIZE);
		hmac_update(&hmac, sess->ononceOSAP, TPM_NONCE_SIZE);
		hmac_finish(&hmac, key, TPM_HASH_SIZE, sess->ssecret);
	}

	return result;
}