-
Notifications
You must be signed in to change notification settings - Fork 1
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
SM9密文顺序问题 #4
Comments
最终的密文构造是按 C1,C3,C2顺序返回的 def encrypt(self, plain: bytes, uid: bytes) -> bytes:
"""Encrypt.
Args:
plain: Plain data.
uid: ID of another user.
Returns:
bytes: Cipher data.
Raises:
RequireArgumentError: Missing some required arguments.
"""
if not self.can_encrypt:
raise RequireArgumentError("encrypt", "hid_e", "mpk_e", "mac_klen")
C1, C2, C3 = self._core.encrypt(self._hid_e, self._mpk_e, plain, uid, self._mac_klen)
cipher = bytearray()
cipher.extend(point_to_bytes_1(C1, self._pc_mode))
cipher.extend(C3)
cipher.extend(C2)
return bytes(cipher) Line 981 in eb537b2
|
两个工具都解不出来,MAC是保证完整性的,MAC验不过,解密过程不会发生。 |
方便提供一下你使用的两个验证工具吗?
不过完整性校验发生在解密之后,不知道验证工具是否给出了解密后的明文,再提示MAC校验失败,这样我可以排查是密文算错了还是单独MAC算错了 另外你安装的版本是最新的吗? |
两个工具我都测试了没问题,应该是数据格式的问题 “”算法测试工具——Yaoyuan“都不需要PC字节(主公钥、密文、用户私钥), ”SM9算法验证工具“的密文不能有PC标识字节,并且只需要提供主私钥,并没有用到主公钥和加密私钥(乱填都能解密,因此格式未知) 你可以再试试,应该都是前面那个”04“字节导致的问题,有时候需要有时候不需要,但是 gmalg 里面凡是涉及椭圆曲线点转成字节串的地方都需要PC标识字节。 |
我看代码里面return的是C1, C2, C3,C2是不定长的,放在中间无法校验密文的合法性。
The text was updated successfully, but these errors were encountered: