This commit is contained in:
Markus Teich 2016-08-03 12:26:51 +02:00
parent 3dea4b69f5
commit 342d3729df

142
crypto.c
View File

@ -58,17 +58,17 @@ struct zkp_challenge_0og {
};
static gcry_ctx_t ec_ctx;
static gcry_mpi_point_t ec_gen;
static gcry_mpi_point_t ec_zero;
static gcry_mpi_t ec_n;
static gcry_ctx_t ec_ctx;
static gcry_mpi_point_t ec_gen;
static gcry_mpi_point_t ec_zero;
static gcry_mpi_t ec_n;
static struct GNUNET_CRYPTO_EccDlogContext *ec_dlogctx;
/**
* brandt_crypto_init initializes the crypto system and must be called before
* any other function from this file.
*
*
* @param[in] dlogctx Pointer to the prepared dlog context.
*/
void
@ -648,9 +648,9 @@ smc_gen_keyshare (struct BRANDT_Auction *ad, size_t *buflen)
int
smc_recv_keyshare (struct BRANDT_Auction *ad,
const unsigned char *buf,
size_t buflen,
uint16_t sender)
const unsigned char *buf,
size_t buflen,
uint16_t sender)
{
int ret = 0;
struct proof_dl *proof1;
@ -740,16 +740,16 @@ smc_encrypt_bid (struct BRANDT_Auction *ad, size_t *buflen)
int
smc_recv_encrypted_bid (struct BRANDT_Auction *ad,
const unsigned char *buf,
size_t buflen,
uint16_t sender)
const unsigned char *buf,
size_t buflen,
uint16_t sender)
{
int ret = 0;
const unsigned char *cur = buf;
struct proof_0og *proof3;
gcry_mpi_point_t **ct; /* ciphertexts */
gcry_mpi_point_t alpha_sum = gcry_mpi_point_new (0);
gcry_mpi_point_t beta_sum = gcry_mpi_point_new (0);
int ret = 0;
const unsigned char *cur = buf;
struct proof_0og *proof3;
gcry_mpi_point_t **ct; /* ciphertexts */
gcry_mpi_point_t alpha_sum = gcry_mpi_point_new (0);
gcry_mpi_point_t beta_sum = gcry_mpi_point_new (0);
brandt_assert (ad && buf);
@ -944,15 +944,15 @@ fp_pub_compute_outcome (struct BRANDT_Auction *ad, size_t *buflen)
int
fp_pub_recv_outcome (struct BRANDT_Auction *ad,
const unsigned char *buf,
size_t buflen,
uint16_t sender)
const unsigned char *buf,
size_t buflen,
uint16_t sender)
{
int ret = 0;
const unsigned char *cur = buf;
struct proof_2dle *proof2;
gcry_mpi_point_t gamma = gcry_mpi_point_new (0);
gcry_mpi_point_t delta = gcry_mpi_point_new (0);
int ret = 0;
const unsigned char *cur = buf;
struct proof_2dle *proof2;
gcry_mpi_point_t gamma = gcry_mpi_point_new (0);
gcry_mpi_point_t delta = gcry_mpi_point_new (0);
brandt_assert (ad && buf);
@ -1058,14 +1058,14 @@ fp_pub_decrypt_outcome (struct BRANDT_Auction *ad, size_t *buflen)
int
fp_pub_recv_decryption (struct BRANDT_Auction *ad,
const unsigned char *buf,
size_t buflen,
uint16_t sender)
const unsigned char *buf,
size_t buflen,
uint16_t sender)
{
int ret = 0;
const unsigned char *cur = buf;
struct proof_2dle *proof2;
gcry_mpi_point_t phi = gcry_mpi_point_new (0);
int ret = 0;
const unsigned char *cur = buf;
struct proof_2dle *proof2;
gcry_mpi_point_t phi = gcry_mpi_point_new (0);
brandt_assert (ad && buf);
@ -1296,15 +1296,15 @@ fp_priv_compute_outcome (struct BRANDT_Auction *ad, size_t *buflen)
int
fp_priv_recv_outcome (struct BRANDT_Auction *ad,
const unsigned char *buf,
size_t buflen,
uint16_t sender)
const unsigned char *buf,
size_t buflen,
uint16_t sender)
{
int ret = 0;
const unsigned char *cur = buf;
struct proof_2dle *proof2;
gcry_mpi_point_t gamma = gcry_mpi_point_new (0);
gcry_mpi_point_t delta = gcry_mpi_point_new (0);
int ret = 0;
const unsigned char *cur = buf;
struct proof_2dle *proof2;
gcry_mpi_point_t gamma = gcry_mpi_point_new (0);
gcry_mpi_point_t delta = gcry_mpi_point_new (0);
brandt_assert (ad && buf);
@ -1406,14 +1406,14 @@ fp_priv_decrypt_outcome (struct BRANDT_Auction *ad, size_t *buflen)
int
fp_priv_recv_decryption (struct BRANDT_Auction *ad,
const unsigned char *buf,
size_t buflen,
uint16_t sender)
const unsigned char *buf,
size_t buflen,
uint16_t sender)
{
int ret = 0;
const unsigned char *cur = buf;
struct proof_2dle *proof2;
gcry_mpi_point_t phi = gcry_mpi_point_new (0);
int ret = 0;
const unsigned char *cur = buf;
struct proof_2dle *proof2;
gcry_mpi_point_t phi = gcry_mpi_point_new (0);
brandt_assert (ad && buf);
@ -1511,7 +1511,13 @@ smc_zkp_dl (gcry_mpi_point_t v,
ec_point_serialize (&challenge.g, ec_gen);
ec_point_serialize (&challenge.v, v);
ec_point_serialize (&challenge.a, a);
GNUNET_CRYPTO_kdf_mod_mpi (&c, ec_n, NULL, 0, &challenge, sizeof (challenge), "libbrandt zkp dl");
GNUNET_CRYPTO_kdf_mod_mpi (&c,
ec_n,
NULL,
0,
&challenge,
sizeof (challenge),
"libbrandt zkp dl");
/* r = z + cx */
gcry_mpi_mulm (r, c, x, ec_n);
@ -1554,7 +1560,13 @@ smc_zkp_dl_check (const gcry_mpi_point_t v,
ec_point_serialize (&challenge.g, ec_gen);
ec_point_serialize (&challenge.v, v);
ec_point_serialize (&challenge.a, a);
GNUNET_CRYPTO_kdf_mod_mpi (&c, ec_n, NULL, 0, &challenge, sizeof (challenge), "libbrandt zkp dl");
GNUNET_CRYPTO_kdf_mod_mpi (&c,
ec_n,
NULL,
0,
&challenge,
sizeof (challenge),
"libbrandt zkp dl");
/* rg =? a + cv */
gcry_mpi_ec_mul (left, r, ec_gen, ec_ctx);
@ -1632,7 +1644,13 @@ smc_zkp_2dle (gcry_mpi_point_t v,
ec_point_serialize (&challenge.w, rw);
ec_point_serialize (&challenge.a, a);
ec_point_serialize (&challenge.b, b);
GNUNET_CRYPTO_kdf_mod_mpi (&c, ec_n, NULL, 0, &challenge, sizeof (challenge), "libbrandt zkp 2dle");
GNUNET_CRYPTO_kdf_mod_mpi (&c,
ec_n,
NULL,
0,
&challenge,
sizeof (challenge),
"libbrandt zkp 2dle");
/* r = z + cx */
gcry_mpi_mulm (r, c, rx, ec_n);
@ -1694,7 +1712,13 @@ smc_zkp_2dle_check (const gcry_mpi_point_t v,
ec_point_serialize (&challenge.w, w);
ec_point_serialize (&challenge.a, a);
ec_point_serialize (&challenge.b, b);
GNUNET_CRYPTO_kdf_mod_mpi (&c, ec_n, NULL, 0, &challenge, sizeof (challenge), "libbrandt zkp 2dle");
GNUNET_CRYPTO_kdf_mod_mpi (&c,
ec_n,
NULL,
0,
&challenge,
sizeof (challenge),
"libbrandt zkp 2dle");
/* r*g1 =? a + cv */
gcry_mpi_ec_mul (left, r, g1, ec_ctx);
@ -1825,7 +1849,13 @@ smc_zkp_0og (int m_is_gen,
ec_point_serialize (&challenge.a2, a2);
ec_point_serialize (&challenge.b1, b1);
ec_point_serialize (&challenge.b2, b2);
GNUNET_CRYPTO_kdf_mod_mpi (&c, ec_n, NULL, 0, &challenge, sizeof (challenge), "libbrandt zkp 0og");
GNUNET_CRYPTO_kdf_mod_mpi (&c,
ec_n,
NULL,
0,
&challenge,
sizeof (challenge),
"libbrandt zkp 0og");
if (!m_is_gen)
{ /* m == 0 */
@ -1918,7 +1948,13 @@ smc_zkp_0og_check (const gcry_mpi_point_t y,
ec_point_serialize (&challenge.a2, a2);
ec_point_serialize (&challenge.b1, b1);
ec_point_serialize (&challenge.b2, b2);
GNUNET_CRYPTO_kdf_mod_mpi (&c, ec_n, NULL, 0, &challenge, sizeof (challenge), "libbrandt zkp 0og");
GNUNET_CRYPTO_kdf_mod_mpi (&c,
ec_n,
NULL,
0,
&challenge,
sizeof (challenge),
"libbrandt zkp 0og");
/* c == d1 + d2 */
gcry_mpi_addm (sum, d1, d2, ec_n);