diff options
author | Florian Dold <florian.dold@gmail.com> | 2014-03-30 21:41:58 +0000 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2014-03-30 21:41:58 +0000 |
commit | 9f10abfdc35d8f189a8e0a77a389799ca6b7f9e5 (patch) | |
tree | 39d855abacebeaa45752e4abc5b4a660d2603d70 /src/main/java/org/gnunet/voting/DisjunctionZkp.java | |
parent | 1fbef203844b19f8141bddcba20a977de34b211e (diff) | |
download | gnunet-java-9f10abfdc35d8f189a8e0a77a389799ca6b7f9e5.tar.gz gnunet-java-9f10abfdc35d8f189a8e0a77a389799ca6b7f9e5.zip |
- fix election crypto
- multi-way elections
- high-level signature containers
- fix bug in mesh test case
- fix bug in Strings.java
- ivy repo
Diffstat (limited to 'src/main/java/org/gnunet/voting/DisjunctionZkp.java')
-rw-r--r-- | src/main/java/org/gnunet/voting/DisjunctionZkp.java | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/src/main/java/org/gnunet/voting/DisjunctionZkp.java b/src/main/java/org/gnunet/voting/DisjunctionZkp.java new file mode 100644 index 0000000..cfa823c --- /dev/null +++ b/src/main/java/org/gnunet/voting/DisjunctionZkp.java | |||
@@ -0,0 +1,64 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2014 Christian Grothoff (and other contributing authors) | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | package org.gnunet.voting; | ||
22 | |||
23 | import org.gnunet.construct.*; | ||
24 | import org.gnunet.secretsharing.Parameters; | ||
25 | |||
26 | import java.math.BigInteger; | ||
27 | import java.security.MessageDigest; | ||
28 | import java.security.NoSuchAlgorithmException; | ||
29 | |||
30 | /** | ||
31 | * Disjunction of Chaum Pedersen ZKPs. | ||
32 | */ | ||
33 | public class DisjunctionZkp implements Message { | ||
34 | @UInt64 | ||
35 | public int numProofs; | ||
36 | @FixedSizeIntegerArray(signed = true, bitSize = 8, length = Parameters.elgamalBits / 8) | ||
37 | public byte[] challenge_c; | ||
38 | @VariableSizeArray(lengthField = "numProofs") | ||
39 | public ChaumPedersenZkp[] chaumPedersenZkps; | ||
40 | |||
41 | public boolean verifyChallenge() { | ||
42 | BigInteger c_actual = new BigInteger(1, challenge_c); | ||
43 | BigInteger c_expected = BigInteger.ZERO; | ||
44 | for (ChaumPedersenZkp chaumPedersenZkp : chaumPedersenZkps) { | ||
45 | BigInteger d = new BigInteger(1, chaumPedersenZkp.challenge_d); | ||
46 | c_expected = c_expected.add(d).mod(Parameters.elgamalQ); | ||
47 | } | ||
48 | return c_actual.equals(c_expected) && computeChallengeFromCommits().equals(c_actual); | ||
49 | } | ||
50 | |||
51 | public BigInteger computeChallengeFromCommits() { | ||
52 | MessageDigest digest; | ||
53 | try { | ||
54 | digest = MessageDigest.getInstance("SHA-512"); | ||
55 | } catch (NoSuchAlgorithmException e) { | ||
56 | throw new RuntimeException("crypto algorithm 'SHA-512' required but not provided"); | ||
57 | } | ||
58 | for (ChaumPedersenZkp chaumPedersenZkp : chaumPedersenZkps) { | ||
59 | digest.update(chaumPedersenZkp.commit_a); | ||
60 | digest.update(chaumPedersenZkp.commit_b); | ||
61 | } | ||
62 | return (new BigInteger(digest.digest())).mod(Parameters.elgamalQ); | ||
63 | } | ||
64 | } | ||