Giter Site home page Giter Site logo

SM9密文顺序问题 about gmalg HOT 8 CLOSED

entarohydralisk avatar entarohydralisk commented on July 29, 2024
SM9密文顺序问题

from gmalg.

Comments (8)

ww-rm avatar ww-rm commented on July 29, 2024

最终的密文构造是按 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)

return bytes(cipher)

from gmalg.

entarohydralisk avatar entarohydralisk commented on July 29, 2024

图片
解密测试C3验不过,去掉04也一样

from gmalg.

entarohydralisk avatar entarohydralisk commented on July 29, 2024

图片
我用另一个算法验证工具产生的加密数据,拿来解密,也解不了

from gmalg.

ww-rm avatar ww-rm commented on July 29, 2024

图片 解密测试C3验不过,去掉04也一样

这个是仅仅MAC验证失败,但是明文解密出来了吗?

from gmalg.

entarohydralisk avatar entarohydralisk commented on July 29, 2024

两个工具都解不出来,MAC是保证完整性的,MAC验不过,解密过程不会发生。

from gmalg.

ww-rm avatar ww-rm commented on July 29, 2024

方便提供一下你使用的两个验证工具吗?

两个工具都解不出来,MAC是保证完整性的,MAC验不过,解密过程不会发生。

不过完整性校验发生在解密之后,不知道验证工具是否给出了解密后的明文,再提示MAC校验失败,这样我可以排查是密文算错了还是单独MAC算错了

另外你安装的版本是最新的吗?

from gmalg.

entarohydralisk avatar entarohydralisk commented on July 29, 2024

https://github.com/zweib730/SM9-misc
https://www.alipan.com/s/JFwwpTh6vQr
我用的最新的1.05版本

from gmalg.

ww-rm avatar ww-rm commented on July 29, 2024

两个工具我都测试了没问题,应该是数据格式的问题

“”算法测试工具——Yaoyuan“都不需要PC字节(主公钥、密文、用户私钥),

”SM9算法验证工具“的密文不能有PC标识字节,并且只需要提供主私钥,并没有用到主公钥和加密私钥(乱填都能解密,因此格式未知)

你可以再试试,应该都是前面那个”04“字节导致的问题,有时候需要有时候不需要,但是 gmalg 里面凡是涉及椭圆曲线点转成字节串的地方都需要PC标识字节。

from gmalg.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.