low level implementation of round1
This commit is contained in:
parent
9938f3ad20
commit
ad52777275
46
internals.h
Normal file
46
internals.h
Normal file
@ -0,0 +1,46 @@
|
||||
/* 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 internals.h
|
||||
* @brief This header contains library internal structs.
|
||||
*/
|
||||
|
||||
#ifndef _BRANDT_INTERNALS_H
|
||||
#define _BRANDT_INTERNALS_H
|
||||
|
||||
#include <pari/pari.h>
|
||||
|
||||
struct AuctionData {
|
||||
GEN p; /** The "safe prime" p */
|
||||
GEN q; /** The prime @f$q = (p - 1) / 2@f$. */
|
||||
GEN g; /** The generator of @f$\mathbb{G}_q@f$ */
|
||||
uint16_t n; /** The amount of bidders/agents */
|
||||
uint16_t k; /** The amount of possible prices */
|
||||
|
||||
GEN x; /** Own private additive key share */
|
||||
GEN y; /** Own public multiplicative key share */
|
||||
GEN Y; /** Shared public key */
|
||||
|
||||
GEN m; /** Additive share of random exponents, type: Matrix(n,k) */
|
||||
GEN r; /** Key share exponent, type: Vector(k) */
|
||||
GEN b; /** Own bid, type: Vector(k) */
|
||||
|
||||
GEN alpha; /** Own alpha, type: Vector(k) */
|
||||
GEN beta; /** Own beta, type: Vector(k) */
|
||||
};
|
||||
|
||||
#endif
|
72
smc.c
72
smc.c
@ -19,27 +19,71 @@
|
||||
* @brief Implementation of the smc primitives.
|
||||
*/
|
||||
|
||||
#include "util.h"
|
||||
|
||||
#include <pari/pari.h>
|
||||
|
||||
GEN
|
||||
smc_hextodec (char *s) /* int */
|
||||
{
|
||||
unsigned int i, tmp;
|
||||
size_t i;
|
||||
char c;
|
||||
pari_sp ltop = avma;
|
||||
GEN ret = gen_0; /* int */
|
||||
GEN v = gtovecsmall (strtoGENstr (s)); /* vecsmall */
|
||||
|
||||
for (i = 1; i < lg (v); ++i)
|
||||
for (i = 0; i < strlen (s); i++)
|
||||
{
|
||||
///TODO: scanf instead of if
|
||||
if ((v[i] >= '0') && (v[i] <= '9'))
|
||||
tmp = v[i] - '0';
|
||||
else if ((v[i] >= 'a') && (v[i] <= 'f'))
|
||||
tmp = v[i] + 10 - 'a';
|
||||
else if ((v[i] >= 'A') && (v[i] <= 'F'))
|
||||
tmp = v[i] + 10 - 'A';
|
||||
else
|
||||
pari_err (e_MISC, "invalid input format");
|
||||
ret = addis (shifti (ret, 4), tmp);
|
||||
errno = 0;
|
||||
if (1 != sscanf (&s[i], "%1hhx", &c))
|
||||
{
|
||||
brandt_eprintf ("failed to parse hex (\"%s\") to decimal:", s);
|
||||
return NULL;
|
||||
}
|
||||
ret = addis (shifti (ret, 4), c);
|
||||
}
|
||||
return ret;
|
||||
return gerepilecopy (ltop, ret);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
smc_genbid (AuctionData *ad, uint16_t bid)
|
||||
{
|
||||
uint16_t j;
|
||||
pari_sp ltop = avma;
|
||||
GEN ret = cgetg (itos (ad->k)+1, t_VEC); /* vec */
|
||||
|
||||
for (j = 1; j <= ad->k; j++)
|
||||
{
|
||||
gel (ret, j) = gpowgs (ad->g, bid == j);
|
||||
}
|
||||
ad->b = gerepilecopy (ltop, ret);
|
||||
}
|
||||
|
||||
void
|
||||
smc_genalpha (AuctionData *ad)
|
||||
{
|
||||
uint16_t j;
|
||||
pari_sp ltop = avma;
|
||||
GEN ret = cgetg (ad->k+1, t_VEC);
|
||||
|
||||
for (j = 1; j <= ad->k; ++j)
|
||||
{
|
||||
gel (ret, j) = gmul (gel (ad->b, j), gpowgi (ad->y, gel (ad->r, j)));
|
||||
}
|
||||
ab->alpha = gerepilecopy (ltop, ret);
|
||||
}
|
||||
|
||||
void
|
||||
smc_genbeta (AuctionData *ad)
|
||||
{
|
||||
uint16_t j;
|
||||
pari_sp ltop = avma;
|
||||
GEN ret = cgetg (ad->k+1, t_VEC);
|
||||
|
||||
for (j = 1; j <= ad->k; ++j)
|
||||
{
|
||||
gel (ret, j) = gpowgi (ad->g, gel (ad->r, j));
|
||||
}
|
||||
ab->beta = gerepilecopy (ltop, ret);
|
||||
}
|
||||
|
||||
|
18
smc.gp
18
smc.gp
@ -17,15 +17,19 @@ smc_hextodec(s:str) =
|
||||
ret;
|
||||
}
|
||||
|
||||
smc_genfield(p:int, g)=
|
||||
smc_genbid(k:small, bid:small, g)=
|
||||
{
|
||||
local(q:int);
|
||||
q = (p - 1) / 2;
|
||||
[Mod(g^2, p), q];
|
||||
vector(k,j,g^(bid==j));
|
||||
}
|
||||
|
||||
smc_genkeypair(field:vec)=
|
||||
smc_genalpha(k:small, b:vec, r:vec, y)=
|
||||
{
|
||||
local(x:int=random(field[2]));
|
||||
[x, field[1]^x];
|
||||
vector(k, j, b[j]*y^r[j]);
|
||||
}
|
||||
|
||||
smc_genbeta(k:small, r:vec, g)=
|
||||
{
|
||||
vector(k, j, g^r[j]);
|
||||
}
|
||||
|
||||
|
||||
|
25
util.h
Normal file
25
util.h
Normal file
@ -0,0 +1,25 @@
|
||||
/* This file is part of libgotr.
|
||||
* (C) 2014-2015 Markus Teich, Jannik Theiß
|
||||
*
|
||||
* libgotr is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published
|
||||
* by the Free Software Foundation; either version 3, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* libgotr 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with libgotr; see the file LICENSE. If not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef _BRANDT_UTIL_H
|
||||
#define _BRANDT_UTIL_H
|
||||
|
||||
void brandt_eprintf(const char *format, ...);
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user