Blame SOURCES/libgcrypt-1.10.0-disable-brainpool.patch

331546
From d651e25be0bc0c11f4d3d7c72be8cfbbe82b3874 Mon Sep 17 00:00:00 2001
331546
From: Jakub Jelen <jjelen@redhat.com>
331546
Date: Fri, 10 Sep 2021 18:39:00 +0200
331546
Subject: [PATCH] Allow building libgcrypt without Brainpool curves
331546
331546
* README: Document possibility to build without brainpool curves
331546
* cipher/ecc-curves.c: Conditionalize brainpool curves definitions
331546
* configure.ac: Implement possibility to build without brainpool curves
331546
* tests/curves.c: Skip brainpool curves if they are not built-in
331546
* tests/keygrip.c: Skip brainpool curves if they are not built-in
331546
331546
--
331546
331546
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
331546
---
331546
 README              |  3 +++
331546
 cipher/ecc-curves.c |  4 ++++
331546
 configure.ac        | 13 +++++++++++++
331546
 tests/curves.c      | 46 ++++++++++++++++++++++++++++++---------------
331546
 tests/keygrip.c     |  2 ++
331546
 5 files changed, 53 insertions(+), 15 deletions(-)
331546
331546
diff --git a/README b/README
331546
index 436b6cd4..1044109c 100644
331546
--- a/README
331546
+++ b/README
331546
@@ -127,6 +127,9 @@
331546
                      the list used with the current build the program
331546
                      tests/version may be used.
331546
 
331546
+     --disable-brainpool
331546
+                     Do not build in support for Brainpool curves.
331546
+
331546
      --disable-endian-check
331546
                      Don't let configure test for the endianness but
331546
                      try to use the OS provided macros at compile
331546
diff --git a/cipher/ecc-curves.c b/cipher/ecc-curves.c
331546
index 7c86e12c..8fd95a9c 100644
331546
--- a/cipher/ecc-curves.c
331546
+++ b/cipher/ecc-curves.c
331546
@@ -77,6 +77,7 @@ static const struct
331546
     { "NIST P-521", "1.3.132.0.35" },
331546
     { "NIST P-521", "nistp521"   },          /* rfc5656.  */
331546
 
331546
+#ifdef ENABLE_BRAINPOOL
331546
     { "brainpoolP160r1", "1.3.36.3.3.2.8.1.1.1" },
331546
     { "brainpoolP192r1", "1.3.36.3.3.2.8.1.1.3" },
331546
     { "brainpoolP224r1", "1.3.36.3.3.2.8.1.1.5" },
331546
@@ -84,6 +85,7 @@ static const struct
331546
     { "brainpoolP320r1", "1.3.36.3.3.2.8.1.1.9" },
331546
     { "brainpoolP384r1", "1.3.36.3.3.2.8.1.1.11"},
331546
     { "brainpoolP512r1", "1.3.36.3.3.2.8.1.1.13"},
331546
+#endif /* ENABLE_BRAINPOOL */
331546
 
331546
     { "GOST2001-test", "1.2.643.2.2.35.0" },
331546
     { "GOST2001-CryptoPro-A", "1.2.643.2.2.35.1" },
331546
@@ -297,6 +299,7 @@ static const ecc_domain_parms_t domain_parms[] =
331546
       1
331546
     },
331546
 
331546
+#ifdef ENABLE_BRAINPOOL
331546
     { "brainpoolP160r1", 160, 0,
331546
       MPI_EC_WEIERSTRASS, ECC_DIALECT_STANDARD,
331546
       "0xe95e4a5f737059dc60dfc7ad95b3d8139515620f",
331546
@@ -391,6 +394,7 @@ static const ecc_domain_parms_t domain_parms[] =
331546
       "b2dcde494a5f485e5bca4bd88a2763aed1ca2b2fa8f0540678cd1e0f3ad80892",
331546
       1
331546
     },
331546
+#endif /* ENABLE_BRAINPOOL */
331546
     {
331546
       "GOST2001-test", 256, 0,
331546
       MPI_EC_WEIERSTRASS, ECC_DIALECT_STANDARD,
331546
diff --git a/configure.ac b/configure.ac
331546
index 6efbf139..f4ac1887 100644
331546
--- a/configure.ac
331546
+++ b/configure.ac
331546
@@ -614,6 +614,14 @@ AC_ARG_WITH(fips-module-version,
331546
 AC_DEFINE_UNQUOTED(FIPS_MODULE_VERSION, "$fips_module_version",
331546
                    [Define FIPS module version for certification])
331546
 
331546
+# Implementation of the --disable-brainpool switch.
331546
+AC_MSG_CHECKING([whether we want to disable the use of brainpool curves])
331546
+AC_ARG_ENABLE(brainpool,
331546
+              AS_HELP_STRING([--disable-brainpool],
331546
+                             [Disable the brainpool curves]),
331546
+              use_brainpool="$enableval",use_brainpool=yes)
331546
+AC_MSG_RESULT($use_brainpool)
331546
+
331546
 # Implementation of the --disable-jent-support switch.
331546
 AC_MSG_CHECKING([whether jitter entropy support is requested])
331546
 AC_ARG_ENABLE(jent-support,
331546
@@ -2466,6 +2474,10 @@ if test x"$ppccryptosupport" = xyes ; then
331546
   AC_DEFINE(ENABLE_PPC_CRYPTO_SUPPORT,1,
331546
             [Enable support for POWER 8 (PowerISA 2.07) crypto extension.])
331546
 fi
331546
+if test x"$use_brainpool" = xyes ; then
331546
+  AC_DEFINE(ENABLE_BRAINPOOL, 1,
331546
+            [Enable support for the brainpool curves.])
331546
+fi
331546
 if test x"$jentsupport" = xyes ; then
331546
   AC_DEFINE(ENABLE_JENT_SUPPORT, 1,
331546
             [Enable support for the jitter entropy collector.])
331546
@@ -3296,6 +3308,7 @@ GCRY_MSG_WRAP([Enabled digest algorithms:],[$enabled_digests])
331546
 GCRY_MSG_WRAP([Enabled kdf algorithms:   ],[$enabled_kdfs])
331546
 GCRY_MSG_WRAP([Enabled pubkey algorithms:],[$enabled_pubkey_ciphers])
331546
 GCRY_MSG_SHOW([Random number generator:  ],[$random])
331546
+GCRY_MSG_SHOW([Enabled Brainpool curves: ],[$use_brainpool])
331546
 GCRY_MSG_SHOW([Try using jitter entropy: ],[$jentsupport])
331546
 GCRY_MSG_SHOW([Using linux capabilities: ],[$use_capabilities])
331546
 GCRY_MSG_SHOW([FIPS module version:      ],[$fips_module_version])
331546
diff --git a/tests/curves.c b/tests/curves.c
331546
index 3c738171..8eb79565 100644
331546
--- a/tests/curves.c
331546
+++ b/tests/curves.c
331546
@@ -33,7 +33,11 @@
331546
 #include "t-common.h"
331546
 
331546
 /* Number of curves defined in ../cipher/ecc-curves.c */
331546
-#define N_CURVES 27
331546
+#ifdef ENABLE_BRAINPOOL
331546
+# define N_CURVES 27
331546
+#else
331546
+# define N_CURVES 20
331546
+#endif
331546
 
331546
 /* A real world sample public key.  */
331546
 static char const sample_key_1[] =
331546
@@ -52,6 +56,7 @@ static char const sample_key_1[] =
331546
 static char const sample_key_1_curve[] = "NIST P-256";
331546
 static unsigned int sample_key_1_nbits = 256;
331546
 
331546
+#ifdef ENABLE_BRAINPOOL
331546
 /* A made up sample public key.  */
331546
 static char const sample_key_2[] =
331546
 "(public-key\n"
331546
@@ -68,6 +73,7 @@ static char const sample_key_2[] =
331546
 "  ))";
331546
 static char const sample_key_2_curve[] = "brainpoolP160r1";
331546
 static unsigned int sample_key_2_nbits = 160;
331546
+#endif /* ENABLE_BRAINPOOL */
331546
 
331546
 static int in_fips_mode;
331546
 
331546
@@ -113,6 +119,7 @@ check_matching (void)
331546
 
331546
   gcry_sexp_release (key);
331546
 
331546
+#ifdef ENABLE_BRAINPOOL
331546
   if (!in_fips_mode)
331546
     {
331546
       err = gcry_sexp_new (&key, sample_key_2, 0, 1);
331546
@@ -130,6 +137,7 @@ check_matching (void)
331546
 
331546
       gcry_sexp_release (key);
331546
     }
331546
+#endif /* ENABLE_BRAINPOOL */
331546
 }
331546
 
331546
 #define TEST_ERROR_EXPECTED (1 << 0)
331546
@@ -185,20 +193,26 @@ check_get_params (void)
331546
        { GCRY_PK_ECC, "1.3.132.0.35" },
331546
        { GCRY_PK_ECC, "nistp521"   },
331546
 
331546
-       { GCRY_PK_ECC, "brainpoolP160r1",       TEST_NOFIPS },
331546
-       { GCRY_PK_ECC, "1.3.36.3.3.2.8.1.1.1",  TEST_NOFIPS },
331546
-       { GCRY_PK_ECC, "brainpoolP192r1",       TEST_NOFIPS },
331546
-       { GCRY_PK_ECC, "1.3.36.3.3.2.8.1.1.3",  TEST_NOFIPS },
331546
-       { GCRY_PK_ECC, "brainpoolP224r1",       TEST_NOFIPS },
331546
-       { GCRY_PK_ECC, "1.3.36.3.3.2.8.1.1.5",  TEST_NOFIPS },
331546
-       { GCRY_PK_ECC, "brainpoolP256r1",       TEST_NOFIPS },
331546
-       { GCRY_PK_ECC, "1.3.36.3.3.2.8.1.1.7",  TEST_NOFIPS },
331546
-       { GCRY_PK_ECC, "brainpoolP320r1",       TEST_NOFIPS },
331546
-       { GCRY_PK_ECC, "1.3.36.3.3.2.8.1.1.9",  TEST_NOFIPS },
331546
-       { GCRY_PK_ECC, "brainpoolP384r1",       TEST_NOFIPS },
331546
-       { GCRY_PK_ECC, "1.3.36.3.3.2.8.1.1.11", TEST_NOFIPS },
331546
-       { GCRY_PK_ECC, "brainpoolP512r1",       TEST_NOFIPS },
331546
-       { GCRY_PK_ECC, "1.3.36.3.3.2.8.1.1.13", TEST_NOFIPS },
331546
+#ifdef ENABLE_BRAINPOOL
331546
+# define BRAINPOOL_FLAGS TEST_NOFIPS
331546
+#else
331546
+# define BRAINPOOL_FLAGS TEST_ERROR_EXPECTED
331546
+#endif /* ENABLE_BRAINPOOL */
331546
+       { GCRY_PK_ECC, "brainpoolP160r1",       BRAINPOOL_FLAGS },
331546
+       { GCRY_PK_ECC, "1.3.36.3.3.2.8.1.1.1",  BRAINPOOL_FLAGS },
331546
+       { GCRY_PK_ECC, "brainpoolP192r1",       BRAINPOOL_FLAGS },
331546
+       { GCRY_PK_ECC, "1.3.36.3.3.2.8.1.1.3",  BRAINPOOL_FLAGS },
331546
+       { GCRY_PK_ECC, "brainpoolP224r1",       BRAINPOOL_FLAGS },
331546
+       { GCRY_PK_ECC, "1.3.36.3.3.2.8.1.1.5",  BRAINPOOL_FLAGS },
331546
+       { GCRY_PK_ECC, "brainpoolP256r1",       BRAINPOOL_FLAGS },
331546
+       { GCRY_PK_ECC, "1.3.36.3.3.2.8.1.1.7",  BRAINPOOL_FLAGS },
331546
+       { GCRY_PK_ECC, "brainpoolP320r1",       BRAINPOOL_FLAGS },
331546
+       { GCRY_PK_ECC, "1.3.36.3.3.2.8.1.1.9",  BRAINPOOL_FLAGS },
331546
+       { GCRY_PK_ECC, "brainpoolP384r1",       BRAINPOOL_FLAGS },
331546
+       { GCRY_PK_ECC, "1.3.36.3.3.2.8.1.1.11", BRAINPOOL_FLAGS },
331546
+       { GCRY_PK_ECC, "brainpoolP512r1",       BRAINPOOL_FLAGS },
331546
+       { GCRY_PK_ECC, "1.3.36.3.3.2.8.1.1.13", BRAINPOOL_FLAGS },
331546
+#undef BRAINPOOL_ERROR_EXPECTED
331546
 
331546
        { GCRY_PK_ECC, "GOST2001-test", TEST_NOFIPS },
331546
        { GCRY_PK_ECC, "1.2.643.2.2.35.0", TEST_NOFIPS },
331546
@@ -282,6 +296,7 @@ check_get_params (void)
331546
 
331546
   gcry_sexp_release (param);
331546
 
331546
+#ifdef ENABLE_BRAINPOOL
331546
   if (!in_fips_mode)
331546
     {
331546
       param = gcry_pk_get_param (GCRY_PK_ECDSA, sample_key_2_curve);
331546
@@ -297,6 +312,7 @@ check_get_params (void)
331546
 
331546
       gcry_sexp_release (param);
331546
     }
331546
+#endif /* ENABLE_BRAINPOOL */
331546
 
331546
   /* Some simple tests */
331546
   for (idx=0; idx < DIM (tv); idx++)
331546
diff --git a/tests/keygrip.c b/tests/keygrip.c
331546
index 49bd71bc..fc4c17be 100644
331546
--- a/tests/keygrip.c
331546
+++ b/tests/keygrip.c
331546
@@ -149,6 +149,7 @@ static struct
331546
       " (q #04C8A4CEC2E9A9BC8E173531A67B0840DF345C32E261ADD780E6D83D56EFADFD5DE872F8B854819B59543CE0B7F822330464FBC4E6324DADDCD9D059554F63B344#)))",
331546
       "\xE6\xDF\x94\x2D\xBD\x8C\x77\x05\xA3\xDD\x41\x6E\xFC\x04\x01\xDB\x31\x0E\x99\xB6"
331546
     },
331546
+#ifdef ENABLE_BRAINPOOL
331546
     {
331546
       GCRY_PK_ECC,
331546
       "(public-key"
331546
@@ -197,6 +198,7 @@ static struct
331546
       "\xD6\xE1\xBF\x43\xAC\x9B\x9A\x12\xE7\x3F",
331546
       1
331546
     },
331546
+#endif /*ENABLE_BRAINPOOL */
331546
     { /* Ed25519 standard */
331546
       GCRY_PK_ECC,
331546
       "(public-key"
331546
-- 
331546
2.34.1
331546