paillierp
Class Paillier

java.lang.Object
  extended by paillierp.AbstractPaillier
      extended by paillierp.Paillier

public class Paillier
extends AbstractPaillier

A simple implementation of the generalized Paillier encryption scheme CS1. This is based on the gernarlization given in Generalization of Paillier's Public-Key System with Applications to Electronic Voting by Damgård et al. with the parameter s fixed at 1.

With most of the methods already defined in AbstractPaillier, this class provides the essential methods of encryption and decryption in the simplified Paillier encryption scheme, as well as a few test/diagnostic methods.

Paillier Encryption Scheme

The Paillier encryption scheme is a probabilistic asymmetric encryption scheme with homomorphic properties for both addition and multiplication. It takes plaintext i less than n to compute the encryption E(i,r) for a random r (with n predetermined by the public key). Damgård et al. constructed a generalized version of the scheme to allow more freedom in changing the block size of the encryption independently of the size of the public key. Whereas Paillier's original scheme created plaintexts less than n, this generalized version allows plaintexts to be less than ns. This implementation is of Paillier's original scheme as expressed in the generalized version of Damgård et al. (i.e. s fixed to 1).

The Math: The simplified Paillier encryption scheme takes a PaillierKey n to encrypt a plaintext i in Zns by choosing a random rZn* by simply computing (n+1)irn mod ns+1. If given a PaillierPrivateKey d, raising a ciphertext c to the power d gives a value (1+n)id, and by using a method in the paper, can give the original message i mod ns.

Note that the random number generator is included in the key object. (The default is SecureRandom.)

Future expansions will include support for encrypting arbitrary length strings/byte arrays to avoid padding issues, and support for padding.

Author:
Murat Kantarcioglu, James Garrity, Sean Hall
See Also:
AbstractPaillier

Field Summary
protected  PaillierPrivateKey deckey
          Private Key allowing decryption; should be same as public key.
 
Fields inherited from class paillierp.AbstractPaillier
decryptMode, encryptMode, key, notReadyForDecryption, notReadyForEncryption
 
Constructor Summary
Paillier()
          Default constructor.
Paillier(PaillierKey key)
          Constructs a new encryption object which uses the specified key for encryption.
Paillier(PaillierPrivateKey key)
          Constructs a new encryption/decryption object which uses the specified key for both encryption and decryption.
 
Method Summary
 java.math.BigInteger decrypt(java.math.BigInteger c)
          Decrypts the given ciphertext.
 PaillierPrivateKey getPrivateKey()
          Returns the current private key in use by this encryption object.
 void setDecryptEncrypt(PaillierPrivateKey key)
          Sets the mode for this object to decrypt and encrypt using the provided key.
 void setDecryption(PaillierPrivateKey key)
          Sets the mode for this object to decrypt and will use the provided key to decrypt only.
 void setEncryption(PaillierKey key)
          Sets the mode for this object to encrypt and will use the provided key to encrypt messages.
static void test()
          This main method basically tests the different features of the Paillier encryption
static void testICDE()
           
 
Methods inherited from class paillierp.AbstractPaillier
add, add, encrypt, encrypt, encrypt, encrypt, encrypt, encryptone, encryptProof, encryptzero, getPublicKey, multiply, multiply, multiply, multiplyProof, randomize, randomize
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

deckey

protected PaillierPrivateKey deckey
Private Key allowing decryption; should be same as public key.

Constructor Detail

Paillier

public Paillier()
Default constructor. This constructor can be used if there is no need to generate public/private key pair.


Paillier

public Paillier(PaillierKey key)
Constructs a new encryption object which uses the specified key for encryption.

Parameters:
key - Public key used for encryption

Paillier

public Paillier(PaillierPrivateKey key)
Constructs a new encryption/decryption object which uses the specified key for both encryption and decryption.

Parameters:
key - Private key used for decryption and encryption
Method Detail

setEncryption

public void setEncryption(PaillierKey key)
Sets the mode for this object to encrypt and will use the provided key to encrypt messages.

Parameters:
key - Public key which this class will use to encrypt

setDecryption

public void setDecryption(PaillierPrivateKey key)
Sets the mode for this object to decrypt and will use the provided key to decrypt only. (Encryption will continue to be done using the key provided in setEncryption(PaillierKey).)

Parameters:
key - Private key which this class will use to decrypt

setDecryptEncrypt

public void setDecryptEncrypt(PaillierPrivateKey key)
Sets the mode for this object to decrypt and encrypt using the provided key.

Parameters:
key - Private key which this class will use to encrypt and decrypt

getPrivateKey

public PaillierPrivateKey getPrivateKey()
Returns the current private key in use by this encryption object.

Returns:
The private key used; returns null if this is not in decryption mode.

decrypt

public java.math.BigInteger decrypt(java.math.BigInteger c)
Decrypts the given ciphertext.

Parameters:
c - Ciphertext as BigInteger c
Returns:
Decrypted value D(c) as BigInteger

test

public static void test()
This main method basically tests the different features of the Paillier encryption


testICDE

public static void testICDE()