diff --git a/src/libsodium/crypto_core/hchacha20/core_hchacha20.c b/src/libsodium/crypto_core/hchacha20/core_hchacha20.c index 13e67396..b3fc1c81 100644 --- a/src/libsodium/crypto_core/hchacha20/core_hchacha20.c +++ b/src/libsodium/crypto_core/hchacha20/core_hchacha20.c @@ -1,42 +1,10 @@ #include #include -#include #include "core_hchacha20.h" #include "crypto_core_hchacha20.h" -static inline uint32_t -load32(const void *src) -{ -#ifdef NATIVE_LITTLE_ENDIAN - uint32_t w; - memcpy(&w, src, sizeof w); - return w; -#else - const uint8_t *p = (const uint8_t *) src; - uint32_t w = *p++; - w |= (uint32_t)(*p++) << 8; - w |= (uint32_t)(*p++) << 16; - w |= (uint32_t)(*p++) << 24; - return w; -#endif -} - -static inline void -store32(void *dst, uint32_t w) -{ -#ifdef NATIVE_LITTLE_ENDIAN - memcpy(dst, &w, sizeof w); -#else - uint8_t *p = (uint8_t *) dst; - *p++ = (uint8_t) w; w >>= 8; - *p++ = (uint8_t) w; w >>= 8; - *p++ = (uint8_t) w; w >>= 8; - *p++ = (uint8_t) w; -#endif -} - int crypto_core_hchacha20(unsigned char *out, const unsigned char *in, const unsigned char *k, const unsigned char *c) diff --git a/src/libsodium/crypto_core/hchacha20/core_hchacha20.h b/src/libsodium/crypto_core/hchacha20/core_hchacha20.h index c1419f3c..b7d3a16c 100644 --- a/src/libsodium/crypto_core/hchacha20/core_hchacha20.h +++ b/src/libsodium/crypto_core/hchacha20/core_hchacha20.h @@ -1,6 +1,10 @@ #ifndef core_hchacha20_H #define core_hchacha20_H +#include +#include +#include + #define U8C(v) (v##U) #define U32C(v) (v##U) @@ -21,4 +25,35 @@ c = PLUS(c, d); b = ROTATE(XOR(b, c), 7); \ } while(0) +static inline uint32_t +load32(const void *src) +{ +#ifdef NATIVE_LITTLE_ENDIAN + uint32_t w; + memcpy(&w, src, sizeof w); + return w; +#else + const uint8_t *p = (const uint8_t *) src; + uint32_t w = *p++; + w |= (uint32_t)(*p++) << 8; + w |= (uint32_t)(*p++) << 16; + w |= (uint32_t)(*p++) << 24; + return w; +#endif +} + +static inline void +store32(void *dst, uint32_t w) +{ +#ifdef NATIVE_LITTLE_ENDIAN + memcpy(dst, &w, sizeof w); +#else + uint8_t *p = (uint8_t *) dst; + *p++ = (uint8_t) w; w >>= 8; + *p++ = (uint8_t) w; w >>= 8; + *p++ = (uint8_t) w; w >>= 8; + *p++ = (uint8_t) w; +#endif +} + #endif