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

请问 TLS_SM4_GCM_SM3 模式下,X25519交换得到的密钥是32字节,怎么转换为SM4的密钥? #17

Open
is-xuwei opened this issue May 15, 2023 · 2 comments

Comments

@is-xuwei
Copy link

使用wireshark抓TLSv1.3 TLS_SM4_GCM_SM3 的包,里面很多Encrypted Application Data 密文;

我现在已经拿到X25519交换得到的密钥(例如d8879229fb7f0000f0d89c010000000002000000000000003b01000000000000)了,对称加密使用的是SM4_GCM是吗?32字节密钥需要怎么转化呢?

@zzl360
Copy link

zzl360 commented May 18, 2023

我理解无论是sm2dhe还是X25519协商出来的密钥其实都是裸数据,可以用于sm4也可以用于aes等算法的密钥。因为加密套件里只规定了对称加密和hash的算法, 并没有规定具体用什么算法协商密钥。而在tls1.3中,是使用tls扩展的机制协商出来的密钥。
至于解密,可以参考https://openanolis.github.io/whitebook-shangmi/wireshark.html

@yanshichao0226
Copy link
Contributor

yanshichao0226 commented May 23, 2023

工作密钥产生流程:

  1. 密钥协商产生<预主密钥-pre_masterkey>
  2. <预主密钥-pre_masterkey>和其它参数经过密钥推导得到<主密钥-masterkey>
  3. <主密钥-masterkey>和其它参数经过推导得到<工作密钥-key_block>

所以x25519协商产生的是<预主密钥-pre_masterkey>,SM4密钥则包含在<工作密钥-key_block>中。中间还要经过两次密钥推导,密钥推导函数可以根据算法套件来确定需要推导的密钥长度

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

3 participants