def getSharesWithMac(self, shares): """Generates a list of string format shares with MAC tags for verification. For each share [x, y] in the list shares, where x and y are integers, it performs the following steps: 1. Convert it into a string '[x, y]' 2. Generate a MAC tag for the message '[x, y]' 3. Create a list ['[x, y]', tag] and convert it into string "['[x, y]', tag]" Args: shares: A list of [int, int] lists corresponding to the shares to be sent to intermediate nodes. Returns: A list of string value shares including MAC tags. Raises: TypeError: Error when shares is not a list. """ if type(shares) != list: raise TypeError("invalid shares: list expected") sharesToSend = [] for share in shares: shareStr = message.listToStr(share) mac = secretSharing.generateMac(shareStr, self.key) msg = message.listToStr([shareStr, mac]) sharesToSend.append(msg) return sharesToSend
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 getSharesWithAuxInfo(self, shares, prime): """Generates a list of string format shares with auxilliary information for verification using information theoretic technique. Let the number of shares is n. For each share[i] = [x, s] in the list shares, where x and s are integers, it performs the following steps: 1. Generate n-1 values y[i][j], b[j][i] and c[j][i] such that c[j][i] = b[j][i]*s[i] + y[i][j] and i != j. 2. Create lists y[i] = {y: y = y[i][j], j != i}, b[i] = {b: b = b[j][i], j != i}, c[i] = {c: c = c[j][i], j != i} 3. Create a list [[x, s], y[i], b[i], c[i]] 4. Convert it into string "[[x, s], y[i], b[i], c[i]]" Args: shares: A list of [int, int] lists corresponding to the shares to be sent to intermediate nodes. prime: A integer value specifying the prime field for modulo operations. Returns: A list of string value shares including auxilliary information for information theoretic verification. Raises: TypeError: Error when shares is not a list, or when prime is not integer. """ if type(shares) != list: raise TypeError("invalid shares: list expected") elif type(prime) not in [int, long]: raise TypeError("invalid prime: int or long expected") sharesToSend = [] yList = [] bList = [] cList = [] for i in range(0, len(shares)): for j in range(0, len(shares)): if i == j: continue c, b, y = secretSharing.generateAuxInfo(shares[i][1], prime) yList.append([i + 1, j + 1, y]) bList.append([j + 1, i + 1, b]) cList.append([j + 1, i + 1, c]) for i in range(0, len(shares)): share = shares[i] y = [element for element in yList if element[0] == i + 1] b = [element for element in bList if element[1] == i + 1] c = [element for element in cList if element[1] == i + 1] msg = message.listToStr([share, y, b, c]) sharesToSend.append(msg) return sharesToSend
def getSharesNoVrfy(self, shares): """Generates a list of string format shares without any verification related information. Args: shares: A list of [int, int] lists corresponding to the shares to be sent to intermediate nodes. Returns: A list of string value shares. Raises: TypeError: Error when shares is not a list. """ if type(shares) != list: raise TypeError("invalid shares: list expected") sharesToSend = [] for share in shares: msg = message.listToStr(share) sharesToSend.append(msg) return sharesToSend