gmp: Use helper to determine XOF type
authorTobias Brunner <tobias@strongswan.org>
Mon, 25 Sep 2017 16:07:58 +0000 (18:07 +0200)
committerTobias Brunner <tobias@strongswan.org>
Wed, 8 Nov 2017 15:48:10 +0000 (16:48 +0100)
src/libstrongswan/plugins/gmp/gmp_rsa_private_key.c
src/libstrongswan/plugins/gmp/gmp_rsa_public_key.c

index 3a92965..e24fda8 100644 (file)
@@ -354,21 +354,12 @@ static bool build_emsa_pss_signature(private_gmp_rsa_private_key_t *this,
        {
                return FALSE;
        }
-       switch (params->mgf1_hash)
+       xof = xof_mgf1_from_hash_algorithm(params->mgf1_hash);
+       if (xof == XOF_UNDEFINED)
        {
-               case HASH_SHA1:
-                       xof = XOF_MGF1_SHA1;
-                       break;
-               case HASH_SHA256:
-                       xof = XOF_MGF1_SHA256;
-                       break;
-               case HASH_SHA512:
-                       xof = XOF_MGF1_SHA512;
-                       break;
-               default:
-                       DBG1(DBG_LIB, "%N is not supported for MGF1", hash_algorithm_names,
-                                params->mgf1_hash);
-                       return FALSE;
+               DBG1(DBG_LIB, "%N is not supported for MGF1", hash_algorithm_names,
+                        params->mgf1_hash);
+               return FALSE;
        }
        /* emBits = modBits - 1 */
        embits = mpz_sizeinbase(this->n, 2) - 1;
index 45fdf1d..52bc9fb 100644 (file)
@@ -304,21 +304,12 @@ static bool verify_emsa_pss_signature(private_gmp_rsa_public_key_t *this,
        {
                return FALSE;
        }
-       switch (params->mgf1_hash)
+       xof = xof_mgf1_from_hash_algorithm(params->mgf1_hash);
+       if (xof == XOF_UNDEFINED)
        {
-               case HASH_SHA1:
-                       xof = XOF_MGF1_SHA1;
-                       break;
-               case HASH_SHA256:
-                       xof = XOF_MGF1_SHA256;
-                       break;
-               case HASH_SHA512:
-                       xof = XOF_MGF1_SHA512;
-                       break;
-               default:
-                       DBG1(DBG_LIB, "%N is not supported for MGF1", hash_algorithm_names,
-                                params->mgf1_hash);
-                       return FALSE;
+               DBG1(DBG_LIB, "%N is not supported for MGF1", hash_algorithm_names,
+                        params->mgf1_hash);
+               return FALSE;
        }
        chunk_skip_zero(signature);
        if (signature.len == 0 || signature.len > this->k)