How to Add a New Cipher

Adding a New Cipher

Class com.kryptel.cipher.BlockCipherBase lets you easily add a new block cipher to the library. The first step you need to do is to create a new CID (component ID). Add a new record to the com.kryptel.Guids class. Please remember that CIDs 11056249-400A-4461-BD5E-xxxxxxxxxxxx are reserved.

static public final UUID CID_MY_COOL_CIPHER =

Now declare your cipher class by extending the com.kryptel.cipher.BlockCipherBase class.

final class MyCoolCipher extends BlockCipherBase {

Declare a static constant componentID containing the CID of your cipher:

static final UUID componentID = CID_MY_COOL_CIPHER;

Declare a class constructor to initialize the CipherInfo structure describing your cipher, and default cipher parameters:

MyCoolCipher(long capabilities) {


  private static final CipherInfo info = new CipherInfo(
    new int[] { 16, 32 },     // Key sizes (128 and 256 bits)
    new int[] { 16, 32 },     // Block sizes (128 and 256 bits)
    new int[] { 1 },          // Rounds
    new String[] { "Standard" }

  cipherKeySize = DEFAULT_KEY_SIZE;
  cipherBlockSize = DEFAULT_BLOCK_SIZE;
  cipherRounds = DEFAULT_ROUNDS;
  cipherScheme = DEFAULT_SCHEME;

  // Other construction code

Implement IKryptelComponent methods, which BlockCipherBase does not implement.

public UUID ComponentID() { return componentID; }
public String ComponentName() { return "My Cool Cipher"; }

Now it is time to add the actual cipher implementation. Override three abstract functions – ExpandKey, EncryptBasicBlock, and DecryptBasicBlock. ExpandKey is called by the ICipherParams.SetKey method to prepare (expand) key for using by encryption and decryption methods. The key to be expanded is in the cipherKey byte array. The size of the array is the current key size, which may be found in the variable cipherKeySize.

EncryptBasicBlock and DecryptBasicBlock correspondingly encrypt or decrypt single block of data residing in src at from position, and store the resulting block of data to dst at to position.

protected void ExpandKey()

protected void EncryptBasicBlock(byte[] dst, int to, byte[] src, int from)

protected void DecryptBasicBlock(byte[] dst, int to, byte[] src, int from)

EncryptBasicBlock and DecryptBasicBlock must allow inplace processing, that is, they must correctly work in the situation when src/from and dst/to point to the same or overlapping memory area.

Now the cipher class is completed and the last step is to add it to com.kryptel.cipher.ComponentLoader class. Add this code

if (cid.equals(CID_MY_COOL_CIPHER)) return new MyCoolCipher(capabilities);

to the CreateComponent function and the following line

if ((MyCoolCipher.componentType & mask) != 0) uidList.add(MyCoolCipher.componentID);

to the GetComponentList function.

That's all! Your new cipher is ready to be used.