def manipulateShare(self, mode): """Manipulate the share value by replacing it with a random integer value. The manipulation algorithm varies based on the mode of verification because the message format is different for different modes of verification. When mode is NO_VERIFICATION, the share is of the form "[x, y]". The manipulation converts the share into a list, replaces the y value with a random integer value and converts it back to a string. When mode is AUX_INFO_VERIFICATION, the share is of the form "[[x, s], yList, bList, cList]". The manipulation converts the share into a list, replaces the s value with a random integer value and converts it back to a string. When mode is MAC_VERIFICATION, the share is of the form "['[x, y]', tag]". The manipulation converts the share into a list, extracts the first element '[x, y]', converts it into a list, replaces the y value with a random integer value, converts it back to a string, replaces the original '[x, y]' string with the new string in the list form share and converts it back to a string. ** Invoked by faulty nodes only. ** Args: mode: An integer value representing the mode of verification as defined in the module message.py Raises: TypeError: Error when mode is not an integer. ValueError: Error when mode is not a valid value. """ if type(mode) not in [int, long]: raise TypeError("invalid mode: int or long expected") elif mode not in [NO_VERIFICATION, MAC_VERIFICATION, AUX_INFO_VERIFICATION]: modeRange = "%d, %d or %d" % (NO_VERIFICATION, MAC_VERIFICATION, AUX_INFO_VERIFICATION) raise ValueError("invalid mode: " + modeRange + " expected") share = message.strToList(self.share) if mode == NO_VERIFICATION: share[1] = genRandNum(share[1]) elif mode == AUX_INFO_VERIFICATION: share[0][1] = genRandNum(share[0][1]) elif mode == MAC_VERIFICATION: shareStr = share[0] shareList = message.strToList(shareStr) shareList[1] = genRandNum(shareList[1]) shareStr = message.listToStr(shareList) share[0] = shareStr self.share = message.listToStr(share)
def getReconSharesNoVrfy(self, sList, k): """Returns a list of k shares, of the form [x, y] where x and y are integers, for reconstruction of the secret. Args: sList: A list of string shares of the form "[x, y]" where x and y are integers. k: An integer representing the number of shares required for reconstructing the secret message. Returns: A list of k shares of the form [x, y] where x and y are integers. Raises: TypeError: Error when sList is not a list, or when k is not an integer. ValueError: Error when k is greater than the number of shares. """ if type(sList) != list: raise TypeError("invalid sList: list expected") elif type(k) not in [int, long]: raise TypeError("invalid k: int or long expected") elif k > len(sList): raise ValueError("invalid sList: expected %d or more shares" % k) sharesForRecon = [] for share in sList: sharesForRecon.append(message.strToList(share)) return sharesForRecon[0:k]
def unpackSharesAuxMode(self, shares): """Unpacks a list of string shares of the form "[msg, y, b, c]" into 4 separate lists of msg, y, b and c values. Args: shares: A list of string shares of the form "[msg, y, b, c]" where msg, y, b and c are lists. Returns: A list containing 4 lists, one list for each of msg, y, b and c values extracted from the shares. Raises: TypeError: Error when shares is not a list. """ if type(shares) != list: raise TypeError("invalid shares: list expected") sList = [] yList = [] bList = [] cList = [] for share in shares: shareList = message.strToList(share) sList.append(shareList[0]) yList += shareList[1] bList += shareList[2] cList += shareList[3] return [sList, yList, bList, cList]
def unpackSharesMacMode(self, shares): """Unpacks a list of string shares of the form "[msg, tag]" into a list of all msg values and a list of all tag values. Args: shares: A list of string shares of the form "[msg, tag]" where msg and tag are strings. Returns: A list containing 2 lists: a list of all msg values and a list of all tag values from the list shares. Raises: TypeError: Error when shares is not a list. """ if type(shares) != list: raise TypeError("invalid shares: list expected") sList = [] macList = [] for share in shares: shareList = message.strToList(share) sList.append(shareList[0]) macList.append(shareList[1]) return [sList, macList]
def getReconSharesMacMode(self, sList, honestNodes, k): """Returns a list of k valid shares, of the form [x, y] where x and y are integers, for reconstruction of the secret. Validity of shares is ascertained by the corresponding boolean value in the list honestNodes such that honestNodes[i] = True iff sList[i] is a valid share. Args: sList: A list of string shares of the form "[x, y]" where x and y are integers. honestNodes: A list of booleans corresponding to each share in sList such that honestNodes[i] = True iff sList[i] is a valid share. k: An integer representing the number of shares required for reconstructing the secret message. Returns: A list of k shares of the form [x, y] where x and y are integers. Raises: TypeError: Error when either sList or honestNodes is not a list, or when k is not an integer. ValueError: Error when k is greater than the number of shares, or when number of shares is not the same as the size of list honestNodes. """ if type(sList) != list: raise TypeError("invalid sList: list expected") elif type(honestNodes) != list: raise TypeError("invalid honestNodes: list expected") elif type(k) not in [int, long]: raise TypeError("invalid k: int or long expected") elif k > len(sList): raise ValueError("invalid sList: expected %d or more shares" % k) elif len(sList) != len(honestNodes): raise ValueError( "invalid sList or honestNodes: list counts expected to match") sharesForRecon = [] for i in range(0, len(honestNodes)): if honestNodes[i] == True: share = message.strToList(sList[i]) sharesForRecon.append(share) return sharesForRecon[0:k]
def getReconSharesMacMode(self, sList, honestNodes, k): """Returns a list of k valid shares, of the form [x, y] where x and y are integers, for reconstruction of the secret. Validity of shares is ascertained by the corresponding boolean value in the list honestNodes such that honestNodes[i] = True iff sList[i] is a valid share. Args: sList: A list of string shares of the form "[x, y]" where x and y are integers. honestNodes: A list of booleans corresponding to each share in sList such that honestNodes[i] = True iff sList[i] is a valid share. k: An integer representing the number of shares required for reconstructing the secret message. Returns: A list of k shares of the form [x, y] where x and y are integers. Raises: TypeError: Error when either sList or honestNodes is not a list, or when k is not an integer. ValueError: Error when k is greater than the number of shares, or when number of shares is not the same as the size of list honestNodes. """ if type(sList) != list: raise TypeError("invalid sList: list expected") elif type(honestNodes) != list: raise TypeError("invalid honestNodes: list expected") elif type(k) not in [int, long]: raise TypeError("invalid k: int or long expected") elif k > len(sList): raise ValueError("invalid sList: expected %d or more shares" % k) elif len(sList) != len(honestNodes): raise ValueError("invalid sList or honestNodes: list counts expected to match") sharesForRecon = [] for i in range(0, len(honestNodes)): if honestNodes[i] == True: share = message.strToList(sList[i]) sharesForRecon.append(share) return sharesForRecon[0:k]
# Boilerplate Code # ############################################################# if __name__ == "__main__": # code to execute if called from command-line parser = argparse.ArgumentParser() parser.add_argument("-d", "--debug", dest="debug", action="store_true") parser.set_defaults(debug=False) args = parser.parse_args() try: fp = open("sender.txt", "r") dictStr = fp.read() fp.close() senderDict = message.strToList(dictStr) ports = senderDict["ports"] msg = senderDict["msg"] n = senderDict["n"] k = senderDict["k"] prime = senderDict["prime"] key = senderDict["key"] mode = senderDict["mode"] nodePorts = senderDict["nodes"] addr = mysocket.gethostname() nodes = [(addr, portNum) for portNum in nodePorts] s = sender(ports, key, args.debug) shares, genTime = s.sendShares(msg, n, k, prime, nodes, mode) print "Time taken to generate shares:", genTime
# Boilerplate Code # ############################################################# if __name__ == "__main__": #code to execute if called from command-line parser = argparse.ArgumentParser() parser.add_argument("-d", "--debug", dest="debug", action='store_true') parser.set_defaults(debug=False) args = parser.parse_args() try: fp = open("receiver.txt", "r") dictStr = fp.read() fp.close() recvrDict = message.strToList(dictStr) ports = recvrDict['ports'] t = recvrDict['t'] k = recvrDict['k'] prime = recvrDict['prime'] key = recvrDict['key'] mode = recvrDict['mode'] buf = recvrDict['buffer'] nodePorts = recvrDict['nodes'] addr = mysocket.gethostname() nodes = [(addr, portNum) for portNum in nodePorts] r = receiver(ports, key, args.debug) secret, faultyNodes, reconTime = r.reconstructSecret( nodes, buf, k, t, prime, mode) if len(faultyNodes) == 0:
# Boilerplate Code # ############################################################# if __name__ == "__main__": #code to execute if called from command-line parser = argparse.ArgumentParser() parser.add_argument("-d", "--debug", dest="debug", action='store_true') parser.set_defaults(debug=False) args = parser.parse_args() try: fp = open("sender.txt", "r") dictStr = fp.read() fp.close() senderDict = message.strToList(dictStr) ports = senderDict['ports'] msg = senderDict['msg'] n = senderDict['n'] k = senderDict['k'] prime = senderDict['prime'] key = senderDict['key'] mode = senderDict['mode'] nodePorts = senderDict['nodes'] addr = mysocket.gethostname() nodes = [(addr, portNum) for portNum in nodePorts] s = sender(ports, key, args.debug) shares, genTime = s.sendShares(msg, n, k, prime, nodes, mode) print "Time taken to generate shares:", genTime
# Boilerplate Code # ############################################################# if __name__ == "__main__": #code to execute if called from command-line parser = argparse.ArgumentParser() parser.add_argument("-d", "--debug", dest="debug", action='store_true') parser.set_defaults(debug=False) args = parser.parse_args() try: fp = open("receiver.txt", "r") dictStr = fp.read() fp.close() recvrDict = message.strToList(dictStr) ports = recvrDict['ports'] t = recvrDict['t'] k = recvrDict['k'] prime = recvrDict['prime'] key = recvrDict['key'] mode = recvrDict['mode'] buf = recvrDict['buffer'] nodePorts = recvrDict['nodes'] addr = mysocket.gethostname() nodes = [(addr, portNum) for portNum in nodePorts] r = receiver(ports, key, args.debug) secret, faultyNodes, reconTime = r.reconstructSecret(nodes, buf, k, t, prime, mode) if len(faultyNodes) == 0: faultyNodes = None
parser.add_argument("-p", "--port", type=int) parser.add_argument("-f", dest="faulty", action='store_true') parser.add_argument("-d", "--debug", dest="debug", action='store_true') parser.set_defaults(debug=False) parser.set_defaults(faulty=False) args = parser.parse_args() if args.port == None: parser.error("Missing -p <port>") try: fp = open("nodes.txt", "r") dictStr = fp.read() fp.close() nodeDict = message.strToList(dictStr) mode = nodeDict['mode'] buf = nodeDict['buffer'] senderPorts = nodeDict['sender'] receiverPorts = nodeDict['receiver'] port = args.port if args.faulty != None: honest = not args.faulty else: honest = True if honest == False: print "**** Faulty Node ****" startTime = time()