prg_lowmc_impl.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /* Copyright (C) 2019 Anonymous
  2. *
  3. * This is a pre-release version of the DPF++ library distributed anonymously
  4. * for peer review. A public release of the software will be published under the
  5. * LPGL v2.1 license in the near future. Please do not redistribute this version
  6. * of the software.
  7. */
  8. #ifndef DPFPP_PRG_LOWMC_IMPL_H__
  9. #define DPFPP_PRG_LOWMC_IMPL_H__
  10. #include "prg.h"
  11. #include "../lowmc/lowmc.h"
  12. namespace dpf
  13. {
  14. template <typename lowmc>
  15. inline void PRG(const lowmc & prgkey, const __m128i & seed, void * outbuf, const uint32_t len, const uint32_t from = 0)
  16. {
  17. using block_t = typename lowmc::block_t;
  18. block_t * outbuf128 = reinterpret_cast<block_t*>(outbuf);
  19. //printf(" seed = %llu <-> %llu\n", seed[0], seed[1]);
  20. for (size_t i = 0; i < len; ++i)
  21. {
  22. auto tmp = _mm_xor_si128(seed, _mm_set_epi64x(0, from+i));
  23. outbuf128[i] = prgkey.encrypt(tmp);
  24. outbuf128[i] = _mm_xor_si128(outbuf128[i], tmp);
  25. }
  26. }
  27. template<typename lowmc>
  28. inline std::ostream & operator<<(std::ostream & os, const lowmc & prgkey)
  29. {
  30. auto zero = _mm_setzero_si128();
  31. return os.write(reinterpret_cast<const char *>(&zero), sizeof(__m128i));
  32. }
  33. } // namespace dpf
  34. #endif // DPFPP_PRG_LOWMC_IMPL_H