add 3dim array helpers
This commit is contained in:
parent
8e44164fac
commit
65775f8276
4
brandt.h
4
brandt.h
@ -148,7 +148,7 @@ BRANDT_join (BRANDT_BroadcastCallback broadcast,
|
||||
* the price of the highest loosing bid. \todo: what if bidders < m?
|
||||
* @param[in] outcome_public If 1, the auction winner and price will be public
|
||||
* to all participants, if 0, this information will only be revealed to the
|
||||
* winner and the seller. => \todo: Turn into AuctionMode bit flag!
|
||||
* winner and the seller.
|
||||
* @return A pointer, which should only be remembered and passed to
|
||||
* libbrandt functions when the client needs to refer to this auction. This is a
|
||||
* black-box pointer, do NOT access/change it or the data it points to!
|
||||
@ -160,7 +160,7 @@ BRANDT_new (BRANDT_BroadcastCallback broadcast,
|
||||
const void ** auction_data,
|
||||
size_t * auction_data_len,
|
||||
uint16_t num_prices,
|
||||
enum BRANDT_AuctionMode m,
|
||||
uint16_t m,
|
||||
int outcome_public);
|
||||
|
||||
|
||||
|
53
crypto.c
53
crypto.c
@ -37,9 +37,8 @@ static gcry_mpi_t ec_n;
|
||||
|
||||
|
||||
/**
|
||||
* brandt_crypto_init
|
||||
*
|
||||
*
|
||||
* brandt_crypto_init initializes the crypto system and must be called before
|
||||
* any other function from this file.
|
||||
*/
|
||||
void
|
||||
brandt_crypto_init ()
|
||||
@ -297,8 +296,9 @@ smc_init2 (uint16_t size1, uint16_t size2)
|
||||
gcry_mpi_point_t **ret;
|
||||
gcry_mpi_point_t *data;
|
||||
|
||||
ret = calloc (size1, sizeof (*ret) + (size2 * sizeof (**ret)));
|
||||
ret = calloc (size1, sizeof (*ret) + size2 * sizeof (**ret));
|
||||
brandt_assert (NULL != ret);
|
||||
|
||||
data = (gcry_mpi_point_t *)&ret[size1];
|
||||
for (i = 0; i < size1; i++)
|
||||
{
|
||||
@ -322,6 +322,51 @@ smc_free2 (gcry_mpi_point_t **dst, uint16_t size1, uint16_t size2)
|
||||
}
|
||||
|
||||
|
||||
static gcry_mpi_point_t ***
|
||||
smc_init3 (uint16_t size1, uint16_t size2, uint16_t size3)
|
||||
{
|
||||
uint16_t i, j, k;
|
||||
gcry_mpi_point_t ***ret;
|
||||
gcry_mpi_point_t **layer1;
|
||||
gcry_mpi_point_t *layer2;
|
||||
|
||||
ret = calloc (size1, sizeof (*ret) +
|
||||
size2 * sizeof (**ret) +
|
||||
size2 * size3 * sizeof (***ret));
|
||||
brandt_assert (NULL != ret);
|
||||
|
||||
layer1 = (gcry_mpi_point_t **)&ret[size1];
|
||||
layer2 = (gcry_mpi_point_t *)&layer1[size1*size2];
|
||||
for (i = 0; i < size1; i++)
|
||||
{
|
||||
ret[i] = &layer1[i * size2];
|
||||
for (j = 0; j < size2; j++)
|
||||
{
|
||||
layer1[i * size2 + j] = &layer2[(i * size2 + j) * size3];
|
||||
for (k = 0; k < size3; k++)
|
||||
ret[i][j][k] = gcry_mpi_point_new (0);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
smc_free3 (gcry_mpi_point_t ***dst,
|
||||
uint16_t size1,
|
||||
uint16_t size2,
|
||||
uint16_t size3)
|
||||
{
|
||||
uint16_t i, j, k;
|
||||
|
||||
for (i = 0; i < size1; i++)
|
||||
for (j = 0; j < size2; j++)
|
||||
for (k = 0; k < size3; k++)
|
||||
gcry_mpi_point_release (dst[i][j][k]);
|
||||
free (dst);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* smc_sums_partial calculates sums up until the current index and stores them
|
||||
* in @a out. \f$\forall i \leq len: out_i=\sum_{h=1}^iin_h\f$
|
||||
|
@ -46,6 +46,27 @@ test_smc_2d_array ()
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
test_smc_3d_array ()
|
||||
{
|
||||
gcry_mpi_point_t ***array;
|
||||
uint16_t size1 = 3;
|
||||
uint16_t size2 = 7;
|
||||
uint16_t size3 = 11;
|
||||
uint16_t i, j, k;
|
||||
|
||||
array = smc_init3 (size1, size2, size3);
|
||||
check (array, "memory allocation failed");
|
||||
|
||||
for (i = 0; i < size1; i++)
|
||||
for (j = 0; j < size2; j++)
|
||||
for (k = 0; k < size3; k++)
|
||||
check (array[i][j][k], "point has not been initialized");
|
||||
|
||||
smc_free3 (array, size1, size2, size3);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
test_smc_zkp_dl ()
|
||||
{
|
||||
@ -185,6 +206,7 @@ main (int argc, char *argv[])
|
||||
|
||||
/* tests that need to run only once */
|
||||
run (test_smc_2d_array);
|
||||
run (test_smc_3d_array);
|
||||
|
||||
for (tests_run = 0; tests_run < repeat; tests_run++)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user