예제 #1
0
 public BulkData(
     byte[] chunkData, int[] chunkX, int[] chunkZ, boolean skylight, short[] bitmap, short[] add) {
   this.chunkData = ByteUtils.clone(chunkData);
   this.chunkX = Arrays.copyOf(chunkX, chunkX.length);
   this.chunkZ = Arrays.copyOf(chunkZ, chunkZ.length);
   this.skylight = skylight;
   this.bitmap = new short[bitmap.length];
   System.arraycopy(bitmap, 0, this.bitmap, 0, bitmap.length);
   this.add = new short[add.length];
   System.arraycopy(add, 0, this.add, 0, add.length);
 }
예제 #2
0
  /** Karazuba multiplication */
  private BigIntPolynomial multRecursive(BigIntPolynomial poly2) {
    BigInteger[] a = coeffs;
    BigInteger[] b = poly2.coeffs;

    int n = poly2.coeffs.length;
    if (n <= 1) {
      BigInteger[] c = Arrays.clone(coeffs);
      for (int i = 0; i < coeffs.length; i++) {
        c[i] = c[i].multiply(poly2.coeffs[0]);
      }
      return new BigIntPolynomial(c);
    } else {
      int n1 = n / 2;

      BigIntPolynomial a1 = new BigIntPolynomial(Arrays.copyOf(a, n1));
      BigIntPolynomial a2 = new BigIntPolynomial(Arrays.copyOfRange(a, n1, n));
      BigIntPolynomial b1 = new BigIntPolynomial(Arrays.copyOf(b, n1));
      BigIntPolynomial b2 = new BigIntPolynomial(Arrays.copyOfRange(b, n1, n));

      BigIntPolynomial A = (BigIntPolynomial) a1.clone();
      A.add(a2);
      BigIntPolynomial B = (BigIntPolynomial) b1.clone();
      B.add(b2);

      BigIntPolynomial c1 = a1.multRecursive(b1);
      BigIntPolynomial c2 = a2.multRecursive(b2);
      BigIntPolynomial c3 = A.multRecursive(B);
      c3.sub(c1);
      c3.sub(c2);

      BigIntPolynomial c = new BigIntPolynomial(2 * n - 1);
      for (int i = 0; i < c1.coeffs.length; i++) {
        c.coeffs[i] = c1.coeffs[i];
      }
      for (int i = 0; i < c3.coeffs.length; i++) {
        c.coeffs[n1 + i] = c.coeffs[n1 + i].add(c3.coeffs[i]);
      }
      for (int i = 0; i < c2.coeffs.length; i++) {
        c.coeffs[2 * n1 + i] = c.coeffs[2 * n1 + i].add(c2.coeffs[i]);
      }
      return c;
    }
  }
예제 #3
0
 public static byte[] decodeB64UrlSafe(final byte[] data) {
   byte[] encode = Arrays.copyOf(data, data.length);
   for (int i = 0; i < encode.length; i++) {
     if (encode[i] == '-') {
       encode[i] = '+';
     } else if (encode[i] == '_') {
       encode[i] = '/';
     }
   }
   return Base64.decodeBase64(encode);
 }
예제 #4
0
 /**
  * Subtracts another polynomial which can have a different number of coefficients.
  *
  * @param b another polynomial
  */
 public void sub(BigIntPolynomial b) {
   if (b.coeffs.length > coeffs.length) {
     int N = coeffs.length;
     coeffs = Arrays.copyOf(coeffs, b.coeffs.length);
     for (int i = N; i < coeffs.length; i++) {
       coeffs[i] = Constants.BIGINT_ZERO;
     }
   }
   for (int i = 0; i < b.coeffs.length; i++) {
     coeffs[i] = coeffs[i].subtract(b.coeffs[i]);
   }
 }
예제 #5
0
  /**
   * Multiplies the polynomial by another, taking the indices mod N. Does not change this polynomial
   * but returns the result as a new polynomial.<br>
   * Both polynomials must have the same number of coefficients.
   *
   * @param poly2 the polynomial to multiply by
   * @return a new polynomial
   */
  public BigIntPolynomial mult(BigIntPolynomial poly2) {
    int N = coeffs.length;
    if (poly2.coeffs.length != N) {
      throw new IllegalArgumentException("Number of coefficients must be the same");
    }

    BigIntPolynomial c = multRecursive(poly2);

    if (c.coeffs.length > N) {
      for (int k = N; k < c.coeffs.length; k++) {
        c.coeffs[k - N] = c.coeffs[k - N].add(c.coeffs[k]);
      }
      c.coeffs = Arrays.copyOf(c.coeffs, N);
    }
    return c;
  }
예제 #6
0
  private synchronized byte[] createIV(String originalFileName, SecretKey obKey)
      throws ObfuscationException {
    try {
      ivDigest.update(originalFileName.getBytes(PanboxConstants.STANDARD_CHARSET));
      ivDigest.update(obKey.getEncoded());
      byte[] hash = ivDigest.digest();

      // truncate to IV size
      return Arrays.copyOf(hash, KeyConstants.SYMMETRIC_BLOCK_SIZE);

    } catch (UnsupportedEncodingException e) {
      logger.error("Unsupported encoding", e);
      throw new ObfuscationException(
          "Error creating IV for filename due to unsupported encoding!", e);
    }
  }
예제 #7
0
 DatabaseKey(byte[] key, Random random) {
   this.databaseKey = Arrays.copyOf(key, key.length);
   this.random = random;
 }