diff options
author | Richard Levitte <levitte@openssl.org> | 2020-07-09 08:37:46 +0200 |
---|---|---|
committer | Richard Levitte <levitte@openssl.org> | 2020-07-11 10:00:33 +0200 |
commit | e23d850ff3281220f33ed78d9ca4fcadfa279565 (patch) | |
tree | 4e7f73d978bb1a7986e0ac27ee61bdab23d66ed2 /providers/implementations/digests/blake2_impl.h | |
parent | d685fc7a59699aeb17120aebd17a9175ce5930cd (diff) |
Add and use internal header that implements endianness check
This moves test/ossl_test_endian.h to include/internal/endian.h and
thereby makes the macros in there our standard way to check endianness
in run-time.
Reviewed-by: Kurt Roeckx <kurt@roeckx.be>
(Merged from https://github.com/openssl/openssl/pull/12390)
Diffstat (limited to 'providers/implementations/digests/blake2_impl.h')
-rw-r--r-- | providers/implementations/digests/blake2_impl.h | 29 |
1 files changed, 9 insertions, 20 deletions
diff --git a/providers/implementations/digests/blake2_impl.h b/providers/implementations/digests/blake2_impl.h index 52477a8fe2..aa6d8a3075 100644 --- a/providers/implementations/digests/blake2_impl.h +++ b/providers/implementations/digests/blake2_impl.h @@ -15,15 +15,13 @@ */ #include <string.h> +#include "internal/endian.h" static ossl_inline uint32_t load32(const uint8_t *src) { - const union { - long one; - char little; - } is_endian = { 1 }; + DECLARE_IS_ENDIAN; - if (is_endian.little) { + if (IS_LITTLE_ENDIAN) { uint32_t w; memcpy(&w, src, sizeof(w)); return w; @@ -38,12 +36,9 @@ static ossl_inline uint32_t load32(const uint8_t *src) static ossl_inline uint64_t load64(const uint8_t *src) { - const union { - long one; - char little; - } is_endian = { 1 }; + DECLARE_IS_ENDIAN; - if (is_endian.little) { + if (IS_LITTLE_ENDIAN) { uint64_t w; memcpy(&w, src, sizeof(w)); return w; @@ -62,12 +57,9 @@ static ossl_inline uint64_t load64(const uint8_t *src) static ossl_inline void store32(uint8_t *dst, uint32_t w) { - const union { - long one; - char little; - } is_endian = { 1 }; + DECLARE_IS_ENDIAN; - if (is_endian.little) { + if (IS_LITTLE_ENDIAN) { memcpy(dst, &w, sizeof(w)); } else { uint8_t *p = (uint8_t *)dst; @@ -80,12 +72,9 @@ static ossl_inline void store32(uint8_t *dst, uint32_t w) static ossl_inline void store64(uint8_t *dst, uint64_t w) { - const union { - long one; - char little; - } is_endian = { 1 }; + DECLARE_IS_ENDIAN; - if (is_endian.little) { + if (IS_LITTLE_ENDIAN) { memcpy(dst, &w, sizeof(w)); } else { uint8_t *p = (uint8_t *)dst; |