Nathan Whitaker
bac8171c40
perf(crypto): use ring for asm implementations of sha256/sha512 ( #27885 )
...
Currently we are using the pure rust backend of `sha2`, which has subpar
performance compared to asm implementations. We already depend on
`ring`, so just use that instead of `sha2` for sha256/sha512 digests.
This also speeds up things like S3 uploads, which calculate sha digests
of the uploaded objects. On my local machine, this speeds up uploading a
100MB file (to a localhost s3 provider via`@aws-sdk/client-s3`) by about
2x
<details>
<summary>Benchmark:</summary>
```ts
import { createHmac } from "node:crypto";
for (
const size of [1, 10, 100, 1_000, 10_000, 100_000, 1_000_000, 10_000_000]
) {
const input = "a".repeat(size);
Deno.bench({
name: `sha256-${size}`,
fn() {
const _hash = createHmac("sha256", input).update(input).digest();
},
});
Deno.bench({
name: `sha512-${size}`,
fn() {
const _hash = createHmac("sha512", input).update(input).digest();
},
});
}
```
</details>
<details>
<summary>Results (arm64 macOS):</summary>
```
--- sha256-1 ---
../../deno/target/release/deno 2.527 µs 1.240 times faster
/Users/nathanwhit/.deno/bin/deno 3.132 µs
--- sha512-1 ---
../../deno/target/release/deno 3.364 µs 1.071 times faster
/Users/nathanwhit/.deno/bin/deno 3.603 µs
--- sha256-10 ---
../../deno/target/release/deno 3.060 µs 1.027 times faster
/Users/nathanwhit/.deno/bin/deno 3.144 µs
--- sha512-10 ---
../../deno/target/release/deno 3.583 µs 1.047 times faster
/Users/nathanwhit/.deno/bin/deno 3.751 µs
--- sha256-100 ---
../../deno/target/release/deno 3.695 µs 1.244 times faster
/Users/nathanwhit/.deno/bin/deno 4.598 µs
--- sha512-100 ---
../../deno/target/release/deno 3.386 µs 1.188 times faster
/Users/nathanwhit/.deno/bin/deno 4.021 µs
--- sha256-1000 ---
../../deno/target/release/deno 4.007 µs 3.230 times faster
/Users/nathanwhit/.deno/bin/deno 12.944 µs
--- sha512-1000 ---
../../deno/target/release/deno 6.463 µs 1.466 times faster
/Users/nathanwhit/.deno/bin/deno 9.477 µs
--- sha256-10000 ---
../../deno/target/release/deno 11.674 µs 6.981 times faster
/Users/nathanwhit/.deno/bin/deno 81.493 µs
--- sha512-10000 ---
../../deno/target/release/deno 31.250 µs 1.740 times faster
/Users/nathanwhit/.deno/bin/deno 54.364 µs
--- sha256-100000 ---
../../deno/target/release/deno 82.800 µs 9.393 times faster
/Users/nathanwhit/.deno/bin/deno 777.719 µs
--- sha512-100000 ---
../../deno/target/release/deno 269.726 µs 1.851 times faster
/Users/nathanwhit/.deno/bin/deno 499.243 µs
--- sha256-1000000 ---
../../deno/target/release/deno 808.662 µs 9.427 times faster
/Users/nathanwhit/.deno/bin/deno 7.623 ms
--- sha512-1000000 ---
../../deno/target/release/deno 2.672 ms 1.795 times faster
/Users/nathanwhit/.deno/bin/deno 4.795 ms
--- sha256-10000000 ---
../../deno/target/release/deno 7.823 ms 9.868 times faster
/Users/nathanwhit/.deno/bin/deno 77.201 ms
--- sha512-10000000 ---
../../deno/target/release/deno 26.197 ms 1.846 times faster
/Users/nathanwhit/.deno/bin/deno 48.356 ms
```
</details>
<details>
<summary>Results (x86_64 linux):</summary>
```
--- sha256-1 ---
/home/nathanwhit/.deno/bin/deno 10.726 µs 1.229 times faster
../../../deno/target/release-lite/deno 13.184 µs
--- sha512-1 ---
/home/nathanwhit/.deno/bin/deno 13.177 µs 1.051 times faster
../../../deno/target/release-lite/deno 13.845 µs
--- sha256-10 ---
/home/nathanwhit/.deno/bin/deno 13.156 µs 1.047 times faster
../../../deno/target/release-lite/deno 13.780 µs
--- sha512-10 ---
/home/nathanwhit/.deno/bin/deno 14.386 µs 1.029 times faster
../../../deno/target/release-lite/deno 14.807 µs
--- sha256-100 ---
/home/nathanwhit/.deno/bin/deno 14.580 µs 1.083 times faster
../../../deno/target/release-lite/deno 15.789 µs
--- sha512-100 ---
/home/nathanwhit/.deno/bin/deno 13.477 µs 1.131 times faster
../../../deno/target/release-lite/deno 15.238 µs
--- sha256-1000 ---
../../../deno/target/release-lite/deno 17.208 µs 1.116 times faster
/home/nathanwhit/.deno/bin/deno 19.198 µs
--- sha512-1000 ---
../../../deno/target/release-lite/deno 21.168 µs 1.026 times faster
/home/nathanwhit/.deno/bin/deno 21.717 µs
--- sha256-10000 ---
../../../deno/target/release-lite/deno 33.586 µs 1.990 times faster
/home/nathanwhit/.deno/bin/deno 66.837 µs
--- sha512-10000 ---
../../../deno/target/release-lite/deno 53.338 µs 1.009 times faster
/home/nathanwhit/.deno/bin/deno 53.817 µs
--- sha256-100000 ---
../../../deno/target/release-lite/deno 168.238 µs 3.063 times faster
/home/nathanwhit/.deno/bin/deno 515.354 µs
--- sha512-100000 ---
../../../deno/target/release-lite/deno 383.311 µs 1.036 times faster
/home/nathanwhit/.deno/bin/deno 397.122 µs
--- sha256-1000000 ---
../../../deno/target/release-lite/deno 1.474 ms 3.471 times faster
/home/nathanwhit/.deno/bin/deno 5.115 ms
--- sha512-1000000 ---
../../../deno/target/release-lite/deno 3.658 ms 1.057 times faster
/home/nathanwhit/.deno/bin/deno 3.865 ms
--- sha256-10000000 ---
../../../deno/target/release-lite/deno 16.438 ms 3.136 times faster
/home/nathanwhit/.deno/bin/deno 51.556 ms
--- sha512-10000000 ---
../../../deno/target/release-lite/deno 37.128 ms 1.056 times faster
/home/nathanwhit/.deno/bin/deno 39.220 ms
```
</details>
2025-01-30 23:38:14 +00:00
Leo Kettmeir
ea30e188a8
refactor: update deno_core for error refactor ( #26867 )
...
Closes #26171
---------
Co-authored-by: David Sherret <dsherret@gmail.com>
2025-01-08 14:52:32 -08:00
Kenta Moriuchi
8fb073d7b4
chore: Happy New Year 2025 ( #27509 )
2024-12-31 19:12:39 +00:00
David Sherret
ac7b33a340
chore: cargo fmt - turn on group_imports=StdExternalCrate ( #26646 )
2024-12-31 12:13:39 -05:00
Leo Kettmeir
1cab4f07a3
refactor: use concrete error type for remaining ops ( #26746 )
2024-11-06 16:57:57 -08:00
Luca Casonato
81c9e0ba25
fix(ext/crypto): support md4 digest algorithm ( #25656 )
...
Fixes #25646
2024-09-16 11:04:40 +00:00
Luca Casonato
4fa8869f24
feat(ext/node): rewrite crypto keys ( #24463 )
...
This completely rewrites how we handle key material in ext/node. Changes
in this
PR:
- **Signing**
- RSA
- RSA-PSS 🆕
- DSA 🆕
- EC
- ED25519 🆕
- **Verifying**
- RSA
- RSA-PSS 🆕
- DSA 🆕
- EC 🆕
- ED25519 🆕
- **Private key import**
- Passphrase encrypted private keys 🆕
- RSA
- PEM
- DER (PKCS#1) 🆕
- DER (PKCS#8) 🆕
- RSA-PSS
- PEM
- DER (PKCS#1) 🆕
- DER (PKCS#8) 🆕
- DSA 🆕
- EC
- PEM
- DER (SEC1) 🆕
- DER (PKCS#8) 🆕
- X25519 🆕
- ED25519 🆕
- DH
- **Public key import**
- RSA
- PEM
- DER (PKCS#1) 🆕
- DER (PKCS#8) 🆕
- RSA-PSS 🆕
- DSA 🆕
- EC 🆕
- X25519 🆕
- ED25519 🆕
- DH 🆕
- **Private key export**
- RSA 🆕
- DSA 🆕
- EC 🆕
- X25519 🆕
- ED25519 🆕
- DH 🆕
- **Public key export**
- RSA
- DSA 🆕
- EC 🆕
- X25519 🆕
- ED25519 🆕
- DH 🆕
- **Key pair generation**
- Overhauled, but supported APIs unchanged
This PR adds a lot of new individual functionality. But most importantly
because
of the new key material representation, it is now trivial to add new
algorithms
(as shown by this PR).
Now, when adding a new algorithm, it is also widely supported - for
example
previously we supported ED25519 key pair generation, but we could not
import,
export, sign or verify with ED25519. We can now do all of those things.
2024-08-07 08:43:58 +02:00
Luca Casonato
08e5606c34
fix(ext/node): rewrite digest handling ( #24392 )
...
Previously we had many different code paths all
handling digests in different places, all with
wildly different digest support. This commit
rewrites this to use a single digest handling
mechanism for all digest operations.
It adds various aliases for digest algorithms,
like node does. For example
`sha1WithRSAEncryption` is an alias for `sha1`.
It also adds support for `md5-sha1` digests in
various places.
2024-07-05 10:10:22 +02:00
snek
a555cb4d1d
feat: upgrade deno_core ( #24364 )
...
- Symbol.asyncDispose no longer needs to be polyfilled
- assorted updates for cppgc api changes
2024-07-01 15:48:52 -07:00
Luca Casonato
1e8a6b94b1
fix(ext/node): rewrite crypto.Hash ( #24302 )
...
Changes in this PR:
- Added new fixed size hash algorithms (blake2b512, blake2s256,
sha512-224, sha512-256, sha3-224, sha3-256, sha3-384, sha3-512, sm3)
- Added variable size hash algorithms (the concept), with the algorithms
shake128 and shake256
- Use cppgc instead of resources for the hasher
- Enable Node's crypto.Hash tests and fix found bugs
2024-06-24 11:47:12 +02:00
David Sherret
7e72f3af61
chore: update copyright to 2024 ( #21753 )
2024-01-01 19:58:21 +00:00
Felipe Baltor
814edcdd57
test(ext/node): port crypto_test.ts from deno_std ( #19561 )
2023-06-27 11:04:49 +09:00
Bartek Iwańczuk
1f0360c073
refactor(ext/node): reorganize ops ( #18799 )
...
Move all op related code of "ext/node" to "ext/node/ops" module.
These files were unnecessarily scattered around the extension.
2023-04-24 12:22:21 +02:00