Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Curve25519 PublicKeys conform to Hashable #175

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

Sajjon
Copy link
Contributor

@Sajjon Sajjon commented Apr 18, 2023

Make Curve25519 PublicKeys conform to Hashable

N.B. Merge open PR #173 first (or if #173 is closed, close this one too), since this PR builds on top of that.

Checklist

  • I've run tests to see all new and existing tests pass
  • I've followed the code style of the rest of the project
  • I've read the Contribution Guidelines
  • 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:

PublicKey's are fundamental building blocks within EC-oriented code bases. They can act as a natural key in Dictionaries and otherwise important property of larger structs, which us developers often would like to make Hashable. Today, Curve25519 public keys prevent auto-synthesis of Hashable for any structs they are members of, thus Curve25519 keys ought to be Hashable!

This poses no security risk nor any performance downgrade.

This PR is an addition of open PR #173.

Modifications:

Curve25519.KeyAgreement.PublicKey and Curve25519.Signing.PublicKey have been made Hashable and unit tests have been added.

Result:

Curve25519.KeyAgreement.PublicKey and Curve25519.Signing.PublicKey are now Hashable

return try self.baseKey.keyBytes.withUnsafeBytes(body)
}

public static func ==(lhs: Self, rhs: Self) -> Bool {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Part of #173 but I was unable to create a diff between just this PR and #173 since my branch is in a fork, otherwise I would have created this PR with the branch curve25519_publickeys_equatable as the target branch, so that we could have seen only the relevant diff.

@@ -54,6 +54,14 @@ extension Curve25519 {
private func withUnsafeBytes<R>(_ body: (UnsafeRawBufferPointer) throws -> R) rethrows -> R {
return try self.baseKey.keyBytes.withUnsafeBytes(body)
}

public static func ==(lhs: Self, rhs: Self) -> Bool {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Part of #173 but I was unable to create a diff between just this PR and #173 since my branch is in a fork, otherwise I would have created this PR with the branch curve25519_publickeys_equatable as the target branch, so that we could have seen only the relevant diff.

@@ -75,4 +75,54 @@ class EdDSATests: XCTestCase {
// This signature should be invalid
XCTAssertFalse(privateKey.publicKey.isValidSignature(DispatchData.empty, for: DispatchData.empty))
}

func testCurve25519SigningPublicKeyEquatable() throws {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Part of #173 but I was unable to create a diff between just this PR and #173 since my branch is in a fork, otherwise I would have created this PR with the branch curve25519_publickeys_equatable as the target branch, so that we could have seen only the relevant diff.

Curve25519.Signing.PrivateKey().publicKey
)
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Part of #173 but I was unable to create a diff between just this PR and #173 since my branch is in a fork, otherwise I would have created this PR with the branch curve25519_publickeys_equatable as the target branch, so that we could have seen only the relevant diff.

Copy link
Contributor

@Lukasa Lukasa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delaying for future release of CryptoKit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants