tolerate additional IPv4 address now available for gnunet.org
[oweals/gnunet.git] / src / util / crypto_ecc.c
index ac7662a103faf73d42177765257052140258cb87..339180dffbf91a12cf5dc4ed455a203aa9b18edf 100644 (file)
@@ -11,7 +11,7 @@
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      Affero General Public License for more details.
-    
+
      You should have received a copy of the GNU Affero General Public License
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
@@ -762,23 +762,6 @@ GNUNET_CRYPTO_ecdsa_key_get_anonymous ()
 }
 
 
-/**
- * Compare two Peer Identities.
- *
- * @param first first peer identity
- * @param second second peer identity
- * @return bigger than 0 if first > second,
- *         0 if they are the same
- *         smaller than 0 if second > first
- */
-int
-GNUNET_CRYPTO_cmp_peer_identity (const struct GNUNET_PeerIdentity *first,
-                                 const struct GNUNET_PeerIdentity *second)
-{
-  return memcmp (first, second, sizeof (struct GNUNET_PeerIdentity));
-}
-
-
 /**
  * Convert the data specified in the given purpose argument to an
  * S-expression suitable for signature operations.
@@ -789,19 +772,41 @@ GNUNET_CRYPTO_cmp_peer_identity (const struct GNUNET_PeerIdentity *first,
 static gcry_sexp_t
 data_to_eddsa_value (const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose)
 {
-  struct GNUNET_HashCode hc;
   gcry_sexp_t data;
   int rc;
 
+/* SEE #5398 */
+#if 1
+  struct GNUNET_HashCode hc;
+
+  GNUNET_CRYPTO_hash (purpose,
+                     ntohl (purpose->size),
+                     &hc);
+  if (0 != (rc = gcry_sexp_build (&data, NULL,
+                                 "(data(flags eddsa)(hash-algo %s)(value %b))",
+                                 "sha512",
+                                 (int)sizeof (hc),
+                                 &hc)))
+  {
+    LOG_GCRY (GNUNET_ERROR_TYPE_ERROR,
+             "gcry_sexp_build",
+             rc);
+    return NULL;
+  }
+#else
   GNUNET_CRYPTO_hash (purpose, ntohl (purpose->size), &hc);
   if (0 != (rc = gcry_sexp_build (&data, NULL,
                                  "(data(flags eddsa)(hash-algo %s)(value %b))",
                                  "sha512",
-                                 (int)sizeof (hc), &hc)))
+                                 ntohl (purpose->size),
+                                 purpose)))
   {
-    LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_sexp_build", rc);
+    LOG_GCRY (GNUNET_ERROR_TYPE_ERROR,
+             "gcry_sexp_build",
+             rc);
     return NULL;
   }
+#endif
   return data;
 }
 
@@ -816,19 +821,39 @@ data_to_eddsa_value (const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose)
 static gcry_sexp_t
 data_to_ecdsa_value (const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose)
 {
-  struct GNUNET_HashCode hc;
   gcry_sexp_t data;
   int rc;
 
-  GNUNET_CRYPTO_hash (purpose, ntohl (purpose->size), &hc);
+/* See #5398 */
+#if 1
+  struct GNUNET_HashCode hc;
+
+  GNUNET_CRYPTO_hash (purpose,
+                     ntohl (purpose->size),
+                     &hc);
   if (0 != (rc = gcry_sexp_build (&data, NULL,
                                  "(data(flags rfc6979)(hash %s %b))",
                                  "sha512",
                                  (int)sizeof (hc), &hc)))
   {
-    LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_sexp_build", rc);
+    LOG_GCRY (GNUNET_ERROR_TYPE_ERROR,
+             "gcry_sexp_build",
+             rc);
     return NULL;
   }
+#else
+  if (0 != (rc = gcry_sexp_build (&data, NULL,
+                                 "(data(flags rfc6979)(hash %s %b))",
+                                 "sha512",
+                                 ntohl (purpose->size),
+                                 purpose)))
+  {
+    LOG_GCRY (GNUNET_ERROR_TYPE_ERROR,
+             "gcry_sexp_build",
+             rc);
+    return NULL;
+  }
+#endif
   return data;
 }
 
@@ -877,8 +902,12 @@ GNUNET_CRYPTO_ecdsa_sign (const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv,
     return GNUNET_SYSERR;
   }
   gcry_sexp_release (sig_sexp);
-  GNUNET_CRYPTO_mpi_print_unsigned (sig->r, sizeof (sig->r), rs[0]);
-  GNUNET_CRYPTO_mpi_print_unsigned (sig->s, sizeof (sig->s), rs[1]);
+  GNUNET_CRYPTO_mpi_print_unsigned (sig->r,
+                                   sizeof (sig->r),
+                                   rs[0]);
+  GNUNET_CRYPTO_mpi_print_unsigned (sig->s,
+                                   sizeof (sig->s),
+                                   rs[1]);
   gcry_mpi_release (rs[0]);
   gcry_mpi_release (rs[1]);