terl / lazysodium-java

A Java implementation of the Libsodium crypto library. For the lazy dev.
https://github.com/terl/lazysodium-java/wiki
Mozilla Public License 2.0
134 stars 46 forks source link

cryptoScalarMult takes inputs in the wrong order #129

Open timmc opened 10 months ago

timmc commented 10 months ago

DiffieHellman.Lazy.cryptoScalarMult accepts parameters named publicKey, secretKey, but the underlying implementation expects the secret key first. If you use the documented argument order, key agreement doesn't work.

https://github.com/terl/lazysodium-java/blob/64dc78554f45eb9b81e74354d61eba4e3da2452b/src/main/java/com/goterl/lazysodium/interfaces/DiffieHellman.java#L49

timmc commented 10 months ago

Relatedly, it also might be wise to create subclasses of Key with names like SodiumBoxPublicKey. Even if the method is documented correctly, having everything be called Key makes it easy for a caller to mess up. (I'd be happy to submit a PR for this, as I've done something similar in my own use of lazysodium.)