コード例 #1
0
    // Everyone except player 1 creates a new keypair and sends it around to everyone else.
    DecryptionKey broadcastNewKey(Map<VerificationKey, Address> changeAddresses)
        throws TimeoutException, InterruptedException, IOException, FormatException {
      DecryptionKey dk = null;
      dk = crypto.makeDecryptionKey();

      // Broadcast the public key and store it in the set with everyone else's.
      encryptionKeys.put(vk, dk.EncryptionKey());
      changeAddresses.put(vk, change);
      Message message = messages.make().attach(dk.EncryptionKey());
      if (change != null) {
        message = message.attach(change);
      }
      mailbox.broadcast(message, phase.get());
      return dk;
    }
コード例 #2
0
    // In the shuffle phase, we have to receive a set of strings from the previous player and
    // decrypt them all.
    final Message decryptAll(Message message, DecryptionKey key, int expected)
        throws IOException, InterruptedException, FormatException {

      Message decrypted = messages.make();

      int count = 0;
      Set<String> addrs = new HashSet<>(); // Used to check that all addresses are different.

      while (!message.isEmpty()) {
        String encrypted = message.readString();
        message = message.rest();

        addrs.add(encrypted);
        count++;
        decrypted = decrypted.attach(key.decrypt(encrypted));
      }

      if (addrs.size() != count || count != expected) {
        phase.set(Phase.Blame);
        mailbox.broadcast(
            messages.make().attach(Blame.ShuffleFailure(players.get(N))), phase.get());

        return null;
      }

      return decrypted;
    }