简体   繁体   English

如何在sgx ecall中返回大小未知的指针?

[英]How to return a pointer of unknown size in an sgx ecall?

How can I return a pointer of an unknown size in an ecall using [out]? 如何使用[out]在ecall中返回未知大小的指针? The current method I know requires that the size of the pointer is set when calling the ecall, eg: 我知道的当前方法要求在调用ecall时设置指针的大小,例如:

[out, size=len] int *p, size_t len

Is there another way, where I don't have to specify the size of the pointer when calling the ecall function? 还有另一种方法,我在调用ecall函数时不必指定指针的大小吗?

You seem to need the EDL generated code to get the data of unknown length (at the time of the call) from the enclave. 您似乎需要EDL生成的代码才能从飞地获取未知长度的数据(在调用时)。

Option 1 is to provide a buffer which is large enough to receive the data: 选项1是提供一个足够大的缓冲区来接收数据:

public int ecall_test(
                              uint32_t  data_capacity,
    [out, size=data_capacity] uint8_t*  data,
    [out]                     uint32_t* data_size
);

The trusted implementation can fill the buffer with up to data_capacity bytes of data and return the actual length in data_size . 可信执行最多可以填充缓冲区data_capacity字节的数据,并在返回的实际长度data_size Edge-function code will still copy data_capacity bytes from the trusted output buffer, but you should be fine because your data_size < data_capacity bytes will be taken care of. 边缘功能代码仍会从受信任的输出缓冲区中复制data_capacity字节,但是您应该没问题,因为您的data_size < data_capacity字节将得到处理。

Option 2 is two step process: the first ecall requests the actual data length the trusted method is going to return, then it is followed with another call that provides the actual data. 选项2分两步进行:第一个ecall请求可信方法将要返回的实际数据长度,然后是另一个提供实际数据的调用。

public int ecall_test_1(
    [out]                 uint32_t* data_size
);

public int ecall_test_2(
                          uint32_t  data_size,
    [out, size=data_size] uint8_t*  data,
);

The edge code needs to be aware of buffer sizes in advance and it is unable to accept the length of the data just from trusted function (in which case there is no way to allocate respective buffer to carry the copy of the data on the untrusted side). 边缘代码需要事先知道缓冲区的大小,并且不能仅从受信任的函数接受数据的长度(在这种情况下,无法分配相应的缓冲区来在不受信任的一侧携带数据的副本)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM