def splitAdd(user, password, name, value): splits = getSplits(user, password) k = int(splits[0]) n = (len(splits) - 1)/2 assert int(n) == n assert k <= n splitter = ShamirSplit() shares = splitter.share(value, k, n) for s in range(n): global host, port host = splits[2*s + 1] port = splits[2*s + 2] print "Sending split", s, "to", host + ":" + port add(user, password, 1, name, concat([int2bin(s + 1), int2bin(shares[s])]))
def splitAdd(user, password, name, value): splits = getSplits(user, password) k = int(splits[0]) n = (len(splits) - 1) / 2 assert int(n) == n assert k <= n splitter = ShamirSplit() shares = splitter.share(value, k, n) for s in range(n): global host, port host = splits[2 * s + 1] port = splits[2 * s + 2] print "Sending split", s, "to", host + ":" + port add(user, password, 1, name, concat([int2bin(s + 1), int2bin(shares[s])]))
def splitGet(user, password, name): splits = getSplits(user, password) k = int(splits[0]) n = (len(splits) - 1)/2 assert int(n) == n assert k <= n keys = KeyDeriver(password) shares = {} # FIXME: obviously we should try all n until we get k splits for s in range(k): global host, port host = splits[2*s + 1] port = splits[2*s + 2] print "Getting split", s, "from", host + ":" + port records = baseGetList(user, password, 1, name) record = records[-1] share = unconcat(keys.decrypt(record['value'])) assert len(share) == 2 shares[bin2int(share[0])] = bin2int(share[1]) splitter = ShamirSplit() secret = splitter.recover(shares) print "value =", secret
def splitGet(user, password, name): splits = getSplits(user, password) k = int(splits[0]) n = (len(splits) - 1) / 2 assert int(n) == n assert k <= n keys = KeyDeriver(password) shares = {} # FIXME: obviously we should try all n until we get k splits for s in range(k): global host, port host = splits[2 * s + 1] port = splits[2 * s + 2] print "Getting split", s, "from", host + ":" + port records = baseGetList(user, password, 1, name) record = records[-1] share = unconcat(keys.decrypt(record['value'])) assert len(share) == 2 shares[bin2int(share[0])] = bin2int(share[1]) splitter = ShamirSplit() secret = splitter.recover(shares) print "value =", secret