Is crypt_r really 32 times slower than crypt?

I'm doing a descrypt bruteforcer proof-of-concept and have a single threaded version working well with 190k hashes with a single i-7 860 cpu core.

Now I am trying to make a multi-threaded version of this program (my first time playing with threads, so I hope I am doing something wrong).

I first tried using crypt directly, it was fast, but resulted in garbled hashes as the threads were challenging the crypt function.

Using the lock and unlock mutex function helped, but it reduced the speed of the program several percent faster than the single threaded version.

Then I was able to run google crypt_r, which was advertised as thread safe. Changed singlethreaded version to use crypt_r (with one thread) and multithreaded version to use it instead of crypt, and performance in single-threaded version dropped to about 3.6k h / s and 7.7k h / s in multithreaded version when using two cores using 99.9%.

So the question is, should it be slow?

+3


source to share


1 answer


The problem was that the function I was calling when executing the crypt_r function also contained code to initialize the required structure.

The solution was to take the initialization out of the function that gets called when hashing.

simplified example wrong way:



for (int i = 0; i < 200000; i++)
{
    struct crypt_data data;
    data.initialized = 0;

    char* hash = crypt_r("password", "sa", &data);
    printf("%i %s", i, hash);
}

      

the right way:

struct crypt_data data;
data.initialized = 0;

for (int i = 0; i < 200000; i++)
{
    char* hash = crypt_r("password", "sa", &data);
    printf("%i %s", i, hash);
}

      

0


source







All Articles