private void doCtr(
      final byte[] input,
      int inputOffset,
      int inputLen,
      byte[] output,
      int outputOffset,
      final byte[] iv,
      boolean encrypt)
      throws GeneralSecurityException {
    Cipher cipher = localCipher.get();
    // The counter is big-endian. The counter is composed of iv and (blockSize - ivSize) of zeros.
    byte[] counter = new byte[blockSize];
    System.arraycopy(iv, 0, counter, 0, ivSize);

    IvParameterSpec paramSpec = new IvParameterSpec(counter);
    if (encrypt) {
      cipher.init(Cipher.ENCRYPT_MODE, keySpec, paramSpec);
    } else {
      cipher.init(Cipher.DECRYPT_MODE, keySpec, paramSpec);
    }
    int numBytes = cipher.doFinal(input, inputOffset, inputLen, output, outputOffset);
    if (numBytes != inputLen) {
      throw new GeneralSecurityException("stored output's length does not match input's length");
    }
  }
Decrypts the ciphertext with counter mode decryption. The ciphertext format is iv || raw
ciphertext.

@param ciphertext the ciphertext to be decrypted.
@return the decrypted plaintext.
java_src/src/main/java/com/google/crypto/tink/subtle/AesCtrJceCipher.java