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 [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to