Exemplo n.º 1
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'))
     hash_context.update(data)
     digest = hash_context.finalize()
     try:
         self._key.verify(encode_dss_signature(r, s), digest, Prehashed(SHA256HMAC160()))
     except InvalidSignature:
         raise ValueError("invalid signature")
Exemplo n.º 2
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")
Exemplo n.º 3
0
 def _decode_numbers(cls, encoded_numbers):
     p, q, g, y = read_content(encoded_numbers, MPI, MPI, MPI, MPI)
     public_numbers = dsa.DSAPublicNumbers(y, dsa.DSAParameterNumbers(p, q, g))
     return public_numbers.public_key(cls.__backend__)
Exemplo n.º 4
0
 def _decode_numbers(cls, encoded_numbers):
     p, q, g, y = read_content(encoded_numbers, MPI, MPI, MPI, MPI)
     public_numbers = dsa.DSAPublicNumbers(y, dsa.DSAParameterNumbers(p, q, g))
     return public_numbers.public_key(cls.__backend__)