X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Futil%2Fcrypto_ecc_dlog.c;h=07777e377d562fdd8e5cb42b9c1515e1c1f8c7a5;hb=31adcb0e020b7861ee7f306a6e2fac0df9b10290;hp=29cba3336faf8d64df23c7e1beebcc0f30b47ac9;hpb=f1a73a358739cd2bebf7b83ef1c097a04dc50cd4;p=oweals%2Fgnunet.git diff --git a/src/util/crypto_ecc_dlog.c b/src/util/crypto_ecc_dlog.c index 29cba3336..07777e377 100644 --- a/src/util/crypto_ecc_dlog.c +++ b/src/util/crypto_ecc_dlog.c @@ -1,21 +1,21 @@ /* 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 - by the Free Software Foundation; either version 3, or (at your - option) any later version. + GNUnet is free software: you can redistribute it and/or modify it + under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, + or (at your option) any later version. GNUnet is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. + 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 . - 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. + SPDX-License-Identifier: AGPL3.0-or-later */ /** @@ -130,6 +130,7 @@ GNUNET_CRYPTO_ecc_bin_to_point (struct GNUNET_CRYPTO_EccDlogContext *edc, gcry_ctx_t ctx; gcry_mpi_point_t q; + (void) edc; if (0 != gcry_sexp_build (&pub_sexpr, NULL, "(public-key(ecc(curve " CURVE ")(q %b)))", (int) sizeof (bin->q_y), @@ -151,7 +152,7 @@ GNUNET_CRYPTO_ecc_bin_to_point (struct GNUNET_CRYPTO_EccDlogContext *edc, * * @param max maximum value the factor can be * @param mem memory to use (should be smaller than @a max), must not be zero. - * @return @a max if dlog failed, otherwise the factor + * @return NULL on error */ struct GNUNET_CRYPTO_EccDlogContext * GNUNET_CRYPTO_ecc_dlog_prepare (unsigned int max, @@ -219,7 +220,7 @@ GNUNET_CRYPTO_ecc_dlog_prepare (unsigned int max, * * @param edc precalculated values, determine range of factors * @param input point on the curve to factor - * @return `edc->max` if dlog failed, otherwise the factor + * @return INT_MAX if dlog failed, otherwise the factor */ int GNUNET_CRYPTO_ecc_dlog (struct GNUNET_CRYPTO_EccDlogContext *edc, @@ -237,7 +238,7 @@ GNUNET_CRYPTO_ecc_dlog (struct GNUNET_CRYPTO_EccDlogContext *edc, GNUNET_assert (NULL != g); q = gcry_mpi_point_new (0); - res = edc->max; + res = INT_MAX; for (i=0;i<=edc->max/edc->mem;i++) { if (0 == i) @@ -466,6 +467,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. *