def create_challenge(self, secret: Union[bytes, str, bytearray], token: int): secret_hash: int = crypto.hash_numeric(secret) y: int = pow(self._g0, secret_hash, self._ecc.d) r: int = convert.point_to_int(crypto.get_random_point(self._curve)) t: int = pow(self._g0, r, self._ecc.d) payload = b''.join(map(convert.int_to_bytes, (y, t, token))) c = crypto.hash_numeric(payload) z = r - (secret_hash * c) return ZKChallenge(params=self.params, token=token, c=c, z=z)
def prove_challenge(self, challenge: ZKChallenge, signature: ZKSignature, token: int): t = pow(signature.signature, challenge.c, self._ecc.d) * pow( self._g0, challenge.z, self._ecc.d) % self._ecc.d payload = b''.join( map(convert.int_to_bytes, (signature.signature, t, token))) return challenge.token == token and challenge.c == crypto.hash_numeric( payload)
def create_signature(self, secret: Union[bytes, str, bytearray]): signature = pow(self._g0, crypto.hash_numeric(secret), self._ecc.d) return ZKSignature(params=self.params, signature=signature)
def hash(self, *values): return hash_numeric(*[v for v in values if v is not None], self.salt, alg=self.params.alg) & self._mask