Exemple #1
0
    def from_totient(public_key, totient):
        """given the totient, one can factorize the modulus

        The totient is defined as totient = (p - 1) * (q - 1),
        and the modulus is defined as modulus = p * q

        Args:
          public_key (PaillierPublicKey): The corresponding public
            key
          totient (int): the totient of the modulus

        Returns:
          the :class:`PaillierPrivateKey` that corresponds to the inputs

        Raises:
          ValueError: if the given totient is not the totient of the modulus
            of the given public key
        """
        p_plus_q = public_key.n - totient + 1
        p_minus_q = isqrt(p_plus_q * p_plus_q - public_key.n * 4)
        q = (p_plus_q - p_minus_q) // 2
        p = p_plus_q - q
        if not p*q == public_key.n:
            raise ValueError('given public key and totient do not match.')
        return PaillierPrivateKey(public_key, p, q, random_alpha)
Exemple #2
0
    def from_totient(public_key, totient):
        """given the totient, one can factorize the modulus

        The totient is defined as totient = (p - 1) * (q - 1),
        and the modulus is defined as modulus = p * q

        Args:
          public_key (PaillierPublicKey): The corresponding public
            key
          totient (int): the totient of the modulus

        Returns:
          the :class:`PaillierPrivateKey` that corresponds to the inputs

        Raises:
          ValueError: if the given totient is not the totient of the modulus
            of the given public key
        """
        p_plus_q = public_key.n - totient + 1
        p_minus_q = isqrt(p_plus_q * p_plus_q - public_key.n * 4)
        q = (p_plus_q - p_minus_q) // 2
        p = p_plus_q - q
        if not p*q == public_key.n:
            raise ValueError('given public key and totient do not match.')
        return PaillierPrivateKey(public_key, p, q)
Exemple #3
0
    def from_totient(public_key, totient):
        """given the totient, one can factorize the modulus
        The totient is defined as totient = (p - 1) * (q - 1),
        and the modulus is defined as modulus = p * q
        考虑到totient,可以分解模量。
        totient被定义为totient = (p - 1) * (q - 1),
        模被定义为模= p * q。

        Args:
          public_key (PaillierPublicKey): The corresponding public
            key
          totient (int): the totient of the modulus

        Returns:
          the :class:`PaillierPrivateKey` that corresponds to the inputs
            对应于输入的Paillier私钥。
        Raises:
          ValueError: if the given totient is not the totient of the modulus
            of the given public key
            如果给定的totient不是模量的totient给定的公钥。
        """
        p_plus_q = public_key.n - totient + 1#加
        p_minus_q = isqrt(p_plus_q * p_plus_q - public_key.n * 4)#乘
        q = (p_plus_q - p_minus_q) // 2
        p = p_plus_q - q
        if not p*q == public_key.n:
            raise ValueError('given public key and totient do not match.')
        return PaillierPrivateKey(public_key, p, q)
 def from_totient(public_key, totient):
     p_plus_q = public_key.n - totient + 1
     p_minus_q = isqrt(p_plus_q * p_plus_q - public_key.n * 4)
     q = (p_plus_q - p_minus_q) // 2
     p = p_plus_q - q
     if not p * q == public_key.n:
         raise ValueError('given public key and totient do not match.')
     return PaillierPrivateKey(public_key, p, q)
Exemple #5
0
 def testIsqrt(self):
     for _ in range(100):
         n = random.randint(2, 10000000)
         nsq = n*n
         self.assertEqual(int(math.floor(math.sqrt(n))), util.isqrt(n))
         self.assertEqual(util.isqrt(nsq), util.improved_i_sqrt(nsq))
Exemple #6
0
 def testIsqrt(self):
     for _ in range(100):
         n = random.randint(2, 10000000)
         nsq = n * n
         self.assertEqual(int(math.floor(math.sqrt(n))), util.isqrt(n))
         self.assertEqual(util.isqrt(nsq), util.improved_i_sqrt(nsq))