gpt4 book ai didi

c - 将 char 数组传递给函数以获取更新 char 数组的值

转载 作者:行者123 更新时间:2023-11-30 16:31:54 24 4
gpt4 key购买 nike

int get_alpha()
{
std::string sealed_alpha_file = "/home/roshan/thesis/osn_server/sealed_alpha";

long fsize;
ocall_get_textsize(sealed_alpha_file.c_str(), &fsize, 0);
unsigned char sealed_data[fsize];
size_t ocall_return;
ocall_load_file(&ocall_return, sealed_alpha_file.c_str(), fsize, sealed_data, 0);

char resecret[12];
uint64_t resecret_size = sizeof(resecret);
sgx_status_t ret;
ret = sgx_unseal_data(
(sgx_sealed_data_t*)sealed_data,
NULL,
NULL,
(uint8_t*)&resecret,
(uint32_t*)&resecret_size);

if(ret != SGX_SUCCESS)
{
mbedtls_printf("Enclave: Unsealing sealed_alpha failed %#x\n", ret);
return -1;
}

mbedtls_printf("Enclave: Unsealing sealed_alpha success");
mbedtls_printf("Enclave: After unsealing alpha number: %llu\n", *(char *)resecret);
return 0;
}

我想从另一个函数调用 get_alpha() 函数并从 resecret char 数组中获取值。我尝试将 get_alpha() 更改为 get_alpha(char *resecret) 并评论 char resecret[12];在 get_alpha 函数中,还制作了 uint64_t resecret_size = sizeof(resecret);到 uint64_t resecret_size = (12);。

并从其他函数中这样调用它

char resecret[12];
get_alpha(resecret);

mbedtls_printf("Enclave: After unsealing alpha number: %llu\n", *(char *)resecret);

但我没有得到正确的答案。看来 sgx_unseal_data 失败了。

sgx_unseal_data的签名:

sgx_status_t SGXAPI sgx_unseal_data(const sgx_sealed_data_t *p_sealed_data,
uint8_t *p_additional_MACtext,
uint32_t *p_additional_MACtext_length,
uint8_t *p_decrypted_text,
uint32_t *p_decrypted_text_length);

最佳答案

标记的线看起来很奇怪:

ret = sgx_unseal_data(
(sgx_sealed_data_t*)sealed_data,
NULL,
NULL,
(uint8_t*)&resecret, // Probably shouldn't use address-of (&) here?
(uint32_t*)&resecret_size);

我认为调用应该是:

ret = sgx_unseal_data(
(sgx_sealed_data_t*)sealed_data,
NULL,
NULL,
(uint8_t*)resecret,
(uint32_t*)&resecret_size);

关于c - 将 char 数组传递给函数以获取更新 char 数组的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50381275/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com