Пример #1
0
 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)
Пример #2
0
 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)
Пример #3
0
 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)
Пример #4
0
 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