yet another hash algorithm
- From: Rade <rade.vuckovac@xxxxxxxxx>
- Date: Wed, 23 May 2012 14:40:58 -0700 (PDT)
Hi all
There is a new attempt for hash algorithm . Initial idea is discussed
here
http://groups.google.com/group/sci.crypt/browse_thread/thread/118b5fdf66144d64/6bf70c66565222a7?hl=en&lnk=gst&q=rule+30+hash#6bf70c66565222a7
First unsuccessful try is here
http://groups.google.com/group/sci.crypt/browse_thread/thread/508a58bb1559a9cb/ad661fd1d51d53ac?hl=en&lnk=gst&q=rule+30+hash#ad661fd1d51d53ac
Interface is the same as for SHA 3 competition. The algorithm may not
be more secure than first attempt, but it has some interesting
features.
//vez.h
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
typedef enum { SUCCESS = 0, FAIL = 1, BAD_HASHBITLEN = 2 }
HashReturn;
typedef unsigned char BitSequence;
typedef unsigned long long DataLength; // a typical 64-bit value
typedef struct
{
uint8_t rounds_no;
uint16_t hashbytelen;
uint64_t pos;
uint16_t size;
uint64_t mixer;
uint64_t carry;
uint64_t state[512];
uint64_t current[512];
} hashState;
HashReturn Init (hashState *state, int hashbitlen);
HashReturn Update (hashState *state, const BitSequence *data,
DataLength databitlen);
HashReturn Final (hashState *state, BitSequence *hashval);
HashReturn Hash (int hashbitlen, const BitSequence *data, DataLength
databitlen, BitSequence *hashval);
int evolve(hashState *state);
HashReturn Init(hashState *state, int hashbitlen)
{
int i;
state->hashbytelen = hashbitlen / 8;
if((hashbitlen % 8) != 0)
state->hashbytelen++;
state->rounds_no = 3;
state->mixer = 6148914691236517205;
state->carry = 1234567890123456789;
state->pos = 0;
state->size = 512;
for(i = 0; i < state->size; i++)
{
state->state[i] = 0;
state->current[i] =0;
}
return SUCCESS;
}
HashReturn Update (hashState *state, const BitSequence *data,
DataLength databitlen)
{
uint64_t i, start, databytelen, datablock;
state->carry += databitlen;
databytelen = databitlen / 8;
if((databitlen % 8) > 0 || databitlen == 0)
databytelen++;
datablock = databitlen / 64;
if((databitlen % 64) > 0 || databitlen == 0)
datablock++;
uint64_t padded[datablock];
for(i = 0; i < datablock; i++)
padded[i] = 0;
memcpy(padded, data, databytelen);
start = state->pos;
for(i = 0; i < datablock; i++)
{
state->current[(start+i) % state->size] = padded[i];
state->pos++;
if(state->pos == state->size)
evolve(state);
}
return SUCCESS;
}
HashReturn Final(hashState *state, BitSequence *hashval)
{
int i;
if(state->pos > 0)
evolve(state);
for(i = 0; i < (2 * state->size); i++)
{
if(state->state[(i + 1) % state->size] > state->state[(i + 3) %
state->size])
state->state[i % state->size] ^= state->state[(i + 1) % state-
size];else
state->state[i % state->size] ^= ~state->state[(i + 1) % state-
size];
if(state->state[(i + 2) % state->size] > state->state[(i + 3) %
state->size])
state->state[i % state->size] ^= state->state[(i + 2) % state-
size];else
state->state[i % state->size] ^= ~state->state[(i + 2) % state-
size];
if(state->state[(i + 3) % state->size] % 2 == 1)
state->state[i % state->size] ^= state->state[(i + 3) % state-
size];else
state->state[i % state->size] ^= ~state->state[(i + 3) % state-
size];}
memcpy(hashval, state->state, state->hashbytelen);
return SUCCESS;
}
HashReturn Hash(int hashbitlen, const BitSequence *data,
DataLength databitlen, BitSequence *hashval)
{
hashState state;
Init(&state, hashbitlen);
Update(&state, data, databitlen);
Final(&state, hashval);
return SUCCESS;
}
int evolve(hashState *state)
{
int j, k;
//operation key
for(j = 0; j < state->size; j++)
state->state[j] ^= state->current[j];
for(j = 0; j < state->rounds_no; j++)
{
for(k = 0; k < state->size; k++)
{
if(state->state[(k+2)%state->size]>state->state[(k+3)%state->size])
state->carry ^= state->state[(k+1)%state->size];
else
state->carry ^= ~state->state[(k+1)%state->size];
state->state[k] ^= state->carry;
state->carry += state->mixer;
}
}
//operation evolve
for(j = 0; j < state->size; j++)
state->state[j] ^= state->current[j];
for(j = 0; j < state->rounds_no; j++)
{
for(k = 0; k < state->size; k++)
{
if(state->state[(k+2)%state->size]>state->state[(k+3)%state->size])
state->carry ^= state->state[(k+1)%state->size];
else
state->carry ^= ~state->state[(k+1)%state->size];
state->state[k] ^= state->carry;
}
}
state->pos = 0;
for(j =0; j < state->size; j++)
state->current[j] = 0;
return 0;
}
.
- Follow-Ups:
- Re: yet another hash algorithm
- From: orz
- Re: yet another hash algorithm
- Prev by Date: 4130 Solution manuals & Test banks to Industrial Engineering, Business, Accounting, Economics and Finance Books
- Next by Date: Re: yet another hash algorithm
- Previous by thread: 4130 Solution manuals & Test banks to Industrial Engineering, Business, Accounting, Economics and Finance Books
- Next by thread: Re: yet another hash algorithm
- Index(es):