diff options
author | David Hook <dgh@cryptoworkshop.com> | 2014-05-25 08:37:41 +0400 |
---|---|---|
committer | David Hook <dgh@cryptoworkshop.com> | 2014-05-25 08:37:41 +0400 |
commit | 7b9d9c412c29a12ea3cfecc35ecdbeba96d1c4ce (patch) | |
tree | 90a9835f2b5456b25e17b19e825147960b207a63 /core/src/main/java/org/bouncycastle/crypto | |
parent | d9c5523df0b969c851272bc50d79269b3940c859 (diff) |
brought processByte in StreamCipher into line with other usages.
Diffstat (limited to 'core/src/main/java/org/bouncycastle/crypto')
15 files changed, 38 insertions, 19 deletions
diff --git a/core/src/main/java/org/bouncycastle/crypto/StreamBlockCipher.java b/core/src/main/java/org/bouncycastle/crypto/StreamBlockCipher.java index 5d4050a6..09aadfbf 100644 --- a/core/src/main/java/org/bouncycastle/crypto/StreamBlockCipher.java +++ b/core/src/main/java/org/bouncycastle/crypto/StreamBlockCipher.java @@ -26,10 +26,10 @@ public abstract class StreamBlockCipher public final byte returnByte(byte in) { - return processByte(in); + return calculateByte(in); } - public void processBytes(byte[] in, int inOff, int len, byte[] out, int outOff) + public int processBytes(byte[] in, int inOff, int len, byte[] out, int outOff) throws DataLengthException { if (outOff + len > out.length) @@ -48,9 +48,11 @@ public abstract class StreamBlockCipher while (inStart < inEnd) { - out[outStart++] = processByte(in[inStart++]); + out[outStart++] = calculateByte(in[inStart++]); } + + return len; } - protected abstract byte processByte(byte b); + protected abstract byte calculateByte(byte b); }
\ No newline at end of file diff --git a/core/src/main/java/org/bouncycastle/crypto/StreamCipher.java b/core/src/main/java/org/bouncycastle/crypto/StreamCipher.java index 2a55d4f6..c1255e94 100644 --- a/core/src/main/java/org/bouncycastle/crypto/StreamCipher.java +++ b/core/src/main/java/org/bouncycastle/crypto/StreamCipher.java @@ -40,9 +40,10 @@ public interface StreamCipher * @param len the number of bytes to be processed. * @param out the output buffer the processed bytes go into. * @param outOff the offset into the output byte array the processed data starts at. + * @return the number of bytes produced - should always be len. * @exception DataLengthException if the output buffer is too small. */ - public void processBytes(byte[] in, int inOff, int len, byte[] out, int outOff) + public int processBytes(byte[] in, int inOff, int len, byte[] out, int outOff) throws DataLengthException; /** diff --git a/core/src/main/java/org/bouncycastle/crypto/engines/Grain128Engine.java b/core/src/main/java/org/bouncycastle/crypto/engines/Grain128Engine.java index 89271f0d..f5ecb75c 100644 --- a/core/src/main/java/org/bouncycastle/crypto/engines/Grain128Engine.java +++ b/core/src/main/java/org/bouncycastle/crypto/engines/Grain128Engine.java @@ -232,7 +232,7 @@ public class Grain128Engine } } - public void processBytes(byte[] in, int inOff, int len, byte[] out, + public int processBytes(byte[] in, int inOff, int len, byte[] out, int outOff) throws DataLengthException { @@ -256,6 +256,8 @@ public class Grain128Engine { out[outOff + i] = (byte)(in[inOff + i] ^ getKeyStream()); } + + return len; } public void reset() diff --git a/core/src/main/java/org/bouncycastle/crypto/engines/Grainv1Engine.java b/core/src/main/java/org/bouncycastle/crypto/engines/Grainv1Engine.java index 782a93ce..77f52d1c 100644 --- a/core/src/main/java/org/bouncycastle/crypto/engines/Grainv1Engine.java +++ b/core/src/main/java/org/bouncycastle/crypto/engines/Grainv1Engine.java @@ -220,7 +220,7 @@ public class Grainv1Engine } } - public void processBytes(byte[] in, int inOff, int len, byte[] out, + public int processBytes(byte[] in, int inOff, int len, byte[] out, int outOff) throws DataLengthException { @@ -244,6 +244,8 @@ public class Grainv1Engine { out[outOff + i] = (byte)(in[inOff + i] ^ getKeyStream()); } + + return len; } public void reset() diff --git a/core/src/main/java/org/bouncycastle/crypto/engines/HC128Engine.java b/core/src/main/java/org/bouncycastle/crypto/engines/HC128Engine.java index 015e49e4..7d18d623 100644 --- a/core/src/main/java/org/bouncycastle/crypto/engines/HC128Engine.java +++ b/core/src/main/java/org/bouncycastle/crypto/engines/HC128Engine.java @@ -220,7 +220,7 @@ public class HC128Engine return ret; } - public void processBytes(byte[] in, int inOff, int len, byte[] out, + public int processBytes(byte[] in, int inOff, int len, byte[] out, int outOff) throws DataLengthException { if (!initialised) @@ -243,6 +243,8 @@ public class HC128Engine { out[outOff + i] = (byte)(in[inOff + i] ^ getByte()); } + + return len; } public void reset() diff --git a/core/src/main/java/org/bouncycastle/crypto/engines/HC256Engine.java b/core/src/main/java/org/bouncycastle/crypto/engines/HC256Engine.java index 8bd7e9da..a74164ae 100644 --- a/core/src/main/java/org/bouncycastle/crypto/engines/HC256Engine.java +++ b/core/src/main/java/org/bouncycastle/crypto/engines/HC256Engine.java @@ -200,7 +200,7 @@ public class HC256Engine return ret; } - public void processBytes(byte[] in, int inOff, int len, byte[] out, + public int processBytes(byte[] in, int inOff, int len, byte[] out, int outOff) throws DataLengthException { if (!initialised) @@ -223,6 +223,8 @@ public class HC256Engine { out[outOff + i] = (byte)(in[inOff + i] ^ getByte()); } + + return len; } public void reset() diff --git a/core/src/main/java/org/bouncycastle/crypto/engines/ISAACEngine.java b/core/src/main/java/org/bouncycastle/crypto/engines/ISAACEngine.java index dbf5b6ab..d2dd2657 100644 --- a/core/src/main/java/org/bouncycastle/crypto/engines/ISAACEngine.java +++ b/core/src/main/java/org/bouncycastle/crypto/engines/ISAACEngine.java @@ -69,7 +69,7 @@ public class ISAACEngine return out; } - public void processBytes( + public int processBytes( byte[] in, int inOff, int len, @@ -101,6 +101,8 @@ public class ISAACEngine out[i+outOff] = (byte)(keyStream[index]^in[i+inOff]); index = (index + 1) & 1023; } + + return len; } public String getAlgorithmName() diff --git a/core/src/main/java/org/bouncycastle/crypto/engines/RC4Engine.java b/core/src/main/java/org/bouncycastle/crypto/engines/RC4Engine.java index 4de7ea69..c1ceaa4a 100644 --- a/core/src/main/java/org/bouncycastle/crypto/engines/RC4Engine.java +++ b/core/src/main/java/org/bouncycastle/crypto/engines/RC4Engine.java @@ -68,7 +68,7 @@ public class RC4Engine implements StreamCipher return (byte)(in ^ engineState[(engineState[x] + engineState[y]) & 0xff]); } - public void processBytes( + public int processBytes( byte[] in, int inOff, int len, @@ -99,6 +99,8 @@ public class RC4Engine implements StreamCipher out[i+outOff] = (byte)(in[i + inOff] ^ engineState[(engineState[x] + engineState[y]) & 0xff]); } + + return len; } public void reset() diff --git a/core/src/main/java/org/bouncycastle/crypto/engines/Salsa20Engine.java b/core/src/main/java/org/bouncycastle/crypto/engines/Salsa20Engine.java index ad11bbd0..a6acc96f 100644 --- a/core/src/main/java/org/bouncycastle/crypto/engines/Salsa20Engine.java +++ b/core/src/main/java/org/bouncycastle/crypto/engines/Salsa20Engine.java @@ -170,7 +170,7 @@ public class Salsa20Engine } } - public void processBytes( + public int processBytes( byte[] in, int inOff, int len, @@ -208,6 +208,8 @@ public class Salsa20Engine generateKeyStream(keyStream); } } + + return len; } public long skip(long numberOfBytes) diff --git a/core/src/main/java/org/bouncycastle/crypto/engines/VMPCEngine.java b/core/src/main/java/org/bouncycastle/crypto/engines/VMPCEngine.java index f16f6d44..364c5d82 100644 --- a/core/src/main/java/org/bouncycastle/crypto/engines/VMPCEngine.java +++ b/core/src/main/java/org/bouncycastle/crypto/engines/VMPCEngine.java @@ -91,7 +91,7 @@ public class VMPCEngine implements StreamCipher n = 0; } - public void processBytes(byte[] in, int inOff, int len, byte[] out, + public int processBytes(byte[] in, int inOff, int len, byte[] out, int outOff) { if ((inOff + len) > in.length) @@ -117,6 +117,8 @@ public class VMPCEngine implements StreamCipher // xor out[i + outOff] = (byte) (in[i + inOff] ^ z); } + + return len; } public void reset() diff --git a/core/src/main/java/org/bouncycastle/crypto/modes/CFBBlockCipher.java b/core/src/main/java/org/bouncycastle/crypto/modes/CFBBlockCipher.java index a82fae5f..6167d256 100644 --- a/core/src/main/java/org/bouncycastle/crypto/modes/CFBBlockCipher.java +++ b/core/src/main/java/org/bouncycastle/crypto/modes/CFBBlockCipher.java @@ -113,7 +113,7 @@ public class CFBBlockCipher return cipher.getAlgorithmName() + "/CFB" + (blockSize * 8); } - protected byte processByte(byte in) + protected byte calculateByte(byte in) throws DataLengthException, IllegalStateException { return (encrypting) ? encryptByte(in) : decryptByte(in); diff --git a/core/src/main/java/org/bouncycastle/crypto/modes/GCFBBlockCipher.java b/core/src/main/java/org/bouncycastle/crypto/modes/GCFBBlockCipher.java index 2f84bc5a..5791e89c 100644 --- a/core/src/main/java/org/bouncycastle/crypto/modes/GCFBBlockCipher.java +++ b/core/src/main/java/org/bouncycastle/crypto/modes/GCFBBlockCipher.java @@ -81,7 +81,7 @@ public class GCFBBlockCipher return cfbEngine.getBlockSize(); } - protected byte processByte(byte b) + protected byte calculateByte(byte b) { if (counter > 0 && counter % 1024 == 0) { @@ -109,7 +109,7 @@ public class GCFBBlockCipher counter++; - return cfbEngine.processByte(b); + return cfbEngine.calculateByte(b); } public void reset() diff --git a/core/src/main/java/org/bouncycastle/crypto/modes/GOFBBlockCipher.java b/core/src/main/java/org/bouncycastle/crypto/modes/GOFBBlockCipher.java index ccd9e0f7..b025a1b8 100644 --- a/core/src/main/java/org/bouncycastle/crypto/modes/GOFBBlockCipher.java +++ b/core/src/main/java/org/bouncycastle/crypto/modes/GOFBBlockCipher.java @@ -191,7 +191,7 @@ public class GOFBBlockCipher out[outOff] = (byte)num; } - protected byte processByte(byte b) + protected byte calculateByte(byte b) { if (byteCount == 0) { diff --git a/core/src/main/java/org/bouncycastle/crypto/modes/OFBBlockCipher.java b/core/src/main/java/org/bouncycastle/crypto/modes/OFBBlockCipher.java index 7655535f..d9ff428f 100644 --- a/core/src/main/java/org/bouncycastle/crypto/modes/OFBBlockCipher.java +++ b/core/src/main/java/org/bouncycastle/crypto/modes/OFBBlockCipher.java @@ -155,7 +155,7 @@ public class OFBBlockCipher cipher.reset(); } - protected byte processByte(byte in) + protected byte calculateByte(byte in) throws DataLengthException, IllegalStateException { if (byteCount == 0) diff --git a/core/src/main/java/org/bouncycastle/crypto/modes/SICBlockCipher.java b/core/src/main/java/org/bouncycastle/crypto/modes/SICBlockCipher.java index e27a5f2f..9068304b 100644 --- a/core/src/main/java/org/bouncycastle/crypto/modes/SICBlockCipher.java +++ b/core/src/main/java/org/bouncycastle/crypto/modes/SICBlockCipher.java @@ -84,7 +84,7 @@ public class SICBlockCipher return blockSize; } - protected byte processByte(byte in) + protected byte calculateByte(byte in) throws DataLengthException, IllegalStateException { if (byteCount == 0) |