rdpf.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #include <bsd/stdlib.h> // arc4random_buf
  2. #include "rdpf.hpp"
  3. #include "bitutils.hpp"
  4. #include "aes.hpp"
  5. #include "prg.hpp"
  6. // Construct a DPF of the given depth to be used for random-access
  7. // memory reads and writes. The DPF is construction collaboratively by
  8. // P0 and P1, with the server P2 helping by providing various kinds of
  9. // correlated randomness, such as MultTriples and AndTriples.
  10. void rdpf_gen(MPCTIO &tio, yield_t &yield,
  11. RDPF &rdpf, nbits_t depth)
  12. {
  13. int player = tio.player();
  14. // Choose a random seed
  15. DPFnode seed;
  16. arc4random_buf(&seed, sizeof(seed));
  17. // Ensure the flag bits (the lsb of each node) are different
  18. seed = set_lsb(seed, !!player);
  19. printf("seed: "); for(int i=0;i<16;++i) { printf("%02x", ((unsigned char *)&seed)[15-i]); } printf("\n");
  20. rdpf.seed = seed;
  21. AESkey prgkey;
  22. __m128i key = _mm_set_epi64x(314159265, 271828182);
  23. AES_128_Key_Expansion(prgkey, key);
  24. __m128i left, right;
  25. AES_ECB_encrypt(left, set_lsb(seed, 0), prgkey);
  26. AES_ECB_encrypt(right, set_lsb(seed, 1), prgkey);
  27. __m128i nleft, nright, oleft, oright;
  28. prg(nleft, seed, 0);
  29. prg(nright, seed, 1);
  30. prgboth(oleft, oright, seed);
  31. printf("left : "); for(int i=0;i<16;++i) { printf("%02x", ((unsigned char *)&left)[15-i]); } printf("\n");
  32. printf("nleft: "); for(int i=0;i<16;++i) { printf("%02x", ((unsigned char *)&nleft)[15-i]); } printf("\n");
  33. printf("oleft: "); for(int i=0;i<16;++i) { printf("%02x", ((unsigned char *)&oleft)[15-i]); } printf("\n");
  34. printf("rght : "); for(int i=0;i<16;++i) { printf("%02x", ((unsigned char *)&right)[15-i]); } printf("\n");
  35. printf("nrght: "); for(int i=0;i<16;++i) { printf("%02x", ((unsigned char *)&nright)[15-i]); } printf("\n");
  36. printf("orght: "); for(int i=0;i<16;++i) { printf("%02x", ((unsigned char *)&oright)[15-i]); } printf("\n");
  37. }