CodesInChaos / Chaos.NaCl

Chaos.NaCl cryptography library
Other
131 stars 54 forks source link

Ed25519 KeyExchange performance improvement #12

Open mishamosher opened 8 years ago

mishamosher commented 8 years ago

The method KeyExchange(ArraySegment<byte>, ArraySegment<byte>, ArraySegment<byte>) defined in the file Chaos.NaCl/Ed25519.cs performs an unnecessary ScalarOperations.sc_clamp(byte[], int) operation (link with details: Chaos.NaCl/Ed25519.cs on Line 140).

This is beacuse the following line calls MontgomeryOperations.scalarmult(out sharedMontgomeryX, h, 0, ref montgomeryX), which in turn will end calling the very same sc_clamp operation on Chaos.NaCl/Internal/Ed25519Ref10/scalarmult.cs on Line 39.

Simple fix (for a very small performance gain) is to simply remove the unnecessary ScalarOperations.sc_clamp(byte[], int) operation. Already tested and KeyExchange keeps working as expected after removing Chaos.NaCl/Ed25519.cs on Line 140).