blake2_common.h 957 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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) {
  19. memcpy(dst, &w, sizeof w);
  20. }
  21. static inline void store32(void* dst, uint32_t w) {
  22. #if BYTE_ORDER == BIG_ENDIAN
  23. REVERSE32(w, w);
  24. #endif
  25. memcpy(dst, &w, sizeof w);
  26. }
  27. static inline void store64(void* dst, uint64_t w) {
  28. #if BYTE_ORDER == BIG_ENDIAN
  29. REVERSE64(w, w);
  30. #endif
  31. memcpy(dst, &w, sizeof w);
  32. }
  33. static inline uint32_t rotr32(const uint32_t w, const unsigned c) {
  34. return (w >> c) | (w << (32 - c));
  35. }
  36. static inline uint64_t rotr64(const uint64_t w, const unsigned c) {
  37. return (w >> c) | (w << (64 - c));
  38. }