paillierp
Class AbstractPaillier

java.lang.Object
  extended by paillierp.AbstractPaillier
Direct Known Subclasses:
Paillier, PaillierThreshold

public abstract class AbstractPaillier
extends java.lang.Object

An abstract class of the simple Paillier cryptosystem. This class is intended for use in both the Paillier and PaillierThreshold implementations of the generalized Paillier cryptosystem by Damgård.

This includes methods and fields common to both implementations, especially encryption and operations on ciphertexts; more specifically, the following operations are provided in this abstract class:

Any operations needing the decryption key is left to the specific cryptosystem and is not included in this class.

Note that every ciphertext and plaintext is a BigInteger.

Author:
Sean Hall, James Garrity
See Also:
Paillier, PaillierThreshold

Field Summary
protected  boolean decryptMode
          Boolean signifying that the variables for decryption are in place.
protected  boolean encryptMode
          Boolean signifying that the variables for encryption are in place.
protected  PaillierKey key
          Public Key allowing encryption.
protected  java.lang.String notReadyForDecryption
          String for error messages indicating that decryptMode is not set.
protected  java.lang.String notReadyForEncryption
          String for error messages indicating that encryptMode is not set.
 
Constructor Summary
AbstractPaillier()
           
 
Method Summary
 java.math.BigInteger add(java.math.BigInteger c1, java.math.BigInteger c2)
          Calculates E(m1+m2) given E(m1) and E(m2).
static java.math.BigInteger add(java.math.BigInteger c1, java.math.BigInteger c2, java.math.BigInteger nsplus1)
          Calculates E(m1+m2) given E(m1) and E(m2), for a given cryptosystem CSs with public key n
 java.math.BigInteger encrypt(java.math.BigInteger m)
          Produces the random encryption of m.
 java.math.BigInteger encrypt(java.math.BigInteger m, java.math.BigInteger r)
          Produces the encryption E(m, r) using the message m and the randomization r in the Paillier cryptosystem.
static java.math.BigInteger encrypt(java.math.BigInteger m, java.math.BigInteger r, java.math.BigInteger n, java.math.BigInteger ns, java.math.BigInteger nSPlusOne)
          Produces the encryption E(m, r).
static java.math.BigInteger encrypt(java.math.BigInteger m, java.math.BigInteger r, PaillierKey key)
          Produces the encryption E(m, r).
static java.math.BigInteger encrypt(java.math.BigInteger m, PaillierKey key)
          Produces a random encryption of m
 java.math.BigInteger encryptone()
          A random encryption of 1.
 EncryptionZKP encryptProof(java.math.BigInteger m)
          Produces a Zero Knowledge Proof of the encryption m
 java.math.BigInteger encryptzero()
          A random encryption of 0.
 PaillierKey getPublicKey()
          Returns the simple public key already in use in this instance of the cryptosystem.
 java.math.BigInteger multiply(java.math.BigInteger c1, java.math.BigInteger cons)
          Calculates E(cons*m) given E(m) and the constant cons, under our current public key.
static java.math.BigInteger multiply(java.math.BigInteger c, java.math.BigInteger cons, java.math.BigInteger nSquare)
          Calculates E(cons*m) given E(m) and the constant cons, under the public key n for crypto system CSs.
 java.math.BigInteger multiply(java.math.BigInteger c1, long cons)
          Calculates E(cons*m) given E(m) and the constant cons, under our current public key.
 MultiplicationZKP multiplyProof(java.math.BigInteger c1, java.math.BigInteger cons)
          Calculates E(cons*m) given E(m) and the constant cons, under our current public key.
 java.math.BigInteger randomize(java.math.BigInteger c)
          Randomizes a given encryption by the given variable.
 java.math.BigInteger randomize(java.math.BigInteger c, java.math.BigInteger r)
          Randomizes a given encryption by the given variable.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

key

protected PaillierKey key
Public Key allowing encryption.


encryptMode

protected boolean encryptMode
Boolean signifying that the variables for encryption are in place.


decryptMode

protected boolean decryptMode
Boolean signifying that the variables for decryption are in place.


notReadyForEncryption

protected java.lang.String notReadyForEncryption
String for error messages indicating that encryptMode is not set.


notReadyForDecryption

protected java.lang.String notReadyForDecryption
String for error messages indicating that decryptMode is not set.

Constructor Detail

AbstractPaillier

public AbstractPaillier()
Method Detail

getPublicKey

public PaillierKey getPublicKey()
Returns the simple public key already in use in this instance of the cryptosystem. This includes the two values n and g needed for encryption. Returns null if no key has yet to be specified.

Returns:
the Paillier public key in use; null if the key is not initialized.

encrypt

public java.math.BigInteger encrypt(java.math.BigInteger m)
Produces the random encryption of m.

Parameters:
m - plaintext to be encrypted; must be less than ns
Returns:
the encryption E(m,r) with a random r

encrypt

public java.math.BigInteger encrypt(java.math.BigInteger m,
                                    java.math.BigInteger r)
Produces the encryption E(m, r) using the message m and the randomization r in the Paillier cryptosystem.

Parameters:
m - plaintext to be encrypted; must be less than ns
r - randomizer integer for the encryption; must be relatively prime to n and less than n
Returns:
the encryption E(m,r)

encrypt

public static java.math.BigInteger encrypt(java.math.BigInteger m,
                                           PaillierKey key)
Produces a random encryption of m

Parameters:
m - Message to be encoded; m<ns
key - Public Key doing the encoding
Returns:
The encryption E(m, r) using the public key key with random r

encrypt

public static java.math.BigInteger encrypt(java.math.BigInteger m,
                                           java.math.BigInteger r,
                                           PaillierKey key)
Produces the encryption E(m, r).

Parameters:
m - Message to be encoded; m<ns
r - Random number in Z*n
key - Public Key doing the encoding
Returns:
The encryption E(m, r) using the public key key

encrypt

public static java.math.BigInteger encrypt(java.math.BigInteger m,
                                           java.math.BigInteger r,
                                           java.math.BigInteger n,
                                           java.math.BigInteger ns,
                                           java.math.BigInteger nSPlusOne)
Produces the encryption E(m, r).

Parameters:
m - Message to be encoded; m<ns
r - Random number in Z*n
n - RSA modulus
ns - The value ns
nSPlusOne - The value ns+1
Returns:
The encryption E(m, r) using the public key n

encryptProof

public EncryptionZKP encryptProof(java.math.BigInteger m)
Produces a Zero Knowledge Proof of the encryption m

Parameters:
m - A message to be encrypted (must be less than n
Returns:
A non-interactive Zero Knowledge Proof that we in fact encrypted m

encryptzero

public java.math.BigInteger encryptzero()
A random encryption of 0.

Returns:
the encrypted value E(0,r) with random r

encryptone

public java.math.BigInteger encryptone()
A random encryption of 1.

Returns:
the encrypted value E(1,r) with random r

add

public java.math.BigInteger add(java.math.BigInteger c1,
                                java.math.BigInteger c2)
Calculates E(m1+m2) given E(m1) and E(m2).

Parameters:
c1 - the encryption E(m1)
c2 - the encryption E(m2)
Returns:
the encryption E(m1+m2)

add

public static java.math.BigInteger add(java.math.BigInteger c1,
                                       java.math.BigInteger c2,
                                       java.math.BigInteger nsplus1)
Calculates E(m1+m2) given E(m1) and E(m2), for a given cryptosystem CSs with public key n

Parameters:
c1 - the encryption E(m1) under the public key n
c2 - the encryption E(m2) under the public key n
nsplus1 - n to the (s+1)th power
Returns:
the encryption E(m1+m2) under the supposed public key n in cryptosystem CSs.

multiply

public java.math.BigInteger multiply(java.math.BigInteger c1,
                                     long cons)
Calculates E(cons*m) given E(m) and the constant cons, under our current public key.

Parameters:
c1 - the encryption E(m)
cons - the integer multiplicand
Returns:
the encryption E(cons*m)

multiply

public java.math.BigInteger multiply(java.math.BigInteger c1,
                                     java.math.BigInteger cons)
Calculates E(cons*m) given E(m) and the constant cons, under our current public key.

Parameters:
c1 - the encryption E(m)
cons - the integer multiplicand
Returns:
the encryption E(cons*m)

multiplyProof

public MultiplicationZKP multiplyProof(java.math.BigInteger c1,
                                       java.math.BigInteger cons)
Calculates E(cons*m) given E(m) and the constant cons, under our current public key. This method then returns a non-interactive Zero Knowledge Proof that the resulting encryption (i.e. E(cons*m)) is indeed the encryption of the multiplication of m by cons.

Parameters:
c1 - the encryption E(m)
cons - the integer multiplicand
Returns:
a ZKP of the encryption E(cons*m)

multiply

public static java.math.BigInteger multiply(java.math.BigInteger c,
                                            java.math.BigInteger cons,
                                            java.math.BigInteger nSquare)
Calculates E(cons*m) given E(m) and the constant cons, under the public key n for crypto system CSs.

Parameters:
c - the encryption E(m) under the public key n
cons - the integer multiplicand
nSquare - n to the (s+1)th power
Returns:
the encryption E(cons*m) under the supposed public key n in cryptosystem CSs

randomize

public java.math.BigInteger randomize(java.math.BigInteger c,
                                      java.math.BigInteger r)
Randomizes a given encryption by the given variable. Given E(m,r'), it returns E(m,r'*r).

Parameters:
c - the encryption E(m,r')
r - randomizer variable; must be relatively prime to n and less than n
Returns:
the encryption E(m,r'*r)

randomize

public java.math.BigInteger randomize(java.math.BigInteger c)
Randomizes a given encryption by the given variable. Given E(m,r), it returns E(m,r') for random r'.

Parameters:
c - the encryption E(m,r)
Returns:
the encryption E(m,r') for a new random r'