Exemplo n.º 1
0
static void test_BigInt_getsetOctetString(void)
{
	const uint8_t os1[] = { 1, 2, 3, 4 };
	const uint8_t os2[] = { 1, 2, 3, 4, 5 };
	const uint8_t os3[] = { 0, 1, 2, 3, 4 };
	const uint8_t os4[] = { 0x11, 0x22, 0x44, 0x55, 0x66, 0x77, 0x88 };
	uint8_t os_res[10];
	TEE_Result res;
	size_t os_len;

	DEF_BIGINT(a, 512);
	DEF_BIGINT(b, 512);

	TB_INFO("Testing Convert to and from OctetString");

	/* Test with 0x0102030405 */
	TEE_BigIntConvertFromString(a, "0x0102030405");
	os_len = sizeof(os_res);
	res = TEE_BigIntConvertToOctetString(os_res, &os_len, a);
	TB_ASSERT(res == TEE_SUCCESS);
	TB_ASSERT(sizeof(os2) == os_len
		  && TEE_MemCompare(os2, os_res, sizeof(os2)) == 0);

	res = TEE_BigIntConvertFromOctetString(b, os_res, os_len, 1);
	TB_ASSERT(res == TEE_SUCCESS);
	TB_ASSERT(TEE_BigIntCmp(a, b) == 0);

	/* Test with 0x11224455667788 */
	TEE_BigIntConvertFromString(a, "0x11224455667788");
	os_len = sizeof(os_res);
	res = TEE_BigIntConvertToOctetString(os_res, &os_len, a);
	TB_ASSERT(res == TEE_SUCCESS);
	TB_ASSERT(sizeof(os4) == os_len
		  && TEE_MemCompare(os4, os_res, sizeof(os4)) == 0);

	res = TEE_BigIntConvertFromOctetString(b, os_res, os_len, 1);
	TB_ASSERT(res == TEE_SUCCESS);
	TB_ASSERT(TEE_BigIntCmp(a, b) == 0);

	/* Test with static octet strings */
	res = TEE_BigIntConvertFromOctetString(a, os1, sizeof(os1), 1);
	TB_ASSERT(res == TEE_SUCCESS);

	os_len = sizeof(os_res);
	res = TEE_BigIntConvertToOctetString(os_res, &os_len, a);
	TB_ASSERT(res == TEE_SUCCESS);
	TB_ASSERT(sizeof(os1) == os_len
		  && TEE_MemCompare(os1, os_res, sizeof(os1)) == 0);

	res = TEE_BigIntConvertFromOctetString(b, os3, sizeof(os3), 1);
	TB_ASSERT(res == TEE_SUCCESS);
	TB_ASSERT(TEE_BigIntCmp(a, b) == 0);

	DEL_BIGINT(a);
	DEL_BIGINT(b);
}
Exemplo n.º 2
0
TEE_Result TA_EXPORT TA_InvokeCommandEntryPoint(void *sessionContext,
						uint32_t commandID,
						uint32_t paramTypes,
						TEE_Param params[4])
{
	TEE_Result tee_rv = TEE_SUCCESS;

	/* Check session context */
	if (TEE_MemCompare(sessionContext, out_vector, SIZE_OF_VEC(out_vector))) {
		OT_LOG(LOG_ERR, "Not a correct session context");
		return TEE_ERROR_GENERIC;
	}

	if (!(commandID == INVOKE_CMD_ID_1 ||
	      commandID == INVOKE_CMD_ID_2)) {
		OT_LOG(LOG_ERR, "Not a valid command ID");
		return TEE_ERROR_BAD_PARAMETERS;
	}

	tee_rv = handle_params(paramTypes, params);
	if (tee_rv != TEE_SUCCESS)
		return tee_rv;

	if (storage_test(2))
		return TEE_ERROR_GENERIC;

	if (crypto_test(2))
		return TEE_ERROR_GENERIC;

	return TEE_SUCCESS;
}
Exemplo n.º 3
0
static TEE_Result check_recv_params(uint32_t paramTypes,
				    TEE_Param *params)
{
	uint32_t i;

	/* Check parameter type */
	if (TEE_PARAM_TYPE_GET(paramTypes, 0) != TEE_PARAM_TYPE_VALUE_INOUT) {
		OT_LOG(LOG_ERR, "Expected value inout type as index 0 parameter");
		return TEE_ERROR_BAD_PARAMETERS;
	}

	if (TEE_PARAM_TYPE_GET(paramTypes, 1) != TEE_PARAM_TYPE_MEMREF_INOUT ||
	    TEE_PARAM_TYPE_GET(paramTypes, 2) != TEE_PARAM_TYPE_MEMREF_INOUT ||
	    TEE_PARAM_TYPE_GET(paramTypes, 3) != TEE_PARAM_TYPE_MEMREF_INOUT) {
		OT_LOG(LOG_ERR, "Expected buffer inout type as index 1,2,3 parameter");
		return TEE_ERROR_BAD_PARAMETERS;
	}

	/* Param 0 */
	if (params[0].value.a != IN_VALUE_A) {
		OT_LOG(LOG_ERR, "Not expected parameter at 0 (value a)");
		return TEE_ERROR_BAD_PARAMETERS;
	}

	if (params[0].value.b != IN_VALUE_B) {
		OT_LOG(LOG_ERR, "Not expected parameter at 0 (value b)");
		return TEE_ERROR_BAD_PARAMETERS;
	}

	/* Param 1 & 2 */
	for (i = 1; i < 3; i++) {

		if (SIZE_OF_VEC(in_vector) != params[i].memref.size) {
			OT_LOG(LOG_ERR, "Not expected parameter at %u (wrong buffer length)", i);
			return TEE_ERROR_BAD_PARAMETERS;
		}

		if (TEE_MemCompare(in_vector, params[1].memref.buffer, params[1].memref.size)) {
			OT_LOG(LOG_ERR, "Not expected parameter at %u (wrong data)", i);
			return TEE_ERROR_BAD_PARAMETERS;
		}
	}

	/* Param 3, just length */
	if (RAND_BUFFER_SIZE != params[3].memref.size) {
		OT_LOG(LOG_ERR, "Not expected parameter at 3 (wrong buffer length)");
		return TEE_ERROR_BAD_PARAMETERS;
	}

	return TEE_SUCCESS;
}
Exemplo n.º 4
0
void TA_EXPORT TA_CloseSessionEntryPoint(void *sessionContext)
{
	OT_LOG(LOG_INFO, "Calling the Close session entry point");

	if (storage_test(2))
		TEE_Panic(TEE_ERROR_GENERIC);

	if (crypto_test(2))
		TEE_Panic(TEE_ERROR_GENERIC);

	/* Check session context */
	if (TEE_MemCompare(sessionContext, out_vector, SIZE_OF_VEC(out_vector))) {
		OT_LOG(LOG_ERR, "Not a correct session context");
		TEE_Panic(TEE_ERROR_GENERIC);
	}

	TEE_Free(sessionContext);
}