-
-
Notifications
You must be signed in to change notification settings - Fork 79
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
Wasm target #88
Wasm target #88
Conversation
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.
In principle, I'm not against adding additional code to support WebAssembly. However, I find your implementation a bit confusing.
- Instead of using an
#elif
preprocessor instruction you are nesting#if ... #endif
constructs. IMHO that makes the code less readable - There are quite a few unnecessary empty lines
- Your code uses unconditionally console out (
printf
). Such output may be useful while debugging, but should not be in production code - Your implementation has actually unreachable code:
#else
#if defined(__WASM__)
/* Code that will be executed if symbol __WASM__ is defined */
#else
#if defined(__WASM__)
/* Code unreachable !!! */
/* Symbol __WASM_ can't be defined here, because we are in*/
/* the #else branch of the first check for symbol __WASM__ */
#else
# error "Secure pseudorandom number generator not implemented for this OS"
#endif
#endif
I would prefer something like this (if that's what you want/need):
#elif defined(__WASM__)
static size_t entropy(void* buf, size_t n)
{
if (getentropy(buf, n) == 0)
return n;
}
#else
# error "Secure pseudorandom number generator not implemented for this OS"
#endif
Conditional define __WASM__ to allow wasm target for clang + wasi-sdk for browser.
Conditional define __WASM__ to allow wasm target for clang + wasi-sdk for browser.
Sorry about all the noise! Something was wrong with my local git repo, every time i commited changes, it would be a strange merge of an old commit with the new. Fixed now. I thought I was losing my mind! I do remember why I had the full braces and return here. SQLite3MultipleCiphers/src/chacha20poly1305.c Line 393 in cc7033e
I was seeing this warning and thought I would clear it up.
|
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.
Thanks for cleaning up the code.
Unfortunately, I missed one glitch in the code; function entropy
must return a value. That is, this code
if (getentropy(buf, n) == 0)
return n
has to be changed for example to
return (getentropy(buf, n) == 0) ? n : 0;
Additionally, the line 401 #endif
has to be removed, because there is no corresponding #if
.
I already commented on the latter, but additionally the keyword extern size_t entropy(void* buf, size_t n);
size_t entropy(void* buf, size_t n)
{
return (getentropy(buf, n) == 0) ? n : 0;
} |
Conditional define __WASM__ to allow wasm target for clang + wasi-sdk for browser.
Ok, I removed the static keyword, just curious why? There is another definition further up where I believe I got the signature from when I was making the change that is static. Also just to be sure, your code above is not what I have.
This is what I have. the extern decl is for getentropy. extern size_t getentropy(void* buf, size_t n);
size_t entropy(void* buf, size_t n)
{
return (getentropy(buf, n) == 0) ? n : 0;
} |
Ouch, please revert this change. That is, the
Yes, your version is correct. Sorry for my lack of concentration. |
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.
I think the PR is now finally correct.
Added conditional WASM so that the entropy can be properly defined for wasm targets.