mirror of
https://github.com/transmission/transmission
synced 2025-01-01 12:35:22 +00:00
Extend SSHA1 test to check for predefined matches
Reduce number of test iterations to 4K along the way to shorten execution time.
This commit is contained in:
parent
35fea28d1a
commit
15625de3c7
1 changed files with 19 additions and 7 deletions
|
@ -116,22 +116,30 @@ test_sha1 (void)
|
|||
static int
|
||||
test_ssha1 (void)
|
||||
{
|
||||
const char * const test_data[] =
|
||||
{
|
||||
"test",
|
||||
"QNY)(*#$B)!_X$B !_B#($^!)*&$%CV!#)&$C!@$(P*)"
|
||||
};
|
||||
struct
|
||||
{
|
||||
const char * const plain_text;
|
||||
const char * const ssha1;
|
||||
}
|
||||
test_data[] =
|
||||
{
|
||||
{ "test", "{15ad0621b259a84d24dcd4e75b09004e98a3627bAMbyRHJy" },
|
||||
{ "QNY)(*#$B)!_X$B !_B#($^!)*&$%CV!#)&$C!@$(P*)", "{10e2d7acbb104d970514a147cd16d51dfa40fb3c0OSwJtOL" }
|
||||
};
|
||||
|
||||
size_t i;
|
||||
|
||||
#define HASH_COUNT (16 * 1024)
|
||||
#define HASH_COUNT (4 * 1024)
|
||||
|
||||
for (i = 0; i < sizeof (test_data) / sizeof (*test_data); ++i)
|
||||
{
|
||||
char * const phrase = tr_strdup (test_data[i]);
|
||||
char * const phrase = tr_strdup (test_data[i].plain_text);
|
||||
char ** hashes = tr_new (char *, HASH_COUNT);
|
||||
size_t j;
|
||||
|
||||
check (tr_ssha1_matches (test_data[i].ssha1, phrase));
|
||||
check (tr_ssha1_matches_ (test_data[i].ssha1, phrase));
|
||||
|
||||
for (j = 0; j < HASH_COUNT; ++j)
|
||||
{
|
||||
hashes[j] = j % 2 == 0 ? tr_ssha1 (phrase) : tr_ssha1_ (phrase);
|
||||
|
@ -173,6 +181,10 @@ test_ssha1 (void)
|
|||
|
||||
#undef HASH_COUNT
|
||||
|
||||
/* should work with different salt lengths as well */
|
||||
check (tr_ssha1_matches ("{a94a8fe5ccb19ba61c4c0873d391e987982fbbd3", "test"));
|
||||
check (tr_ssha1_matches ("{d209a21d3bc4f8fc4f8faf347e69f3def597eb170pySy4ai1ZPMjeU1", "test"));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue