IBlockCipherParams interface
Contents
- Introduction to the Library
- Basic support package (com.kryptel.bslx)
- Kryptel API Commons package (com.kryptel)
- Cipher package (com.kryptel.cipher)
- Compressor package (com.kryptel.compressor)
- Exceptions package (com.kryptel.exceptions)
- Hash function package (com.kryptel.hash_function)
- MAC function package (com.kryptel.mac)
- Key-related functions (com.kryptel.key)
- Silver Key engine (com.kryptel.silver_key)
- Kryptel encrypted storage (com.kryptel.storage)
Declaration
package com.kryptel.cipher; public interface IBlockCipherParams extends ICipherParams { static final int MODE_ECB = 0; static final int MODE_CBC = 1; static final int MODE_CFB = 2; static final int MODE_OFB = 3; static final int MODE_CTR = 4; int GetBlockSize() throws Exception; int GetChainingMode() throws Exception; byte[] GetInitVector() throws Exception; void SetBlockSize(int size) throws Exception; void SetChainingMode(int mode) throws Exception; void SetInitVector(byte[] vector, int start, int size) throws Exception; }
Description
This interface extends ICipherParams with the parameters specific for block ciphers, namely block size, block chaining mode, and initialization vector.
MODE_* Constants
static final int MODE_ECB = 0; static final int MODE_CBC = 1; static final int MODE_CFB = 2; static final int MODE_OFB = 3; static final int MODE_CTR = 4;
These constants represent block chaining mode as defined in NIST recommendation SP 800-38A. See methods GetChainingMode and SetChainingMode.
GetBlockSize
int GetBlockSize() throws Exception;
Returns the cipher block size in bytes.
GetChainingMode
int GetChainingMode() throws Exception;
Returns the current block chaining mode (one of the MODE_* constants).
GetInitVector
byte[] GetInitVector() throws Exception;
Returns the currently set cipher initialization vector. The returned vector is the being actually used normalized vector, and not the original vector provided as the argument of the SetInitVector method. See SetInitVector for notes on vector normalizing procedure.
SetBlockSize
void SetBlockSize(int size) throws Exception;
Sets cipher block size (in bytes). The argument must be one of the valid block size values (see CipherInfo) or DEFAULT_VALUE to set the default block size, which depends on specific implementations.
SetChainingMode
void SetChainingMode(int mode) throws Exception;
Sets the block chaining mode. The argument must be one of the MODE_* constants. The default chaining mode is CTR (don't rely on this though).
SetInitVector
void SetInitVector(byte[] vector, int start, int size) throws Exception;
Set cipher initialization vector. The vector is used to start block chaining. Note that in the ECB mode cipher does not chain blocks so the init vector is not used.
If the length of the provided vector is not equal to the cipher block size, the vector gets normalized. If the vector is longer, it is truncated. If the vector is shorter, zero bytes are added at the end. Note that a cipher implementation, which is not based on the BlockCipherBase class, may use a different normalization method.
The default init vector is all zeroes. Different implementations however may have different defaults; always set the init vector explicitly.