code: def generate_paillier_keypair(private_keyring=None, n_length=DEFAULT_KEYSIZE):
      
      p = q = n = None
      n_len = 0
      while n_len != n_length:
          p = getprimeover(n_length // 2)
          q = p
          while q == p:
              q = getprimeover(n_length // 2)
          n = p * q
          n_len = n.bit_length()
  
      public_key = PaillierPublicKey(n)
      private_key = PaillierPrivateKey(public_key, p, q)
  
      if private_keyring is not None:
          private_keyring.add(private_key)
  
      return public_key, private_key
docs: Return a new :class:`PaillierPublicKey` and :class:`PaillierPrivateKey`.
  
      Add the private key to *private_keyring* if given.
  
      Args:
        private_keyring (PaillierPrivateKeyring): a
          :class:`PaillierPrivateKeyring` on which to store the private
          key.
        n_length: key size in bits.
  
      Returns:
        tuple: The generated :class:`PaillierPublicKey` and
        :class:`PaillierPrivateKey`