tests/unit: always build the pbkdf crypto unit test

The meson rules were excluding the pbkdf crypto test when gnutls was the
crypto backend. It was then excluded again in #if statements in the test
file.

Rather than update these conditions, remove them all, and use the result
of the qcrypto_pbkdf_supports() function to determine whether to skip
test registration.

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
Daniel P. Berrangé 2024-08-29 14:50:33 +01:00
parent e6c09ea4f9
commit b0fe44b56b
2 changed files with 9 additions and 8 deletions

View File

@ -121,9 +121,7 @@ if have_block
if config_host_data.get('CONFIG_REPLICATION')
tests += {'test-replication': [testblock]}
endif
if nettle.found() or gcrypt.found()
tests += {'test-crypto-pbkdf': [io]}
endif
tests += {'test-crypto-pbkdf': [io]}
endif
if have_system

View File

@ -25,8 +25,7 @@
#include <sys/resource.h>
#endif
#if ((defined(CONFIG_NETTLE) || defined(CONFIG_GCRYPT)) && \
(defined(_WIN32) || defined(RUSAGE_THREAD)))
#if defined(_WIN32) || defined(RUSAGE_THREAD)
#include "crypto/pbkdf.h"
typedef struct QCryptoPbkdfTestData QCryptoPbkdfTestData;
@ -394,7 +393,7 @@ static void test_pbkdf(const void *opaque)
}
static void test_pbkdf_timing(void)
static void test_pbkdf_timing_sha256(void)
{
uint8_t key[32];
uint8_t salt[32];
@ -422,14 +421,18 @@ int main(int argc, char **argv)
g_assert(qcrypto_init(NULL) == 0);
for (i = 0; i < G_N_ELEMENTS(test_data); i++) {
if (!qcrypto_pbkdf2_supports(test_data[i].hash)) {
continue;
}
if (!test_data[i].slow ||
g_test_slow()) {
g_test_add_data_func(test_data[i].path, &test_data[i], test_pbkdf);
}
}
if (g_test_slow()) {
g_test_add_func("/crypt0/pbkdf/timing", test_pbkdf_timing);
if (g_test_slow() && qcrypto_pbkdf2_supports(QCRYPTO_HASH_ALG_SHA256)) {
g_test_add_func("/crypt0/pbkdf/timing/sha256", test_pbkdf_timing_sha256);
}
return g_test_run();