aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2014-02-17 16:55:22 +0000
committerFlorian Dold <florian.dold@gmail.com>2014-02-17 16:55:22 +0000
commit5287f057386174262284b427358d916176f2df4c (patch)
treece4ddeb812bbc605d85f67196c0e0255a2cb0fc4 /src/main/java
parentf4988bbbf0b185d26f3fb668c9dd0baa88c2a6e1 (diff)
downloadgnunet-java-5287f057386174262284b427358d916176f2df4c.tar.gz
gnunet-java-5287f057386174262284b427358d916176f2df4c.zip
- java api for secretsharing
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/gnunet/secretsharing/Ciphertext.java35
-rw-r--r--src/main/java/org/gnunet/secretsharing/Decryption.java88
-rw-r--r--src/main/java/org/gnunet/secretsharing/FieldElement.java29
-rw-r--r--src/main/java/org/gnunet/secretsharing/KeyGeneration.java88
-rw-r--r--src/main/java/org/gnunet/secretsharing/Parameters.java69
-rw-r--r--src/main/java/org/gnunet/secretsharing/Plaintext.java90
-rw-r--r--src/main/java/org/gnunet/secretsharing/Share.java63
-rw-r--r--src/main/java/org/gnunet/secretsharing/ThresholdPublicKey.java32
-rw-r--r--src/main/java/org/gnunet/secretsharing/callbacks/DecryptCallback.java35
-rw-r--r--src/main/java/org/gnunet/secretsharing/callbacks/SecretReadyCallback.java35
-rw-r--r--src/main/java/org/gnunet/secretsharing/messages/ClientDecryptMessage.java59
-rw-r--r--src/main/java/org/gnunet/secretsharing/messages/DecryptDoneMessage.java48
-rw-r--r--src/main/java/org/gnunet/secretsharing/messages/GenerateMessage.java51
-rw-r--r--src/main/java/org/gnunet/secretsharing/messages/SecretReadyMessage.java39
14 files changed, 761 insertions, 0 deletions
diff --git a/src/main/java/org/gnunet/secretsharing/Ciphertext.java b/src/main/java/org/gnunet/secretsharing/Ciphertext.java
new file mode 100644
index 0000000..bb2962e
--- /dev/null
+++ b/src/main/java/org/gnunet/secretsharing/Ciphertext.java
@@ -0,0 +1,35 @@
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
21package org.gnunet.secretsharing;
22
23import org.gnunet.construct.FixedSizeIntegerArray;
24import org.gnunet.construct.Message;
25
26/**
27 * ElGamal ciphertext
28 */
29public class Ciphertext implements Message {
30 @FixedSizeIntegerArray(signed = true, bitSize = 8, length = Parameters.elgamalBits / 8)
31 public byte[] c_1;
32
33 @FixedSizeIntegerArray(signed = true, bitSize = 8, length = Parameters.elgamalBits / 8)
34 public byte[] c_2;
35}
diff --git a/src/main/java/org/gnunet/secretsharing/Decryption.java b/src/main/java/org/gnunet/secretsharing/Decryption.java
new file mode 100644
index 0000000..76197fb
--- /dev/null
+++ b/src/main/java/org/gnunet/secretsharing/Decryption.java
@@ -0,0 +1,88 @@
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
21package org.gnunet.secretsharing;
22
23import org.gnunet.secretsharing.callbacks.DecryptCallback;
24import org.gnunet.secretsharing.messages.ClientDecryptMessage;
25import org.gnunet.secretsharing.messages.DecryptDoneMessage;
26import org.gnunet.util.AbsoluteTime;
27import org.gnunet.util.Client;
28import org.gnunet.util.Configuration;
29import org.gnunet.util.RunaboutMessageReceiver;
30
31/**
32 * Cooperatively decrypt a ciphertext.
33 */
34public class Decryption {
35 private Client client;
36 private DecryptCallback decryptCallback;
37
38 private class DecryptionReceiver extends RunaboutMessageReceiver {
39 public void visit(DecryptDoneMessage m) {
40 if (m.success != 0) {
41 decryptCallback.onResult(m.plaintext);
42 } else {
43 decryptCallback.onResult(null);
44 }
45 client.disconnect();
46 client = null;
47 }
48 @Override
49 public void handleError() {
50 decryptCallback.onResult(null);
51 }
52 }
53
54 /**
55 * Cooperatively decrypt a ciphertext encrypted with a
56 * threshold key.
57 *
58 * @param configuration configuration to use for connecting to the
59 * secretsharing service
60 * @param share the local peer's share of the threshold key
61 * @param ciphertext ciphertext to decrypt
62 * @param start when should we start decrypting?
63 * @param deadline when should decryption be finished?
64 * @param decryptCallback called when the decryption finished, or
65 * an error occurred.
66 */
67 public Decryption(Configuration configuration, Share share, Ciphertext ciphertext,
68 AbsoluteTime start, AbsoluteTime deadline, DecryptCallback decryptCallback) {
69 this.decryptCallback = decryptCallback;
70 client = new Client("secretsharing", configuration);
71 client.installReceiver(new DecryptionReceiver());
72
73 ClientDecryptMessage m = new ClientDecryptMessage();
74 m.ciphertext = ciphertext;
75 m.deadline = deadline.asMessage();
76 m.start = start.asMessage();
77 m.share = share;
78
79 client.send(m);
80 }
81
82 public void disconnect() {
83 if (null != client) {
84 client.disconnect();
85 client = null;
86 }
87 }
88}
diff --git a/src/main/java/org/gnunet/secretsharing/FieldElement.java b/src/main/java/org/gnunet/secretsharing/FieldElement.java
new file mode 100644
index 0000000..e1fcac6
--- /dev/null
+++ b/src/main/java/org/gnunet/secretsharing/FieldElement.java
@@ -0,0 +1,29 @@
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
21package org.gnunet.secretsharing;
22
23import org.gnunet.construct.FixedSizeIntegerArray;
24import org.gnunet.construct.Message;
25
26public class FieldElement implements Message {
27 @FixedSizeIntegerArray(signed = true, bitSize = 8, length = Parameters.elgamalBits / 8)
28 public byte[] bits;
29}
diff --git a/src/main/java/org/gnunet/secretsharing/KeyGeneration.java b/src/main/java/org/gnunet/secretsharing/KeyGeneration.java
new file mode 100644
index 0000000..8b9a759
--- /dev/null
+++ b/src/main/java/org/gnunet/secretsharing/KeyGeneration.java
@@ -0,0 +1,88 @@
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
21package org.gnunet.secretsharing;
22
23import org.gnunet.secretsharing.callbacks.SecretReadyCallback;
24import org.gnunet.secretsharing.messages.GenerateMessage;
25import org.gnunet.secretsharing.messages.SecretReadyMessage;
26import org.gnunet.util.*;
27
28/**
29 * Key generation session.
30 */
31public class KeyGeneration {
32 private Client client;
33 private SecretReadyCallback secretReadyCallback;
34
35 private class KeyGenerationReceiver extends RunaboutMessageReceiver {
36 public void visit(SecretReadyMessage m) {
37 secretReadyCallback.onSecretReady(m.share);
38 client.disconnect();
39 client = null;
40 }
41 @Override
42 public void handleError() {
43 secretReadyCallback.onSecretReady(null);
44 }
45 }
46
47 /**
48 * Generate a threshold key pair.
49 *
50 * @param configuration configuratio to use
51 * @param peers peers in the session, the local peer is optional
52 * @param sessionId session id
53 * @param start when should we start to generate the key with other peers?
54 * @param deadline when should the key generation be finished?
55 * @param threshold minimum number of peers required to decrypt a ciphertext
56 * @param secretReadyCallback called when the key has been generated or
57 * an error occured
58 */
59 public KeyGeneration(Configuration configuration, PeerIdentity[] peers,
60 HashCode sessionId, AbsoluteTime start, AbsoluteTime deadline,
61 int threshold, SecretReadyCallback secretReadyCallback) {
62 this.client = new Client("secretsharing", configuration);
63 this.secretReadyCallback = secretReadyCallback;
64
65 client.installReceiver(new KeyGenerationReceiver());
66
67 GenerateMessage m = new GenerateMessage();
68 m.start = start.asMessage();
69 m.deadline = deadline.asMessage();
70 m.threshold = threshold;
71 m.numPeers = peers.length;
72 m.peers = peers;
73 m.sessionId = sessionId;
74
75 client.send(m);
76 }
77
78 /**
79 * Disconnect from the secretsharing service and cancel the operation.
80 * The SecretReadyCallback will not be called after calling disconnect.
81 */
82 public void disconnect() {
83 if (null != client) {
84 client.disconnect();
85 client = null;
86 }
87 }
88}
diff --git a/src/main/java/org/gnunet/secretsharing/Parameters.java b/src/main/java/org/gnunet/secretsharing/Parameters.java
new file mode 100644
index 0000000..cd0e5de
--- /dev/null
+++ b/src/main/java/org/gnunet/secretsharing/Parameters.java
@@ -0,0 +1,69 @@
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
21package org.gnunet.secretsharing;
22
23import java.math.BigInteger;
24
25/**
26 * Constants used by the crypto of the secretsharing API.
27 */
28public interface Parameters {
29 /**
30 * Size of the key.
31 */
32 public static final int elgamalBits = 1024;
33
34 /**
35 * Order of the group.
36 */
37 public static final BigInteger elgamalQ = new BigInteger(
38 "0451a3e9eb4f4596ebe8d895046fde65f5fa65" +
39 "37a134d040a70ac51a1894b26ca359f79144118b" +
40 "95e7987e047bb93ba65a027cde001537b3584d3c" +
41 "ec086b3e27c659df6e303071e477c3a58db26fb8" +
42 "b63e958016d4407134a1c6ad3bb735af929e46fa" +
43 "b50b58e3e72c6f783e01eda411c556fe2951aa51" +
44 "3f6942d860b3ae569f9", 16);
45
46 /**
47 * Modulus of the group.
48 */
49 public static final BigInteger elgamalP = new BigInteger(
50 "08a347d3d69e8b2dd7d1b12a08dfbccbebf4ca" +
51 "6f4269a0814e158a34312964d946b3ef22882317" +
52 "2bcf30fc08f772774cb404f9bc002a6f66b09a79" +
53 "d810d67c4f8cb3bedc6060e3c8ef874b1b64df71" +
54 "6c7d2b002da880e269438d5a776e6b5f253c8df5" +
55 "6a16b1c7ce58def07c03db48238aadfc52a354a2" +
56 "7ed285b0c1675cad3f3", 16);
57
58 /**
59 * Generator of the group.
60 */
61 public static final BigInteger elgamalG = new BigInteger(
62 "05c00c36d2e822950087ef09d8252994adc4e4" +
63 "8fe3ec70269f035b46063aff0c99b633fd64df43" +
64 "02442e1914c829a41505a275438871f365e91c12" +
65 "3d5303ef9e90f4b8cb89bf86cc9b513e74a72634" +
66 "9cfd9f953674fab5d511e1c078fc72d72b34086f" +
67 "c82b4b951989eb85325cb203ff98df76bc366bba" +
68 "1d7024c3650f60d0da", 16);
69}
diff --git a/src/main/java/org/gnunet/secretsharing/Plaintext.java b/src/main/java/org/gnunet/secretsharing/Plaintext.java
new file mode 100644
index 0000000..c4fdd3e
--- /dev/null
+++ b/src/main/java/org/gnunet/secretsharing/Plaintext.java
@@ -0,0 +1,90 @@
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
21package org.gnunet.secretsharing;
22
23import com.google.common.base.Preconditions;
24import org.gnunet.construct.FixedSizeIntegerArray;
25import org.gnunet.construct.Message;
26
27import java.math.BigInteger;
28import java.security.SecureRandom;
29
30public class Plaintext implements Message {
31 @FixedSizeIntegerArray(signed = true, bitSize = 8, length = Parameters.elgamalBits / 8)
32 public byte[] bits;
33
34 public static Plaintext generate(BigInteger exp) {
35 BigInteger val;
36 val = Parameters.elgamalG.modPow(exp, Parameters.elgamalP);
37 Plaintext plaintext = new Plaintext();
38 plaintext.bits = serializeBigIntUnsigned(val, Parameters.elgamalBits);
39 return plaintext;
40 }
41
42 /**
43 * Serialize a BigInteger, but do not add an extra bit for a
44 * sign.
45 *
46 * @param bigInteger
47 * @param bits
48 * @return
49 */
50 private static byte[] serializeBigIntUnsigned(BigInteger bigInteger, int bits) {
51 byte[] bytes = bigInteger.toByteArray();
52 int start;
53 Preconditions.checkArgument(bigInteger.bitCount() <= bits);
54 // skip byte that was only added to fit the sign
55 if (bytes[0] == 0) {
56 start = 1;
57 } else {
58 start = 0;
59 }
60 byte[] fixedBytes = new byte[(bits + 7) / 8];
61 System.arraycopy(bytes, start, fixedBytes,
62 fixedBytes.length - bytes.length + start, bytes.length - start);
63 return fixedBytes;
64 }
65
66 public Ciphertext encrypt(ThresholdPublicKey publicKey) {
67 SecureRandom secureRandom = new SecureRandom();
68 BigInteger c_1;
69 BigInteger c_2;
70 BigInteger y;
71 BigInteger m;
72 BigInteger h;
73
74 m = new BigInteger(1, this.bits);
75 h = new BigInteger(1, publicKey.bits);
76
77 do {
78 y = new BigInteger(Parameters.elgamalBits - 1, secureRandom);
79 } while (y.compareTo(BigInteger.ONE) == 0 || y.compareTo(Parameters.elgamalQ) >= 0);
80
81 c_1 = Parameters.elgamalG.modPow(y, Parameters.elgamalP);
82 c_2 = m.multiply(h.modPow(y, Parameters.elgamalP)).mod(Parameters.elgamalP);
83
84 Ciphertext ciphertext = new Ciphertext();
85 ciphertext.c_1 = serializeBigIntUnsigned(c_1, Parameters.elgamalBits);
86 ciphertext.c_2 = serializeBigIntUnsigned(c_2, Parameters.elgamalBits);
87
88 return ciphertext;
89 }
90}
diff --git a/src/main/java/org/gnunet/secretsharing/Share.java b/src/main/java/org/gnunet/secretsharing/Share.java
new file mode 100644
index 0000000..5389031
--- /dev/null
+++ b/src/main/java/org/gnunet/secretsharing/Share.java
@@ -0,0 +1,63 @@
1package org.gnunet.secretsharing;
2
3import org.gnunet.construct.*;
4import org.gnunet.util.PeerIdentity;
5
6/**
7 * Share of the threshold secret key. Contains both the
8 * public key as well as one peer's private share.
9 */
10public class Share implements Message {
11 /**
12 * Threshold for the key this share belongs to.
13 */
14 @UInt16
15 public int threshold;
16
17 /**
18 * Peers that have the share.
19 */
20 @UInt16
21 public int numPeers;
22
23 /**
24 * Index of our peer in the list.
25 */
26 @UInt16
27 public int myPeer;
28
29 /**
30 * Padding, always zero.
31 */
32 @UInt16
33 public int padding;
34
35 /**
36 * Public key. Must correspond to the product of
37 * the homomorphic share commitments.
38 */
39 @NestedMessage
40 public ThresholdPublicKey publicKey;
41
42 /**
43 * Share of 'my_peer'
44 */
45 @NestedMessage
46 public FieldElement myShare;
47
48 /**
49 * Peers that have a share of the secret.
50 */
51 @VariableSizeArray(lengthField = "numPeers")
52 public PeerIdentity[] peerIdentities;
53
54 /**
55 * Sigma for each peer. The sigma is pow(g,s)
56 * where g is the generator and s is the peer's share.
57 */
58 @VariableSizeArray(lengthField = "numPeers")
59 public FieldElement[] sigmas;
60
61 @VariableSizeIntegerArray(lengthField = "numPeers", bitSize = 16, signed = false)
62 public int[] originalIndices;
63}
diff --git a/src/main/java/org/gnunet/secretsharing/ThresholdPublicKey.java b/src/main/java/org/gnunet/secretsharing/ThresholdPublicKey.java
new file mode 100644
index 0000000..b7075be
--- /dev/null
+++ b/src/main/java/org/gnunet/secretsharing/ThresholdPublicKey.java
@@ -0,0 +1,32 @@
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
21package org.gnunet.secretsharing;
22
23import org.gnunet.construct.FixedSizeIntegerArray;
24import org.gnunet.construct.Message;
25
26/**
27 * Threshold public key.
28 */
29public class ThresholdPublicKey implements Message {
30 @FixedSizeIntegerArray(signed = true, bitSize = 8, length = Parameters.elgamalBits / 8)
31 public byte[] bits;
32}
diff --git a/src/main/java/org/gnunet/secretsharing/callbacks/DecryptCallback.java b/src/main/java/org/gnunet/secretsharing/callbacks/DecryptCallback.java
new file mode 100644
index 0000000..1947811
--- /dev/null
+++ b/src/main/java/org/gnunet/secretsharing/callbacks/DecryptCallback.java
@@ -0,0 +1,35 @@
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
21package org.gnunet.secretsharing.callbacks;
22
23import org.gnunet.secretsharing.Plaintext;
24
25/**
26 * Callback for when the secretsharing service has decrypted a ciphertext.
27 */
28public interface DecryptCallback {
29 /**
30 * Called when the secretsharing service has decrypted a ciphertext.
31 *
32 * @param plaintext the plaintext, or null on error
33 */
34 void onResult(Plaintext plaintext);
35}
diff --git a/src/main/java/org/gnunet/secretsharing/callbacks/SecretReadyCallback.java b/src/main/java/org/gnunet/secretsharing/callbacks/SecretReadyCallback.java
new file mode 100644
index 0000000..a2ca57c
--- /dev/null
+++ b/src/main/java/org/gnunet/secretsharing/callbacks/SecretReadyCallback.java
@@ -0,0 +1,35 @@
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
21package org.gnunet.secretsharing.callbacks;
22
23import org.gnunet.secretsharing.Share;
24
25/**
26 * Callback for when shared secret key has been established.
27 */
28public interface SecretReadyCallback {
29 /**
30 * Called when the shared secret key has been established.
31 * @param share the share for the local peer, including the public key,
32 * or null on error
33 */
34 public void onSecretReady(Share share);
35}
diff --git a/src/main/java/org/gnunet/secretsharing/messages/ClientDecryptMessage.java b/src/main/java/org/gnunet/secretsharing/messages/ClientDecryptMessage.java
new file mode 100644
index 0000000..1dc0981
--- /dev/null
+++ b/src/main/java/org/gnunet/secretsharing/messages/ClientDecryptMessage.java
@@ -0,0 +1,59 @@
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
21package org.gnunet.secretsharing.messages;
22
23import org.gnunet.construct.NestedMessage;
24import org.gnunet.construct.UnionCase;
25import org.gnunet.secretsharing.Ciphertext;
26import org.gnunet.secretsharing.Share;
27import org.gnunet.util.AbsoluteTimeMessage;
28import org.gnunet.util.GnunetMessage;
29
30/**
31 * Sent by the client to the service to request the cooperative decryption of a
32 * ciphertext.
33 */
34@UnionCase(781)
35public class ClientDecryptMessage implements GnunetMessage.Body {
36 /**
37 * When should communication with other peers start?
38 */
39 @NestedMessage
40 public AbsoluteTimeMessage start;
41
42 /**
43 * When should the operation have finished?
44 */
45 @NestedMessage
46 public AbsoluteTimeMessage deadline;
47
48 /**
49 * Ciphertext to cooperatively decrypt.
50 */
51 @NestedMessage
52 public Ciphertext ciphertext;
53
54 /**
55 * Our share of the secret key.
56 */
57 @NestedMessage
58 public Share share;
59}
diff --git a/src/main/java/org/gnunet/secretsharing/messages/DecryptDoneMessage.java b/src/main/java/org/gnunet/secretsharing/messages/DecryptDoneMessage.java
new file mode 100644
index 0000000..71f24da
--- /dev/null
+++ b/src/main/java/org/gnunet/secretsharing/messages/DecryptDoneMessage.java
@@ -0,0 +1,48 @@
1/*
2
3 This file is part of GNUnet.
4 (C) 2014 Christian Grothoff (and other contributing authors)
5
6 GNUnet is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published
8 by the Free Software Foundation; either version 3, or (at your
9 option) any later version.
10
11 GNUnet is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GNUnet; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.
20
21 */
22
23package org.gnunet.secretsharing.messages;
24
25import org.gnunet.construct.NestedMessage;
26import org.gnunet.construct.UInt32;
27import org.gnunet.construct.UnionCase;
28import org.gnunet.secretsharing.Plaintext;
29import org.gnunet.util.GnunetMessage;
30
31/**
32 * Created by dold on 2/2/14.
33 */
34@UnionCase(782)
35public class DecryptDoneMessage implements GnunetMessage.Body{
36
37 /**
38 * Was the decryption successful?
39 */
40 @UInt32
41 public int success;
42
43 /**
44 * Plaintext, only valid if 'success' is non-zero.
45 */
46 @NestedMessage
47 public Plaintext plaintext;
48}
diff --git a/src/main/java/org/gnunet/secretsharing/messages/GenerateMessage.java b/src/main/java/org/gnunet/secretsharing/messages/GenerateMessage.java
new file mode 100644
index 0000000..b1ce6b2
--- /dev/null
+++ b/src/main/java/org/gnunet/secretsharing/messages/GenerateMessage.java
@@ -0,0 +1,51 @@
1/*
2
3 This file is part of GNUnet.
4 (C) 2014 Christian Grothoff (and other contributing authors)
5
6 GNUnet is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published
8 by the Free Software Foundation; either version 3, or (at your
9 option) any later version.
10
11 GNUnet is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GNUnet; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.
20
21 */
22
23package org.gnunet.secretsharing.messages;
24
25import org.gnunet.construct.NestedMessage;
26import org.gnunet.construct.UInt16;
27import org.gnunet.construct.UnionCase;
28import org.gnunet.construct.VariableSizeArray;
29import org.gnunet.util.*;
30
31
32@UnionCase(780)
33public class GenerateMessage implements GnunetMessage.Body {
34 @NestedMessage
35 public HashCode sessionId;
36
37 @NestedMessage
38 public AbsoluteTimeMessage start;
39
40 @NestedMessage
41 public AbsoluteTimeMessage deadline;
42
43 @UInt16
44 public int threshold;
45
46 @UInt16
47 public int numPeers;
48
49 @VariableSizeArray(lengthField = "numPeers")
50 public PeerIdentity[] peers;
51}
diff --git a/src/main/java/org/gnunet/secretsharing/messages/SecretReadyMessage.java b/src/main/java/org/gnunet/secretsharing/messages/SecretReadyMessage.java
new file mode 100644
index 0000000..479fe2c
--- /dev/null
+++ b/src/main/java/org/gnunet/secretsharing/messages/SecretReadyMessage.java
@@ -0,0 +1,39 @@
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
21package org.gnunet.secretsharing.messages;
22
23import org.gnunet.construct.NestedMessage;
24import org.gnunet.construct.UnionCase;
25import org.gnunet.secretsharing.Share;
26import org.gnunet.util.GnunetMessage;
27
28/**
29 * Sent by the service to the client when the key generation
30 * has been successful.
31 */
32@UnionCase(783)
33public class SecretReadyMessage implements GnunetMessage.Body {
34 /**
35 * Share for the local peer.
36 */
37 @NestedMessage
38 public Share share;
39}