return ret;
}
+
+static TEE_Result KM_CopyEcdhPrivateAttributes(TEE_ObjectHandle dest_key,
+ TEE_ObjectHandle src_key)
+{
+ TEE_Result ret = TEE_SUCCESS;
+ uint32_t curve_a = 0, curve_b = 0;
+ KM_BinaryData data_priv = {0, NULL};
+ KM_BinaryData data_pub_x = {0, NULL};
+ KM_BinaryData data_pub_y = {0, NULL};
+ TEE_Attribute attrs[4];
+ TEE_ObjectInfo info_src, info_dest;
+
+ TEE_GetObjectInfo(src_key, &info_src);
+ TEE_GetObjectInfo(dest_key, &info_dest);
+
+ // check compatibility of source & destination
+ if (info_dest.objectType != TEE_TYPE_ECDH_KEYPAIR
+ || !(
+ (info_src.objectType == TEE_TYPE_ECDSA_KEYPAIR) || (info_src.objectType == TEE_TYPE_ECDH_KEYPAIR)
+ )) {
+ ret = TEE_ERROR_GENERIC;
+ LOG("Invalid Object Type. source object type=%x, dest object type=%x",
+ info_src.objectType, info_dest.objectType);
+ goto clean;
+ }
+
+ ret = TEE_GetObjectValueAttribute(src_key, TEE_ATTR_ECC_CURVE, &curve_a, &curve_b);
+ if (ret != TEE_SUCCESS) {
+ LOG("Failed to get TEE_ATTR_ECC_CURVE attribute info, ret = %x", ret);
+ goto clean;
+ }
+ ret = KM_GetBufferAttribute(src_key, TEE_ATTR_ECC_PRIVATE_VALUE, &data_priv);
+ if (ret != TEE_SUCCESS) {
+ LOG("Failed to get TEE_ATTR_ECC_PRIVATE_VALUE attribute, ret = %x", ret);
+ goto clean;
+ }
+ ret = KM_GetBufferAttribute(src_key, TEE_ATTR_ECC_PUBLIC_VALUE_X, &data_pub_x);
+ if (ret != TEE_SUCCESS) {
+ LOG("Failed to get TEE_ATTR_ECC_PUBLIC_VALUE_X attribute, ret = %x", ret);
+ goto clean;
+ }
+ ret = KM_GetBufferAttribute(src_key, TEE_ATTR_ECC_PUBLIC_VALUE_Y, &data_pub_y);
+ if (ret != TEE_SUCCESS) {
+ LOG("Failed to get TEE_ATTR_ECC_PUBLIC_VALUE_Y attribute, ret = %x", ret);
+ goto clean;
+ }
+
+ KM_InitValueAttribute(&attrs[0], TEE_ATTR_ECC_CURVE, curve_a, curve_b);
+ KM_InitRefAttribute(&attrs[1], TEE_ATTR_ECC_PRIVATE_VALUE, data_priv.data, data_priv.data_size);
+ KM_InitRefAttribute(&attrs[2], TEE_ATTR_ECC_PUBLIC_VALUE_X, data_pub_x.data, data_pub_x.data_size);
+ KM_InitRefAttribute(&attrs[3], TEE_ATTR_ECC_PUBLIC_VALUE_Y, data_pub_y.data, data_pub_y.data_size);
+
+ ret = TEE_PopulateTransientObject(dest_key, attrs, sizeof(attrs) / sizeof(attrs[0]));
+ if(ret != TEE_SUCCESS) {
+ LOG("Failed to populate transient object. ret=%x.", ret);
+ goto clean;
+ }
+
+clean:
+ free(data_priv.data);
+ free(data_pub_x.data);
+ free(data_pub_y.data);
+ return ret;
+}
+
static TEE_Result KM_DeriveEcdhSecret(const TEE_ObjectHandle prv_key,
uint32_t curve, const KM_BinaryData *pub_x, const KM_BinaryData *pub_y,
TEE_ObjectHandle *secret_hndl)
"key_bits_size=%d.", ret, TEE_TYPE_ECDH_KEYPAIR, info.objectSize);
goto clean;
}
- TEE_CopyObjectAttributes(ecdh_key, prv_key);
+ ret = KM_CopyEcdhPrivateAttributes(ecdh_key, prv_key);
+ if (TEE_SUCCESS != ret) {
+ LOG("Failed to copy ecdh private attribute=%x.", ret);
+ goto clean;
+ }
} else {
ecdh_key = prv_key;
}