[openssl] master update
Dr. Paul Dale
pauli at openssl.org
Wed Mar 27 22:07:04 UTC 2019
The branch master has been updated
via 045162e52c7eabe241cc831f3fb0f81ba47b8e48 (commit)
from 2500c093aa1e9c90c11c415053c0a27a00661d0d (commit)
- Log -----------------------------------------------------------------
commit 045162e52c7eabe241cc831f3fb0f81ba47b8e48
Author: Pauli <paul.dale at oracle.com>
Date: Mon Mar 25 11:52:58 2019 +1000
Detect endian without relying on defined symbols.
Reviewed-by: Richard Levitte <levitte at openssl.org>
(Merged from https://github.com/openssl/openssl/pull/8572)
-----------------------------------------------------------------------
Summary of changes:
test/{testutil/apps_mem.c => endian.h} | 17 ++++++++++-------
test/params_api_test.c | 23 +++++++++++++----------
2 files changed, 23 insertions(+), 17 deletions(-)
copy test/{testutil/apps_mem.c => endian.h} (52%)
diff --git a/test/testutil/apps_mem.c b/test/endian.h
similarity index 52%
copy from test/testutil/apps_mem.c
copy to test/endian.h
index fa60bc6..0bcec04 100644
--- a/test/testutil/apps_mem.c
+++ b/test/endian.h
@@ -7,13 +7,16 @@
* https://www.openssl.org/source/license.html
*/
-#include "apps.h"
+#ifndef HEADER_INTERNAL_ENDIAN_H
+# define HEADER_INTERNAL_ENDIAN_H
-/* shim that avoids sucking in too much from apps/apps.c */
+# define DECLARE_IS_ENDIAN \
+ const union { \
+ long one; \
+ char little; \
+ } ossl_is_endian = { 1 }
-void* app_malloc(int sz, const char *what)
-{
- void *vp = OPENSSL_malloc(sz);
+# define IS_LITTLE_ENDIAN (ossl_is_endian.little != 0)
+# define IS_BIG_ENDIAN (ossl_is_endian.little == 0)
- return vp;
-}
+#endif
diff --git a/test/params_api_test.c b/test/params_api_test.c
index e592661..c99af3d 100644
--- a/test/params_api_test.c
+++ b/test/params_api_test.c
@@ -11,6 +11,7 @@
#include <string.h>
#include "testutil.h"
#include "internal/nelem.h"
+#include "endian.h"
#include <openssl/params.h>
#include <openssl/bn.h>
@@ -27,20 +28,22 @@ static void swap_copy(unsigned char *out, const void *in, size_t len)
static void copy_to_le(unsigned char *out, const void *in, size_t len)
{
-#ifdef B_ENDIAN
- swap_copy(out, in, len);
-#else
- memcpy(out, in, len);
-#endif
+ DECLARE_IS_ENDIAN;
+
+ if (IS_LITTLE_ENDIAN)
+ memcpy(out, in, len);
+ else
+ swap_copy(out, in, len);
}
static void copy_be_to_native(unsigned char *out, const void *in, size_t len)
{
-#ifdef B_ENDIAN
- memcpy(out, in, len);
-#else
- swap_copy(out, in, len);
-#endif
+ DECLARE_IS_ENDIAN;
+
+ if (IS_LITTLE_ENDIAN)
+ swap_copy(out, in, len);
+ else
+ memcpy(out, in, len);
}
static const struct {
More information about the openssl-commits
mailing list