|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectpaillierp.key.PaillierKey
public class PaillierKey
A simple public key for the generalized Paillier cryptosystem CS1. This public key is intended to be extended for other private keys and for the Paillier Threshold scheme with the degree s to be fixed as 1.
The public key for the generalized Paillier cryptosystem CSs constructed in Damgård et al. requires an n and g as defined as follows:
In this implementation, the user only chooses the n as the g is fixed. He can supply either the two primes or n itself, trusting that it a RSA modulus.
In addition, in this implementation the key also carries a random number generator with it. This is to facilitate the choosing of random numbers modulo n. The user has full freedom to change the random number generator to be as secure (or insecure) as one chooses.
Field Summary | |
---|---|
protected int |
k
Bit size of n. |
protected static int |
MAX_KEY_SIZE
Maximum number of bits allowed for keysize. |
protected java.math.BigInteger |
n
The modulus n, an RSA number. |
protected java.math.BigInteger |
nPlusOne
Cached (n+1) to help encryption. |
protected java.math.BigInteger |
ns
The cached value of ns. |
protected java.math.BigInteger |
nSPlusOne
Cached value of ns+1. |
protected java.util.Random |
rnd
Random number generator. |
private static long |
serialVersionUID
This Serial ID |
Constructor Summary | |
---|---|
PaillierKey(java.math.BigInteger p,
java.math.BigInteger q,
long seed)
Creates a new public key from a given two odd primes p and q. |
|
PaillierKey(java.math.BigInteger n,
long seed)
Creates a new public key when given the modulus n. |
|
PaillierKey(java.math.BigInteger n,
java.util.Random rnd)
Creates a new public key when given the modulus n and a specified random number generator. |
|
PaillierKey(byte[] b,
long seed)
Creates a new private key using a byte encoding of a key. |
Method Summary | |
---|---|
boolean |
canEncrypt()
Describes if this key can be used to encrypt. |
int |
getK()
Returns the size of n in bits. |
java.math.BigInteger |
getN()
Returns the modulus n, which in essence is the public key. |
java.math.BigInteger |
getNPlusOne()
Returns the cached value of n+1. |
java.math.BigInteger |
getNS()
Returns the cached value of ns, to be used frequently in calculations. |
java.math.BigInteger |
getNSPlusOne()
Returns the cached value of ns+1, to be used frequently in calculations. |
PaillierKey |
getPublicKey()
Returns the simple public key. |
java.math.BigInteger |
getRandomModN()
A special random number generator to find r in Zn. |
java.math.BigInteger |
getRandomModNSPlusOneStar()
A special random number generator to find r in Z*n2. |
java.math.BigInteger |
getRandomModNStar()
A special random number generator to find r in Z*n. |
java.util.Random |
getRnd()
Returns the random number generator used for this key. |
boolean |
inModN(java.math.BigInteger a)
Checks if a given number is in Zn. |
static boolean |
inModN(java.math.BigInteger a,
java.math.BigInteger n)
Checks if a given number is in Z n . |
boolean |
inModNS(java.math.BigInteger a)
Checks if a given number is in Zns. |
boolean |
inModNSPlusOne(java.math.BigInteger a)
Checks if a given number is in Zn2. |
boolean |
inModNSPlusOneStar(java.math.BigInteger a)
Checks if a given number is in Z*n2. |
boolean |
inModNStar(java.math.BigInteger a)
Checks if a given number is in Z*n. |
static boolean |
inModNStar(java.math.BigInteger a,
java.math.BigInteger n)
Checks if a given number is in Z* n . |
boolean |
isCiphertext(java.math.BigInteger c)
Checks to see if c is a valid ciphertext, that is if it is in
Zns+1. |
boolean |
isPlaintext(java.math.BigInteger m)
Checks to see if m is a valid plaintext, that is if it is in
Zns. |
void |
setRnd(long seed)
Resets the random number generator for this key to be a SecureRandom random number generator, using the
specified seed to help create it. |
void |
setRnd(java.util.Random rnd)
Replaces the random number generator with a user-specified generator. |
byte[] |
toByteArray()
Encodes this key into a byte array. |
void |
updateRnd()
Resets the random number generator for this key, using a generated random number as the seed. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final long serialVersionUID
protected java.math.BigInteger n
protected java.math.BigInteger ns
protected java.math.BigInteger nSPlusOne
protected java.math.BigInteger nPlusOne
protected java.util.Random rnd
protected int k
protected static final int MAX_KEY_SIZE
Constructor Detail |
---|
public PaillierKey(java.math.BigInteger n, java.util.Random rnd)
n
- a RSA modulus. That is, the product of two
different odd primesrnd
- a specified random number generatorpublic PaillierKey(java.math.BigInteger n, long seed)
seed
to create the public
key with a SecureRandom
random number generator.
n
- a RSA modulus. That is, the product of two
different odd primes.seed
- a long integer needed to start a random
number generatorpublic PaillierKey(java.math.BigInteger p, java.math.BigInteger q, long seed)
seed
to create the public key with a SecureRandom
random
number generator.
p
- an odd primeq
- another odd prime different from
p
seed
- a long integer needed to start a random
number generatorpublic PaillierKey(byte[] b, long seed)
b
- Byte array of the necessary values of this private keyseed
- a long integer needed to start a random number generatortoByteArray()
Method Detail |
---|
public PaillierKey getPublicKey()
public boolean canEncrypt()
public java.math.BigInteger getN()
public java.math.BigInteger getNS()
public java.math.BigInteger getNSPlusOne()
public java.math.BigInteger getNPlusOne()
n+1
public java.util.Random getRnd()
public void updateRnd()
public void setRnd(long seed)
SecureRandom
random number generator, using the
specified seed
to help create it.
seed
- a long integer needed to start a new
random number generatorpublic void setRnd(java.util.Random rnd)
rnd
- a specified random number generatorpublic int getK()
n
public static boolean inModN(java.math.BigInteger a, java.math.BigInteger n)
n
.
a
- the BigInteger to be checkedn
- the BigInteger modulus
a
is non-negative
and less than n
public static boolean inModNStar(java.math.BigInteger a, java.math.BigInteger n)
n
.
a
- the BigInteger we are checking
a
is non-negative,
less than n
, and relatively
prime to n
public java.math.BigInteger getRandomModN()
public java.math.BigInteger getRandomModNStar()
public java.math.BigInteger getRandomModNSPlusOneStar()
public boolean inModNStar(java.math.BigInteger a)
a
- the BigInteger we are checking
a
is non-negative,
less than n
, and relatively
prime to n
public boolean inModNSPlusOneStar(java.math.BigInteger a)
a
- the BigInteger we are checking
a
is non-negative,
less than n
, and relatively
prime to n
2public boolean inModN(java.math.BigInteger a)
a
- the BigInteger to be checked
a
is non-negative
and less than n
public boolean inModNS(java.math.BigInteger a)
a
- the BigInteger to be checked
a
is non-negative
and less than n
spublic boolean isPlaintext(java.math.BigInteger m)
m
is a valid plaintext, that is if it is in
Zns.
m
- the plaintext in question
m
is non-negative and less than
n
spublic boolean inModNSPlusOne(java.math.BigInteger a)
a
- the BigInteger to be checked
a
is non-negative
and less than n
.public boolean isCiphertext(java.math.BigInteger c)
c
is a valid ciphertext, that is if it is in
Zns+1.
c
- the ciphertext in question
c
is non-negative and less than
n
s+1public byte[] toByteArray()
n
will be encoded. The size of n
is
not recorded.
PaillierKey(byte[], long)
,
BigInteger.toByteArray()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |