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

crypto createSign significant slower than in Node #9147

Open
telcy opened this issue Feb 28, 2024 · 0 comments
Open

crypto createSign significant slower than in Node #9147

telcy opened this issue Feb 28, 2024 · 0 comments
Labels
node.js Compatibility with Node.js APIs performance An issue with performance

Comments

@telcy
Copy link

telcy commented Feb 28, 2024

What version of Bun is running?

1.0.28+705638470

What platform is your computer?

Darwin 23.2.0 arm64 arm

What steps can reproduce the bug?

import { createSign } from "crypto";

const privateKey = `-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEAkDalaR550JK4X3dPWUeV39ON3fJpF9dyuSY4V3eZZhwcPN6P
qpduGPZKfugI8pSvQgKAN7VawF6N1ynHe3TPS+/4iouIs7xPMhIJFUsI8P7kbeSZ
wLBAVNTZeWhit9Z8jGr/r1fLBZhMnOcbheD9Tsap61qnbojFghCI7a+bF9JOok93
h6hfrxL9YV+AiaSHSDyeu/3MXt9i74e8MFwTM6SucgoW04KN3VW3+EDRB3BBglN6
7mJBpzGqhodEgSQrdMc2OYo7olxxMDiHaZjac3P1JwcWRnBqzzTeFJ1HvKI/Z4FC
VtCG/5fWalfCpAmDhSme1rll7sb6KKHe18vbTwIDAQABAoIBAFwTN8sE1Tuw4Zy6
PWRAS1WL6dEiO60oNqw11dUqnDtQiUrnwoxlgLrZTTj3hvbyrW8Uz65B0P5voFoW
57FQJCZUwbgbXJ19BoducnQw4zWTWF89jFk1bu16tJtKZXUAsaapjjPydsJMueWX
vL/epXxNZSHKUIpHMutXCUXQT9KFyo48SDWVDye39ZhW8ws2v3lDnyop6TY56UIP
8ro79JL517Rqd3EZcPMiw/9Un4YUxF7Gqb941mNf1M0CT2dXP7QdMdGZnVofXRH0
qT9fKnr1PyCMGSYa6E7aGN4VZ/GO21U7PSf4ZVADPgO+Z/ItMuCm2/jFxfVssWfu
w59X0okCgYEA/BzUNXXCxaaoVI1SamQnaE4hfzuhdgWxkxVbMHFqKLquqOZp0Alk
ThZxG9jO6c3J6iH14fNW3pcuUC5VuGM+UBMlCfwI/QxzgV//sPEAQACXPpvuULBK
fLINIITLyH4QpK8xDLL44DHQs1KOSoUHm4LJtQOpkk8myX2fTHJ2eJsCgYEAkm/n
ZifEeUcjh0fpmvHx6VbmEgADuff61TfN5Ne/7qCK6fUQg5suRavXKVQDmDlPvito
NZQznUf67u4LLywxILWl4Xv+GNUUxAYsUzNkQ4i5TQmvZskB9ZE1B913u2RJwpXE
WOKZO5/SRZlg0JRL++gB2YpRrwFlLpcTgm7bUV0CgYAplqvfAcUWi8563DE7QbhK
eZEHBxQ0fu3zIHPBgwQLIfiL/i54VgRI6WTRPiur3/mt+Nox4s1yvKe0LGCRoTV3
SiEzC3OEItiu/+ITEz6CUFaiymA+yUYQWeLWeXGQalNeh1PlD2UEvtL5seWtH1LI
8YNKrAb+DraMSH/NwZgPfwKBgQCKwwuNG+Xr3mNmT9ingNjxeezt5aGiWcAQx56N
WXyAjRTVeem6LBR+5MUwXnJBjx1nYQ6Qpuz5/zljq6JhgwjSrA6SSsKPmWriDc92
z94UuLyOqbzSM2tt3blYyJ4qrm/OucijSaZWf63rUdoSDFSsUj9eetnIchQFQBe2
o4Gj6QKBgAL9vs5gq7ZrDlqRH2hjUY0hkTE3W0KQb6RlaOFOTKRa8N1NcQU2Zsv2
d/kOHiIJZuv+kNUyCtYdZ5iJlCEPQBXA0hEL7h69GUhQdio3u8Id7oPXxWQdxHmo
qQPT1FCrvzfvjcmRwq5ysUK0pln0spsE4DHiY+5KEnuuODzxQFGh
-----END RSA PRIVATE KEY-----`;

const data =
  "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.";

const start = Date.now();
for (let i = 0; i < 100; i++) {
  createSign("RSA-SHA1").update(data).sign(privateKey, "base64");
}
console.log("signing took", Date.now() - start, "ms");

// bun: 2569 ms
// node: 116 ms

What is the expected behavior?

The signing speed should be at least on par with Nodejs.

What do you see instead?

I see signing speeds 20 times slower than Nodejs.

Additional information

I have noticed this issue when working with @aws-sdk/cloudfront-signer as they are using crypto.createSign internally.

@telcy telcy added the bug Something isn't working label Feb 28, 2024
@Electroid Electroid added performance An issue with performance node.js Compatibility with Node.js APIs and removed bug Something isn't working labels Feb 28, 2024
@robobun robobun added node.js Compatibility with Node.js APIs and removed node.js Compatibility with Node.js APIs labels Feb 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
node.js Compatibility with Node.js APIs performance An issue with performance
Projects
None yet
Development

No branches or pull requests

3 participants