blake2_common.h 925 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #include "byte_order.h"
  2. static inline uint32_t load32(const void *src) {
  3. uint32_t w;
  4. memcpy(&w, src, sizeof w);
  5. #if BYTE_ORDER == BIG_ENDIAN
  6. REVERSE32(w, w);
  7. #endif
  8. return w;
  9. }
  10. static inline uint64_t load64(const void *src) {
  11. uint64_t w;
  12. memcpy(&w, src, sizeof w);
  13. #if BYTE_ORDER == BIG_ENDIAN
  14. REVERSE64(w, w);
  15. #endif
  16. return w;
  17. }
  18. static inline void store16(void *dst, uint16_t w) { memcpy(dst, &w, sizeof w); }
  19. static inline void store32(void *dst, uint32_t w) {
  20. #if BYTE_ORDER == BIG_ENDIAN
  21. REVERSE32(w, w);
  22. #endif
  23. memcpy(dst, &w, sizeof w);
  24. }
  25. static inline void store64(void *dst, uint64_t w) {
  26. #if BYTE_ORDER == BIG_ENDIAN
  27. REVERSE64(w, w);
  28. #endif
  29. memcpy(dst, &w, sizeof w);
  30. }
  31. static inline uint32_t rotr32(const uint32_t w, const unsigned c) {
  32. return (w >> c) | (w << (32 - c));
  33. }
  34. static inline uint64_t rotr64(const uint64_t w, const unsigned c) {
  35. return (w >> c) | (w << (64 - c));
  36. }