gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r24166 - gnunet-java/src/org/gnunet/voting


From: gnunet
Subject: [GNUnet-SVN] r24166 - gnunet-java/src/org/gnunet/voting
Date: Wed, 3 Oct 2012 23:15:16 +0200

Author: dold
Date: 2012-10-03 23:15:16 +0200 (Wed, 03 Oct 2012)
New Revision: 24166

Modified:
   gnunet-java/src/org/gnunet/voting/VotingSimulation.java
Log:
finished implementing cryptographic algorithms for voting

Modified: gnunet-java/src/org/gnunet/voting/VotingSimulation.java
===================================================================
--- gnunet-java/src/org/gnunet/voting/VotingSimulation.java     2012-10-03 
20:35:33 UTC (rev 24165)
+++ gnunet-java/src/org/gnunet/voting/VotingSimulation.java     2012-10-03 
21:15:16 UTC (rev 24166)
@@ -195,5 +195,145 @@
         }
 
 
+        simulateBallotZKP1(h, parameters, random);
+        simulateBallotZKP2(h, parameters, random);
+
+        final int voteCount = 25;
+        int result = 0;
+
+        Cyphertext votes[] = new Cyphertext[voteCount];
+        for (int i = 0; i < voteCount; ++i) {
+            if (random.nextBoolean()) {
+                votes[i] = parameters.encrypt(g, h, random);
+                result++;
+            } else {
+                votes[i] = parameters.encrypt(g.modInverse(p), h, random);
+                result--;
+            }
+        }
+
+        BigInteger votesX = BigInteger.ONE;
+        BigInteger votesY = BigInteger.ONE;
+        for (int i = 0; i < voteCount; ++i) {
+            votesX = votesX.multiply(votes[i].c1).mod(p);
+            votesY = votesY.multiply(votes[i].c2).mod(p);
+        }
+
+        // for convenice decrypted with the full private key, the above tests 
demonstrates that this
+        // is equally possible without revealing the private key
+        BigInteger resultG = votesY.multiply(votesX.modPow(x, 
p).modInverse(p)).mod(p);
+        int resultRestored = 0;
+        boolean success = false;
+
+        for (int l = -voteCount; l <= voteCount; ++l) {
+            if (resultG.equals(g.modPow(BigInteger.valueOf(l), p))) {
+                success = true;
+                resultRestored = l;
+                break;
+            }
+        }
+
+        if (!success) {
+            throw new AssertionError();
+        }
+
+        if (resultRestored != result) {
+            throw new AssertionError();
+        }
     }
+
+    public static void simulateBallotZKP1(BigInteger h, ElGamalScheme 
parameters, Random random) {
+        final BigInteger p = parameters.getP();
+        final BigInteger q = parameters.getQ();
+        final BigInteger g = parameters.getG();
+
+        // prover
+        BigInteger alpha = parameters.generateZq(random);
+        BigInteger w = parameters.generateZq(random);
+        BigInteger r_1 = parameters.generateZq(random);
+        BigInteger d_1 = parameters.generateZq(random);
+
+        BigInteger x = g.modPow(alpha, p);
+        BigInteger y = h.modPow(alpha, p).multiply(g).mod(p);
+
+        BigInteger a_1 = g.modPow(r_1, p).multiply(x.modPow(d_1, p)).mod(p);
+        BigInteger b_1 = h.modPow(r_1, p).multiply(y.multiply(g).modPow(d_1, 
p)).mod(p);
+        BigInteger a_2 = g.modPow(w, p);
+        BigInteger b_2 = h.modPow(w, p);
+
+        // verifier
+        BigInteger c = parameters.generateZq(random);
+
+        // prover
+        BigInteger d_2 = c.subtract(d_1);
+        BigInteger r_2 = w.subtract(alpha.multiply(d_2));
+
+        // verifier
+        if (!c.equals(d_1.add(d_2).mod(p))) {
+            throw new AssertionError();
+        }
+        if (!a_1.equals(g.modPow(r_1, p).multiply(x.modPow(d_1, p)).mod(p))) {
+            throw new AssertionError();
+        }
+        if (!b_1.equals(h.modPow(r_1, p).multiply(y.multiply(g).modPow(d_1, 
p)).mod(p))) {
+            throw new AssertionError();
+        }
+
+        if (!a_2.equals(g.modPow(r_2, p).multiply(x.modPow(d_2, p)).mod(p))) {
+            throw new AssertionError();
+        }
+
+        if (!b_2.equals(h.modPow(r_2, 
p).multiply(y.multiply(g.modInverse(p)).modPow(d_2, p)).mod(p))) {
+            throw new AssertionError();
+        }
+    }
+
+
+    public static void simulateBallotZKP2(BigInteger h, ElGamalScheme 
parameters, Random random) {
+        final BigInteger p = parameters.getP();
+        final BigInteger q = parameters.getQ();
+        final BigInteger g = parameters.getG();
+
+        // prover
+        BigInteger alpha = parameters.generateZq(random);
+        BigInteger w = parameters.generateZq(random);
+        BigInteger r_2 = parameters.generateZq(random);
+        BigInteger d_2 = parameters.generateZq(random);
+
+        BigInteger x = g.modPow(alpha, p);
+        BigInteger y = h.modPow(alpha, p).multiply(g.modInverse(p)).mod(p);
+
+        BigInteger a_1 = g.modPow(w, p);
+        BigInteger b_1 = h.modPow(w, p);
+        BigInteger a_2 = g.modPow(r_2, p).multiply(x.modPow(d_2, p)).mod(p);
+        BigInteger b_2 = h.modPow(r_2, 
p).multiply(y.multiply(g.modInverse(p)).modPow(d_2, p)).mod(p);
+
+
+        // verifier
+        BigInteger c = parameters.generateZq(random);
+
+        // prover
+        BigInteger d_1 = c.subtract(d_2);
+        BigInteger r_1 = w.subtract(alpha.multiply(d_1));
+
+        // verifier
+        if (!c.equals(d_1.add(d_2).mod(p))) {
+            throw new AssertionError();
+        }
+        if (!a_1.equals(g.modPow(r_1, p).multiply(x.modPow(d_1, p)).mod(p))) {
+            throw new AssertionError();
+        }
+        if (!b_1.equals(h.modPow(r_1, p).multiply(y.multiply(g).modPow(d_1, 
p)).mod(p))) {
+            throw new AssertionError();
+        }
+
+        if (!a_2.equals(g.modPow(r_2, p).multiply(x.modPow(d_2, p)).mod(p))) {
+            throw new AssertionError();
+        }
+
+        if (!b_2.equals(h.modPow(r_2, 
p).multiply(y.multiply(g.modInverse(p)).modPow(d_2, p)).mod(p))) {
+            throw new AssertionError();
+        }
+    }
 }
+




reply via email to

[Prev in Thread] Current Thread [Next in Thread]