def ecdsa_verify(message: bytes, signature: bytes, pubkey: UmbralPublicKey ) -> bool: """ Accepts a message and signature and verifies it with the provided public key. :param message: Message to verify :param signature: Signature to verify :param pubkey: UmbralPublicKey to verify signature with :return: True if valid, False if invalid. """ cryptography_pub_key = pubkey.to_cryptography_pubkey() try: cryptography_pub_key.verify( signature, message, ec.ECDSA(BLAKE2B) ) except InvalidSignature: return False return True
def verify(self, message: bytes, verifying_key: UmbralPublicKey, is_prehashed: bool = False) -> bool: """ Verifies that a message's signature was valid. :param message: The message to verify :param verifying_key: UmbralPublicKey of the signer :param is_prehashed: True if the message has been prehashed previously :return: True if valid, False if invalid """ cryptography_pub_key = verifying_key.to_cryptography_pubkey() if is_prehashed: signature_algorithm = ECDSA(utils.Prehashed(self.hash_algorithm())) else: signature_algorithm = ECDSA(self.hash_algorithm()) # TODO: Raise error instead of returning boolean try: cryptography_pub_key.verify( signature=self._der_encoded_bytes(), data=message, signature_algorithm=signature_algorithm) except InvalidSignature: return False return True
def verify(self, message: bytes, verifying_key: UmbralPublicKey) -> bool: """ Verifies that a message's signature was valid. :param message: The message to verify :param pubkey: UmbralPublicKey of the signer :return: True if valid, False if invalid """ cryptography_pub_key = verifying_key.to_cryptography_pubkey() try: cryptography_pub_key.verify(self._der_encoded_bytes(), message, ec.ECDSA(_BLAKE2B)) except InvalidSignature: return False return True