hash

=programming =cryptography =algorithms

 

 

This is a cryptographic hash algorithm I designed for 64-bit x86 CPUs.

The following is C-style pseudocode, using 512-byte blocks.

int length = 64;
uint64_t[length] input;
uint64_t[length] old_input;
uint64_t[length] temp_array;
uint8_t[length] keys;

uint64_t[] sbox(uint64_t[] input)
    {
    int i = 0;
    for (int n=0; n<length; n=n+4)
        {
        temp_array[i] = input[n] ^ input[n + 1];
        i++;
        temp_array[i] = input[n + 2];
        i++;
        }
    for (int n=0; n<length; n=n+4)
        {
        temp_array[i] = input[n] ^ input[n + 2];
        i++;
        }
    for (int n=0; n<length; n=n+4)
        {
        temp_array[i] = input[n + 1] ^ input[n + 3];
        i++;
        }
    tmp = temp_array;
    temp_array = input;
    input = tmp;
    }

uint64_t[] sbox_set(uint64_t[] input)
    {
    for (int i=0; i<6; i++)
        {sbox(input);}
    for (int i=0; i<length; i++)
        {
        input[i] = rotate_right(input[i], i)
        }
    for (int i=0; i<6; i++)
        {sbox(input);}
    }

uint64_t[] pbox(uint64_t[] input, uint64_t[] modifier)
    {
    for (int i=0; i<length; i++)
        {
        uint64_t mod_element = modifier[i];
        input[i] = rotate_right(input[i], mod_element & 63);
        keys[i] = mod_element >> 6;
        }
   
    for (int count=0; count<3; count++)
        {
        int start_index = 0;
        int end_index = length-1;
       
        for (int i=0; i<length; i++)
            {
            uint8_t key = keys[i] & 3;
            uint64_t element = input[i];
            if (key == 0)
                {
                temp_array[start_index] = element;
                start_index++;
                }
            if (key == 3)
                {
                temp_array[end_index] = element;
                end_index--;
                }
            }
        for (int i=0; i<length; i++)
            {
            uint8_t key = keys[i];
            keys[i] = key >> 2;
            key = key & 3;
            uint64_t element = input[i];
            if (key == 1)
                {
                temp_array[start_index] = element;
                start_index++;
                }
            if (key == 2)
                {
                temp_array[end_index] = element;
                end_index--;
                }
            }
        tmp = temp_array;
        temp_array = input;
        input = tmp;
        }
    }

int rounds = 6;
// I would suggest using at least 4 rounds for cryptography.

while (input_remains)
    {
    input = input ^ (some data to be hashed);
   
    sbox_set(input);
    for (int i=0; i<rounds; i++)
        {
        memcpy(input, old_input, sizeof(input));
        sbox_set(input);
        pbox(input, old_input);
        }
    }
sbox_set(input);



The output is however many bits you want from the start of "input".

 




back to index