Skip to content

X25519 Support - #3686

Merged
alex merged 19 commits into
pyca:masterfrom
reaperhulk:x25519
Jun 9, 2017
Merged

alex merged 19 commits into
pyca:masterfrom
reaperhulk:x25519

Conversation

@reaperhulk

@reaperhulk reaperhulk commented Jun 6, 2017 •

Copy link
Copy Markdown
Member

depends on #3685 and #3684 and fixes #3590


:returns: :class:`X25519PublicKey`

.. method:: private_bytes()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I thought we agreed that private_bytes wasn't needed?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We did! And everywhere but the docs I removed it. Missed this one!

@reaperhulk reaperhulk changed the title [WIP] X25519 Support X25519 Support Jun 8, 2017

.. versionadded:: 2.0

.. classmethod:: from_public_bytes(data)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's add an example of generating a private key, and then round tripping its public key.

Comment thread src/cryptography/exceptions.py Outdated
UNSUPPORTED_X509 = 8
UNSUPPORTED_EXCHANGE_ALGORITHM = 9
UNSUPPORTED_DIFFIE_HELLMAN = 10
UNSUPPORTED_X25519 = 11

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why not just use one of the two existing relevant reasons?

# This is the standard PKCS8 prefix for a 32 byte X25519 key.
# The form is:
# (SEQUENCE INTEGER ALGORITHMIDENTIFIER OCTETSTRING)
pkcs8_prefix = b'0.\x02\x01\x000\x05\x06\x03+en\x04"\x04 '

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This could probably use a longer comment, expanding on the ASN.1 parsing. Not everyone likes to parse it by hand (although I did)

Comment thread tests/hazmat/primitives/test_x25519.py Outdated
]
)
def test_public_bytes(self, private_bytes, public_bytes, backend):
private_key = X25519PrivateKey._from_private_bytes(private_bytes)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

overindent

Comment thread tests/hazmat/primitives/test_x25519.py Outdated
b"8520f0098930a754748b7ddcb43ef75a0dbf3a0d26381af4eba4a98"
b"eaa9b4e6a"
)
],

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should be a tuple.

@evilaliv3

Copy link
Copy Markdown
Contributor

@reaperhulk: is there a reason why it was not designed the API for serializing private bytes?

Is there any internal that helps in case this is needed?

@reaperhulk

Copy link
Copy Markdown
Member Author

@evilaliv3 #4386 exists to track that issue. If you wouldn't mind writing up your use case that will help us when deciding how to prioritize our dev efforts.

@evilaliv3

evilaliv3 commented Aug 28, 2018 via email

Copy link
Copy Markdown
Contributor

@reaperhulk

Copy link
Copy Markdown
Member Author

Presumably they're using X25519 for ECIES encryption since that's a DH kex? X25519 is explicitly specified for key exchange, which is why we have it exposed in that fashion. People using it to build ECIES constructions is an interesting use case and provides some form of rationale for having non-ephemeral keys.

If you could put this info on #4386 that would be helpful, thanks.

@evilaliv3

evilaliv3 commented Aug 28, 2018 via email

Copy link
Copy Markdown
Contributor

@reaperhulk

Copy link
Copy Markdown
Member Author

There's no way to export right now without using the C bindings themselves unfortunately. You'd need to use i2d_PKCS8PrivateKey_bio or PEM_write_bio_PKCS8PrivateKey.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Aug 7, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Development

Successfully merging this pull request may close these issues.

X25519 support

3 participants