aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Teich <markus.teich@stusta.mhn.de>2016-06-08 15:40:22 +0200
committerMarkus Teich <markus.teich@stusta.mhn.de>2016-06-08 15:40:22 +0200
commitd4360a4f8b7d29aedf6f9af0a878a9060d434ea2 (patch)
tree40836708043afa8fb7c1a320e86e652fec44dd14
parent8cf93a6c188d6a726bce46aa987c11611cf2baac (diff)
downloadlibbrandt-d4360a4f8b7d29aedf6f9af0a878a9060d434ea2.tar.gz
libbrandt-d4360a4f8b7d29aedf6f9af0a878a9060d434ea2.zip
fix typos and types
-rw-r--r--gp-scripts/m+1stPrice91
-rw-r--r--smc.c14
2 files changed, 99 insertions, 6 deletions
diff --git a/gp-scripts/m+1stPrice b/gp-scripts/m+1stPrice
new file mode 100644
index 0000000..8407e96
--- /dev/null
+++ b/gp-scripts/m+1stPrice
@@ -0,0 +1,91 @@
1\\ From: "Fully private auctions in a constant number of rounds" (2003) by Felix Brandt pages 9-10
2
3
4\\\\\\\\\\\\
5\\ Adapt the following values to your needs
6\\\\\\\\\\\\
7
8\\ amount of bidders
9n = 2^3
10\\ amount of possible prices
11k = 2^7
12\\ randomize bids (change to something static, if you like)
13bid = vector(n,i,random(k)+1)
14\\bid = vector(n,i,n-i+1) \\ first bidder wins
15\\bid = vector(n,i,i) \\ last bidder wins
16\\bid = vector(n,i,(i+1)%2) \\ second bidder wins (with ties)
17
18\\ prime finite field setup (result may be ambiguous if your prime is too small, 4*n*k seems to work fine)
19q = prime(4*n*k)
20
21\\\\\\\\\\\\
22\\ SETUP
23\\\\\\\\\\\\
24
25\\ p not needed? wat?
26\\p = 47
27
28\\ get generator / primitive element for Z_q
29var = 'x \\ copy pasta from internet
30pe=ffgen(minpoly(ffprimroot(ffgen(ffinit(q,1))),var),var) \\ get primitive element
311/(fforder(pe) == q-1) \\ error out, if ord(pe) is wrong
32g = Mod(eval(Str(pe)), q) \\ dirty hack to convert t_FFELEM to t_INT
33
34\\\\\\\\\\\\
35\\ PROLOG
36\\\\\\\\\\\\
37
38\\ private keys of agents
39x = vector(n,i,random(q))
40\\ public keyshares of agents
41yshares = vector(n,i,g^x[i])
42\\ shared public key
43y = prod(X=1,n,yshares[X])
44
45\\ first index level = owning agent id (additive share)
46\\ second index level = agent id, price id
47m = vector(n,i,matrix(n,k,a,b,random(q)))
48
49\\ index = owning agent id, price id
50r = matrix(n,k,i,j,random(q))
51\\ bid matrix
52b = matrix(n,k,i,j,g^(bid[i]==j))
53
54\\\\\\\\\\\\
55\\ ROUND1
56\\\\\\\\\\\\
57
58\\ encrypted bids
59alpha = matrix(n,k,i,j, b[i,j]*y^r[i,j])
60beta = matrix(n,k,i,j, g^r[i,j])
61
62\\\\\\\\\\\\
63\\ ROUND2
64\\\\\\\\\\\\
65
66\\ multiplicative shares
67\\ first index level = owning agent id (multiplicative share)
68\\ second index level = agent id, price id
69Gamma = vector(n,a,matrix(n,k,i,j, ( prod(h=1,n,prod(d=j+1,k,alpha[h,d])) * prod(d=1,j-1,alpha[i,d]) * prod(h=1,i-1,alpha[h,j]) )^m[a][i,j] ))
70Delta = vector(n,a,matrix(n,k,i,j, ( prod(h=1,n,prod(d=j+1,k, beta[h,d])) * prod(d=1,j-1, beta[i,d]) * prod(h=1,i-1, beta[h,j]) )^m[a][i,j] ))
71
72\\\\\\\\\\\\
73\\ ROUND3
74\\\\\\\\\\\\
75
76\\ multiplicative shares (decryption)
77\\ first index level = owning agent id (multiplicative share)
78\\ second index level = agent id, price id
79Phi = vector(n,a,matrix(n,k,i,j, prod(h=1,n,Delta[h][i,j])^x[a] ))
80
81\\\\\\\\\\\\
82\\ EPILOG
83\\\\\\\\\\\\
84
85\\ winner matrix
86v = matrix(n,k,a,j, prod(i=1,n,Gamma[i][a,j]) / prod(i=1,n,Phi[i][a,j]) )
87
88vi = lift(v)
89
90print("bids are: ", bid)
91for(X=1,n, if(vecmin(vi[X,])==1, print("And the winner is ", X) ))
diff --git a/smc.c b/smc.c
index 02dfafc..399f031 100644
--- a/smc.c
+++ b/smc.c
@@ -24,7 +24,7 @@
24#include <pari/pari.h> 24#include <pari/pari.h>
25 25
26GEN 26GEN
27smc_hextodec (char *s) /* int */ 27smc_hextodec (const char *s) /* int */
28{ 28{
29 size_t i; 29 size_t i;
30 char c; 30 char c;
@@ -46,7 +46,7 @@ smc_hextodec (char *s) /* int */
46 46
47 47
48void 48void
49smc_genbid (AuctionData *ad, uint16_t bid) 49smc_genbid (struct AuctionData *ad, uint16_t bid)
50{ 50{
51 uint16_t j; 51 uint16_t j;
52 pari_sp ltop = avma; 52 pari_sp ltop = avma;
@@ -59,8 +59,9 @@ smc_genbid (AuctionData *ad, uint16_t bid)
59 ad->b = gerepilecopy (ltop, ret); 59 ad->b = gerepilecopy (ltop, ret);
60} 60}
61 61
62
62void 63void
63smc_genalpha (AuctionData *ad) 64smc_genalpha (struct AuctionData *ad)
64{ 65{
65 uint16_t j; 66 uint16_t j;
66 pari_sp ltop = avma; 67 pari_sp ltop = avma;
@@ -70,11 +71,12 @@ smc_genalpha (AuctionData *ad)
70 { 71 {
71 gel (ret, j) = gmul (gel (ad->b, j), gpowgi (ad->y, gel (ad->r, j))); 72 gel (ret, j) = gmul (gel (ad->b, j), gpowgi (ad->y, gel (ad->r, j)));
72 } 73 }
73 ab->alpha = gerepilecopy (ltop, ret); 74 ad->alpha = gerepilecopy (ltop, ret);
74} 75}
75 76
77
76void 78void
77smc_genbeta (AuctionData *ad) 79smc_genbeta (struct AuctionData *ad)
78{ 80{
79 uint16_t j; 81 uint16_t j;
80 pari_sp ltop = avma; 82 pari_sp ltop = avma;
@@ -84,6 +86,6 @@ smc_genbeta (AuctionData *ad)
84 { 86 {
85 gel (ret, j) = gpowgi (ad->g, gel (ad->r, j)); 87 gel (ret, j) = gpowgi (ad->g, gel (ad->r, j));
86 } 88 }
87 ab->beta = gerepilecopy (ltop, ret); 89 ad->beta = gerepilecopy (ltop, ret);
88} 90}
89 91