```Date: Fri, 8 May 2015 14:58:31 +0300
From: Aleksey Cherepanov <lyosha@...nwall.com>
To: john-dev@...ts.openwall.com
Subject: Re: get_binary_*() and get_hash_*() methods

On Tue, May 05, 2015 at 10:40:24PM +0200, magnum wrote:
> On 2015-05-05 21:53, Aleksey Cherepanov wrote:
> >Does binary_hash_6() and get_hash_6() functions have to return the
> >same values for the same hashes?
>
> Yes that's the whole point of these functions, and the self-tests tries to
> verify this.

In dummy.c:

static int get_hash_0(int index)
{
ARCH_WORD_32 hash = string_hash(saved_key[index]);
hash ^= hash >> 8;
return (hash ^ (hash >> 4)) & 0xf;
}
[...]
static int get_hash_4(int index)
{
return string_hash(saved_key[index]) & 0xfffff;
}

So I think it is ok to have different algorithms in get_hash*() methods.

As Solar Designer told, get_hash*() methods are slow for bitslice.

DES_bs.c:

int DES_bs_get_hash_0(int index)
{
return DES_bs_get_hash(index, 4, 0);
}
int DES_bs_get_hash_1(int index)
{
return DES_bs_get_hash(index, 8, 0);
}

static MAYBE_INLINE int DES_bs_get_hash(int index, int count, int trip)
[...]
result = GET_BIT(0);
result |= MOVE_BIT(1);
result |= MOVE_BIT(2);
result |= MOVE_BIT(3);
if (count == 4) return result;

result |= MOVE_BIT(4);
result |= MOVE_BIT(5);
result |= MOVE_BIT(6);
b += trip; /* for tripcodes, skip bit 7 */
result |= MOVE_BIT(7);
if (count == 8) return result;

DES_bs_get_hash() collects 'count' bits starting from 0. Though we may
just return bits 0-3 from get_hash_1(), bits 4-7 from get_hash_2()
(i.e. without bits 0-3) and so on not collecting the whole chain of 27
bits (or like that, most probably starting with fewer operators). Or
is it required to return a hash with ~31 bits of information about the
hash from get_hash_6? Or the question may sound differently: are
get_hash[]() methods called sequentially for each binary like the
following algo?

for each index
if not table_0[get_hash[0](index)]
next index
end if
if not table_1[get_hash[1](index)]
next index
end if
...
if not table_6[get_hash[6](index)]
next index
end if
... most probably hash is matching ...
end for

Thanks!

--
Regards,
Aleksey Cherepanov
```

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.