-
Notifications
You must be signed in to change notification settings - Fork 296
Faster signatures #134
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
base: master
Are you sure you want to change the base?
Faster signatures #134
Conversation
This makes signing/verifying ~3 times faster. On 2.6 GHz Intel Core i5 (MBPr Mid 2014), Node.js v8.8.1: Before: sign 92 ops 5.46 ms/op 183.17 ops/sec sign.open 48 ops 10.50 ms/op 95.26 ops/sec After: sign 269 ops 1.86 ms/op 536.52 ops/sec sign.open 136 ops 3.70 ms/op 270.55 ops/sec
f4ed5c0
to
328ee60
Compare
This potentially breaks constant timing. Arrays created by This is just a theory, but it explains why I'm hesitant to merge this PR. I'd really like to do it, since it brings a great improvement in performance. Perhaps, someone more familiar with internals of JavaScript VMs can take a look? |
…riations introduced by previous solution (PR dchest#134) that could leak information about secret keys PR makes: signing ~2 times faster on m4 max (~ same performance as previous solution) verifying ~40+ times faster (~20+ times faster than previous solution) On M4 Max (MBP Nov 2024), Node.js v8.8.1:
…riations introduced by previous solution (PR dchest#134) that could leak information about secret keys PR makes: signing ~2 times faster on m4 max (~ same performance as previous solution) verifying ~40+ times faster (~20+ times faster than previous solution) On M4 Max (MBP Nov 2024), tested in browser: CURRENT sign 405 ops 1.24 ms/op 809.68 ops/sec sign.open 206 ops 2.44 ms/op 410.44 ops/sec PR dchest#134 sign 893 ops 0.56 ms/op 1784.93 ops/sec sign.open 456 ops 1.10 ms/op 910.36 ops/sec THIS PR sign 795 ops 0.63 ms/op 1589.36 ops/sec sign.open 8609 ops 0.06 ms/op 17193.93 ops/sec
…aphic operations while maintaining security: - **Eliminates timing variations** present in the previous solution (PR dchest#134) that could potentially leak secret key information - **Signing operations:** ~2x faster on M4 Max compared to current implementation (slightly slower than PR dchest#134) - **Verification operations:** ~40x faster than current implementation (~20x faster than previous PR dchest#134 solution) On M4 Max (MBP Nov 2024), tested in Chrome Version 134.0.6998.89 - arm64: | Operation | Operations | Time per operation | Operations per second | Delta | |-----------|------------|--------------------|-----------------------|-------| | sign | 787 ops | 0.64 ms/op | 1573.69 ops/sec | [+91.1%] | | sign.open | 8641 ops | 0.06 ms/op | 17261.29 ops/sec | [+4067.3%] | | Operation | Operations | Time per operation | Operations per second | Delta | |-----------|------------|--------------------|-----------------------|-------| | sign | 889 ops | 0.56 ms/op | 1775.51 ops/sec | [+115.6%] | | sign.open | 454 ops | 1.10 ms/op | 906.55 ops/sec | [+118.9%] | | Operation | Operations | Time per operation | Operations per second | Delta | |-----------|------------|--------------------|-----------------------|-------| | sign | 412 ops | 1.21 ms/op | 823.34 ops/sec | - | | sign.open | 208 ops | 2.41 ms/op | 414.18 ops/sec | - |
…───────────┐ │ PERFORMANCE IMPROVEMENTS SUMMARY │ ├───────────────────────────────────────────────────────────────────────────────┤ │ This PR delivers significant performance improvements in cryptographic │ │ operations while maintaining security: │ │ │ │ • Eliminates timing variations present in the previous solution (PR dchest#134) │ │ that could potentially leak secret key information │ │ │ │ • Signing operations: ~2x faster on M4 Max compared to current implementation │ │ (slightly slower than PR dchest#134) │ │ │ │ • Verification operations: ~40x faster than current implementation │ │ (~20x faster than previous PR dchest#134 solution) │ │ │ ├───────────────────────────────────────────────────────────────────────────────┤ │ BENCHMARK RESULTS │ ├─────────────────────────────────────────────────────────────────────────────────────────────┤ │ On M4 Max (MBP Nov 2024), tested in Chrome Version 134.0.6998.89 - arm64: │ │ │ │ THIS PR │ │ sign 787 ops 0.64 ms/op 1573.69 ops/sec [+91.1%] │ │ sign.open 8641 ops 0.06 ms/op 17261.29 ops/sec [+4067.3%] │ │ │ │ PR dchest#134 with risk of timing attacks │ │ sign 889 ops 0.56 ms/op 1775.51 ops/sec [+115.6%] │ │ sign.open 454 ops 1.10 ms/op 906.55 ops/sec [+118.9%] │ │ │ │ CURRENT IMPLEMENTATION │ │ sign 412 ops 1.21 ms/op 823.34 ops/sec - │ │ sign.open 208 ops 2.41 ms/op 414.18 ops/sec - │ └─────────────────────────────────────────────────────────────────────────────────────────────┘
Huge increase of performance in signing/verifying WITHOUT timing variations that could leak information about secret keys (that made PR dchest#134 unmergeable) ┌───────────────────────────────────────────────────────────────────────────────┐ │ PERFORMANCE IMPROVEMENTS SUMMARY │ ├───────────────────────────────────────────────────────────────────────────────┤ │ • Signing: ~2x faster on M4 Max compared to current implementation │ │ (slightly slower than previous solution) │ │ │ │ • Verification: ~40x faster than current implementation │ │ (~20x faster than previous PR dchest#134 solution) │ │ │ ├───────────────────────────────────────────────────────────────────────────────┤ │ BENCHMARK RESULTS │ ├─────────────────────────────────────────────────────────────────────────────────────────────┤ │ On M4 Max (MBP Nov 2024), tested in Chrome Version 134.0.6998.89 - arm64: │ │ │ │ THIS PR │ │ sign 787 ops 0.64 ms/op 1573.69 ops/sec [+91.1%] │ │ sign.open 8641 ops 0.06 ms/op 17261.29 ops/sec [+4067.3%] │ │ │ │ PR dchest#134 with risk of timing attacks │ │ sign 889 ops 0.56 ms/op 1775.51 ops/sec [+115.6%] │ │ sign.open 454 ops 1.10 ms/op 906.55 ops/sec [+118.9%] │ │ │ │ CURRENT IMPLEMENTATION │ │ sign 412 ops 1.21 ms/op 823.34 ops/sec - │ │ sign.open 208 ops 2.41 ms/op 414.18 ops/sec - │ └─────────────────────────────────────────────────────────────────────────────────────────────┘
Huge increase of performance in signing/verifying WITHOUT timing variations that could leak information about secret keys (that made PR dchest#134 unmergeable) ┌───────────────────────────────────────────────────────────────────────────────┐ │ PERFORMANCE IMPROVEMENTS SUMMARY │ ├───────────────────────────────────────────────────────────────────────────────┤ │ • Signing: ~2x faster on M4 Max compared to current implementation │ │ (slightly slower than previous solution) │ │ │ │ • Verification: ~40x faster than current implementation │ │ (~20x faster than previous PR dchest#134 solution) │ │ │ ├───────────────────────────────────────────────────────────────────────────────┤ │ BENCHMARK RESULTS │ ├─────────────────────────────────────────────────────────────────────────────────────────────┤ │ On M4 Max (MBP Nov 2024), tested in Chrome Version 134.0.6998.89 - arm64: │ │ │ │ THIS PR │ │ sign 787 ops 0.64 ms/op 1573.69 ops/sec [+91.1%] │ │ sign.open 8641 ops 0.06 ms/op 17261.29 ops/sec [+4067.3%] │ │ │ │ PR dchest#134 with risk of timing attacks │ │ sign 889 ops 0.56 ms/op 1775.51 ops/sec [+115.6%] │ │ sign.open 454 ops 1.10 ms/op 906.55 ops/sec [+118.9%] │ │ │ │ CURRENT IMPLEMENTATION │ │ sign 412 ops 1.21 ms/op 823.34 ops/sec - │ │ sign.open 208 ops 2.41 ms/op 414.18 ops/sec - │ └─────────────────────────────────────────────────────────────────────────────────────────────┘
Use plain arrays instead of Float64Array.