Skip to content

Conversation

linegel
Copy link
Owner

@linegel linegel commented Mar 16, 2025

No description provided.

Evgenii Popov and others added 7 commits March 16, 2025 01:02
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      -               │
└─────────────────────────────────────────────────────────────────────────────────────────────┘
Copy link

Benchmark Comparison for nacl-fast.min.js

Raw Results (PR Branch)

yarn run v1.22.22
$ node test/benchmark/bench.js
crypto_stream_xor 1K                 95097 ops           0.01 ms/op    189795.13 ops/sec    185.35 MiB/s
crypto_onetimeauth 1K               129905 ops           0.00 ms/op    258965.13 ops/sec    252.90 MiB/s
crypto_secretbox 1K                  54017 ops           0.01 ms/op    107980.82 ops/sec    105.45 MiB/s
crypto_hash 1K                       20563 ops           0.02 ms/op     41035.86 ops/sec     40.07 MiB/s
crypto_hash 16K                       1505 ops           0.33 ms/op      3003.67 ops/sec     46.93 MiB/s
secretbox 1K                         41121 ops           0.01 ms/op     82027.86 ops/sec     80.11 MiB/s
secretbox.open 1K                    39761 ops           0.01 ms/op     79321.41 ops/sec     77.46 MiB/s
crypto_scalarmult_base                 794 ops           0.63 ms/op      1585.40 ops/sec                
box 1K                                 789 ops           0.63 ms/op      1576.52 ops/sec      1.54 MiB/s
box.open 1K                            811 ops           0.62 ms/op      1618.09 ops/sec      1.58 MiB/s
sign                                   399 ops           1.25 ms/op       797.99 ops/sec                
sign.open                              208 ops           2.41 ms/op       415.07 ops/sec                
Done in 6.15s.

Performance Delta (PR vs master)

Benchmark PR (ops/sec) Target (ops/sec) Change (%)
crypto_stream_xor 189795.13 189184.00 0.32% ⚪
crypto_onetimeauth 258965.13 257461.40 0.58% ⚪
crypto_secretbox 107980.82 110142.31 -1.96% ⚪
crypto_hash 3003.67 3021.74 -0.60% ⚪
secretbox 82027.86 84225.74 -2.61% ⚪
secretbox.open 79321.41 80054.22 -0.92% ⚪
crypto_scalarmult_base 1585.40 1622.48 -2.29% ⚪
box 1576.52 1588.51 -0.75% ⚪
box.open 1618.09 1619.66 -0.10% ⚪
sign 797.99 313.56 +154.49% 🟢
sign.open 415.07 162.65 +155.19% 🟢

Note: Changes within ±10% are considered neutral due to normal benchmark variation. This threshold aligns with common benchmarking practices in JavaScript engines and Node.js projects.

Copy link

Benchmark Comparison for nacl.js

Raw Results (PR Branch)

yarn run v1.22.22
$ node test/benchmark/bench.js
crypto_stream_xor 1K                 18520 ops           0.03 ms/op     37033.73 ops/sec     36.17 MiB/s
crypto_onetimeauth 1K                 9269 ops           0.05 ms/op     18483.62 ops/sec     18.05 MiB/s
crypto_secretbox 1K                   6369 ops           0.08 ms/op     12719.17 ops/sec     12.42 MiB/s
crypto_hash 1K                        3305 ops           0.15 ms/op      6593.05 ops/sec      6.44 MiB/s
crypto_hash 16K                        206 ops           2.43 ms/op       411.81 ops/sec      6.43 MiB/s
secretbox 1K                          5953 ops           0.08 ms/op     11898.62 ops/sec     11.62 MiB/s
secretbox.open 1K                     5681 ops           0.09 ms/op     11347.25 ops/sec     11.08 MiB/s
crypto_scalarmult_base                 129 ops           3.90 ms/op       256.58 ops/sec                
box 1K                                 123 ops           4.08 ms/op       245.32 ops/sec      0.24 MiB/s
box.open 1K                            128 ops           3.93 ms/op       254.33 ops/sec      0.25 MiB/s
sign                                    57 ops           8.91 ms/op       112.28 ops/sec                
sign.open                               27 ops          19.04 ms/op        52.51 ops/sec                
Done in 6.21s.

Performance Delta (PR vs master)

Benchmark PR (ops/sec) Target (ops/sec) Change (%)
crypto_stream_xor 37033.73 37414.17 -1.02% ⚪
crypto_onetimeauth 18483.62 18038.50 2.47% ⚪
crypto_secretbox 12719.17 12828.50 -0.85% ⚪
crypto_hash 411.81 435.39 -5.42% 🔴
secretbox 11898.62 11961.60 -0.53% ⚪
secretbox.open 11347.25 11520.10 -1.50% ⚪
crypto_scalarmult_base 256.58 258.68 -0.81% ⚪
box 245.32 250.73 -2.16% ⚪
box.open 254.33 255.39 -0.42% ⚪
sign 112.28 114.53 -1.96% ⚪
sign.open 52.51 57.21 -8.22% 🔴

Note: Changes within ±10% are considered neutral due to normal benchmark variation. This threshold aligns with common benchmarking practices in JavaScript engines and Node.js projects.

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.

1 participant