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

sm2: encryption support ASN.1 encoding format #9

Closed
emmansun opened this issue Dec 2, 2021 · 2 comments
Closed

sm2: encryption support ASN.1 encoding format #9

emmansun opened this issue Dec 2, 2021 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@emmansun
Copy link
Owner

emmansun commented Dec 2, 2021

HUAWEI Cloud KMS (DEW) sm2 encryption result is ASN.1 encoding fomat.

密文编码问题

SM2密文由C1、C2、C3三部分构成,如何对SM2密文进行编码在已经公布的两个标准中有所不同,在早期公布的《SM2椭圆曲线公钥密码算法 第4部分:公钥加密算法》中,SM2密文中的三部分依次输出,没有采用如Tag-Length-Value形式的编码,我们称其为Plain编码。在之后公布的GM/T国标中,SM2密文采用ASN.1/DER方式编码。

GmSSL通过SM2_CIPHERTEXT_VALUE对象来表示密文数据结构,函数SM2_do_encrypt()和SM2_do_decrypt()可以生成SM2_CIPHERTEXT_VALUE对象及对其解密,函数SM2_CIPHERTEXT_VALUE_encode()和SM2_CIPHERTEXT_VALUE_decode()实现该对象的Plain编解码。GmSSL预计还会通过函数i2d_SM2_CIPHERTEXT_VALUE()和d2i_SM2_CIPHERTEXT_VALUE()实现该密文对象的ASN.1/DER编解码,以支持最新的GM/T国密标准。

GmSSL的SM2_encrypt()和SM2_decrypt()在加解密的同时也完成SM2_CIPHERTEXT_VALUE对象的编解码。目前采用Plain编解码,在相应功能完成后会替换为ASN.1/DER编码方案。

@emmansun emmansun added the enhancement New feature or request label Dec 2, 2021
@emmansun emmansun self-assigned this Dec 2, 2021
@emmansun
Copy link
Owner Author

emmansun commented Dec 2, 2021

“在之后公布的GM/T国标中,SM2密文采用ASN.1/DER方式编码。”, 其实我也没找到相应标准,只是华为云KMS也采用这个编码。

@emmansun
Copy link
Owner Author

emmansun commented Dec 3, 2021

include in v0.7.0

@emmansun emmansun closed this as completed Dec 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant