Skip to content

Commit

Permalink
new MultiBlockCipher interface.
Browse files Browse the repository at this point in the history
  • Loading branch information
dghgit committed Jul 29, 2022
1 parent 16c9fd5 commit c34accc
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.bouncycastle.crypto;

public abstract class DefaultMultiBlockCipher
implements MultiBlockCipher
{
protected DefaultMultiBlockCipher()
{
}

public int getMultiBlockSize()
{
return this.getBlockSize();
}

public int processBlocks(byte[] in, int inOff, int blockCount, byte[] out, int outOff)
throws DataLengthException, IllegalStateException
{

// TODO check if the underlying cipher supports the multiblock interface and call it directly?

int resultLen = 0;
int blockSize = this.getMultiBlockSize();

for (int i = 0; i != blockCount; i++)
{
resultLen += this.processBlock(in, inOff, out, outOff + resultLen);

inOff += blockSize;
}

return resultLen;
}
}
31 changes: 31 additions & 0 deletions core/src/main/java/org/bouncycastle/crypto/MultiBlockCipher.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.bouncycastle.crypto;

/**
* Base interface for a cipher engine capable of processing multiple blocks at a time.
*/
public interface MultiBlockCipher
extends BlockCipher
{
/**
* Return the multi-block size for this cipher (in bytes).
*
* @return the multi-block size for this cipher in bytes.
*/
int getMultiBlockSize();

/**
* Process blockCount blocks from input in offset inOff and place the output in
* out from offset outOff.
*
* @param in input data array.
* @param inOff start of input data in in.
* @param blockCount number of blocks to be processed.
* @param out output data array.
* @param outOff start position for output data.
* @return number of bytes written to out.
* @throws DataLengthException
* @throws IllegalStateException
*/
int processBlocks(byte[] in, int inOff, int blockCount, byte[] out, int outOff)
throws DataLengthException, IllegalStateException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
* a streaming mode.
*/
public abstract class StreamBlockCipher
implements BlockCipher, StreamCipher
extends DefaultMultiBlockCipher
implements StreamCipher
{
private final BlockCipher cipher;

Expand Down

0 comments on commit c34accc

Please sign in to comment.