diff --git a/.gitignore b/.gitignore index f527be142..b4ec9c645 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,7 @@ /.idea/other.xml /.idea/runConfigurations.xml /.idea/ChatHistory_schema_v2.xml +/.idea/artifacts/* .DS_Store /build /captures diff --git a/README.md b/README.md index f32278427..d1bf11d23 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -
- * Following the naming conventions used in the C source code to enable easy review of the implementation. - */ -public class KeccakDigest implements ExtendedDigest { - - private static long[] KeccakRoundConstants = keccakInitializeRoundConstants(); - - private static int[] KeccakRhoOffsets = keccakInitializeRhoOffsets(); - - private static long[] keccakInitializeRoundConstants() { - long[] keccakRoundConstants = new long[24]; - byte[] LFSRstate = new byte[1]; - - LFSRstate[0] = 0x01; - int i, j, bitPosition; - - for (i = 0; i < 24; i++) { - keccakRoundConstants[i] = 0; - - for (j = 0; j < 7; j++) { - bitPosition = (1 << j) - 1; - - if (LFSR86540(LFSRstate)) { - keccakRoundConstants[i] ^= 1L << bitPosition; - } - } - } - - return keccakRoundConstants; - } - - private static boolean LFSR86540(byte[] LFSR) { - boolean result = (((LFSR[0]) & 0x01) != 0); - - if (((LFSR[0]) & 0x80) != 0) { - LFSR[0] = (byte) (((LFSR[0]) << 1) ^ 0x71); - } else { - LFSR[0] <<= 1; - } - - return result; - } - - private static int[] keccakInitializeRhoOffsets() { - int[] keccakRhoOffsets = new int[25]; - int x, y, t, newX, newY; - - keccakRhoOffsets[(((0) % 5) + 5 * ((0) % 5))] = 0; - x = 1; - y = 0; - - for (t = 0; t < 24; t++) { - keccakRhoOffsets[(((x) % 5) + 5 * ((y) % 5))] = ((t + 1) * (t + 2) / 2) % 64; - newX = (0 * x + 1 * y) % 5; - newY = (2 * x + 3 * y) % 5; - x = newX; - y = newY; - } - - return keccakRhoOffsets; - } - - protected byte[] state = new byte[(1600 / 8)]; - protected byte[] dataQueue = new byte[(1536 / 8)]; - protected int rate; - protected int bitsInQueue; - protected int fixedOutputLength; - protected boolean squeezing; - protected int bitsAvailableForSqueezing; - protected byte[] chunk; - protected byte[] oneByte; - - private void clearDataQueueSection(int off, int len) { - for (int i = off; i != off + len; i++) { - dataQueue[i] = 0; - } - } - - public KeccakDigest() { - this(288); - } - - public KeccakDigest(int bitLength) { - init(bitLength); - } - - public KeccakDigest(KeccakDigest source) { - System.arraycopy(source.state, 0, this.state, 0, source.state.length); - System.arraycopy(source.dataQueue, 0, this.dataQueue, 0, source.dataQueue.length); - this.rate = source.rate; - this.bitsInQueue = source.bitsInQueue; - this.fixedOutputLength = source.fixedOutputLength; - this.squeezing = source.squeezing; - this.bitsAvailableForSqueezing = source.bitsAvailableForSqueezing; - this.chunk = Utils.arraysCopy(source.chunk); - this.oneByte = Utils.arraysCopy(source.oneByte); - } - - public String getAlgorithmName() { - return "Keccak-" + fixedOutputLength; - } - - public int getDigestSize() { - return fixedOutputLength / 8; - } - - public void update(byte in) { - oneByte[0] = in; - - absorb(oneByte, 0, 8L); - } - - public void update(byte[] in, int inOff, int len) { - absorb(in, inOff, len * 8L); - } - - public int doFinal(byte[] out, int outOff) { - squeeze(out, outOff, fixedOutputLength); - reset(); - - return getDigestSize(); - } - - /* - * TODO Possible API change to support partial-byte suffixes. - */ - protected int doFinal(byte[] out, int outOff, byte partialByte, int partialBits) { - if (partialBits > 0) { - oneByte[0] = partialByte; - absorb(oneByte, 0, partialBits); - } - - squeeze(out, outOff, fixedOutputLength); - reset(); - - return getDigestSize(); - } - - public void reset() { - init(fixedOutputLength); - } - - /** - * Return the size of block that the compression function is applied to in bytes. - * - * @return internal byte length of a block. - */ - public int getByteLength() { - return rate / 8; - } - - private void init(int bitLength) { - switch (bitLength) { - case 288: - initSponge(1024, 576); - break; - case 128: - initSponge(1344, 256); - break; - case 224: - initSponge(1152, 448); - break; - case 256: - initSponge(1088, 512); - break; - case 384: - initSponge(832, 768); - break; - case 512: - initSponge(576, 1024); - break; - default: - throw new IllegalArgumentException("bitLength must be one of 128, 224, 256, 288, 384, or 512."); - } - } - - private void initSponge(int rate, int capacity) { - if (rate + capacity != 1600) { - throw new IllegalStateException("rate + capacity != 1600"); - } - - if ((rate <= 0) || (rate >= 1600) || ((rate % 64) != 0)) { - throw new IllegalStateException("invalid rate value"); - } - - this.rate = rate; - // this is never read, need to check to see why we want to save it - // this.capacity = capacity; - Utils.arrayFill(this.state, (byte) 0); - Utils.arrayFill(this.dataQueue, (byte) 0); - this.bitsInQueue = 0; - this.squeezing = false; - this.bitsAvailableForSqueezing = 0; - this.fixedOutputLength = capacity / 2; - this.chunk = new byte[rate / 8]; - this.oneByte = new byte[1]; - } - - private void absorbQueue() { - KeccakAbsorb(state, dataQueue, rate / 8); - bitsInQueue = 0; - } - - protected void absorb(byte[] data, int off, long databitlen) { - long i, j, wholeBlocks; - - if ((bitsInQueue % 8) != 0) { - throw new IllegalStateException("attempt to absorb with odd length queue"); - } - - if (squeezing) { - throw new IllegalStateException("attempt to absorb while squeezing"); - } - - i = 0; - - while (i < databitlen) { - if ((bitsInQueue == 0) && (databitlen >= rate) && (i <= (databitlen - rate))) { - wholeBlocks = (databitlen - i) / rate; - - for (j = 0; j < wholeBlocks; j++) { - System.arraycopy(data, (int) (off + (i / 8) + (j * chunk.length)), chunk, 0, chunk.length); - -// displayIntermediateValues.displayBytes(1, "Block to be absorbed", curData, rate / 8); - - KeccakAbsorb(state, chunk, chunk.length); - } - - i += wholeBlocks * rate; - } else { - int partialBlock = (int) (databitlen - i); - - if (partialBlock + bitsInQueue > rate) { - partialBlock = rate - bitsInQueue; - } - - int partialByte = partialBlock % 8; - partialBlock -= partialByte; - System.arraycopy(data, off + (int) (i / 8), dataQueue, bitsInQueue / 8, partialBlock / 8); - - bitsInQueue += partialBlock; - i += partialBlock; - - if (bitsInQueue == rate) { - absorbQueue(); - } - - if (partialByte > 0) { - int mask = (1 << partialByte) - 1; - dataQueue[bitsInQueue / 8] = (byte) (data[off + ((int) (i / 8))] & mask); - bitsInQueue += partialByte; - i += partialByte; - } - } - } - } - - private void padAndSwitchToSqueezingPhase() { - if (bitsInQueue + 1 == rate) { - dataQueue[bitsInQueue / 8] |= 1 << (bitsInQueue % 8); - absorbQueue(); - clearDataQueueSection(0, rate / 8); - } else { - clearDataQueueSection((bitsInQueue + 7) / 8, rate / 8 - (bitsInQueue + 7) / 8); - dataQueue[bitsInQueue / 8] |= 1 << (bitsInQueue % 8); - } - - dataQueue[(rate - 1) / 8] |= 1 << ((rate - 1) % 8); - absorbQueue(); - -// displayIntermediateValues.displayText(1, "--- Switching to squeezing phase ---"); - - if (rate == 1024) { - KeccakExtract1024bits(state, dataQueue); - bitsAvailableForSqueezing = 1024; - } else { - KeccakExtract(state, dataQueue, rate / 64); - bitsAvailableForSqueezing = rate; - } - -// displayIntermediateValues.displayBytes(1, "Block available for squeezing", dataQueue, bitsAvailableForSqueezing / 8); - - squeezing = true; - } - - protected void squeeze(byte[] output, int offset, long outputLength) { - long i; - int partialBlock; - - if (!squeezing) { - padAndSwitchToSqueezingPhase(); - } - - if ((outputLength % 8) != 0) { - throw new IllegalStateException("outputLength not a multiple of 8"); - } - - i = 0; - - while (i < outputLength) { - if (bitsAvailableForSqueezing == 0) { - keccakPermutation(state); - - if (rate == 1024) { - KeccakExtract1024bits(state, dataQueue); - bitsAvailableForSqueezing = 1024; - } else { - KeccakExtract(state, dataQueue, rate / 64); - bitsAvailableForSqueezing = rate; - } - -// displayIntermediateValues.displayBytes(1, "Block available for squeezing", dataQueue, bitsAvailableForSqueezing / 8); - - } - - partialBlock = bitsAvailableForSqueezing; - - if ((long) partialBlock > outputLength - i) { - partialBlock = (int) (outputLength - i); - } - - System.arraycopy(dataQueue, (rate - bitsAvailableForSqueezing) / 8, output, offset + (int) (i / 8), partialBlock / 8); - bitsAvailableForSqueezing -= partialBlock; - i += partialBlock; - } - } - - private void fromBytesToWords(long[] stateAsWords, byte[] state) { - for (int i = 0; i < (1600 / 64); i++) { - stateAsWords[i] = 0; - int index = i * (64 / 8); - - for (int j = 0; j < (64 / 8); j++) { - stateAsWords[i] |= ((long) state[index + j] & 0xff) << ((8 * j)); - } - } - } - - private void fromWordsToBytes(byte[] state, long[] stateAsWords) { - for (int i = 0; i < (1600 / 64); i++) { - int index = i * (64 / 8); - - for (int j = 0; j < (64 / 8); j++) { - state[index + j] = (byte) ((stateAsWords[i] >>> ((8 * j))) & 0xFF); - } - } - } - - private void keccakPermutation(byte[] state) { - long[] longState = new long[state.length / 8]; - - fromBytesToWords(longState, state); - -// displayIntermediateValues.displayStateAsBytes(1, "Input of permutation", longState); - - keccakPermutationOnWords(longState); - -// displayIntermediateValues.displayStateAsBytes(1, "State after permutation", longState); - - fromWordsToBytes(state, longState); - } - - private void keccakPermutationAfterXor(byte[] state, byte[] data, int dataLengthInBytes) { - int i; - - for (i = 0; i < dataLengthInBytes; i++) { - state[i] ^= data[i]; - } - - keccakPermutation(state); - } - - private void keccakPermutationOnWords(long[] state) { - int i; - -// displayIntermediateValues.displayStateAs64bitWords(3, "Same, with lanes as 64-bit words", state); - - for (i = 0; i < 24; i++) { -// displayIntermediateValues.displayRoundNumber(3, i); - - theta(state); -// displayIntermediateValues.displayStateAs64bitWords(3, "After theta", state); - - rho(state); -// displayIntermediateValues.displayStateAs64bitWords(3, "After rho", state); - - pi(state); -// displayIntermediateValues.displayStateAs64bitWords(3, "After pi", state); - - chi(state); -// displayIntermediateValues.displayStateAs64bitWords(3, "After chi", state); - - iota(state, i); -// displayIntermediateValues.displayStateAs64bitWords(3, "After iota", state); - } - } - - long[] C = new long[5]; - - private void theta(long[] A) { - for (int x = 0; x < 5; x++) { - C[x] = 0; - - for (int y = 0; y < 5; y++) { - C[x] ^= A[x + 5 * y]; - } - } - for (int x = 0; x < 5; x++) { - long dX = ((((C[(x + 1) % 5]) << 1) ^ ((C[(x + 1) % 5]) >>> (64 - 1)))) ^ C[(x + 4) % 5]; - - for (int y = 0; y < 5; y++) { - A[x + 5 * y] ^= dX; - } - } - } - - private void rho(long[] A) { - for (int x = 0; x < 5; x++) { - for (int y = 0; y < 5; y++) { - int index = x + 5 * y; - A[index] = ((KeccakRhoOffsets[index] != 0) ? (((A[index]) << KeccakRhoOffsets[index]) ^ ((A[index]) >>> (64 - KeccakRhoOffsets[index]))) : A[index]); - } - } - } - - long[] tempA = new long[25]; - - private void pi(long[] A) { - System.arraycopy(A, 0, tempA, 0, tempA.length); - - for (int x = 0; x < 5; x++) { - for (int y = 0; y < 5; y++) { - A[y + 5 * ((2 * x + 3 * y) % 5)] = tempA[x + 5 * y]; - } - } - } - - long[] chiC = new long[5]; - - private void chi(long[] A) { - for (int y = 0; y < 5; y++) { - for (int x = 0; x < 5; x++) { - chiC[x] = A[x + 5 * y] ^ ((~A[(((x + 1) % 5) + 5 * y)]) & A[(((x + 2) % 5) + 5 * y)]); - } - - for (int x = 0; x < 5; x++) { - A[x + 5 * y] = chiC[x]; - } - } - } - - private void iota(long[] A, int indexRound) { - A[(((0) % 5) + 5 * ((0) % 5))] ^= KeccakRoundConstants[indexRound]; - } - - private void KeccakAbsorb(byte[] byteState, byte[] data, int dataInBytes) { - keccakPermutationAfterXor(byteState, data, dataInBytes); - } - - private void KeccakExtract1024bits(byte[] byteState, byte[] data) { - System.arraycopy(byteState, 0, data, 0, 128); - } - - private void KeccakExtract(byte[] byteState, byte[] data, int laneCount) { - System.arraycopy(byteState, 0, data, 0, laneCount * 8); - } -} diff --git a/quartz/src/main/java/com/vitorpamplona/quartz/nip03Timestamp/ots/crypto/Memoable.java b/quartz/src/main/java/com/vitorpamplona/quartz/nip03Timestamp/ots/crypto/Memoable.java deleted file mode 100644 index 59b8154a8..000000000 --- a/quartz/src/main/java/com/vitorpamplona/quartz/nip03Timestamp/ots/crypto/Memoable.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.vitorpamplona.quartz.nip03Timestamp.ots.crypto; - -/** - * Interface for Memoable objects. Memoable objects allow the taking of a snapshot of their internal state - * via the {@link #copy copy()} method and then resetting the object back to that state later using the - * {@link #reset reset()} method. - */ -public interface Memoable { - /** - * Produce a copy of this object with its configuration and in its current state. - *
- * The returned object may be used simply to store the state, or may be used as a similar object - * starting from the copied state. - * - * @return Memoable object - */ - Memoable copy(); - - /** - * Restore a copied object state into this object. - *
- * Implementations of this method should try to avoid or minimise memory allocation to perform the reset.
- *
- * @param other an object originally {@link #copy() copied} from an object of the same type as this instance.
- * @throws ClassCastException if the provided object is not of the correct type.
- */
- void reset(Memoable other);
-}
diff --git a/quartz/src/main/java/com/vitorpamplona/quartz/nip03Timestamp/ots/crypto/Pack.java b/quartz/src/main/java/com/vitorpamplona/quartz/nip03Timestamp/ots/crypto/Pack.java
deleted file mode 100644
index 7fe7a0ce3..000000000
--- a/quartz/src/main/java/com/vitorpamplona/quartz/nip03Timestamp/ots/crypto/Pack.java
+++ /dev/null
@@ -1,242 +0,0 @@
-package com.vitorpamplona.quartz.nip03Timestamp.ots.crypto;
-
-/**
- * Utility methods for converting byte arrays into ints and longs, and back again.
- */
-public abstract class Pack
-{
- public static short bigEndianToShort(byte[] bs, int off)
- {
- int n = (bs[ off] & 0xff) << 8;
- n |= (bs[++off] & 0xff);
- return (short)n;
- }
-
- public static int bigEndianToInt(byte[] bs, int off)
- {
- int n = bs[ off] << 24;
- n |= (bs[++off] & 0xff) << 16;
- n |= (bs[++off] & 0xff) << 8;
- n |= (bs[++off] & 0xff);
- return n;
- }
-
- public static void bigEndianToInt(byte[] bs, int off, int[] ns)
- {
- for (int i = 0; i < ns.length; ++i)
- {
- ns[i] = bigEndianToInt(bs, off);
- off += 4;
- }
- }
-
- public static byte[] intToBigEndian(int n)
- {
- byte[] bs = new byte[4];
- intToBigEndian(n, bs, 0);
- return bs;
- }
-
- public static void intToBigEndian(int n, byte[] bs, int off)
- {
- bs[ off] = (byte)(n >>> 24);
- bs[++off] = (byte)(n >>> 16);
- bs[++off] = (byte)(n >>> 8);
- bs[++off] = (byte)(n );
- }
-
- public static byte[] intToBigEndian(int[] ns)
- {
- byte[] bs = new byte[4 * ns.length];
- intToBigEndian(ns, bs, 0);
- return bs;
- }
-
- public static void intToBigEndian(int[] ns, byte[] bs, int off)
- {
- for (int i = 0; i < ns.length; ++i)
- {
- intToBigEndian(ns[i], bs, off);
- off += 4;
- }
- }
-
- public static long bigEndianToLong(byte[] bs, int off)
- {
- int hi = bigEndianToInt(bs, off);
- int lo = bigEndianToInt(bs, off + 4);
- return ((long)(hi & 0xffffffffL) << 32) | (long)(lo & 0xffffffffL);
- }
-
- public static void bigEndianToLong(byte[] bs, int off, long[] ns)
- {
- for (int i = 0; i < ns.length; ++i)
- {
- ns[i] = bigEndianToLong(bs, off);
- off += 8;
- }
- }
-
- public static byte[] longToBigEndian(long n)
- {
- byte[] bs = new byte[8];
- longToBigEndian(n, bs, 0);
- return bs;
- }
-
- public static void longToBigEndian(long n, byte[] bs, int off)
- {
- intToBigEndian((int)(n >>> 32), bs, off);
- intToBigEndian((int)(n & 0xffffffffL), bs, off + 4);
- }
-
- public static byte[] longToBigEndian(long[] ns)
- {
- byte[] bs = new byte[8 * ns.length];
- longToBigEndian(ns, bs, 0);
- return bs;
- }
-
- public static void longToBigEndian(long[] ns, byte[] bs, int off)
- {
- for (int i = 0; i < ns.length; ++i)
- {
- longToBigEndian(ns[i], bs, off);
- off += 8;
- }
- }
-
- public static short littleEndianToShort(byte[] bs, int off)
- {
- int n = bs[ off] & 0xff;
- n |= (bs[++off] & 0xff) << 8;
- return (short)n;
- }
-
- public static int littleEndianToInt(byte[] bs, int off)
- {
- int n = bs[ off] & 0xff;
- n |= (bs[++off] & 0xff) << 8;
- n |= (bs[++off] & 0xff) << 16;
- n |= bs[++off] << 24;
- return n;
- }
-
- public static void littleEndianToInt(byte[] bs, int off, int[] ns)
- {
- for (int i = 0; i < ns.length; ++i)
- {
- ns[i] = littleEndianToInt(bs, off);
- off += 4;
- }
- }
-
- public static void littleEndianToInt(byte[] bs, int bOff, int[] ns, int nOff, int count)
- {
- for (int i = 0; i < count; ++i)
- {
- ns[nOff + i] = littleEndianToInt(bs, bOff);
- bOff += 4;
- }
- }
-
- public static int[] littleEndianToInt(byte[] bs, int off, int count)
- {
- int[] ns = new int[count];
- for (int i = 0; i < ns.length; ++i)
- {
- ns[i] = littleEndianToInt(bs, off);
- off += 4;
- }
- return ns;
- }
-
- public static byte[] shortToLittleEndian(short n)
- {
- byte[] bs = new byte[2];
- shortToLittleEndian(n, bs, 0);
- return bs;
- }
-
- public static void shortToLittleEndian(short n, byte[] bs, int off)
- {
- bs[ off] = (byte)(n );
- bs[++off] = (byte)(n >>> 8);
- }
-
- public static byte[] intToLittleEndian(int n)
- {
- byte[] bs = new byte[4];
- intToLittleEndian(n, bs, 0);
- return bs;
- }
-
- public static void intToLittleEndian(int n, byte[] bs, int off)
- {
- bs[ off] = (byte)(n );
- bs[++off] = (byte)(n >>> 8);
- bs[++off] = (byte)(n >>> 16);
- bs[++off] = (byte)(n >>> 24);
- }
-
- public static byte[] intToLittleEndian(int[] ns)
- {
- byte[] bs = new byte[4 * ns.length];
- intToLittleEndian(ns, bs, 0);
- return bs;
- }
-
- public static void intToLittleEndian(int[] ns, byte[] bs, int off)
- {
- for (int i = 0; i < ns.length; ++i)
- {
- intToLittleEndian(ns[i], bs, off);
- off += 4;
- }
- }
-
- public static long littleEndianToLong(byte[] bs, int off)
- {
- int lo = littleEndianToInt(bs, off);
- int hi = littleEndianToInt(bs, off + 4);
- return ((long)(hi & 0xffffffffL) << 32) | (long)(lo & 0xffffffffL);
- }
-
- public static void littleEndianToLong(byte[] bs, int off, long[] ns)
- {
- for (int i = 0; i < ns.length; ++i)
- {
- ns[i] = littleEndianToLong(bs, off);
- off += 8;
- }
- }
-
- public static byte[] longToLittleEndian(long n)
- {
- byte[] bs = new byte[8];
- longToLittleEndian(n, bs, 0);
- return bs;
- }
-
- public static void longToLittleEndian(long n, byte[] bs, int off)
- {
- intToLittleEndian((int)(n & 0xffffffffL), bs, off);
- intToLittleEndian((int)(n >>> 32), bs, off + 4);
- }
-
- public static byte[] longToLittleEndian(long[] ns)
- {
- byte[] bs = new byte[8 * ns.length];
- longToLittleEndian(ns, bs, 0);
- return bs;
- }
-
- public static void longToLittleEndian(long[] ns, byte[] bs, int off)
- {
- for (int i = 0; i < ns.length; ++i)
- {
- longToLittleEndian(ns[i], bs, off);
- off += 8;
- }
- }
-}
diff --git a/quartz/src/main/java/com/vitorpamplona/quartz/nip03Timestamp/ots/crypto/RIPEMD160Digest.java b/quartz/src/main/java/com/vitorpamplona/quartz/nip03Timestamp/ots/crypto/RIPEMD160Digest.java
deleted file mode 100644
index d50e65ab6..000000000
--- a/quartz/src/main/java/com/vitorpamplona/quartz/nip03Timestamp/ots/crypto/RIPEMD160Digest.java
+++ /dev/null
@@ -1,442 +0,0 @@
-package com.vitorpamplona.quartz.nip03Timestamp.ots.crypto;
-
-/**
- * Implementation of RIPEMD
- *
- * @see ripemd160
- */
-public class RIPEMD160Digest
- extends GeneralDigest
-{
- private static final int DIGEST_LENGTH = 20;
-
- private int H0, H1, H2, H3, H4; // IV's
-
- private int[] X = new int[16];
- private int xOff;
-
- /**
- * Standard constructor
- */
- public RIPEMD160Digest()
- {
- reset();
- }
-
- /**
- * Copy constructor. This will copy the state of the provided
- * message digest.
- * @param t RIPEMD160Digest
- */
- public RIPEMD160Digest(RIPEMD160Digest t)
- {
- super(t);
-
- copyIn(t);
- }
-
- private void copyIn(RIPEMD160Digest t)
- {
- super.copyIn(t);
-
- H0 = t.H0;
- H1 = t.H1;
- H2 = t.H2;
- H3 = t.H3;
- H4 = t.H4;
-
- System.arraycopy(t.X, 0, X, 0, t.X.length);
- xOff = t.xOff;
- }
-
- public String getAlgorithmName()
- {
- return "RIPEMD160";
- }
-
- public int getDigestSize()
- {
- return DIGEST_LENGTH;
- }
-
- protected void processWord(
- byte[] in,
- int inOff)
- {
- X[xOff++] = (in[inOff] & 0xff) | ((in[inOff + 1] & 0xff) << 8)
- | ((in[inOff + 2] & 0xff) << 16) | ((in[inOff + 3] & 0xff) << 24);
-
- if (xOff == 16)
- {
- processBlock();
- }
- }
-
- protected void processLength(
- long bitLength)
- {
- if (xOff > 14)
- {
- processBlock();
- }
-
- X[14] = (int)(bitLength & 0xffffffff);
- X[15] = (int)(bitLength >>> 32);
- }
-
- private void unpackWord(
- int word,
- byte[] out,
- int outOff)
- {
- out[outOff] = (byte)word;
- out[outOff + 1] = (byte)(word >>> 8);
- out[outOff + 2] = (byte)(word >>> 16);
- out[outOff + 3] = (byte)(word >>> 24);
- }
-
- public int doFinal(
- byte[] out,
- int outOff)
- {
- finish();
-
- unpackWord(H0, out, outOff);
- unpackWord(H1, out, outOff + 4);
- unpackWord(H2, out, outOff + 8);
- unpackWord(H3, out, outOff + 12);
- unpackWord(H4, out, outOff + 16);
-
- reset();
-
- return DIGEST_LENGTH;
- }
-
- /**
- * reset the chaining variables to the IV values.
- */
- public void reset()
- {
- super.reset();
-
- H0 = 0x67452301;
- H1 = 0xefcdab89;
- H2 = 0x98badcfe;
- H3 = 0x10325476;
- H4 = 0xc3d2e1f0;
-
- xOff = 0;
-
- for (int i = 0; i != X.length; i++)
- {
- X[i] = 0;
- }
- }
-
- /*
- * rotate int x left n bits.
- */
- private int RL(
- int x,
- int n)
- {
- return (x << n) | (x >>> (32 - n));
- }
-
- /*
- * f1,f2,f3,f4,f5 are the basic RIPEMD160 functions.
- */
-
- /*
- * rounds 0-15
- */
- private int f1(
- int x,
- int y,
- int z)
- {
- return x ^ y ^ z;
- }
-
- /*
- * rounds 16-31
- */
- private int f2(
- int x,
- int y,
- int z)
- {
- return (x & y) | (~x & z);
- }
-
- /*
- * rounds 32-47
- */
- private int f3(
- int x,
- int y,
- int z)
- {
- return (x | ~y) ^ z;
- }
-
- /*
- * rounds 48-63
- */
- private int f4(
- int x,
- int y,
- int z)
- {
- return (x & z) | (y & ~z);
- }
-
- /*
- * rounds 64-79
- */
- private int f5(
- int x,
- int y,
- int z)
- {
- return x ^ (y | ~z);
- }
-
- protected void processBlock()
- {
- int a, aa;
- int b, bb;
- int c, cc;
- int d, dd;
- int e, ee;
-
- a = aa = H0;
- b = bb = H1;
- c = cc = H2;
- d = dd = H3;
- e = ee = H4;
-
- //
- // Rounds 1 - 16
- //
- // left
- a = RL(a + f1(b,c,d) + X[ 0], 11) + e; c = RL(c, 10);
- e = RL(e + f1(a,b,c) + X[ 1], 14) + d; b = RL(b, 10);
- d = RL(d + f1(e,a,b) + X[ 2], 15) + c; a = RL(a, 10);
- c = RL(c + f1(d,e,a) + X[ 3], 12) + b; e = RL(e, 10);
- b = RL(b + f1(c,d,e) + X[ 4], 5) + a; d = RL(d, 10);
- a = RL(a + f1(b,c,d) + X[ 5], 8) + e; c = RL(c, 10);
- e = RL(e + f1(a,b,c) + X[ 6], 7) + d; b = RL(b, 10);
- d = RL(d + f1(e,a,b) + X[ 7], 9) + c; a = RL(a, 10);
- c = RL(c + f1(d,e,a) + X[ 8], 11) + b; e = RL(e, 10);
- b = RL(b + f1(c,d,e) + X[ 9], 13) + a; d = RL(d, 10);
- a = RL(a + f1(b,c,d) + X[10], 14) + e; c = RL(c, 10);
- e = RL(e + f1(a,b,c) + X[11], 15) + d; b = RL(b, 10);
- d = RL(d + f1(e,a,b) + X[12], 6) + c; a = RL(a, 10);
- c = RL(c + f1(d,e,a) + X[13], 7) + b; e = RL(e, 10);
- b = RL(b + f1(c,d,e) + X[14], 9) + a; d = RL(d, 10);
- a = RL(a + f1(b,c,d) + X[15], 8) + e; c = RL(c, 10);
-
- // right
- aa = RL(aa + f5(bb,cc,dd) + X[ 5] + 0x50a28be6, 8) + ee; cc = RL(cc, 10);
- ee = RL(ee + f5(aa,bb,cc) + X[14] + 0x50a28be6, 9) + dd; bb = RL(bb, 10);
- dd = RL(dd + f5(ee,aa,bb) + X[ 7] + 0x50a28be6, 9) + cc; aa = RL(aa, 10);
- cc = RL(cc + f5(dd,ee,aa) + X[ 0] + 0x50a28be6, 11) + bb; ee = RL(ee, 10);
- bb = RL(bb + f5(cc,dd,ee) + X[ 9] + 0x50a28be6, 13) + aa; dd = RL(dd, 10);
- aa = RL(aa + f5(bb,cc,dd) + X[ 2] + 0x50a28be6, 15) + ee; cc = RL(cc, 10);
- ee = RL(ee + f5(aa,bb,cc) + X[11] + 0x50a28be6, 15) + dd; bb = RL(bb, 10);
- dd = RL(dd + f5(ee,aa,bb) + X[ 4] + 0x50a28be6, 5) + cc; aa = RL(aa, 10);
- cc = RL(cc + f5(dd,ee,aa) + X[13] + 0x50a28be6, 7) + bb; ee = RL(ee, 10);
- bb = RL(bb + f5(cc,dd,ee) + X[ 6] + 0x50a28be6, 7) + aa; dd = RL(dd, 10);
- aa = RL(aa + f5(bb,cc,dd) + X[15] + 0x50a28be6, 8) + ee; cc = RL(cc, 10);
- ee = RL(ee + f5(aa,bb,cc) + X[ 8] + 0x50a28be6, 11) + dd; bb = RL(bb, 10);
- dd = RL(dd + f5(ee,aa,bb) + X[ 1] + 0x50a28be6, 14) + cc; aa = RL(aa, 10);
- cc = RL(cc + f5(dd,ee,aa) + X[10] + 0x50a28be6, 14) + bb; ee = RL(ee, 10);
- bb = RL(bb + f5(cc,dd,ee) + X[ 3] + 0x50a28be6, 12) + aa; dd = RL(dd, 10);
- aa = RL(aa + f5(bb,cc,dd) + X[12] + 0x50a28be6, 6) + ee; cc = RL(cc, 10);
-
- //
- // Rounds 16-31
- //
- // left
- e = RL(e + f2(a,b,c) + X[ 7] + 0x5a827999, 7) + d; b = RL(b, 10);
- d = RL(d + f2(e,a,b) + X[ 4] + 0x5a827999, 6) + c; a = RL(a, 10);
- c = RL(c + f2(d,e,a) + X[13] + 0x5a827999, 8) + b; e = RL(e, 10);
- b = RL(b + f2(c,d,e) + X[ 1] + 0x5a827999, 13) + a; d = RL(d, 10);
- a = RL(a + f2(b,c,d) + X[10] + 0x5a827999, 11) + e; c = RL(c, 10);
- e = RL(e + f2(a,b,c) + X[ 6] + 0x5a827999, 9) + d; b = RL(b, 10);
- d = RL(d + f2(e,a,b) + X[15] + 0x5a827999, 7) + c; a = RL(a, 10);
- c = RL(c + f2(d,e,a) + X[ 3] + 0x5a827999, 15) + b; e = RL(e, 10);
- b = RL(b + f2(c,d,e) + X[12] + 0x5a827999, 7) + a; d = RL(d, 10);
- a = RL(a + f2(b,c,d) + X[ 0] + 0x5a827999, 12) + e; c = RL(c, 10);
- e = RL(e + f2(a,b,c) + X[ 9] + 0x5a827999, 15) + d; b = RL(b, 10);
- d = RL(d + f2(e,a,b) + X[ 5] + 0x5a827999, 9) + c; a = RL(a, 10);
- c = RL(c + f2(d,e,a) + X[ 2] + 0x5a827999, 11) + b; e = RL(e, 10);
- b = RL(b + f2(c,d,e) + X[14] + 0x5a827999, 7) + a; d = RL(d, 10);
- a = RL(a + f2(b,c,d) + X[11] + 0x5a827999, 13) + e; c = RL(c, 10);
- e = RL(e + f2(a,b,c) + X[ 8] + 0x5a827999, 12) + d; b = RL(b, 10);
-
- // right
- ee = RL(ee + f4(aa,bb,cc) + X[ 6] + 0x5c4dd124, 9) + dd; bb = RL(bb, 10);
- dd = RL(dd + f4(ee,aa,bb) + X[11] + 0x5c4dd124, 13) + cc; aa = RL(aa, 10);
- cc = RL(cc + f4(dd,ee,aa) + X[ 3] + 0x5c4dd124, 15) + bb; ee = RL(ee, 10);
- bb = RL(bb + f4(cc,dd,ee) + X[ 7] + 0x5c4dd124, 7) + aa; dd = RL(dd, 10);
- aa = RL(aa + f4(bb,cc,dd) + X[ 0] + 0x5c4dd124, 12) + ee; cc = RL(cc, 10);
- ee = RL(ee + f4(aa,bb,cc) + X[13] + 0x5c4dd124, 8) + dd; bb = RL(bb, 10);
- dd = RL(dd + f4(ee,aa,bb) + X[ 5] + 0x5c4dd124, 9) + cc; aa = RL(aa, 10);
- cc = RL(cc + f4(dd,ee,aa) + X[10] + 0x5c4dd124, 11) + bb; ee = RL(ee, 10);
- bb = RL(bb + f4(cc,dd,ee) + X[14] + 0x5c4dd124, 7) + aa; dd = RL(dd, 10);
- aa = RL(aa + f4(bb,cc,dd) + X[15] + 0x5c4dd124, 7) + ee; cc = RL(cc, 10);
- ee = RL(ee + f4(aa,bb,cc) + X[ 8] + 0x5c4dd124, 12) + dd; bb = RL(bb, 10);
- dd = RL(dd + f4(ee,aa,bb) + X[12] + 0x5c4dd124, 7) + cc; aa = RL(aa, 10);
- cc = RL(cc + f4(dd,ee,aa) + X[ 4] + 0x5c4dd124, 6) + bb; ee = RL(ee, 10);
- bb = RL(bb + f4(cc,dd,ee) + X[ 9] + 0x5c4dd124, 15) + aa; dd = RL(dd, 10);
- aa = RL(aa + f4(bb,cc,dd) + X[ 1] + 0x5c4dd124, 13) + ee; cc = RL(cc, 10);
- ee = RL(ee + f4(aa,bb,cc) + X[ 2] + 0x5c4dd124, 11) + dd; bb = RL(bb, 10);
-
- //
- // Rounds 32-47
- //
- // left
- d = RL(d + f3(e,a,b) + X[ 3] + 0x6ed9eba1, 11) + c; a = RL(a, 10);
- c = RL(c + f3(d,e,a) + X[10] + 0x6ed9eba1, 13) + b; e = RL(e, 10);
- b = RL(b + f3(c,d,e) + X[14] + 0x6ed9eba1, 6) + a; d = RL(d, 10);
- a = RL(a + f3(b,c,d) + X[ 4] + 0x6ed9eba1, 7) + e; c = RL(c, 10);
- e = RL(e + f3(a,b,c) + X[ 9] + 0x6ed9eba1, 14) + d; b = RL(b, 10);
- d = RL(d + f3(e,a,b) + X[15] + 0x6ed9eba1, 9) + c; a = RL(a, 10);
- c = RL(c + f3(d,e,a) + X[ 8] + 0x6ed9eba1, 13) + b; e = RL(e, 10);
- b = RL(b + f3(c,d,e) + X[ 1] + 0x6ed9eba1, 15) + a; d = RL(d, 10);
- a = RL(a + f3(b,c,d) + X[ 2] + 0x6ed9eba1, 14) + e; c = RL(c, 10);
- e = RL(e + f3(a,b,c) + X[ 7] + 0x6ed9eba1, 8) + d; b = RL(b, 10);
- d = RL(d + f3(e,a,b) + X[ 0] + 0x6ed9eba1, 13) + c; a = RL(a, 10);
- c = RL(c + f3(d,e,a) + X[ 6] + 0x6ed9eba1, 6) + b; e = RL(e, 10);
- b = RL(b + f3(c,d,e) + X[13] + 0x6ed9eba1, 5) + a; d = RL(d, 10);
- a = RL(a + f3(b,c,d) + X[11] + 0x6ed9eba1, 12) + e; c = RL(c, 10);
- e = RL(e + f3(a,b,c) + X[ 5] + 0x6ed9eba1, 7) + d; b = RL(b, 10);
- d = RL(d + f3(e,a,b) + X[12] + 0x6ed9eba1, 5) + c; a = RL(a, 10);
-
- // right
- dd = RL(dd + f3(ee,aa,bb) + X[15] + 0x6d703ef3, 9) + cc; aa = RL(aa, 10);
- cc = RL(cc + f3(dd,ee,aa) + X[ 5] + 0x6d703ef3, 7) + bb; ee = RL(ee, 10);
- bb = RL(bb + f3(cc,dd,ee) + X[ 1] + 0x6d703ef3, 15) + aa; dd = RL(dd, 10);
- aa = RL(aa + f3(bb,cc,dd) + X[ 3] + 0x6d703ef3, 11) + ee; cc = RL(cc, 10);
- ee = RL(ee + f3(aa,bb,cc) + X[ 7] + 0x6d703ef3, 8) + dd; bb = RL(bb, 10);
- dd = RL(dd + f3(ee,aa,bb) + X[14] + 0x6d703ef3, 6) + cc; aa = RL(aa, 10);
- cc = RL(cc + f3(dd,ee,aa) + X[ 6] + 0x6d703ef3, 6) + bb; ee = RL(ee, 10);
- bb = RL(bb + f3(cc,dd,ee) + X[ 9] + 0x6d703ef3, 14) + aa; dd = RL(dd, 10);
- aa = RL(aa + f3(bb,cc,dd) + X[11] + 0x6d703ef3, 12) + ee; cc = RL(cc, 10);
- ee = RL(ee + f3(aa,bb,cc) + X[ 8] + 0x6d703ef3, 13) + dd; bb = RL(bb, 10);
- dd = RL(dd + f3(ee,aa,bb) + X[12] + 0x6d703ef3, 5) + cc; aa = RL(aa, 10);
- cc = RL(cc + f3(dd,ee,aa) + X[ 2] + 0x6d703ef3, 14) + bb; ee = RL(ee, 10);
- bb = RL(bb + f3(cc,dd,ee) + X[10] + 0x6d703ef3, 13) + aa; dd = RL(dd, 10);
- aa = RL(aa + f3(bb,cc,dd) + X[ 0] + 0x6d703ef3, 13) + ee; cc = RL(cc, 10);
- ee = RL(ee + f3(aa,bb,cc) + X[ 4] + 0x6d703ef3, 7) + dd; bb = RL(bb, 10);
- dd = RL(dd + f3(ee,aa,bb) + X[13] + 0x6d703ef3, 5) + cc; aa = RL(aa, 10);
-
- //
- // Rounds 48-63
- //
- // left
- c = RL(c + f4(d,e,a) + X[ 1] + 0x8f1bbcdc, 11) + b; e = RL(e, 10);
- b = RL(b + f4(c,d,e) + X[ 9] + 0x8f1bbcdc, 12) + a; d = RL(d, 10);
- a = RL(a + f4(b,c,d) + X[11] + 0x8f1bbcdc, 14) + e; c = RL(c, 10);
- e = RL(e + f4(a,b,c) + X[10] + 0x8f1bbcdc, 15) + d; b = RL(b, 10);
- d = RL(d + f4(e,a,b) + X[ 0] + 0x8f1bbcdc, 14) + c; a = RL(a, 10);
- c = RL(c + f4(d,e,a) + X[ 8] + 0x8f1bbcdc, 15) + b; e = RL(e, 10);
- b = RL(b + f4(c,d,e) + X[12] + 0x8f1bbcdc, 9) + a; d = RL(d, 10);
- a = RL(a + f4(b,c,d) + X[ 4] + 0x8f1bbcdc, 8) + e; c = RL(c, 10);
- e = RL(e + f4(a,b,c) + X[13] + 0x8f1bbcdc, 9) + d; b = RL(b, 10);
- d = RL(d + f4(e,a,b) + X[ 3] + 0x8f1bbcdc, 14) + c; a = RL(a, 10);
- c = RL(c + f4(d,e,a) + X[ 7] + 0x8f1bbcdc, 5) + b; e = RL(e, 10);
- b = RL(b + f4(c,d,e) + X[15] + 0x8f1bbcdc, 6) + a; d = RL(d, 10);
- a = RL(a + f4(b,c,d) + X[14] + 0x8f1bbcdc, 8) + e; c = RL(c, 10);
- e = RL(e + f4(a,b,c) + X[ 5] + 0x8f1bbcdc, 6) + d; b = RL(b, 10);
- d = RL(d + f4(e,a,b) + X[ 6] + 0x8f1bbcdc, 5) + c; a = RL(a, 10);
- c = RL(c + f4(d,e,a) + X[ 2] + 0x8f1bbcdc, 12) + b; e = RL(e, 10);
-
- // right
- cc = RL(cc + f2(dd,ee,aa) + X[ 8] + 0x7a6d76e9, 15) + bb; ee = RL(ee, 10);
- bb = RL(bb + f2(cc,dd,ee) + X[ 6] + 0x7a6d76e9, 5) + aa; dd = RL(dd, 10);
- aa = RL(aa + f2(bb,cc,dd) + X[ 4] + 0x7a6d76e9, 8) + ee; cc = RL(cc, 10);
- ee = RL(ee + f2(aa,bb,cc) + X[ 1] + 0x7a6d76e9, 11) + dd; bb = RL(bb, 10);
- dd = RL(dd + f2(ee,aa,bb) + X[ 3] + 0x7a6d76e9, 14) + cc; aa = RL(aa, 10);
- cc = RL(cc + f2(dd,ee,aa) + X[11] + 0x7a6d76e9, 14) + bb; ee = RL(ee, 10);
- bb = RL(bb + f2(cc,dd,ee) + X[15] + 0x7a6d76e9, 6) + aa; dd = RL(dd, 10);
- aa = RL(aa + f2(bb,cc,dd) + X[ 0] + 0x7a6d76e9, 14) + ee; cc = RL(cc, 10);
- ee = RL(ee + f2(aa,bb,cc) + X[ 5] + 0x7a6d76e9, 6) + dd; bb = RL(bb, 10);
- dd = RL(dd + f2(ee,aa,bb) + X[12] + 0x7a6d76e9, 9) + cc; aa = RL(aa, 10);
- cc = RL(cc + f2(dd,ee,aa) + X[ 2] + 0x7a6d76e9, 12) + bb; ee = RL(ee, 10);
- bb = RL(bb + f2(cc,dd,ee) + X[13] + 0x7a6d76e9, 9) + aa; dd = RL(dd, 10);
- aa = RL(aa + f2(bb,cc,dd) + X[ 9] + 0x7a6d76e9, 12) + ee; cc = RL(cc, 10);
- ee = RL(ee + f2(aa,bb,cc) + X[ 7] + 0x7a6d76e9, 5) + dd; bb = RL(bb, 10);
- dd = RL(dd + f2(ee,aa,bb) + X[10] + 0x7a6d76e9, 15) + cc; aa = RL(aa, 10);
- cc = RL(cc + f2(dd,ee,aa) + X[14] + 0x7a6d76e9, 8) + bb; ee = RL(ee, 10);
-
- //
- // Rounds 64-79
- //
- // left
- b = RL(b + f5(c,d,e) + X[ 4] + 0xa953fd4e, 9) + a; d = RL(d, 10);
- a = RL(a + f5(b,c,d) + X[ 0] + 0xa953fd4e, 15) + e; c = RL(c, 10);
- e = RL(e + f5(a,b,c) + X[ 5] + 0xa953fd4e, 5) + d; b = RL(b, 10);
- d = RL(d + f5(e,a,b) + X[ 9] + 0xa953fd4e, 11) + c; a = RL(a, 10);
- c = RL(c + f5(d,e,a) + X[ 7] + 0xa953fd4e, 6) + b; e = RL(e, 10);
- b = RL(b + f5(c,d,e) + X[12] + 0xa953fd4e, 8) + a; d = RL(d, 10);
- a = RL(a + f5(b,c,d) + X[ 2] + 0xa953fd4e, 13) + e; c = RL(c, 10);
- e = RL(e + f5(a,b,c) + X[10] + 0xa953fd4e, 12) + d; b = RL(b, 10);
- d = RL(d + f5(e,a,b) + X[14] + 0xa953fd4e, 5) + c; a = RL(a, 10);
- c = RL(c + f5(d,e,a) + X[ 1] + 0xa953fd4e, 12) + b; e = RL(e, 10);
- b = RL(b + f5(c,d,e) + X[ 3] + 0xa953fd4e, 13) + a; d = RL(d, 10);
- a = RL(a + f5(b,c,d) + X[ 8] + 0xa953fd4e, 14) + e; c = RL(c, 10);
- e = RL(e + f5(a,b,c) + X[11] + 0xa953fd4e, 11) + d; b = RL(b, 10);
- d = RL(d + f5(e,a,b) + X[ 6] + 0xa953fd4e, 8) + c; a = RL(a, 10);
- c = RL(c + f5(d,e,a) + X[15] + 0xa953fd4e, 5) + b; e = RL(e, 10);
- b = RL(b + f5(c,d,e) + X[13] + 0xa953fd4e, 6) + a; d = RL(d, 10);
-
- // right
- bb = RL(bb + f1(cc,dd,ee) + X[12], 8) + aa; dd = RL(dd, 10);
- aa = RL(aa + f1(bb,cc,dd) + X[15], 5) + ee; cc = RL(cc, 10);
- ee = RL(ee + f1(aa,bb,cc) + X[10], 12) + dd; bb = RL(bb, 10);
- dd = RL(dd + f1(ee,aa,bb) + X[ 4], 9) + cc; aa = RL(aa, 10);
- cc = RL(cc + f1(dd,ee,aa) + X[ 1], 12) + bb; ee = RL(ee, 10);
- bb = RL(bb + f1(cc,dd,ee) + X[ 5], 5) + aa; dd = RL(dd, 10);
- aa = RL(aa + f1(bb,cc,dd) + X[ 8], 14) + ee; cc = RL(cc, 10);
- ee = RL(ee + f1(aa,bb,cc) + X[ 7], 6) + dd; bb = RL(bb, 10);
- dd = RL(dd + f1(ee,aa,bb) + X[ 6], 8) + cc; aa = RL(aa, 10);
- cc = RL(cc + f1(dd,ee,aa) + X[ 2], 13) + bb; ee = RL(ee, 10);
- bb = RL(bb + f1(cc,dd,ee) + X[13], 6) + aa; dd = RL(dd, 10);
- aa = RL(aa + f1(bb,cc,dd) + X[14], 5) + ee; cc = RL(cc, 10);
- ee = RL(ee + f1(aa,bb,cc) + X[ 0], 15) + dd; bb = RL(bb, 10);
- dd = RL(dd + f1(ee,aa,bb) + X[ 3], 13) + cc; aa = RL(aa, 10);
- cc = RL(cc + f1(dd,ee,aa) + X[ 9], 11) + bb; ee = RL(ee, 10);
- bb = RL(bb + f1(cc,dd,ee) + X[11], 11) + aa; dd = RL(dd, 10);
-
- dd += c + H1;
- H1 = H2 + d + ee;
- H2 = H3 + e + aa;
- H3 = H4 + a + bb;
- H4 = H0 + b + cc;
- H0 = dd;
-
- //
- // reset the offset and clean out the word buffer.
- //
- xOff = 0;
- for (int i = 0; i != X.length; i++)
- {
- X[i] = 0;
- }
- }
-
- public Memoable copy()
- {
- return new RIPEMD160Digest(this);
- }
-
- public void reset(Memoable other)
- {
- RIPEMD160Digest d = (RIPEMD160Digest)other;
-
- copyIn(d);
- }
-}
diff --git a/quartz/src/main/java/com/vitorpamplona/quartz/nip03Timestamp/ots/exceptions/CommitmentNotFoundException.java b/quartz/src/main/java/com/vitorpamplona/quartz/nip03Timestamp/ots/exceptions/CommitmentNotFoundException.java
deleted file mode 100644
index 47af42bf2..000000000
--- a/quartz/src/main/java/com/vitorpamplona/quartz/nip03Timestamp/ots/exceptions/CommitmentNotFoundException.java
+++ /dev/null
@@ -1,7 +0,0 @@
-package com.vitorpamplona.quartz.nip03Timestamp.ots.exceptions;
-
-public class CommitmentNotFoundException extends Exception {
- public CommitmentNotFoundException(String message) {
- super(message);
- }
-}
diff --git a/quartz/src/main/java/com/vitorpamplona/quartz/nip03Timestamp/ots/exceptions/DeserializationException.java b/quartz/src/main/java/com/vitorpamplona/quartz/nip03Timestamp/ots/exceptions/DeserializationException.java
deleted file mode 100644
index 2b5d46265..000000000
--- a/quartz/src/main/java/com/vitorpamplona/quartz/nip03Timestamp/ots/exceptions/DeserializationException.java
+++ /dev/null
@@ -1,7 +0,0 @@
-package com.vitorpamplona.quartz.nip03Timestamp.ots.exceptions;
-
-public class DeserializationException extends Exception {
- public DeserializationException(String message) {
- super(message);
- }
-}
diff --git a/quartz/src/main/java/com/vitorpamplona/quartz/nip03Timestamp/ots/exceptions/ExceededSizeException.java b/quartz/src/main/java/com/vitorpamplona/quartz/nip03Timestamp/ots/exceptions/ExceededSizeException.java
deleted file mode 100644
index 7c2269a45..000000000
--- a/quartz/src/main/java/com/vitorpamplona/quartz/nip03Timestamp/ots/exceptions/ExceededSizeException.java
+++ /dev/null
@@ -1,7 +0,0 @@
-package com.vitorpamplona.quartz.nip03Timestamp.ots.exceptions;
-
-public class ExceededSizeException extends Exception {
- public ExceededSizeException(String message) {
- super(message);
- }
-}
diff --git a/quartz/src/main/java/com/vitorpamplona/quartz/nip03Timestamp/ots/exceptions/UrlException.java b/quartz/src/main/java/com/vitorpamplona/quartz/nip03Timestamp/ots/exceptions/UrlException.java
deleted file mode 100644
index d5a195505..000000000
--- a/quartz/src/main/java/com/vitorpamplona/quartz/nip03Timestamp/ots/exceptions/UrlException.java
+++ /dev/null
@@ -1,7 +0,0 @@
-package com.vitorpamplona.quartz.nip03Timestamp.ots.exceptions;
-
-public class UrlException extends Exception {
- public UrlException(String message) {
- super(message);
- }
-}
diff --git a/quartz/src/main/java/com/vitorpamplona/quartz/nip03Timestamp/ots/exceptions/VerificationException.java b/quartz/src/main/java/com/vitorpamplona/quartz/nip03Timestamp/ots/exceptions/VerificationException.java
deleted file mode 100644
index 39e24656a..000000000
--- a/quartz/src/main/java/com/vitorpamplona/quartz/nip03Timestamp/ots/exceptions/VerificationException.java
+++ /dev/null
@@ -1,7 +0,0 @@
-package com.vitorpamplona.quartz.nip03Timestamp.ots.exceptions;
-
-public class VerificationException extends Exception {
- public VerificationException(String message) {
- super(message);
- }
-}
diff --git a/quartz/src/main/java/com/vitorpamplona/quartz/nip03Timestamp/ots/http/Request.java b/quartz/src/main/java/com/vitorpamplona/quartz/nip03Timestamp/ots/http/Request.java
deleted file mode 100644
index c2dd66c76..000000000
--- a/quartz/src/main/java/com/vitorpamplona/quartz/nip03Timestamp/ots/http/Request.java
+++ /dev/null
@@ -1,92 +0,0 @@
-package com.vitorpamplona.quartz.nip03Timestamp.ots.http;
-
-import android.util.Log;
-
-import java.io.DataOutputStream;
-import java.io.InputStream;
-import java.net.HttpURLConnection;
-import java.net.URL;
-import java.util.Map;
-import java.util.concurrent.BlockingQueue;
-import java.util.concurrent.Callable;
-import java.util.zip.GZIPInputStream;
-
-/**
- * For making an HTTP request.
- */
-public class Request implements Callable
- * For a verifier, this limit is what limits the maximum amount of memory you
- * need at any one time to verify a particular timestamp path; while verifying
- * a particular commitment operation path previously calculated results can be
- * discarded.
- *
- * Of course, if everything was a merkle tree you never need to append/prepend
- * anything near 4KiB of data; 64 bytes would be plenty even with SHA512. The
- * main need for this is compatibility with existing systems like Bitcoin
- * timestamps and Certificate Transparency servers. While the pathological
- * limits required by both are quite large - 1MB and 16MiB respectively - 4KiB
- * is perfectly adequate in both cases for more reasonable usage.
- *
- * @see Op subclasses should set this limit even lower if doing so is appropriate
- * for them.
- */
- public static int _MAX_RESULT_LENGTH = 4096;
-
- /**
- * Maximum length of the message an com.vitorpamplona.quartz.ots.op.Op can be applied too.
- *
- * Similar to the result length limit, this limit gives implementations a sane
- * constraint to work with; the maximum result-length limit implicitly
- * constrains maximum message length anyway.
- *
- * com.vitorpamplona.quartz.ots.op.Op subclasses should set this limit even lower if doing so is appropriate
- * for them.
- */
- public static int _MAX_MSG_LENGTH = 4096;
-
- public static byte _TAG = (byte) 0x00;
-
- public String _TAG_NAME() {
- return "";
- }
-
- public byte _TAG() {
- return Op._TAG;
- }
-
- /**
- * Deserialize operation from a buffer.
- *
- * @param ctx The stream deserialization context.
- * @return The subclass Operation.
- */
- public static Op deserialize(StreamDeserializationContext ctx) throws DeserializationException {
- byte tag = ctx.readBytes(1)[0];
-
- return Op.deserializeFromTag(ctx, tag);
- }
-
- /**
- * Deserialize operation from a buffer.
- *
- * @param ctx The stream deserialization context.
- * @param tag The tag of the operation.
- * @return The subclass Operation.
- */
- public static Op deserializeFromTag(StreamDeserializationContext ctx, byte tag)
- throws DeserializationException {
- if (tag == OpAppend._TAG) {
- return OpAppend.deserializeFromTag(ctx, tag);
- } else if (tag == OpPrepend._TAG) {
- return OpPrepend.deserializeFromTag(ctx, tag);
- } else if (tag == OpSHA1._TAG) {
- return OpSHA1.deserializeFromTag(ctx, tag);
- } else if (tag == OpSHA256._TAG) {
- return OpSHA256.deserializeFromTag(ctx, tag);
- } else if (tag == OpRIPEMD160._TAG) {
- return OpRIPEMD160.deserializeFromTag(ctx, tag);
- } else if (tag == OpKECCAK256._TAG) {
- return OpKECCAK256.deserializeFromTag(ctx, tag);
- } else {
- Log.e("OpenTimestamp", "Unknown operation tag: " + tag + " 0x" + String.format("%02x", tag));
- return null; // TODO: Is this OK? Won't it blow up later? Better to throw?
- }
- }
-
- /**
- * Serialize operation.
- *
- * @param ctx The stream serialization context.
- */
- public void serialize(StreamSerializationContext ctx) {
- if (this._TAG() == 0x00) {
- Log.e("OpenTimestamp", "No valid serialized Op");
- // TODO: Is it OK to just log and carry on? Won't it blow up later? Better to throw?
- }
-
- ctx.writeByte(this._TAG());
- }
-
- /**
- * Apply the operation to a message.
- * Raises MsgValueError if the message value is invalid, such as it being
- * too long, or it causing the result to be too long.
- *
- * @param msg The message.
- * @return the msg after the operation has been applied
- */
- public byte[] call(byte[] msg) {
- if (msg.length > _MAX_MSG_LENGTH) {
- Log.e("OpenTimestamp", "Error : Message too long;");
- return new byte[]{}; // TODO: Is this OK? Won't it blow up later? Better to throw?
- }
-
- byte[] r = this.call(msg);
-
- if (r.length > _MAX_RESULT_LENGTH) {
- Log.e("OpenTimestamp", "Error : Result too long;");
- // TODO: Is it OK to just log and carry on? Won't it blow up later? Better to throw?
- }
-
- return r;
- }
-
- @Override
- public int compareTo(Op o) {
- return this._TAG() - o._TAG();
- }
-}
diff --git a/quartz/src/main/java/com/vitorpamplona/quartz/nip03Timestamp/ots/op/OpAppend.java b/quartz/src/main/java/com/vitorpamplona/quartz/nip03Timestamp/ots/op/OpAppend.java
deleted file mode 100644
index e1631278a..000000000
--- a/quartz/src/main/java/com/vitorpamplona/quartz/nip03Timestamp/ots/op/OpAppend.java
+++ /dev/null
@@ -1,62 +0,0 @@
-package com.vitorpamplona.quartz.nip03Timestamp.ots.op;
-
-import com.vitorpamplona.quartz.nip03Timestamp.ots.StreamDeserializationContext;
-import com.vitorpamplona.quartz.nip03Timestamp.ots.Utils;
-import com.vitorpamplona.quartz.nip03Timestamp.ots.exceptions.DeserializationException;
-
-import java.util.Arrays;
-
-/**
- * Append a suffix to a message.
- *
- * @see OpBinary
- */
-public class OpAppend extends OpBinary {
- byte[] arg;
-
- public static byte _TAG = (byte) 0xf0;
-
- @Override
- public byte _TAG() {
- return OpAppend._TAG;
- }
-
- @Override
- public String _TAG_NAME() {
- return "append";
- }
-
- public OpAppend() {
- super();
- this.arg = new byte[]{};
- }
-
- public OpAppend(byte[] arg_) {
- super(arg_);
- this.arg = arg_;
- }
-
- @Override
- public byte[] call(byte[] msg) {
- return Utils.arraysConcat(msg, this.arg);
- }
-
- public static Op deserializeFromTag(StreamDeserializationContext ctx, byte tag)
- throws DeserializationException {
- return OpBinary.deserializeFromTag(ctx, tag);
- }
-
- @Override
- public boolean equals(Object obj) {
- if (!(obj instanceof OpAppend)) {
- return false;
- }
-
- return Arrays.equals(this.arg, ((OpAppend) obj).arg);
- }
-
- @Override
- public int hashCode() {
- return _TAG ^ Arrays.hashCode(this.arg);
- }
-}
diff --git a/quartz/src/main/java/com/vitorpamplona/quartz/nip03Timestamp/ots/op/OpBinary.java b/quartz/src/main/java/com/vitorpamplona/quartz/nip03Timestamp/ots/op/OpBinary.java
deleted file mode 100644
index 5a16b9732..000000000
--- a/quartz/src/main/java/com/vitorpamplona/quartz/nip03Timestamp/ots/op/OpBinary.java
+++ /dev/null
@@ -1,76 +0,0 @@
-package com.vitorpamplona.quartz.nip03Timestamp.ots.op;
-
-import android.util.Log;
-
-import com.vitorpamplona.quartz.nip03Timestamp.ots.StreamDeserializationContext;
-import com.vitorpamplona.quartz.nip03Timestamp.ots.StreamSerializationContext;
-import com.vitorpamplona.quartz.nip03Timestamp.ots.Utils;
-import com.vitorpamplona.quartz.nip03Timestamp.ots.exceptions.DeserializationException;
-import com.vitorpamplona.quartz.utils.Hex;
-
-import java.util.Arrays;
-import java.util.Locale;
-
-/**
- * Operations that act on a message and a single argument.
- *
- * @see OpUnary
- */
-public abstract class OpBinary extends Op implements Comparable