Skip to content
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

node:crypto: native Hmac and Hash #17920

Merged
merged 19 commits into from
Mar 7, 2025
Merged

node:crypto: native Hmac and Hash #17920

merged 19 commits into from
Mar 7, 2025

Conversation

dylan-conway
Copy link
Member

@dylan-conway dylan-conway commented Mar 5, 2025

What does this PR do?

Moves Hmac and Hash to c++ using ncrypto

How did you verify your code works?

Added test-crypto-hmac.js, test-crypto-hash.js, and test-crypto-hash-stream-pipe.js

@robobun
Copy link

robobun commented Mar 5, 2025

Updated 9:34 PM PT - Mar 6th, 2025

@dylan-conway, your commit fbe992d has 2 failures in Build #12817:


🧪   try this PR locally:

bunx bun-pr 17920

@dylan-conway dylan-conway changed the title node:crypto: native Hmac node:crypto: native Hmac and Hash Mar 6, 2025
@dylan-conway dylan-conway marked this pull request as ready for review March 6, 2025 01:52
@dylan-conway dylan-conway marked this pull request as draft March 6, 2025 03:11
@dylan-conway dylan-conway marked this pull request as ready for review March 7, 2025 01:41
@dylan-conway dylan-conway requested a review from paperclover March 7, 2025 02:46
@@ -2337,6 +2337,111 @@ pub const Crypto = struct {
pub usingnamespace JSC.Codegen.JSCryptoHasher;
usingnamespace bun.New(@This());

// For using only CryptoHasherZig in c++
pub const Extern = struct {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

non-blocking note: when zig structs do not contain fields, it is convention to name them snake case lowercase since it is just a namespace.


case WebCore::BufferEncodingType::ucs2:
case WebCore::BufferEncodingType::utf16le: {
memcpy(data.data(), bytes.data(), bytes.size());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thinking

it would be interesting if all our memcpy calls had ASSERT(data.size() >= bytes.size())

hmac->m_ctx.reset();
}

// TODO(dylan-conway): We shouldn't set finalized if coming from _flush
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

im not sure if this todo is blocking

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the comment. It's true we shouldn't set finalized if the caller is _flush, but the field isn't javascript facing and turns out it works the same due to m_ctx.reset() above this.

void finishCreation(JSC::VM& vm, JSC::JSObject* prototype)
{
Base::finishCreation(vm, 2, "Hmac"_s, PropertyAdditionMode::WithStructureTransition);
// putDirectWithoutTransition(vm, vm.propertyNames->prototype, prototype, JSC::PropertyAdditionMode::WithStructureTransition);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is that right

@Jarred-Sumner Jarred-Sumner merged commit ae19729 into main Mar 7, 2025
67 of 70 checks passed
@Jarred-Sumner Jarred-Sumner deleted the dylan/native-hmac branch March 7, 2025 07:52
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.

4 participants