import numpy as np import sys OP_MUL = 1 OP_ADD = 2 OP_LESS = 3 OP_GREATER = 4 OP_DIV = 5 OP_SUB = 6 OP_MOD = 7 OP_EQUAL = 8 OP_NOTEQUAL = 9 OP_GREATEREQUAL = 10 OP_LESSEQUAL = 11 OP_OR = 12 OP_NOT = 13 OP_AND = 14 OP_XOR = 15 ctx = None def init(parid, conf): ''' :param parid: partyid :param conf: conf :return: ctx example: conf = { "NODE_INFO": [ { "HOST": "127.0.0.1", "PORT": 44122, "NODE_ID": "P0" }, { "HOST": "127.0.0.1", "PORT": 42143, "NODE_ID": "P1" }, { "HOST": "127.0.0.1", "PORT": 53169, "NODE_ID": "P2" } ], "DATA_NODES": [ "P0", "P1", "P2" ], "COMPUTATION_NODES": { "P0": 0, "P1": 1, "P2": 2 }, "RESULT_NODES": [ "P0", "P1", "P2" ] } lib.init(0, confbuf) ''' global ctx ctx = snninit(parid, conf) return ctx def privateinput(inputlist, input): ''' :param inputlist: ["P0", "P1"] :param input: numpyarray 1d or 2d, or None :return: a numpy array of same shape of input with type 64uint, which restore the data of secretshared value of input example: P0: s_data = lib.privateinput(["P0"], np.array([[1,2],[3,4]]), dtype=np.float64) P1: s_data = lib.privateinput(["P0"], None) P2: s_data = lib.privateinput(["P0"], None) return a numpy array of same shape of value 64uint ''' pass def opvector(x, y, optype): ''' :param x:left value of op, must be secretshared array :param y:righ value of op, must be secretshared array :param optype: OP_ADD, OP_MUL... :return: OP_MUL 乘法 OP_ADD 加法 OP_LESS 小于 OP_GREATER 大于 OP_DIV 除法 OP_SUB 减法 OP_MOD 取余 OP_EQUAL 等于 OP_NOTEQUAL 不等于 OP_GREATEREQUAL 大于 OP_LESSEQUAL 小于 example: res = lib.opvector(s_data[0], s_data[1], lib.OP_MUL) ''' pass def reveal(receiverlist, value): ''' :param receiverlist:["P0", "P1"] :param value: secretshared array :return: realvalue of same shape of input with type float64t example: real_res = lib.reveal(["P0"], res) ''' pass from dbsec import *