memxor.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. /*
  2. * XOR two pieces of memory, copying the result into a third, which
  3. * may precisely alias one of the input pair (but no guarantees if it
  4. * partially overlaps).
  5. */
  6. #include "defs.h"
  7. #include "misc.h"
  8. void memxor(uint8_t *out, const uint8_t *in1, const uint8_t *in2, size_t size)
  9. {
  10. switch (size & 15) {
  11. case 0:
  12. while (size >= 16) {
  13. size -= 16;
  14. *out++ = *in1++ ^ *in2++;
  15. case 15: *out++ = *in1++ ^ *in2++;
  16. case 14: *out++ = *in1++ ^ *in2++;
  17. case 13: *out++ = *in1++ ^ *in2++;
  18. case 12: *out++ = *in1++ ^ *in2++;
  19. case 11: *out++ = *in1++ ^ *in2++;
  20. case 10: *out++ = *in1++ ^ *in2++;
  21. case 9: *out++ = *in1++ ^ *in2++;
  22. case 8: *out++ = *in1++ ^ *in2++;
  23. case 7: *out++ = *in1++ ^ *in2++;
  24. case 6: *out++ = *in1++ ^ *in2++;
  25. case 5: *out++ = *in1++ ^ *in2++;
  26. case 4: *out++ = *in1++ ^ *in2++;
  27. case 3: *out++ = *in1++ ^ *in2++;
  28. case 2: *out++ = *in1++ ^ *in2++;
  29. case 1: *out++ = *in1++ ^ *in2++;
  30. }
  31. }
  32. }