From f036d7e93887b4885072cdb2e7dfd2de499ccb3c Mon Sep 17 00:00:00 2001 From: Nikos Mavrogiannopoulos Date: Mon, 22 May 2017 16:39:14 +0200 Subject: self-tests: all parameter was replaced by flags This allows to introduce more options than just check all ciphers. Signed-off-by: Nikos Mavrogiannopoulos --- lib/crypto-selftests-pk.c | 14 +++++++------- lib/crypto-selftests.c | 26 +++++++++++++------------- lib/includes/gnutls/self-test.h | 10 ++++++---- 3 files changed, 26 insertions(+), 24 deletions(-) (limited to 'lib') diff --git a/lib/crypto-selftests-pk.c b/lib/crypto-selftests-pk.c index 84a9963cea..9a7f3505bf 100644 --- a/lib/crypto-selftests-pk.c +++ b/lib/crypto-selftests-pk.c @@ -475,7 +475,7 @@ static int test_known_sig(gnutls_pk_algorithm_t pk, unsigned bits, gnutls_assert(); \ goto cleanup; \ } \ - if (all == 0) \ + if (!(flags & GNUTLS_SELF_TEST_FLAG_ALL)) \ return 0 #define PK_KNOWN_TEST(pk, det, bits, dig, pkey, sig) \ @@ -484,7 +484,7 @@ static int test_known_sig(gnutls_pk_algorithm_t pk, unsigned bits, gnutls_assert(); \ goto cleanup; \ } \ - if (all == 0) \ + if (!(flags & GNUTLS_SELF_TEST_FLAG_ALL)) \ return 0 @@ -683,7 +683,7 @@ cleanup: /*- * gnutls_pk_self_test: - * @all: if non-zero then tests to all public key algorithms are performed. + * @flags: GNUTLS_SELF_TEST_FLAG flags * @pk: the algorithm to use * * This function will run self tests on the provided public key algorithm. @@ -692,11 +692,11 @@ cleanup: * * Since: 3.3.0-FIPS140 -*/ -int gnutls_pk_self_test(unsigned all, gnutls_pk_algorithm_t pk) +int gnutls_pk_self_test(unsigned flags, gnutls_pk_algorithm_t pk) { int ret; - if (all != 0) + if (flags & GNUTLS_SELF_TEST_FLAG_ALL) pk = GNUTLS_PK_UNKNOWN; switch (pk) { @@ -710,7 +710,7 @@ int gnutls_pk_self_test(unsigned all, gnutls_pk_algorithm_t pk) goto cleanup; } - if (all == 0) + if (!(flags & GNUTLS_SELF_TEST_FLAG_ALL)) return 0; #endif case GNUTLS_PK_RSA: @@ -731,7 +731,7 @@ int gnutls_pk_self_test(unsigned all, gnutls_pk_algorithm_t pk) goto cleanup; } - if (all == 0) + if (!(flags & GNUTLS_SELF_TEST_FLAG_ALL)) return 0; #endif diff --git a/lib/crypto-selftests.c b/lib/crypto-selftests.c index b9d14a5538..255654b0a5 100644 --- a/lib/crypto-selftests.c +++ b/lib/crypto-selftests.c @@ -1089,40 +1089,40 @@ static int test_mac(gnutls_mac_algorithm_t mac, #define CASE(x, func, vectors) case x: \ ret = func(x, V(vectors)); \ - if (all == 0 || ret < 0) \ + if (!(flags & GNUTLS_SELF_TEST_FLAG_ALL) || ret < 0) \ return ret #define NON_FIPS_CASE(x, func, vectors) case x: \ if (_gnutls_fips_mode_enabled() == 0) { \ ret = func(x, V(vectors)); \ - if (all == 0 || ret < 0) \ + if (!(flags & GNUTLS_SELF_TEST_FLAG_ALL) || ret < 0) \ return ret; \ } #define FIPS_STARTUP_ONLY_TEST_CASE(x, func, vectors) case x: \ if (_gnutls_fips_mode_enabled() != 1) { \ ret = func(x, V(vectors)); \ - if (all == 0 || ret < 0) \ + if (!(flags & GNUTLS_SELF_TEST_FLAG_ALL) || ret < 0) \ return ret; \ } /*- * gnutls_cipher_self_test: - * @all: if non-zero then tests to all ciphers are performed. + * @flags: GNUTLS_SELF_TEST_FLAG flags * @cipher: the encryption algorithm to use * * This function will run self tests on the provided cipher or all - * available ciphers if @all is non-zero. + * available ciphers if @flags is %GNUTLS_SELF_TEST_FLAG_ALL. * * Returns: Zero or a negative error code on error. * * Since: 3.3.0-FIPS140 -*/ -int gnutls_cipher_self_test(unsigned all, gnutls_cipher_algorithm_t cipher) +int gnutls_cipher_self_test(unsigned flags, gnutls_cipher_algorithm_t cipher) { int ret; - if (all != 0) + if (flags & GNUTLS_SELF_TEST_FLAG_ALL) cipher = GNUTLS_CIPHER_UNKNOWN; switch (cipher) { @@ -1157,7 +1157,7 @@ int gnutls_cipher_self_test(unsigned all, gnutls_cipher_algorithm_t cipher) /*- * gnutls_mac_self_test: - * @all: if non-zero then tests to all ciphers are performed. + * @flags: GNUTLS_SELF_TEST_FLAG flags * @mac: the message authentication algorithm to use * * This function will run self tests on the provided mac. @@ -1166,11 +1166,11 @@ int gnutls_cipher_self_test(unsigned all, gnutls_cipher_algorithm_t cipher) * * Since: 3.3.0-FIPS140 -*/ -int gnutls_mac_self_test(unsigned all, gnutls_mac_algorithm_t mac) +int gnutls_mac_self_test(unsigned flags, gnutls_mac_algorithm_t mac) { int ret; - if (all != 0) + if (flags & GNUTLS_SELF_TEST_FLAG_ALL) mac = GNUTLS_MAC_UNKNOWN; switch (mac) { @@ -1192,7 +1192,7 @@ int gnutls_mac_self_test(unsigned all, gnutls_mac_algorithm_t mac) /*- * gnutls_digest_self_test: - * @all: if non-zero then tests to all ciphers are performed. + * @flags: GNUTLS_SELF_TEST_FLAG flags * @digest: the digest algorithm to use * * This function will run self tests on the provided digest. @@ -1201,11 +1201,11 @@ int gnutls_mac_self_test(unsigned all, gnutls_mac_algorithm_t mac) * * Since: 3.3.0-FIPS140 -*/ -int gnutls_digest_self_test(unsigned all, gnutls_digest_algorithm_t digest) +int gnutls_digest_self_test(unsigned flags, gnutls_digest_algorithm_t digest) { int ret; - if (all != 0) + if (flags & GNUTLS_SELF_TEST_FLAG_ALL) digest = GNUTLS_DIG_UNKNOWN; switch (digest) { diff --git a/lib/includes/gnutls/self-test.h b/lib/includes/gnutls/self-test.h index c3fd84cd06..e87d99eab1 100644 --- a/lib/includes/gnutls/self-test.h +++ b/lib/includes/gnutls/self-test.h @@ -27,9 +27,11 @@ /* Self checking functions */ -int gnutls_cipher_self_test(unsigned all, gnutls_cipher_algorithm_t cipher); -int gnutls_mac_self_test(unsigned all, gnutls_mac_algorithm_t mac); -int gnutls_digest_self_test(unsigned all, gnutls_digest_algorithm_t digest); -int gnutls_pk_self_test(unsigned all, gnutls_pk_algorithm_t pk); +#define GNUTLS_SELF_TEST_FLAG_ALL 1 + +int gnutls_cipher_self_test(unsigned flags, gnutls_cipher_algorithm_t cipher); +int gnutls_mac_self_test(unsigned flags, gnutls_mac_algorithm_t mac); +int gnutls_digest_self_test(unsigned flags, gnutls_digest_algorithm_t digest); +int gnutls_pk_self_test(unsigned flags, gnutls_pk_algorithm_t pk); #endif -- cgit v1.2.1