summaryrefslogtreecommitdiff
path: root/crypto/sha
diff options
context:
space:
mode:
authorRichard Levitte <levitte@openssl.org>2020-07-09 08:37:46 +0200
committerRichard Levitte <levitte@openssl.org>2020-07-11 10:00:33 +0200
commite23d850ff3281220f33ed78d9ca4fcadfa279565 (patch)
tree4e7f73d978bb1a7986e0ac27ee61bdab23d66ed2 /crypto/sha
parentd685fc7a59699aeb17120aebd17a9175ce5930cd (diff)
downloadopenssl-new-e23d850ff3281220f33ed78d9ca4fcadfa279565.tar.gz
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 'crypto/sha')
-rw-r--r--crypto/sha/sha256.c10
-rw-r--r--crypto/sha/sha_local.h12
2 files changed, 7 insertions, 15 deletions
diff --git a/crypto/sha/sha256.c b/crypto/sha/sha256.c
index d16a9c91b2..4fa68953d1 100644
--- a/crypto/sha/sha256.c
+++ b/crypto/sha/sha256.c
@@ -21,6 +21,7 @@
#include <openssl/crypto.h>
#include <openssl/sha.h>
#include <openssl/opensslv.h>
+#include "internal/endian.h"
int SHA224_Init(SHA256_CTX *c)
{
@@ -256,12 +257,7 @@ static void sha256_block_data_order(SHA256_CTX *ctx, const void *in,
SHA_LONG X[16];
int i;
const unsigned char *data = in;
- const union {
- long one;
- char little;
- } is_endian = {
- 1
- };
+ DECLARE_IS_ENDIAN;
while (num--) {
@@ -274,7 +270,7 @@ static void sha256_block_data_order(SHA256_CTX *ctx, const void *in,
g = ctx->h[6];
h = ctx->h[7];
- if (!is_endian.little && sizeof(SHA_LONG) == 4
+ if (!IS_LITTLE_ENDIAN && sizeof(SHA_LONG) == 4
&& ((size_t)in % 4) == 0) {
const SHA_LONG *W = (const SHA_LONG *)data;
diff --git a/crypto/sha/sha_local.h b/crypto/sha/sha_local.h
index f7c0ac707b..d592a829f4 100644
--- a/crypto/sha/sha_local.h
+++ b/crypto/sha/sha_local.h
@@ -12,6 +12,7 @@
#include <openssl/opensslconf.h>
#include <openssl/sha.h>
+#include "internal/endian.h"
#define DATA_ORDER_IS_BIG_ENDIAN
@@ -151,14 +152,9 @@ static void HASH_BLOCK_DATA_ORDER(SHA_CTX *c, const void *p, size_t num)
E = c->h4;
for (;;) {
- const union {
- long one;
- char little;
- } is_endian = {
- 1
- };
-
- if (!is_endian.little && sizeof(SHA_LONG) == 4
+ DECLARE_IS_ENDIAN;
+
+ if (!IS_LITTLE_ENDIAN && sizeof(SHA_LONG) == 4
&& ((size_t)p % 4) == 0) {
const SHA_LONG *W = (const SHA_LONG *)data;