Esempio n. 1
0
    def match(self, n_loops=None):
        if n_loops is None or n_loops > self.N * self.M:
            loop = do_while
            init_rounds = self.N
        else:
            loop = for_range(n_loops)
            init_rounds = n_loops / self.M
        self.wives = \
            self.oram_type(self.N, entry_size=log2(self.N), \
                               init_rounds=0, value_type=self.basic_type)
        self.husbands = \
            self.oram_type(self.N, entry_size=log2(self.N), \
                               init_rounds=0, value_type=self.basic_type)
        propose = \
            self.oram_type(self.N, entry_size=log2(self.N), \
                               init_rounds=0, value_type=self.basic_type)
        self.unengaged = OStack(self.N, oram_type=self.oram_type, \
                                    int_type=self.int_type)

        @for_range(init_rounds)
        def f(i):
            self.unengaged.append(i)

        rounds = types.MemValue(types.regint(0))

        @loop
        def f(i=None):
            rounds.iadd(1)
            time()
            man = self.unengaged.pop()
            #self.husbands.ram[0].x[0].reveal().print_reg('j')
            pref = self.int_type(propose[man])
            if self.M < self.N and n_loops is None:

                @if_((pref == self.M).reveal())
                def f():
                    print_ln('run out of acceptable women')
                    crash()

            #self.husbands.ram[0].x[0].reveal().print_reg('k')
            propose[man] = pref + 1
            #self.husbands.ram[0].x[0].reveal().print_reg('l')
            self.propose(man, self.m_prefs[man][pref], True)
            print_ln('man: %s, pref: %s, left: %s', \
                         *(x.reveal() for x in (man, pref, self.unengaged.size)))
            # self.wives[man].reveal().print_reg('wife')
            return types.regint((self.unengaged.size > 0).reveal())

        print_ln('%s rounds', rounds)

        @for_range(init_rounds)
        def f(i):
            types.cint(i).print_reg('wife')
            self.husbands[i].reveal().print_reg('husb')
Esempio n. 2
0
 def __init__(self, N, oram_type=OptimalORAM, int_type=types.sint):
     print('stack', oram_type)
     self.oram = oram_type(N, entry_size=log2(N), init_rounds=0, \
                               value_type=int_type.basic_type)
     self.size = types.MemValue(int_type(0))
     self.int_type = int_type