-fix the fix
[oweals/gnunet.git] / src / util / crypto_ecc_dlog.c
index 13ee1e6be86d30ca3ea332651efa8894d401c4f0..f6eb58a9ac4ddcdd729c101820f2fc01260732a9 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     Copyright (C) 2012, 2013, 2015 Christian Grothoff (and other contributing authors)
+     Copyright (C) 2012, 2013, 2015 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
@@ -406,6 +406,28 @@ GNUNET_CRYPTO_ecc_add (struct GNUNET_CRYPTO_EccDlogContext *edc,
 }
 
 
+/**
+ * Multiply the point @a p on the elliptic curve by @a val.
+ *
+ * @param edc calculation context for ECC operations
+ * @param p point to multiply
+ * @param val (positive) value to encode into a point
+ * @return representation of the value as an ECC point,
+ *         must be freed using #GNUNET_CRYPTO_ecc_free()
+ */
+gcry_mpi_point_t
+GNUNET_CRYPTO_ecc_pmul_mpi (struct GNUNET_CRYPTO_EccDlogContext *edc,
+                            gcry_mpi_point_t p,
+                           gcry_mpi_t val)
+{
+  gcry_mpi_point_t r;
+
+  r = gcry_mpi_point_new (0);
+  gcry_mpi_ec_mul (r, val, p, edc->ctx);
+  return r;
+}
+
+
 /**
  * Obtain a random point on the curve and its
  * additive inverse. Both returned values
@@ -444,6 +466,29 @@ GNUNET_CRYPTO_ecc_rnd (struct GNUNET_CRYPTO_EccDlogContext *edc,
 }
 
 
+/**
+ * Obtain a random scalar for point multiplication on the curve and
+ * its multiplicative inverse.
+ *
+ * @param edc calculation context for ECC operations
+ * @param[out] r set to a random scalar on the curve
+ * @param[out] r_inv set to the multiplicative inverse of @a r
+ */
+void
+GNUNET_CRYPTO_ecc_rnd_mpi (struct GNUNET_CRYPTO_EccDlogContext *edc,
+                           gcry_mpi_t *r,
+                           gcry_mpi_t *r_inv)
+{
+  gcry_mpi_t n;
+
+  *r = GNUNET_CRYPTO_ecc_random_mod_n (edc);
+  /* r_inv = n - r = - r */
+  *r_inv = gcry_mpi_new (0);
+  n = gcry_mpi_ec_get_mpi ("n", edc->ctx, 1);
+  gcry_mpi_sub (*r_inv, n, *r);
+}
+
+
 /**
  * Free a point value returned by the API.
  *