From 15625de3c7a3d6959120b7e6b259d26fa7087957 Mon Sep 17 00:00:00 2001 From: Mike Gelfand Date: Mon, 9 Jan 2017 14:12:17 +0300 Subject: [PATCH] Extend SSHA1 test to check for predefined matches Reduce number of test iterations to 4K along the way to shorten execution time. --- libtransmission/crypto-test.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/libtransmission/crypto-test.c b/libtransmission/crypto-test.c index 62912ce8d..f4252f2c2 100644 --- a/libtransmission/crypto-test.c +++ b/libtransmission/crypto-test.c @@ -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; } -- 2.40.0