// GenerateKey generates an Paillier keypair of the given bit size using the
// random source random (for example, crypto/rand.Reader).
GenerateKey generates an Paillier keypair of the given bit size using the
random source random (for example, crypto/rand.Reader).
// GenerateKey generates an Paillier keypair of the given bit size using the // random source random ( for example crypto / rand . Reader ) .
func GenerateKey(random io.Reader, bits int) (*PrivateKey, error) {
	p, err := rand.Prime(random, bits)
	if err != nil {
		return nil, err
	}
	q, err := rand.Prime(random, bits)
	if err != nil {
		return nil, err
	}
	n := new(big.Int).Mul(p, q)
	l := new(big.Int).Mul(
		new(big.Int).Sub(p, one),
		new(big.Int).Sub(q, one),
	)
	return &PrivateKey{
		PublicKey: PublicKey{
			N:        n,
			NSquared: new(big.Int).Mul(n, n),
			G:        new(big.Int).Add(n, one), 
		},
		L: l,
		U: new(big.Int).ModInverse(l, n),
	}, nil
}
func GenerateKey ( random io . Reader , bits int ) ( * PrivateKey , error ) { p , err := rand . Prime ( random , bits ) if err != nil { return nil , err } q , err := rand . Prime ( random , bits ) if err != nil { return nil , err } n := new ( big . Int ) . Mul ( p , q ) l := new ( big . Int ) . Mul ( new ( big . Int ) . Sub ( p , one ) , new ( big . Int ) . Sub ( q , one ) , ) return & PrivateKey { PublicKey : PublicKey { N : n , NSquared : new ( big . Int ) . Mul ( n , n ) , G : new ( big . Int ) . Add ( n , one ) , } , L : l , U : new ( big . Int ) . ModInverse ( l , n ) , } , nil }
GenerateKey generates an Paillier keypair of the given bit size using the
random source random (for example, crypto/rand.Reader).
GenerateKey generates an Paillier keypair of the given bit size using the random source random ( for example crypto / rand . Reader ) .
// n = p * q // l = phi(n) = (p-1) * q(-1) // g = n + 1