问题描述
因此,我试图使用其cyrpto库在intel sgx中创建两个sha256哈希。当前,如果我运行以下命令:
sgx_sha256_hash_t *hash1;
int first = 1;
sgx_status_t = stat;
stat = sgx_sha256_msg( ( uint8_t * ) &first,8,hash1 );
我没有问题,并且可以正确获得hash1,但是如果尝试
sgx_sha256_hash_t *hash1;
sgx_sha256_hash_t *hash2;
int first = 1;
int second = 2;
sgx_status_t = stat;
stat = sgx_sha256_msg( ( uint8_t * ) &first,hash1 );
stat = sgx_sha256_msg( ( uint8_t * ) &second,hash2 );
我遇到了细分错误。我尝试使用sha init,update,get_hash和close方法来执行此操作,但是没有改进的结果,有人知道为什么会这样吗?我当时以为我可能会在该区域中耗尽内存,如果的确如此,是否有办法扩展我的区域?
解决方法
您正在通过这两个未初始化的指针将哈希写入内存中的随机位置,因此出现了段错误。另外,您的src_len
参数不正确,为完整起见,第一个参数应为const
。
所以,您想要的是:
sgx_sha256_hash_t hash1; // note: no asterisk
sgx_sha256_hash_t hash2;
int first = 1;
int second = 2;
sgx_status_t = stat;
stat = sgx_sha256_msg( ( const uint8_t * ) &first,sizeof (first),&hash1 );
stat = sgx_sha256_msg( ( const uint8_t * ) &second,sizeof (second),&hash2 );