Example #1
0
  /** @com.intel.drl.spec_ref */
  public ECFieldF2m(int m, BigInteger rp) {
    this.m = m;
    if (this.m <= 0) {
      throw new IllegalArgumentException(Messages.getString("security.75")); // $NON-NLS-1$
    }
    this.rp = rp;
    if (this.rp == null) {
      throw new NullPointerException(Messages.getString("security.76")); // $NON-NLS-1$
    }
    // the leftmost bit must be (m+1)-th one,
    // set bits count must be 3 or 5,
    // bits 0 and m must be set
    int rp_bc = this.rp.bitCount();
    if ((this.rp.bitLength() != (m + 1))
        || (rp_bc != TPB_LEN && rp_bc != PPB_LEN)
        || (!this.rp.testBit(0) || !this.rp.testBit(m))) {
      throw new IllegalArgumentException(Messages.getString("security.77")); // $NON-NLS-1$
    }

    // setup ks using rp:
    // allocate for mid terms only
    ks = new int[rp_bc - 2];
    // find midterm orders and set ks accordingly
    BigInteger rpTmp = rp.clearBit(0);
    for (int i = ks.length - 1; i >= 0; i--) {
      ks[i] = rpTmp.getLowestSetBit();
      rpTmp = rpTmp.clearBit(ks[i]);
    }
  }
Example #2
0
  public static void bitOps(int order) {
    int failCount1 = 0, failCount2 = 0, failCount3 = 0;

    for (int i = 0; i < size * 5; i++) {
      BigInteger x = fetchNumber(order);
      BigInteger y;

      /* Test setBit and clearBit (and testBit) */
      if (x.signum() < 0) {
        y = BigInteger.valueOf(-1);
        for (int j = 0; j < x.bitLength(); j++) if (!x.testBit(j)) y = y.clearBit(j);
      } else {
        y = BigInteger.ZERO;
        for (int j = 0; j < x.bitLength(); j++) if (x.testBit(j)) y = y.setBit(j);
      }
      if (!x.equals(y)) failCount1++;

      /* Test flipBit (and testBit) */
      y = BigInteger.valueOf(x.signum() < 0 ? -1 : 0);
      for (int j = 0; j < x.bitLength(); j++) if (x.signum() < 0 ^ x.testBit(j)) y = y.flipBit(j);
      if (!x.equals(y)) failCount2++;
    }
    report("clearBit/testBit", failCount1);
    report("flipBit/testBit", failCount2);

    for (int i = 0; i < size * 5; i++) {
      BigInteger x = fetchNumber(order);

      /* Test getLowestSetBit() */
      int k = x.getLowestSetBit();
      if (x.signum() == 0) {
        if (k != -1) failCount3++;
      } else {
        BigInteger z = x.and(x.negate());
        int j;
        for (j = 0; j < z.bitLength() && !z.testBit(j); j++) ;
        if (k != j) failCount3++;
      }
    }
    report("getLowestSetBit", failCount3);
  }