-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Replace ring with ed25519-dalek in primitives #2415
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use ed25519-dalek
only when targeting wasm? I suspect that ring
is faster, though I don’t have benchmarks. ring
also is more likely to resist side-channel attacks.
I could do that if that's the general feeling. |
I pushed another commit that does that. |
It appears ring choose optimizations dynamically at runtime, which likely makes achieving good performance easier, while all dalek ecosystem crates including schnorrkel require compile time parameters for 64 bit architectures, AVX2, etc. There are some benchmarks in https://lib.rs/crates/ed25519-dalek but ed25519 benchmarks do not yet exist in https://github.com/briansmith/crypto-bench and thus dalek does not appear there. We should also switch to batch verification eventually, which ring does not support but should boost performance by like 40%. |
That can (and should) be added to ring. |
d028013
to
49016e8
Compare
After some discussion in the |
I took the time to write some benchmarks. With ring:
With ed25519-dalek:
|
I added multiple payload sizes. With ring:
With ed25519-dalek (compared to ring):
|
I suspect the hashing impacts this significantly for either ring or dalek to reach those signing times. It appears ring does not support the ed25519 prehashed variants, but if larger messages are first hashed with blake2s then we'd see more the actual signing times. It's maybe work adding a 32 byte variant to these benchmarks. Also, I'm afraid schnorrkel's |
That's what I did! Signing 32 bytes: 25.124us (dalek) vs 23.624us (ring) As you mention, for the other lengths I'm probably benchmarking the hashing function more than the signing/verifying. @folsen's opinion is basically that we should merge that, and if any performance issue arises, then fix them. But let's not pre-occupy ourselves with performances too much at this time. I agree with that. |
Oops I missed that, thanks! Yes, we can optimize later since we already know the target performance numbers. If dalek saves you some dev time with WASM then just use it. :) |
Also, we should mark our two big performance TODOs as being:
|
I'll summarize the situation as I understand it: I have not quite understood if/when WASM invokes native signature verification code, but if we need ed25519 implemented in WASM, TEEs, etc. then ed25519-dalek works better for the foreseeable future. We expect some traits for ed25519 signatures to emerge based on dalek-cryptography/ed25519-dalek#80 which might improve HSM support for many projects, although our lives sound more complex there. Right now, ring has a faster sha2 than the sha2 crate used by ed25519-dalek (RustCrypto project). Ideally, one might simply fix the sha2 crate, but maybe their traits create the issue, ala NRVO or whatever. It's clear one could substitute an ed25519-crate with the sha2 manually replaced throughout though, dramatically reducing the performance difference. We do not care much if everything gets hashed by bake2b first anyways. Also, curve25519-dalek has Pippenger multiscalar multiplication dalek-cryptography/curve25519-dalek#129 dalek-cryptography/curve25519-dalek#249 which improves large batch verifications dramatically, but realistically ring will never adopt Pippenger, and likely never implement bath verification. |
Contrary to
ring
,ed25519-dalek
successfully compiles to WASM.The changes are pretty straight-forward, but I'd understand if this gets rejected if ed25519-dalek is not considered mature enough.
cc #2416