blob: e549c57e2f080cb611ce236b92c30174fb87c6c1 [file] [log] [blame]
 Paillier
org.apache.pirk.encryption

Class Paillier

• java.lang.Object
• org.apache.pirk.encryption.Paillier
• All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable

public class Paillier
extends java.lang.Object
implements java.lang.Cloneable, java.io.Serializable
Implementation of the Paillier cryptosystem

The algorithm is as follows:

Let N=pq, be a RSA modulus where p,q are large primes of roughly the same length

The plaintext space is the additive group Z/NZ and the ciphertext space is the multiplicative group (Z/N^2 Z)*.

Public key: N, Private key: The factorization of N=pq.

Let lambda(N) be the Carmichael function of N (the exponent of the multiplicative group of units modulo N):

lambda(N) = lcm(p-1,q-1) = (p-1)(q-1)/gcd(p-1,q-1)

Encryption E(m) for a message m is as follows:

- Given N and m

- Select a random value r in (Z/NZ)*

- E(m) = (1 + mN)r^N mod N^2

Decryption D(c) for a ciphertext c is as follows:

- Given N, its factorization N=pq, and ciphertext c

- Set w = lambda(N)^-1 mod N

- Set x = c^(lambda(N))mod N^2

- Set y = (x-1)/N

- D(c) = yw mod N

Ref: Paillier, Pascal. "Public-Key Cryptosystems Based on Composite Degree Residuosity Classes." EUROCRYPT'99.

Serialized Form
• Constructor Summary

Constructors
Constructor and Description
Paillier(java.math.BigInteger pInput, java.math.BigInteger qInput, int bitLengthInput)
Constructor with all parameters p,q, and bitLengthInput specified
Paillier(int bitLengthInput, int certainty)
Constructor to generate keys given the desired bitLength and prime certainty value
Paillier(int bitLengthInput, int certainty, int ensureBitSet)
Constructor to generate keys given the desired bitLength and prime certainty value
• Method Summary

Methods
Modifier and Type Method and Description
Paillier clone()
java.math.BigInteger decrypt(java.math.BigInteger c)
Method to decrypt a given ciphertext
java.math.BigInteger encrypt(java.math.BigInteger m)
Encrypt - generate r
java.math.BigInteger encrypt(java.math.BigInteger m, java.math.BigInteger r)
Encrypt - use provided r
int getBitLength()
java.math.BigInteger getLambdaN()
java.math.BigInteger getN()
java.math.BigInteger getNSquared()
java.math.BigInteger getP()
java.math.BigInteger getQ()
• Methods inherited from class java.lang.Object

equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
• Constructor Detail

• Paillier

public Paillier(java.math.BigInteger pInput,
java.math.BigInteger qInput,
int bitLengthInput)
throws PIRException
Constructor with all parameters p,q, and bitLengthInput specified

Only used, at this point, for testing purposes

Throws:
PIRException
• Paillier

public Paillier(int bitLengthInput,
int certainty)
throws PIRException
Constructor to generate keys given the desired bitLength and prime certainty value

The probability that the new BigInteger values represents primes will exceed (1 - (1/2)^certainty). The execution time of this constructor is proportional to the value of this parameter.

Throws:
PIRException
• Paillier

public Paillier(int bitLengthInput,
int certainty,
int ensureBitSet)
throws PIRException
Constructor to generate keys given the desired bitLength and prime certainty value

Can optionally, ensure a certain bit is set in the modulus (if ensureBitSet != 0)

The probability that the new BigInteger values represents primes will exceed (1 - (1/2)^certainty). The execution time of this constructor is proportional to the value of this parameter.

Throws:
PIRException
• Method Detail

• getP

public java.math.BigInteger getP()
• getQ

public java.math.BigInteger getQ()
• getN

public java.math.BigInteger getN()
• getNSquared

public java.math.BigInteger getNSquared()
• getLambdaN

public java.math.BigInteger getLambdaN()
• getBitLength

public int getBitLength()
• encrypt

public java.math.BigInteger encrypt(java.math.BigInteger m)
throws PIRException
Encrypt - generate r
Throws:
PIRException
• encrypt

public java.math.BigInteger encrypt(java.math.BigInteger m,
java.math.BigInteger r)
throws PIRException
Encrypt - use provided r
Throws:
PIRException
• decrypt

public java.math.BigInteger decrypt(java.math.BigInteger c)
Method to decrypt a given ciphertext
• clone

public Paillier clone()
Overrides:
clone in class java.lang.Object