Skip to content

Can X25519/Ed25519 functions be possibly exposed for direct use? #5453

Closed

Description

Hello, I'd like to ask about the following functions from curve25519.c:

int ED25519_sign(uint8_t *out_sig, const uint8_t *message, size_t message_len,
		const uint8_t public_key[32], const uint8_t private_key[32]);
int ED25519_verify(const uint8_t *message, size_t message_len,
		const uint8_t signature[64], const uint8_t public_key[32]);
void ED25519_public_from_private(uint8_t out_public_key[32],
		const uint8_t private_key[32]);

int X25519(uint8_t out_shared_key[32], const uint8_t private_key[32],
		const uint8_t peer_public_value[32]);
void X25519_public_from_private(uint8_t out_public_value[32],
		const uint8_t private_key[32]);

Trying to get equivalent functionality over the binary data using only available OpenSSL API seems pretty hard or even impossible. I'm not very familiar with OpenSSL so I failed to figure it out. On the other hand, these functions are simple and obvious.

Activity

  1. richsalz commented on Feb 23, 2018

    @richsalz
    Contributor

    We understand, but our policy is that the EVP interface is the only one we are going to expose. Of course, you have the source and can do what you want.

  2. mattcaswell commented on Feb 23, 2018

    @mattcaswell
    Member

    I'm going to reopen this, because I think there may be some issues with the EVP interface to this, but I need time to investigate.

  3. mattcaswell commented on Feb 26, 2018

    @mattcaswell
    Member

    The difficulty with the X25519/Ed25519 EVP interface at the moment is that it is built for TLS use and not much else. This is mainly a problem when getting/setting private/public keys. You either have to generate a new key, or read it from a file in a recognised format (PKCS#8, or embedded in X509), or (in the case of public keys) know how to use some undocumented and TLS specific functions (EVP_PKEY_set1_tls_encodedpoint() and EVP_PKEY_get1_tls_encodedpoint()). You can't just say "here's my key, use that".

    My PR #5419 adds some functions which should make this easier. That PR is actually about adding X448/Ed448 support but co-incidentally adds some functions which should ease X25519/Ed25519. The basic process then will be:

    1. Create a new EVP_PKEY for the private/public key (using EVP_PKEY_new_priv_key() or EVP_PKEY_new_pub_key())

    2a) For signing use EVP_DigestSignInit() and EVP_DigestSign()

    2b) For verifying use EVP_DigestVerifyInit() and EVP_DigestVerify()

    2c) For key derivation use EVP_PKEY_derive_init(). Set the peer key using EVP_PKEY_derive_set_peer() and then EVP_PKEY_derive().

    You might also find the overview documentation relevant:
    https://www.openssl.org/docs/manmaster/man7/Ed25519.html
    https://www.openssl.org/docs/manmaster/man7/X25519.html

  4. mattcaswell commented on Mar 20, 2018

    @mattcaswell
    Member

    #5520 eventually got merged which makes using X25519/Ed25519 via EVP considerably easier. Closing this.

  5. aep commented on Feb 7, 2022

    @aep

    doesn't look like there's an EVP equivalent to ED25519_public_from_private yet?

  6. t8m commented on Feb 7, 2022

    @t8m
    Member

    doesn't look like there's an EVP equivalent to ED25519_public_from_private yet?

    If you create a new EVP_PKEY via EVP_PKEY_fromdata with just setting the private key, the resulting key will have the public key calculated during the import. So you can then get the public key value via EVP_PKEY_get_BN_param().

  7. mattcaswell commented on Feb 8, 2022

    @mattcaswell
    Member

    If you create a new EVP_PKEY via EVP_PKEY_fromdata with just setting the private key, the resulting key will have the public key calculated during the import. So you can then get the public key value via EVP_PKEY_get_BN_param().

    Easier is to create the EVP_PKEY using EVP_PKEY_new_raw_private_key_ex(). The public key is actually an octet string so you actually have to use EVP_PKEY_get_octet_string_param(). E.g. something like this:

        EVP_PKEY *our_pkey = EVP_PKEY_new_raw_private_key_ex(NULL, "X25519", NULL,
                                                             priv_key, 32);
        size_t outlen = 0;
        unsigned char pub_key[32];
    
        if (!EVP_PKEY_get_octet_string_param(pkey, OSSL_PKEY_PARAM_PUB_KEY, pub_key, 32, &outlen))
            goto err;
    
  8. mattcaswell commented on Feb 8, 2022

    @mattcaswell
    Member

    Oh...sorry...you said Ed25519 and my example was X25519. Same concept applies though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions