-
Notifications
You must be signed in to change notification settings - Fork 716
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WASI] WASI Random Plugin #2875
base: master
Are you sure you want to change the base?
Conversation
Hello, I am a code review bot on flows.network. Here are my reviews of code commits in this PR. Commit 81f8220a28eb71105b068071d9042b2e3f06c5b2Key Changes: The pull request appears to add a new plugin Specifically, the changes include:
Potential Issues:
|
c80813d
to
27c9782
Compare
Codecov Report
@@ Coverage Diff @@
## master #2875 +/- ##
==========================================
+ Coverage 80.94% 80.96% +0.01%
==========================================
Files 150 150
Lines 21624 21624
Branches 4352 4352
==========================================
+ Hits 17503 17507 +4
Misses 2954 2954
+ Partials 1167 1163 -4 see 3 files with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
27c9782
to
f1805e1
Compare
7711d1a
to
2e07267
Compare
NOTE glibc's LCG is insufficient for cryptography. |
2e07267
to
38df4ee
Compare
Signed-off-by: Sylveon <sylveon@secondstate.io>
38df4ee
to
81f8220
Compare
bool WasiRandomEnvironment::getRandomBytes(uint64_t Len, uint8_t *Buf) { | ||
ssize_t RealQuerySize = | ||
getrandom_wrapper(Buf, Len, GRND_RANDOM | GRND_NONBLOCK); | ||
|
||
// note: the spec did not handle the error such like EAGAIN, we just make that | ||
// case fail. | ||
if (RealQuerySize < 0 || RealQuerySize != static_cast<ssize_t>(Len)) | ||
return false; | ||
|
||
return true; | ||
} | ||
|
||
bool WasiRandomEnvironment::getInsecureRandomBytes(uint64_t Len, uint8_t *Buf) { | ||
ssize_t RealQuerySize = | ||
getrandom_wrapper(Buf, Len, GRND_INSECURE | GRND_NONBLOCK); | ||
|
||
// note: the spec did not handle the error such like EAGAIN, we just make that | ||
// case fail. | ||
if (RealQuerySize < 0 || RealQuerySize != static_cast<ssize_t>(Len)) | ||
return false; | ||
|
||
return true; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not merge them? If they're just with different flag.
bool WasiRandomEnvironment::getRandomBytes(uint64_t Len, uint8_t *Buf) { | ||
auto Status = CCRandomGenerateBytes(Buf, Len); | ||
return Status == kCCSuccess; | ||
} | ||
|
||
bool WasiRandomEnvironment::getInsecureRandomBytes(uint64_t Len, uint8_t *Buf) { | ||
auto Status = CCRandomGenerateBytes(Buf, Len); | ||
return Status == kCCSuccess; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They're exact same, right?
bool WasiRandomEnvironment::getRandomBytes(uint64_t Len, uint8_t *Buf) { | ||
if (Len > UINT32_MAX) | ||
return false; | ||
return WinGetRandomBytes(static_cast<uint32_t>(Len), Buf); | ||
} | ||
|
||
bool WasiRandomEnvironment::getInsecureRandomBytes(uint64_t Len, uint8_t *Buf) { | ||
if (Len > UINT32_MAX) | ||
return false; | ||
return WinGetRandomBytes(static_cast<uint32_t>(Len), Buf); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar problem
if (unlikely(Env.getRandomBytes(Len, Buf.data()) == false)) { | ||
return Unexpect(ErrCode::Value::HostFuncError); | ||
} | ||
return {}; | ||
} | ||
|
||
Expect<void> WasiGetInsecureRandomU64::body(const Runtime::CallingFrame &Frame, | ||
uint32_t /* Out */ U64Ptr) { | ||
// Check memory instance from module. | ||
auto *MemInst = Frame.getMemoryByIndex(0); | ||
if (unlikely(MemInst == nullptr)) { | ||
return Unexpect(ErrCode::Value::HostFuncError); | ||
} | ||
|
||
// Check for invalid address. | ||
constexpr auto U64Len = sizeof(uint64_t); | ||
const auto Buf = MemInst->getSpan<uint8_t>(U64Ptr, U64Len); | ||
if (unlikely(Buf.size() != U64Len)) { | ||
return Unexpect(ErrCode::Value::HostFuncError); | ||
} | ||
|
||
if (unlikely(Env.getRandomBytes(U64Len, Buf.data()) == false)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are them going to use getInsecureRandomBytes
? Or intended use getRandomBytes
?
namespace Host { | ||
|
||
using namespace std::literals; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe leave a link to the preview2, where one can check the WIT definitions.
add WASI Random Plugin
Progress
Support