forked from bcgit/bc-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
66 additions
and
1 deletion.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
core/src/main/java/org/bouncycastle/crypto/DefaultMultiBlockCipher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
31
core/src/main/java/org/bouncycastle/crypto/MultiBlockCipher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters