How to Add a New Hash Function

Adding a New Hash Function

Class com.kryptel.hash_function.HashBase lets you easily add a new hash function 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_HASH_FUNCTION =

Now declare your hash function class by extending the com.kryptel.hash_function.HashBase class.

final class MyHashFunction extends HashBase {

Declare a static constant componentID containing the CID of your hash function:

static final UUID componentID = CID_MY_HASH_FUNCTION;

Declare a class constructor to initialize the HashFunctionInfo structure describing your hash function, and default hash function parameters:

MyHashFunction(long capabilities) {

  DEFAULT_HASH_SIZE = 32;  // 256 bits

  hashFunctionInfo = new HashFunctionInfo(
    new int[] { 16, 20, 32 },			// Hash sizes
    new int[] { DEFAULT_PASSES },		// Passes
    new String[] { "Standard" }

  hashPasses = DEFAULT_PASSES;
  hashScheme = DEFAULT_SCHEME;

  // Other construction code

Implement IKryptelComponent methods, which HashBase does not implement.

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

The next step is adding the actual hash function implementation, i.e. overriding three abstract functions InitImpl, HashImpl, and DoneImpl:

protected void InitImpl()

protected void HashImpl(byte[] buffer, int start, int size)

protected byte[] DoneImpl()

If the hash function supports several hash sizes, passes, or schemes, the implementation functions should examine the variables hashSize, hashPasses, and hashScheme to get the currently set values. Keep in mind that schemes are numbered starting from 1.

The last step is adding a reference to the new hash function to com.kryptel.hash_function.ComponentLoader class. Add this code

if (cid.equals(CID_MY_HASH_FUNCTION)) return new MyHashFunction(capabilities);

to the CreateComponent function and the following line

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

to the GetComponentList function.

Your new hash function component is now ready.