swift-crypto icon indicating copy to clipboard operation
swift-crypto copied to clipboard

Make Curve25519 `PublicKey`s conform to `Equatable`

Open Sajjon opened this issue 2 years ago • 0 comments

Make Curve25519 PublicKeys conform to Equatable

Checklist

  • [x] I've run tests to see all new and existing tests pass
  • [x] I've followed the code style of the rest of the project
  • [x] I've read the Contribution Guidelines
  • [x] I've updated the documentation if necessary

If you've made changes to gyb files

  • [ ] I've run .script/generate_boilerplate_files_with_gyb and included updated generated files in a commit of this pull request

Motivation:

When PublicKey's are used in struct's that are marked Equatable those structs cannot be auto-synthetized conform to Equatable since these PublicKeys before this PR do not conform to Equatable. This is rather annoying. And during the 5 years I've been working in the crypto industry I have added my own conformance to CryptoKit's PublicKeys to be Equatable probably more than 10 times!

There exists no security risk in making PublicKeys conform to Equatable, the current implementation does not use safeCompare, it could, but I deem it not necessary.

There is really no drawback in adding Equatable conformance.

Modifications:

  1. Make Curve25519.Signing.PublicKey be Equatable
  2. Make Curve25519.KeyAgreement.PublicKey be Equatable
  3. Add tests for these.

Result:

Curve25519.Signing.PublicKey and Curve25519.KeyAgreement.PublicKey now conform to Equatable.

Sajjon avatar Apr 14 '23 12:04 Sajjon