/*
This file is part of GNUnet.
Copyright (C) 2015 GNUnet e.V.
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
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 .
SPDX-License-Identifier: AGPL3.0-or-later
*/
/**
* @file util/test_ecc_scalarproduct.c
* @brief testcase for math behind ECC SP calculation
* @author Christian Grothoff
*/
#include "platform.h"
#include "gnunet_util_lib.h"
#include
/**
* Global context.
*/
static struct GNUNET_CRYPTO_EccDlogContext *edc;
/**
* Perform SP calculation.
*
* @param avec 0-terminated vector of Alice's values
* @param bvec 0-terminated vector of Bob's values
* @return avec * bvec
*/
static int
test_sp (const unsigned int *avec,
const unsigned int *bvec)
{
unsigned int len;
unsigned int i;
gcry_mpi_t a;
gcry_mpi_t a_inv;
gcry_mpi_t ri;
gcry_mpi_t val;
gcry_mpi_t ria;
gcry_mpi_t tmp;
gcry_mpi_point_t *g;
gcry_mpi_point_t *h;
gcry_mpi_point_t pg;
gcry_mpi_point_t ph;
gcry_mpi_point_t pgi;
gcry_mpi_point_t gsp;
int sp;
/* determine length */
for (len=0;0 != avec[len];len++) ;
if (0 == len)
return 0;
/* Alice */
GNUNET_CRYPTO_ecc_rnd_mpi (edc,
&a, &a_inv);
g = GNUNET_new_array (len,
gcry_mpi_point_t);
h = GNUNET_new_array (len,
gcry_mpi_point_t);
ria = gcry_mpi_new (0);
tmp = gcry_mpi_new (0);
for (i=0;i