python类HashContext()的实例源码

cryptography.py 文件源码 项目:python-otr 作者: AGProjects 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def sign(self, data, hash_context):
        if not isinstance(hash_context, hashes.HashContext):
            raise TypeError("hash_context must be an instance of hashes.HashContext.")
        signer = self._key.signer(hashes.SHA256())
        signer._hash_ctx = hash_context
        signer.update(data)
        r, s = decode_dss_signature(signer.finalize())
        # return long_to_bytes(r, 20) + long_to_bytes(s, 20)
        size = self.private_numbers.public_numbers.parameter_numbers.q.bit_length() // 8
        return long_to_bytes(r, size) + long_to_bytes(s, size)
cryptography.py 文件源码 项目:python-otr 作者: AGProjects 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def verify(self, signature, data, hash_context):
        if not isinstance(hash_context, hashes.HashContext):
            raise TypeError("hash_context must be an instance of hashes.HashContext.")
        size = self.public_numbers.parameter_numbers.q.bit_length() // 8
        r, s = (bytes_to_long(value) for value in read_content(signature, '{0}s{0}s'.format(size)))
        # r, s = (bytes_to_long(value) for value in read_content(signature, '20s20s'))
        verifier = self._key.verifier(encode_dss_signature(r, s), hashes.SHA256())
        verifier._hash_ctx = hash_context
        verifier.update(data)
        try:
            verifier.verify()
        except InvalidSignature:
            raise ValueError("invalid signature")


问题


面经


文章

微信
公众号

扫码关注公众号