def __init__(self, args, options, param=-1, assemblymode=False): self.options = options self.args = args self.init_names(args, assemblymode) self.P = P_VALUES[param] self.param = param self.bit_length = BIT_LENGTHS[param] print 'Default bit length:', self.bit_length self.security = 40 print 'Default security parameter:', self.security self.galois_length = int(options.galois) print 'Galois length:', self.galois_length self.schedule = [('start', [])] self.main_ctr = 0 self.tapes = [] self._curr_tape = None self.EMULATE = True # defaults self.FIRST_PASS = False self.DEBUG = False self.main_thread_running = False self.allocated_mem = RegType.create_dict(lambda: USER_MEM) self.free_mem_blocks = defaultdict(set) self.allocated_mem_blocks = {} self.req_num = None self.tape_stack = [] self.n_threads = 1 self.free_threads = set() self.public_input_file = open(self.programs_dir + '/Public-Input/%s' % self.name, 'w') self.types = {} self.to_merge = [Compiler.instructions.asm_open_class, \ Compiler.instructions.gasm_open_class, \ Compiler.instructions.muls_class, \ Compiler.instructions.gmuls_class, \ Compiler.instructions.asm_input_class, \ Compiler.instructions.gasm_input_class] import Compiler.GC.instructions as gc self.to_merge += [gc.ldmsdi, gc.stmsdi, gc.ldmsd, gc.stmsd, \ gc.stmsdci, gc.xors, gc.andrs, gc.ands, gc.inputb] Program.prog = self self.reset_values()
def init_registers(self): self.reset_registers() self.reg_counter = RegType.create_dict(lambda: 0)
def reset_registers(self): """ Reset register values to zero. """ self.reg_values = RegType.create_dict(lambda: [0] * INIT_REG_MAX)
def __init__(self, args, options=defaults): from .non_linear import Ring, Prime, KnownPrime self.options = options self.verbose = options.verbose self.args = args self.init_names(args) self._security = 40 self.prime = None if sum(x != 0 for x in(options.ring, options.field, options.binary)) > 1: raise CompilerError('can only use one out of -B, -R, -F') if options.prime and (options.ring or options.binary): raise CompilerError('can only use one out of -B, -R, -p') if options.ring: self.bit_length = int(options.ring) - 1 self.non_linear = Ring(int(options.ring)) else: self.bit_length = int(options.binary) or int(options.field) if options.prime: self.prime = int(options.prime) max_bit_length = int(options.prime).bit_length() - 2 if self.bit_length > max_bit_length: raise CompilerError('integer bit length can be maximal %s' % max_bit_length) self.bit_length = self.bit_length or max_bit_length self.non_linear = KnownPrime(self.prime) else: self.non_linear = Prime(self.security) if not self.bit_length: self.bit_length = 64 print('Default bit length:', self.bit_length) print('Default security parameter:', self.security) self.galois_length = int(options.galois) if self.verbose: print('Galois length:', self.galois_length) self.tape_counter = 0 self.tapes = [] self._curr_tape = None self.DEBUG = options.debug self.allocated_mem = RegType.create_dict(lambda: USER_MEM) self.free_mem_blocks = defaultdict(al.BlockAllocator) self.allocated_mem_blocks = {} self.saved = 0 self.req_num = None self.tape_stack = [] self.n_threads = 1 self.free_threads = set() self.public_input_file = None self.types = {} self.budget = int(self.options.budget) self.to_merge = [Compiler.instructions.asm_open_class, \ Compiler.instructions.gasm_open_class, \ Compiler.instructions.muls_class, \ Compiler.instructions.gmuls_class, \ Compiler.instructions.mulrs_class, \ Compiler.instructions.gmulrs, \ Compiler.instructions.dotprods_class, \ Compiler.instructions.gdotprods_class, \ Compiler.instructions.asm_input_class, \ Compiler.instructions.gasm_input_class, Compiler.instructions.inputfix_class, Compiler.instructions.inputfloat_class, Compiler.instructions.inputmixed_class, Compiler.instructions.trunc_pr_class, Compiler.instructions_base.Mergeable] import Compiler.GC.instructions as gc self.to_merge += [gc.ldmsdi, gc.stmsdi, gc.ldmsd, gc.stmsd, \ gc.stmsdci, gc.xors, gc.andrs, gc.ands, gc.inputb] self.use_trunc_pr = False """ Setting whether to use special probabilistic truncation. """ self.use_dabit = options.mixed """ Setting whether to use daBits for non-linear functionality. """ self._edabit = options.edabit self._split = False if options.split: self.use_split(int(options.split)) self._square = False self._always_raw = False self.warn_about_mem = [True] Program.prog = self from . import instructions_base, instructions, types, comparison instructions.program = self instructions_base.program = self types.program = self comparison.program = self comparison.set_variant(options)
def __init__(self, args, options, param=-1): self.options = options self.verbose = options.verbose self.args = args self.init_names(args) self.P = P_VALUES[param] self.param = param if (param != -1) + sum( x != 0 for x in (options.ring, options.field, options.binary)) > 1: raise CompilerError('can only use one out of -p, -B, -R, -F') if options.ring: self.bit_length = int(options.ring) - 1 else: self.bit_length = int(options.binary) or int(options.field) if not self.bit_length: self.bit_length = BIT_LENGTHS[param] print('Default bit length:', self.bit_length) self.security = 40 print('Default security parameter:', self.security) self.galois_length = int(options.galois) if self.verbose: print('Galois length:', self.galois_length) self.schedule = [('start', [])] self.tape_counter = 0 self.tapes = [] self._curr_tape = None self.DEBUG = False self.main_thread_running = False self.allocated_mem = RegType.create_dict(lambda: USER_MEM) self.free_mem_blocks = defaultdict(set) self.allocated_mem_blocks = {} self.req_num = None self.tape_stack = [] self.n_threads = 1 self.free_threads = set() self.public_input_file = open( self.programs_dir + '/Public-Input/%s' % self.name, 'w') self.use_public_input_file = False self.types = {} self.budget = int(self.options.budget) self.to_merge = [Compiler.instructions.asm_open_class, \ Compiler.instructions.gasm_open_class, \ Compiler.instructions.muls_class, \ Compiler.instructions.gmuls_class, \ Compiler.instructions.mulrs_class, \ Compiler.instructions.gmulrs, \ Compiler.instructions.dotprods_class, \ Compiler.instructions.gdotprods_class, \ Compiler.instructions.asm_input_class, \ Compiler.instructions.gasm_input_class, Compiler.instructions.inputfix_class, Compiler.instructions.inputfloat_class, Compiler.instructions.inputmixed_class, Compiler.instructions.trunc_pr_class, Compiler.instructions_base.Mergeable] import Compiler.GC.instructions as gc self.to_merge += [gc.ldmsdi, gc.stmsdi, gc.ldmsd, gc.stmsd, \ gc.stmsdci, gc.xors, gc.andrs, gc.ands, gc.inputb] self.use_trunc_pr = False self.use_dabit = options.mixed self._edabit = options.edabit self._split = False self._square = False Program.prog = self
def __init__(self, args, options): self.options = options self.verbose = options.verbose self.args = args self.init_names(args) if sum(x != 0 for x in (options.ring, options.field, options.binary)) > 1: raise CompilerError('can only use one out of -B, -R, -F') if options.ring: self.bit_length = int(options.ring) - 1 else: self.bit_length = int(options.binary) or int(options.field) if not self.bit_length: self.bit_length = 64 print('Default bit length:', self.bit_length) self.security = 40 print('Default security parameter:', self.security) self.galois_length = int(options.galois) if self.verbose: print('Galois length:', self.galois_length) self.tape_counter = 0 self.tapes = [] self._curr_tape = None self.DEBUG = False self.allocated_mem = RegType.create_dict(lambda: USER_MEM) self.free_mem_blocks = defaultdict(al.BlockAllocator) self.allocated_mem_blocks = {} self.saved = 0 self.req_num = None self.tape_stack = [] self.n_threads = 1 self.free_threads = set() self.public_input_file = None self.types = {} self.budget = int(self.options.budget) self.to_merge = [Compiler.instructions.asm_open_class, \ Compiler.instructions.gasm_open_class, \ Compiler.instructions.muls_class, \ Compiler.instructions.gmuls_class, \ Compiler.instructions.mulrs_class, \ Compiler.instructions.gmulrs, \ Compiler.instructions.dotprods_class, \ Compiler.instructions.gdotprods_class, \ Compiler.instructions.asm_input_class, \ Compiler.instructions.gasm_input_class, Compiler.instructions.inputfix_class, Compiler.instructions.inputfloat_class, Compiler.instructions.inputmixed_class, Compiler.instructions.trunc_pr_class, Compiler.instructions_base.Mergeable] import Compiler.GC.instructions as gc self.to_merge += [gc.ldmsdi, gc.stmsdi, gc.ldmsd, gc.stmsd, \ gc.stmsdci, gc.xors, gc.andrs, gc.ands, gc.inputb] self.use_trunc_pr = False self.use_dabit = options.mixed self._edabit = options.edabit self._split = False if options.split: self.use_split(int(options.split)) self._square = False self._always_raw = False Program.prog = self
def reset_registers(self): """ Reset register values to zero. """ self.reg_values = RegType.create_dict(lambda: [0] * INIT_REG_MAX)
def init_registers(self): self.reset_registers() self.reg_counter = RegType.create_dict(lambda: 0)