aboutsummaryrefslogtreecommitdiff
path: root/crypto.c
diff options
context:
space:
mode:
authorMarkus Teich <markus.teich@stusta.mhn.de>2016-06-20 00:36:18 +0200
committerMarkus Teich <markus.teich@stusta.mhn.de>2016-06-20 00:36:18 +0200
commit65775f8276b082a18c99cb75c11193685bd5d822 (patch)
tree626229703ecafef6ce509584582f2e3b181f5bab /crypto.c
parent8e44164facc215a09984d83f488345f548753477 (diff)
downloadlibbrandt-65775f8276b082a18c99cb75c11193685bd5d822.tar.gz
libbrandt-65775f8276b082a18c99cb75c11193685bd5d822.zip
add 3dim array helpers
Diffstat (limited to 'crypto.c')
-rw-r--r--crypto.c53
1 files changed, 49 insertions, 4 deletions
diff --git a/crypto.c b/crypto.c
index 044db00..e7397d5 100644
--- a/crypto.c
+++ b/crypto.c
@@ -37,9 +37,8 @@ static gcry_mpi_t ec_n;
37 37
38 38
39/** 39/**
40 * brandt_crypto_init 40 * brandt_crypto_init initializes the crypto system and must be called before
41 * 41 * any other function from this file.
42 *
43 */ 42 */
44void 43void
45brandt_crypto_init () 44brandt_crypto_init ()
@@ -297,8 +296,9 @@ smc_init2 (uint16_t size1, uint16_t size2)
297 gcry_mpi_point_t **ret; 296 gcry_mpi_point_t **ret;
298 gcry_mpi_point_t *data; 297 gcry_mpi_point_t *data;
299 298
300 ret = calloc (size1, sizeof (*ret) + (size2 * sizeof (**ret))); 299 ret = calloc (size1, sizeof (*ret) + size2 * sizeof (**ret));
301 brandt_assert (NULL != ret); 300 brandt_assert (NULL != ret);
301
302 data = (gcry_mpi_point_t *)&ret[size1]; 302 data = (gcry_mpi_point_t *)&ret[size1];
303 for (i = 0; i < size1; i++) 303 for (i = 0; i < size1; i++)
304 { 304 {
@@ -322,6 +322,51 @@ smc_free2 (gcry_mpi_point_t **dst, uint16_t size1, uint16_t size2)
322} 322}
323 323
324 324
325static gcry_mpi_point_t ***
326smc_init3 (uint16_t size1, uint16_t size2, uint16_t size3)
327{
328 uint16_t i, j, k;
329 gcry_mpi_point_t ***ret;
330 gcry_mpi_point_t **layer1;
331 gcry_mpi_point_t *layer2;
332
333 ret = calloc (size1, sizeof (*ret) +
334 size2 * sizeof (**ret) +
335 size2 * size3 * sizeof (***ret));
336 brandt_assert (NULL != ret);
337
338 layer1 = (gcry_mpi_point_t **)&ret[size1];
339 layer2 = (gcry_mpi_point_t *)&layer1[size1*size2];
340 for (i = 0; i < size1; i++)
341 {
342 ret[i] = &layer1[i * size2];
343 for (j = 0; j < size2; j++)
344 {
345 layer1[i * size2 + j] = &layer2[(i * size2 + j) * size3];
346 for (k = 0; k < size3; k++)
347 ret[i][j][k] = gcry_mpi_point_new (0);
348 }
349 }
350 return ret;
351}
352
353
354static void
355smc_free3 (gcry_mpi_point_t ***dst,
356 uint16_t size1,
357 uint16_t size2,
358 uint16_t size3)
359{
360 uint16_t i, j, k;
361
362 for (i = 0; i < size1; i++)
363 for (j = 0; j < size2; j++)
364 for (k = 0; k < size3; k++)
365 gcry_mpi_point_release (dst[i][j][k]);
366 free (dst);
367}
368
369
325/** 370/**
326 * smc_sums_partial calculates sums up until the current index and stores them 371 * smc_sums_partial calculates sums up until the current index and stores them
327 * in @a out. \f$\forall i \leq len: out_i=\sum_{h=1}^iin_h\f$ 372 * in @a out. \f$\forall i \leq len: out_i=\sum_{h=1}^iin_h\f$