Skip to content

Conversation

@wenyongh
Copy link
Contributor

@wenyongh wenyongh commented May 19, 2022

Implement SGX getrandom with sgx_read_rand and getentropy with rdseed instruction
instead of ocall to improve the security.

@zhenghaven
Copy link

The new getrandom implementation looks good to me. However, for getentropy, I'm not sure if using sgx_read_rand is secure enough for the entropy, since sgx_read_rand uses RDRAND instruction (reference: https://github.com/intel/linux-sgx/blob/master/external/rdrand/src/rdrand.c and https://github.com/intel/linux-sgx/blob/master/common/src/sgx_read_rand.cpp). Probably RDSEED instruction is a better option for entropy. As far as I know, Intel SGX SDK does not provide a high-level API to RDSEED instruction, but RDSEED instruction itself should be available inside of SGX. And I found Intel provides some sample code for using the RDSEED instruction: https://www.intel.com/content/www/us/en/developer/articles/guide/intel-digital-random-number-generator-drng-software-implementation-guide.html

@wenyongh
Copy link
Contributor Author

The new getrandom implementation looks good to me. However, for getentropy, I'm not sure if using sgx_read_rand is secure enough for the entropy, since sgx_read_rand uses RDRAND instruction (reference: https://github.com/intel/linux-sgx/blob/master/external/rdrand/src/rdrand.c and https://github.com/intel/linux-sgx/blob/master/common/src/sgx_read_rand.cpp). Probably RDSEED instruction is a better option for entropy. As far as I know, Intel SGX SDK does not provide a high-level API to RDSEED instruction, but RDSEED instruction itself should be available inside of SGX. And I found Intel provides some sample code for using the RDSEED instruction: https://www.intel.com/content/www/us/en/developer/articles/guide/intel-digital-random-number-generator-drng-software-implementation-guide.html

Thanks, code of getentropy was updated by using rdseed instruction.

@zhenghaven
Copy link

It compiles and works on my end. Thank you for addressing this issue!

@wenyongh wenyongh merged commit 37cc6ea into bytecodealliance:main May 21, 2022
@wenyongh wenyongh deleted the refine_sgx_getrandom branch May 22, 2022 09:18
NingW101 pushed a commit to NingW101/wasm-micro-runtime that referenced this pull request Jul 19, 2022
Implement SGX getrandom with sgx_read_rand and getentropy with `rdseed` instruction
instead of ocall to improve the security.
vickiegpt pushed a commit to vickiegpt/wamr-aot-gc-checkpoint-restore that referenced this pull request May 27, 2024
Implement SGX getrandom with sgx_read_rand and getentropy with `rdseed` instruction
instead of ocall to improve the security.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants