aboutsummaryrefslogtreecommitdiff
path: root/crypto.c
diff options
context:
space:
mode:
authorMarkus Teich <markus.teich@stusta.mhn.de>2016-08-09 12:53:08 +0200
committerMarkus Teich <markus.teich@stusta.mhn.de>2016-08-09 12:53:08 +0200
commitf64f620b074bec1bbcca0a5cbc9331ff8c323605 (patch)
tree4db706ac7b7739fa065dc6c6c336c4c2432c8909 /crypto.c
parentf55d10d5f64d9f859a2693821bacb8da3dd50eb9 (diff)
downloadlibbrandt-f64f620b074bec1bbcca0a5cbc9331ff8c323605.tar.gz
libbrandt-f64f620b074bec1bbcca0a5cbc9331ff8c323605.zip
use GNUNET_new_array instead of calloc
Diffstat (limited to 'crypto.c')
-rw-r--r--crypto.c30
1 files changed, 13 insertions, 17 deletions
diff --git a/crypto.c b/crypto.c
index 71ee706..e96fd0e 100644
--- a/crypto.c
+++ b/crypto.c
@@ -404,11 +404,7 @@ smc_init1 (uint16_t size1)
404{ 404{
405 gcry_mpi_point_t *ret; 405 gcry_mpi_point_t *ret;
406 406
407 if (NULL == (ret = calloc (size1, sizeof (*ret)))) 407 ret = GNUNET_new_array (size1, gcry_mpi_point_t);
408 {
409 weprintf ("could not alloc memory for 1 dimensional point array");
410 return NULL;
411 }
412 408
413 for (uint16_t i = 0; i < size1; i++) 409 for (uint16_t i = 0; i < size1; i++)
414 { 410 {
@@ -629,8 +625,8 @@ smc_gen_keyshare (struct BRANDT_Auction *ad, size_t *buflen)
629 625
630 brandt_assert (ad && buflen); 626 brandt_assert (ad && buflen);
631 *buflen = (sizeof (struct ec_mpi) + sizeof (*proof1)); 627 *buflen = (sizeof (struct ec_mpi) + sizeof (*proof1));
632 if (NULL == (ret = calloc (1, *buflen)) || 628 ret = GNUNET_new_array (*buflen, unsigned char);
633 NULL == (ad->y = smc_init1 (ad->n))) 629 if (NULL == (ad->y = smc_init1 (ad->n)))
634 { 630 {
635 weprintf ("unable to alloc memory for key shares"); 631 weprintf ("unable to alloc memory for key shares");
636 return NULL; 632 return NULL;
@@ -701,8 +697,8 @@ smc_encrypt_bid (struct BRANDT_Auction *ad, size_t *buflen)
701 (sizeof (struct ec_mpi) * 2 + /* alpha, beta */ 697 (sizeof (struct ec_mpi) * 2 + /* alpha, beta */
702 sizeof (*proof3)) + 698 sizeof (*proof3)) +
703 sizeof (struct proof_2dle)); 699 sizeof (struct proof_2dle));
704 if (NULL == (cur = (ret = calloc (1, *buflen))) || 700 cur = ret = GNUNET_new_array (*buflen, unsigned char);
705 NULL == (ad->alpha = smc_init2 (ad->n, ad->k)) || 701 if (NULL == (ad->alpha = smc_init2 (ad->n, ad->k)) ||
706 NULL == (ad->beta = smc_init2 (ad->n, ad->k))) 702 NULL == (ad->beta = smc_init2 (ad->n, ad->k)))
707 { 703 {
708 weprintf ("unable to alloc memory for encrypted bids"); 704 weprintf ("unable to alloc memory for encrypted bids");
@@ -829,8 +825,8 @@ fp_pub_compute_outcome (struct BRANDT_Auction *ad, size_t *buflen)
829 brandt_assert (ad && buflen); 825 brandt_assert (ad && buflen);
830 826
831 *buflen = (ad->k * (sizeof (*gamma) + sizeof (*delta) + sizeof (*proof2))); 827 *buflen = (ad->k * (sizeof (*gamma) + sizeof (*delta) + sizeof (*proof2)));
832 if (NULL == (cur = (ret = calloc (1, *buflen))) || 828 cur = ret = GNUNET_new_array (*buflen, unsigned char);
833 NULL == (ad->gamma2 = smc_init2 (ad->n, ad->k)) || 829 if (NULL == (ad->gamma2 = smc_init2 (ad->n, ad->k)) ||
834 NULL == (ad->delta2 = smc_init2 (ad->n, ad->k)) || 830 NULL == (ad->delta2 = smc_init2 (ad->n, ad->k)) ||
835 NULL == (ad->tmpa1 = smc_init1 (ad->k)) || 831 NULL == (ad->tmpa1 = smc_init1 (ad->k)) ||
836 NULL == (ad->tmpb1 = smc_init1 (ad->k))) 832 NULL == (ad->tmpb1 = smc_init1 (ad->k)))
@@ -1018,8 +1014,8 @@ fp_pub_decrypt_outcome (struct BRANDT_Auction *ad, size_t *buflen)
1018 brandt_assert (ad && buflen); 1014 brandt_assert (ad && buflen);
1019 1015
1020 *buflen = (ad->k * (sizeof (*phi) + sizeof (*proof2))); 1016 *buflen = (ad->k * (sizeof (*phi) + sizeof (*proof2)));
1021 if (NULL == (cur = (ret = calloc (1, *buflen))) || 1017 cur = ret = GNUNET_new_array (*buflen, unsigned char);
1022 NULL == (ad->phi2 = smc_init2 (ad->n, ad->k))) 1018 if (NULL == (ad->phi2 = smc_init2 (ad->n, ad->k)))
1023 { 1019 {
1024 weprintf ("unable to alloc memory for first price outcome decryption"); 1020 weprintf ("unable to alloc memory for first price outcome decryption");
1025 return NULL; 1021 return NULL;
@@ -1171,8 +1167,8 @@ fp_priv_compute_outcome (struct BRANDT_Auction *ad, size_t *buflen)
1171 1167
1172 *buflen = (ad->n * ad->k * /* nk * (gamma, delta, proof2) */ 1168 *buflen = (ad->n * ad->k * /* nk * (gamma, delta, proof2) */
1173 (sizeof (*gamma) + sizeof (*delta) + sizeof (*proof2))); 1169 (sizeof (*gamma) + sizeof (*delta) + sizeof (*proof2)));
1174 if (NULL == (cur = (ret = calloc (1, *buflen))) || 1170 cur = ret = GNUNET_new_array (*buflen, unsigned char);
1175 NULL == (ad->gamma3 = smc_init3 (ad->n, ad->n, ad->k)) || 1171 if (NULL == (ad->gamma3 = smc_init3 (ad->n, ad->n, ad->k)) ||
1176 NULL == (ad->delta3 = smc_init3 (ad->n, ad->n, ad->k))) 1172 NULL == (ad->delta3 = smc_init3 (ad->n, ad->n, ad->k)))
1177 { 1173 {
1178 weprintf ("unable to alloc memory for first price outcome computation"); 1174 weprintf ("unable to alloc memory for first price outcome computation");
@@ -1363,8 +1359,8 @@ fp_priv_decrypt_outcome (struct BRANDT_Auction *ad, size_t *buflen)
1363 brandt_assert (ad && buflen); 1359 brandt_assert (ad && buflen);
1364 1360
1365 *buflen = (ad->n * ad->k * (sizeof (*phi) + sizeof (*proof2))); 1361 *buflen = (ad->n * ad->k * (sizeof (*phi) + sizeof (*proof2)));
1366 if (NULL == (cur = (ret = calloc (1, *buflen))) || 1362 cur = ret = GNUNET_new_array (*buflen, unsigned char);
1367 NULL == (ad->phi3 = smc_init3 (ad->n, ad->n, ad->k))) 1363 if (NULL == (ad->phi3 = smc_init3 (ad->n, ad->n, ad->k)))
1368 { 1364 {
1369 weprintf ("unable to alloc memory for first price outcome decryption"); 1365 weprintf ("unable to alloc memory for first price outcome decryption");
1370 return NULL; 1366 return NULL;