]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
self-tests: all parameter was replaced by flags
authorNikos Mavrogiannopoulos <nmav@redhat.com>
Mon, 22 May 2017 14:39:14 +0000 (16:39 +0200)
committerNikos Mavrogiannopoulos <nmav@gnutls.org>
Mon, 22 May 2017 21:25:51 +0000 (23:25 +0200)
This allows to introduce more options than just check all
ciphers.

Signed-off-by: Nikos Mavrogiannopoulos <nmav@redhat.com>
lib/crypto-selftests-pk.c
lib/crypto-selftests.c
lib/includes/gnutls/self-test.h

index 84a9963cea9705200b96b2ac12153ad340767df6..9a7f3505bf35e7fb7eeb069df34f4e13b4d39761 100644 (file)
@@ -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
 
index b9d14a5538fb396f5271d8820a13e2ed64c7313f..255654b0a52c7ac53450fd48609674d14939a486 100644 (file)
@@ -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) {
index c3fd84cd068c59934ed18856a1d513486e110b33..e87d99eab1f9110b96067a966997db17792aa550 100644 (file)
 
  /* 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