Merge branch 'master' of ssh://gnunet.org/gnunet
[oweals/gnunet.git] / src / util / crypto_mpi.c
index 5a503c6391c2a6513b28d25fb997b1dc87c1cd55..ff3e9a8a72aaab5c6c2e4e805554c30adc48d3ef 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (C) 2012, 2013 Christian Grothoff (and other contributing authors)
+     Copyright (C) 2012, 2013 GNUnet e.V.
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -14,8 +14,8 @@
 
      You should have received a copy of the GNU General Public License
      along with GNUnet; see the file COPYING.  If not, write to the
-     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-     Boston, MA 02111-1307, USA.
+     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+     Boston, MA 02110-1301, USA.
 */
 
 /**
  */
 #include "platform.h"
 #include <gcrypt.h>
-#include "gnunet_util_lib.h"
+#include "gnunet_crypto_lib.h"
 
 
-#define LOG(kind,...) GNUNET_log_from (kind, "util", __VA_ARGS__)
+#define LOG(kind,...) GNUNET_log_from (kind, "util-crypto-mpi", __VA_ARGS__)
 
 /**
  * Log an error message at log-level 'level' that indicates
@@ -77,6 +77,7 @@ GNUNET_CRYPTO_mpi_print_unsigned (void *buf,
                                   gcry_mpi_t val)
 {
   size_t rsize;
+  int rc;
 
   if (gcry_mpi_get_flag (val, GCRYMPI_FLAG_OPAQUE))
   {
@@ -89,7 +90,7 @@ GNUNET_CRYPTO_mpi_print_unsigned (void *buf,
     rsize = (nbits+7)/8;
     if (rsize > size)
       rsize = size;
-    memcpy (buf, p, rsize);
+    GNUNET_memcpy (buf, p, rsize);
     if (rsize < size)
       memset (buf+rsize, 0, size - rsize);
   }
@@ -98,9 +99,17 @@ GNUNET_CRYPTO_mpi_print_unsigned (void *buf,
     /* Store regular MPIs as unsigned integers right aligned into
        the buffer.  */
     rsize = size;
-    GNUNET_assert (0 ==
-                   gcry_mpi_print (GCRYMPI_FMT_USG, buf, rsize, &rsize,
-                                   val));
+    if (0 !=
+        (rc = gcry_mpi_print (GCRYMPI_FMT_USG,
+                              buf,
+                              rsize, &rsize,
+                              val)))
+    {
+      LOG_GCRY (GNUNET_ERROR_TYPE_ERROR,
+                "gcry_mpi_print",
+                rc);
+      GNUNET_assert (0);
+    }
     adjust (buf, rsize, size);
   }
 }
@@ -126,7 +135,9 @@ GNUNET_CRYPTO_mpi_scan_unsigned (gcry_mpi_t *result,
                                GCRYMPI_FMT_USG,
                                data, size, &size)))
   {
-    LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc);
+    LOG_GCRY (GNUNET_ERROR_TYPE_ERROR,
+              "gcry_mpi_scan",
+              rc);
     GNUNET_assert (0);
   }
 }