You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pirk.apache.org by tellison <gi...@git.apache.org> on 2016/09/27 11:59:05 UTC

[GitHub] incubator-pirk pull request #102: [Minor] Enhancements to Paillier class.

GitHub user tellison opened a pull request:

    https://github.com/apache/incubator-pirk/pull/102

    [Minor] Enhancements to Paillier class.

     - JavaDoc updates to public API constructors and methods.
     - Class now marked 'final'.
     - Minor tidy-up in generateKeys() for clarity.
     - Constructors throw IllegalArgumentException rather than PIRException.
     - No need to implement Cloneable.

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/tellison/incubator-pirk PaillierDocs

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/incubator-pirk/pull/102.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #102
    
----
commit d25e2cc51ef7a66199912c3f492ba02896ccb8bb
Author: Tim Ellison <t....@gmail.com>
Date:   2016-09-27T11:46:20Z

    Enhancements to Paillier class.
    
     - JavaDoc updates to public API constructors and methods.
     - Class now marked 'final'.
     - Minor tidy-up in generateKeys() for clarity.
     - Constructors throw IllegalArgumentException rather than PIRException.
     - No need to implement Cloneable.

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-pirk pull request #102: [Minor] Enhancements to Paillier class.

Posted by tellison <gi...@git.apache.org>.
Github user tellison commented on a diff in the pull request:

    https://github.com/apache/incubator-pirk/pull/102#discussion_r80862797
  
    --- Diff: src/main/java/org/apache/pirk/encryption/Paillier.java ---
    @@ -95,140 +95,185 @@
         }
       }
     
    -  private BigInteger p = null; // large prime
    -  private BigInteger q = null; // large prime
    -  private BigInteger N = null; // N=pq, RSA modulus
    +  private BigInteger p; // large prime
    +  private BigInteger q; // large prime
    +  private BigInteger N; // N=pq, RSA modulus
     
    -  private BigInteger NSquared = null; // NSquared = N^2
    -  private BigInteger lambdaN = null; // lambda(N) = lcm(p-1,q-1), Carmichael function of N
    -  private BigInteger w = null; // lambda(N)^-1 mod N
    +  private BigInteger NSquared; // NSquared = N^2
    +  private BigInteger lambdaN; // lambda(N) = lcm(p-1,q-1), Carmichael function of N
    +  private BigInteger w; // lambda(N)^-1 mod N
     
    -  private int bitLength = 0; // bit length of the modulus N
    +  private final int bitLength; // bit length of the modulus N
     
       /**
    -   * Constructor with all parameters p,q, and bitLengthInput specified
    -   * <p>
    -   * Only used, at this point, for testing purposes
    -   *
    +   * Creates a Paillier algorithm with all parameters specified.
    +   * 
    +   * @param p
    +   *          First large prime.
    +   * @param q
    +   *          Second large prime.
    +   * @param bitLength
    +   *          Bit length of the modulus {@code N}.
    +   * @throws IllegalArgumentException
    +   *           If {@code p} or {@code q} do not satisfy primality constraints.
        */
    -  public Paillier(BigInteger pInput, BigInteger qInput, int bitLengthInput) throws PIRException
    +  public Paillier(BigInteger p, BigInteger q, int bitLength)
       {
    -    bitLength = bitLengthInput;
    +    this.bitLength = bitLength;
     
         // Verify the prime conditions are satisfied
         int primeCertainty = SystemConfiguration.getIntProperty("pir.primeCertainty", 128);
         BigInteger three = BigInteger.valueOf(3);
    -    if ((pInput.compareTo(three) < 0) || (qInput.compareTo(three) < 0) || pInput.equals(qInput) || !pInput.isProbablePrime(primeCertainty)
    -        || !qInput.isProbablePrime(primeCertainty))
    +    if ((p.compareTo(three) < 0) || (q.compareTo(three) < 0) || p.equals(q) || !p.isProbablePrime(primeCertainty) || !q.isProbablePrime(primeCertainty))
         {
    -      throw new PIRException("pInput = " + pInput + " qInput = " + qInput + " do not satisfy primality constraints");
    +      throw new IllegalArgumentException("p = " + p + " q = " + q + " do not satisfy primality constraints");
         }
     
    -    p = pInput;
    -    q = qInput;
    +    this.p = p;
    +    this.q = q;
     
    -    N = p.multiply(q);
    +    this.N = p.multiply(q);
     
         setDerivativeElements();
     
         logger.info("Parameters = " + parametersToString());
       }
     
       /**
    -   * Constructor to generate keys given the desired bitLength and prime certainty value
    +   * Constructs a Paillier algorithm with generated keys.
        * <p>
    -   * 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.
    -   *
    +   * The generated keys {@code p} and {@code q} will have the given modulus bit length and prime certainty.
    --- End diff --
    
    Fixed - thanks.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-pirk pull request #102: [Minor] Enhancements to Paillier class.

Posted by tellison <gi...@git.apache.org>.
Github user tellison commented on a diff in the pull request:

    https://github.com/apache/incubator-pirk/pull/102#discussion_r80862814
  
    --- Diff: src/main/java/org/apache/pirk/encryption/Paillier.java ---
    @@ -95,140 +95,185 @@
         }
       }
     
    -  private BigInteger p = null; // large prime
    -  private BigInteger q = null; // large prime
    -  private BigInteger N = null; // N=pq, RSA modulus
    +  private BigInteger p; // large prime
    +  private BigInteger q; // large prime
    +  private BigInteger N; // N=pq, RSA modulus
     
    -  private BigInteger NSquared = null; // NSquared = N^2
    -  private BigInteger lambdaN = null; // lambda(N) = lcm(p-1,q-1), Carmichael function of N
    -  private BigInteger w = null; // lambda(N)^-1 mod N
    +  private BigInteger NSquared; // NSquared = N^2
    +  private BigInteger lambdaN; // lambda(N) = lcm(p-1,q-1), Carmichael function of N
    +  private BigInteger w; // lambda(N)^-1 mod N
     
    -  private int bitLength = 0; // bit length of the modulus N
    +  private final int bitLength; // bit length of the modulus N
     
       /**
    -   * Constructor with all parameters p,q, and bitLengthInput specified
    -   * <p>
    -   * Only used, at this point, for testing purposes
    -   *
    +   * Creates a Paillier algorithm with all parameters specified.
    +   * 
    +   * @param p
    +   *          First large prime.
    +   * @param q
    +   *          Second large prime.
    +   * @param bitLength
    +   *          Bit length of the modulus {@code N}.
    +   * @throws IllegalArgumentException
    +   *           If {@code p} or {@code q} do not satisfy primality constraints.
        */
    -  public Paillier(BigInteger pInput, BigInteger qInput, int bitLengthInput) throws PIRException
    +  public Paillier(BigInteger p, BigInteger q, int bitLength)
       {
    -    bitLength = bitLengthInput;
    +    this.bitLength = bitLength;
     
         // Verify the prime conditions are satisfied
         int primeCertainty = SystemConfiguration.getIntProperty("pir.primeCertainty", 128);
         BigInteger three = BigInteger.valueOf(3);
    -    if ((pInput.compareTo(three) < 0) || (qInput.compareTo(three) < 0) || pInput.equals(qInput) || !pInput.isProbablePrime(primeCertainty)
    -        || !qInput.isProbablePrime(primeCertainty))
    +    if ((p.compareTo(three) < 0) || (q.compareTo(three) < 0) || p.equals(q) || !p.isProbablePrime(primeCertainty) || !q.isProbablePrime(primeCertainty))
         {
    -      throw new PIRException("pInput = " + pInput + " qInput = " + qInput + " do not satisfy primality constraints");
    +      throw new IllegalArgumentException("p = " + p + " q = " + q + " do not satisfy primality constraints");
         }
     
    -    p = pInput;
    -    q = qInput;
    +    this.p = p;
    +    this.q = q;
     
    -    N = p.multiply(q);
    +    this.N = p.multiply(q);
     
         setDerivativeElements();
     
         logger.info("Parameters = " + parametersToString());
       }
     
       /**
    -   * Constructor to generate keys given the desired bitLength and prime certainty value
    +   * Constructs a Paillier algorithm with generated keys.
        * <p>
    -   * 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.
    -   *
    +   * The generated keys {@code p} and {@code q} will have the given modulus bit length and prime certainty.
    +   * <p>
    +   * The probability that the generated keys represent primes will exceed (1 - (1/2)<sup>{@code certainty}</sup>). The execution time of this constructor is
    +   * proportional to the value of this parameter.
    +   * 
    +   * @param bitLength
    +   *          The bit length of the resulting modulus {@code N}.
    +   * @param certainty
    +   *          The probability that the new {@code p} and {@code q} represent prime numbers.
    +   * @throws IllegalArgumentException
    +   *           If the {@code certainty} is less than the system allowed lower bound.
        */
    -  public Paillier(int bitLengthInput, int certainty) throws PIRException
    +  public Paillier(int bitLength, int certainty)
       {
    -    this(bitLengthInput, certainty, -1);
    +    this(bitLength, certainty, -1);
       }
     
       /**
    -   * Constructor to generate keys given the desired bitLength and prime certainty value
    +   * Constructs a Paillier algorithm with generated keys and optionally ensures a certain bit is set in the modulus.
        * <p>
    -   * Can optionally, ensure a certain bit is set in the modulus (if ensureBitSet != 0)
    +   * The generated keys {@code p} and {@code q} will have the given modulus bit length and prime certainty.
    --- End diff --
    
    Fixed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-pirk pull request #102: [Minor] Enhancements to Paillier class.

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/incubator-pirk/pull/102


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-pirk pull request #102: [Minor] Enhancements to Paillier class.

Posted by ellisonanne <gi...@git.apache.org>.
Github user ellisonanne commented on a diff in the pull request:

    https://github.com/apache/incubator-pirk/pull/102#discussion_r80806778
  
    --- Diff: src/main/java/org/apache/pirk/encryption/Paillier.java ---
    @@ -95,140 +95,185 @@
         }
       }
     
    -  private BigInteger p = null; // large prime
    -  private BigInteger q = null; // large prime
    -  private BigInteger N = null; // N=pq, RSA modulus
    +  private BigInteger p; // large prime
    +  private BigInteger q; // large prime
    +  private BigInteger N; // N=pq, RSA modulus
     
    -  private BigInteger NSquared = null; // NSquared = N^2
    -  private BigInteger lambdaN = null; // lambda(N) = lcm(p-1,q-1), Carmichael function of N
    -  private BigInteger w = null; // lambda(N)^-1 mod N
    +  private BigInteger NSquared; // NSquared = N^2
    +  private BigInteger lambdaN; // lambda(N) = lcm(p-1,q-1), Carmichael function of N
    +  private BigInteger w; // lambda(N)^-1 mod N
     
    -  private int bitLength = 0; // bit length of the modulus N
    +  private final int bitLength; // bit length of the modulus N
     
       /**
    -   * Constructor with all parameters p,q, and bitLengthInput specified
    -   * <p>
    -   * Only used, at this point, for testing purposes
    -   *
    +   * Creates a Paillier algorithm with all parameters specified.
    +   * 
    +   * @param p
    +   *          First large prime.
    +   * @param q
    +   *          Second large prime.
    +   * @param bitLength
    +   *          Bit length of the modulus {@code N}.
    +   * @throws IllegalArgumentException
    +   *           If {@code p} or {@code q} do not satisfy primality constraints.
        */
    -  public Paillier(BigInteger pInput, BigInteger qInput, int bitLengthInput) throws PIRException
    +  public Paillier(BigInteger p, BigInteger q, int bitLength)
       {
    -    bitLength = bitLengthInput;
    +    this.bitLength = bitLength;
     
         // Verify the prime conditions are satisfied
         int primeCertainty = SystemConfiguration.getIntProperty("pir.primeCertainty", 128);
         BigInteger three = BigInteger.valueOf(3);
    -    if ((pInput.compareTo(three) < 0) || (qInput.compareTo(three) < 0) || pInput.equals(qInput) || !pInput.isProbablePrime(primeCertainty)
    -        || !qInput.isProbablePrime(primeCertainty))
    +    if ((p.compareTo(three) < 0) || (q.compareTo(three) < 0) || p.equals(q) || !p.isProbablePrime(primeCertainty) || !q.isProbablePrime(primeCertainty))
         {
    -      throw new PIRException("pInput = " + pInput + " qInput = " + qInput + " do not satisfy primality constraints");
    +      throw new IllegalArgumentException("p = " + p + " q = " + q + " do not satisfy primality constraints");
         }
     
    -    p = pInput;
    -    q = qInput;
    +    this.p = p;
    +    this.q = q;
     
    -    N = p.multiply(q);
    +    this.N = p.multiply(q);
     
         setDerivativeElements();
     
         logger.info("Parameters = " + parametersToString());
       }
     
       /**
    -   * Constructor to generate keys given the desired bitLength and prime certainty value
    +   * Constructs a Paillier algorithm with generated keys.
        * <p>
    -   * 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.
    -   *
    +   * The generated keys {@code p} and {@code q} will have the given modulus bit length and prime certainty.
    --- End diff --
    
    Minor correction to the javadoc: ...'will have the given modulus bit length...' needs to be ...'will have half of the given modulus bit length'...


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-pirk pull request #102: [Minor] Enhancements to Paillier class.

Posted by ellisonanne <gi...@git.apache.org>.
Github user ellisonanne commented on a diff in the pull request:

    https://github.com/apache/incubator-pirk/pull/102#discussion_r80807342
  
    --- Diff: src/main/java/org/apache/pirk/encryption/Paillier.java ---
    @@ -95,140 +95,185 @@
         }
       }
     
    -  private BigInteger p = null; // large prime
    -  private BigInteger q = null; // large prime
    -  private BigInteger N = null; // N=pq, RSA modulus
    +  private BigInteger p; // large prime
    +  private BigInteger q; // large prime
    +  private BigInteger N; // N=pq, RSA modulus
     
    -  private BigInteger NSquared = null; // NSquared = N^2
    -  private BigInteger lambdaN = null; // lambda(N) = lcm(p-1,q-1), Carmichael function of N
    -  private BigInteger w = null; // lambda(N)^-1 mod N
    +  private BigInteger NSquared; // NSquared = N^2
    +  private BigInteger lambdaN; // lambda(N) = lcm(p-1,q-1), Carmichael function of N
    +  private BigInteger w; // lambda(N)^-1 mod N
     
    -  private int bitLength = 0; // bit length of the modulus N
    +  private final int bitLength; // bit length of the modulus N
     
       /**
    -   * Constructor with all parameters p,q, and bitLengthInput specified
    -   * <p>
    -   * Only used, at this point, for testing purposes
    -   *
    +   * Creates a Paillier algorithm with all parameters specified.
    +   * 
    +   * @param p
    +   *          First large prime.
    +   * @param q
    +   *          Second large prime.
    +   * @param bitLength
    +   *          Bit length of the modulus {@code N}.
    +   * @throws IllegalArgumentException
    +   *           If {@code p} or {@code q} do not satisfy primality constraints.
        */
    -  public Paillier(BigInteger pInput, BigInteger qInput, int bitLengthInput) throws PIRException
    +  public Paillier(BigInteger p, BigInteger q, int bitLength)
       {
    -    bitLength = bitLengthInput;
    +    this.bitLength = bitLength;
     
         // Verify the prime conditions are satisfied
         int primeCertainty = SystemConfiguration.getIntProperty("pir.primeCertainty", 128);
         BigInteger three = BigInteger.valueOf(3);
    -    if ((pInput.compareTo(three) < 0) || (qInput.compareTo(three) < 0) || pInput.equals(qInput) || !pInput.isProbablePrime(primeCertainty)
    -        || !qInput.isProbablePrime(primeCertainty))
    +    if ((p.compareTo(three) < 0) || (q.compareTo(three) < 0) || p.equals(q) || !p.isProbablePrime(primeCertainty) || !q.isProbablePrime(primeCertainty))
         {
    -      throw new PIRException("pInput = " + pInput + " qInput = " + qInput + " do not satisfy primality constraints");
    +      throw new IllegalArgumentException("p = " + p + " q = " + q + " do not satisfy primality constraints");
         }
     
    -    p = pInput;
    -    q = qInput;
    +    this.p = p;
    +    this.q = q;
     
    -    N = p.multiply(q);
    +    this.N = p.multiply(q);
     
         setDerivativeElements();
     
         logger.info("Parameters = " + parametersToString());
       }
     
       /**
    -   * Constructor to generate keys given the desired bitLength and prime certainty value
    +   * Constructs a Paillier algorithm with generated keys.
        * <p>
    -   * 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.
    -   *
    +   * The generated keys {@code p} and {@code q} will have the given modulus bit length and prime certainty.
    +   * <p>
    +   * The probability that the generated keys represent primes will exceed (1 - (1/2)<sup>{@code certainty}</sup>). The execution time of this constructor is
    +   * proportional to the value of this parameter.
    +   * 
    +   * @param bitLength
    +   *          The bit length of the resulting modulus {@code N}.
    +   * @param certainty
    +   *          The probability that the new {@code p} and {@code q} represent prime numbers.
    +   * @throws IllegalArgumentException
    +   *           If the {@code certainty} is less than the system allowed lower bound.
        */
    -  public Paillier(int bitLengthInput, int certainty) throws PIRException
    +  public Paillier(int bitLength, int certainty)
       {
    -    this(bitLengthInput, certainty, -1);
    +    this(bitLength, certainty, -1);
       }
     
       /**
    -   * Constructor to generate keys given the desired bitLength and prime certainty value
    +   * Constructs a Paillier algorithm with generated keys and optionally ensures a certain bit is set in the modulus.
        * <p>
    -   * Can optionally, ensure a certain bit is set in the modulus (if ensureBitSet != 0)
    +   * The generated keys {@code p} and {@code q} will have the given modulus bit length and prime certainty.
        * <p>
    -   * 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.
    -   *
    +   * The probability that the generated keys represent primes will exceed (1 - (1/2)<sup>{@code certainty}</sup>). The execution time of this constructor is
    +   * proportional to the value of this parameter.
    +   * <p>
    +   * When ensureBitSet > -1 the value of bit "{@code ensureBitSet}" in modulus {@code N} will be set.
    +   * 
    +   * @param bitLength
    +   *          The bit length of the resulting modulus {@code N}.
    +   * @param certainty
    +   *          The probability that the new {@code p} and {@code q} represent prime numbers.
    +   * @param ensureBitSet
    +   *          index of bit in {@code N} to ensure is set.
    +   * @throws IllegalArgumentException
    +   *           If the {@code certainty} is less than the system allowed lower bound, or the index of {@code ensureBitSet} is greater than the {@code bitLength}.
        */
    -  public Paillier(int bitLengthInput, int certainty, int ensureBitSet) throws PIRException
    +  public Paillier(int bitLength, int certainty, int ensureBitSet)
       {
    -    bitLength = bitLengthInput;
    -
         int systemPrimeCertainty = SystemConfiguration.getIntProperty("pir.primeCertainty", 128);
         if (certainty < systemPrimeCertainty)
         {
    -      throw new PIRException("Input certainty = " + certainty + " is less than allowed system lower bound = " + systemPrimeCertainty);
    +      throw new IllegalArgumentException("Input certainty = " + certainty + " is less than allowed system lower bound = " + systemPrimeCertainty);
         }
    -    if (ensureBitSet >= bitLengthInput)
    +    if (ensureBitSet >= bitLength)
         {
    -      throw new PIRException("ensureBitSet = " + ensureBitSet + " must be less than bitLengthInput = " + bitLengthInput);
    +      throw new IllegalArgumentException("ensureBitSet = " + ensureBitSet + " must be less than bitLengthInput = " + bitLength);
         }
    -    generateKeys(certainty, ensureBitSet);
    +    this.bitLength = bitLength;
    +    generateKeys(bitLength, certainty, ensureBitSet);
         setDerivativeElements();
     
         logger.info("Parameters = " + parametersToString());
       }
     
    +  /**
    +   * Returns the value of the large prime {@code p}.
    +   * 
    +   * @return p.
    +   */
       public BigInteger getP()
       {
         return p;
       }
     
    +  /**
    +   * Returns the value of the large prime {@code q}.
    +   * 
    +   * @return q.
    +   */
       public BigInteger getQ()
       {
         return q;
       }
     
    +  /**
    +   * Returns the RSA modulus value {@code N}.
    +   * 
    +   * @return N, the product of {@code p} and {@code q}.
    +   */
       public BigInteger getN()
       {
         return N;
       }
     
    +  /**
    +   * Returns the value of {@code N}<sup>2</sup>.
    +   * 
    +   * @return N squared.
    +   */
       public BigInteger getNSquared()
       {
         return NSquared;
       }
     
    +  /**
    +   * Returns the value of Carmichael's function at {@code N}.
    +   * <p>
    +   * The Carmichael function of {@code N} is the lowest common multiple of {@code p-1} and {@code q-1},
    --- End diff --
    
    LCM = Least Common Multiple (maybe 'lowest common multiple' is British terminology? ;))


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-pirk pull request #102: [Minor] Enhancements to Paillier class.

Posted by tellison <gi...@git.apache.org>.
Github user tellison commented on a diff in the pull request:

    https://github.com/apache/incubator-pirk/pull/102#discussion_r80863023
  
    --- Diff: src/main/java/org/apache/pirk/encryption/Paillier.java ---
    @@ -95,140 +95,185 @@
         }
       }
     
    -  private BigInteger p = null; // large prime
    -  private BigInteger q = null; // large prime
    -  private BigInteger N = null; // N=pq, RSA modulus
    +  private BigInteger p; // large prime
    +  private BigInteger q; // large prime
    +  private BigInteger N; // N=pq, RSA modulus
     
    -  private BigInteger NSquared = null; // NSquared = N^2
    -  private BigInteger lambdaN = null; // lambda(N) = lcm(p-1,q-1), Carmichael function of N
    -  private BigInteger w = null; // lambda(N)^-1 mod N
    +  private BigInteger NSquared; // NSquared = N^2
    +  private BigInteger lambdaN; // lambda(N) = lcm(p-1,q-1), Carmichael function of N
    +  private BigInteger w; // lambda(N)^-1 mod N
     
    -  private int bitLength = 0; // bit length of the modulus N
    +  private final int bitLength; // bit length of the modulus N
     
       /**
    -   * Constructor with all parameters p,q, and bitLengthInput specified
    -   * <p>
    -   * Only used, at this point, for testing purposes
    -   *
    +   * Creates a Paillier algorithm with all parameters specified.
    +   * 
    +   * @param p
    +   *          First large prime.
    +   * @param q
    +   *          Second large prime.
    +   * @param bitLength
    +   *          Bit length of the modulus {@code N}.
    +   * @throws IllegalArgumentException
    +   *           If {@code p} or {@code q} do not satisfy primality constraints.
        */
    -  public Paillier(BigInteger pInput, BigInteger qInput, int bitLengthInput) throws PIRException
    +  public Paillier(BigInteger p, BigInteger q, int bitLength)
       {
    -    bitLength = bitLengthInput;
    +    this.bitLength = bitLength;
     
         // Verify the prime conditions are satisfied
         int primeCertainty = SystemConfiguration.getIntProperty("pir.primeCertainty", 128);
         BigInteger three = BigInteger.valueOf(3);
    -    if ((pInput.compareTo(three) < 0) || (qInput.compareTo(three) < 0) || pInput.equals(qInput) || !pInput.isProbablePrime(primeCertainty)
    -        || !qInput.isProbablePrime(primeCertainty))
    +    if ((p.compareTo(three) < 0) || (q.compareTo(three) < 0) || p.equals(q) || !p.isProbablePrime(primeCertainty) || !q.isProbablePrime(primeCertainty))
         {
    -      throw new PIRException("pInput = " + pInput + " qInput = " + qInput + " do not satisfy primality constraints");
    +      throw new IllegalArgumentException("p = " + p + " q = " + q + " do not satisfy primality constraints");
         }
     
    -    p = pInput;
    -    q = qInput;
    +    this.p = p;
    +    this.q = q;
     
    -    N = p.multiply(q);
    +    this.N = p.multiply(q);
     
         setDerivativeElements();
     
         logger.info("Parameters = " + parametersToString());
       }
     
       /**
    -   * Constructor to generate keys given the desired bitLength and prime certainty value
    +   * Constructs a Paillier algorithm with generated keys.
        * <p>
    -   * 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.
    -   *
    +   * The generated keys {@code p} and {@code q} will have the given modulus bit length and prime certainty.
    +   * <p>
    +   * The probability that the generated keys represent primes will exceed (1 - (1/2)<sup>{@code certainty}</sup>). The execution time of this constructor is
    +   * proportional to the value of this parameter.
    +   * 
    +   * @param bitLength
    +   *          The bit length of the resulting modulus {@code N}.
    +   * @param certainty
    +   *          The probability that the new {@code p} and {@code q} represent prime numbers.
    +   * @throws IllegalArgumentException
    +   *           If the {@code certainty} is less than the system allowed lower bound.
        */
    -  public Paillier(int bitLengthInput, int certainty) throws PIRException
    +  public Paillier(int bitLength, int certainty)
       {
    -    this(bitLengthInput, certainty, -1);
    +    this(bitLength, certainty, -1);
       }
     
       /**
    -   * Constructor to generate keys given the desired bitLength and prime certainty value
    +   * Constructs a Paillier algorithm with generated keys and optionally ensures a certain bit is set in the modulus.
        * <p>
    -   * Can optionally, ensure a certain bit is set in the modulus (if ensureBitSet != 0)
    +   * The generated keys {@code p} and {@code q} will have the given modulus bit length and prime certainty.
        * <p>
    -   * 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.
    -   *
    +   * The probability that the generated keys represent primes will exceed (1 - (1/2)<sup>{@code certainty}</sup>). The execution time of this constructor is
    +   * proportional to the value of this parameter.
    +   * <p>
    +   * When ensureBitSet > -1 the value of bit "{@code ensureBitSet}" in modulus {@code N} will be set.
    +   * 
    +   * @param bitLength
    +   *          The bit length of the resulting modulus {@code N}.
    +   * @param certainty
    +   *          The probability that the new {@code p} and {@code q} represent prime numbers.
    +   * @param ensureBitSet
    +   *          index of bit in {@code N} to ensure is set.
    +   * @throws IllegalArgumentException
    +   *           If the {@code certainty} is less than the system allowed lower bound, or the index of {@code ensureBitSet} is greater than the {@code bitLength}.
        */
    -  public Paillier(int bitLengthInput, int certainty, int ensureBitSet) throws PIRException
    +  public Paillier(int bitLength, int certainty, int ensureBitSet)
       {
    -    bitLength = bitLengthInput;
    -
         int systemPrimeCertainty = SystemConfiguration.getIntProperty("pir.primeCertainty", 128);
         if (certainty < systemPrimeCertainty)
         {
    -      throw new PIRException("Input certainty = " + certainty + " is less than allowed system lower bound = " + systemPrimeCertainty);
    +      throw new IllegalArgumentException("Input certainty = " + certainty + " is less than allowed system lower bound = " + systemPrimeCertainty);
         }
    -    if (ensureBitSet >= bitLengthInput)
    +    if (ensureBitSet >= bitLength)
         {
    -      throw new PIRException("ensureBitSet = " + ensureBitSet + " must be less than bitLengthInput = " + bitLengthInput);
    +      throw new IllegalArgumentException("ensureBitSet = " + ensureBitSet + " must be less than bitLengthInput = " + bitLength);
         }
    -    generateKeys(certainty, ensureBitSet);
    +    this.bitLength = bitLength;
    +    generateKeys(bitLength, certainty, ensureBitSet);
    --- End diff --
    
    I changed ```generateKeys``` to take ```bitLength``` as a parameter rather than the code relying on the ordering of setting the ```bitLength``` instance variable from the constructor's parameter and calling the method - it just makes ```generateKeys``` self-sufficient should it ever be called from a new constructor/method.  A minor style point I agree.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-pirk pull request #102: [Minor] Enhancements to Paillier class.

Posted by tellison <gi...@git.apache.org>.
Github user tellison commented on a diff in the pull request:

    https://github.com/apache/incubator-pirk/pull/102#discussion_r80862831
  
    --- Diff: src/main/java/org/apache/pirk/encryption/Paillier.java ---
    @@ -95,140 +95,185 @@
         }
       }
     
    -  private BigInteger p = null; // large prime
    -  private BigInteger q = null; // large prime
    -  private BigInteger N = null; // N=pq, RSA modulus
    +  private BigInteger p; // large prime
    +  private BigInteger q; // large prime
    +  private BigInteger N; // N=pq, RSA modulus
     
    -  private BigInteger NSquared = null; // NSquared = N^2
    -  private BigInteger lambdaN = null; // lambda(N) = lcm(p-1,q-1), Carmichael function of N
    -  private BigInteger w = null; // lambda(N)^-1 mod N
    +  private BigInteger NSquared; // NSquared = N^2
    +  private BigInteger lambdaN; // lambda(N) = lcm(p-1,q-1), Carmichael function of N
    +  private BigInteger w; // lambda(N)^-1 mod N
     
    -  private int bitLength = 0; // bit length of the modulus N
    +  private final int bitLength; // bit length of the modulus N
     
       /**
    -   * Constructor with all parameters p,q, and bitLengthInput specified
    -   * <p>
    -   * Only used, at this point, for testing purposes
    -   *
    +   * Creates a Paillier algorithm with all parameters specified.
    +   * 
    +   * @param p
    +   *          First large prime.
    +   * @param q
    +   *          Second large prime.
    +   * @param bitLength
    +   *          Bit length of the modulus {@code N}.
    +   * @throws IllegalArgumentException
    +   *           If {@code p} or {@code q} do not satisfy primality constraints.
        */
    -  public Paillier(BigInteger pInput, BigInteger qInput, int bitLengthInput) throws PIRException
    +  public Paillier(BigInteger p, BigInteger q, int bitLength)
       {
    -    bitLength = bitLengthInput;
    +    this.bitLength = bitLength;
     
         // Verify the prime conditions are satisfied
         int primeCertainty = SystemConfiguration.getIntProperty("pir.primeCertainty", 128);
         BigInteger three = BigInteger.valueOf(3);
    -    if ((pInput.compareTo(three) < 0) || (qInput.compareTo(three) < 0) || pInput.equals(qInput) || !pInput.isProbablePrime(primeCertainty)
    -        || !qInput.isProbablePrime(primeCertainty))
    +    if ((p.compareTo(three) < 0) || (q.compareTo(three) < 0) || p.equals(q) || !p.isProbablePrime(primeCertainty) || !q.isProbablePrime(primeCertainty))
         {
    -      throw new PIRException("pInput = " + pInput + " qInput = " + qInput + " do not satisfy primality constraints");
    +      throw new IllegalArgumentException("p = " + p + " q = " + q + " do not satisfy primality constraints");
         }
     
    -    p = pInput;
    -    q = qInput;
    +    this.p = p;
    +    this.q = q;
     
    -    N = p.multiply(q);
    +    this.N = p.multiply(q);
     
         setDerivativeElements();
     
         logger.info("Parameters = " + parametersToString());
       }
     
       /**
    -   * Constructor to generate keys given the desired bitLength and prime certainty value
    +   * Constructs a Paillier algorithm with generated keys.
        * <p>
    -   * 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.
    -   *
    +   * The generated keys {@code p} and {@code q} will have the given modulus bit length and prime certainty.
    +   * <p>
    +   * The probability that the generated keys represent primes will exceed (1 - (1/2)<sup>{@code certainty}</sup>). The execution time of this constructor is
    +   * proportional to the value of this parameter.
    +   * 
    +   * @param bitLength
    +   *          The bit length of the resulting modulus {@code N}.
    +   * @param certainty
    +   *          The probability that the new {@code p} and {@code q} represent prime numbers.
    +   * @throws IllegalArgumentException
    +   *           If the {@code certainty} is less than the system allowed lower bound.
        */
    -  public Paillier(int bitLengthInput, int certainty) throws PIRException
    +  public Paillier(int bitLength, int certainty)
       {
    -    this(bitLengthInput, certainty, -1);
    +    this(bitLength, certainty, -1);
       }
     
       /**
    -   * Constructor to generate keys given the desired bitLength and prime certainty value
    +   * Constructs a Paillier algorithm with generated keys and optionally ensures a certain bit is set in the modulus.
        * <p>
    -   * Can optionally, ensure a certain bit is set in the modulus (if ensureBitSet != 0)
    +   * The generated keys {@code p} and {@code q} will have the given modulus bit length and prime certainty.
        * <p>
    -   * 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.
    -   *
    +   * The probability that the generated keys represent primes will exceed (1 - (1/2)<sup>{@code certainty}</sup>). The execution time of this constructor is
    +   * proportional to the value of this parameter.
    +   * <p>
    +   * When ensureBitSet > -1 the value of bit "{@code ensureBitSet}" in modulus {@code N} will be set.
    +   * 
    +   * @param bitLength
    +   *          The bit length of the resulting modulus {@code N}.
    +   * @param certainty
    +   *          The probability that the new {@code p} and {@code q} represent prime numbers.
    +   * @param ensureBitSet
    +   *          index of bit in {@code N} to ensure is set.
    +   * @throws IllegalArgumentException
    +   *           If the {@code certainty} is less than the system allowed lower bound, or the index of {@code ensureBitSet} is greater than the {@code bitLength}.
        */
    -  public Paillier(int bitLengthInput, int certainty, int ensureBitSet) throws PIRException
    +  public Paillier(int bitLength, int certainty, int ensureBitSet)
       {
    -    bitLength = bitLengthInput;
    -
         int systemPrimeCertainty = SystemConfiguration.getIntProperty("pir.primeCertainty", 128);
         if (certainty < systemPrimeCertainty)
         {
    -      throw new PIRException("Input certainty = " + certainty + " is less than allowed system lower bound = " + systemPrimeCertainty);
    +      throw new IllegalArgumentException("Input certainty = " + certainty + " is less than allowed system lower bound = " + systemPrimeCertainty);
         }
    -    if (ensureBitSet >= bitLengthInput)
    +    if (ensureBitSet >= bitLength)
         {
    -      throw new PIRException("ensureBitSet = " + ensureBitSet + " must be less than bitLengthInput = " + bitLengthInput);
    +      throw new IllegalArgumentException("ensureBitSet = " + ensureBitSet + " must be less than bitLengthInput = " + bitLength);
         }
    -    generateKeys(certainty, ensureBitSet);
    +    this.bitLength = bitLength;
    +    generateKeys(bitLength, certainty, ensureBitSet);
         setDerivativeElements();
     
         logger.info("Parameters = " + parametersToString());
       }
     
    +  /**
    +   * Returns the value of the large prime {@code p}.
    +   * 
    +   * @return p.
    +   */
       public BigInteger getP()
       {
         return p;
       }
     
    +  /**
    +   * Returns the value of the large prime {@code q}.
    +   * 
    +   * @return q.
    +   */
       public BigInteger getQ()
       {
         return q;
       }
     
    +  /**
    +   * Returns the RSA modulus value {@code N}.
    +   * 
    +   * @return N, the product of {@code p} and {@code q}.
    +   */
       public BigInteger getN()
       {
         return N;
       }
     
    +  /**
    +   * Returns the value of {@code N}<sup>2</sup>.
    +   * 
    +   * @return N squared.
    +   */
       public BigInteger getNSquared()
       {
         return NSquared;
       }
     
    +  /**
    +   * Returns the value of Carmichael's function at {@code N}.
    +   * <p>
    +   * The Carmichael function of {@code N} is the lowest common multiple of {@code p-1} and {@code q-1},
    --- End diff --
    
    Americanized ;-)


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-pirk pull request #102: [Minor] Enhancements to Paillier class.

Posted by ellisonanne <gi...@git.apache.org>.
Github user ellisonanne commented on a diff in the pull request:

    https://github.com/apache/incubator-pirk/pull/102#discussion_r80808304
  
    --- Diff: src/main/java/org/apache/pirk/encryption/Paillier.java ---
    @@ -95,140 +95,185 @@
         }
       }
     
    -  private BigInteger p = null; // large prime
    -  private BigInteger q = null; // large prime
    -  private BigInteger N = null; // N=pq, RSA modulus
    +  private BigInteger p; // large prime
    +  private BigInteger q; // large prime
    +  private BigInteger N; // N=pq, RSA modulus
     
    -  private BigInteger NSquared = null; // NSquared = N^2
    -  private BigInteger lambdaN = null; // lambda(N) = lcm(p-1,q-1), Carmichael function of N
    -  private BigInteger w = null; // lambda(N)^-1 mod N
    +  private BigInteger NSquared; // NSquared = N^2
    +  private BigInteger lambdaN; // lambda(N) = lcm(p-1,q-1), Carmichael function of N
    +  private BigInteger w; // lambda(N)^-1 mod N
     
    -  private int bitLength = 0; // bit length of the modulus N
    +  private final int bitLength; // bit length of the modulus N
     
       /**
    -   * Constructor with all parameters p,q, and bitLengthInput specified
    -   * <p>
    -   * Only used, at this point, for testing purposes
    -   *
    +   * Creates a Paillier algorithm with all parameters specified.
    +   * 
    +   * @param p
    +   *          First large prime.
    +   * @param q
    +   *          Second large prime.
    +   * @param bitLength
    +   *          Bit length of the modulus {@code N}.
    +   * @throws IllegalArgumentException
    +   *           If {@code p} or {@code q} do not satisfy primality constraints.
        */
    -  public Paillier(BigInteger pInput, BigInteger qInput, int bitLengthInput) throws PIRException
    +  public Paillier(BigInteger p, BigInteger q, int bitLength)
       {
    -    bitLength = bitLengthInput;
    +    this.bitLength = bitLength;
     
         // Verify the prime conditions are satisfied
         int primeCertainty = SystemConfiguration.getIntProperty("pir.primeCertainty", 128);
         BigInteger three = BigInteger.valueOf(3);
    -    if ((pInput.compareTo(three) < 0) || (qInput.compareTo(three) < 0) || pInput.equals(qInput) || !pInput.isProbablePrime(primeCertainty)
    -        || !qInput.isProbablePrime(primeCertainty))
    +    if ((p.compareTo(three) < 0) || (q.compareTo(three) < 0) || p.equals(q) || !p.isProbablePrime(primeCertainty) || !q.isProbablePrime(primeCertainty))
         {
    -      throw new PIRException("pInput = " + pInput + " qInput = " + qInput + " do not satisfy primality constraints");
    +      throw new IllegalArgumentException("p = " + p + " q = " + q + " do not satisfy primality constraints");
         }
     
    -    p = pInput;
    -    q = qInput;
    +    this.p = p;
    +    this.q = q;
     
    -    N = p.multiply(q);
    +    this.N = p.multiply(q);
     
         setDerivativeElements();
     
         logger.info("Parameters = " + parametersToString());
       }
     
       /**
    -   * Constructor to generate keys given the desired bitLength and prime certainty value
    +   * Constructs a Paillier algorithm with generated keys.
        * <p>
    -   * 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.
    -   *
    +   * The generated keys {@code p} and {@code q} will have the given modulus bit length and prime certainty.
    +   * <p>
    +   * The probability that the generated keys represent primes will exceed (1 - (1/2)<sup>{@code certainty}</sup>). The execution time of this constructor is
    +   * proportional to the value of this parameter.
    +   * 
    +   * @param bitLength
    +   *          The bit length of the resulting modulus {@code N}.
    +   * @param certainty
    +   *          The probability that the new {@code p} and {@code q} represent prime numbers.
    +   * @throws IllegalArgumentException
    +   *           If the {@code certainty} is less than the system allowed lower bound.
        */
    -  public Paillier(int bitLengthInput, int certainty) throws PIRException
    +  public Paillier(int bitLength, int certainty)
       {
    -    this(bitLengthInput, certainty, -1);
    +    this(bitLength, certainty, -1);
       }
     
       /**
    -   * Constructor to generate keys given the desired bitLength and prime certainty value
    +   * Constructs a Paillier algorithm with generated keys and optionally ensures a certain bit is set in the modulus.
        * <p>
    -   * Can optionally, ensure a certain bit is set in the modulus (if ensureBitSet != 0)
    +   * The generated keys {@code p} and {@code q} will have the given modulus bit length and prime certainty.
        * <p>
    -   * 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.
    -   *
    +   * The probability that the generated keys represent primes will exceed (1 - (1/2)<sup>{@code certainty}</sup>). The execution time of this constructor is
    +   * proportional to the value of this parameter.
    +   * <p>
    +   * When ensureBitSet > -1 the value of bit "{@code ensureBitSet}" in modulus {@code N} will be set.
    +   * 
    +   * @param bitLength
    +   *          The bit length of the resulting modulus {@code N}.
    +   * @param certainty
    +   *          The probability that the new {@code p} and {@code q} represent prime numbers.
    +   * @param ensureBitSet
    +   *          index of bit in {@code N} to ensure is set.
    +   * @throws IllegalArgumentException
    +   *           If the {@code certainty} is less than the system allowed lower bound, or the index of {@code ensureBitSet} is greater than the {@code bitLength}.
        */
    -  public Paillier(int bitLengthInput, int certainty, int ensureBitSet) throws PIRException
    +  public Paillier(int bitLength, int certainty, int ensureBitSet)
       {
    -    bitLength = bitLengthInput;
    -
         int systemPrimeCertainty = SystemConfiguration.getIntProperty("pir.primeCertainty", 128);
         if (certainty < systemPrimeCertainty)
         {
    -      throw new PIRException("Input certainty = " + certainty + " is less than allowed system lower bound = " + systemPrimeCertainty);
    +      throw new IllegalArgumentException("Input certainty = " + certainty + " is less than allowed system lower bound = " + systemPrimeCertainty);
         }
    -    if (ensureBitSet >= bitLengthInput)
    +    if (ensureBitSet >= bitLength)
         {
    -      throw new PIRException("ensureBitSet = " + ensureBitSet + " must be less than bitLengthInput = " + bitLengthInput);
    +      throw new IllegalArgumentException("ensureBitSet = " + ensureBitSet + " must be less than bitLengthInput = " + bitLength);
         }
    -    generateKeys(certainty, ensureBitSet);
    +    this.bitLength = bitLength;
    +    generateKeys(bitLength, certainty, ensureBitSet);
         setDerivativeElements();
     
         logger.info("Parameters = " + parametersToString());
       }
     
    +  /**
    +   * Returns the value of the large prime {@code p}.
    +   * 
    +   * @return p.
    +   */
       public BigInteger getP()
       {
         return p;
       }
     
    +  /**
    +   * Returns the value of the large prime {@code q}.
    +   * 
    +   * @return q.
    +   */
       public BigInteger getQ()
       {
         return q;
       }
     
    +  /**
    +   * Returns the RSA modulus value {@code N}.
    +   * 
    +   * @return N, the product of {@code p} and {@code q}.
    +   */
       public BigInteger getN()
       {
         return N;
       }
     
    +  /**
    +   * Returns the value of {@code N}<sup>2</sup>.
    +   * 
    +   * @return N squared.
    +   */
       public BigInteger getNSquared()
       {
         return NSquared;
       }
     
    +  /**
    +   * Returns the value of Carmichael's function at {@code N}.
    +   * <p>
    +   * The Carmichael function of {@code N} is the lowest common multiple of {@code p-1} and {@code q-1},
    +   * 
    +   * @return Carmichael's function at {@code N}.
    +   */
       public BigInteger getLambdaN()
       {
         return lambdaN;
       }
     
    +  /**
    +   * Returns the bit length of the modulus {@code N}.
    +   * 
    +   * @return the bit length, as an integer.
    +   */
       public int getBitLength()
       {
         return bitLength;
       }
     
    -  private void generateKeys(int certainty, int ensureBitSet)
    +  private void generateKeys(int bitLength, int certainty, final int ensureBitSet)
       {
    -    if (ensureBitSet != -1)
    +    getKeys(bitLength, certainty);
    +
    +    if (ensureBitSet > -1)
         {
    -      while (true)
    +      while (!N.testBit(ensureBitSet))
           {
    -        getKeys(certainty);
    -        if (N.testBit(ensureBitSet))
    -        {
    -          logger.info("testBit true\n N = " + N.toString(2));
    -          break;
    -        }
    -        else
    -        {
    -          logger.info("testBit false\n N = " + N.toString(2));
    -        }
    +        logger.info("testBit false\n N = " + N.toString(2));
    +        getKeys(bitLength, certainty);
           }
    -    }
    -    else
    -    {
    -      getKeys(certainty);
    +      logger.info("testBit true\n N = " + N.toString(2));
         }
       }
     
    -  private void getKeys(int certainty)
    +  private void getKeys(int bitLength, int certainty)
    --- End diff --
    
    Why change the signature of getKeys and pass bitLength as a param?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-pirk pull request #102: [Minor] Enhancements to Paillier class.

Posted by ellisonanne <gi...@git.apache.org>.
Github user ellisonanne commented on a diff in the pull request:

    https://github.com/apache/incubator-pirk/pull/102#discussion_r80807988
  
    --- Diff: src/main/java/org/apache/pirk/encryption/Paillier.java ---
    @@ -95,140 +95,185 @@
         }
       }
     
    -  private BigInteger p = null; // large prime
    -  private BigInteger q = null; // large prime
    -  private BigInteger N = null; // N=pq, RSA modulus
    +  private BigInteger p; // large prime
    +  private BigInteger q; // large prime
    +  private BigInteger N; // N=pq, RSA modulus
     
    -  private BigInteger NSquared = null; // NSquared = N^2
    -  private BigInteger lambdaN = null; // lambda(N) = lcm(p-1,q-1), Carmichael function of N
    -  private BigInteger w = null; // lambda(N)^-1 mod N
    +  private BigInteger NSquared; // NSquared = N^2
    +  private BigInteger lambdaN; // lambda(N) = lcm(p-1,q-1), Carmichael function of N
    +  private BigInteger w; // lambda(N)^-1 mod N
     
    -  private int bitLength = 0; // bit length of the modulus N
    +  private final int bitLength; // bit length of the modulus N
     
       /**
    -   * Constructor with all parameters p,q, and bitLengthInput specified
    -   * <p>
    -   * Only used, at this point, for testing purposes
    -   *
    +   * Creates a Paillier algorithm with all parameters specified.
    +   * 
    +   * @param p
    +   *          First large prime.
    +   * @param q
    +   *          Second large prime.
    +   * @param bitLength
    +   *          Bit length of the modulus {@code N}.
    +   * @throws IllegalArgumentException
    +   *           If {@code p} or {@code q} do not satisfy primality constraints.
        */
    -  public Paillier(BigInteger pInput, BigInteger qInput, int bitLengthInput) throws PIRException
    +  public Paillier(BigInteger p, BigInteger q, int bitLength)
       {
    -    bitLength = bitLengthInput;
    +    this.bitLength = bitLength;
     
         // Verify the prime conditions are satisfied
         int primeCertainty = SystemConfiguration.getIntProperty("pir.primeCertainty", 128);
         BigInteger three = BigInteger.valueOf(3);
    -    if ((pInput.compareTo(three) < 0) || (qInput.compareTo(three) < 0) || pInput.equals(qInput) || !pInput.isProbablePrime(primeCertainty)
    -        || !qInput.isProbablePrime(primeCertainty))
    +    if ((p.compareTo(three) < 0) || (q.compareTo(three) < 0) || p.equals(q) || !p.isProbablePrime(primeCertainty) || !q.isProbablePrime(primeCertainty))
         {
    -      throw new PIRException("pInput = " + pInput + " qInput = " + qInput + " do not satisfy primality constraints");
    +      throw new IllegalArgumentException("p = " + p + " q = " + q + " do not satisfy primality constraints");
         }
     
    -    p = pInput;
    -    q = qInput;
    +    this.p = p;
    +    this.q = q;
     
    -    N = p.multiply(q);
    +    this.N = p.multiply(q);
     
         setDerivativeElements();
     
         logger.info("Parameters = " + parametersToString());
       }
     
       /**
    -   * Constructor to generate keys given the desired bitLength and prime certainty value
    +   * Constructs a Paillier algorithm with generated keys.
        * <p>
    -   * 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.
    -   *
    +   * The generated keys {@code p} and {@code q} will have the given modulus bit length and prime certainty.
    +   * <p>
    +   * The probability that the generated keys represent primes will exceed (1 - (1/2)<sup>{@code certainty}</sup>). The execution time of this constructor is
    +   * proportional to the value of this parameter.
    +   * 
    +   * @param bitLength
    +   *          The bit length of the resulting modulus {@code N}.
    +   * @param certainty
    +   *          The probability that the new {@code p} and {@code q} represent prime numbers.
    +   * @throws IllegalArgumentException
    +   *           If the {@code certainty} is less than the system allowed lower bound.
        */
    -  public Paillier(int bitLengthInput, int certainty) throws PIRException
    +  public Paillier(int bitLength, int certainty)
       {
    -    this(bitLengthInput, certainty, -1);
    +    this(bitLength, certainty, -1);
       }
     
       /**
    -   * Constructor to generate keys given the desired bitLength and prime certainty value
    +   * Constructs a Paillier algorithm with generated keys and optionally ensures a certain bit is set in the modulus.
        * <p>
    -   * Can optionally, ensure a certain bit is set in the modulus (if ensureBitSet != 0)
    +   * The generated keys {@code p} and {@code q} will have the given modulus bit length and prime certainty.
        * <p>
    -   * 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.
    -   *
    +   * The probability that the generated keys represent primes will exceed (1 - (1/2)<sup>{@code certainty}</sup>). The execution time of this constructor is
    +   * proportional to the value of this parameter.
    +   * <p>
    +   * When ensureBitSet > -1 the value of bit "{@code ensureBitSet}" in modulus {@code N} will be set.
    +   * 
    +   * @param bitLength
    +   *          The bit length of the resulting modulus {@code N}.
    +   * @param certainty
    +   *          The probability that the new {@code p} and {@code q} represent prime numbers.
    +   * @param ensureBitSet
    +   *          index of bit in {@code N} to ensure is set.
    +   * @throws IllegalArgumentException
    +   *           If the {@code certainty} is less than the system allowed lower bound, or the index of {@code ensureBitSet} is greater than the {@code bitLength}.
        */
    -  public Paillier(int bitLengthInput, int certainty, int ensureBitSet) throws PIRException
    +  public Paillier(int bitLength, int certainty, int ensureBitSet)
       {
    -    bitLength = bitLengthInput;
    -
         int systemPrimeCertainty = SystemConfiguration.getIntProperty("pir.primeCertainty", 128);
         if (certainty < systemPrimeCertainty)
         {
    -      throw new PIRException("Input certainty = " + certainty + " is less than allowed system lower bound = " + systemPrimeCertainty);
    +      throw new IllegalArgumentException("Input certainty = " + certainty + " is less than allowed system lower bound = " + systemPrimeCertainty);
         }
    -    if (ensureBitSet >= bitLengthInput)
    +    if (ensureBitSet >= bitLength)
         {
    -      throw new PIRException("ensureBitSet = " + ensureBitSet + " must be less than bitLengthInput = " + bitLengthInput);
    +      throw new IllegalArgumentException("ensureBitSet = " + ensureBitSet + " must be less than bitLengthInput = " + bitLength);
         }
    -    generateKeys(certainty, ensureBitSet);
    +    this.bitLength = bitLength;
    +    generateKeys(bitLength, certainty, ensureBitSet);
    --- End diff --
    
    Why change the signature of generateKeys to pass bitLength?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-pirk pull request #102: [Minor] Enhancements to Paillier class.

Posted by ellisonanne <gi...@git.apache.org>.
Github user ellisonanne commented on a diff in the pull request:

    https://github.com/apache/incubator-pirk/pull/102#discussion_r80806938
  
    --- Diff: src/main/java/org/apache/pirk/encryption/Paillier.java ---
    @@ -95,140 +95,185 @@
         }
       }
     
    -  private BigInteger p = null; // large prime
    -  private BigInteger q = null; // large prime
    -  private BigInteger N = null; // N=pq, RSA modulus
    +  private BigInteger p; // large prime
    +  private BigInteger q; // large prime
    +  private BigInteger N; // N=pq, RSA modulus
     
    -  private BigInteger NSquared = null; // NSquared = N^2
    -  private BigInteger lambdaN = null; // lambda(N) = lcm(p-1,q-1), Carmichael function of N
    -  private BigInteger w = null; // lambda(N)^-1 mod N
    +  private BigInteger NSquared; // NSquared = N^2
    +  private BigInteger lambdaN; // lambda(N) = lcm(p-1,q-1), Carmichael function of N
    +  private BigInteger w; // lambda(N)^-1 mod N
     
    -  private int bitLength = 0; // bit length of the modulus N
    +  private final int bitLength; // bit length of the modulus N
     
       /**
    -   * Constructor with all parameters p,q, and bitLengthInput specified
    -   * <p>
    -   * Only used, at this point, for testing purposes
    -   *
    +   * Creates a Paillier algorithm with all parameters specified.
    +   * 
    +   * @param p
    +   *          First large prime.
    +   * @param q
    +   *          Second large prime.
    +   * @param bitLength
    +   *          Bit length of the modulus {@code N}.
    +   * @throws IllegalArgumentException
    +   *           If {@code p} or {@code q} do not satisfy primality constraints.
        */
    -  public Paillier(BigInteger pInput, BigInteger qInput, int bitLengthInput) throws PIRException
    +  public Paillier(BigInteger p, BigInteger q, int bitLength)
       {
    -    bitLength = bitLengthInput;
    +    this.bitLength = bitLength;
     
         // Verify the prime conditions are satisfied
         int primeCertainty = SystemConfiguration.getIntProperty("pir.primeCertainty", 128);
         BigInteger three = BigInteger.valueOf(3);
    -    if ((pInput.compareTo(three) < 0) || (qInput.compareTo(three) < 0) || pInput.equals(qInput) || !pInput.isProbablePrime(primeCertainty)
    -        || !qInput.isProbablePrime(primeCertainty))
    +    if ((p.compareTo(three) < 0) || (q.compareTo(three) < 0) || p.equals(q) || !p.isProbablePrime(primeCertainty) || !q.isProbablePrime(primeCertainty))
         {
    -      throw new PIRException("pInput = " + pInput + " qInput = " + qInput + " do not satisfy primality constraints");
    +      throw new IllegalArgumentException("p = " + p + " q = " + q + " do not satisfy primality constraints");
         }
     
    -    p = pInput;
    -    q = qInput;
    +    this.p = p;
    +    this.q = q;
     
    -    N = p.multiply(q);
    +    this.N = p.multiply(q);
     
         setDerivativeElements();
     
         logger.info("Parameters = " + parametersToString());
       }
     
       /**
    -   * Constructor to generate keys given the desired bitLength and prime certainty value
    +   * Constructs a Paillier algorithm with generated keys.
        * <p>
    -   * 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.
    -   *
    +   * The generated keys {@code p} and {@code q} will have the given modulus bit length and prime certainty.
    +   * <p>
    +   * The probability that the generated keys represent primes will exceed (1 - (1/2)<sup>{@code certainty}</sup>). The execution time of this constructor is
    +   * proportional to the value of this parameter.
    +   * 
    +   * @param bitLength
    +   *          The bit length of the resulting modulus {@code N}.
    +   * @param certainty
    +   *          The probability that the new {@code p} and {@code q} represent prime numbers.
    +   * @throws IllegalArgumentException
    +   *           If the {@code certainty} is less than the system allowed lower bound.
        */
    -  public Paillier(int bitLengthInput, int certainty) throws PIRException
    +  public Paillier(int bitLength, int certainty)
       {
    -    this(bitLengthInput, certainty, -1);
    +    this(bitLength, certainty, -1);
       }
     
       /**
    -   * Constructor to generate keys given the desired bitLength and prime certainty value
    +   * Constructs a Paillier algorithm with generated keys and optionally ensures a certain bit is set in the modulus.
        * <p>
    -   * Can optionally, ensure a certain bit is set in the modulus (if ensureBitSet != 0)
    +   * The generated keys {@code p} and {@code q} will have the given modulus bit length and prime certainty.
    --- End diff --
    
    Same comment as above for the similar line in this javadoc 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-pirk issue #102: [Minor] Enhancements to Paillier class.

Posted by ellisonanne <gi...@git.apache.org>.
Github user ellisonanne commented on the issue:

    https://github.com/apache/incubator-pirk/pull/102
  
    +1


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-pirk pull request #102: [Minor] Enhancements to Paillier class.

Posted by ellisonanne <gi...@git.apache.org>.
Github user ellisonanne commented on a diff in the pull request:

    https://github.com/apache/incubator-pirk/pull/102#discussion_r80808049
  
    --- Diff: src/main/java/org/apache/pirk/encryption/Paillier.java ---
    @@ -95,140 +95,185 @@
         }
       }
     
    -  private BigInteger p = null; // large prime
    -  private BigInteger q = null; // large prime
    -  private BigInteger N = null; // N=pq, RSA modulus
    +  private BigInteger p; // large prime
    +  private BigInteger q; // large prime
    +  private BigInteger N; // N=pq, RSA modulus
     
    -  private BigInteger NSquared = null; // NSquared = N^2
    -  private BigInteger lambdaN = null; // lambda(N) = lcm(p-1,q-1), Carmichael function of N
    -  private BigInteger w = null; // lambda(N)^-1 mod N
    +  private BigInteger NSquared; // NSquared = N^2
    +  private BigInteger lambdaN; // lambda(N) = lcm(p-1,q-1), Carmichael function of N
    +  private BigInteger w; // lambda(N)^-1 mod N
     
    -  private int bitLength = 0; // bit length of the modulus N
    +  private final int bitLength; // bit length of the modulus N
     
       /**
    -   * Constructor with all parameters p,q, and bitLengthInput specified
    -   * <p>
    -   * Only used, at this point, for testing purposes
    -   *
    +   * Creates a Paillier algorithm with all parameters specified.
    +   * 
    +   * @param p
    +   *          First large prime.
    +   * @param q
    +   *          Second large prime.
    +   * @param bitLength
    +   *          Bit length of the modulus {@code N}.
    +   * @throws IllegalArgumentException
    +   *           If {@code p} or {@code q} do not satisfy primality constraints.
        */
    -  public Paillier(BigInteger pInput, BigInteger qInput, int bitLengthInput) throws PIRException
    +  public Paillier(BigInteger p, BigInteger q, int bitLength)
       {
    -    bitLength = bitLengthInput;
    +    this.bitLength = bitLength;
     
         // Verify the prime conditions are satisfied
         int primeCertainty = SystemConfiguration.getIntProperty("pir.primeCertainty", 128);
         BigInteger three = BigInteger.valueOf(3);
    -    if ((pInput.compareTo(three) < 0) || (qInput.compareTo(three) < 0) || pInput.equals(qInput) || !pInput.isProbablePrime(primeCertainty)
    -        || !qInput.isProbablePrime(primeCertainty))
    +    if ((p.compareTo(three) < 0) || (q.compareTo(three) < 0) || p.equals(q) || !p.isProbablePrime(primeCertainty) || !q.isProbablePrime(primeCertainty))
         {
    -      throw new PIRException("pInput = " + pInput + " qInput = " + qInput + " do not satisfy primality constraints");
    +      throw new IllegalArgumentException("p = " + p + " q = " + q + " do not satisfy primality constraints");
         }
     
    -    p = pInput;
    -    q = qInput;
    +    this.p = p;
    +    this.q = q;
     
    -    N = p.multiply(q);
    +    this.N = p.multiply(q);
     
         setDerivativeElements();
     
         logger.info("Parameters = " + parametersToString());
       }
     
       /**
    -   * Constructor to generate keys given the desired bitLength and prime certainty value
    +   * Constructs a Paillier algorithm with generated keys.
        * <p>
    -   * 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.
    -   *
    +   * The generated keys {@code p} and {@code q} will have the given modulus bit length and prime certainty.
    +   * <p>
    +   * The probability that the generated keys represent primes will exceed (1 - (1/2)<sup>{@code certainty}</sup>). The execution time of this constructor is
    +   * proportional to the value of this parameter.
    +   * 
    +   * @param bitLength
    +   *          The bit length of the resulting modulus {@code N}.
    +   * @param certainty
    +   *          The probability that the new {@code p} and {@code q} represent prime numbers.
    +   * @throws IllegalArgumentException
    +   *           If the {@code certainty} is less than the system allowed lower bound.
        */
    -  public Paillier(int bitLengthInput, int certainty) throws PIRException
    +  public Paillier(int bitLength, int certainty)
       {
    -    this(bitLengthInput, certainty, -1);
    +    this(bitLength, certainty, -1);
       }
     
       /**
    -   * Constructor to generate keys given the desired bitLength and prime certainty value
    +   * Constructs a Paillier algorithm with generated keys and optionally ensures a certain bit is set in the modulus.
        * <p>
    -   * Can optionally, ensure a certain bit is set in the modulus (if ensureBitSet != 0)
    +   * The generated keys {@code p} and {@code q} will have the given modulus bit length and prime certainty.
        * <p>
    -   * 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.
    -   *
    +   * The probability that the generated keys represent primes will exceed (1 - (1/2)<sup>{@code certainty}</sup>). The execution time of this constructor is
    +   * proportional to the value of this parameter.
    +   * <p>
    +   * When ensureBitSet > -1 the value of bit "{@code ensureBitSet}" in modulus {@code N} will be set.
    +   * 
    +   * @param bitLength
    +   *          The bit length of the resulting modulus {@code N}.
    +   * @param certainty
    +   *          The probability that the new {@code p} and {@code q} represent prime numbers.
    +   * @param ensureBitSet
    +   *          index of bit in {@code N} to ensure is set.
    +   * @throws IllegalArgumentException
    +   *           If the {@code certainty} is less than the system allowed lower bound, or the index of {@code ensureBitSet} is greater than the {@code bitLength}.
        */
    -  public Paillier(int bitLengthInput, int certainty, int ensureBitSet) throws PIRException
    +  public Paillier(int bitLength, int certainty, int ensureBitSet)
       {
    -    bitLength = bitLengthInput;
    -
         int systemPrimeCertainty = SystemConfiguration.getIntProperty("pir.primeCertainty", 128);
         if (certainty < systemPrimeCertainty)
         {
    -      throw new PIRException("Input certainty = " + certainty + " is less than allowed system lower bound = " + systemPrimeCertainty);
    +      throw new IllegalArgumentException("Input certainty = " + certainty + " is less than allowed system lower bound = " + systemPrimeCertainty);
         }
    -    if (ensureBitSet >= bitLengthInput)
    +    if (ensureBitSet >= bitLength)
         {
    -      throw new PIRException("ensureBitSet = " + ensureBitSet + " must be less than bitLengthInput = " + bitLengthInput);
    +      throw new IllegalArgumentException("ensureBitSet = " + ensureBitSet + " must be less than bitLengthInput = " + bitLength);
         }
    -    generateKeys(certainty, ensureBitSet);
    +    this.bitLength = bitLength;
    +    generateKeys(bitLength, certainty, ensureBitSet);
         setDerivativeElements();
     
         logger.info("Parameters = " + parametersToString());
       }
     
    +  /**
    +   * Returns the value of the large prime {@code p}.
    +   * 
    +   * @return p.
    +   */
       public BigInteger getP()
       {
         return p;
       }
     
    +  /**
    +   * Returns the value of the large prime {@code q}.
    +   * 
    +   * @return q.
    +   */
       public BigInteger getQ()
       {
         return q;
       }
     
    +  /**
    +   * Returns the RSA modulus value {@code N}.
    +   * 
    +   * @return N, the product of {@code p} and {@code q}.
    +   */
       public BigInteger getN()
       {
         return N;
       }
     
    +  /**
    +   * Returns the value of {@code N}<sup>2</sup>.
    +   * 
    +   * @return N squared.
    +   */
       public BigInteger getNSquared()
       {
         return NSquared;
       }
     
    +  /**
    +   * Returns the value of Carmichael's function at {@code N}.
    +   * <p>
    +   * The Carmichael function of {@code N} is the lowest common multiple of {@code p-1} and {@code q-1},
    +   * 
    +   * @return Carmichael's function at {@code N}.
    +   */
       public BigInteger getLambdaN()
       {
         return lambdaN;
       }
     
    +  /**
    +   * Returns the bit length of the modulus {@code N}.
    +   * 
    +   * @return the bit length, as an integer.
    +   */
       public int getBitLength()
       {
         return bitLength;
       }
     
    -  private void generateKeys(int certainty, int ensureBitSet)
    +  private void generateKeys(int bitLength, int certainty, final int ensureBitSet)
    --- End diff --
    
    See comment above regarding the signature of generateKeys


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---