1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- #include <functional>
- #include "types.hpp"
- #include "duoram.hpp"
- #include "cell.hpp"
- // We use the cell in various ways. This function is called by
- // online.cpp.
- void cell(MPCIO &mpcio,
- const PRACOptions &opts, char **args)
- {
- nbits_t depth=4;
- if (*args) {
- depth = atoi(*args);
- ++args;
- }
- MPCTIO tio(mpcio, 0, opts.num_threads);
- run_coroutines(tio, [&tio, depth] (yield_t &yield) {
- size_t size = size_t(1)<<depth;
- Duoram<Cell> oram(tio.player(), size);
- auto A = oram.flat(tio, yield);
- Cell c;
- c.key.set(0x0102030405060708);
- c.pointers.set(0x1112131415161718);
- c.value.set(0x2122232425262728);
- // Explicit write
- A[0] = c;
- RegAS idx;
- // Explicit read
- Cell expl_read_c = A[0];
- printf("expl_read_c = ");
- expl_read_c.dump();
- printf("\n");
- // ORAM read
- Cell oram_read_c = A[idx];
- printf("oram_read_c = ");
- oram_read_c.dump();
- printf("\n");
- RegXS valueupdate;
- valueupdate.set(0x4040404040404040 * tio.player());
- RegXS pointersset;
- pointersset.set(0x123456789abcdef0 * tio.player());
- // Explicit update and write of individual fields
- A[1].CELL_VALUE += valueupdate;
- A[3].CELL_POINTERS = pointersset;
- // Explicit read of individual field
- RegXS pointval = A[0].CELL_POINTERS;
- printf("pointval = ");
- pointval.dump();
- printf("\n");
- idx.set(1 * tio.player());
- // ORAM read of individual field
- RegXS oram_value_read = A[idx].CELL_VALUE;
- printf("oram_value_read = ");
- oram_value_read.dump();
- printf("\n");
- valueupdate.set(0x8080808080808080 * tio.player());
- // ORAM update of individual field
- A[idx].CELL_VALUE += valueupdate;
- idx.set(2 * tio.player());
- // ORAM write of individual field
- A[idx].CELL_VALUE = valueupdate;
- c.key.set(0x0102030405060708 * tio.player());
- c.pointers.set(0x1112131415161718 * tio.player());
- c.value.set(0x2122232425262728 * tio.player());
- // ORAM update of full Cell
- A[idx] += c;
- idx.set(3 * tio.player());
- // ORAM write of full Cell
- A[idx] = c;
- printf("\n");
- if (depth < 10) {
- oram.dump();
- auto R = A.reconstruct();
- if (tio.player() == 0) {
- for(size_t i=0;i<R.size();++i) {
- printf("\n%04lx ", i);
- R[i].dump();
- }
- printf("\n");
- }
- }
- });
- }
|