diff options
author | NIIBE Yutaka <gniibe@fsij.org> | 2021-12-09 09:47:47 +0900 |
---|---|---|
committer | NIIBE Yutaka <gniibe@fsij.org> | 2021-12-09 09:47:47 +0900 |
commit | 7d8403b59a105d2d3e5d0fd9d5d25b7e3b2d2787 (patch) | |
tree | dc75473b4721e8588bf8fac1b23f24d7558c2ba5 /tests | |
parent | 5b82f4b4dbf393d0ce901fc9e0c559c488b013cb (diff) | |
download | libgcrypt-7d8403b59a105d2d3e5d0fd9d5d25b7e3b2d2787.tar.gz |
tests,fips: Align the use of variable in_fips_mode.
* tests/pubkey.c (check_run): Fix use of pkey and skey.
* tests/*.c (in_fips_mode): No initialize by 0.
--
There are no cases where *_key_new allocates pkey and skey when
IN_FIPS_MODE!=0. Nevertheless, from viewpoint of resource management,
calling gcry_sexp_release always is easier for maintenance.
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/bench-slope.c | 2 | ||||
-rw-r--r-- | tests/curves.c | 2 | ||||
-rw-r--r-- | tests/dsa-rfc6979.c | 2 | ||||
-rw-r--r-- | tests/fips186-dsa.c | 2 | ||||
-rw-r--r-- | tests/pubkey.c | 53 | ||||
-rw-r--r-- | tests/t-cv25519.c | 2 | ||||
-rw-r--r-- | tests/t-dsa.c | 2 | ||||
-rw-r--r-- | tests/t-ecdsa.c | 2 | ||||
-rw-r--r-- | tests/t-ed25519.c | 2 | ||||
-rw-r--r-- | tests/t-ed448.c | 2 | ||||
-rw-r--r-- | tests/t-rsa-15.c | 2 | ||||
-rw-r--r-- | tests/t-rsa-pss.c | 2 | ||||
-rw-r--r-- | tests/t-secmem.c | 2 | ||||
-rw-r--r-- | tests/t-x448.c | 2 |
14 files changed, 46 insertions, 33 deletions
diff --git a/tests/bench-slope.c b/tests/bench-slope.c index 7a17cf10..4ff7140d 100644 --- a/tests/bench-slope.c +++ b/tests/bench-slope.c @@ -75,7 +75,7 @@ static double bench_ghz; /* Current accuracy of auto-detected CPU Ghz. */ static double bench_ghz_diff; -static int in_fips_mode = 0; +static int in_fips_mode; /*************************************** Default parameters for measurements. */ diff --git a/tests/curves.c b/tests/curves.c index 2dd067a0..3c738171 100644 --- a/tests/curves.c +++ b/tests/curves.c @@ -69,7 +69,7 @@ static char const sample_key_2[] = static char const sample_key_2_curve[] = "brainpoolP160r1"; static unsigned int sample_key_2_nbits = 160; -static int in_fips_mode = 0; +static int in_fips_mode; static void list_curves (void) diff --git a/tests/dsa-rfc6979.c b/tests/dsa-rfc6979.c index b647efa2..cd68cd25 100644 --- a/tests/dsa-rfc6979.c +++ b/tests/dsa-rfc6979.c @@ -33,7 +33,7 @@ #define PGM "dsa-rfc6979" #include "t-common.h" -static int in_fips_mode = 0; +static int in_fips_mode; static void show_sexp (const char *prefix, gcry_sexp_t a) diff --git a/tests/fips186-dsa.c b/tests/fips186-dsa.c index 22a88892..3f7c0d1b 100644 --- a/tests/fips186-dsa.c +++ b/tests/fips186-dsa.c @@ -34,7 +34,7 @@ #define PGM "fips186-dsa" #include "t-common.h" -static int in_fips_mode = 0; +static int in_fips_mode; static void show_sexp (const char *prefix, gcry_sexp_t a) diff --git a/tests/pubkey.c b/tests/pubkey.c index 751f508c..c5510d05 100644 --- a/tests/pubkey.c +++ b/tests/pubkey.c @@ -728,6 +728,7 @@ check_run (void) gcry_sexp_t pkey, skey; int variant; + pkey = skey = NULL; for (variant=0; variant < 3; variant++) { if (verbose) @@ -742,6 +743,7 @@ check_run (void) check_keys (pkey, skey, 800, variant == 2? GPG_ERR_NO_OBJ : 0); gcry_sexp_release (pkey); gcry_sexp_release (skey); + pkey = skey = NULL; } if (verbose) @@ -750,6 +752,7 @@ check_run (void) check_keys (pkey, skey, 800, 0); gcry_sexp_release (pkey); gcry_sexp_release (skey); + pkey = skey = NULL; if (verbose) fprintf (stderr, "Checking generated RSA key (X9.31).\n"); @@ -757,26 +760,25 @@ check_run (void) check_keys (pkey, skey, 800, 0); gcry_sexp_release (pkey); gcry_sexp_release (skey); + pkey = skey = NULL; if (verbose) fprintf (stderr, "Checking generated Elgamal key.\n"); get_elg_key_new (&pkey, &skey, 0); if (!in_fips_mode) - { - check_keys (pkey, skey, 400, 0); - gcry_sexp_release (pkey); - gcry_sexp_release (skey); - } + check_keys (pkey, skey, 400, 0); + gcry_sexp_release (pkey); + gcry_sexp_release (skey); + pkey = skey = NULL; if (verbose) fprintf (stderr, "Checking passphrase generated Elgamal key.\n"); get_elg_key_new (&pkey, &skey, 1); if (!in_fips_mode) - { - check_keys (pkey, skey, 800, 0); - gcry_sexp_release (pkey); - gcry_sexp_release (skey); - } + check_keys (pkey, skey, 800, 0); + gcry_sexp_release (pkey); + gcry_sexp_release (skey); + pkey = skey = NULL; if (verbose) fprintf (stderr, "Generating DSA key.\n"); @@ -784,19 +786,24 @@ check_run (void) if (!in_fips_mode) { /* Fixme: Add a check function for DSA keys. */ - gcry_sexp_release (pkey); - gcry_sexp_release (skey); + ; } + gcry_sexp_release (pkey); + gcry_sexp_release (skey); + pkey = skey = NULL; + if (verbose) fprintf (stderr, "Generating transient DSA key.\n"); get_dsa_key_new (&pkey, &skey, 1); if (!in_fips_mode) { /* Fixme: Add a check function for DSA keys. */ - gcry_sexp_release (pkey); - gcry_sexp_release (skey); + ; } + gcry_sexp_release (pkey); + gcry_sexp_release (skey); + pkey = skey = NULL; if (verbose) fprintf (stderr, "Generating DSA key (FIPS 186).\n"); @@ -804,9 +811,11 @@ check_run (void) if (!in_fips_mode) { /* Fixme: Add a check function for DSA keys. */ - gcry_sexp_release (pkey); - gcry_sexp_release (skey); + ; } + gcry_sexp_release (pkey); + gcry_sexp_release (skey); + pkey = skey = NULL; if (verbose) fprintf (stderr, "Generating DSA key with given domain.\n"); @@ -814,9 +823,11 @@ check_run (void) if (!in_fips_mode) { /* Fixme: Add a check function for DSA keys. */ - gcry_sexp_release (pkey); - gcry_sexp_release (skey); + ; } + gcry_sexp_release (pkey); + gcry_sexp_release (skey); + pkey = skey = NULL; /* We need new test vectors for get_dsa_key_fips186_with_domain_new. */ if (verbose) @@ -833,9 +844,11 @@ check_run (void) if (!in_fips_mode) { /* Fixme: Add a check function for DSA keys. */ - gcry_sexp_release (pkey); - gcry_sexp_release (skey); + ; } + gcry_sexp_release (pkey); + gcry_sexp_release (skey); + pkey = skey = NULL; } diff --git a/tests/t-cv25519.c b/tests/t-cv25519.c index b4126f4c..ec1472a9 100644 --- a/tests/t-cv25519.c +++ b/tests/t-cv25519.c @@ -33,7 +33,7 @@ #include "t-common.h" #define N_TESTS 18 -static int in_fips_mode = 0; +static int in_fips_mode; static void print_mpi (const char *text, gcry_mpi_t a) diff --git a/tests/t-dsa.c b/tests/t-dsa.c index e82db62d..965b7cf2 100644 --- a/tests/t-dsa.c +++ b/tests/t-dsa.c @@ -35,7 +35,7 @@ static int no_verify; static int custom_data_file; -static int in_fips_mode = 0; +static int in_fips_mode; static void diff --git a/tests/t-ecdsa.c b/tests/t-ecdsa.c index ddc49df0..9a0773b7 100644 --- a/tests/t-ecdsa.c +++ b/tests/t-ecdsa.c @@ -35,7 +35,7 @@ static int no_verify; static int custom_data_file; -static int in_fips_mode = 0; +static int in_fips_mode; static void diff --git a/tests/t-ed25519.c b/tests/t-ed25519.c index 567bc797..160bf980 100644 --- a/tests/t-ed25519.c +++ b/tests/t-ed25519.c @@ -36,7 +36,7 @@ static int sign_with_pk; static int no_verify; static int custom_data_file; -static int in_fips_mode = 0; +static int in_fips_mode; static void diff --git a/tests/t-ed448.c b/tests/t-ed448.c index f38cd10c..3e3dd34a 100644 --- a/tests/t-ed448.c +++ b/tests/t-ed448.c @@ -36,7 +36,7 @@ static int sign_with_pk; static int no_verify; static int custom_data_file; -static int in_fips_mode = 0; +static int in_fips_mode; static void diff --git a/tests/t-rsa-15.c b/tests/t-rsa-15.c index 99315509..63495e9e 100644 --- a/tests/t-rsa-15.c +++ b/tests/t-rsa-15.c @@ -35,7 +35,7 @@ static int no_verify; static int custom_data_file; -static int in_fips_mode = 0; +static int in_fips_mode; static void diff --git a/tests/t-rsa-pss.c b/tests/t-rsa-pss.c index f167a79d..521d5734 100644 --- a/tests/t-rsa-pss.c +++ b/tests/t-rsa-pss.c @@ -35,7 +35,7 @@ static int no_verify; static int custom_data_file; -static int in_fips_mode = 0; +static int in_fips_mode; static void diff --git a/tests/t-secmem.c b/tests/t-secmem.c index e735628f..a6557dce 100644 --- a/tests/t-secmem.c +++ b/tests/t-secmem.c @@ -37,7 +37,7 @@ #define MINIMUM_POOL_SIZE 16384 static size_t pool_size; static size_t chunk_size; -static int in_fips_mode = 0; +static int in_fips_mode; static void test_secmem (void) diff --git a/tests/t-x448.c b/tests/t-x448.c index cc4b10fc..f5f49e5e 100644 --- a/tests/t-x448.c +++ b/tests/t-x448.c @@ -34,7 +34,7 @@ #include "t-common.h" #define N_TESTS 9 -static int in_fips_mode = 0; +static int in_fips_mode; static void print_mpi (const char *text, gcry_mpi_t a) |