Esempio n. 1
0
    def __realMix(self, message, path, tempProcess=None):
        temp = message.permute(self.permutation[path])
        result = Vector([
            CyclicGroupVector.scalarMultiply(temp.at(i),
                                             self.S[path].array.at(i))
            for i in range(0, self.b)
        ])
        if not self.__finalNode(path):
            self.__toNextNode(
                path,
                Message(self.realMixCallback[path],
                        [v.vector for v in result.vector]))
        else:
            self.network.broadcastToNodes(
                self.id,
                Message(self.mixCommitCallback[path],
                        [v.vector for v in result.vector]))
            temp = CyclicGroupVector.multiply(self.decryptionShare[path],
                                              self.mixMessageComponents[path])
            if tempProcess is not None:
                temp = tempProcess(temp)

            result = Vector([
                CyclicGroupVector.scalarMultiply(result.at(i), temp.at(i))
                for i in range(0, self.b)
            ])
            self.network.sendToNH(
                Message(self.realPostProcessCallback[path],
                        [True, [v.vector for v in result.vector]]))
        return Status.OK
Esempio n. 2
0
 def __preMix(self, message, path):
     result = ElGamalVector.multiply(
         message.permute(self.permutation[path]),
         self.S[path].inverse.encrypt(self.sharedKey))
     if not self.__finalNode(path):
         self.__toNextNode(
             path, Message(self.preMixCallback[path], result.vector))
     else:
         self.mixMessageComponents[path] = result.messageComponents()
         message = Message(self.prePostProcessCallback[path],
                           result.randomComponents().vector)
         self.network.broadcastToNodes(self.id, message)
         self.receive(message.toJSON())
     return Status.OK
Esempio n. 3
0
 def __realMixCommit(self, message, path, resultProcess):
     self.realMixCommitment[path] = message
     result = resultProcess(self.decryptionShare[path])
     self.network.sendToNH(
         Message(self.realPostProcessCallback[path],
                 [False, result.vector]))
     return Status.OK
Esempio n. 4
0
 def receive(self, messageJSON):
     message = Message.fromJSON(messageJSON)
     if self.timesMax[message.callback] is None or self.timesCalled[message.callback] < self.timesMax[message.callback]:
         self.timesCalled[message.callback] += 1
         return self.callbacks[message.callback](message)
     else:
         return Status.ERROR
Esempio n. 5
0
    def appendKeyShare(self, message):
        code = message.callback
        share = message.payload
        self.d = CyclicGroup.multiply(self.d, share)
        if self.isLastCall(code):
            self.broadcast(Message(Callback.KEY_SHARE, self.d))

        return Status.OK
Esempio n. 6
0
 def realForPreProcess(self, message):
     self.senders = message.payload
     cyclicVector = self.keyManager.getNextKeys(ids=self.senders,
                                                type=KeyManager.MESSAGE,
                                                inverse=False)
     product = CyclicGroupVector.multiply(cyclicVector, self.r.array)
     self.network.sendToNH(
         Message(Callback.REAL_FOR_PREPROCESS, product.vector))
     return Status.OK
Esempio n. 7
0
 def realForPreProcess(self, message):
     code = message.callback
     cyclicVector = CyclicGroupVector(vector=message.payload)
     self.sendersBuffer.scalarMultiply(cyclicVector)
     if self.isLastCall(code):
         self.network.sendToFirstNode(
             Message(Callback.REAL_FOR_MIX,
                     self.sendersBuffer.getMessages()))
     return Status.OK
Esempio n. 8
0
 def getUserResponse(self, message):
     index = message.payload[0]
     response = CyclicGroupVector(vector=message.payload[1])
     self.receiversBuffer.addUserMessage(index, response)
     if self.receiversBuffer.isFull():
         self.network.sendToLastNode(
             Message(Callback.REAL_RET_MIX,
                     self.receiversBuffer.getMessages()))
     return Status.OK
Esempio n. 9
0
 def sendUserKey(self, message):
     userId = message.payload
     self.keyManager.addSeeds(userId)
     payload = [
         self.id,
         self.keyManager.getSeed(userId, KeyManager.MESSAGE),
         self.keyManager.getSeed(userId, KeyManager.RESPONSE)
     ]
     self.network.sendToUser(userId, Message(Callback.KEY_USER, payload))
     return Status.OK
Esempio n. 10
0
    def preForwardMix(self, message):
        status = self.__preMix(message=ElGamalVector(vector=message.payload),
                               path='FOR')

        # the last node initiates the matching return path
        if self.__finalNode('FOR'):
            self.network.sendToPreviousNode(
                self.id,
                Message(Callback.PRE_RET_MIX,
                        self.S['RET'].inverse.encrypt(self.sharedKey).vector))
        return status
Esempio n. 11
0
 def getUserMessage(self, message):
     senderId = message.payload[0]
     messageId = message.payload[1]
     blindMessage = CyclicGroupVector(vector=message.payload[2])
     self.sendersBuffer.addUser(senderId, messageId, blindMessage)
     self.network.sendToUser(
         senderId,
         Message(Callback.USER_MESSAGE_STATUS,
                 (messageId, MessageStatus.PENDING)))
     if self.sendersBuffer.isFull():
         for senderId, messageId in zip(self.sendersBuffer.getUsers(),
                                        self.sendersBuffer.getMessageIds()):
             self.network.sendToUser(
                 senderId,
                 Message(Callback.USER_MESSAGE_STATUS,
                         (messageId, MessageStatus.SENT)))
         self.network.broadcastToNodes(
             self.id,
             Message(Callback.REAL_FOR_PREPROCESS,
                     self.sendersBuffer.getUsers()))
     return Status.OK
Esempio n. 12
0
    def preForPreProcess(self, message):
        code = message.callback
        r_inverseEG = ElGamalVector(vector=message.payload)

        if not self.R_inverseEG:
            self.R_inverseEG = r_inverseEG
        else:
            self.R_inverseEG = ElGamalVector.multiply(self.R_inverseEG,
                                                      r_inverseEG)
            if self.isLastCall(code):
                self.network.sendToFirstNode(
                    Message(Callback.PRE_FOR_MIX, self.R_inverseEG.vector))
        return Status.OK
Esempio n. 13
0
File: user.py Progetto: johntsr/cMix
    def sendMessage(self, userId, messageId, messageVector):
        # store the message for future reference
        self.messageSent = messageVector.copyVector()

        # append the userId (the receiver)
        # the NH will read this id (after the message is un-blinded) and route the message accordingly
        messageVector.append(userId)

        # blind the message with the combined key and send it to the NH
        combinedKey = self.keyManager.getCombinedKey(type=KeyManager.MESSAGE,
                                                     inverse=True)
        blindMessage = CyclicGroupVector.scalarMultiply(
            messageVector, combinedKey)
        self.network.sendToNH(
            Message(Callback.USER_MESSAGE,
                    [self.id, messageId, blindMessage.vector]))
Esempio n. 14
0
File: user.py Progetto: johntsr/cMix
    def readMessage(self, message):
        index = message.payload[0]

        # the payload is the message (mapped to cyclic group members)
        messageVector = CyclicGroupVector(vector=message.payload[1])

        # compute a response and send it to the mixnet
        responseVector = self.callbackHandler.messageHandler(
            self, messageVector)
        # store message and response for future reference
        self.messageGot = messageVector.copyVector()
        self.responseSent = responseVector.copyVector()

        self.network.sendToNH(
            Message(Callback.USER_RESPONSE, [index, responseVector.vector]))
        return Status.OK
Esempio n. 15
0
    def __realPostProcess(self, message, path, getUsersCallback):
        code = message.callback
        isLastNode = message.payload[0]

        # the last node send the mix results along with his decryption share
        if isLastNode:
            self.mixResult[path] = Vector(vector=[
                CyclicGroupVector(vector=v) for v in message.payload[1]
            ])
        else:
            self.__appendDecrShare(
                CyclicGroupVector(vector=message.payload[1]), path)

        # gradually un-blind messages
        if self.mixResult[path] is not None and self.decryptionShares[
                path] is not None:
            self.mixResult[path] = Vector([
                CyclicGroupVector.scalarMultiply(
                    self.mixResult[path].at(i),
                    self.decryptionShares[path].at(i))
                for i in range(0, self.b)
            ])

        # when they are un-blinded, send to users
        if self.isLastCall(code):
            users = getUsersCallback()
            for i in range(0, self.b):
                if path == 'FOR':
                    # in the forward path, also send the index
                    # the response will contain this index, so the NH will know which slot to associate it with
                    # NOTE: as an alternative, the NH could wait for a response before he delivers the next message
                    # that way, the index is not needed to be sent
                    payload = [i, self.mixResult[path].at(i).vector]
                else:
                    payload = self.mixResult[path].at(i).vector
                self.network.sendToUser(
                    users[i], Message(self.sendCallback[path], payload))
            else:
                if path == 'RET':
                    self.reset()
        return Status.OK
Esempio n. 16
0
 def computeSecretShare(self):
     self.network.sendToNH(Message(Callback.KEY_SHARE, self.e[1]))
Esempio n. 17
0
File: user.py Progetto: johntsr/cMix
 def setUp(self):
     self.network.broadcastToNodes(self.id,
                                   Message(Callback.KEY_USER, self.id))
Esempio n. 18
0
 def precompute(self):
     self.network.sendToNH(
         Message(Callback.PRE_FOR_PREPROCESS,
                 self.r.inverse.encrypt(self.sharedKey).vector))