Ejemplo n.º 1
0
TEE_Result TEE_CopyObjectAttributes1(TEE_ObjectHandle destObject,
			      TEE_ObjectHandle srcObject)
{
	TEE_Result res;
	TEE_ObjectInfo dst_info;
	TEE_ObjectInfo src_info;

	res = utee_cryp_obj_get_info((unsigned long)destObject, &dst_info);
	if (res != TEE_SUCCESS)
		goto exit;

	res = utee_cryp_obj_get_info((unsigned long)srcObject, &src_info);
	if (res != TEE_SUCCESS)
		goto exit;

	if (!(src_info.handleFlags & TEE_HANDLE_FLAG_INITIALIZED))
		TEE_Panic(0);

	if ((dst_info.handleFlags & TEE_HANDLE_FLAG_PERSISTENT))
		TEE_Panic(0);

	if ((dst_info.handleFlags & TEE_HANDLE_FLAG_INITIALIZED))
		TEE_Panic(0);

	res = utee_cryp_obj_copy((unsigned long)destObject,
				 (unsigned long)srcObject);

exit:
	if (res != TEE_SUCCESS &&
	    res != TEE_ERROR_CORRUPT_OBJECT &&
	    res != TEE_ERROR_STORAGE_NOT_AVAILABLE)
		TEE_Panic(res);

	return res;
}
Ejemplo n.º 2
0
void TEE_CopyObjectAttributes(TEE_ObjectHandle destObject,
                              TEE_ObjectHandle srcObject)
{
    TEE_Result res;
    TEE_ObjectInfo dst_info;
    TEE_ObjectInfo src_info;

    res = utee_cryp_obj_get_info((uint32_t)destObject, &dst_info);
    if (res != TEE_SUCCESS)
        TEE_Panic(0);

    res = utee_cryp_obj_get_info((uint32_t)srcObject, &src_info);
    if (res != TEE_SUCCESS)
        TEE_Panic(0);

    if ((src_info.handleFlags & TEE_HANDLE_FLAG_INITIALIZED) == 0)
        TEE_Panic(0);
    if ((dst_info.handleFlags & TEE_HANDLE_FLAG_PERSISTENT) != 0)
        TEE_Panic(0);
    if ((dst_info.handleFlags & TEE_HANDLE_FLAG_INITIALIZED) != 0)
        TEE_Panic(0);

    res = utee_cryp_obj_copy((uint32_t)destObject, (uint32_t)srcObject);
    if (res != TEE_SUCCESS)
        TEE_Panic(0);
}
Ejemplo n.º 3
0
TEE_Result TEE_GetObjectBufferAttribute(TEE_ObjectHandle object,
					uint32_t attributeID, void *buffer,
					uint32_t *size)
{
	TEE_Result res;
	TEE_ObjectInfo info;
	uint64_t sz;

	res = utee_cryp_obj_get_info((unsigned long)object, &info);
	if (res != TEE_SUCCESS)
		goto exit;

	/* This function only supports reference attributes */
	if ((attributeID & TEE_ATTR_BIT_VALUE)) {
		res = TEE_ERROR_BAD_PARAMETERS;
		goto exit;
	}

	sz = *size;
	res = utee_cryp_obj_get_attr((unsigned long)object, attributeID,
				     buffer, &sz);
	*size = sz;

exit:
	if (res != TEE_SUCCESS &&
	    res != TEE_ERROR_ITEM_NOT_FOUND &&
	    res != TEE_ERROR_SHORT_BUFFER &&
	    res != TEE_ERROR_CORRUPT_OBJECT &&
	    res != TEE_ERROR_STORAGE_NOT_AVAILABLE)
		TEE_Panic(0);

	return res;
}
Ejemplo n.º 4
0
TEE_Result TEE_GetObjectValueAttribute(TEE_ObjectHandle object,
                                       uint32_t attributeID, uint32_t *a,
                                       uint32_t *b)
{
    TEE_Result res;
    TEE_ObjectInfo info;
    uint32_t buf[2];
    size_t size = sizeof(buf);

    res = utee_cryp_obj_get_info((uint32_t)object, &info);
    if (res != TEE_SUCCESS)
        TEE_Panic(0);

    if ((info.handleFlags & TEE_HANDLE_FLAG_INITIALIZED) == 0)
        TEE_Panic(0);

    /* This function only supports value attributes */
    if ((attributeID & TEE_ATTR_BIT_VALUE) == 0)
        TEE_Panic(0);

    res =
        utee_cryp_obj_get_attr((uint32_t)object, attributeID, buf, &size);

    if (res != TEE_SUCCESS && res != TEE_ERROR_ITEM_NOT_FOUND &&
            res != TEE_ERROR_ACCESS_DENIED)
        TEE_Panic(0);

    if (size != sizeof(buf))
        TEE_Panic(0);

    *a = buf[0];
    *b = buf[1];

    return res;
}
Ejemplo n.º 5
0
TEE_Result TEE_GetObjectBufferAttribute(TEE_ObjectHandle object,
                                        uint32_t attributeID, void *buffer,
                                        size_t *size)
{
    TEE_Result res;
    TEE_ObjectInfo info;

    res = utee_cryp_obj_get_info((uint32_t)object, &info);
    if (res != TEE_SUCCESS)
        TEE_Panic(0);

    if ((info.handleFlags & TEE_HANDLE_FLAG_INITIALIZED) == 0)
        TEE_Panic(0);

    /* This function only supports reference attributes */
    if ((attributeID & TEE_ATTR_BIT_VALUE) != 0)
        TEE_Panic(0);

    res =
        utee_cryp_obj_get_attr((uint32_t)object, attributeID, buffer,
                               size);

    if (res != TEE_SUCCESS && res != TEE_ERROR_ITEM_NOT_FOUND &&
            res != TEE_ERROR_SHORT_BUFFER)
        TEE_Panic(0);

    return res;
}
Ejemplo n.º 6
0
TEE_Result TEE_PopulateTransientObject(TEE_ObjectHandle object,
				       TEE_Attribute *attrs,
				       uint32_t attrCount)
{
	TEE_Result res;
	TEE_ObjectInfo info;
	struct utee_attribute ua[attrCount];

	res = utee_cryp_obj_get_info((unsigned long)object, &info);
	if (res != TEE_SUCCESS)
		TEE_Panic(0);

	/* Must be a transient object */
	if ((info.handleFlags & TEE_HANDLE_FLAG_PERSISTENT) != 0)
		TEE_Panic(0);

	/* Must not be initialized already */
	if ((info.handleFlags & TEE_HANDLE_FLAG_INITIALIZED) != 0)
		TEE_Panic(0);

	__utee_from_attr(ua, attrs, attrCount);
	res = utee_cryp_obj_populate((unsigned long)object, ua, attrCount);
	if (res != TEE_SUCCESS && res != TEE_ERROR_BAD_PARAMETERS)
		TEE_Panic(res);
	return res;
}
Ejemplo n.º 7
0
/* Data and Key Storage API  - Generic Object Functions */
void TEE_GetObjectInfo(TEE_ObjectHandle object, TEE_ObjectInfo *objectInfo)
{
    TEE_Result res;

    res = utee_cryp_obj_get_info((uint32_t)object, objectInfo);
    if (res != TEE_SUCCESS)
        TEE_Panic(res);
}
Ejemplo n.º 8
0
TEE_Result TEE_SeekObjectData(TEE_ObjectHandle object, int32_t offset,
			      TEE_Whence whence)
{
	TEE_Result res;
	TEE_ObjectInfo info;

	if (object == TEE_HANDLE_NULL) {
		res = TEE_ERROR_BAD_PARAMETERS;
		goto out;
	}

	res = utee_cryp_obj_get_info((unsigned long)object, &info);
	if (res != TEE_SUCCESS)
		goto out;

	switch (whence) {
	case TEE_DATA_SEEK_SET:
		if (offset > 0 && (uint32_t)offset > TEE_DATA_MAX_POSITION) {
			res = TEE_ERROR_OVERFLOW;
			goto out;
		}
		break;
	case TEE_DATA_SEEK_CUR:
		if (offset > 0 &&
		    ((uint32_t)offset + info.dataPosition >
		     TEE_DATA_MAX_POSITION ||
		     (uint32_t)offset + info.dataPosition <
		     info.dataPosition)) {
			res = TEE_ERROR_OVERFLOW;
			goto out;
		}
		break;
	case TEE_DATA_SEEK_END:
		if (offset > 0 &&
		    ((uint32_t)offset + info.dataSize > TEE_DATA_MAX_POSITION ||
		     (uint32_t)offset + info.dataSize < info.dataSize)) {
			res = TEE_ERROR_OVERFLOW;
			goto out;
		}
		break;
	default:
		res = TEE_ERROR_ITEM_NOT_FOUND;
		goto out;
	}

	res = utee_storage_obj_seek((unsigned long)object, offset, whence);

out:
	if (res != TEE_SUCCESS &&
	    res != TEE_ERROR_OVERFLOW &&
	    res != TEE_ERROR_CORRUPT_OBJECT &&
	    res != TEE_ERROR_STORAGE_NOT_AVAILABLE)
		TEE_Panic(0);

	return res;
}
Ejemplo n.º 9
0
TEE_Result TEE_CopyObjectAttributes1(TEE_ObjectHandle destObject,
			      TEE_ObjectHandle srcObject)
{
	TEE_Result res;
	TEE_ObjectInfo dst_info;
	TEE_ObjectInfo src_info;

	res = utee_cryp_obj_get_info((uint32_t)destObject, &dst_info);
	if (res != TEE_SUCCESS)
		goto err;

	res = utee_cryp_obj_get_info((uint32_t)srcObject, &src_info);
	if (res != TEE_SUCCESS)
		goto err;

	if ((src_info.handleFlags & TEE_HANDLE_FLAG_INITIALIZED) == 0)
		TEE_Panic(0);
	if ((dst_info.handleFlags & TEE_HANDLE_FLAG_PERSISTENT) != 0)
		TEE_Panic(0);
	if ((dst_info.handleFlags & TEE_HANDLE_FLAG_INITIALIZED) != 0)
		TEE_Panic(0);

	res = utee_cryp_obj_copy((uint32_t)destObject, (uint32_t)srcObject);
	if (res != TEE_SUCCESS)
		TEE_Panic(0);

	goto out;

err:
	if (res == TEE_ERROR_CORRUPT_OBJECT) {
		res = utee_storage_obj_del(srcObject);
		if (res != TEE_SUCCESS)
			TEE_Panic(0);
		return TEE_ERROR_CORRUPT_OBJECT;
	}
	if (res == TEE_ERROR_STORAGE_NOT_AVAILABLE)
		return res;
	TEE_Panic(0);
out:
	return TEE_SUCCESS;
}
Ejemplo n.º 10
0
TEE_Result TEE_GetObjectInfo1(TEE_ObjectHandle object, TEE_ObjectInfo *objectInfo)
{
	TEE_Result res;

	res = utee_cryp_obj_get_info((unsigned long)object, objectInfo);

	if (res != TEE_SUCCESS &&
	    res != TEE_ERROR_CORRUPT_OBJECT &&
	    res != TEE_ERROR_STORAGE_NOT_AVAILABLE)
		TEE_Panic(res);

	return res;
}
Ejemplo n.º 11
0
/*
 * Use of this function is deprecated
 * new code SHOULD use the TEE_CopyObjectAttributes1 function instead
 * These functions will be removed at some future major revision of
 * this specification
 */
void TEE_CopyObjectAttributes(TEE_ObjectHandle destObject,
			      TEE_ObjectHandle srcObject)
{
	TEE_Result res;
	TEE_ObjectInfo src_info;

	res = utee_cryp_obj_get_info((unsigned long)srcObject, &src_info);
	if (src_info.objectType == TEE_TYPE_CORRUPTED_OBJECT)
		return;

	res = TEE_CopyObjectAttributes1(destObject, srcObject);
	if (res != TEE_SUCCESS)
		TEE_Panic(0);
}
Ejemplo n.º 12
0
/*
 * Use of this function is deprecated
 * new code SHOULD use the TEE_RestrictObjectUsage1 function instead
 * These functions will be removed at some future major revision of
 * this specification
 */
void TEE_RestrictObjectUsage(TEE_ObjectHandle object, uint32_t objectUsage)
{
	TEE_Result res;
	TEE_ObjectInfo objectInfo;

	res = utee_cryp_obj_get_info((unsigned long)object, &objectInfo);
	if (objectInfo.objectType == TEE_TYPE_CORRUPTED_OBJECT)
		return;

	res = TEE_RestrictObjectUsage1(object, objectUsage);

	if (res != TEE_SUCCESS)
		TEE_Panic(0);
}
Ejemplo n.º 13
0
TEE_Result TEE_GetObjectInfo1(TEE_ObjectHandle object, TEE_ObjectInfo *objectInfo)
{
	TEE_Result res;

	res = utee_cryp_obj_get_info((uint32_t)object, objectInfo);

	if (res == TEE_ERROR_CORRUPT_OBJECT) {
		res = utee_storage_obj_del(object);
		if (res != TEE_SUCCESS)
			TEE_Panic(0);
		return TEE_ERROR_CORRUPT_OBJECT;
	}

	if (res != TEE_SUCCESS && res != TEE_ERROR_STORAGE_NOT_AVAILABLE)
		TEE_Panic(res);

	return res;
}
Ejemplo n.º 14
0
/*
 * Use of this function is deprecated
 * new code SHOULD use the TEE_GetObjectInfo1 function instead
 * These functions will be removed at some future major revision of
 * this specification
 */
void TEE_GetObjectInfo(TEE_ObjectHandle object, TEE_ObjectInfo *objectInfo)
{
	TEE_Result res;

	res = utee_cryp_obj_get_info((unsigned long)object, objectInfo);

	if (res != TEE_SUCCESS)
		TEE_Panic(res);

	if (objectInfo->objectType == TEE_TYPE_CORRUPTED_OBJECT) {
		objectInfo->keySize = 0;
		objectInfo->maxKeySize = 0;
		objectInfo->objectUsage = 0;
		objectInfo->dataSize = 0;
		objectInfo->dataPosition = 0;
		objectInfo->handleFlags = 0;
	}
}
Ejemplo n.º 15
0
TEE_Result TEE_SeekObjectData(TEE_ObjectHandle object, int32_t offset,
                              TEE_Whence whence)
{
    TEE_Result res;
    TEE_ObjectInfo info;

    if (object == TEE_HANDLE_NULL)
        TEE_Panic(0);

    res = utee_cryp_obj_get_info((uint32_t)object, &info);
    if (res != TEE_SUCCESS)
        TEE_Panic(0);

    switch (whence) {
    case TEE_DATA_SEEK_SET:
        if (offset > 0 && (uint32_t)offset > TEE_DATA_MAX_POSITION)
            return TEE_ERROR_OVERFLOW;
        break;
    case TEE_DATA_SEEK_CUR:
        if (offset > 0 &&
                ((uint32_t)offset + info.dataPosition >
                 TEE_DATA_MAX_POSITION ||
                 (uint32_t)offset + info.dataPosition <
                 info.dataPosition))
            return TEE_ERROR_OVERFLOW;
        break;
    case TEE_DATA_SEEK_END:
        if (offset > 0 &&
                ((uint32_t)offset + info.dataSize > TEE_DATA_MAX_POSITION ||
                 (uint32_t)offset + info.dataSize < info.dataSize))
            return TEE_ERROR_OVERFLOW;
        break;
    default:
        TEE_Panic(0);
    }

    res = utee_storage_obj_seek(object, offset, whence);

    if (res != TEE_SUCCESS && res != TEE_ERROR_OVERFLOW)
        TEE_Panic(0);

    return res;
}
Ejemplo n.º 16
0
void TEE_ResetTransientObject(TEE_ObjectHandle object)
{
	TEE_Result res;
	TEE_ObjectInfo info;

	if (object == TEE_HANDLE_NULL)
		return;

	res = utee_cryp_obj_get_info((unsigned long)object, &info);
	if (res != TEE_SUCCESS)
		TEE_Panic(0);

	if ((info.handleFlags & TEE_HANDLE_FLAG_PERSISTENT) != 0)
		TEE_Panic(0);

	res = utee_cryp_obj_reset((unsigned long)object);
	if (res != TEE_SUCCESS)
		TEE_Panic(0);
}
Ejemplo n.º 17
0
TEE_Result TEE_GetObjectValueAttribute(TEE_ObjectHandle object,
				       uint32_t attributeID, uint32_t *a,
				       uint32_t *b)
{
	TEE_Result res;
	TEE_ObjectInfo info;
	uint32_t buf[2];
	uint64_t size = sizeof(buf);

	res = utee_cryp_obj_get_info((unsigned long)object, &info);
	if (res != TEE_SUCCESS)
		goto exit;

	/* This function only supports value attributes */
	if (!(attributeID & TEE_ATTR_BIT_VALUE)) {
		res = TEE_ERROR_BAD_PARAMETERS;
		goto exit;
	}

	res = utee_cryp_obj_get_attr((unsigned long)object, attributeID, buf,
				     &size);

exit:
	if (res != TEE_SUCCESS &&
	    res != TEE_ERROR_ITEM_NOT_FOUND &&
	    res != TEE_ERROR_CORRUPT_OBJECT &&
	    res != TEE_ERROR_STORAGE_NOT_AVAILABLE)
		TEE_Panic(0);

	if (size != sizeof(buf))
		TEE_Panic(0);

	if (res == TEE_SUCCESS) {
		if (a)
			*a = buf[0];
		if (b)
			*b = buf[1];
	}

	return res;
}
Ejemplo n.º 18
0
void TEE_DeriveKey(TEE_OperationHandle operation,
		   const TEE_Attribute *params, uint32_t paramCount,
		   TEE_ObjectHandle derivedKey)
{
	TEE_Result res;
	TEE_ObjectInfo key_info;

	if (operation == TEE_HANDLE_NULL || derivedKey == 0)
		TEE_Panic(0);
	if (paramCount != 0 && params == NULL)
		TEE_Panic(0);

	if (operation->info.algorithm != TEE_ALG_DH_DERIVE_SHARED_SECRET)
		TEE_Panic(0);

	if (operation->info.operationClass != TEE_OPERATION_KEY_DERIVATION)
		TEE_Panic(0);
	if (operation->info.mode != TEE_MODE_DERIVE)
		TEE_Panic(0);
	if ((operation->info.handleState & TEE_HANDLE_FLAG_KEY_SET) == 0)
		TEE_Panic(0);

	res = utee_cryp_obj_get_info((uint32_t) derivedKey, &key_info);
	if (res != TEE_SUCCESS)
		TEE_Panic(0);

	if (key_info.objectType != TEE_TYPE_GENERIC_SECRET)
		TEE_Panic(0);
	if ((key_info.handleFlags & TEE_HANDLE_FLAG_INITIALIZED) != 0)
		TEE_Panic(0);

	if ((operation->info.algorithm == TEE_ALG_DH_DERIVE_SHARED_SECRET) &&
	    (paramCount != 1 ||
	     params[0].attributeID != TEE_ATTR_DH_PUBLIC_VALUE))
		TEE_Panic(0);

	res = utee_cryp_derive_key(operation->state, params, paramCount,
				   (uint32_t) derivedKey);
	if (res != TEE_SUCCESS)
		TEE_Panic(res);
}
Ejemplo n.º 19
0
void TEE_DeriveKey(TEE_OperationHandle operation,
		   const TEE_Attribute *params, uint32_t paramCount,
		   TEE_ObjectHandle derivedKey)
{
	TEE_Result res;
	TEE_ObjectInfo key_info;
	struct utee_attribute ua[paramCount];

	if (operation == TEE_HANDLE_NULL || derivedKey == 0)
		TEE_Panic(0);
	if (params == NULL && paramCount != 0)
		TEE_Panic(0);
	if (TEE_ALG_GET_CLASS(operation->info.algorithm) !=
	    TEE_OPERATION_KEY_DERIVATION)
		TEE_Panic(0);

	if (operation->info.operationClass != TEE_OPERATION_KEY_DERIVATION)
		TEE_Panic(0);
	if (!operation->key1)
		TEE_Panic(0);
	if (operation->info.mode != TEE_MODE_DERIVE)
		TEE_Panic(0);
	if ((operation->info.handleState & TEE_HANDLE_FLAG_KEY_SET) == 0)
		TEE_Panic(0);

	res = utee_cryp_obj_get_info((unsigned long)derivedKey, &key_info);
	if (res != TEE_SUCCESS)
		TEE_Panic(0);

	if (key_info.objectType != TEE_TYPE_GENERIC_SECRET)
		TEE_Panic(0);
	if ((key_info.handleFlags & TEE_HANDLE_FLAG_INITIALIZED) != 0)
		TEE_Panic(0);

	__utee_from_attr(ua, params, paramCount);
	res = utee_cryp_derive_key(operation->state, ua, paramCount,
				   (unsigned long)derivedKey);
	if (res != TEE_SUCCESS)
		TEE_Panic(res);
}