2016-06-12 01:14:56 +02:00
|
|
|
/* 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 crypto.h
|
|
|
|
* @brief Interface of the crypto primitives.
|
2016-06-22 23:18:46 +02:00
|
|
|
* @author Markus Teich
|
2016-06-12 01:14:56 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _BRANDT_CRYPTO_H
|
|
|
|
#define _BRANDT_CRYPTO_H
|
|
|
|
|
|
|
|
#include <gcrypt.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
2016-06-20 00:47:20 +02:00
|
|
|
#include "internals.h"
|
|
|
|
|
2016-06-12 20:52:22 +02:00
|
|
|
void brandt_crypto_init ();
|
|
|
|
|
2016-06-12 01:14:56 +02:00
|
|
|
|
|
|
|
/* --- HASHING --- */
|
|
|
|
|
|
|
|
struct brandt_hash_code {
|
|
|
|
uint32_t bits[512 / 8 / sizeof (uint32_t)]; /* = 16 */
|
|
|
|
};
|
|
|
|
|
|
|
|
void brandt_hash (const void *block, size_t size, struct brandt_hash_code *ret);
|
|
|
|
|
|
|
|
|
2016-06-12 20:52:22 +02:00
|
|
|
/* --- EC --- */
|
2016-06-12 01:14:56 +02:00
|
|
|
|
2016-06-21 00:20:47 +02:00
|
|
|
/* used for serialized mpis and serialized curve points (they are the same size
|
|
|
|
* when compressed) */
|
|
|
|
struct ec_mpi {
|
2016-06-19 22:37:31 +02:00
|
|
|
unsigned char data[256 / 8];
|
|
|
|
};
|
|
|
|
|
|
|
|
int ec_point_cmp (const gcry_mpi_point_t a, const gcry_mpi_point_t b);
|
|
|
|
void ec_skey_create (gcry_mpi_t skey);
|
|
|
|
void ec_keypair_create (gcry_mpi_point_t pkey, gcry_mpi_t skey);
|
|
|
|
void ec_keypair_create_base (gcry_mpi_point_t pkey,
|
|
|
|
gcry_mpi_t skey,
|
|
|
|
const gcry_mpi_point_t base);
|
|
|
|
|
|
|
|
|
|
|
|
/* --- Zero knowledge proofs --- */
|
|
|
|
|
2016-06-21 16:12:57 +02:00
|
|
|
struct proof_dl {
|
|
|
|
struct ec_mpi r;
|
|
|
|
struct ec_mpi a;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct proof_2dle {
|
|
|
|
struct ec_mpi r;
|
|
|
|
struct ec_mpi a;
|
|
|
|
struct ec_mpi b;
|
|
|
|
};
|
|
|
|
|
2016-06-21 23:06:15 +02:00
|
|
|
struct proof_0og {
|
|
|
|
struct ec_mpi a1;
|
|
|
|
struct ec_mpi a2;
|
|
|
|
struct ec_mpi b1;
|
|
|
|
struct ec_mpi b2;
|
|
|
|
struct ec_mpi d1;
|
|
|
|
struct ec_mpi d2;
|
|
|
|
struct ec_mpi r1;
|
|
|
|
struct ec_mpi r2;
|
|
|
|
};
|
|
|
|
|
2016-06-22 02:05:00 +02:00
|
|
|
void smc_zkp_dl (gcry_mpi_point_t v,
|
|
|
|
const gcry_mpi_t x,
|
|
|
|
struct proof_dl *proof);
|
2016-06-19 22:37:31 +02:00
|
|
|
int smc_zkp_dl_check (const gcry_mpi_point_t v,
|
2016-06-21 23:06:15 +02:00
|
|
|
const struct proof_dl *proof);
|
2016-06-19 22:37:31 +02:00
|
|
|
|
|
|
|
void smc_zkp_2dle (const gcry_mpi_point_t v,
|
|
|
|
const gcry_mpi_point_t w,
|
|
|
|
const gcry_mpi_point_t g1,
|
|
|
|
const gcry_mpi_point_t g2,
|
|
|
|
const gcry_mpi_t x,
|
2016-06-21 23:06:15 +02:00
|
|
|
struct proof_2dle *proof);
|
|
|
|
int smc_zkp_2dle_check (const gcry_mpi_point_t v,
|
|
|
|
const gcry_mpi_point_t w,
|
|
|
|
const gcry_mpi_point_t g1,
|
|
|
|
const gcry_mpi_point_t g2,
|
|
|
|
const struct proof_2dle *proof);
|
|
|
|
|
|
|
|
void smc_zkp_0og (int m_is_gen,
|
2016-06-19 22:37:31 +02:00
|
|
|
const gcry_mpi_point_t y,
|
2016-06-21 23:06:15 +02:00
|
|
|
gcry_mpi_t r,
|
|
|
|
gcry_mpi_point_t alpha,
|
2016-06-19 22:37:31 +02:00
|
|
|
gcry_mpi_point_t beta,
|
2016-06-21 23:06:15 +02:00
|
|
|
struct proof_0og *proof);
|
|
|
|
int smc_zkp_0og_check (const gcry_mpi_point_t y,
|
|
|
|
const gcry_mpi_point_t alpha,
|
2016-06-19 22:37:31 +02:00
|
|
|
const gcry_mpi_point_t beta,
|
2016-06-21 23:06:15 +02:00
|
|
|
const struct proof_0og *proof);
|
2016-06-12 01:14:56 +02:00
|
|
|
|
2016-06-20 00:47:20 +02:00
|
|
|
/* --- Protocol implementation --- */
|
|
|
|
|
2016-06-22 14:22:52 +02:00
|
|
|
unsigned char *smc_gen_keyshare (struct AuctionData *ad, size_t *buflen);
|
2016-06-22 14:25:48 +02:00
|
|
|
int smc_recv_keyshare (struct AuctionData *ad,
|
|
|
|
unsigned char *buf,
|
|
|
|
size_t buflen,
|
|
|
|
uint16_t sender_index);
|
|
|
|
|
|
|
|
unsigned char *smc_encrypt_bid (struct AuctionData *ad, size_t *buflen);
|
|
|
|
int smc_recv_encrypted_bid (struct AuctionData *ad,
|
|
|
|
unsigned char *buf,
|
|
|
|
size_t buflen,
|
|
|
|
uint16_t sender_index);
|
2016-06-20 00:47:20 +02:00
|
|
|
|
2016-06-28 16:29:18 +02:00
|
|
|
unsigned char *smc_compute_outcome (struct AuctionData *ad, size_t *buflen);
|
|
|
|
int smc_recv_outcome (struct AuctionData *ad,
|
|
|
|
unsigned char *buf,
|
|
|
|
size_t buflen,
|
|
|
|
uint16_t sender);
|
2016-06-12 01:14:56 +02:00
|
|
|
#endif /* ifndef _BRANDT_CRYPTO_H */
|