apple / swift-crypto

Open-source implementation of a substantial portion of the API of Apple CryptoKit suitable for use on Linux platforms.
https://apple.github.io/swift-crypto
Apache License 2.0
1.45k stars 157 forks source link

Make Curve25519 `PublicKey`s conform to `Equatable` #173

Open Sajjon opened 1 year ago

Sajjon commented 1 year ago

Make Curve25519 PublicKeys conform to Equatable

Checklist

If you've made changes to gyb files

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.