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

EVP_PKEY_get_octet_string_param returns compressed SM2 public key #656

Open
johnshajiang opened this issue Oct 9, 2024 · 2 comments
Open

Comments

@johnshajiang
Copy link

johnshajiang commented Oct 9, 2024

使用EVP_PKEY_keygen生成了SM2密钥对EVP_PKEY,然后使用接口EVP_PKEY_get_octet_string_param获取公钥,

EVP_PKEY_get_octet_string_param(pkey, OSSL_PKEY_PARAM_PUB_KEY, pub_key_buf, pub_key_len, &pub_key_len)

Tongsuo返回的公钥是压缩格式的,即以0x020x03开头,长度仅为33个字节,如下所示,

0375c05a9371f2ced4573fb2cfd10a36c00294f34582bcba257817b973902a81c5
02c1be22935ed71a406e2b1b3e5f163582e016fc58e7e676b0fdadd215457ead67

但这与原生OpenSSL中该接口返回的格式不兼容。OpenSSL生成的是非压缩格式的公钥,即以0x04开头,长度为65个字节,如下所示,

04cccbcb22ad97a0749dd8d597108b862c48a58c290bf643d9c884d3e59096fa34d66847fa5f4790a767546e148fc769daf213e24ac57e58e9b8e033bce2932d05
04c7e35918cd835e2aba73bd2f7a76f3330420bcea577b64c4847125844a82495c236e054b80dc183d51672986ace8b1e153c3619cab3863d8d54caa69ccef293b
@johnshajiang
Copy link
Author

我测试时用的是Tongsuo 8.4.0和OpenSSL 3.3.2。

@johnshajiang
Copy link
Author

奇怪的是,在macOS aarch64(M3)平台上测试时,没有遇到这个问题。
在该平台上,Tongsuo也是生成的非压缩格式的公钥。

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

No branches or pull requests

1 participant