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

Add x25519 AKE test vectors #404

Merged
merged 15 commits into from
May 22, 2023
Merged

Add x25519 AKE test vectors #404

merged 15 commits into from
May 22, 2023

Conversation

chris-wood
Copy link
Collaborator

@chris-wood chris-wood commented Mar 21, 2023

This did introduce some editorial changes to accommodate the x25519 AKE, but I don't think they're unreasonable. The actual reference implementation needs to be cleaned up somewhat, but I think we can at least use this to test for interop for the time being. I'll work on cleaning up the code in a bit, so, starting as a draft now.

Closes #238

cc @daxpedda

@stef
Copy link
Contributor

stef commented Mar 21, 2023

lgtm. thank you for this effort!

@daxpedda
Copy link
Contributor

That's pretty amazing @chris-wood! 🎉

Gonna report back as soon as I figure out why I couldn't make them work in opaque-ke.

@armfazh
Copy link
Contributor

armfazh commented Mar 21, 2023

just to be clear, this effort is about
a) instantiating a 3DH with X25519 (a.k.a RFC7748), or
b) using the prime subgroup of Curve25519, (just like the NIST PXXX curves).
or something else?

Comment on lines 1442 to 1444
- DeriveAuthKeyPair(seed): This function is implemented by returning the private
key `k` based on seed (of length `Nseed = 32` bytes), as described in {{Section 5 of Curve25519}},
as well as the result of ScalarMult(k, B), where B is the base point of Curve25519.
Copy link
Contributor

Choose a reason for hiding this comment

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

Why does this differ from the other groups?
Because OPRF doesn't specify a ciphersuite for Curve25519?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, exactly.

Copy link
Contributor

Choose a reason for hiding this comment

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

After consulting the spec again, I couldn't really find an answer to this. Doesn't removing the G.HashToScalar have any security implications at all?
And if not, why is it in place for the other ciphersuites?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not sure I understand the question. But to try and reiterate, there was no existing function in the OPRF document we could point to, which is why we just lean on standard key generation for curve25519 -- treat random bytes as the key (scalar).

Copy link
Contributor

@daxpedda daxpedda Mar 25, 2023

Choose a reason for hiding this comment

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

Ah, sorry, I can see how my question is confusing. So in opaque-ke we were using OPRF with a custom ciphersuite when chossing Curve25519, which was possible because the hash2curve specification does provide a ciphersuite for Curve25519.

So my question is: the other ciphersuites do use OPRF to derive a key pair in DeriveAuthKeyPair. So why do other ciphersuites need that but Curve25519 doesn't? I thought it was necessary for security reasons (that I have no clue about).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh, I see! You're asking if it's necessary to map the input seed to a scalar using something like a random oracle? I don't think it's necessary, but I actually don't know the answer off the top of my head. I think this should probably be asked on the list (I can do that).

Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you!

@daxpedda
Copy link
Contributor

0253cbb updated the draft-irtf-cfrg-opaque.md but not the other files, I am assuming the new ones are correct?

@chris-wood
Copy link
Collaborator Author

just to be clear, this effort is about

a) instantiating a 3DH with X25519 (a.k.a RFC7748), or

b) using the prime subgroup of Curve25519, (just like the NIST PXXX curves).

or something else?

@armfazh it's about option (a) =)

@chris-wood
Copy link
Collaborator Author

0253cbb updated the draft-irtf-cfrg-opaque.md but not the other files, I am assuming the new ones are correct?

@daxpedda I added clamping and updated the vectors in the latest commit.

@kevinlewi, @daxpedda: I'm going to promote this draft to a real PR now. I think it's ready to go.

@chris-wood chris-wood marked this pull request as ready for review March 23, 2023 15:30
@chris-wood
Copy link
Collaborator Author

@bytemare can you please take another look?

def create_cleartext_credentials(self, server_public_key, client_public_key, server_identity, client_identity):
def derive_auth_key_pair(self, seed):
if self.config.group.name == "x25519":
return seed, self.config.group.scalar_mult(seed, self.config.group.generator())
Copy link
Collaborator

Choose a reason for hiding this comment

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

@chris-wood Additionally, I believe we need to make sure that seed is clamped here, before using it. Otherwise, the private key that we generate will not be clamped (since it just equal to the seed).

KSF: Identity
KDF: HKDF-SHA512
MAC: HMAC-SHA512
Group: x25519
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should say Group: curve25519

Copy link
Collaborator

@kevinlewi kevinlewi left a comment

Choose a reason for hiding this comment

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

Based on above comments. Maybe it would be helpful to add a test to check that all private keys / scalars that we publish in the test vectors are actually clamped?

@kevinlewi
Copy link
Collaborator

kevinlewi commented May 21, 2023

Spec changes:

  • Renamed "ScalarMult(k, B)" to "DiffieHellman(k, B)" to more accurately reflect that we are doing a DH operation in the places where it is mentioned in the spec
  • Renamed the group's display name from "x25519" to "curve25519" in the test vectors
  • Synced latest test vectors into spec

Sage POC code changes:

  • Fixed clamping issue
  • Added test to ensure that private key outputs for curve25519 are always clamped
  • Added back client_public_keyshare into the inputs for each test vector (was mistakenly removed in Add x25519 AKE test vectors #404)

@kevinlewi kevinlewi mentioned this pull request May 21, 2023
@kevinlewi kevinlewi requested a review from bytemare May 22, 2023 00:33
Copy link
Collaborator

@kevinlewi kevinlewi left a comment

Choose a reason for hiding this comment

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

This is approved by me in case it wasn't clear :P

@chris-wood chris-wood merged commit 727b9ac into master May 22, 2023
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.

Curve25519 support
6 participants