Treshold Paillier Encryption
Treshold Paillier Encryption
1 Introduction
Following a desire for secure (encrypted) multiparty computation, the University of Texas
at Dallas Data Security and Privacy Lab created the paillierp Java packages. By using
a threshold variant of the Paillier Encryption scheme as laid out in [2], we use the methods
described in [1] to allow secure multiparty computation. This implementation is heavily
Object Oriented, having separate objects for (1) encryption/decryption environments, (2)
keys, and (3) zero knowledge proofs. As the threshold variant of Paillier is an improvement
on the original scheme, the original Paillier encryption scheme is included and is a superclass
of the threshold version.
1
Any collaboration between fewer than the specified number of decryption servers does not
result in a complete decryption.
When creating keys, variables w and l are chosen, resulting in 1 public key and l private
keys being generated, set with a threshold of w. It is necessary for at least w of these keys
to collaborate to decrypt a message encoded with the public key.
The process for decryption involves at least w decryption servers to obtain the same
ciphertext, and then apply their private key for decryption to produce a “partial decryp-
tion” or “share”, each partial decryption being shared with the remaining servers. Once a
server obtains at least w unique shares, that server can obtain the original plaintext.
Damgård and Jurik also proposed a generalization of the Paillier cryptosystem, allow-
ing ciphertexts to range in Zns+1 for any s ≥ 1. Such a feature can even allows the receiver
to decide on s upon encryption and so can allow variable block lengths. In this imple-
mentation, we are more concerned with multiparty computations and so fix s to be one at
every step.
Cramer, et al. provided exactly those zero-knowledge protocols for the threshold variant
of Paillier, making multiparty computation possible using Paillier.
2
1.4 The Packages
The intention of this suite is to provide the tools necessary to enable multiparty com-
putation based on the threshold variant of the Paillier cryptosystem. The requirements
enumerated above for such computation are all satisfied in Paillier and are provided to the
user of this package.
Three packages are included in this suite, namely:
paillierp.keys which includes key objects needed for encryption and decryption.
These two methods are the most necessary for random key generation. A further method
to eliminate randomness is also provided.
3
2.2 paillierp.keys.PaillierKey and paillierp.keys.PaillierPrivateKey
As in the original version of the Paillier cryptosystem, the key is generated by choosing a
RSA modulus n = pq of k bits for p, q prime. Originally, an element g ∈ Z∗n2 is also chosen,
but we fix g to be 1 + n without loss of security (as given in [2]). The private key is a value
d which is the least common multiple of p − 1 and q − 1.
While the choosing of these random numbers is left to paillierp.keys.KeyGen, the
class PaillierKey holds the necessary values for a public key, PaillierPrivateKey for a
private key. The constructors vary in arguments to provide flexibility. For the public key,
the constructors are
PaillierKey(BigInteger n, long seed) Creates a new public key when given the mod-
ulus n.
4
PaillierPrivateThresholdKey(BigInteger n, int l, int w, BigInteger v,
BigInteger[] viarray, BigInteger si, int i, long seed) Creates a new pri-
vate key for the generalized Paillier threshold scheme from the given modulus n, for
use on l decryption servers, w of which are needed to decrypt any message encrypted
by using this public key. The private value si is for this particular key ID i.
Other constructors are available which include the combineSharesConstant. That param-
eter is available for efficiencey at key distribution, but it can be computed by the other
values.
3.1.1 Encryption
Once a public key has been assigned to the encryption environment, whether by the
constructor or by setEncryption or setEncryptionDecryption, it is possible to call
encrypt( BigInteger m ) to encode a message m. The resulting BigInteger is the en-
crypted message.
Other encrypt methods are available, both static and otherwise, and are listed in the
online documentation.
3.1.2 Decryption
Once a private key has been assigned to the encryption environment, whether by the
constructor or by setDecryption or setEncryptionDecryption, it is possible to call
5
decrypt( BigInteger c ) to decode a ciphertext c. The resulting BigInteger is the
original message.
Just like above, other decrypt are available for greater flexibility. There are static
and non-static methods, all of which are listed in the online documentation.
static variants of the addition and multiplication methods are also available. Also
available are helpful utilities for random encryptions of 1 and of zero, and a method that
will randomize a ciphertext at no distortion of the original message.
3.2.1 Encryption
Encryption with PaillierThreshold is just the same as with Paillier in Section 3.1.1.
6
3.2.2 Decryption
The decryption methods for PaillierThreshold differ from Paillier.
Once a private key has been assigned to the encryption environment, whetherby the cus-
troctor or by setDecryption or setEncryptionDecryption, it is possible to call decrypt(
BigInteger c ) to decode a ciphertext c. The result is a PartialDecryption, which is
not the original message. Rather, one must provide many PartialDecryption objects to
combineShares( PartialDecryption... ) to obtain a BigInteger which is the original
message; at least deckey.getW() must be provided, where deckey is the private key.
In order to fully decrypt a ciphertext c, the following must happen
7
3.3 paillierp.ByteUtils - Byte Manipulation Utilities
ByteUtils is a bundle of static, byte manipulation methods for the toByteArray methods
as listed in Section 5.
EncryptionZKP This provides knowledge that one knows the plaintext of a given en-
cryption. This protocol is described on page 40 of [1].
8
DecryptionZKP This provides knowledge that one has indeed partially decrypted a ci-
phertext. The method is found on pages 16-17 of [3].
5 Transferring information
Transferring of both public and private keys, and of the PartialDecryption wrapper and
of each zero knowledge proof is made easy in this package. Not only are they serializable,
but they also are given a toByteArray() method to specifically encode the object as a byte
array for communication. Each of the above objects are also given a constructor which
takes as input the byte array as specifically engineered by that object’s toByteArray().
6 Example
We close with an example of the paillierp package, particularly PaillierThreshold.
1 package testingPaillier ;
9
33 // Alice encrypts a message
BigInteger msg = BigInteger . valueOf (135819283) ;
35 BigInteger Emsg = alice . encrypt ( msg ) ;
System . out . println (" Alice encrypts the message "+ msg +" and sends "+
37 Emsg +" to everyone .") ;
// Alice sends Emsg to everyone
39
System . out . println (" p1 receives the message and tries to decrypt all
alone :") ;
41 BigInteger p1decrypt = p1 . decryptOnly ( Emsg ) ;
if ( p1decrypt . equals ( msg ) ) {
43 System . out . println (" p1 succeeds decrypting the message all alone .") ;
} else {
45 System . out . println (" p1 fails decrypting the message all alone . :(") ;
}
47
System . out . println (" p2 and p3 receive the message and " +
49 " create a partial decryptions .") ;
DecryptionZKP p2share = p2 . decryptProof ( Emsg ) ;
51 DecryptionZKP p3share = p3 . decryptProof ( Emsg ) ;
// p2 sends the partial decryption to p3
53 // p3 sends the partial decryption to p2
55 System . out . println (" p2 receives the partial p3 ’ s partial decryption " +
" and attempts to decrypt the whole message using its own " +
57 " share twice ") ;
try {
59 BigInteger p2decrypt = p2 . combineShares ( p2share , p3share , p2share ) ;
if ( p2decrypt . equals ( msg ) ) {
61 System . out . println (" p2 succeeds decrypting the message with p3 .") ;
} else {
63 System . out . println (" p2 fails decrypting the message with p3 . :(") ;
}
65 } catch ( I l l eg a l A rg u m e nt E x c ep t i o n e ) {
System . out . println (" p2 fails decrypting and throws an error ") ;
67 }
69 System . out . println (" p4 , p5 , p6 receive Alice ’ s original message and " +
" create partial decryptions .") ;
71 DecryptionZKP p4share = p4 . decryptProof ( Emsg ) ;
DecryptionZKP p5share = p5 . decryptProof ( Emsg ) ;
73 DecryptionZKP p6share = p6 . decryptProof ( Emsg ) ;
// p4 , p5 , and p6 share each of their partial decryptions with each
other
75
System . out . println (" p4 receives and combines each partial decryption " +
77 " to decrypt whole message :") ;
BigInteger p4decrypt = p4 . combineShares ( p4share , p5share , p6share ) ;
79 if ( p4decrypt . equals ( msg ) ) {
10
System . out . println (" p4 succeeds decrypting the message with p5 and p6
.") ;
81 } else {
System . out . println (" p4 fails decrypting the message with p5 and p6 .
:(") ;
83 }
}
85 }
References
[1] Cramer, R., Damgård, I., and Nielsen, J. B. Multiparty computation from
threshold homomorphic encryption. In EUROCRYPT ’01: Proceedings of the Interna-
tional Conference on the Theory and Application of Cryptographic Techniques (London,
UK, 2001), Springer-Verlag, pp. 280–299.
[2] Damgård, I., and Jurik, M. A generalisation, a simplification and some applica-
tions of Paillier’s probabilistic public-key system. In PKC ’01: Proceedings of the 4th
International Workshop on Practice and Theory in Public Key Cryptography (London,
UK, 2001), Springer-Verlag, pp. 119–136.
[3] Damgård, I., Jurik, M., and Nielsen, J. B. A generalization of Paillier’s public-
key system with applications to electronic voting. http://www.brics.dk/~ivan/
GenPaillierfinaljour.ps, 2003. Manuscript.
11