简体   繁体   English

将char数组传递给函数以获取update char数组的值

[英]passing char array to function to get the value of update char array

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;
}

I wanted to call the get_alpha() function from another function and get the value from the resecret char array. 我想从另一个函数调用get_alpha()函数,并从resecret char数组获取值。 I tried to change the get_alpha() to get_alpha(char *resecret) and commented the char resecret[12]; 我试图将get_alpha()更改为get_alpha(char * resecret)并注释了char resecret [12]; in the get_alpha function and also made uint64_t resecret_size = sizeof(resecret); 在get_alpha函数中,还使uint64_t resecret_size = sizeof(resecret); to uint64_t resecret_size = (12);. 为uint64_t resecret_size =(12);。

And call it like this from other function 然后从其他函数中这样调用它

char resecret[12];
get_alpha(resecret);

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

But I do not get the correct answer. 但是我没有得到正确的答案。 It seems sgx_unseal_data fails. 似乎sgx_unseal_data失败。

The signature of 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);

The marked line seems odd: 标记的行似乎很奇怪:

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);

I believe the call should be: 我相信电话应该是:

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

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

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