random fixes
This commit is contained in:
parent
a9e4574c49
commit
0fc7fb86b8
2
brandt.c
2
brandt.c
@ -17,6 +17,7 @@
|
|||||||
/**
|
/**
|
||||||
* @file brandt.c
|
* @file brandt.c
|
||||||
* @brief \todo
|
* @brief \todo
|
||||||
|
* @author Markus Teich
|
||||||
*/
|
*/
|
||||||
#include <gcrypt.h>
|
#include <gcrypt.h>
|
||||||
|
|
||||||
@ -42,6 +43,5 @@ BRANDT_init ()
|
|||||||
gcry_strerror (err));
|
gcry_strerror (err));
|
||||||
|
|
||||||
gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);
|
gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);
|
||||||
brandt_rand_poll ();
|
|
||||||
brandt_crypto_init ();
|
brandt_crypto_init ();
|
||||||
}
|
}
|
||||||
|
1
brandt.h
1
brandt.h
@ -17,6 +17,7 @@
|
|||||||
/**
|
/**
|
||||||
* @file brandt.h
|
* @file brandt.h
|
||||||
* @brief This Header defines the external interface of libbrandt.
|
* @brief This Header defines the external interface of libbrandt.
|
||||||
|
* @author Markus Teich
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _BRANDT_BRANDT_H
|
#ifndef _BRANDT_BRANDT_H
|
||||||
|
55
crypto.c
55
crypto.c
@ -17,6 +17,7 @@
|
|||||||
/**
|
/**
|
||||||
* @file crypto.c
|
* @file crypto.c
|
||||||
* @brief Implementation of the crypto primitives.
|
* @brief Implementation of the crypto primitives.
|
||||||
|
* @author Markus Teich
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
@ -86,18 +87,6 @@ brandt_crypto_init ()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* --- RANDOM --- */
|
|
||||||
|
|
||||||
void
|
|
||||||
brandt_rand_poll ()
|
|
||||||
{
|
|
||||||
static unsigned char rand_amount = 255;
|
|
||||||
|
|
||||||
if (!(rand_amount--))
|
|
||||||
gcry_fast_random_poll ();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* --- HASHING --- */
|
/* --- HASHING --- */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -299,8 +288,11 @@ mpi_parse (gcry_mpi_t dst, const struct ec_mpi *src)
|
|||||||
gcry_mpi_t ret;
|
gcry_mpi_t ret;
|
||||||
gcry_error_t rc;
|
gcry_error_t rc;
|
||||||
|
|
||||||
rc = gcry_mpi_scan (&ret, GCRYMPI_FMT_USG,
|
rc = gcry_mpi_scan (&ret,
|
||||||
src, sizeof (struct ec_mpi), NULL);
|
GCRYMPI_FMT_USG,
|
||||||
|
src,
|
||||||
|
sizeof (struct ec_mpi),
|
||||||
|
NULL);
|
||||||
brandt_assert_gpgerr (rc);
|
brandt_assert_gpgerr (rc);
|
||||||
|
|
||||||
gcry_mpi_snatch (dst, ret);
|
gcry_mpi_snatch (dst, ret);
|
||||||
@ -369,6 +361,7 @@ ec_point_parse (gcry_mpi_point_t dst, const struct ec_mpi *src)
|
|||||||
brandt_assert (ret);
|
brandt_assert (ret);
|
||||||
gcry_ctx_release (ctx);
|
gcry_ctx_release (ctx);
|
||||||
gcry_mpi_ec_mul (dst, GCRYMPI_CONST_ONE, ret, ec_ctx);
|
gcry_mpi_ec_mul (dst, GCRYMPI_CONST_ONE, ret, ec_ctx);
|
||||||
|
gcry_mpi_point_release (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -382,7 +375,8 @@ ec_point_parse (gcry_mpi_point_t dst, const struct ec_mpi *src)
|
|||||||
static void
|
static void
|
||||||
smc_free2 (gcry_mpi_point_t **dst, uint16_t size1, uint16_t size2)
|
smc_free2 (gcry_mpi_point_t **dst, uint16_t size1, uint16_t size2)
|
||||||
{
|
{
|
||||||
uint16_t i, j;
|
uint16_t i;
|
||||||
|
uint16_t j;
|
||||||
|
|
||||||
if (NULL == dst)
|
if (NULL == dst)
|
||||||
return;
|
return;
|
||||||
@ -406,7 +400,8 @@ smc_free2 (gcry_mpi_point_t **dst, uint16_t size1, uint16_t size2)
|
|||||||
static gcry_mpi_point_t **
|
static gcry_mpi_point_t **
|
||||||
smc_init2 (uint16_t size1, uint16_t size2)
|
smc_init2 (uint16_t size1, uint16_t size2)
|
||||||
{
|
{
|
||||||
uint16_t i, j;
|
uint16_t i;
|
||||||
|
uint16_t j;
|
||||||
gcry_mpi_point_t **ret;
|
gcry_mpi_point_t **ret;
|
||||||
gcry_mpi_point_t *data;
|
gcry_mpi_point_t *data;
|
||||||
|
|
||||||
@ -449,7 +444,9 @@ smc_free3 (gcry_mpi_point_t ***dst,
|
|||||||
uint16_t size2,
|
uint16_t size2,
|
||||||
uint16_t size3)
|
uint16_t size3)
|
||||||
{
|
{
|
||||||
uint16_t i, j, k;
|
uint16_t i;
|
||||||
|
uint16_t j;
|
||||||
|
uint16_t k;
|
||||||
|
|
||||||
if (NULL == dst)
|
if (NULL == dst)
|
||||||
return;
|
return;
|
||||||
@ -475,7 +472,9 @@ smc_free3 (gcry_mpi_point_t ***dst,
|
|||||||
static gcry_mpi_point_t ***
|
static gcry_mpi_point_t ***
|
||||||
smc_init3 (uint16_t size1, uint16_t size2, uint16_t size3)
|
smc_init3 (uint16_t size1, uint16_t size2, uint16_t size3)
|
||||||
{
|
{
|
||||||
uint16_t i, j, k;
|
uint16_t i;
|
||||||
|
uint16_t j;
|
||||||
|
uint16_t k;
|
||||||
gcry_mpi_point_t ***ret;
|
gcry_mpi_point_t ***ret;
|
||||||
gcry_mpi_point_t **layer1;
|
gcry_mpi_point_t **layer1;
|
||||||
gcry_mpi_point_t *layer2;
|
gcry_mpi_point_t *layer2;
|
||||||
@ -667,8 +666,12 @@ smc_encrypt_bid (struct AuctionData *ad, size_t *buflen)
|
|||||||
for (j = 0; j < ad->k; j++)
|
for (j = 0; j < ad->k; j++)
|
||||||
{
|
{
|
||||||
proof3 = (struct proof_0og *)(cur + 2 * sizeof (struct ec_mpi));
|
proof3 = (struct proof_0og *)(cur + 2 * sizeof (struct ec_mpi));
|
||||||
smc_zkp_0og (j == ad->b, ad->Y, r_part,
|
smc_zkp_0og (j == ad->b,
|
||||||
ad->alpha[ad->i][j], ad->beta[ad->i][j], proof3);
|
ad->Y,
|
||||||
|
r_part,
|
||||||
|
ad->alpha[ad->i][j],
|
||||||
|
ad->beta[ad->i][j],
|
||||||
|
proof3);
|
||||||
ec_point_serialize ((struct ec_mpi *)cur, ad->alpha[ad->i][j]);
|
ec_point_serialize ((struct ec_mpi *)cur, ad->alpha[ad->i][j]);
|
||||||
ec_point_serialize (&((struct ec_mpi *)cur)[1], ad->beta[ad->i][j]);
|
ec_point_serialize (&((struct ec_mpi *)cur)[1], ad->beta[ad->i][j]);
|
||||||
gcry_mpi_addm (r_sum, r_sum, r_part, ec_n);
|
gcry_mpi_addm (r_sum, r_sum, r_part, ec_n);
|
||||||
@ -726,7 +729,10 @@ smc_recv_encrypted_bid (struct AuctionData *ad,
|
|||||||
}
|
}
|
||||||
|
|
||||||
gcry_mpi_ec_sub (alpha_sum, alpha_sum, ec_gen, ec_ctx);
|
gcry_mpi_ec_sub (alpha_sum, alpha_sum, ec_gen, ec_ctx);
|
||||||
if (smc_zkp_2dle_check (alpha_sum, beta_sum, ad->Y, ec_gen,
|
if (smc_zkp_2dle_check (alpha_sum,
|
||||||
|
beta_sum,
|
||||||
|
ad->Y,
|
||||||
|
ec_gen,
|
||||||
(struct proof_2dle *)cur))
|
(struct proof_2dle *)cur))
|
||||||
{
|
{
|
||||||
weprintf ("wrong zkp2 for alpha, beta received");
|
weprintf ("wrong zkp2 for alpha, beta received");
|
||||||
@ -757,7 +763,8 @@ quit:
|
|||||||
void
|
void
|
||||||
smc_compute_outcome (struct AuctionData *ad)
|
smc_compute_outcome (struct AuctionData *ad)
|
||||||
{
|
{
|
||||||
uint16_t i, j;
|
uint16_t i;
|
||||||
|
uint16_t j;
|
||||||
|
|
||||||
// create temporary table with partial sums
|
// create temporary table with partial sums
|
||||||
|
|
||||||
@ -900,8 +907,8 @@ smc_zkp_2dle (gcry_mpi_point_t v,
|
|||||||
gcry_mpi_t c = gcry_mpi_new (0);
|
gcry_mpi_t c = gcry_mpi_new (0);
|
||||||
gcry_mpi_t z = gcry_mpi_new (0);
|
gcry_mpi_t z = gcry_mpi_new (0);
|
||||||
|
|
||||||
rv = (NULL == v) ? rv = gcry_mpi_point_new (0) : v;
|
rv = (NULL == v) ? gcry_mpi_point_new (0) : v;
|
||||||
rw = (NULL == w) ? rw = gcry_mpi_point_new (0) : w;
|
rw = (NULL == w) ? gcry_mpi_point_new (0) : w;
|
||||||
|
|
||||||
/* v = x*g1 */
|
/* v = x*g1 */
|
||||||
gcry_mpi_ec_mul (rv, x, g1, ec_ctx);
|
gcry_mpi_ec_mul (rv, x, g1, ec_ctx);
|
||||||
|
6
crypto.h
6
crypto.h
@ -17,6 +17,7 @@
|
|||||||
/**
|
/**
|
||||||
* @file crypto.h
|
* @file crypto.h
|
||||||
* @brief Interface of the crypto primitives.
|
* @brief Interface of the crypto primitives.
|
||||||
|
* @author Markus Teich
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _BRANDT_CRYPTO_H
|
#ifndef _BRANDT_CRYPTO_H
|
||||||
@ -30,11 +31,6 @@
|
|||||||
void brandt_crypto_init ();
|
void brandt_crypto_init ();
|
||||||
|
|
||||||
|
|
||||||
/* --- RANDOM --- */
|
|
||||||
|
|
||||||
void brandt_rand_poll ();
|
|
||||||
|
|
||||||
|
|
||||||
/* --- HASHING --- */
|
/* --- HASHING --- */
|
||||||
|
|
||||||
struct brandt_hash_code {
|
struct brandt_hash_code {
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
/**
|
/**
|
||||||
* @file internals.h
|
* @file internals.h
|
||||||
* @brief This header contains library internal structs.
|
* @brief This header contains library internal structs.
|
||||||
|
* @author Markus Teich
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _BRANDT_INTERNALS_H
|
#ifndef _BRANDT_INTERNALS_H
|
||||||
|
1
test.h
1
test.h
@ -17,6 +17,7 @@
|
|||||||
/**
|
/**
|
||||||
* @file test.h
|
* @file test.h
|
||||||
* @brief Some helpers for running tests
|
* @brief Some helpers for running tests
|
||||||
|
* @author Markus Teich
|
||||||
*/
|
*/
|
||||||
#ifndef _BRANDT_TEST_H
|
#ifndef _BRANDT_TEST_H
|
||||||
#define _BRANDT_TEST_H
|
#define _BRANDT_TEST_H
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
/**
|
/**
|
||||||
* @file test_crypto.c
|
* @file test_crypto.c
|
||||||
* @brief testing crypto and smc functions.
|
* @brief testing crypto and smc functions.
|
||||||
|
* @author Markus Teich
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* For testing static functions and variables we include the whole source */
|
/* For testing static functions and variables we include the whole source */
|
||||||
@ -259,10 +260,13 @@ test_round1 ()
|
|||||||
void
|
void
|
||||||
cleanup_auction_data ()
|
cleanup_auction_data ()
|
||||||
{
|
{
|
||||||
uint16_t i;
|
for (uint16_t i = 0; i < bidders; i++)
|
||||||
|
|
||||||
for (i = 0; i < bidders; i++)
|
|
||||||
{
|
{
|
||||||
|
for (uint16_t h = 0; h < bidders; h++)
|
||||||
|
gcry_mpi_point_release (ad[i].y[h]);
|
||||||
|
|
||||||
|
gcry_mpi_point_release (ad[i].Y);
|
||||||
|
gcry_mpi_release (ad[i].x);
|
||||||
free (ad[i].y);
|
free (ad[i].y);
|
||||||
smc_free2 (ad[i].alpha, ad[i].n, ad[i].k);
|
smc_free2 (ad[i].alpha, ad[i].n, ad[i].k);
|
||||||
smc_free2 (ad[i].beta, ad[i].n, ad[i].k);
|
smc_free2 (ad[i].beta, ad[i].n, ad[i].k);
|
||||||
|
1
util.c
1
util.c
@ -17,6 +17,7 @@
|
|||||||
/**
|
/**
|
||||||
* @file util.c
|
* @file util.c
|
||||||
* @brief \todo
|
* @brief \todo
|
||||||
|
* @author Markus Teich
|
||||||
*/
|
*/
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
22
util.h
22
util.h
@ -1,3 +1,25 @@
|
|||||||
|
/* This file is part of libbrandt.
|
||||||
|
* Copyright (C) 2016 GNUnet e.V.
|
||||||
|
*
|
||||||
|
* libbrandt 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 of the License, or (at your option) any later
|
||||||
|
* version.
|
||||||
|
*
|
||||||
|
* libbrandt 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.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with
|
||||||
|
* libbrandt. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file util.h
|
||||||
|
* @brief \todo
|
||||||
|
* @author Markus Teich
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef _BRANDT_UTIL_H
|
#ifndef _BRANDT_UTIL_H
|
||||||
#define _BRANDT_UTIL_H
|
#define _BRANDT_UTIL_H
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user