简体   繁体   English

如何使用25519打开SSL 1.1.1 ECDH

[英]how to openSSL 1.1.1 ECDH with 25519

i need to implement ecdh with 25519 using openssl. 我需要使用openssl用25519实现ecdh。

using: 使用:

key = EC_KEY_new_by_curve_name(NID_X25519)

fails. 失败。

using this: 使用这个:

EVP_PKEY *pkey = NULL;
EVP_PKEY_CTX *pctx = EVP_PKEY_CTX_new_id(NID_X25519, NULL);
EVP_PKEY_keygen_init(pctx);
EVP_PKEY_keygen(pctx, &pkey);

seems to work but i have no idea how to export the public key in uncompressed bin format. 似乎有效,但我不知道如何以未压缩的bin格式导出公钥。 or how to import the other sides public key. 或如何导入对方的公共密钥。

any help? 有什么帮助吗?

Importing the other side's public key from raw binary format can be done with the EVP_PKEY_new_raw_public_key() function. 可以使用EVP_PKEY_new_raw_public_key()函数从原始二进制格式导入另一方的公钥。 Man page here: 手册页在这里:

https://www.openssl.org/docs/man1.1.1/man3/EVP_PKEY_new_raw_public_key.html https://www.openssl.org/docs/man1.1.1/man3/EVP_PKEY_new_raw_public_key.html

Exporting the public key in raw binary format is a little more tricky since there is no function to do it. 以原始二进制格式导出公钥会有些棘手,因为没有函数可以执行此操作。 You can do it in SubjectPublicKeyInfo format using i2d_PUBKEY() described here: 您可以使用此处描述的i2d_PUBKEY()以SubjectPublicKeyInfo格式进行操作:

https://www.openssl.org/docs/man1.1.1/man3/i2d_PUBKEY.html https://www.openssl.org/docs/man1.1.1/man3/i2d_PUBKEY.html

Fortunately the SubjectPublicKeyInfo format has the raw public key as the last 32 bytes of its output. 幸运的是,SubjectPublicKeyInfo格式具有原始公钥作为其输出的最后32个字节。 So you can use i2d_PUBKEY() and just use the last the 32 bytes. 因此,您可以使用i2d_PUBKEY()并仅使用最后32个字节。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM