rdpf.cpp 772 B

12345678910111213141516171819202122
  1. #include <bsd/stdlib.h> // arc4random_buf
  2. #include "rdpf.hpp"
  3. #include "bitutils.hpp"
  4. // Construct a DPF of the given depth to be used for random-access
  5. // memory reads and writes. The DPF is construction collaboratively by
  6. // P0 and P1, with the server P2 helping by providing various kinds of
  7. // correlated randomness, such as MultTriples and AndTriples.
  8. void rdpf_gen(MPCTIO &tio, yield_t &yield,
  9. RDPF &rdpf, nbits_t depth)
  10. {
  11. int player = tio.player();
  12. // Choose a random seed
  13. DPFnode seed;
  14. arc4random_buf(&seed, sizeof(seed));
  15. // Ensure the flag bits (the lsb of each node) are different
  16. seed = set_lsb(seed, !!player);
  17. for(int i=0;i<16;++i) { printf("%02x", ((unsigned char *)&seed)[15-i]); } printf("\n");
  18. rdpf.seed = seed;
  19. }