Exemple #1
0
    def from_private_bytes(cls, data):
        from cryptography.hazmat.backends.openssl.backend import backend
        if not backend.x25519_supported():
            raise UnsupportedAlgorithm(
                "X25519 is not supported by this version of OpenSSL.",
                _Reasons.UNSUPPORTED_EXCHANGE_ALGORITHM)

        return backend.x25519_load_private_bytes(data)
Exemple #2
0
    def from_private_bytes(cls, data):
        from cryptography.hazmat.backends.openssl.backend import backend
        if not backend.x25519_supported():
            raise UnsupportedAlgorithm(
                "X25519 is not supported by this version of OpenSSL.",
                _Reasons.UNSUPPORTED_EXCHANGE_ALGORITHM
            )

        return backend.x25519_load_private_bytes(data)
Exemple #3
0
def sk_to_curve25519(ed: ed25519.Ed25519PrivateKey) -> x25519.X25519PrivateKey:
    raw = ed.private_bytes(
        encoding=serialization.Encoding.Raw,
        format=serialization.PrivateFormat.Raw,
        encryption_algorithm=serialization.NoEncryption(),
    )

    # as proposed in https://github.com/pyca/cryptography/issues/5557#issuecomment-739339132

    from cryptography.hazmat.primitives import hashes
    from cryptography.hazmat.backends.openssl.backend import backend

    hasher = hashes.Hash(hashes.SHA512())
    hasher.update(raw)
    h = bytearray(hasher.finalize())
    # curve25519 clamping
    h[0] &= 248
    h[31] &= 127
    h[31] |= 64

    return backend.x25519_load_private_bytes(h[0:32])
Exemple #4
0
 def _from_private_bytes(cls, data):
     from cryptography.hazmat.backends.openssl.backend import backend
     return backend.x25519_load_private_bytes(data)
Exemple #5
0
 def _from_private_bytes(cls, data):
     from cryptography.hazmat.backends.openssl.backend import backend
     return backend.x25519_load_private_bytes(data)