-
Notifications
You must be signed in to change notification settings - Fork 105
feat: add xsalsa20
cipher from libsodium
#689
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
Conversation
…pt, C++ 20, test passes
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.
@boorad haven't tested this locally, but I plan to before approving.
Just a few minor questions to get me started.
Can I get more context on why libsodium? I was not aware of it before reading this PR.
I need to use |
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.
Honestly great code, I couldn't find any real problems. Nice work Brad 👍
(keep in mind I only looked at C++ code, no JS)
if (result != 0) { | ||
throw std::runtime_error("XSalsa20Cipher: Failed to update"); | ||
} | ||
return std::make_shared<NativeArrayBuffer>(output, native_data->size(), [=]() { delete[] output; }); |
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.
return std::make_shared<NativeArrayBuffer>(output, native_data->size(), [=]() { delete[] output; }); | |
return ArrayBuffer::wrap(output, native_data->size(), [=]() { delete[] output; }); |
use the initializer functions instead of the constructor, kinda more explicit.
* xsalsa20 does not have a final step, returns empty buffer | ||
*/ | ||
std::shared_ptr<ArrayBuffer> XSalsa20Cipher::final() { | ||
return std::make_shared<NativeArrayBuffer>(nullptr, 0, nullptr); |
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.
Does that deallocate fine? Not sure if this calls delete[]
at some point but maybe it's fine.
Adds
xsalsa20
cipher to the library@noble/ciphers/salsa