Closed magnumripper closed 9 years ago
A canonical salt_hash() could be as follows
static int salt_hash(void *salt)
{
unsigned char *s = salt;
unsigned int hash = 5381;
unsigned int len = SALT_SIZE;
while (len--)
hash = ((hash << 5) + hash) ^ *s++;
return hash & (SALT_HASH_SIZE - 1);
}
However, this is only reliable for fixed-size salts (ie. where we are sure all of SALT_SIZE is really initialized in salt()
). Otherwise we need to use something like salt->len instead of SALT_SIZE. Alternatively, there needs to be a memset() in salt() that guarantees nothing in uninitialized.
Now, we could change fmt_default_salt_hash() to be like above. That is kinda dangerous but our recently added self-test for salt cleaning should ensure proper function...
...oh, and it can't really be like above, because the SALT_SIZE macro won't be available in formats.c.
Now, we could change fmt_default_salt_hash() to be like above.
:+1:
I really don't want to write such boilerplate code in every format (well, the real reason is that I am a bit lazy).
One option is to add a file salt_hash.c that contains the function as above. Any format that wants to use it (and that fits the requirement that if SALT_SIZE has a margin for variable length, the full size HAS to be 'cleaned' for each call to get_salt()) could just #include "salt_hash.c"
and then say salt_hash
in the format struct definition.
I'd prefer to put those functions into a .h file.
#ifndef JTR_SALT_HASH_H
#define JTR_SALT_HASH_H
...
There are already some other .h files which include function implementations.
BTW: There are other possible "helper functions" which could be reused this way: -functions verifying that certain ciphertexts elements contain hex values of a given length (range)) -functions for base64 verification
Calling it .h is fine with me. But those ifdefs (that are normally crucial for headers) will not do any good in this case, they would just hide bugs.
Changing this from bug->enhancement because it really does not affect anything but loader performance. If that.
I see no important format among the current list. And this is only about loading a LOT of salts/hashes. Closing.
These files use SALT_SIZE
definition from a header; anyway, they are doing the same as the CPU versions do.
opencl_rawsha256_fmt_plug.c
opencl_rawsha512_gpl_fmt_plug.c
I hope I'm doing this wrong because this is a LOT of formats :cry:
OTOH many of the below are "salt-only" non-hashes so doesn't benefit that much of a hash function.